path: root/tools/perf/builtin-record.c
diff options
authorWang Nan <>2015-07-10 07:36:10 +0000
committerArnaldo Carvalho de Melo <>2015-07-20 17:49:17 -0300
commit4ba1faa19fa5f415bd69b1d7c366028332468bca (patch)
tree95a83aa5383a812da74eb3cc6abf33ab97236da1 /tools/perf/builtin-record.c
parent15bfd2cc107a9971ac8aeb4b7724ced581a2ed30 (diff)
perf record: Allow filtering perf's pid via --exclude-perf
This patch allows 'perf record' to exclude events issued by perf itself by '--exclude-perf' option. Before this patch, when doing something like: # perf record -a -e syscalls:sys_enter_write <cmd> One could easily get result like this: # /tmp/perf report --stdio ... # Overhead Command Shared Object Symbol # ........ ....... .................. .................... # 99.99% perf [.] __write_nocancel 0.01% ls [.] write 0.01% sshd [.] write ... Where most events are generated by perf itself. A shell trick can be done to filter perf itself out: # cat << EOF > ./tmp > #!/bin/sh > exec perf record -e ... --filter="common_pid != \$\$" -a sleep 10 > EOF # chmod a+x ./tmp # ./tmp However, doing so is user unfriendly. This patch extracts evsel iteration framework introduced by patch 'perf record: Apply filter to all events in a glob matching' into foreach_evsel_in_last_glob(), and makes exclude_perf() function append new filter expression to each evsel selected by a '-e' selector. To avoid losing filters if user pass '--filter' after '--exclude-perf', this patch uses perf_evsel__append_filter() in both case, instead of perf_evsel__set_filter() which removes old filter. As a side effect, now it is possible to use multiple '--filter' option for one selector. They are combinded with '&&'. Signed-off-by: Wang Nan <> Cc: Andi Kleen <> Cc: Brendan Gregg <> Cc: Steven Rostedt <> Cc: Zefan Li <> Cc: Link: Signed-off-by: Arnaldo Carvalho de Melo <>
Diffstat (limited to 'tools/perf/builtin-record.c')
1 files changed, 3 insertions, 0 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 283fe96bdfc1..1932e27c00d8 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -992,6 +992,9 @@ struct option __record_options[] = {
OPT_CALLBACK(0, "filter", &record.evlist, "filter",
"event filter", parse_filter),
+ OPT_CALLBACK_NOOPT(0, "exclude-perf", &record.evlist,
+ NULL, "don't record events from perf itself",
+ exclude_perf),
OPT_STRING('p', "pid", &, "pid",
"record events on existing process id"),
OPT_STRING('t', "tid", &, "tid",