perf tools: Add support for event post configuration
authorJiri Olsa <jolsa@kernel.org>
Wed, 29 Jul 2015 09:42:10 +0000 (05:42 -0400)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 29 Jul 2015 19:15:57 +0000 (16:15 -0300)
Add support to overload any global settings for event and force user
specified term value. It will be useful for new time and backtrace
terms.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1438162936-59698-2-git-send-email-kan.liang@intel.com
Signed-off-by: Kan Liang <kan.liang@intel.com>
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 71f6905c7cb9f5ef85e4b19e290082f752d35756..048d61dde3f6a9d779d889956992e23e5b03fb54 100644 (file)
@@ -207,6 +207,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
        evsel->unit        = "";
        evsel->scale       = 1.0;
        INIT_LIST_HEAD(&evsel->node);
+       INIT_LIST_HEAD(&evsel->config_terms);
        perf_evsel__object.init(evsel);
        evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
        perf_evsel__calc_id_pos(evsel);
@@ -586,6 +587,19 @@ perf_evsel__config_callgraph(struct perf_evsel *evsel,
        }
 }
 
+static void apply_config_terms(struct perf_event_attr *attr __maybe_unused,
+                              struct list_head *config_terms)
+{
+       struct perf_evsel_config_term *term;
+
+       list_for_each_entry(term, config_terms, list) {
+               switch (term->type) {
+               default:
+                       break;
+               }
+       }
+}
+
 /*
  * The enable_on_exec/disabled value strategy:
  *
@@ -777,6 +791,12 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)
                attr->use_clockid = 1;
                attr->clockid = opts->clockid;
        }
+
+       /*
+        * Apply event specific term settings,
+        * it overloads any global configuration.
+        */
+       apply_config_terms(attr, &evsel->config_terms);
 }
 
 static int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
@@ -900,6 +920,16 @@ static void perf_evsel__free_id(struct perf_evsel *evsel)
        zfree(&evsel->id);
 }
 
+static void perf_evsel__free_config_terms(struct perf_evsel *evsel)
+{
+       struct perf_evsel_config_term *term, *h;
+
+       list_for_each_entry_safe(term, h, &evsel->config_terms, list) {
+               list_del(&term->list);
+               free(term);
+       }
+}
+
 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
 {
        int cpu, thread;
@@ -919,6 +949,7 @@ void perf_evsel__exit(struct perf_evsel *evsel)
        assert(list_empty(&evsel->node));
        perf_evsel__free_fd(evsel);
        perf_evsel__free_id(evsel);
+       perf_evsel__free_config_terms(evsel);
        close_cgroup(evsel->cgrp);
        cpu_map__put(evsel->cpus);
        thread_map__put(evsel->threads);
index 1fc263a80d91669dcc854bcbac0fb1bccaf0e6a1..033981974fd2d14c37ce51fdba957077ab4ff710 100644 (file)
@@ -31,6 +31,24 @@ struct perf_sample_id {
 
 struct cgroup_sel;
 
+/*
+ * The 'struct perf_evsel_config_term' is used to pass event
+ * specific configuration data to perf_evsel__config routine.
+ * It is allocated within event parsing and attached to
+ * perf_evsel::config_terms list head.
+*/
+enum {
+       PERF_EVSEL__CONFIG_TERM_MAX,
+};
+
+struct perf_evsel_config_term {
+       struct list_head        list;
+       int     type;
+       union {
+               u64     period;
+       } val;
+};
+
 /** struct perf_evsel - event selector
  *
  * @name - Can be set to retain the original event name passed by the user,
@@ -87,6 +105,7 @@ struct perf_evsel {
        struct perf_evsel       *leader;
        char                    *group_name;
        bool                    cmdline_group_boundary;
+       struct list_head        config_terms;
 };
 
 union u64_swap {
index 4f807fc1b14a4783d5be8ec3e94b17b2253b3ab4..3271d134e8c11180a3cd7ad663c490ac465886f9 100644 (file)
@@ -276,7 +276,8 @@ const char *event_type(int type)
 static struct perf_evsel *
 __add_event(struct list_head *list, int *idx,
            struct perf_event_attr *attr,
-           char *name, struct cpu_map *cpus)
+           char *name, struct cpu_map *cpus,
+           struct list_head *config_terms)
 {
        struct perf_evsel *evsel;
 
@@ -291,14 +292,19 @@ __add_event(struct list_head *list, int *idx,
 
        if (name)
                evsel->name = strdup(name);
+
+       if (config_terms)
+               list_splice(config_terms, &evsel->config_terms);
+
        list_add_tail(&evsel->node, list);
        return evsel;
 }
 
 static int add_event(struct list_head *list, int *idx,
-                    struct perf_event_attr *attr, char *name)
+                    struct perf_event_attr *attr, char *name,
+                    struct list_head *config_terms)
 {
-       return __add_event(list, idx, attr, name, NULL) ? 0 : -ENOMEM;
+       return __add_event(list, idx, attr, name, NULL, config_terms) ? 0 : -ENOMEM;
 }
 
 static int parse_aliases(char *str, const char *names[][PERF_EVSEL__MAX_ALIASES], int size)
@@ -377,7 +383,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
        memset(&attr, 0, sizeof(attr));
        attr.config = cache_type | (cache_op << 8) | (cache_result << 16);
        attr.type = PERF_TYPE_HW_CACHE;
-       return add_event(list, idx, &attr, name);
+       return add_event(list, idx, &attr, name, NULL);
 }
 
 static int add_tracepoint(struct list_head *list, int *idx,
@@ -539,7 +545,7 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx,
        attr.type = PERF_TYPE_BREAKPOINT;
        attr.sample_period = 1;
 
-       return add_event(list, idx, &attr, NULL);
+       return add_event(list, idx, &attr, NULL, NULL);
 }
 
 static int check_type_val(struct parse_events_term *term,
@@ -622,22 +628,56 @@ static int config_attr(struct perf_event_attr *attr,
        return 0;
 }
 
+static int get_config_terms(struct list_head *head_config,
+                           struct list_head *head_terms __maybe_unused)
+{
+#define ADD_CONFIG_TERM(__type, __name, __val)                 \
+do {                                                           \
+       struct perf_evsel_config_term *__t;                     \
+                                                               \
+       __t = zalloc(sizeof(*__t));                             \
+       if (!__t)                                               \
+               return -ENOMEM;                                 \
+                                                               \
+       INIT_LIST_HEAD(&__t->list);                             \
+       __t->type       = PERF_EVSEL__CONFIG_TERM_ ## __type;   \
+       __t->val.__name = __val;                                \
+       list_add_tail(&__t->list, head_terms);                  \
+} while (0)
+
+       struct parse_events_term *term;
+
+       list_for_each_entry(term, head_config, list) {
+               switch (term->type_term) {
+               default:
+                       break;
+               }
+       }
+#undef ADD_EVSEL_CONFIG
+       return 0;
+}
+
 int parse_events_add_numeric(struct parse_events_evlist *data,
                             struct list_head *list,
                             u32 type, u64 config,
                             struct list_head *head_config)
 {
        struct perf_event_attr attr;
+       LIST_HEAD(config_terms);
 
        memset(&attr, 0, sizeof(attr));
        attr.type = type;
        attr.config = config;
 
-       if (head_config &&
-           config_attr(&attr, head_config, data->error))
-               return -EINVAL;
+       if (head_config) {
+               if (config_attr(&attr, head_config, data->error))
+                       return -EINVAL;
+
+               if (get_config_terms(head_config, &config_terms))
+                       return -ENOMEM;
+       }
 
-       return add_event(list, &data->idx, &attr, NULL);
+       return add_event(list, &data->idx, &attr, NULL, &config_terms);
 }
 
 static int parse_events__is_name_term(struct parse_events_term *term)
@@ -664,6 +704,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
        struct perf_pmu_info info;
        struct perf_pmu *pmu;
        struct perf_evsel *evsel;
+       LIST_HEAD(config_terms);
 
        pmu = perf_pmu__find(name);
        if (!pmu)
@@ -678,7 +719,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
 
        if (!head_config) {
                attr.type = pmu->type;
-               evsel = __add_event(list, &data->idx, &attr, NULL, pmu->cpus);
+               evsel = __add_event(list, &data->idx, &attr, NULL, pmu->cpus, NULL);
                return evsel ? 0 : -ENOMEM;
        }
 
@@ -692,11 +733,15 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
        if (config_attr(&attr, head_config, data->error))
                return -EINVAL;
 
+       if (get_config_terms(head_config, &config_terms))
+               return -ENOMEM;
+
        if (perf_pmu__config(pmu, &attr, head_config, data->error))
                return -EINVAL;
 
        evsel = __add_event(list, &data->idx, &attr,
-                           pmu_event_name(head_config), pmu->cpus);
+                           pmu_event_name(head_config), pmu->cpus,
+                           &config_terms);
        if (evsel) {
                evsel->unit = info.unit;
                evsel->scale = info.scale;
This page took 0.030268 seconds and 5 git commands to generate.