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

sashiko-bot
2026-04-20T00:30:07Z

Sashiko AI review found 2 potential issue(s):
- [High] Accessing `sample.sample_comm` crashes the script with an AttributeError because the property is not implemented in the `perf` Python C extension.
- [High] Calling `.filter()` on a Python function object causes an AttributeError, crashing the script when a user supplies a filter argument.
--

commit e19ed9f5bdaeeb7d6732e01b049d84fb4e856fc0
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 to improve performance by avoiding intermediate
dictionaries.

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

[ ... ]

> + @classmethod
> + def create_pending(cls, pid: int, comm: str, start_secs: int, start_nsecs: int) -> None:
> + """Create a pending node for a process."""
> + filtered = False
> + try:
> + head = cls.heads[pid]
> + filtered = head.is_filtered()
> + except KeyError:
> + if cls.fobj is not None:
> + filtered = cls.fobj.filter(pid, comm)

Does calling .filter() on cls.fobj cause an AttributeError?

The helper functions get_comm_filter() and get_pid_filter() return standard
Python closures (functions) rather than class instances.

Since a function object does not have a .filter() method, it appears this
will crash the script when a user supplies a filter argument.

Should this be invoked directly as cls.fobj(pid, comm)?

> + head = cls.heads[pid] = Chead(comm, pid, filtered)
> +
> + if not filtered:
> + head.mark_pending(start_secs, start_nsecs)

[ ... ]

> +def process_event(sample: perf.sample_event) -> None:
> + """Callback for processing events."""
> + event_name = str(sample.evsel)
> + pid = sample.sample_pid
> + comm = sample.sample_comm

Will accessing sample.sample_comm crash the script with an AttributeError?

The perf Python C extension does not implement a sample_comm member or
getter in pyrf_sample_event__members or pyrf_sample_event__getset.

The underlying tracepoint exposes the command line string as common_comm,
which can be accessed via dynamic tracepoint field resolution.

Because this property is missing, accessing it will raise an AttributeError
on the first processed event.

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

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