Skip to content

Commit 7f84f67

Browse files
captain5050acmel
authored andcommitted
perf list: Display the PMU name associated with a perf metric in JSON
The 'perf stat --cputype' option can be used to filter which metrics will be applied, for this reason the JSON metrics have an associated PMU. List this PMU name in the 'perf list' output in JSON mode so that tooling may access it. An example of the new field is: ``` { "MetricGroup": "Backend", "MetricName": "tma_core_bound", "MetricExpr": "max(0, tma_backend_bound - tma_memory_bound)", "MetricThreshold": "tma_core_bound > 0.1 & tma_backend_bound > 0.2", "ScaleUnit": "100%", "BriefDescription": "This metric represents fraction of slots where ... "PublicDescription": "This metric represents fraction of slots where ... "Unit": "cpu_core" }, ``` Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Weilin Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 4102ff8 commit 7f84f67

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

tools/perf/builtin-list.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ static void default_print_metric(void *ps,
197197
const char *long_desc,
198198
const char *expr,
199199
const char *threshold,
200-
const char *unit __maybe_unused)
200+
const char *unit __maybe_unused,
201+
const char *pmu_name __maybe_unused)
201202
{
202203
struct print_state *print_state = ps;
203204
FILE *fp = print_state->fp;
@@ -433,7 +434,8 @@ static void json_print_event(void *ps, const char *topic, const char *pmu_name,
433434
static void json_print_metric(void *ps __maybe_unused, const char *group,
434435
const char *name, const char *desc,
435436
const char *long_desc, const char *expr,
436-
const char *threshold, const char *unit)
437+
const char *threshold, const char *unit,
438+
const char *pmu_name)
437439
{
438440
struct json_print_state *print_state = ps;
439441
bool need_sep = false;
@@ -483,6 +485,12 @@ static void json_print_metric(void *ps __maybe_unused, const char *group,
483485
long_desc);
484486
need_sep = true;
485487
}
488+
if (pmu_name) {
489+
fix_escape_fprintf(fp, &buf, "%s\t\"Unit\": \"%S\"",
490+
need_sep ? ",\n" : "",
491+
pmu_name);
492+
need_sep = true;
493+
}
486494
fprintf(fp, "%s}", need_sep ? "\n" : "");
487495
strbuf_release(&buf);
488496
}

tools/perf/util/metricgroup.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ struct mep {
396396
const char *metric_expr;
397397
const char *metric_threshold;
398398
const char *metric_unit;
399+
const char *pmu_name;
399400
};
400401

401402
static int mep_cmp(struct rb_node *rb_node, const void *entry)
@@ -476,6 +477,7 @@ static int metricgroup__add_to_mep_groups(const struct pmu_metric *pm,
476477
me->metric_expr = pm->metric_expr;
477478
me->metric_threshold = pm->metric_threshold;
478479
me->metric_unit = pm->unit;
480+
me->pmu_name = pm->pmu;
479481
}
480482
}
481483
free(omg);
@@ -551,7 +553,8 @@ void metricgroup__print(const struct print_callbacks *print_cb, void *print_stat
551553
me->metric_long_desc,
552554
me->metric_expr,
553555
me->metric_threshold,
554-
me->metric_unit);
556+
me->metric_unit,
557+
me->pmu_name);
555558
next = rb_next(node);
556559
rblist__remove_node(&groups, node);
557560
}

tools/perf/util/print-events.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ struct print_callbacks {
2525
const char *long_desc,
2626
const char *expr,
2727
const char *threshold,
28-
const char *unit);
28+
const char *unit,
29+
const char *pmu_name);
2930
bool (*skip_duplicate_pmus)(void *print_state);
3031
};
3132

0 commit comments

Comments
 (0)