aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2015-02-21 14:36:52 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-02-22 20:21:52 -0500
commitf078c3852c7367b78552be432bc24ca93ebbd4cf (patch)
tree20f27a357f6cf92c8679537df3e08c011b8b8c41 /tools
parentbe199ada4fbbe5f742f854dce8e455cfcfcf7adb (diff)
perf trace: Introduce --filter-pids
When tracing in X we get event loops due to the tracing activity, i.e. updates to a gnome-terminal that generate syscalls for X.org, etc. To get a more useful view of what is happening, syscall wise, system wide, we need to filter those, like in: # ps ax|egrep '981|2296|1519' | grep -v egrep 981 tty1 Ss+ 5:40 /usr/bin/Xorg :0 -background none ... 1519 ? Sl 2:22 /usr/bin/gnome-shell 2296 ? Sl 4:16 /usr/libexec/gnome-terminal-server # # trace -e write --filter-pids 981,2296,1519 0.385 ( 0.021 ms): goa-daemon/2061 write(fd: 1</dev/null>, buf: 0x7fbeb017b000, count: 136) = 136 0.922 ( 0.014 ms): goa-daemon/2061 write(fd: 1</dev/null>, buf: 0x7fbeb017b000, count: 140) = 140 5006.525 ( 0.029 ms): goa-daemon/2061 write(fd: 1</dev/null>, buf: 0x7fbeb017b000, count: 136) = 136 5007.235 ( 0.023 ms): goa-daemon/2061 write(fd: 1</dev/null>, buf: 0x7fbeb017b000, count: 140) = 140 5177.646 ( 0.018 ms): rtkit-daemon/782 write(fd: 5<anon_inode:[eventfd]>, buf: 0x7f7eea70be88, count: 8) = 8 8314.497 ( 0.004 ms): gsd-locate-poi/2084 write(fd: 5<anon_inode:[eventfd]>, buf: 0x7fffe96af7b0, count: 8) = 8 8314.518 ( 0.002 ms): gsd-locate-poi/2084 write(fd: 5<anon_inode:[eventfd]>, buf: 0x7fffe96af0e0, count: 8) = 8 ^C# When this option is used the tracer pid is also filtered. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: David Ahern <dsahern@gmail.com> Cc: Don Zickus <dzickus@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-f5qmiyy7c0uxdm21ncatpeek@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/Documentation/perf-trace.txt3
-rw-r--r--tools/perf/builtin-trace.c49
2 files changed, 50 insertions, 2 deletions
diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt
index 7e1b1f2bb83c..d6778e66fa92 100644
--- a/tools/perf/Documentation/perf-trace.txt
+++ b/tools/perf/Documentation/perf-trace.txt
@@ -55,6 +55,9 @@ OPTIONS
55--uid=:: 55--uid=::
56 Record events in threads owned by uid. Name or number. 56 Record events in threads owned by uid. Name or number.
57 57
58--filter-pids=::
59 Filter out events for these pids and for 'trace' itself (comma separated list).
60
58-v:: 61-v::
59--verbose=:: 62--verbose=::
60 Verbosity level. 63 Verbosity level.
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index cb33e4c8821a..60ccfd52189d 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1229,6 +1229,10 @@ struct trace {
1229 const char *last_vfs_getname; 1229 const char *last_vfs_getname;
1230 struct intlist *tid_list; 1230 struct intlist *tid_list;
1231 struct intlist *pid_list; 1231 struct intlist *pid_list;
1232 struct {
1233 size_t nr;
1234 pid_t *entries;
1235 } filter_pids;
1232 double duration_filter; 1236 double duration_filter;
1233 double runtime_ms; 1237 double runtime_ms;
1234 struct { 1238 struct {
@@ -2157,8 +2161,15 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
2157 * workload was, and in that case we will fill in the thread_map when 2161 * workload was, and in that case we will fill in the thread_map when
2158 * we fork the workload in perf_evlist__prepare_workload. 2162 * we fork the workload in perf_evlist__prepare_workload.
2159 */ 2163 */
2160 if (evlist->threads->map[0] == -1) 2164 if (trace->filter_pids.nr > 0)
2161 perf_evlist__set_filter_pid(evlist, getpid()); 2165 err = perf_evlist__set_filter_pids(evlist, trace->filter_pids.nr, trace->filter_pids.entries);
2166 else if (evlist->threads->map[0] == -1)
2167 err = perf_evlist__set_filter_pid(evlist, getpid());
2168
2169 if (err < 0) {
2170 printf("err=%d,%s\n", -err, strerror(-err));
2171 exit(1);
2172 }
2162 2173
2163 err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false); 2174 err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false);
2164 if (err < 0) 2175 if (err < 0)
@@ -2491,6 +2502,38 @@ static int trace__set_duration(const struct option *opt, const char *str,
2491 return 0; 2502 return 0;
2492} 2503}
2493 2504
2505static int trace__set_filter_pids(const struct option *opt, const char *str,
2506 int unset __maybe_unused)
2507{
2508 int ret = -1;
2509 size_t i;
2510 struct trace *trace = opt->value;
2511 /*
2512 * FIXME: introduce a intarray class, plain parse csv and create a
2513 * { int nr, int entries[] } struct...
2514 */
2515 struct intlist *list = intlist__new(str);
2516
2517 if (list == NULL)
2518 return -1;
2519
2520 i = trace->filter_pids.nr = intlist__nr_entries(list) + 1;
2521 trace->filter_pids.entries = calloc(i, sizeof(pid_t));
2522
2523 if (trace->filter_pids.entries == NULL)
2524 goto out;
2525
2526 trace->filter_pids.entries[0] = getpid();
2527
2528 for (i = 1; i < trace->filter_pids.nr; ++i)
2529 trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i;
2530
2531 intlist__delete(list);
2532 ret = 0;
2533out:
2534 return ret;
2535}
2536
2494static int trace__open_output(struct trace *trace, const char *filename) 2537static int trace__open_output(struct trace *trace, const char *filename)
2495{ 2538{
2496 struct stat st; 2539 struct stat st;
@@ -2581,6 +2624,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
2581 "trace events on existing process id"), 2624 "trace events on existing process id"),
2582 OPT_STRING('t', "tid", &trace.opts.target.tid, "tid", 2625 OPT_STRING('t', "tid", &trace.opts.target.tid, "tid",
2583 "trace events on existing thread id"), 2626 "trace events on existing thread id"),
2627 OPT_CALLBACK(0, "filter-pids", &trace, "float",
2628 "show only events with duration > N.M ms", trace__set_filter_pids),
2584 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide, 2629 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide,
2585 "system-wide collection from all CPUs"), 2630 "system-wide collection from all CPUs"),
2586 OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu", 2631 OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu",