Re: [PATCH v7 51/59] perf wakeup-latency: Port wakeup-latency to use python module

sashiko-bot
2026-04-25T23:12:47Z

Sashiko AI review found 1 potential issue(s):
- [Medium] Incorrect initialization and reporting of min_wakeup_latency causes misleading statistics.
--

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

perf wakeup-latency: Port wakeup-latency to use python module

This commit ports the legacy Perl script wakeup-latency.pl to a Python script
using the perf.session API. It leverages a class-based architecture to track
timestamps between sched_wakeup and sched_switch events to measure latency.

> diff --git a/tools/perf/python/wakeup-latency.py b/tools/perf/python/wakeup-latency.py
> new file mode 100755
> index 000000000000..1b0db115abcf
> --- /dev/null
> +++ b/tools/perf/python/wakeup-latency.py

[ ... ]

> +class WakeupLatency:
> + """Tracks and displays wakeup latency statistics."""
> + def __init__(self) -> None:
> + self.last_wakeup: Dict[int, int] = defaultdict(int)
> + self.max_wakeup_latency = 0
> + self.min_wakeup_latency = 1000000000

If all recorded wakeup latencies happen to be greater than 1 second
(1,000,000,000 ns), will this hardcoded initialization cause the reported
minimum to be incorrectly capped at 1 second instead of reflecting the actual
minimum latency?

Could this be initialized to float('inf') or the first observed latency
instead?

[ ... ]

> + def print_totals(self) -> None:
> + """Print summary statistics."""
> + print("wakeup_latency stats:\n")
> + print(f"total_wakeups: {self.total_wakeups}")
> + if self.total_wakeups:
> + avg = self.total_wakeup_latency // self.total_wakeups
> + print(f"avg_wakeup_latency (ns): {avg}")
> + else:
> + print("avg_wakeup_latency (ns): N/A")
> + print(f"min_wakeup_latency (ns): {self.min_wakeup_latency}")
> + print(f"max_wakeup_latency (ns): {self.max_wakeup_latency}")

When no wakeups are recorded during the session (total_wakeups == 0),
does this code unconditionally print the initialized values for min and max?

It appears this might result in "min_wakeup_latency (ns): 1000000000" and
"max_wakeup_latency (ns): 0" being printed for an empty trace. Should these
outputs also be moved inside the `if self.total_wakeups:` block or given an
"N/A" fallback?

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