perf parse-events: Add parse_events_option() variant that creates evlist
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 27 Apr 2020 16:58:11 +0000 (13:58 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 5 May 2020 19:35:29 +0000 (16:35 -0300)
For the upcoming --switch-output-event option we want to create the side
band event, populate it with the specified events and then, if it is
present multiple times, go on adding to it, then, if the BPF tracking is
required, use the first event to set its attr.bpf_event to get those
PERF_RECORD_BPF_EVENT metadata events too.

Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Song Liu <songliubraving@fb.com>
Link: http://lore.kernel.org/lkml/20200429131106.27974-5-acme@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/parse-events.c
tools/perf/util/parse-events.h

index 10107747b36176f2b49ee7aa65f2607de5645fe6..5795f3a8f71c7768911043017667bbbcd3fbf486 100644 (file)
@@ -2190,6 +2190,29 @@ int parse_events_option(const struct option *opt, const char *str,
        return ret;
 }
 
+int parse_events_option_new_evlist(const struct option *opt, const char *str, int unset)
+{
+       struct evlist **evlistp = opt->value;
+       int ret;
+
+       if (*evlistp == NULL) {
+               *evlistp = evlist__new();
+
+               if (*evlistp == NULL) {
+                       fprintf(stderr, "Not enough memory to create evlist\n");
+                       return -1;
+               }
+       }
+
+       ret = parse_events_option(opt, str, unset);
+       if (ret) {
+               evlist__delete(*evlistp);
+               *evlistp = NULL;
+       }
+
+       return ret;
+}
+
 static int
 foreach_evsel_in_last_glob(struct evlist *evlist,
                           int (*func)(struct evsel *evsel,
index 27596cbd0ba06a73af36557d818dbeb71ef91ed0..6ead9661238c398807ddee5e0b2412c8284731be 100644 (file)
@@ -31,6 +31,7 @@ bool have_tracepoints(struct list_head *evlist);
 const char *event_type(int type);
 
 int parse_events_option(const struct option *opt, const char *str, int unset);
+int parse_events_option_new_evlist(const struct option *opt, const char *str, int unset);
 int parse_events(struct evlist *evlist, const char *str,
                 struct parse_events_error *error);
 int parse_events_terms(struct list_head *terms, const char *str);