[PATCH v14 18/32] perf evlist: Try to avoid computing evsel from sample
From: Ian Rogers
Date: Wed May 20 2026 - 18:16:48 EST
As struct perf_sample now directly contains its own resolved evsel pointer,
passing the evsel separately is redundant and clutters the interface.
Remove the redundant evsel parameter from evlist-specific handlers and
structures, ensuring the tool always directly accesses the evsel bound to the
sample. This simplifies the API signatures and eliminates the risk of passing
an inconsistent evsel.
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
Acked-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/builtin-top.c | 4 +++-
tools/perf/tests/mmap-basic.c | 4 +++-
tools/perf/tests/switch-tracking.c | 5 ++++-
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 6cf73bb0c7af..c8474f7ac658 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1164,7 +1164,9 @@ static int deliver_event(struct ordered_events *qe,
goto next_event;
}
- evsel = evlist__id2evsel(session->evlist, sample.id);
+ evsel = sample.evsel;
+ if (!evsel)
+ evsel = evlist__id2evsel(session->evlist, sample.id);
assert(evsel != NULL);
if (event->header.type == PERF_RECORD_SAMPLE) {
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 3313c236104e..a18d84d858aa 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -142,7 +142,9 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtest
}
err = -1;
- evsel = evlist__id2evsel(evlist, sample.id);
+ evsel = sample.evsel;
+ if (!evsel)
+ evsel = evlist__id2evsel(evlist, sample.id);
perf_sample__exit(&sample);
if (evsel == NULL) {
pr_debug("event with id %" PRIu64
diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-tracking.c
index 22b0302252db..e32331fee277 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -138,7 +138,10 @@ static int process_sample_event(struct evlist *evlist,
goto out;
}
- evsel = evlist__id2evsel(evlist, sample.id);
+ evsel = sample.evsel;
+ if (!evsel)
+ evsel = evlist__id2evsel(evlist, sample.id);
+
if (evsel == switch_tracking->switch_evsel) {
next_tid = perf_sample__intval(&sample, "next_pid");
prev_tid = perf_sample__intval(&sample, "prev_pid");
--
2.54.0.746.g67dd491aae-goog