* [PATCH] perf python: Accept events larger than union perf_event
@ 2026-10-18 7:45 Lalit Maganti
2026-11-09 17:58 ` Samuel Wu
0 siblings, 1 reply; 4+ messages in thread
From: Lalit Maganti @ 2026-10-18 7:45 UTC (permalink / raw)
To: irogers, acme, namhyung
Cc: james.clark, adrian.hunter, linux-perf-users, linux-kernel,
Lalit Maganti
Samples recorded with --call-graph dwarf carry a copy of the user stack
and are larger than union perf_event, so session.process_events()
fails on the first one:
$ perf record --call-graph dwarf -- ./workload
$ python3 tools/perf/python/stackcollapse.py
...
TypeError: Unexpected event size: 4168 < 8424
This makes all the standalone scripts unusable on such recordings.
pyrf_event__new() rejects events larger than union perf_event, which
guarded the copy into the union that pyrf_event used to embed. Since
commit 2c672ffdad4b ("perf python: Lazily copy events and samples from
process_events") the event is borrowed, or copied to a buffer of
header.size bytes when a callback keeps it, so nothing depends on the
event fitting in the union any more. Remove the check.
With this, stackcollapse.py and flamegraph.py process a DWARF recording
of a two-thread workload, with the same per-symbol sample counts as
perf script, also when the callback keeps the events after returning.
Assisted-by: LLM
Signed-off-by: Lalit Maganti <lalitmaganti@gmail.com>
---
tools/perf/util/python.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 60dbe2dad5eb..8b4b2f3d0926 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1792,11 +1792,6 @@ static PyObject *pyrf_event__new(const union perf_event *event, struct evsel *ev
event->header.size, event->header.type);
}
- if (event->header.size > sizeof(union perf_event)) {
- return PyErr_Format(PyExc_TypeError, "Unexpected event size: %zu < %u",
- sizeof(union perf_event), event->header.size);
- }
-
pevent = PyObject_New(struct pyrf_event, pyrf_event__type[event->header.type]);
if (pevent == NULL)
return PyErr_NoMemory();
base-commit: 1c90f0a3c8a1c4e38f9edd97af9e20848805a7fb
--
2.56.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] perf python: Accept events larger than union perf_event
2026-10-18 7:45 [PATCH] perf python: Accept events larger than union perf_event Lalit Maganti
@ 2026-11-09 17:58 ` Samuel Wu
2026-11-09 18:27 ` Ian Rogers
0 siblings, 1 reply; 4+ messages in thread
From: Samuel Wu @ 2026-11-09 17:58 UTC (permalink / raw)
To: Lalit Maganti
Cc: irogers, acme, namhyung, james.clark, adrian.hunter,
linux-perf-users, linux-kernel
On Sun, Oct 18, 2026 at 12:45 AM Lalit Maganti <lalitmaganti@gmail.com> wrote:
>
> Samples recorded with --call-graph dwarf carry a copy of the user stack
> and are larger than union perf_event, so session.process_events()
> fails on the first one:
>
> $ perf record --call-graph dwarf -- ./workload
> $ python3 tools/perf/python/stackcollapse.py
> ...
> TypeError: Unexpected event size: 4168 < 8424
>
> This makes all the standalone scripts unusable on such recordings.
>
> pyrf_event__new() rejects events larger than union perf_event, which
> guarded the copy into the union that pyrf_event used to embed. Since
> commit 2c672ffdad4b ("perf python: Lazily copy events and samples from
> process_events") the event is borrowed, or copied to a buffer of
> header.size bytes when a callback keeps it, so nothing depends on the
> event fitting in the union any more. Remove the check.
>
> With this, stackcollapse.py and flamegraph.py process a DWARF recording
> of a two-thread workload, with the same per-symbol sample counts as
> perf script, also when the callback keeps the events after returning.
>
> Assisted-by: LLM
> Signed-off-by: Lalit Maganti <lalitmaganti@gmail.com>
> ---
> tools/perf/util/python.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> index 60dbe2dad5eb..8b4b2f3d0926 100644
> --- a/tools/perf/util/python.c
> +++ b/tools/perf/util/python.c
> @@ -1792,11 +1792,6 @@ static PyObject *pyrf_event__new(const union perf_event *event, struct evsel *ev
> event->header.size, event->header.type);
> }
>
> - if (event->header.size > sizeof(union perf_event)) {
> - return PyErr_Format(PyExc_TypeError, "Unexpected event size: %zu < %u",
> - sizeof(union perf_event), event->header.size);
> - }
> -
> pevent = PyObject_New(struct pyrf_event, pyrf_event__type[event->header.type]);
> if (pevent == NULL)
> return PyErr_NoMemory();
>
> base-commit: 1c90f0a3c8a1c4e38f9edd97af9e20848805a7fb
> --
> 2.56.0
>
Reviewed-by: Samuel Wu <wusamuel@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] perf python: Accept events larger than union perf_event
2026-11-09 17:58 ` Samuel Wu
@ 2026-11-09 18:27 ` Ian Rogers
2026-11-09 20:02 ` Arnaldo Melo
0 siblings, 1 reply; 4+ messages in thread
From: Ian Rogers @ 2026-11-09 18:27 UTC (permalink / raw)
To: Samuel Wu
Cc: Lalit Maganti, acme, namhyung, james.clark, adrian.hunter,
linux-perf-users, linux-kernel
On Mon, Nov 9, 2026 at 9:58 AM Samuel Wu <wusamuel@google.com> wrote:
>
> On Sun, Oct 18, 2026 at 12:45 AM Lalit Maganti <lalitmaganti@gmail.com> wrote:
> >
> > Samples recorded with --call-graph dwarf carry a copy of the user stack
> > and are larger than union perf_event, so session.process_events()
> > fails on the first one:
> >
> > $ perf record --call-graph dwarf -- ./workload
> > $ python3 tools/perf/python/stackcollapse.py
> > ...
> > TypeError: Unexpected event size: 4168 < 8424
> >
> > This makes all the standalone scripts unusable on such recordings.
> >
> > pyrf_event__new() rejects events larger than union perf_event, which
> > guarded the copy into the union that pyrf_event used to embed. Since
> > commit 2c672ffdad4b ("perf python: Lazily copy events and samples from
> > process_events") the event is borrowed, or copied to a buffer of
> > header.size bytes when a callback keeps it, so nothing depends on the
> > event fitting in the union any more. Remove the check.
> >
> > With this, stackcollapse.py and flamegraph.py process a DWARF recording
> > of a two-thread workload, with the same per-symbol sample counts as
> > perf script, also when the callback keeps the events after returning.
> >
> > Assisted-by: LLM
> > Signed-off-by: Lalit Maganti <lalitmaganti@gmail.com>
Probably worth having:
Fixes: 2c672ffdad4b ("perf python: Lazily copy events and samples from
process_events")
Reviewed-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> > ---
> > tools/perf/util/python.c | 5 -----
> > 1 file changed, 5 deletions(-)
> >
> > diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> > index 60dbe2dad5eb..8b4b2f3d0926 100644
> > --- a/tools/perf/util/python.c
> > +++ b/tools/perf/util/python.c
> > @@ -1792,11 +1792,6 @@ static PyObject *pyrf_event__new(const union perf_event *event, struct evsel *ev
> > event->header.size, event->header.type);
> > }
> >
> > - if (event->header.size > sizeof(union perf_event)) {
> > - return PyErr_Format(PyExc_TypeError, "Unexpected event size: %zu < %u",
> > - sizeof(union perf_event), event->header.size);
> > - }
> > -
> > pevent = PyObject_New(struct pyrf_event, pyrf_event__type[event->header.type]);
> > if (pevent == NULL)
> > return PyErr_NoMemory();
> >
> > base-commit: 1c90f0a3c8a1c4e38f9edd97af9e20848805a7fb
> > --
> > 2.56.0
> >
>
> Reviewed-by: Samuel Wu <wusamuel@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] perf python: Accept events larger than union perf_event
2026-11-09 18:27 ` Ian Rogers
@ 2026-11-09 20:02 ` Arnaldo Melo
0 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Melo @ 2026-11-09 20:02 UTC (permalink / raw)
To: linux-perf-users, Ian Rogers, Samuel Wu
Cc: Lalit Maganti, acme, namhyung, james.clark, adrian.hunter, linux-kernel
On November 9, 2026 3:27:56 PM GMT-03:00, Ian Rogers <irogers@google.com> wrote:
>On Mon, Nov 9, 2026 at 9:58 AM Samuel Wu <wusamuel@google.com> wrote:
>>
>> On Sun, Oct 18, 2026 at 12:45 AM Lalit Maganti <lalitmaganti@gmail.com> wrote:
>> >
>> > Samples recorded with --call-graph dwarf carry a copy of the user stack
>> > and are larger than union perf_event, so session.process_events()
>> > fails on the first one:
>> >
>> > $ perf record --call-graph dwarf -- ./workload
>> > $ python3 tools/perf/python/stackcollapse.py
>> > ...
>> > TypeError: Unexpected event size: 4168 < 8424
>> >
>> > This makes all the standalone scripts unusable on such recordings.
>> >
>> > pyrf_event__new() rejects events larger than union perf_event, which
>> > guarded the copy into the union that pyrf_event used to embed. Since
>> > commit 2c672ffdad4b ("perf python: Lazily copy events and samples from
>> > process_events") the event is borrowed, or copied to a buffer of
>> > header.size bytes when a callback keeps it, so nothing depends on the
>> > event fitting in the union any more. Remove the check.
>> >
>> > With this, stackcollapse.py and flamegraph.py process a DWARF recording
>> > of a two-thread workload, with the same per-symbol sample counts as
>> > perf script, also when the callback keeps the events after returning.
>> >
>> > Assisted-by: LLM
>> > Signed-off-by: Lalit Maganti <lalitmaganti@gmail.com>
>
>Probably worth having:
>
>Fixes: 2c672ffdad4b ("perf python: Lazily copy events and samples from
>process_events")
>
>Reviewed-by: Ian Rogers <irogers@google.com>
I'll pick it for v7.4,
Thanks,
- Arnaldo
>
>Thanks,
>Ian
>
>> > ---
>> > tools/perf/util/python.c | 5 -----
>> > 1 file changed, 5 deletions(-)
>> >
>> > diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
>> > index 60dbe2dad5eb..8b4b2f3d0926 100644
>> > --- a/tools/perf/util/python.c
>> > +++ b/tools/perf/util/python.c
>> > @@ -1792,11 +1792,6 @@ static PyObject *pyrf_event__new(const union perf_event *event, struct evsel *ev
>> > event->header.size, event->header.type);
>> > }
>> >
>> > - if (event->header.size > sizeof(union perf_event)) {
>> > - return PyErr_Format(PyExc_TypeError, "Unexpected event size: %zu < %u",
>> > - sizeof(union perf_event), event->header.size);
>> > - }
>> > -
>> > pevent = PyObject_New(struct pyrf_event, pyrf_event__type[event->header.type]);
>> > if (pevent == NULL)
>> > return PyErr_NoMemory();
>> >
>> > base-commit: 1c90f0a3c8a1c4e38f9edd97af9e20848805a7fb
>> > --
>> > 2.56.0
>> >
>>
>> Reviewed-by: Samuel Wu <wusamuel@google.com>
>
- Arnaldo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-09 20:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-18 7:45 [PATCH] perf python: Accept events larger than union perf_event Lalit Maganti
2026-11-09 17:58 ` Samuel Wu
2026-11-09 18:27 ` Ian Rogers
2026-11-09 20:02 ` Arnaldo Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®