Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf stat: Fix metric-only aggregation index

Aggregation index was being computed using the evsel's cpumap which
may have a different (typically the same or fewer) entries.

Before:
```
$ perf stat --metric-only -A -M memory_bandwidth_total -a sleep 1

Performance counter stats for 'system wide':

MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total
CPU0 12.8 0.0 12.9 12.7 0.0 12.6
CPU1

1.007806367 seconds time elapsed
```

After:
```
$ perf stat --metric-only -A -M memory_bandwidth_total -a sleep 1

Performance counter stats for 'system wide':

MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total MB/s memory_bandwidth_total
CPU0 15.4 0.0 15.3 15.0 0.0 14.9
CPU18 0.0 0.0 13.5 5.2 0.0 11.9

1.007858736 seconds time elapsed
```

Signed-off-by: Ian Rogers <irogers@google.com> |
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Kaige Ye <ye@kaige.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: John Garry <john.g.garry@oracle.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240221070754.4163916-3-irogers@google.com

authored by

Ian Rogers and committed by
Namhyung Kim
bafd4e75 a59fb796

+7 -2
+7 -2
tools/perf/util/stat-display.c
··· 1137 1137 u64 ena, run, val; 1138 1138 double uval; 1139 1139 struct perf_stat_evsel *ps = counter->stats; 1140 - int aggr_idx = perf_cpu_map__idx(evsel__cpus(counter), cpu); 1140 + int aggr_idx = 0; 1141 1141 1142 - if (aggr_idx < 0) 1142 + if (!perf_cpu_map__has(evsel__cpus(counter), cpu)) 1143 1143 continue; 1144 + 1145 + cpu_aggr_map__for_each_idx(aggr_idx, config->aggr_map) { 1146 + if (config->aggr_map->map[aggr_idx].cpu.cpu == cpu.cpu) 1147 + break; 1148 + } 1144 1149 1145 1150 os->evsel = counter; 1146 1151 os->id = aggr_cpu_id__cpu(cpu, /*data=*/NULL);