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

sashiko-bot
2026-04-24T17:07:35Z

Sashiko AI review found 2 potential issue(s):
- [Medium] PID filtering silently fails and ignores the filter when the target PID is 0.
- [Low] The module docstring contradicts the implemented filtering capabilities.
--

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

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

This commit rewrites the syscall-counts-by-pid.py script to utilize the perf
python module directly. By bypassing the overhead of standard perf script
execution, it yields significant performance improvements.

> 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 00000000000000..45a98e6e8e0116
> --- /dev/null
> +++ b/tools/perf/python/syscall-counts-by-pid.py
> @@ -0,0 +1,88 @@
> +#!/usr/bin/env python3
> +# SPDX-License-Identifier: GPL-2.0
> +"""
> +Displays system-wide system call totals, broken down by syscall.
> +If a [comm] arg is specified, only syscalls called by [comm] are displayed.
> +"""

This isn't a bug, but the docstring only mentions filtering by comm. Should
it be updated to also document the PID filtering capability that the script
provides?

[ ... ]

> +def process_event(sample):
> + """Process a single sample event."""

[ ... ]

> + pid = sample.sample_pid
> +
> + if for_pid and pid != for_pid:
> + return

Does this filtering logic work correctly when targeting PID 0 (the
swapper/idle process)?

In Python, the integer 0 evaluates as false, which means the condition
evaluates to false and bypasses the check entirely when filtering for PID 0.
As a result, the script aggregates syscalls for all processes rather than
filtering just for PID 0.

Would it be better to explicitly check if for_pid is not None to ensure PID 0
is properly filtered?

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