perf evlist: Introduce set_filter() method
[cascardo/linux.git] / tools / perf / util / evsel.c
index c78e42a..6022daa 100644 (file)
@@ -505,6 +505,24 @@ int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
        return evsel->fd != NULL ? 0 : -ENOMEM;
 }
 
+int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
+                          const char *filter)
+{
+       int cpu, thread;
+
+       for (cpu = 0; cpu < ncpus; cpu++) {
+               for (thread = 0; thread < nthreads; thread++) {
+                       int fd = FD(evsel, cpu, thread),
+                           err = ioctl(fd, PERF_EVENT_IOC_SET_FILTER, filter);
+
+                       if (err)
+                               return err;
+               }
+       }
+
+       return 0;
+}
+
 int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads)
 {
        evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id));