[PATCH v1 13/58] perf python: Use evsel in sample in pyrf_event

Ian Rogers
2026-04-19T23:59:51Z

Avoid a duplicated evsel by using the one in sample.

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/python.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index e72b9d52e9ff..46fe173c6b5c 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -43,7 +43,6 @@ PyMODINIT_FUNC PyInit_perf(void);

struct pyrf_event {
PyObject_HEAD
- struct evsel *evsel;
struct perf_sample sample;
union perf_event event;
};
@@ -274,7 +273,7 @@ static PyMemberDef pyrf_sample_event__members[] = {

static void pyrf_sample_event__delete(struct pyrf_event *pevent)
{
- evsel__put(pevent->evsel);
+ evsel__put(pevent->sample.evsel);
perf_sample__exit(&pevent->sample);
Py_TYPE(pevent)->tp_free((PyObject*)pevent);
}
@@ -296,7 +295,7 @@ static PyObject *pyrf_sample_event__repr(const struct pyrf_event *pevent)
#ifdef HAVE_LIBTRACEEVENT
static bool is_tracepoint(const struct pyrf_event *pevent)
{
- return pevent->evsel->core.attr.type == PERF_TYPE_TRACEPOINT;
+ return pevent->sample.evsel->core.attr.type == PERF_TYPE_TRACEPOINT;
}

static PyObject*
@@ -343,7 +342,7 @@ tracepoint_field(const struct pyrf_event *pe, struct tep_format_field *field)
static PyObject*
get_tracepoint_field(struct pyrf_event *pevent, PyObject *attr_name)
{
- struct evsel *evsel = pevent->evsel;
+ struct evsel *evsel = pevent->sample.evsel;
struct tep_event *tp_format = evsel__tp_format(evsel);
struct tep_format_field *field;

@@ -1770,8 +1769,6 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
return Py_None;
}

- pevent->evsel = evsel;
-
perf_mmap__consume(&md->core);

err = evsel__parse_sample(evsel, &pevent->event, &pevent->sample);
--
2.54.0.rc1.513.gad8abe7a5a-goog