]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
perf metric: Collect referenced metrics in struct metric_expr
authorJiri Olsa <jolsa@kernel.org>
Sun, 19 Jul 2020 18:13:10 +0000 (20:13 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 30 Jul 2020 10:01:49 +0000 (07:01 -0300)
Add referenced metrics into struct metric_expr object, so they are
accessible when computing the metric.

Storing just name and expression itself, so the metric can be resolved
and computed.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Reviewed-by: Kajol Jain <kjain@linux.ibm.com>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200719181320.785305-10-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/metricgroup.c
tools/perf/util/metricgroup.h

index 12f8d86577345c95467dca4ffba123928d718e68..f690da21668d7ade9f718f217cfd03180003c211 100644 (file)
@@ -83,6 +83,7 @@ static void metric_event_delete(struct rblist *rblist __maybe_unused,
        struct metric_expr *expr, *tmp;
 
        list_for_each_entry_safe(expr, tmp, &me->head, nd) {
+               free(expr->metric_refs);
                free(expr);
        }
 
@@ -248,6 +249,7 @@ static int metricgroup__setup_events(struct list_head *groups,
 
        list_for_each_entry (eg, groups, nd) {
                struct evsel **metric_events;
+               struct metric_ref *metric_refs = NULL;
 
                metric_events = calloc(sizeof(void *),
                                hashmap__size(&eg->pctx.ids) + 1);
@@ -279,6 +281,36 @@ static int metricgroup__setup_events(struct list_head *groups,
                        free(metric_events);
                        break;
                }
+
+               /*
+                * Collect and store collected nested expressions
+                * for metric processing.
+                */
+               if (eg->metric_refs_cnt) {
+                       struct metric_ref_node *ref;
+
+                       metric_refs = zalloc(sizeof(struct metric_ref) * (eg->metric_refs_cnt + 1));
+                       if (!metric_refs) {
+                               ret = -ENOMEM;
+                               free(metric_events);
+                               break;
+                       }
+
+                       i = 0;
+                       list_for_each_entry(ref, &eg->metric_refs, list) {
+                               /*
+                                * Intentionally passing just const char pointers,
+                                * originally from 'struct pmu_event' object.
+                                * We don't need to change them, so there's no
+                                * need to create our own copy.
+                                */
+                               metric_refs[i].metric_name = ref->metric_name;
+                               metric_refs[i].metric_expr = ref->metric_expr;
+                               i++;
+                       }
+               };
+
+               expr->metric_refs = metric_refs;
                expr->metric_expr = eg->metric_expr;
                expr->metric_name = eg->metric_name;
                expr->metric_unit = eg->metric_unit;
index 8315bd1a7da47266b692f0795eaf145447eb336c..62623a39cbecd46763662463c831a2032b09787b 100644 (file)
@@ -18,12 +18,18 @@ struct metric_event {
        struct list_head head; /* list of metric_expr */
 };
 
+struct metric_ref {
+       const char *metric_name;
+       const char *metric_expr;
+};
+
 struct metric_expr {
        struct list_head nd;
        const char *metric_expr;
        const char *metric_name;
        const char *metric_unit;
        struct evsel **metric_events;
+       struct metric_ref *metric_refs;
        int runtime;
 };