perf evlist: Adopt __set_tracepoint_handlers method from perf_session
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 1 Oct 2019 14:14:26 +0000 (11:14 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 7 Oct 2019 15:22:17 +0000 (12:22 -0300)
It all operates on the evsels in the session's evlist, so move it to the
evlist layer to make it useful to tools not using perf_session, just
evlists, like 'perf trace' in live mode.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-9oc53gnfi53vg82fvolkm85g@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/session.c
tools/perf/util/session.h

index d277a98..b4c43ac 100644 (file)
@@ -186,6 +186,30 @@ void perf_evlist__splice_list_tail(struct evlist *evlist,
        }
 }
 
+int __evlist__set_tracepoints_handlers(struct evlist *evlist,
+                                      const struct evsel_str_handler *assocs, size_t nr_assocs)
+{
+       struct evsel *evsel;
+       size_t i;
+       int err;
+
+       for (i = 0; i < nr_assocs; i++) {
+               // Adding a handler for an event not in this evlist, just ignore it.
+               evsel = perf_evlist__find_tracepoint_by_name(evlist, assocs[i].name);
+               if (evsel == NULL)
+                       continue;
+
+               err = -EEXIST;
+               if (evsel->handler != NULL)
+                       goto out;
+               evsel->handler = assocs[i].handler;
+       }
+
+       err = 0;
+out:
+       return err;
+}
+
 void __perf_evlist__set_leader(struct list_head *list)
 {
        struct evsel *evsel, *leader;
index 7cfe755..00eab94 100644 (file)
@@ -118,6 +118,13 @@ void perf_evlist__stop_sb_thread(struct evlist *evlist);
 int perf_evlist__add_newtp(struct evlist *evlist,
                           const char *sys, const char *name, void *handler);
 
+int __evlist__set_tracepoints_handlers(struct evlist *evlist,
+                                      const struct evsel_str_handler *assocs,
+                                      size_t nr_assocs);
+
+#define evlist__set_tracepoints_handlers(evlist, array) \
+       __evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
+
 void __perf_evlist__set_sample_bit(struct evlist *evlist,
                                   enum perf_event_sample_format bit);
 void __perf_evlist__reset_sample_bit(struct evlist *evlist,
index 061bb4d..6cc32f5 100644 (file)
@@ -2355,35 +2355,6 @@ void perf_session__fprintf_info(struct perf_session *session, FILE *fp,
        fprintf(fp, "# ========\n#\n");
 }
 
-
-int __perf_session__set_tracepoints_handlers(struct perf_session *session,
-                                            const struct evsel_str_handler *assocs,
-                                            size_t nr_assocs)
-{
-       struct evsel *evsel;
-       size_t i;
-       int err;
-
-       for (i = 0; i < nr_assocs; i++) {
-               /*
-                * Adding a handler for an event not in the session,
-                * just ignore it.
-                */
-               evsel = perf_evlist__find_tracepoint_by_name(session->evlist, assocs[i].name);
-               if (evsel == NULL)
-                       continue;
-
-               err = -EEXIST;
-               if (evsel->handler != NULL)
-                       goto out;
-               evsel->handler = assocs[i].handler;
-       }
-
-       err = 0;
-out:
-       return err;
-}
-
 int perf_event__process_id_index(struct perf_session *session,
                                 union perf_event *event)
 {
index b4c9428..8456e1d 100644 (file)
@@ -120,12 +120,8 @@ void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full);
 
 struct evsel_str_handler;
 
-int __perf_session__set_tracepoints_handlers(struct perf_session *session,
-                                            const struct evsel_str_handler *assocs,
-                                            size_t nr_assocs);
-
 #define perf_session__set_tracepoints_handlers(session, array) \
-       __perf_session__set_tracepoints_handlers(session, array, ARRAY_SIZE(array))
+       __evlist__set_tracepoints_handlers(session->evlist, array, ARRAY_SIZE(array))
 
 extern volatile int session_done;