perf evsel: Introduce append_filter() method
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 4 Jul 2015 15:19:13 +0000 (12:19 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 6 Jul 2015 11:57:51 +0000 (08:57 -0300)
To allow building filters in evsel->filter, that will eventually be
applied via perf_evsel__apply_filter().

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-sjfoes3pycx7nlpmgedca13v@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evsel.c
tools/perf/util/evsel.h

index ae925b9ce6dd9f9693e172ee8246a87f4384f6a1..6cc97f37887dff1499c5c4420f60cb95a5d481b4 100644 (file)
@@ -836,6 +836,23 @@ int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter)
        return -1;
 }
 
+int perf_evsel__append_filter(struct perf_evsel *evsel,
+                             const char *op, const char *filter)
+{
+       char *new_filter;
+
+       if (evsel->filter == NULL)
+               return perf_evsel__set_filter(evsel, filter);
+
+       if (asprintf(&new_filter,"(%s) %s (%s)", evsel->filter, op, filter) > 0) {
+               free(evsel->filter);
+               evsel->filter = new_filter;
+               return 0;
+       }
+
+       return -1;
+}
+
 int perf_evsel__enable(struct perf_evsel *evsel, int ncpus, int nthreads)
 {
        return perf_evsel__run_ioctl(evsel, ncpus, nthreads,
index 8aea4baca080acb231a42319df1a778eedbcdd6c..fe9f3279632b3282902f8d01df1ba3d2f1ddeb78 100644 (file)
@@ -183,6 +183,8 @@ void perf_evsel__set_sample_id(struct perf_evsel *evsel,
                               bool use_sample_identifier);
 
 int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter);
+int perf_evsel__append_filter(struct perf_evsel *evsel,
+                             const char *op, const char *filter);
 int perf_evsel__apply_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
                             const char *filter);
 int perf_evsel__enable(struct perf_evsel *evsel, int ncpus, int nthreads);