perf evsel: Introduce set_filter method
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 3 Jul 2015 20:05:50 +0000 (17:05 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 6 Jul 2015 13:46:36 +0000 (10:46 -0300)
Replaces existing filter string with the one provided.

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-jst49z83li0yx3g18o54u51a@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/parse-events.c

index 667677495fb03fe20d6fa870ef616850e645f793..ae925b9ce6dd9f9693e172ee8246a87f4384f6a1 100644 (file)
@@ -823,6 +823,19 @@ int perf_evsel__apply_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
                                     (void *)filter);
 }
 
+int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter)
+{
+       char *new_filter = strdup(filter);
+
+       if (new_filter != NULL) {
+               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 a3ebb83d767e001b73f4b72c8757d6d26bf5f4b5..8aea4baca080acb231a42319df1a778eedbcdd6c 100644 (file)
@@ -182,6 +182,7 @@ void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel,
 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__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);
index 09f8d23571082ef6698f37eefcd8f9d9815f1fdc..a71eeb279ed2a6551080f427beb805cc31c1c5a1 100644 (file)
@@ -1177,8 +1177,7 @@ int parse_filter(const struct option *opt, const char *str,
                return -1;
        }
 
-       last->filter = strdup(str);
-       if (last->filter == NULL) {
+       if (perf_evsel__set_filter(last, str) < 0) {
                fprintf(stderr, "not enough memory to hold filter string\n");
                return -1;
        }