Re: [PATCH] perf stat: Ensure metrics are displayed even with failed events

From: Ian Rogers

Date: Sat Feb 07 2026 - 20:31:04 EST


On Fri, Feb 6, 2026 at 1:17 PM Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
>
> On Tue, Feb 03, 2026 at 03:41:30PM -0800, Ian Rogers wrote:
> > On Tue, Feb 3, 2026 at 3:07 PM Chun-Tse Shao <ctshao@xxxxxxxxxx> wrote:
>
> > > $ ./perf stat -M CPUs_utilized -a --metric-only -j -- sleep 1
> > > {"CPUs CPUs_utilized" : "none"}
>
> > > Signed-off-by: ctshao@xxxxxxxxxx
>
> > Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>
>
> Thanks, applied to perf-tools-next,

I've started seeing this test failure following this change:
```
$ perf test -v 59
--- start ---
test child forked, pid 2316256
metric expr inst_retired.any / cpu_clk_unhalted.thread for IPC
Using CPUID GenuineIntel-6-8D-1
found event inst_retired.any
found event cpu_clk_unhalted.thread
Parsing metric events
'{inst_retired.any/metric-id=inst_retired.any/,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/}:W'
Matched metric-id inst_retired.any to inst_retired.any
Matched metric-id cpu_clk_unhalted.thread to cpu_clk_unhalted.thread
FAILED tests/parse-metric.c:142 IPC failed, wrong ratio
FAILED tests/parse-metric.c:293 IPC failed
---- end(-1) ----
59: Parse and process metrics : FAILED!
```

The following fixes it for me:
```
diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metric.c
index 6bbc209a5c6a..7c7f489a5eb0 100644
--- a/tools/perf/tests/parse-metric.c
+++ b/tools/perf/tests/parse-metric.c
@@ -41,6 +41,8 @@ static void load_runtime_stat(struct evlist *evlist,
struct value *vals)
count = find_value(evsel->name, vals);
evsel->supported = true;
evsel->stats->aggr->counts.val = count;
+ evsel->stats->aggr->counts.ena = 1;
+ evsel->stats->aggr->counts.run = 1;
}
}

```
I'll mail it out as a fix.

Thanks,
Ian

> - Arnaldo