Re: [PATCH v6 27/59] perf syscall-counts: Port syscall-counts to use python module

sashiko-bot
2026-04-25T18:04:51Z

Sashiko AI review found 2 potential issue(s):
- [High] The exact string equality check for `raw_syscalls:sys_enter` fails if users specify event modifiers.
- [High] Thread comm resolution is broken for child threads, causing fallback to "unknown" or the main thread's comm.
--

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

perf syscall-counts: Port syscall-counts to use python module

This commit rewrites the syscall-counts Python script to use the perf
python module directly. This avoids overhead from perf script execution,
providing a performance improvement.

> diff --git a/tools/perf/python/syscall-counts.py b/tools/perf/python/syscall-counts.py
> new file mode 100755
> index 000000000000..ef2bd8c7b24c
> --- /dev/null
> +++ b/tools/perf/python/syscall-counts.py

[ ... ]

> +def process_event(sample):
> + """Process a single sample event."""
> + event_name = str(sample.evsel)
> + if event_name == "evsel(raw_syscalls:sys_enter)":

Will this strict equality fail if the user specifies event modifiers?

If a user records with modifiers like perf record -e raw_syscalls:sys_enter:u,
the string conversion will return "evsel(raw_syscalls:sys_enter:u)". This
would cause the check to fail and silently drop the events.

> + sc_id = getattr(sample, "id", -1)
> + elif event_name.startswith("evsel(syscalls:sys_enter_"):

[ ... ]

> + comm = "unknown"
> + try:
> + if session:
> + proc = session.find_thread(sample.sample_pid)

Does using sample.sample_pid here break comm resolution for child threads?

The Python extension for session.find_thread maps to
machine__find_thread(machine, pid, pid). Since child threads have a TID
that differs from their PID, they might fail to resolve or misattribute
to the main thread.

The old script received the common_comm argument directly from perf, which
avoided this issue.

> + if proc:
> + comm = proc.comm()
> + except (TypeError, AttributeError):
> + pass

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