Re: [PATCH v1 38/58] perf failed-syscalls-by-pid: Port failed-syscalls-by-pid to use python module

sashiko-bot
2026-04-20T00:32:14Z

Sashiko AI review found 2 potential issue(s):
- [High] The script attempts to extract the process comm using `getattr(sample, 'comm', 'Unknown')`, but the new perf Python module does not inject `comm` into the sample object. This causes all events to be aggregated under 'Unknown', fundamentally breaking the output grouping and causing the `--comm` filter to drop all events.
- [High] Formatting a potentially `None` syscall name with a width specifier causes a `TypeError` crash.
--

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

perf failed-syscalls-by-pid: Port failed-syscalls-by-pid to use python module

This commit ports the failed-syscalls-by-pid script to the new perf Python
module API. It updates syscall name resolution, statistic aggregation, error
string lookup, and adds optional COMM/PID filtering.

> diff --git a/tools/perf/python/failed-syscalls-by-pid.py b/tools/perf/python/failed-syscalls-by-pid.py
> new file mode 100755
> index 0000000000000..3873cff947bcd
> --- /dev/null
> +++ b/tools/perf/python/failed-syscalls-by-pid.py

[ ... ]

> + def process_event(self, sample: perf.sample_event) -> None:
> + """Process a single sample event."""
> + if str(sample.evsel) not in ("evsel(raw_syscalls:sys_exit)", "evsel(syscalls:sys_exit)"):
> + return
> +
> + comm = getattr(sample, "comm", "Unknown")

Does the perf.sample_event object expose a comm attribute in the new Python
API?

If it is missing, getattr will fall back to "Unknown" for every event. This
would cause all events to be aggregated together under a single name, and
would drop all events if the comm filter is active.

Should this resolve the comm by querying the session, for example by
calling session.process(sample.pid).comm() instead?

[ ... ]

> + def print_summary(self) -> None:
> + """Print aggregated statistics."""

[ ... ]

> + for comm in sorted(self.syscalls.keys()):
> + for pid in sorted(self.syscalls[comm].keys()):
> + print(f"\n{comm} [{pid}]")
> + for syscall_id in sorted(self.syscalls[comm][pid].keys()):
> + try:
> + name = perf.syscall_name(syscall_id)
> + except AttributeError:
> + name = str(syscall_id)
> + print(f" syscall: {name:<16}")

If perf.syscall_name() returns None for invalid or unknown syscall IDs
(such as the fallback -1), will applying a width format specifier (<16) to
a NoneType cause a TypeError and crash the script?

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