Re: [PATCH v5 48/58] perf rw-by-file: Port rw-by-file to use python module

sashiko-bot
2026-04-24T17:43:44Z

Sashiko AI review found 2 potential issue(s):
- [Medium] Accessing `sample.evsel.name` will crash the script with an `AttributeError` because the `perf.evsel` Python bindings do not expose a `.name` attribute.
- [Medium] The exact string matching logic uses hallucinated `raw_syscalls` tracepoint names and fails to account for the `evsel(...)` string wrapper, rendering the script's core logic dead code.
--

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

perf rw-by-file: Port rw-by-file to use python module

This commit ports the legacy Perl script rw-by-file.pl to a python script
using the perf module in tools/perf/python. It tracks read and write
activity by file descriptor for a given program name.

> diff --git a/tools/perf/python/rw-by-file.py b/tools/perf/python/rw-by-file.py
> new file mode 100755
> index 00000000000000..f71e0b21f64ecd
> --- /dev/null
> +++ b/tools/perf/python/rw-by-file.py
[ ... ]
> + def process_event(self, sample: perf.sample_event) -> None:
> + """Process events."""
> + event_name = sample.evsel.name # type: ignore

Does sample.evsel have a name attribute in the Python bindings?

The C-Python extension for the perf module in tools/perf/util/python.c does
not appear to define a name property for evsel objects. Because the evsel
object uses PyObject_GenericGetAttr, this looks like it will raise an
AttributeError and crash the process_events loop.

Can sample.evsel also be None here?

> +
> + pid = sample.sample_pid
> + assert self.session is not None
> + try:
> + comm = self.session.process(pid).comm()
> + except Exception: # pylint: disable=broad-except
> + comm = "unknown"
> +
> + if comm != self.for_comm:
> + return
> +
> + if event_name in ("syscalls:sys_enter_read", "raw_syscalls:sys_enter_read"):

If event_name is eventually retrieved using str(sample.evsel) instead, the
pyrf_evsel__str C implementation returns a string wrapped in evsel(...)
such as evsel(syscalls:sys_enter_read). Will this exact string match fail
because it does not account for the wrapper?

Additionally, do the raw_syscalls:sys_enter_read and
raw_syscalls:sys_enter_write tracepoints exist? The raw_syscalls subsystem
typically only provides generic sys_enter and sys_exit events.

Could this cause valid events to fail the match and fall through to the
unhandled bucket, rendering the read and write tracking logic unreachable?

> + try:
> + fd = sample.fd
[ ... ]

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