diff options
author | Len Brown <len.brown@intel.com> | 2016-02-12 22:44:48 -0500 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2016-03-13 03:55:32 -0400 |
commit | 2a0609c02e6558df6075f258af98a54a74b050ff (patch) | |
tree | 66cc0732bd346840bacc34b2048f002c851658df /tools/power | |
parent | f0057310b40efe9f797ff337e9464e6a6fb9d782 (diff) |
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: Len Brown <len.brown@intel.com>
Diffstat (limited to 'tools/power')
-rw-r--r-- | tools/power/x86/turbostat/turbostat.8 | 2 | ||||
-rw-r--r-- | tools/power/x86/turbostat/turbostat.c | 20 |
2 files changed, 17 insertions, 5 deletions
diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8 index 622db685b4f9..4d8f198f348f 100644 --- a/tools/power/x86/turbostat/turbostat.8 +++ b/tools/power/x86/turbostat/turbostat.8 | |||
@@ -34,7 +34,7 @@ name as necessary to disambiguate it from others is necessary. Note that option | |||
34 | \fB--debug\fP displays additional system configuration information. Invoking this parameter | 34 | \fB--debug\fP displays additional system configuration information. Invoking this parameter |
35 | more than once may also enable internal turbostat debug information. | 35 | more than once may also enable internal turbostat debug information. |
36 | .PP | 36 | .PP |
37 | \fB--interval seconds\fP overrides the default 5-second measurement interval. | 37 | \fB--interval seconds\fP overrides the default 5.0 second measurement interval. |
38 | .PP | 38 | .PP |
39 | \fB--help\fP displays usage for the most common parameters. | 39 | \fB--help\fP displays usage for the most common parameters. |
40 | .PP | 40 | .PP |
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index c600340dfc4e..e411cc435137 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c | |||
@@ -38,12 +38,13 @@ | |||
38 | #include <string.h> | 38 | #include <string.h> |
39 | #include <ctype.h> | 39 | #include <ctype.h> |
40 | #include <sched.h> | 40 | #include <sched.h> |
41 | #include <time.h> | ||
41 | #include <cpuid.h> | 42 | #include <cpuid.h> |
42 | #include <linux/capability.h> | 43 | #include <linux/capability.h> |
43 | #include <errno.h> | 44 | #include <errno.h> |
44 | 45 | ||
45 | char *proc_stat = "/proc/stat"; | 46 | char *proc_stat = "/proc/stat"; |
46 | unsigned int interval_sec = 5; | 47 | struct timespec interval_ts = {5, 0}; |
47 | unsigned int debug; | 48 | unsigned int debug; |
48 | unsigned int rapl_joules; | 49 | unsigned int rapl_joules; |
49 | unsigned int summary_only; | 50 | unsigned int summary_only; |
@@ -1728,7 +1729,7 @@ restart: | |||
1728 | re_initialize(); | 1729 | re_initialize(); |
1729 | goto restart; | 1730 | goto restart; |
1730 | } | 1731 | } |
1731 | sleep(interval_sec); | 1732 | nanosleep(&interval_ts, NULL); |
1732 | retval = for_all_cpus(get_counters, ODD_COUNTERS); | 1733 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
1733 | if (retval < -1) { | 1734 | if (retval < -1) { |
1734 | exit(retval); | 1735 | exit(retval); |
@@ -1742,7 +1743,7 @@ restart: | |||
1742 | compute_average(EVEN_COUNTERS); | 1743 | compute_average(EVEN_COUNTERS); |
1743 | format_all_counters(EVEN_COUNTERS); | 1744 | format_all_counters(EVEN_COUNTERS); |
1744 | flush_stdout(); | 1745 | flush_stdout(); |
1745 | sleep(interval_sec); | 1746 | nanosleep(&interval_ts, NULL); |
1746 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); | 1747 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
1747 | if (retval < -1) { | 1748 | if (retval < -1) { |
1748 | exit(retval); | 1749 | exit(retval); |
@@ -3347,7 +3348,18 @@ void cmdline(int argc, char **argv) | |||
3347 | help(); | 3348 | help(); |
3348 | exit(1); | 3349 | exit(1); |
3349 | case 'i': | 3350 | case 'i': |
3350 | interval_sec = atoi(optarg); | 3351 | { |
3352 | double interval = strtod(optarg, NULL); | ||
3353 | |||
3354 | if (interval < 0.001) { | ||
3355 | fprintf(stderr, "interval %f seconds is too small\n", | ||
3356 | interval); | ||
3357 | exit(2); | ||
3358 | } | ||
3359 | |||
3360 | interval_ts.tv_sec = interval; | ||
3361 | interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; | ||
3362 | } | ||
3351 | break; | 3363 | break; |
3352 | case 'J': | 3364 | case 'J': |
3353 | rapl_joules++; | 3365 | rapl_joules++; |