summaryrefslogtreecommitdiffstats
path: root/tools/power
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2017-07-15 14:57:37 -0400
committerLen Brown <len.brown@intel.com>2018-06-01 12:13:04 -0400
commit8aa2ed0b2839718b9147bb0119a8012217d25a8b (patch)
tree5e5ce89d93ea8d180262cf0ed8f2fe78d6959414 /tools/power
parent3f44a5c62be2f2b15317942fa7bc4a810d2420aa (diff)
downloadlinux-8aa2ed0b2839718b9147bb0119a8012217d25a8b.tar.gz
linux-8aa2ed0b2839718b9147bb0119a8012217d25a8b.tar.bz2
linux-8aa2ed0b2839718b9147bb0119a8012217d25a8b.zip
tools/power turbostat: on SIGINT: sample, print and exit
When running in interval-mode, catch interrupts and print a final data record before exiting. Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'tools/power')
-rw-r--r--tools/power/x86/turbostat/turbostat.84
-rw-r--r--tools/power/x86/turbostat/turbostat.c30
2 files changed, 34 insertions, 0 deletions
diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8
index 04262ab1b78b..2dafba4900ab 100644
--- a/tools/power/x86/turbostat/turbostat.8
+++ b/tools/power/x86/turbostat/turbostat.8
@@ -267,6 +267,10 @@ CPU PRF_CTRL
.fi
+.SH SIGNALS
+
+SIGINT will interrupt interval-mode.
+The end-of-interval data will be collected and displayed before turbostat exits.
.SH NOTES
.B "turbostat "
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 627e5749d7d1..d9703b728fbb 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -2600,11 +2600,37 @@ int snapshot_proc_sysfs_files(void)
return 0;
}
+int exit_requested;
+
+static void signal_handler (int signal)
+{
+ switch (signal) {
+ case SIGINT:
+ exit_requested = 1;
+ if (debug)
+ fprintf(stderr, " SIGINT\n");
+ break;
+ }
+}
+
+void setup_signal_handler(void)
+{
+ struct sigaction sa;
+
+ memset(&sa, 0, sizeof(sa));
+
+ sa.sa_handler = &signal_handler;
+
+ if (sigaction(SIGINT, &sa, NULL) < 0)
+ err(1, "sigaction SIGINT");
+}
void turbostat_loop()
{
int retval;
int restarted = 0;
+ setup_signal_handler();
+
restart:
restarted++;
@@ -2646,6 +2672,8 @@ restart:
compute_average(EVEN_COUNTERS);
format_all_counters(EVEN_COUNTERS);
flush_output_stdout();
+ if (exit_requested)
+ break;
nanosleep(&interval_ts, NULL);
if (snapshot_proc_sysfs_files())
goto restart;
@@ -2665,6 +2693,8 @@ restart:
compute_average(ODD_COUNTERS);
format_all_counters(ODD_COUNTERS);
flush_output_stdout();
+ if (exit_requested)
+ break;
}
}