Commit 2a0609c0 authored by Len Brown's avatar Len Brown

tools/power turbostat: allow sub-sec intervals

turbostat -i interval_sec

will sample and display statistics every interval_sec.
interval_sec used to be a whole number of seconds,
but now we accept a decimal, as small as 0.001 sec (1 ms).
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent f0057310
...@@ -34,7 +34,7 @@ name as necessary to disambiguate it from others is necessary. Note that option ...@@ -34,7 +34,7 @@ name as necessary to disambiguate it from others is necessary. Note that option
\fB--debug\fP displays additional system configuration information. Invoking this parameter \fB--debug\fP displays additional system configuration information. Invoking this parameter
more than once may also enable internal turbostat debug information. more than once may also enable internal turbostat debug information.
.PP .PP
\fB--interval seconds\fP overrides the default 5-second measurement interval. \fB--interval seconds\fP overrides the default 5.0 second measurement interval.
.PP .PP
\fB--help\fP displays usage for the most common parameters. \fB--help\fP displays usage for the most common parameters.
.PP .PP
......
...@@ -38,12 +38,13 @@ ...@@ -38,12 +38,13 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <sched.h> #include <sched.h>
#include <time.h>
#include <cpuid.h> #include <cpuid.h>
#include <linux/capability.h> #include <linux/capability.h>
#include <errno.h> #include <errno.h>
char *proc_stat = "/proc/stat"; char *proc_stat = "/proc/stat";
unsigned int interval_sec = 5; struct timespec interval_ts = {5, 0};
unsigned int debug; unsigned int debug;
unsigned int rapl_joules; unsigned int rapl_joules;
unsigned int summary_only; unsigned int summary_only;
...@@ -1728,7 +1729,7 @@ void turbostat_loop() ...@@ -1728,7 +1729,7 @@ void turbostat_loop()
re_initialize(); re_initialize();
goto restart; goto restart;
} }
sleep(interval_sec); nanosleep(&interval_ts, NULL);
retval = for_all_cpus(get_counters, ODD_COUNTERS); retval = for_all_cpus(get_counters, ODD_COUNTERS);
if (retval < -1) { if (retval < -1) {
exit(retval); exit(retval);
...@@ -1742,7 +1743,7 @@ void turbostat_loop() ...@@ -1742,7 +1743,7 @@ void turbostat_loop()
compute_average(EVEN_COUNTERS); compute_average(EVEN_COUNTERS);
format_all_counters(EVEN_COUNTERS); format_all_counters(EVEN_COUNTERS);
flush_stdout(); flush_stdout();
sleep(interval_sec); nanosleep(&interval_ts, NULL);
retval = for_all_cpus(get_counters, EVEN_COUNTERS); retval = for_all_cpus(get_counters, EVEN_COUNTERS);
if (retval < -1) { if (retval < -1) {
exit(retval); exit(retval);
...@@ -3347,7 +3348,18 @@ void cmdline(int argc, char **argv) ...@@ -3347,7 +3348,18 @@ void cmdline(int argc, char **argv)
help(); help();
exit(1); exit(1);
case 'i': case 'i':
interval_sec = atoi(optarg); {
double interval = strtod(optarg, NULL);
if (interval < 0.001) {
fprintf(stderr, "interval %f seconds is too small\n",
interval);
exit(2);
}
interval_ts.tv_sec = interval;
interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000;
}
break; break;
case 'J': case 'J':
rapl_joules++; rapl_joules++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment