diff options
author | Chen Yu <yu.c.chen@intel.com> | 2018-04-25 20:41:03 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2018-06-01 23:12:45 -0400 |
commit | 023fe0ac975e4dff592ce90bbd12747dedf7c598 (patch) | |
tree | 42a7e6da73b0a220e97c597ff48b0302516a293e /tools | |
parent | 997e53950e3e71ceb13a7cc220d430b7cb78ef8f (diff) |
tools/power turbostat: if --num_iterations, print for specific number of iterations
There's a use case during test to only print specific round of iterations
if --num_iterations is specified, for example, with this patch applied:
turbostat -i 5 -n 4
will capture 4 samples with 5 seconds interval.
[lenb: renamed to --num_iterations from --iterations]
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
Reviewed-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/power/x86/turbostat/turbostat.8 | 2 | ||||
-rw-r--r-- | tools/power/x86/turbostat/turbostat.c | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8 index 4cffa4a5a2b7..ca9ef7017624 100644 --- a/tools/power/x86/turbostat/turbostat.8 +++ b/tools/power/x86/turbostat/turbostat.8 | |||
@@ -67,6 +67,8 @@ The column name "all" can be used to enable all disabled-by-default built-in cou | |||
67 | .PP | 67 | .PP |
68 | \fB--interval seconds\fP overrides the default 5.0 second measurement interval. | 68 | \fB--interval seconds\fP overrides the default 5.0 second measurement interval. |
69 | .PP | 69 | .PP |
70 | \fB--num_iterations num\fP number of the measurement iterations. | ||
71 | .PP | ||
70 | \fB--out output_file\fP turbostat output is written to the specified output_file. | 72 | \fB--out output_file\fP turbostat output is written to the specified output_file. |
71 | The file is truncated if it already exists, and it is created if it does not exist. | 73 | The file is truncated if it already exists, and it is created if it does not exist. |
72 | .PP | 74 | .PP |
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 1cb38c12a8b5..6910773e85a9 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c | |||
@@ -51,6 +51,7 @@ int *fd_percpu; | |||
51 | struct timeval interval_tv = {5, 0}; | 51 | struct timeval interval_tv = {5, 0}; |
52 | struct timespec interval_ts = {5, 0}; | 52 | struct timespec interval_ts = {5, 0}; |
53 | struct timespec one_msec = {0, 1000000}; | 53 | struct timespec one_msec = {0, 1000000}; |
54 | unsigned int num_iterations; | ||
54 | unsigned int debug; | 55 | unsigned int debug; |
55 | unsigned int quiet; | 56 | unsigned int quiet; |
56 | unsigned int shown; | 57 | unsigned int shown; |
@@ -496,6 +497,7 @@ void help(void) | |||
496 | "--interval sec.subsec Override default 5-second measurement interval\n" | 497 | "--interval sec.subsec Override default 5-second measurement interval\n" |
497 | "--help print this help message\n" | 498 | "--help print this help message\n" |
498 | "--list list column headers only\n" | 499 | "--list list column headers only\n" |
500 | "--num_iterations num number of the measurement iterations\n" | ||
499 | "--out file create or truncate \"file\" for all output\n" | 501 | "--out file create or truncate \"file\" for all output\n" |
500 | "--version print version information\n" | 502 | "--version print version information\n" |
501 | "\n" | 503 | "\n" |
@@ -2763,6 +2765,7 @@ void turbostat_loop() | |||
2763 | { | 2765 | { |
2764 | int retval; | 2766 | int retval; |
2765 | int restarted = 0; | 2767 | int restarted = 0; |
2768 | int done_iters = 0; | ||
2766 | 2769 | ||
2767 | setup_signal_handler(); | 2770 | setup_signal_handler(); |
2768 | 2771 | ||
@@ -2781,6 +2784,7 @@ restart: | |||
2781 | goto restart; | 2784 | goto restart; |
2782 | } | 2785 | } |
2783 | restarted = 0; | 2786 | restarted = 0; |
2787 | done_iters = 0; | ||
2784 | gettimeofday(&tv_even, (struct timezone *)NULL); | 2788 | gettimeofday(&tv_even, (struct timezone *)NULL); |
2785 | 2789 | ||
2786 | while (1) { | 2790 | while (1) { |
@@ -2809,6 +2813,8 @@ restart: | |||
2809 | flush_output_stdout(); | 2813 | flush_output_stdout(); |
2810 | if (exit_requested) | 2814 | if (exit_requested) |
2811 | break; | 2815 | break; |
2816 | if (num_iterations && ++done_iters >= num_iterations) | ||
2817 | break; | ||
2812 | do_sleep(); | 2818 | do_sleep(); |
2813 | if (snapshot_proc_sysfs_files()) | 2819 | if (snapshot_proc_sysfs_files()) |
2814 | goto restart; | 2820 | goto restart; |
@@ -2830,6 +2836,8 @@ restart: | |||
2830 | flush_output_stdout(); | 2836 | flush_output_stdout(); |
2831 | if (exit_requested) | 2837 | if (exit_requested) |
2832 | break; | 2838 | break; |
2839 | if (num_iterations && ++done_iters >= num_iterations) | ||
2840 | break; | ||
2833 | } | 2841 | } |
2834 | } | 2842 | } |
2835 | 2843 | ||
@@ -5212,6 +5220,7 @@ void cmdline(int argc, char **argv) | |||
5212 | {"debug", no_argument, 0, 'd'}, /* internal, not documented */ | 5220 | {"debug", no_argument, 0, 'd'}, /* internal, not documented */ |
5213 | {"enable", required_argument, 0, 'e'}, | 5221 | {"enable", required_argument, 0, 'e'}, |
5214 | {"interval", required_argument, 0, 'i'}, | 5222 | {"interval", required_argument, 0, 'i'}, |
5223 | {"num_iterations", required_argument, 0, 'n'}, | ||
5215 | {"help", no_argument, 0, 'h'}, | 5224 | {"help", no_argument, 0, 'h'}, |
5216 | {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help | 5225 | {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help |
5217 | {"Joules", no_argument, 0, 'J'}, | 5226 | {"Joules", no_argument, 0, 'J'}, |
@@ -5227,7 +5236,7 @@ void cmdline(int argc, char **argv) | |||
5227 | 5236 | ||
5228 | progname = argv[0]; | 5237 | progname = argv[0]; |
5229 | 5238 | ||
5230 | while ((opt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jo:qST:v", | 5239 | while ((opt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jn:o:qST:v", |
5231 | long_options, &option_index)) != -1) { | 5240 | long_options, &option_index)) != -1) { |
5232 | switch (opt) { | 5241 | switch (opt) { |
5233 | case 'a': | 5242 | case 'a': |
@@ -5287,6 +5296,15 @@ void cmdline(int argc, char **argv) | |||
5287 | case 'q': | 5296 | case 'q': |
5288 | quiet = 1; | 5297 | quiet = 1; |
5289 | break; | 5298 | break; |
5299 | case 'n': | ||
5300 | num_iterations = strtod(optarg, NULL); | ||
5301 | |||
5302 | if (num_iterations <= 0) { | ||
5303 | fprintf(outf, "iterations %d should be positive number\n", | ||
5304 | num_iterations); | ||
5305 | exit(2); | ||
5306 | } | ||
5307 | break; | ||
5290 | case 's': | 5308 | case 's': |
5291 | /* | 5309 | /* |
5292 | * --show: show only those specified | 5310 | * --show: show only those specified |