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>
This commit is contained in:
Chen Yu 2018-04-26 08:41:03 +08:00 committed by Len Brown
parent 997e53950e
commit 023fe0ac97
2 changed files with 21 additions and 1 deletions

View File

@ -67,6 +67,8 @@ The column name "all" can be used to enable all disabled-by-default built-in cou
.PP .PP
\fB--interval seconds\fP overrides the default 5.0 second measurement interval. \fB--interval seconds\fP overrides the default 5.0 second measurement interval.
.PP .PP
\fB--num_iterations num\fP number of the measurement iterations.
.PP
\fB--out output_file\fP turbostat output is written to the specified output_file. \fB--out output_file\fP turbostat output is written to the specified output_file.
The file is truncated if it already exists, and it is created if it does not exist. The file is truncated if it already exists, and it is created if it does not exist.
.PP .PP

View File

@ -51,6 +51,7 @@ int *fd_percpu;
struct timeval interval_tv = {5, 0}; struct timeval interval_tv = {5, 0};
struct timespec interval_ts = {5, 0}; struct timespec interval_ts = {5, 0};
struct timespec one_msec = {0, 1000000}; struct timespec one_msec = {0, 1000000};
unsigned int num_iterations;
unsigned int debug; unsigned int debug;
unsigned int quiet; unsigned int quiet;
unsigned int shown; unsigned int shown;
@ -496,6 +497,7 @@ void help(void)
"--interval sec.subsec Override default 5-second measurement interval\n" "--interval sec.subsec Override default 5-second measurement interval\n"
"--help print this help message\n" "--help print this help message\n"
"--list list column headers only\n" "--list list column headers only\n"
"--num_iterations num number of the measurement iterations\n"
"--out file create or truncate \"file\" for all output\n" "--out file create or truncate \"file\" for all output\n"
"--version print version information\n" "--version print version information\n"
"\n" "\n"
@ -2763,6 +2765,7 @@ void turbostat_loop()
{ {
int retval; int retval;
int restarted = 0; int restarted = 0;
int done_iters = 0;
setup_signal_handler(); setup_signal_handler();
@ -2781,6 +2784,7 @@ restart:
goto restart; goto restart;
} }
restarted = 0; restarted = 0;
done_iters = 0;
gettimeofday(&tv_even, (struct timezone *)NULL); gettimeofday(&tv_even, (struct timezone *)NULL);
while (1) { while (1) {
@ -2809,6 +2813,8 @@ restart:
flush_output_stdout(); flush_output_stdout();
if (exit_requested) if (exit_requested)
break; break;
if (num_iterations && ++done_iters >= num_iterations)
break;
do_sleep(); do_sleep();
if (snapshot_proc_sysfs_files()) if (snapshot_proc_sysfs_files())
goto restart; goto restart;
@ -2830,6 +2836,8 @@ restart:
flush_output_stdout(); flush_output_stdout();
if (exit_requested) if (exit_requested)
break; break;
if (num_iterations && ++done_iters >= num_iterations)
break;
} }
} }
@ -5212,6 +5220,7 @@ void cmdline(int argc, char **argv)
{"debug", no_argument, 0, 'd'}, /* internal, not documented */ {"debug", no_argument, 0, 'd'}, /* internal, not documented */
{"enable", required_argument, 0, 'e'}, {"enable", required_argument, 0, 'e'},
{"interval", required_argument, 0, 'i'}, {"interval", required_argument, 0, 'i'},
{"num_iterations", required_argument, 0, 'n'},
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"hide", required_argument, 0, 'H'}, // meh, -h taken by --help {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help
{"Joules", no_argument, 0, 'J'}, {"Joules", no_argument, 0, 'J'},
@ -5227,7 +5236,7 @@ void cmdline(int argc, char **argv)
progname = argv[0]; progname = argv[0];
while ((opt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jo:qST:v", while ((opt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jn:o:qST:v",
long_options, &option_index)) != -1) { long_options, &option_index)) != -1) {
switch (opt) { switch (opt) {
case 'a': case 'a':
@ -5287,6 +5296,15 @@ void cmdline(int argc, char **argv)
case 'q': case 'q':
quiet = 1; quiet = 1;
break; break;
case 'n':
num_iterations = strtod(optarg, NULL);
if (num_iterations <= 0) {
fprintf(outf, "iterations %d should be positive number\n",
num_iterations);
exit(2);
}
break;
case 's': case 's':
/* /*
* --show: show only those specified * --show: show only those specified