From: Namhyung Kim <namhyung@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: Chun-Tse Shao <ctshao@google.com>, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3] perf stat: Include PMU name and split uncore events per PMU in metric-only JSON output
Date: Fri, 31 Jul 2026 16:14:32 -0700 [thread overview]
Message-ID: <am0sWLrB5tNyTJQK@google.com> (raw)
In-Reply-To: <20260729171742.24ABB1F000E9@smtp.kernel.org>
On Wed, Jul 29, 2026 at 05:17:41PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] Flawed line-split transition logic causes spurious empty JSON objects and incorrect PMU attribution for tool events.
> --
>
> --- Patch [1]: [PATCH v3] perf stat: Include PMU name and split uncore events per PMU in metric-only JSON output ---
> commit 20e3cd08fd5e415b458343262ee76bc1f5f6ce85
> Author: Chun-Tse Shao <ctshao@google.com>
>
> perf stat: Include PMU name and split uncore events per PMU in metric-only JSON output
>
> This commit modifies perf stat JSON output in --metric-only and -A mode to
> group metrics by PMU. It achieves this by adding a "pmu" key to the JSON
> output and starting a new JSON line when the underlying PMU instance changes.
>
> > diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
> > index b337cc23f4131..6785e2c442bd7 100644
> > --- a/tools/perf/util/stat-display.c
> > +++ b/tools/perf/util/stat-display.c
>
> [ ... ]
>
> > @@ -1146,13 +1149,34 @@ static void print_no_aggr_metric(struct perf_stat_config *config,
> > if (config->aggr_map->map[aggr_idx].cpu.cpu == cpu.cpu)
> > break;
> > }
> > + if (aggr_idx >= config->aggr_map->nr)
> > + continue;
> >
> > os->evsel = counter;
> > os->id = aggr_cpu_id__cpu(cpu, /*data=*/NULL);
> > - if (first) {
> > - print_metric_begin(config, evlist, os, aggr_idx);
> > - first = false;
> > +
> > + if (config->metric_only) {
> > + struct perf_pmu *pmu = counter->pmu;
> > +
> > + if (!evsel__is_tool(counter)) {
> > + if (config->json_output && line_open &&
> > + (!last_pmu || pmu != last_pmu)) {
>
> [Severity: Medium]
> Does this line-split transition logic handle tool events correctly depending
> on their order in the event list?
>
> If a tool event is processed first, line_open becomes true, but last_pmu
> remains NULL. When the next event (a PMU event) is processed, the condition
> (!last_pmu || pmu != last_pmu) evaluates to true. This prematurely closes
> the line and creates a spurious empty JSON object for the tool event.
Something like this?
$ sudo ./perf stat -aA -e user_time -M insn_per_cycle -j --metric-only true
{"cpu" : "0", "pmu" : "tool"}
{"cpu" : "0", "pmu" : "cpu_core", "instructions insn_per_cycle" : "0.8"}
{"cpu" : "1", "pmu" : "tool"}
{"cpu" : "1", "pmu" : "cpu_core", "instructions insn_per_cycle" : "0.1"}
{"cpu" : "2", "pmu" : "tool"}
{"cpu" : "2", "pmu" : "cpu_core", "instructions insn_per_cycle" : "0.5"}
{"cpu" : "3", "pmu" : "tool"}
{"cpu" : "3", "pmu" : "cpu_core", "instructions insn_per_cycle" : "0.3"}
...
Thanks,
Namhyung
>
> Conversely, if a tool event comes after a PMU event, the else-if block below
> is taken because !evsel__is_tool(counter) evaluates to false. This bypasses
> the line-splitting check entirely, causing the tool event to silently merge
> into the preceding PMU's JSON object and incorrectly inherit its PMU
> attribution.
>
> > + print_metric_end(config, os);
> > + line_open = false;
> > + }
> > + if (!line_open) {
> > + print_metric_begin(config, evlist, os,
> > + aggr_idx, counter);
> > + line_open = true;
> > + }
> > + last_pmu = pmu;
> > + } else if (!line_open) {
> > + print_metric_begin(config, evlist, os,
> > + aggr_idx, counter);
> > + line_open = true;
> > + }
> > }
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260729170416.41904-1-ctshao@google.com?part=1
prev parent reply other threads:[~2026-07-31 23:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 17:04 [PATCH v3] perf stat: Include PMU name and split uncore events per PMU in metric-only JSON output Chun-Tse Shao
2026-07-29 17:17 ` sashiko-bot
2026-07-31 23:14 ` Namhyung Kim [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=am0sWLrB5tNyTJQK@google.com \
--to=namhyung@kernel.org \
--cc=ctshao@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox