Re: [PATCH v2] perf stat: Include PMU name and split uncore events per PMU in metric-only JSON output
From: Chun-Tse Shao
Date: Wed Jul 29 2026 - 13:18:42 EST
On Wed, Jul 22, 2026 at 11:03 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> On Wed, Jul 15, 2026 at 08:15:46PM -0700, Ian Rogers wrote:
> > On Wed, Jul 15, 2026 at 1:30 PM Chun-Tse Shao <ctshao@xxxxxxxxxx> wrote:
> > >
> > > When running `perf stat` with `-A` (--no-aggr) and `--metric-only` in
> > > JSON output mode (`-j`), `perf stat` evaluates metric expressions
> > > across all matching PMUs (including uncore PMUs like `uncore_iio_0`,
> > > `uncore_iio_1`, etc.).
> > >
> > > However, `perf stat` previously formatted JSON output by printing only
> > > "cpu" : "<id>" and grouping all metric values on a single line per CPU
> > > without identifying which PMU instance evaluated each metric. As a
> > > result, when an uncore event spans multiple PMU boxes, `perf stat`
> > > printed repeated, ambiguous metric keys without PMU names.
> > >
> > > Fix this by:
> > > 1. Including "pmu" : "<pmu_name>" in print_aggr_id_json when evsel->pmu
> > > is a non-core or hybrid PMU in AGGR_NONE mode (-A).
> > > 2. Starting a new JSON metric line in AGGR_NONE mode (-A) whenever the
> > > underlying PMU instance changes across PMU events.
> > > 3. Updating perf_json_output_lint.py to recognize the new "pmu" key in
> > > the JSON test suite.
> > >
> > > Example output:
> > > $ perf stat -M iio_bandwidth_read -a -A --metric-only -j -I 1000
> > > {"interval" : 1.000314908, "cpu" : "0", "pmu" : "uncore_iio_0", "MB/s iio_bandwidth_read" : "0.0"}
> > > {"interval" : 1.000314908, "cpu" : "0", "pmu" : "uncore_iio_1", "MB/s iio_bandwidth_read" : "0.1"}
> > > {"interval" : 1.000314908, "cpu" : "0", "pmu" : "uncore_iio_11", "MB/s iio_bandwidth_read" : "0.0"}
> > > ...
> > > {"interval" : 1.000314908, "cpu" : "56", "pmu" : "uncore_iio_0", "MB/s iio_bandwidth_read" : "0.0"}
> > > {"interval" : 1.000314908, "cpu" : "56", "pmu" : "uncore_iio_1", "MB/s iio_bandwidth_read" : "0.0"}
> > > {"interval" : 1.000314908, "cpu" : "56", "pmu" : "uncore_iio_11", "MB/s iio_bandwidth_read" : "0.0"}
> > >
> > > Signed-off-by: Chun-Tse Shao <ctshao@xxxxxxxxxx>
> > > Assisted-by: Gemini:gemini-3.1-pro-preview
> >
> > Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>
> >
> > Nit: It may be nice to include the before output (i.e., without the
> > PMU showing that differentiation isn't possible) in the commit
> > message.
>
> Hi CT, can you please update the commit message? It'd be very helpful
> for others to understand the problem.
>
> Thanks,
> Namhyung
>
Thanks for your feedback, please check the v3 patch:
lore.kernel.org/20260729170416.41904-1-ctshao@xxxxxxxxxx