[PATCH v2 04/30] perf metricgroup: Don't prefer tool events for displaying a metric
From: Ian Rogers
Date: Fri Nov 13 2026 - 14:57:57 EST
pick_display_evsel() selects the event of a metric that perf stat shows
the metric alongside, preferring an event that isn't a tool event, such
as duration_time, and that is used by the fewest metrics. A tool event
used by fewer metrics replaced a non-tool event, so whether the metric
was displayed with a tool event depended on the order of the metric's
events. For example, CPUs_utilized could be shown alongside the
duration_time tool event rather than cpu-clock, and cpu-clock not shown.
Only compare the number of uses of events that are both, or both not,
tool events.
Fixes: c8035a496141 ("perf metricgroup: Add care to picking the evsel for displaying a metric")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/metricgroup.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 779fe56fe8d0..98f3ba8f9533 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -1388,8 +1388,10 @@ static struct evsel *pick_display_evsel(struct list_head *metric_list,
struct evsel *candidate = metric_events[i];
size_t candidate_uses = count_uses(metric_list, candidate);
- if ((selected_is_tool && !evsel__is_tool(candidate)) ||
- (candidate_uses < selected_uses)) {
+ bool candidate_is_tool = evsel__is_tool(candidate);
+
+ if ((selected_is_tool && !candidate_is_tool) ||
+ (selected_is_tool == candidate_is_tool && candidate_uses < selected_uses)) {
selected = candidate;
selected_uses = candidate_uses;
selected_is_tool = evsel__is_tool(selected);
--
2.56.1.703.gf848ed807c-goog