Re: [PATCH v2 34/58] perf compaction-times: Port compaction-times to use python module

sashiko-bot
2026-04-23T04:24:34Z

Sashiko AI review found 1 potential issue(s):
- [Medium] Unhandled TypeError in `process_event` causes the script to crash when encountering an unknown PID.
--

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

perf compaction-times: Port compaction-times to use python module

This commit adds a port of the compaction-times script that uses the perf
python module directly. This approach avoids creating intermediate
dictionaries for all event fields, resulting in faster execution.

> diff --git a/tools/perf/python/compaction-times.py b/tools/perf/python/compaction-times.py
> new file mode 100755
> index 0000000000000..153b47930e3cc
> --- /dev/null
> +++ b/tools/perf/python/compaction-times.py

[ ... ]

> +def process_event(sample: perf.sample_event) -> None:
> + """Callback for processing events."""
> + event_name = str(sample.evsel)
> + pid = sample.sample_pid
> + comm = session.process(pid).comm() if session else "[unknown]"

If the thread for a given pid is not found in the machine's thread map,
session.process(pid) raises a TypeError from the underlying C extension.

Because this call is not wrapped in a try-except block, will this crash the
script when it processes an event from a pre-existing process that is
missing a comm event?

Could this be wrapped to catch the exception and fall back to [unknown],
similar to how the original script safely utilized the comm value directly
from the trace event?

> + secs = sample.sample_time // 1000000000
> + nsecs = sample.sample_time % 1000000000

[ ... ]

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