path: root/tools/perf/builtin-trace.c
diff options
authorArnaldo Carvalho de Melo <>2015-07-03 17:42:03 -0300
committerArnaldo Carvalho de Melo <>2015-07-06 10:46:36 -0300
commit94ad89bc8a61b79c416c180c51b3e61ac16f6124 (patch)
tree873b6c26dbb010800c2f04e806126ab5588b50ec /tools/perf/builtin-trace.c
parent12467ae4e37aab5e263cc9ab6b6909ae0588844c (diff)
perf evlist: Make perf_evlist__set_filter use perf_evsel__set_filter
Instead of calling perf_evsel__apply_filter straight away, so that we can, in the next patches, expand the filter with more conditions before actually calling the ioctl to pass the end result filter to the kernel. Now we need to call perf_evlist__apply_filters() after the filter is completely setup, i.e. do the ioctl calls. The perf_evlist__apply_filters() method was already in place, because that is the model for the other tools that receives filters in the command line: go on setting then in the evsel->filter and only at the end, after parsing the whole command line, apply them. We get, as a bonus, a more expressive message that states which event, if any, failed to have the filter applied to, with an error message stating what happened. Cc: Adrian Hunter <> Cc: Borislav Petkov <> Cc: David Ahern <> Cc: Don Zickus <> Cc: Frederic Weisbecker <> Cc: Jiri Olsa <> Cc: Namhyung Kim <> Cc: Stephane Eranian <> Link: Signed-off-by: Arnaldo Carvalho de Melo <>
Diffstat (limited to 'tools/perf/builtin-trace.c')
1 files changed, 14 insertions, 4 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index b10608680c01..c02b65a72410 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2314,6 +2314,7 @@ out_delete_sys_enter:
static int trace__run(struct trace *trace, int argc, const char **argv)
struct perf_evlist *evlist = trace->evlist;
+ struct perf_evsel *evsel;
int err = -1, i;
unsigned long before;
const bool forks = argc > 0;
@@ -2382,10 +2383,12 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
else if (thread_map__pid(evlist->threads, 0) == -1)
err = perf_evlist__set_filter_pid(evlist, getpid());
- if (err < 0) {
- printf("err=%d,%s\n", -err, strerror(-err));
- exit(1);
- }
+ if (err < 0)
+ goto out_error_mem;
+ err = perf_evlist__apply_filters(evlist, &evsel);
+ if (err < 0)
+ goto out_error_apply_filters;
err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false);
if (err < 0)
@@ -2488,6 +2491,13 @@ out_error_open:
fprintf(trace->output, "%s\n", errbuf);
goto out_delete_evlist;
+ fprintf(trace->output,
+ "Failed to set filter \"%s\" on event %s with %d (%s)\n",
+ evsel->filter, perf_evsel__name(evsel), errno,
+ strerror_r(errno, errbuf, sizeof(errbuf)));
+ goto out_delete_evlist;
fprintf(trace->output, "Not enough memory to run!\n");