Re: [PATCH][v5] tools/power turbostat: if --iterations, print for specific count of iterations

2018-04-25 Thread Yu Chen
On Mon, Apr 23, 2018 at 10:48:39AM +0200, Rafael J. Wysocki wrote:
> On Saturday, April 14, 2018 6:10:55 AM CEST Yu Chen wrote:
> > From: Chen Yu 
> > 
> > There's a use case during test to only print specific round of iterations
> > if --iterations is specified, for example, with this patch applied:
> > 
> > turbostat -i 5 -r 4
> > will capture 4 samples with 5 seconds interval.
> > 
> > Cc: Len Brown 
> > Cc: Rafael J Wysocki 
> > Cc: Artem Bityutskiy 
> > Cc: Doug Smythies 
> > Cc: linux...@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Chen Yu 
[cut]...
> > +   if (iterations && (++done_iters >= iterations))
> 
> The inner parens are not needed here (and similarly below).
> 
> If you fix this little one, please feel free to add
> 
> Reviewed-by: Rafael J. Wysocki 
> 
> to the patch (FWIW). 
> 
OK, will do, thanks!
Yu


Re: [PATCH][v5] tools/power turbostat: if --iterations, print for specific count of iterations

2018-04-25 Thread Yu Chen
On Mon, Apr 23, 2018 at 10:48:39AM +0200, Rafael J. Wysocki wrote:
> On Saturday, April 14, 2018 6:10:55 AM CEST Yu Chen wrote:
> > From: Chen Yu 
> > 
> > There's a use case during test to only print specific round of iterations
> > if --iterations is specified, for example, with this patch applied:
> > 
> > turbostat -i 5 -r 4
> > will capture 4 samples with 5 seconds interval.
> > 
> > Cc: Len Brown 
> > Cc: Rafael J Wysocki 
> > Cc: Artem Bityutskiy 
> > Cc: Doug Smythies 
> > Cc: linux...@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Chen Yu 
[cut]...
> > +   if (iterations && (++done_iters >= iterations))
> 
> The inner parens are not needed here (and similarly below).
> 
> If you fix this little one, please feel free to add
> 
> Reviewed-by: Rafael J. Wysocki 
> 
> to the patch (FWIW). 
> 
OK, will do, thanks!
Yu


Re: [PATCH][v5] tools/power turbostat: if --iterations, print for specific count of iterations

2018-04-23 Thread Rafael J. Wysocki
On Saturday, April 14, 2018 6:10:55 AM CEST Yu Chen wrote:
> From: Chen Yu 
> 
> There's a use case during test to only print specific round of iterations
> if --iterations is specified, for example, with this patch applied:
> 
> turbostat -i 5 -r 4
> will capture 4 samples with 5 seconds interval.
> 
> Cc: Len Brown 
> Cc: Rafael J Wysocki 
> Cc: Artem Bityutskiy 
> Cc: Doug Smythies 
> Cc: linux...@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Chen Yu 
> ---
>  tools/power/x86/turbostat/turbostat.8 |  2 ++
>  tools/power/x86/turbostat/turbostat.c | 23 ++-
>  2 files changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/power/x86/turbostat/turbostat.8 
> b/tools/power/x86/turbostat/turbostat.8
> index ccf2a69365cc..7452dc42273b 100644
> --- a/tools/power/x86/turbostat/turbostat.8
> +++ b/tools/power/x86/turbostat/turbostat.8
> @@ -64,6 +64,8 @@ name as necessary to disambiguate it from others is 
> necessary.  Note that option
>  .PP
>  \fB--interval seconds\fP overrides the default 5.0 second measurement 
> interval.
>  .PP
> +\fB--iterations count\fP number of the measurement iterations.
> +.PP
>  \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.
>  .PP
> diff --git a/tools/power/x86/turbostat/turbostat.c 
> b/tools/power/x86/turbostat/turbostat.c
> index bd9c6b31a504..ae9e3d08e3cf 100644
> --- a/tools/power/x86/turbostat/turbostat.c
> +++ b/tools/power/x86/turbostat/turbostat.c
> @@ -48,6 +48,7 @@ char *proc_stat = "/proc/stat";
>  FILE *outf;
>  int *fd_percpu;
>  struct timespec interval_ts = {5, 0};
> +int iterations;
>  unsigned int debug;
>  unsigned int quiet;
>  unsigned int sums_need_wide_columns;
> @@ -470,6 +471,7 @@ void help(void)
>   "   {core | package | j,k,l..m,n-p }\n"
>   "--quietskip decoding system configuration header\n"
>   "--interval sec Override default 5-second measurement interval\n"
> + "--iterations count number of the measurement iterations\n"
>   "--help print this help message\n"
>   "--list list column headers only\n"
>   "--out file create or truncate \"file\" for all output\n"
> @@ -2565,6 +2567,7 @@ void turbostat_loop()
>  {
>   int retval;
>   int restarted = 0;
> + int done_iters = 0;
>  
>  restart:
>   restarted++;
> @@ -2581,6 +2584,7 @@ void turbostat_loop()
>   goto restart;
>   }
>   restarted = 0;
> + done_iters = 0;
>   gettimeofday(_even, (struct timezone *)NULL);
>  
>   while (1) {
> @@ -2607,6 +2611,10 @@ void turbostat_loop()
>   compute_average(EVEN_COUNTERS);
>   format_all_counters(EVEN_COUNTERS);
>   flush_output_stdout();
> +
> + if (iterations && (++done_iters >= iterations))

The inner parens are not needed here (and similarly below).

If you fix this little one, please feel free to add

Reviewed-by: Rafael J. Wysocki 

to the patch (FWIW). 

> + break;
> +
>   nanosleep(_ts, NULL);
>   if (snapshot_proc_sysfs_files())
>   goto restart;
> @@ -2626,6 +2634,9 @@ void turbostat_loop()
>   compute_average(ODD_COUNTERS);
>   format_all_counters(ODD_COUNTERS);
>   flush_output_stdout();
> +
> + if (iterations && (++done_iters >= iterations))
> + break;
>   }
>  }
>  
> @@ -4999,6 +5010,7 @@ void cmdline(int argc, char **argv)
>   {"Dump",no_argument,0, 'D'},
>   {"debug",   no_argument,0, 'd'},/* 
> internal, not documented */
>   {"interval",required_argument,  0, 'i'},
> + {"iterations",  required_argument,  0, 'r'},
>   {"help",no_argument,0, 'h'},
>   {"hide",required_argument,  0, 'H'},// meh, 
> -h taken by --help
>   {"Joules",  no_argument,0, 'J'},
> @@ -5014,7 +5026,7 @@ void cmdline(int argc, char **argv)
>  
>   progname = argv[0];
>  
> - while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qST:v",
> + while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qr:ST:v",
>   long_options, _index)) != -1) {
>   switch (opt) {
>   case 'a':
> @@ -5063,6 +5075,15 @@ void cmdline(int argc, char **argv)
>   case 'q':
>   quiet = 1;
>   break;
> + case 'r':
> + iterations = strtod(optarg, NULL);
> +
> + if (iterations <= 0) {
> +

Re: [PATCH][v5] tools/power turbostat: if --iterations, print for specific count of iterations

2018-04-23 Thread Rafael J. Wysocki
On Saturday, April 14, 2018 6:10:55 AM CEST Yu Chen wrote:
> From: Chen Yu 
> 
> There's a use case during test to only print specific round of iterations
> if --iterations is specified, for example, with this patch applied:
> 
> turbostat -i 5 -r 4
> will capture 4 samples with 5 seconds interval.
> 
> Cc: Len Brown 
> Cc: Rafael J Wysocki 
> Cc: Artem Bityutskiy 
> Cc: Doug Smythies 
> Cc: linux...@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Chen Yu 
> ---
>  tools/power/x86/turbostat/turbostat.8 |  2 ++
>  tools/power/x86/turbostat/turbostat.c | 23 ++-
>  2 files changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/power/x86/turbostat/turbostat.8 
> b/tools/power/x86/turbostat/turbostat.8
> index ccf2a69365cc..7452dc42273b 100644
> --- a/tools/power/x86/turbostat/turbostat.8
> +++ b/tools/power/x86/turbostat/turbostat.8
> @@ -64,6 +64,8 @@ name as necessary to disambiguate it from others is 
> necessary.  Note that option
>  .PP
>  \fB--interval seconds\fP overrides the default 5.0 second measurement 
> interval.
>  .PP
> +\fB--iterations count\fP number of the measurement iterations.
> +.PP
>  \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.
>  .PP
> diff --git a/tools/power/x86/turbostat/turbostat.c 
> b/tools/power/x86/turbostat/turbostat.c
> index bd9c6b31a504..ae9e3d08e3cf 100644
> --- a/tools/power/x86/turbostat/turbostat.c
> +++ b/tools/power/x86/turbostat/turbostat.c
> @@ -48,6 +48,7 @@ char *proc_stat = "/proc/stat";
>  FILE *outf;
>  int *fd_percpu;
>  struct timespec interval_ts = {5, 0};
> +int iterations;
>  unsigned int debug;
>  unsigned int quiet;
>  unsigned int sums_need_wide_columns;
> @@ -470,6 +471,7 @@ void help(void)
>   "   {core | package | j,k,l..m,n-p }\n"
>   "--quietskip decoding system configuration header\n"
>   "--interval sec Override default 5-second measurement interval\n"
> + "--iterations count number of the measurement iterations\n"
>   "--help print this help message\n"
>   "--list list column headers only\n"
>   "--out file create or truncate \"file\" for all output\n"
> @@ -2565,6 +2567,7 @@ void turbostat_loop()
>  {
>   int retval;
>   int restarted = 0;
> + int done_iters = 0;
>  
>  restart:
>   restarted++;
> @@ -2581,6 +2584,7 @@ void turbostat_loop()
>   goto restart;
>   }
>   restarted = 0;
> + done_iters = 0;
>   gettimeofday(_even, (struct timezone *)NULL);
>  
>   while (1) {
> @@ -2607,6 +2611,10 @@ void turbostat_loop()
>   compute_average(EVEN_COUNTERS);
>   format_all_counters(EVEN_COUNTERS);
>   flush_output_stdout();
> +
> + if (iterations && (++done_iters >= iterations))

The inner parens are not needed here (and similarly below).

If you fix this little one, please feel free to add

Reviewed-by: Rafael J. Wysocki 

to the patch (FWIW). 

> + break;
> +
>   nanosleep(_ts, NULL);
>   if (snapshot_proc_sysfs_files())
>   goto restart;
> @@ -2626,6 +2634,9 @@ void turbostat_loop()
>   compute_average(ODD_COUNTERS);
>   format_all_counters(ODD_COUNTERS);
>   flush_output_stdout();
> +
> + if (iterations && (++done_iters >= iterations))
> + break;
>   }
>  }
>  
> @@ -4999,6 +5010,7 @@ void cmdline(int argc, char **argv)
>   {"Dump",no_argument,0, 'D'},
>   {"debug",   no_argument,0, 'd'},/* 
> internal, not documented */
>   {"interval",required_argument,  0, 'i'},
> + {"iterations",  required_argument,  0, 'r'},
>   {"help",no_argument,0, 'h'},
>   {"hide",required_argument,  0, 'H'},// meh, 
> -h taken by --help
>   {"Joules",  no_argument,0, 'J'},
> @@ -5014,7 +5026,7 @@ void cmdline(int argc, char **argv)
>  
>   progname = argv[0];
>  
> - while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qST:v",
> + while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qr:ST:v",
>   long_options, _index)) != -1) {
>   switch (opt) {
>   case 'a':
> @@ -5063,6 +5075,15 @@ void cmdline(int argc, char **argv)
>   case 'q':
>   quiet = 1;
>   break;
> + case 'r':
> + iterations = strtod(optarg, NULL);
> +
> + if (iterations <= 0) {
> + fprintf(outf, "iterations %d should be positive 
> number\n",
> + iterations);
> + 

[PATCH][v5] tools/power turbostat: if --iterations, print for specific count of iterations

2018-04-13 Thread Yu Chen
From: Chen Yu 

There's a use case during test to only print specific round of iterations
if --iterations is specified, for example, with this patch applied:

turbostat -i 5 -r 4
will capture 4 samples with 5 seconds interval.

Cc: Len Brown 
Cc: Rafael J Wysocki 
Cc: Artem Bityutskiy 
Cc: Doug Smythies 
Cc: linux...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Chen Yu 
---
 tools/power/x86/turbostat/turbostat.8 |  2 ++
 tools/power/x86/turbostat/turbostat.c | 23 ++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/tools/power/x86/turbostat/turbostat.8 
b/tools/power/x86/turbostat/turbostat.8
index ccf2a69365cc..7452dc42273b 100644
--- a/tools/power/x86/turbostat/turbostat.8
+++ b/tools/power/x86/turbostat/turbostat.8
@@ -64,6 +64,8 @@ name as necessary to disambiguate it from others is 
necessary.  Note that option
 .PP
 \fB--interval seconds\fP overrides the default 5.0 second measurement interval.
 .PP
+\fB--iterations count\fP number of the measurement iterations.
+.PP
 \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.
 .PP
diff --git a/tools/power/x86/turbostat/turbostat.c 
b/tools/power/x86/turbostat/turbostat.c
index bd9c6b31a504..ae9e3d08e3cf 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -48,6 +48,7 @@ char *proc_stat = "/proc/stat";
 FILE *outf;
 int *fd_percpu;
 struct timespec interval_ts = {5, 0};
+int iterations;
 unsigned int debug;
 unsigned int quiet;
 unsigned int sums_need_wide_columns;
@@ -470,6 +471,7 @@ void help(void)
"   {core | package | j,k,l..m,n-p }\n"
"--quietskip decoding system configuration header\n"
"--interval sec Override default 5-second measurement interval\n"
+   "--iterations count number of the measurement iterations\n"
"--help print this help message\n"
"--list list column headers only\n"
"--out file create or truncate \"file\" for all output\n"
@@ -2565,6 +2567,7 @@ void turbostat_loop()
 {
int retval;
int restarted = 0;
+   int done_iters = 0;
 
 restart:
restarted++;
@@ -2581,6 +2584,7 @@ void turbostat_loop()
goto restart;
}
restarted = 0;
+   done_iters = 0;
gettimeofday(_even, (struct timezone *)NULL);
 
while (1) {
@@ -2607,6 +2611,10 @@ void turbostat_loop()
compute_average(EVEN_COUNTERS);
format_all_counters(EVEN_COUNTERS);
flush_output_stdout();
+
+   if (iterations && (++done_iters >= iterations))
+   break;
+
nanosleep(_ts, NULL);
if (snapshot_proc_sysfs_files())
goto restart;
@@ -2626,6 +2634,9 @@ void turbostat_loop()
compute_average(ODD_COUNTERS);
format_all_counters(ODD_COUNTERS);
flush_output_stdout();
+
+   if (iterations && (++done_iters >= iterations))
+   break;
}
 }
 
@@ -4999,6 +5010,7 @@ void cmdline(int argc, char **argv)
{"Dump",no_argument,0, 'D'},
{"debug",   no_argument,0, 'd'},/* 
internal, not documented */
{"interval",required_argument,  0, 'i'},
+   {"iterations",  required_argument,  0, 'r'},
{"help",no_argument,0, 'h'},
{"hide",required_argument,  0, 'H'},// meh, 
-h taken by --help
{"Joules",  no_argument,0, 'J'},
@@ -5014,7 +5026,7 @@ void cmdline(int argc, char **argv)
 
progname = argv[0];
 
-   while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qST:v",
+   while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qr:ST:v",
long_options, _index)) != -1) {
switch (opt) {
case 'a':
@@ -5063,6 +5075,15 @@ void cmdline(int argc, char **argv)
case 'q':
quiet = 1;
break;
+   case 'r':
+   iterations = strtod(optarg, NULL);
+
+   if (iterations <= 0) {
+   fprintf(outf, "iterations %d should be positive 
number\n",
+   iterations);
+   exit(2);
+   }
+   break;
case 's':
parse_show_hide(optarg, SHOW_LIST);
break;
-- 
2.13.6



[PATCH][v5] tools/power turbostat: if --iterations, print for specific count of iterations

2018-04-13 Thread Yu Chen
From: Chen Yu 

There's a use case during test to only print specific round of iterations
if --iterations is specified, for example, with this patch applied:

turbostat -i 5 -r 4
will capture 4 samples with 5 seconds interval.

Cc: Len Brown 
Cc: Rafael J Wysocki 
Cc: Artem Bityutskiy 
Cc: Doug Smythies 
Cc: linux...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Chen Yu 
---
 tools/power/x86/turbostat/turbostat.8 |  2 ++
 tools/power/x86/turbostat/turbostat.c | 23 ++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/tools/power/x86/turbostat/turbostat.8 
b/tools/power/x86/turbostat/turbostat.8
index ccf2a69365cc..7452dc42273b 100644
--- a/tools/power/x86/turbostat/turbostat.8
+++ b/tools/power/x86/turbostat/turbostat.8
@@ -64,6 +64,8 @@ name as necessary to disambiguate it from others is 
necessary.  Note that option
 .PP
 \fB--interval seconds\fP overrides the default 5.0 second measurement interval.
 .PP
+\fB--iterations count\fP number of the measurement iterations.
+.PP
 \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.
 .PP
diff --git a/tools/power/x86/turbostat/turbostat.c 
b/tools/power/x86/turbostat/turbostat.c
index bd9c6b31a504..ae9e3d08e3cf 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -48,6 +48,7 @@ char *proc_stat = "/proc/stat";
 FILE *outf;
 int *fd_percpu;
 struct timespec interval_ts = {5, 0};
+int iterations;
 unsigned int debug;
 unsigned int quiet;
 unsigned int sums_need_wide_columns;
@@ -470,6 +471,7 @@ void help(void)
"   {core | package | j,k,l..m,n-p }\n"
"--quietskip decoding system configuration header\n"
"--interval sec Override default 5-second measurement interval\n"
+   "--iterations count number of the measurement iterations\n"
"--help print this help message\n"
"--list list column headers only\n"
"--out file create or truncate \"file\" for all output\n"
@@ -2565,6 +2567,7 @@ void turbostat_loop()
 {
int retval;
int restarted = 0;
+   int done_iters = 0;
 
 restart:
restarted++;
@@ -2581,6 +2584,7 @@ void turbostat_loop()
goto restart;
}
restarted = 0;
+   done_iters = 0;
gettimeofday(_even, (struct timezone *)NULL);
 
while (1) {
@@ -2607,6 +2611,10 @@ void turbostat_loop()
compute_average(EVEN_COUNTERS);
format_all_counters(EVEN_COUNTERS);
flush_output_stdout();
+
+   if (iterations && (++done_iters >= iterations))
+   break;
+
nanosleep(_ts, NULL);
if (snapshot_proc_sysfs_files())
goto restart;
@@ -2626,6 +2634,9 @@ void turbostat_loop()
compute_average(ODD_COUNTERS);
format_all_counters(ODD_COUNTERS);
flush_output_stdout();
+
+   if (iterations && (++done_iters >= iterations))
+   break;
}
 }
 
@@ -4999,6 +5010,7 @@ void cmdline(int argc, char **argv)
{"Dump",no_argument,0, 'D'},
{"debug",   no_argument,0, 'd'},/* 
internal, not documented */
{"interval",required_argument,  0, 'i'},
+   {"iterations",  required_argument,  0, 'r'},
{"help",no_argument,0, 'h'},
{"hide",required_argument,  0, 'H'},// meh, 
-h taken by --help
{"Joules",  no_argument,0, 'J'},
@@ -5014,7 +5026,7 @@ void cmdline(int argc, char **argv)
 
progname = argv[0];
 
-   while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qST:v",
+   while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qr:ST:v",
long_options, _index)) != -1) {
switch (opt) {
case 'a':
@@ -5063,6 +5075,15 @@ void cmdline(int argc, char **argv)
case 'q':
quiet = 1;
break;
+   case 'r':
+   iterations = strtod(optarg, NULL);
+
+   if (iterations <= 0) {
+   fprintf(outf, "iterations %d should be positive 
number\n",
+   iterations);
+   exit(2);
+   }
+   break;
case 's':
parse_show_hide(optarg, SHOW_LIST);
break;
-- 
2.13.6