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

sashiko-bot
2026-04-23T04:28:59Z

Sashiko AI review found 2 potential issue(s):
- [Medium] Unconditional script crash due to accessing non-existent `sample.evsel.name` attribute.
- [Medium] Hallucinated tracepoints `raw_syscalls:sys_enter_read` and `raw_syscalls:sys_enter_write`.
--

commit e4f0d99904b4502561143e05b3d670fc00f299f5
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 uses the perf.session API
to track read and write activity by file descriptor for a given program.

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

Will this raise an AttributeError and crash the script on the first event?

The Python perf.evsel object implemented in the C extension
(tools/perf/util/python.c) does not appear to expose a .name attribute.

Since this access occurs before the try/except AttributeError blocks below,
it seems this will bypass the exception handler entirely and halt execution.

[ ... ]
> + if comm != self.for_comm:
> + return
> +
> + if event_name in ("syscalls:sys_enter_read", "raw_syscalls:sys_enter_read"):

Do these raw_syscalls variants actually exist in the kernel?

The kernel's raw syscall tracepoints are generic (like raw_syscalls:sys_enter)
and do not have per-syscall variants.

Even if generic raw syscall tracepoints were used, wouldn't they carry an
args array rather than distinct named fields like fd and count? Attempting
to extract these fields from raw tracepoints later in this block would
likely result in missing attributes.

> + try:
> + fd = sample.fd
> + count = sample.count
> + self.reads[fd]["bytes_requested"] += count
> + self.reads[fd]["total_reads"] += 1
> + except AttributeError:
> + self.unhandled[event_name] += 1
> + elif event_name in ("syscalls:sys_enter_write", "raw_syscalls:sys_enter_write"):

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