From: sashiko-bot@kernel.org
To: "Chun-Tse Shao" <ctshao@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf stat: Include PMU name and split uncore events per PMU in metric-only JSON output
Date: Tue, 14 Jul 2026 18:10:38 +0000 [thread overview]
Message-ID: <20260714181038.B80C11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714174052.1826692-1-ctshao@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] Bypassing `print_metric_begin` for tool events produces invalid, corrupted JSON and CSV output in `--metric-only` mode.
Pre-existing issues:
- [High] Missing bounds check on `aggr_idx` after searching `config->aggr_map` results in an out-of-bounds array read.
--
--- Patch [1]: [PATCH] perf stat: Include PMU name and split uncore events per PMU in metric-only JSON output ---
commit 418eb65331465e855519851f0438c3a1fe047563
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 to include the PMU name in the metric-only JSON
output when running in no-aggr mode. It ensures that when an uncore event spans
multiple PMU instances, each instance is printed on a separate line with the
correct PMU identifier. The JSON linting script is also updated to recognize
the new PMU key.
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
> index f94f1324d24ac..d7f1feb638784 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
[ ... ]
> @@ -1146,10 +1149,24 @@ static void print_no_aggr_metric(struct perf_stat_config *config,
>
> 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)) {
[Severity: Medium]
Does bypassing the print_metric_begin() initialization for tool events cause
invalid JSON output?
If a metric uses a tool event like duration_time as the metric leader,
skipping print_metric_begin() means the opening bracket, timestamp, and CPU ID
are not printed. This can leave the metric key-value pair as a bare string,
followed by a mid-stream bracket when a subsequent hardware PMU event is
processed.
> + if (config->json_output && line_open && pmu != last_pmu) {
> + 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;
> + }
> + }
> }
> +
> val = ps->aggr[aggr_idx].counts.val;
[Severity: High]
This is a pre-existing issue, but does this code read past the end of the
ps->aggr array if the CPU is not found in the aggregation map?
In print_no_aggr_metric(), there is a loop right before this block that
searches for the CPU:
cpu_aggr_map__for_each_idx(aggr_idx, config->aggr_map) {
if (config->aggr_map->map[aggr_idx].cpu.cpu == cpu.cpu)
break;
}
If a system lacks complete sysfs CPU topology, aggr_cpu_id__cpu() might return
an empty ID, and the CPU may not be found in config->aggr_map.
Could the loop terminate with aggr_idx == config->aggr_map->nr, causing this
line to unconditionally read out of bounds?
> ena = ps->aggr[aggr_idx].counts.ena;
> run = ps->aggr[aggr_idx].counts.run;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260714174052.1826692-1-ctshao@google.com?part=1
prev parent reply other threads:[~2026-07-14 18:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 17:40 [PATCH] perf stat: Include PMU name and split uncore events per PMU in metric-only JSON output Chun-Tse Shao
2026-07-14 18:10 ` sashiko-bot [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=20260714181038.B80C11F000E9@smtp.kernel.org \
--to=sashiko-bot@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