Re: [PATCH v5 33/58] perf check-perf-trace: Port check-perf-trace to use python module

sashiko-bot
2026-04-24T17:14:36Z

Sashiko AI review found 2 potential issue(s):
- [High] The script crashes with an unhandled TypeError if an event's thread is not found in the thread map, and incorrectly uses sample_pid instead of sample_tid.
- [Medium] Substring matching incorrectly routes `kmem:kmalloc_node` events to the `kmem:kmalloc` handler.
--

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

perf check-perf-trace: Port check-perf-trace to use python module

This commit adds a port of the check-perf-trace script that uses the perf
python module directly. This approach is significantly faster than using perf
script callbacks as it avoids creating intermediate dictionaries for all
event fields.

> diff --git a/tools/perf/python/check-perf-trace.py b/tools/perf/python/check-perf-trace.py
> new file mode 100755
> index 00000000000000..4c05540bdc057b
> --- /dev/null
> +++ b/tools/perf/python/check-perf-trace.py

[ ... ]

> +def print_header(event_name: str, sample: perf.sample_event) -> None:
> + """Prints common header for events."""
> + secs = sample.sample_time // 1000000000
> + nsecs = sample.sample_time % 1000000000
> + comm = session.process(sample.sample_pid).comm() if session else "[unknown]"

Could this crash when encountering short-lived or untracked threads?

The underlying Python C extension raises a TypeError if the thread is not
found in the thread map.

Should this also use sample.sample_tid instead of sample.sample_pid to
correctly look up non-leader threads?

> + print(f"{event_name:<20} {sample.sample_cpu:5} {secs:05}.{nsecs:09} "
> + f"{sample.sample_pid:8} {comm:<20} ", end=' ')

[ ... ]

> +def process_event(sample: perf.sample_event) -> None:
> + """Callback for processing events."""
> + event_name = str(sample.evsel)
> + if event_name == "evsel(irq:softirq_entry)":
> + irq__softirq_entry(sample)
> + elif "evsel(kmem:kmalloc)" in event_name:

Will this substring match inadvertently catch evsel(kmem:kmalloc_node) events?

Using exact equality, similar to the irq:softirq_entry check above, might
prevent kmalloc_node events from bypassing trace_unhandled() and misreporting
the event type while silently dropping their node field.

> + kmem__kmalloc(sample)
> + else:
> + trace_unhandled(event_name)

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