perf evsel: Introduce perf_evsel__store_ids()
authorJiri Olsa <jolsa@kernel.org>
Thu, 30 Aug 2018 06:32:16 +0000 (08:32 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 30 Aug 2018 18:52:21 +0000 (15:52 -0300)
Add perf_evsel__store_ids() from stat's store_counter_ids() code to the
evsel class, so that it can be used globally.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180830063252.23729-8-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-stat.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h

index 8291f503d0cc87bd510e5f0e92403c033594870d..45bbd156d496c67c53296298981fe1e7970c4d5c 100644 (file)
@@ -497,37 +497,6 @@ static int perf_stat_synthesize_config(bool is_pipe)
        return 0;
 }
 
-#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
-
-static int __store_counter_ids(struct perf_evsel *counter)
-{
-       int cpu, thread;
-
-       for (cpu = 0; cpu < xyarray__max_x(counter->fd); cpu++) {
-               for (thread = 0; thread < xyarray__max_y(counter->fd);
-                    thread++) {
-                       int fd = FD(counter, cpu, thread);
-
-                       if (perf_evlist__id_add_fd(evsel_list, counter,
-                                                  cpu, thread, fd) < 0)
-                               return -1;
-               }
-       }
-
-       return 0;
-}
-
-static int store_counter_ids(struct perf_evsel *counter)
-{
-       struct cpu_map *cpus = counter->cpus;
-       struct thread_map *threads = counter->threads;
-
-       if (perf_evsel__alloc_id(counter, cpus->nr, threads->nr))
-               return -ENOMEM;
-
-       return __store_counter_ids(counter);
-}
-
 static bool perf_evsel__should_store_id(struct perf_evsel *counter)
 {
        return STAT_RECORD || counter->attr.read_format & PERF_FORMAT_ID;
@@ -658,7 +627,7 @@ try_again:
                        unit_width = l;
 
                if (perf_evsel__should_store_id(counter) &&
-                   store_counter_ids(counter))
+                   perf_evsel__store_ids(counter, evsel_list))
                        return -1;
        }
 
index 1a61628a1c1262c86adff2d76c548985470d9e11..4ec909d57e9c93f48f5eceeecdf2273599e6d843 100644 (file)
@@ -2940,3 +2940,32 @@ struct perf_env *perf_evsel__env(struct perf_evsel *evsel)
                return evsel->evlist->env;
        return NULL;
 }
+
+static int store_evsel_ids(struct perf_evsel *evsel, struct perf_evlist *evlist)
+{
+       int cpu, thread;
+
+       for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) {
+               for (thread = 0; thread < xyarray__max_y(evsel->fd);
+                    thread++) {
+                       int fd = FD(evsel, cpu, thread);
+
+                       if (perf_evlist__id_add_fd(evlist, evsel,
+                                                  cpu, thread, fd) < 0)
+                               return -1;
+               }
+       }
+
+       return 0;
+}
+
+int perf_evsel__store_ids(struct perf_evsel *evsel, struct perf_evlist *evlist)
+{
+       struct cpu_map *cpus = evsel->cpus;
+       struct thread_map *threads = evsel->threads;
+
+       if (perf_evsel__alloc_id(evsel, cpus->nr, threads->nr))
+               return -ENOMEM;
+
+       return store_evsel_ids(evsel, evlist);
+}
index 163c960614d336a62f943e2ccd2e4663e973a0ab..4f8430a85531cf7ecc5828a83d1920b774af4ed3 100644 (file)
@@ -481,4 +481,5 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
 
 struct perf_env *perf_evsel__env(struct perf_evsel *evsel);
 
+int perf_evsel__store_ids(struct perf_evsel *evsel, struct perf_evlist *evlist);
 #endif /* __PERF_EVSEL_H */