[PATCH 0/5] perf python: Honor more perf script options
From: Jens Remus
Date: Fri Dec 04 2026 - 11:24:55 EST
While updating my own perf scripts for commit b02aa1d1343f ("perf
script: Support standalone scripts and remove embedded scripting") I
noticed that perf script accepts but ignores most of its options when
running a Python script:
$ perf script [<options>] -s ~/my_script.py
Only --vmlinux, --kallsyms, --symfs and --itrace are forwarded to the
script's perf.session, via environment variables. perf.session itself
hard-codes the other symbol settings, and two of them differ from the
perf script defaults: it does not resolve inlined frames, and it reports
the kernel DSO by its vmlinux path. So a script cannot reproduce the
output of plain perf script. Neither the command line nor the script
itself can change these settings, because perf.session has no arguments
for them. I use some of these options, so this series forwards
--inline, --show-kernel-path, --max-stack, --demangle and
--demangle-kernel.
For each option, perf.session gains a keyword argument, so a script can
set it itself. If it is not given, perf.session uses an environment
variable set by perf script from the option, and otherwise the previous
hard-coded value. Scripts run directly only gain the keyword arguments,
their defaults do not change.
Behavior change: Python scripts run by perf script now resolve inlined
frames and report the kernel DSO as "[kernel.kallsyms]", like perf script
does. Use --no-inline and --show-kernel-path to get the old behavior.
Patch 1 also adds callchain_node.inlined, so scripts can tell inlined
frames from the frame they are inlined into. Patch 2 exports this flag
in the SQLite and PostgreSQL export scripts, which adds a column to the
symbols table.
Note: On s390 test_export_to_sqlite_python.sh fails, independent of this
series, because "perf record -g" defaults to --call-graph dwarf there.
The resulting samples exceed sizeof(union perf_event), which commit
2c672ffdad4b ("perf python: Lazily copy events and samples from
process_events") rejects with "Unexpected event size: 4168 < 8536".
Based on v7.4-rc4.
Regards,
Jens
Jens Remus (5):
perf python: Support inlined frames in callchains
perf python: Export inlined symbol flag in DB export scripts
perf python: Honor perf script --show-kernel-path
perf python: Honor perf script --demangle and --demangle-kernel
perf python: Honor perf script --max-stack
.../perf/Documentation/perf-script-python.txt | 11 +-
tools/perf/builtin-script.c | 9 ++
tools/perf/python/export-to-postgresql.py | 32 ++---
tools/perf/python/export-to-sqlite.py | 18 +--
tools/perf/python/perf.pyi | 24 +++-
tools/perf/util/python.c | 119 +++++++++++++++++-
6 files changed, 180 insertions(+), 33 deletions(-)
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
--
2.53.0