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

sashiko-bot
2026-04-24T17:21:20Z

Sashiko AI review found 2 potential issue(s):
- [High] The script will crash immediately with an AttributeError when attempting to access `sample.evsel.name`.
- [Medium] The commit message claims a refactoring was performed that is absent from the code.
--

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

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

This commit ports the legacy Perl rw-by-pid script to Python. It introduces
a class-based architecture that uses the perf.session API to track read and
write activity by process ID.

> Complications:
> - Refactored process_event to extract helper methods
> (_handle_sys_enter_read, etc.) to reduce the number of branches and
> satisfy pylint.

Does this portion of the commit message accurately reflect the changes? It
mentions extracting helper methods like _handle_sys_enter_read, but the
implementation uses a single monolithic method with a pylint disable comment
instead.

> diff --git a/tools/perf/python/rw-by-pid.py b/tools/perf/python/rw-by-pid.py
> new file mode 100755
> index 00000000000000..53e16b373111a4
> --- /dev/null
> +++ b/tools/perf/python/rw-by-pid.py

[ ... ]

> + def process_event(self, sample: perf.sample_event) -> None: # pylint: disable=too-many-branches
> + """Process events."""
> + event_name = sample.evsel.name # type: ignore

Does the perf.evsel object expose a name attribute?

Looking at the python C API bindings, it appears only attributes like ids,
config, and type are exposed. If this raises an AttributeError, the script
will crash on the first event.

Additionally, if this were bypassed by using str(sample.evsel), which returns
a string like evsel(syscalls:sys_enter_read), would the subsequent string
matching in the if/elif branches fail? The branches check for exact matches
like "syscalls:sys_enter_read", so the events might be silently ignored.

[ ... ]

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