diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-03-22 12:10:28 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-03-22 13:47:35 -0400 |
commit | 084ab9f862416b2ddb4bb9804884de19bf09774d (patch) | |
tree | 3e6bf779f4e7f75da57a381fab2aa9f60316fb01 /tools/perf/builtin-stat.c | |
parent | ca721e45b39209415d2288dbac3667b26d9d1def (diff) |
perf stat: Better report failure to collect system wide stats
Before:
[acme@doppio linux-2.6-tip]$ perf stat -a sleep 1s
Performance counter stats for 'sleep 1s':
<not counted> task-clock-msecs
<not counted> context-switches
<not counted> CPU-migrations
<not counted> page-faults
<not counted> cycles
<not counted> instructions
<not counted> branches
<not counted> branch-misses
<not counted> cache-references
<not counted> cache-misses
1.016998463 seconds time elapsed
[acme@doppio linux-2.6-tip]$
Now:
[acme@doppio linux-2.6-tip]$ perf stat -a sleep 1s
No permission to collect system-wide stats.
Consider tweaking /proc/sys/kernel/perf_event_paranoid.
[acme@doppio linux-2.6-tip]$
Reported-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1269274229-20442-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/builtin-stat.c')
-rw-r--r-- | tools/perf/builtin-stat.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index c92f90ff5a9f..1036ca739e6f 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -144,10 +144,11 @@ struct stats runtime_branches_stats; | |||
144 | #define ERR_PERF_OPEN \ | 144 | #define ERR_PERF_OPEN \ |
145 | "Error: counter %d, sys_perf_event_open() syscall returned with %d (%s)\n" | 145 | "Error: counter %d, sys_perf_event_open() syscall returned with %d (%s)\n" |
146 | 146 | ||
147 | static void create_perf_stat_counter(int counter) | 147 | static int create_perf_stat_counter(int counter) |
148 | { | 148 | { |
149 | struct perf_event_attr *attr = attrs + counter; | 149 | struct perf_event_attr *attr = attrs + counter; |
150 | int thread; | 150 | int thread; |
151 | int ncreated = 0; | ||
151 | 152 | ||
152 | if (scale) | 153 | if (scale) |
153 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | | 154 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | |
@@ -159,9 +160,11 @@ static void create_perf_stat_counter(int counter) | |||
159 | for (cpu = 0; cpu < nr_cpus; cpu++) { | 160 | for (cpu = 0; cpu < nr_cpus; cpu++) { |
160 | fd[cpu][counter][0] = sys_perf_event_open(attr, | 161 | fd[cpu][counter][0] = sys_perf_event_open(attr, |
161 | -1, cpumap[cpu], -1, 0); | 162 | -1, cpumap[cpu], -1, 0); |
162 | if (fd[cpu][counter][0] < 0 && verbose) | 163 | if (fd[cpu][counter][0] < 0) |
163 | fprintf(stderr, ERR_PERF_OPEN, counter, | 164 | pr_debug(ERR_PERF_OPEN, counter, |
164 | fd[cpu][counter][0], strerror(errno)); | 165 | fd[cpu][counter][0], strerror(errno)); |
166 | else | ||
167 | ++ncreated; | ||
165 | } | 168 | } |
166 | } else { | 169 | } else { |
167 | attr->inherit = inherit; | 170 | attr->inherit = inherit; |
@@ -172,12 +175,16 @@ static void create_perf_stat_counter(int counter) | |||
172 | for (thread = 0; thread < thread_num; thread++) { | 175 | for (thread = 0; thread < thread_num; thread++) { |
173 | fd[0][counter][thread] = sys_perf_event_open(attr, | 176 | fd[0][counter][thread] = sys_perf_event_open(attr, |
174 | all_tids[thread], -1, -1, 0); | 177 | all_tids[thread], -1, -1, 0); |
175 | if (fd[0][counter][thread] < 0 && verbose) | 178 | if (fd[0][counter][thread] < 0) |
176 | fprintf(stderr, ERR_PERF_OPEN, counter, | 179 | pr_debug(ERR_PERF_OPEN, counter, |
177 | fd[0][counter][thread], | 180 | fd[0][counter][thread], |
178 | strerror(errno)); | 181 | strerror(errno)); |
182 | else | ||
183 | ++ncreated; | ||
179 | } | 184 | } |
180 | } | 185 | } |
186 | |||
187 | return ncreated; | ||
181 | } | 188 | } |
182 | 189 | ||
183 | /* | 190 | /* |
@@ -264,7 +271,7 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
264 | { | 271 | { |
265 | unsigned long long t0, t1; | 272 | unsigned long long t0, t1; |
266 | int status = 0; | 273 | int status = 0; |
267 | int counter; | 274 | int counter, ncreated = 0; |
268 | int child_ready_pipe[2], go_pipe[2]; | 275 | int child_ready_pipe[2], go_pipe[2]; |
269 | const bool forks = (argc > 0); | 276 | const bool forks = (argc > 0); |
270 | char buf; | 277 | char buf; |
@@ -324,7 +331,16 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
324 | } | 331 | } |
325 | 332 | ||
326 | for (counter = 0; counter < nr_counters; counter++) | 333 | for (counter = 0; counter < nr_counters; counter++) |
327 | create_perf_stat_counter(counter); | 334 | ncreated += create_perf_stat_counter(counter); |
335 | |||
336 | if (ncreated == 0) { | ||
337 | pr_err("No permission to collect %sstats.\n" | ||
338 | "Consider tweaking /proc/sys/kernel/perf_event_paranoid.\n", | ||
339 | system_wide ? "system-wide " : ""); | ||
340 | if (child_pid != -1) | ||
341 | kill(child_pid, SIGTERM); | ||
342 | return -1; | ||
343 | } | ||
328 | 344 | ||
329 | /* | 345 | /* |
330 | * Enable counters and exec the command: | 346 | * Enable counters and exec the command: |
@@ -587,7 +603,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) | |||
587 | status = run_perf_stat(argc, argv); | 603 | status = run_perf_stat(argc, argv); |
588 | } | 604 | } |
589 | 605 | ||
590 | print_stat(argc, argv); | 606 | if (status != -1) |
607 | print_stat(argc, argv); | ||
591 | 608 | ||
592 | return status; | 609 | return status; |
593 | } | 610 | } |