Re: [PATCH v7 28/59] perf syscall-counts-by-pid: Port syscall-counts-by-pid to use python module

sashiko-bot
2026-04-25T23:05:46Z

Sashiko AI review found 2 potential issue(s):
- [Medium] The new script sorts the syscall output numerically by syscall ID instead of descending by frequency, contradicting the commit message.
- [Medium] Filtering by PID 0 fails and incorrectly aggregates all processes, bypassing the filter entirely.
--

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

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

This commit rewrites the tools/perf/scripts/python/syscall-counts-by-pid.py
script to use the new perf Python module. By bypassing the perf script
execution overhead, it improves performance significantly while displaying
system call totals broken down by syscall and optionally filtered by comm or
PID.

> diff --git a/tools/perf/python/syscall-counts-by-pid.py b/tools/perf/python/syscall-counts-by-pid.py
> new file mode 100755
> index 000000000000..ff962334a143
> --- /dev/null
> +++ b/tools/perf/python/syscall-counts-by-pid.py
> @@ -0,0 +1,88 @@
[ ... ]
> +def print_syscall_totals():
[ ... ]
> + print(f"{'comm [pid]/syscalls':<40} {'count':>10}")
> + print("---------------------------------------- -----------")
> +
> + sorted_keys = sorted(syscalls.keys(), key=lambda k: (k[0], k[1], k[2]))

Does this sort order match the expected output?

The commit message demonstrates the syscall output being sorted descending by
frequency count (e.g., 538989, 32, 17, 2, 1).

By sorting on the keys, it looks like the syscalls are printed in ascending
order of their syscall ID instead.

> + current_comm_pid = None
> + for comm, pid, sc_id in sorted_keys:
[ ... ]
> +def process_event(sample):
[ ... ]
> + pid = sample.sample_pid
> +
> + if for_pid and pid != for_pid:

If a user filters by PID 0 (the idle task), will this logic bypass the
filter?

Since for_pid evaluates to False in Python when it is 0, it seems the script
would incorrectly accumulate events for all PIDs instead of restricting them
to PID 0.

> + return
> +
> + comm = "unknown"

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