diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-05-12 15:25:18 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-05-12 15:25:18 -0400 |
commit | 42ef8a78c1f49f53f29f0f3a6f9a5bcbc653233e (patch) | |
tree | 94e3776eeff15c96c30f32a09d63ad3bcb9fdc84 /tools/perf | |
parent | 08094828b711dd32de57e9e3314935e19db71b3d (diff) |
perf stat: Fallback to user only counters when perf_event_paranoid > 1
After 0161028b7c8a ("perf/core: Change the default paranoia level to 2")
'perf stat' fails for users without CAP_SYS_ADMIN, so just use
'perf_evsel__fallback()' to have the same behaviour as 'perf record',
i.e. set perf_event_attr.exclude_kernel to 1.
Now:
[acme@jouet linux]$ perf stat usleep 1
Performance counter stats for 'usleep 1':
0.352536 task-clock:u (msec) # 0.423 CPUs utilized
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
49 page-faults:u # 0.139 M/sec
309,407 cycles:u # 0.878 GHz
243,791 instructions:u # 0.79 insn per cycle
49,622 branches:u # 140.757 M/sec
3,884 branch-misses:u # 7.83% of all branches
0.000834174 seconds time elapsed
[acme@jouet linux]$
Reported-by: Ingo Molnar <mingo@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-b20jmx4dxt5hpaa9t2rroi0o@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/builtin-stat.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 1f19f2f999c8..307e8a1a003c 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -528,6 +528,7 @@ static int __run_perf_stat(int argc, const char **argv) | |||
528 | perf_evlist__set_leader(evsel_list); | 528 | perf_evlist__set_leader(evsel_list); |
529 | 529 | ||
530 | evlist__for_each(evsel_list, counter) { | 530 | evlist__for_each(evsel_list, counter) { |
531 | try_again: | ||
531 | if (create_perf_stat_counter(counter) < 0) { | 532 | if (create_perf_stat_counter(counter) < 0) { |
532 | /* | 533 | /* |
533 | * PPC returns ENXIO for HW counters until 2.6.37 | 534 | * PPC returns ENXIO for HW counters until 2.6.37 |
@@ -544,7 +545,11 @@ static int __run_perf_stat(int argc, const char **argv) | |||
544 | if ((counter->leader != counter) || | 545 | if ((counter->leader != counter) || |
545 | !(counter->leader->nr_members > 1)) | 546 | !(counter->leader->nr_members > 1)) |
546 | continue; | 547 | continue; |
547 | } | 548 | } else if (perf_evsel__fallback(counter, errno, msg, sizeof(msg))) { |
549 | if (verbose) | ||
550 | ui__warning("%s\n", msg); | ||
551 | goto try_again; | ||
552 | } | ||
548 | 553 | ||
549 | perf_evsel__open_strerror(counter, &target, | 554 | perf_evsel__open_strerror(counter, &target, |
550 | errno, msg, sizeof(msg)); | 555 | errno, msg, sizeof(msg)); |