perf evlist: Add perf_evlist__enable_event_idx()
authorAdrian Hunter <adrian.hunter@intel.com>
Thu, 31 Jul 2014 06:00:56 +0000 (09:00 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 13 Aug 2014 22:23:48 +0000 (19:23 -0300)
Add a function to enable a specific event within a specific perf event
buffer.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
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/r/1406786474-9306-14-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evlist.c
tools/perf/util/evlist.h

index 9d863db3f4b239a84cd4eb9a9c90a4ba01dd62c2..5dcd28c79c6e9728edfc7189d294dc7de7e4a7ae 100644 (file)
@@ -355,6 +355,53 @@ int perf_evlist__enable_event(struct perf_evlist *evlist,
        return 0;
 }
 
+static int perf_evlist__enable_event_cpu(struct perf_evlist *evlist,
+                                        struct perf_evsel *evsel, int cpu)
+{
+       int thread, err;
+       int nr_threads = perf_evlist__nr_threads(evlist, evsel);
+
+       if (!evsel->fd)
+               return -EINVAL;
+
+       for (thread = 0; thread < nr_threads; thread++) {
+               err = ioctl(FD(evsel, cpu, thread),
+                           PERF_EVENT_IOC_ENABLE, 0);
+               if (err)
+                       return err;
+       }
+       return 0;
+}
+
+static int perf_evlist__enable_event_thread(struct perf_evlist *evlist,
+                                           struct perf_evsel *evsel,
+                                           int thread)
+{
+       int cpu, err;
+       int nr_cpus = cpu_map__nr(evlist->cpus);
+
+       if (!evsel->fd)
+               return -EINVAL;
+
+       for (cpu = 0; cpu < nr_cpus; cpu++) {
+               err = ioctl(FD(evsel, cpu, thread), PERF_EVENT_IOC_ENABLE, 0);
+               if (err)
+                       return err;
+       }
+       return 0;
+}
+
+int perf_evlist__enable_event_idx(struct perf_evlist *evlist,
+                                 struct perf_evsel *evsel, int idx)
+{
+       bool per_cpu_mmaps = !cpu_map__empty(evlist->cpus);
+
+       if (per_cpu_mmaps)
+               return perf_evlist__enable_event_cpu(evlist, evsel, idx);
+       else
+               return perf_evlist__enable_event_thread(evlist, evsel, idx);
+}
+
 static int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
 {
        int nr_cpus = cpu_map__nr(evlist->cpus);
index e0084f90c27130b66119f33eb67ff06bc7e3a756..106de53a6a74bc1304e1dc2a638b1f4379723292 100644 (file)
@@ -122,6 +122,8 @@ int perf_evlist__disable_event(struct perf_evlist *evlist,
                               struct perf_evsel *evsel);
 int perf_evlist__enable_event(struct perf_evlist *evlist,
                              struct perf_evsel *evsel);
+int perf_evlist__enable_event_idx(struct perf_evlist *evlist,
+                                 struct perf_evsel *evsel, int idx);
 
 void perf_evlist__set_selected(struct perf_evlist *evlist,
                               struct perf_evsel *evsel);