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

sashiko-bot
2026-04-25T18:10:37Z

Sashiko AI review found 2 potential issue(s):
- [Medium] The script crashes with a TypeError when encountering an untracked thread.
- [Medium] The script improperly aggregates by Process ID (TGID) instead of Thread ID (TID), changing behavior and exacerbating thread lookup failures.
--

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

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

This commit adds a Python port of the compaction-times script that directly
uses the perf python module. This approach is intended to be faster by
avoiding the creation of intermediate dictionaries for all event fields.

> diff --git a/tools/perf/python/compaction-times.py b/tools/perf/python/compaction-times.py
> new file mode 100755
> --- /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

Does using sample.sample_pid instead of sample.sample_tid change the
script's aggregation behavior from per-thread to per-process? The
original script used common_pid, which typically corresponds to the
thread ID.

> + comm = session.find_thread(pid).comm() if session else "[unknown]"

Could this crash the script if it encounters an untracked or short-lived
thread?

When session.find_thread() fails to locate a thread in the machine's
thread map, it explicitly throws a TypeError. Because this exception is
not caught here, a missing thread could cause a fatal Python exception,
halting the entire trace processing.

Additionally, passing the TGID from sample_pid instead of the TID might
exacerbate this issue if a child thread triggers the event and the main
thread's metadata is absent.

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

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