All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] perf python: Add a script to open profiles in the Perfetto UI
@ 2026-11-15  0:39 Lalit Maganti
  2026-11-15  0:39 ` [PATCH 1/4] perf python: Add kernel attribute to callchain_node Lalit Maganti
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Lalit Maganti @ 2026-11-15  0:39 UTC (permalink / raw)
  To: acme, namhyung, irogers
  Cc: adrian.hunter, james.clark, jolsa, mark.rutland,
	alexander.shishkin, peterz, mingo, linux-perf-users, linux-kernel,
	Lalit Maganti

This series adds a perf script that converts the samples in a perf.data
file to a Perfetto trace and opens it in the Perfetto UI
(https://ui.perfetto.dev):

  $ perf record -g -- ./workload
  $ perf script perfetto

Unlike a flame graph, the trace keeps the time of every sample, so you
can see what each thread was running over time, get a flame graph for
any time range, thread or process, and query the samples with SQL.

The samples are written as Perfetto StackSample packets [1]. The few
protobuf messages needed are encoded by hand, so the script only needs
the Python standard library.

 - Patches 1 and 2 add what the script needs from the perf module:
   whether a frame is in the kernel, and the clock from perf record -k.
 - Patch 3 adds the script and a shell test.
 - Patch 4 compresses the trace (zstd, or gzip on Python < 3.14), which
   makes it 3-4x smaller.

I compared the output with perf report and perf script --no-inline
(the perf module doesn't expand inlined frames) on x86 and arm64. The
samples, their periods and their callchains match for:
 - cpu-clock, cycles and {cycles,instructions} groups
 - recordings with and without callchains
 - perf record -k CLOCK_MONOTONIC and CLOCK_BOOTTIME
 - pipe mode (perf record -o - | perf script perfetto -i -)
 - system-wide recording on arm64

DWARF callchains need a separate fix to the perf module, "perf python:
Accept events larger than union perf_event" [2]. Without it, the script
exits with an error on --call-graph dwarf recordings.

[1] https://github.com/google/perfetto/blob/main/protos/perfetto/trace/profiling/stack_sample.proto
[2] https://lore.kernel.org/linux-perf-users/20261018074528.974953-1-lalitmaganti@gmail.com/

Lalit Maganti (4):
  perf python: Add kernel attribute to callchain_node
  perf python: Add clockid attribute to session
  perf python: Add perfetto script to open profiles in the Perfetto UI
  perf python: Compress the traces of the perfetto script

 tools/perf/python/perf.pyi                |   2 +
 tools/perf/python/perfetto.py             | 675 ++++++++++++++++++++++
 tools/perf/tests/shell/script_perfetto.sh |  98 ++++
 tools/perf/util/python.c                  |  17 +
 4 files changed, 792 insertions(+)
 create mode 100755 tools/perf/python/perfetto.py
 create mode 100755 tools/perf/tests/shell/script_perfetto.sh


base-commit: a1c3b14c28ebfa79dd56e2743c2fbad0c02a7146
-- 
2.56.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-15  0:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15  0:39 [PATCH 0/4] perf python: Add a script to open profiles in the Perfetto UI Lalit Maganti
2026-11-15  0:39 ` [PATCH 1/4] perf python: Add kernel attribute to callchain_node Lalit Maganti
2026-11-15  0:45   ` sashiko-bot
2026-11-15  0:39 ` [PATCH 2/4] perf python: Add clockid attribute to session Lalit Maganti
2026-11-15  0:44   ` sashiko-bot
2026-11-15  0:39 ` [PATCH 3/4] perf python: Add perfetto script to open profiles in the Perfetto UI Lalit Maganti
2026-11-15  0:53   ` sashiko-bot
2026-11-15  0:39 ` [PATCH 4/4] perf python: Compress the traces of the perfetto script Lalit Maganti
2026-11-15  0:45   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.