perf stat cleanups
cover perf stat cleanups
Arnaldo:
A few perf-stat cleanups.
David Ahern (3):
perf stat: Fix misleading message when specifying cpu list or system wide perf stat: Don't require a workload when using system wide or CPU options perf stat: Add units to nanosec-based counters
tools/perf/builtin-stat.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.10.1
PATCH 1/3 perf stat: Fix misleading message when specifying cpu list or system wide
perf-stat displays the command run in its summary output which is misleading when using a cpu list or system wide collection.
Before:
perf stat -a -- sleep 1
Performance counter stats for 'sleep 1':
16152.670249 task-clock # 16.132 CPUs utilized
417 context-switches # 0.002 M/sec
7 cpu-migrations # 0.030 K/sec...
After:
perf stat -a -- sleep 1
Performance counter stats for 'system wide':
16206.931120 task-clock # 16.144 CPUs utilized
395 context-switches # 0.002 M/sec
5 cpu-migrations # 0.030 K/sec...
or
perf stat -C1 -- sleep 1
Performance counter stats for 'CPU(s) 1':
1001.669257 task-clock # 1.000 CPUs utilized
4,264 context-switches # 0.004 M/sec
3 cpu-migrations # 0.003 K/sec...
--- tools/perf/builtin-stat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +5 -1
@@ -1115,7 +1115,11 @@ static void print_stat(int argc, const char **argv)if (!csv_output) {fprintf (output,"\n" );fprintf (output," Performance counter stats for " ); -if (!perf_target__has_task (&target)) { +if (target.system_wide) +fprintf (output,"\'system wide" ); +else if (target.cpu_list) +fprintf (output,"\'CPU(s) %s" , target.cpu_list); +else if (!perf_target__has_task (&target)) {fprintf (output,"\'%s" , argv[0 ]);for (i =1 ; i < argc; i++)fprintf (output," %s" , argv[i]);
Signature · 1 line
1.7.10.1
tip-bot for David Ahern
merge bot[tip:perf/core] perf stat: Fix misleading message when specifying cpu list or system wide
perf stat: Fix misleading message when specifying cpu list or system wide
Commit-ID: 62d3b617c02785a4f1fbde8d93ca77a0b33d8454 Gitweb: http://git.kernel.org/tip/62d3b617c02785a4f1fbde8d93ca77a0b33d8454 Author: David Ahern <[email protected]> AuthorDate: Sat, 28 Sep 2013 14:27:58 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 11 Oct 2013 12:17:42 -0300
perf stat: Fix misleading message when specifying cpu list or system wide
The "perf stat" tool displays the command run in its summary output which is misleading when using a cpu list or system wide collection.
Before:
perf stat -a -- sleep 1
Performance counter stats for 'sleep 1':
16152.670249 task-clock # 16.132 CPUs utilized
417 context-switches # 0.002 M/sec
7 cpu-migrations # 0.030 K/sec...
After:
perf stat -a -- sleep 1
Performance counter stats for 'system wide':
16206.931120 task-clock # 16.144 CPUs utilized
395 context-switches # 0.002 M/sec
5 cpu-migrations # 0.030 K/sec...
or
perf stat -C1 -- sleep 1
Performance counter stats for 'CPU(s) 1':
1001.669257 task-clock # 1.000 CPUs utilized
4,264 context-switches # 0.004 M/sec
3 cpu-migrations # 0.003 K/sec...
--- tools/perf/builtin-stat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +5 -1
@@ -1229,7 +1229,11 @@ static void print_stat(int argc, const char **argv)if (!csv_output) {fprintf (output,"\n" );fprintf (output," Performance counter stats for " ); -if (!perf_target__has_task (&target)) { +if (target.system_wide) +fprintf (output,"\'system wide" ); +else if (target.cpu_list) +fprintf (output,"\'CPU(s) %s" , target.cpu_list); +else if (!perf_target__has_task (&target)) {fprintf (output,"\'%s" , argv[0 ]);for (i =1 ; i < argc; i++)fprintf (output," %s" , argv[i]);
PATCH 2/3 perf stat: Don't require a workload when using system wide or CPU options
In reply to David Ahernperf-stat can do system wide counters or one or more cpus. For these options do not require a workload to be specified.
--- tools/perf/builtin-stat.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +3 -1
@@ -1517,8 +1517,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) }else if (big_num_opt ==0 )/* User passed --no-big-num */ big_num = false; -if (!argc && !perf_target__has_task (&target)) +if (!argc && !perf_target__has_task (&target) && + !perf_target__has_cpu (&target))usage_with_options (stat_usage, options); +if (run_count <0 ) {usage_with_options (stat_usage, options); }else if (run_count ==0 ) {
Signature · 1 line
1.7.10.1
Namhyung Kim
maintainerRe: [PATCH 2/3] perf stat: Don't require a workload when using system wide or CPU options
Hi David,
Quoted 19 lines · David Ahern
perf-stat can do system wide counters or one or more cpus. For these options do not require a workload to be specified.
Signed-off-by David Ahern <[email protected]>Cc Ingo Molnar <[email protected]>Cc Frederic Weisbecker <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Cc Stephane Eranian <[email protected]>--- tools/perf/builtin-stat.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/perf/builtin-stat.c +0
-0
tools/perf/builtin-stat.c int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) · line 1521
Quoted 6 lines
tools/perf/builtin-stat.c +2
-1@@ -1517,8 +1517,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) }else if (big_num_opt ==0 )/* User passed --no-big-num */ big_num = false; -if (!argc && !perf_target__has_task (&target)) +if (!argc && !perf_target__has_task (&target) && + !perf_target__has_cpu (&target))
You can use perf_target__none() for this.
Btw I found a bug in setting child_pid (which introduced by me ;) during this review. Will send a fix.
Thanks,
Namhyung
Quoted 5 lines
tools/perf/builtin-stat.c +1
-0usage_with_options (stat_usage, options); +if (run_count <0 ) {usage_with_options (stat_usage, options); }else if (run_count ==0 ) {
Re: [PATCH 2/3] perf stat: Don't require a workload when using system wide or CPU options
Quoted 9 lines · Namhyung Kim
Review int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) · line 1521
Quoted 7 lines
(quoted diff) +2
-1@@ -1517,8 +1517,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) } else if (big_num_opt == 0) /* User passed --no-big-num */ big_num = false; - if (!argc && !perf_target__has_task(&target)) + if (!argc && !perf_target__has_task(&target) && + !perf_target__has_cpu(&target))You can use
perf_target__none()for this.
Indeed. Updated patch attached.
David
Quoted 1 line
From
a7018902283b3cfc5cae8a1876e2c14f3c7c9c7eMon Sep 17 00:00:00 2001
From: David Ahern <[email protected]>
Date: Mon, 30 Sep 2013 07:37:37 -0600
Subject: [PATCH] perf stat: Don't require a workload when using system wide or CPU options -v2
perf-stat can do system wide counters or one or more cpus. For these options do not require a workload to be specified.
v2: use perf_target__none per Namhyung's comment
--- tools/perf/builtin-stat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +2 -1
@@ -1517,8 +1517,9 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) }else if (big_num_opt ==0 )/* User passed --no-big-num */ big_num = false; -if (!argc && !perf_target__has_task (&target)) +if (!argc &&perf_target__none (&target))usage_with_options (stat_usage, options); +if (run_count <0 ) {usage_with_options (stat_usage, options); }else if (run_count ==0 ) {
Signature · 1 line
1.7.10.1
Re: [PATCH 2/3] perf stat: Don't require a workload when using system wide or CPU options
Em Mon, Sep 30, 2013 at 07:40:12AM -0600, David Ahern escreveu:
Quoted 5 lines · Namhyung Kim
Quoted 4 lines
Quoted 4 lines
tools/perf/builtin-stat.c +0
-0@@ -1517,8 +1517,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) }else if (big_num_opt ==0 )/* User passed --no-big-num */ big_num = false;
Quoted 7 lines
Quoted 5 lines
Review int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) · line 1521
Quoted 3 lines
(quoted diff) +2
-1- if (!argc && !perf_target__has_task(&target)) + if (!argc && !perf_target__has_task(&target) && + !perf_target__has_cpu(&target))You can use
perf_target__none()for this.Indeed. Updated patch attached.
Cool patch, applying to acme/perf/core.
While trying it noticed this, that should also be fixed eventually:
[root@zoo ~]# perf stat -c C 0
C: No such file or directory
Performance counter stats for 'C 0':
<not counted> task-clock
<not counted> context-switches
<not counted> cpu-migrations
<SNIP>
- Arnaldo
Re: [PATCH 2/3] perf stat: Don't require a workload when using system wide or CPU options
Quoted 22 lines · Arnaldo Carvalho de Melo
Em Mon, Sep 30, 2013 at 07:40:12AM -0600, David Ahern escreveu:
Quoted 5 lines · Namhyung Kim
Quoted 4 lines
Quoted 4 lines
tools/perf/builtin-stat.c +0
-0@@ -1517,8 +1517,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) }else if (big_num_opt ==0 )/* User passed --no-big-num */ big_num = false;Quoted 7 lines
Quoted 5 lines
Review int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) · line 1521
Quoted 3 lines
(quoted diff) +2
-1- if (!argc && !perf_target__has_task(&target)) + if (!argc && !perf_target__has_task(&target) && + !perf_target__has_cpu(&target))You can use
perf_target__none()for this.Indeed. Updated patch attached.
Cool patch, applying to acme/perf/core.
While trying it noticed this, that should also be fixed eventually:
[root@zoo ~]# perf stat -c C 0
C: No such file or directory
Quoted 6 lines
Performance counter stats for 'C 0':
<not counted> task-clock
<not counted> context-switches
<not counted> cpu-migrations
<SNIP>
Btw., would anyone be interested in adding CPU and node binding options to perf stat?
There's code to do something like that in tools/perf/bench/numa.c:
/* Special option string parsing callbacks: */
OPT_CALLBACK('C', "cpus", NULL, "cpu[,cpu2,...cpuN]",
"bind the first N tasks to these specific cpus (the rest is unbound)",
parse_cpus_opt),
OPT_CALLBACK('M', "memnodes", NULL, "node[,node2,...nodeN]",
"bind the first N tasks to these specific memory nodes (the rest is unbound)",
parse_nodes_opt),Thanks,
Ingo
Re: [PATCH 2/3] perf stat: Don't require a workload when using system wide or CPU options
Em Tue, Oct 08, 2013 at 02:51:13PM +0200, Ingo Molnar escreveu:
Quoted 5 lines
Btw., would anyone be interested in adding CPU and node binding options to perf stat?
There's code to do something like that in
tools/perf/bench/numa.c:
Quoted 7 lines
/* Special option string parsing callbacks: */
OPT_CALLBACK('C', "cpus", NULL, "cpu[,cpu2,...cpuN]",
"bind the first N tasks to these specific cpus (the rest is unbound)",
parse_cpus_opt),
OPT_CALLBACK('M', "memnodes", NULL, "node[,node2,...nodeN]",
"bind the first N tasks to these specific memory nodes (the rest is unbound)",
parse_nodes_opt),As a convenience to using:
taskset -c cpu-list perf stat -C cpu-list workload
?
- Arnaldo
Re: [PATCH 2/3] perf stat: Don't require a workload when using system wide or CPU options
Quoted 14 lines · Arnaldo Carvalho de Melo
Em Tue, Oct 08, 2013 at 02:51:13PM +0200, Ingo Molnar escreveu:
Quoted 5 lines
Btw., would anyone be interested in adding CPU and node binding options to perf stat?
There's code to do something like that in
tools/perf/bench/numa.c:Quoted 7 lines
/* Special option string parsing callbacks: */ OPT_CALLBACK('C', "cpus", NULL, "cpu[,cpu2,...cpuN]", "bind the first N tasks to these specific cpus (the rest is unbound)", parse_cpus_opt), OPT_CALLBACK('M', "memnodes", NULL, "node[,node2,...nodeN]", "bind the first N tasks to these specific memory nodes (the rest is unbound)", parse_nodes_opt),
Quoted 5 lines
As a convenience to using:
taskset -c cpu-list perf stat -C cpu-list workload
?
Yeah, something like that would be handy I think.
Ingo
Re: [PATCH 2/3] perf stat: Don't require a workload when using system wide or CPU options
In reply to Arnaldo Carvalho de MeloQuoted 5 lines · Arnaldo Carvalho de Melo
While trying it noticed this, that should also be fixed eventually:
[root@zoo ~]# perf stat -c C 0
C: No such file or directory
you are missing '-' before the C: perf stat -C 0. The -C = cpus. -c for stat is scale.
David
Re: [PATCH 2/3] perf stat: Don't require a workload when using system wide or CPU options
Em Tue, Oct 08, 2013 at 07:25:39AM -0600, David Ahern escreveu:
Quoted 9 lines · Arnaldo Carvalho de Melo
Quoted 5 lines
While trying it noticed this, that should also be fixed eventually:
[root@zoo ~]# perf stat -c C 0
C: No such file or directoryyou are missing '-' before the C: perf stat -C 0. The -C = cpus. -c for stat is scale.
Nah, I mean:
[acme@zoo linux]$ perf stat non-existent-proggie
non-existent-proggie: No such file or directory
Performance counter stats for 'non-existent-proggie':
<not counted> task-clock
<not counted> context-switches
<not counted> cpu-migrations
<not counted> page-faults
<not counted> cycles
<not counted> stalled-cycles-frontend
<not supported> stalled-cycles-backend
<not counted> instructions
<not counted> branches
<not counted> branch-misses
0.001823577 seconds time elapsed
[acme@zoo linux]$
Why should we report all those counters for something that wasn't found in PATH?
We either report just the first line, with the errno, or that and the last, with how long it took to try to execute it, but that probably shouldn't be printed, as it is supposed to be how long the workload ran, right?
- Arnaldo
Re: [PATCH 2/3] perf stat: Don't require a workload when using system wide or CPU options
Quoted 2 lines · Arnaldo Carvalho de Melo
[acme@zoo linux]$ perf stat non-existent-proggie
non-existent-proggie: No such file or directory
ok. so this is a different error. need to detect the workload does not exist.
Quoted 7 lines
Why should we report all those counters for something that wasn't found in PATH?
We either report just the first line, with the errno, or that and the last, with how long it took to try to execute it, but that probably shouldn't be printed, as it is supposed to be how long the workload ran, right?
Right. need to feed/detect the exec failure back to the parent.
David
tip-bot for David Ahern
merge bot[tip:perf/core] perf stat: Don' t require a workload when using system wide or CPU options
In reply to David Ahernperf stat: Don't require a workload when using system wide or CPU options
Commit-ID: ac3063bd4725689f39d7a23fdfca2e034c73dcac Gitweb: http://git.kernel.org/tip/ac3063bd4725689f39d7a23fdfca2e034c73dcac Author: David Ahern <[email protected]> AuthorDate: Mon, 30 Sep 2013 07:37:37 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 11 Oct 2013 12:17:44 -0300
perf stat: Don't require a workload when using system wide or CPU options
The "perf stat" command can do system wide counters or one or more cpus. For these options do not require a workload to be specified.
v2: use perf_target__none per Namhyung's comment.
--- tools/perf/builtin-stat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +2 -1
@@ -1659,8 +1659,9 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) }else if (big_num_opt ==0 )/* User passed --no-big-num */ big_num = false; -if (!argc && !perf_target__has_task (&target)) +if (!argc &&perf_target__none (&target))usage_with_options (stat_usage, options); +if (run_count <0 ) {usage_with_options (stat_usage, options); }else if (run_count ==0 ) {
PATCH 3/3 perf stat: Add units to nanosec-based counters
In reply to David AhernIngo pointed out that the task-clock counter should have the units explicitly stated since it is not a counter.
Before:
perf stat -a -- sleep 1
Performance counter stats for 'sleep 1':
16186.874834 task-clock # 16.154 CPUs utilized
...
After:
perf stat -a -- sleep 1
Performance counter stats for 'system wide':
16146.402138 task-clock (msec) # 16.125 CPUs utilized
...
--- tools/perf/builtin-stat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
@@ -628,10 +628,13 @@ static void nsec_printout(int cpu, int nr, struct perf_evsel *evsel, double avg) {double msecs = avg /1e6 ;const char *fmt = csv_output ?"%.6f%s%s" :"%18.6f%s%-25s" ; +char name[25 ];aggr_printout (evsel, cpu, nr); -fprintf (output, fmt, msecs, csv_sep,perf_evsel__name (evsel)); +scnprintf (name,sizeof (name),"%s%s" , +perf_evsel__name (evsel), csv_output ?"" :" (msec)" ); +fprintf (output, fmt, msecs, csv_sep, name);if (evsel->cgrp)fprintf (output,"%s%s" , csv_sep, evsel->cgrp->name);
Signature · 1 line
1.7.10.1
tip-bot for David Ahern
merge bot[tip:perf/core] perf stat: Add units to nanosec-based counters
perf stat: Add units to nanosec-based counters
Commit-ID: 4bbe5a61f29b13437a6a16467328d3bae8fce9e7 Gitweb: http://git.kernel.org/tip/4bbe5a61f29b13437a6a16467328d3bae8fce9e7 Author: David Ahern <[email protected]> AuthorDate: Sat, 28 Sep 2013 14:28:00 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 11 Oct 2013 12:17:46 -0300
perf stat: Add units to nanosec-based counters
Ingo pointed out that the task-clock counter should have the units explicitly stated since it is not a counter.
Before:
perf stat -a -- sleep 1
Performance counter stats for 'sleep 1':
16186.874834 task-clock # 16.154 CPUs utilized
...
After:
perf stat -a -- sleep 1
Performance counter stats for 'system wide':
16146.402138 task-clock (msec) # 16.125 CPUs utilized
...
--- tools/perf/builtin-stat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
@@ -706,10 +706,13 @@ static void nsec_printout(int cpu, int nr, struct perf_evsel *evsel, double avg) {double msecs = avg /1e6 ;const char *fmt = csv_output ?"%.6f%s%s" :"%18.6f%s%-25s" ; +char name[25 ];aggr_printout (evsel, cpu, nr); -fprintf (output, fmt, msecs, csv_sep,perf_evsel__name (evsel)); +scnprintf (name,sizeof (name),"%s%s" , +perf_evsel__name (evsel), csv_output ?"" :" (msec)" ); +fprintf (output, fmt, msecs, csv_sep, name);if (evsel->cgrp)fprintf (output,"%s%s" , csv_sep, evsel->cgrp->name);
ping
Quoted 12 lines · David Ahern
Arnaldo:
A few perf-stat cleanups.
David Ahern (3):
perf stat: Fix misleading message when specifying cpu list or system wide perf stat: Don't require a workload when using system wide or CPU options perf stat: Add units to nanosec-based counterstools/perf/builtin-stat.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)