aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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",