Re: [PATCH v6 23/59] perf python: Add LiveSession helper

sashiko-bot
2026-04-25T18:29:07Z

Sashiko AI review found 2 potential issue(s):
- [High] Inefficient ring buffer consumption causes severe event processing delays and dropped events.
- [High] User callback exceptions are silently swallowed, masking consumer code errors.
--

commit a078113929da808a72925816e8a4dc8dd4e7f26d
Author: Ian Rogers <irogers@google.com>

perf python: Add LiveSession helper

Add LiveSession class in tools/perf/python/perf_live.py to support live
event collection using perf.evlist and perf.parse_events, avoiding the
need to fork a separate perf record process.

> diff --git a/tools/perf/python/perf_live.py b/tools/perf/python/perf_live.py
> new file mode 100755
> index 000000000000..d1dcbab1150b
> --- /dev/null
> +++ b/tools/perf/python/perf_live.py
> @@ -0,0 +1,48 @@
[ ... ]
> + def run(self):
> + """Run the live session."""
> + self.evlist.open()
> + try:
> + self.evlist.mmap()
> + self.evlist.enable()
> +
> + while True:
> + # Poll for events with 100ms timeout
> + try:
> + self.evlist.poll(100)
> + except InterruptedError:
> + continue
> + for cpu in self.cpus:
> + try:
> + event = self.evlist.read_on_cpu(cpu)

Will this cause processing delays and dropped events?

If reading a single event drops the unread data below the wakeup watermark,
the next poll() call will block until more events arrive or the 100ms
timeout expires.

Should this code repeatedly call read_on_cpu() in an inner loop until it
returns None before polling again, to avoid a poll() syscall for every
single event?

> + if event and event.type == perf.RECORD_SAMPLE:
> + self.sample_callback(event)
> + except Exception:
> + pass

Does catching Exception and passing here silently swallow errors in the
user's callback?

If sample_callback() contains bugs and raises an exception like
AttributeError or TypeError, it will be silently ignored without a traceback.

Could the try block be narrowed to only wrap the read_on_cpu() operation?

> + except KeyboardInterrupt:
> + pass
> + finally:
> + self.evlist.close()

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260425174858.3922152-1-irogers@google.com?part=23