perf evlist: Introduce set_filter() method
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 26 Sep 2012 18:07:39 +0000 (15:07 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 26 Sep 2012 18:08:43 +0000 (15:08 -0300)
To apply a filter to all the evsels in an evlist.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-v9x3q9rv4caxtox7wtjpchq5@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evlist.c
tools/perf/util/evlist.h
tools/perf/util/evsel.c
tools/perf/util/evsel.h

index c3ec7878985baa9cf84058a39bb9a7d375afded5..ae89686102f4a7224d0f425fb26ad3712f17c616 100644 (file)
@@ -668,30 +668,37 @@ void perf_evlist__delete_maps(struct perf_evlist *evlist)
 
 int perf_evlist__apply_filters(struct perf_evlist *evlist)
 {
-       const struct thread_map *threads = evlist->threads;
-       const struct cpu_map *cpus = evlist->cpus;
        struct perf_evsel *evsel;
-       char *filter;
-       int thread;
-       int cpu;
-       int err;
-       int fd;
+       int err = 0;
+       const int ncpus = cpu_map__nr(evlist->cpus),
+                 nthreads = evlist->threads->nr;
 
        list_for_each_entry(evsel, &evlist->entries, node) {
-               filter = evsel->filter;
-               if (!filter)
+               if (evsel->filter == NULL)
                        continue;
-               for (cpu = 0; cpu < cpus->nr; cpu++) {
-                       for (thread = 0; thread < threads->nr; thread++) {
-                               fd = FD(evsel, cpu, thread);
-                               err = ioctl(fd, PERF_EVENT_IOC_SET_FILTER, filter);
-                               if (err)
-                                       return err;
-                       }
-               }
+
+               err = perf_evsel__set_filter(evsel, ncpus, nthreads, evsel->filter);
+               if (err)
+                       break;
        }
 
-       return 0;
+       return err;
+}
+
+int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter)
+{
+       struct perf_evsel *evsel;
+       int err = 0;
+       const int ncpus = cpu_map__nr(evlist->cpus),
+                 nthreads = evlist->threads->nr;
+
+       list_for_each_entry(evsel, &evlist->entries, node) {
+               err = perf_evsel__set_filter(evsel, ncpus, nthreads, filter);
+               if (err)
+                       break;
+       }
+
+       return err;
 }
 
 bool perf_evlist__valid_sample_type(struct perf_evlist *evlist)
index 25e49e02810a1f8a0ecc95eac366ed8db2ae9efa..3f1fb66be02203e925d8f01b38338d90b66d344a 100644 (file)
@@ -72,6 +72,8 @@ int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist,
 #define perf_evlist__set_tracepoints_handlers_array(evlist, array) \
        perf_evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
 
+int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter);
+
 struct perf_evsel *
 perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id);
 
index c78e42ab97703d42dbae609871e61b9a7f0dbbe0..6022daaa7417b0efd9c0e0795d8565fb4ef82a63 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));
index 60d28853748e0ea20f87ec9def42cee9254bd8c5..25043ff17fd7ad6799563f97fd32b93b0485503a 100644 (file)
@@ -115,6 +115,9 @@ void perf_evsel__free_fd(struct perf_evsel *evsel);
 void perf_evsel__free_id(struct perf_evsel *evsel);
 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
 
+int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
+                          const char *filter);
+
 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
                             struct cpu_map *cpus);
 int perf_evsel__open_per_thread(struct perf_evsel *evsel,