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

perf stat: Display percore events properly

The recent change in the perf stat broke the percore event display.
Note that the aggr counts are already processed so that the every
sibling thread in the same core will get the per-core counter values.

Check percore evsels and skip the sibling threads in the display.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20221018020227.85905-20-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
cec94d69 91f85f98

+25 -18
-16
tools/perf/builtin-stat.c
··· 1404 1404 return perf_stat__get_aggr(config, perf_stat__get_cpu, cpu); 1405 1405 } 1406 1406 1407 - static bool term_percore_set(void) 1408 - { 1409 - struct evsel *counter; 1410 - 1411 - evlist__for_each_entry(evsel_list, counter) { 1412 - if (counter->percore) 1413 - return true; 1414 - } 1415 - 1416 - return false; 1417 - } 1418 - 1419 1407 static aggr_cpu_id_get_t aggr_mode__get_aggr(enum aggr_mode aggr_mode) 1420 1408 { 1421 1409 switch (aggr_mode) { ··· 1416 1428 case AGGR_NODE: 1417 1429 return aggr_cpu_id__node; 1418 1430 case AGGR_NONE: 1419 - if (term_percore_set()) 1420 - return aggr_cpu_id__core; 1421 1431 return aggr_cpu_id__cpu; 1422 1432 case AGGR_GLOBAL: 1423 1433 return aggr_cpu_id__global; ··· 1439 1453 case AGGR_NODE: 1440 1454 return perf_stat__get_node_cached; 1441 1455 case AGGR_NONE: 1442 - if (term_percore_set()) 1443 - return perf_stat__get_core_cached; 1444 1456 return perf_stat__get_cpu_cached; 1445 1457 case AGGR_GLOBAL: 1446 1458 return perf_stat__get_global_cached;
+25 -2
tools/perf/util/stat-display.c
··· 1091 1091 { 1092 1092 bool metric_only = config->metric_only; 1093 1093 FILE *output = config->output; 1094 - int s; 1094 + struct cpu_aggr_map *core_map; 1095 + int s, c, i; 1095 1096 bool first = true; 1096 1097 1097 1098 if (!config->aggr_map || !config->aggr_get_id) ··· 1101 1100 if (config->percore_show_thread) 1102 1101 return print_counter(config, counter, prefix); 1103 1102 1104 - for (s = 0; s < config->aggr_map->nr; s++) { 1103 + core_map = cpu_aggr_map__empty_new(config->aggr_map->nr); 1104 + if (core_map == NULL) { 1105 + fprintf(output, "Cannot allocate per-core aggr map for display\n"); 1106 + return; 1107 + } 1108 + 1109 + for (s = 0, c = 0; s < config->aggr_map->nr; s++) { 1110 + struct perf_cpu curr_cpu = config->aggr_map->map[s].cpu; 1111 + struct aggr_cpu_id core_id = aggr_cpu_id__core(curr_cpu, NULL); 1112 + bool found = false; 1113 + 1114 + for (i = 0; i < c; i++) { 1115 + if (aggr_cpu_id__equal(&core_map->map[i], &core_id)) { 1116 + found = true; 1117 + break; 1118 + } 1119 + } 1120 + if (found) 1121 + continue; 1122 + 1105 1123 if (prefix && metric_only) 1106 1124 fprintf(output, "%s", prefix); 1107 1125 1108 1126 print_counter_aggrdata(config, counter, s, 1109 1127 prefix, metric_only, &first); 1128 + 1129 + core_map->map[c++] = core_id; 1110 1130 } 1131 + free(core_map); 1111 1132 1112 1133 if (metric_only) 1113 1134 fputc('\n', output);