Commit 7f84f674 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

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: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Weilin Wang <weilin.wang@intel.com>
Link: https://lore.kernel.org/r/20250512184700.11691-1-irogers@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 4102ff8b
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -197,7 +197,8 @@ static void default_print_metric(void *ps,
				const char *long_desc,
				const char *expr,
				const char *threshold,
				const char *unit __maybe_unused)
				const char *unit __maybe_unused,
				const char *pmu_name __maybe_unused)
{
	struct print_state *print_state = ps;
	FILE *fp = print_state->fp;
@@ -433,7 +434,8 @@ static void json_print_event(void *ps, const char *topic, const char *pmu_name,
static void json_print_metric(void *ps __maybe_unused, const char *group,
			      const char *name, const char *desc,
			      const char *long_desc, const char *expr,
			      const char *threshold, const char *unit)
			      const char *threshold, const char *unit,
			      const char *pmu_name)
{
	struct json_print_state *print_state = ps;
	bool need_sep = false;
@@ -483,6 +485,12 @@ static void json_print_metric(void *ps __maybe_unused, const char *group,
				   long_desc);
		need_sep = true;
	}
	if (pmu_name) {
		fix_escape_fprintf(fp, &buf, "%s\t\"Unit\": \"%S\"",
				   need_sep ? ",\n" : "",
				   pmu_name);
		need_sep = true;
	}
	fprintf(fp, "%s}", need_sep ? "\n" : "");
	strbuf_release(&buf);
}
+4 −1
Original line number Diff line number Diff line
@@ -396,6 +396,7 @@ struct mep {
	const char *metric_expr;
	const char *metric_threshold;
	const char *metric_unit;
	const char *pmu_name;
};

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,
			me->metric_expr = pm->metric_expr;
			me->metric_threshold = pm->metric_threshold;
			me->metric_unit = pm->unit;
			me->pmu_name = pm->pmu;
		}
	}
	free(omg);
@@ -551,7 +553,8 @@ void metricgroup__print(const struct print_callbacks *print_cb, void *print_stat
				me->metric_long_desc,
				me->metric_expr,
				me->metric_threshold,
				me->metric_unit);
				me->metric_unit,
				me->pmu_name);
		next = rb_next(node);
		rblist__remove_node(&groups, node);
	}
+2 −1
Original line number Diff line number Diff line
@@ -25,7 +25,8 @@ struct print_callbacks {
			const char *long_desc,
			const char *expr,
			const char *threshold,
			const char *unit);
			const char *unit,
			const char *pmu_name);
	bool (*skip_duplicate_pmus)(void *print_state);
};