Skip to content

Commit 4ea2896

Browse files
olsajiriacmel
authored andcommitted
perf metric: Collect referenced metrics in struct metric_expr
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 <[email protected]> Reviewed-by: Kajol Jain <[email protected]> Acked-by: Ian Rogers <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: John Garry <[email protected]> Cc: Michael Petlan <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Clarke <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 83de0b7 commit 4ea2896

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tools/perf/util/metricgroup.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static void metric_event_delete(struct rblist *rblist __maybe_unused,
8383
struct metric_expr *expr, *tmp;
8484

8585
list_for_each_entry_safe(expr, tmp, &me->head, nd) {
86+
free(expr->metric_refs);
8687
free(expr);
8788
}
8889

@@ -248,6 +249,7 @@ static int metricgroup__setup_events(struct list_head *groups,
248249

249250
list_for_each_entry (eg, groups, nd) {
250251
struct evsel **metric_events;
252+
struct metric_ref *metric_refs = NULL;
251253

252254
metric_events = calloc(sizeof(void *),
253255
hashmap__size(&eg->pctx.ids) + 1);
@@ -279,6 +281,36 @@ static int metricgroup__setup_events(struct list_head *groups,
279281
free(metric_events);
280282
break;
281283
}
284+
285+
/*
286+
* Collect and store collected nested expressions
287+
* for metric processing.
288+
*/
289+
if (eg->metric_refs_cnt) {
290+
struct metric_ref_node *ref;
291+
292+
metric_refs = zalloc(sizeof(struct metric_ref) * (eg->metric_refs_cnt + 1));
293+
if (!metric_refs) {
294+
ret = -ENOMEM;
295+
free(metric_events);
296+
break;
297+
}
298+
299+
i = 0;
300+
list_for_each_entry(ref, &eg->metric_refs, list) {
301+
/*
302+
* Intentionally passing just const char pointers,
303+
* originally from 'struct pmu_event' object.
304+
* We don't need to change them, so there's no
305+
* need to create our own copy.
306+
*/
307+
metric_refs[i].metric_name = ref->metric_name;
308+
metric_refs[i].metric_expr = ref->metric_expr;
309+
i++;
310+
}
311+
};
312+
313+
expr->metric_refs = metric_refs;
282314
expr->metric_expr = eg->metric_expr;
283315
expr->metric_name = eg->metric_name;
284316
expr->metric_unit = eg->metric_unit;

tools/perf/util/metricgroup.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ struct metric_event {
1818
struct list_head head; /* list of metric_expr */
1919
};
2020

21+
struct metric_ref {
22+
const char *metric_name;
23+
const char *metric_expr;
24+
};
25+
2126
struct metric_expr {
2227
struct list_head nd;
2328
const char *metric_expr;
2429
const char *metric_name;
2530
const char *metric_unit;
2631
struct evsel **metric_events;
32+
struct metric_ref *metric_refs;
2733
int runtime;
2834
};
2935

0 commit comments

Comments
 (0)