[PATCH 0/2] perf script flamegraph: Fix input file name errors

From: Stephen Brennan

Date: Thu Oct 01 2026 - 14:21:47 EST


The flamegraph.py script has a "-i" option which it uses in an attempt to
know the input file name for the data it is processing. But perf itself is
using that flag and not forwarding its value to the script, so the entire
strategy won't work. It's further complicated by how the option processing
is handled in the flamegraph-report script -- details in patch 2.

This series introduces a helper to allow python scripts to see the input
file name, and then fixes flamegraph.py. Testing with a variety of options
like below shows that it is using the correct input files in most use cases
I can think of:

$ export PERF_EXEC_PATH=$(pwd)/tools/perf

$ sudo -E tools/perf/perf script flamegraph -a -F999 -- sleep 1
dumping data to flamegraph.html

$ sudo -E tools/perf/perf script record flamegraph \
-o myfile.data -a -F999 -- sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 2.891 MB myfile.data (1832 samples) ]

$ sudo -E tools/perf/perf script report flamegraph -i myfile.data \
-- -o myfile.html
dumping data to myfile.html

$ sudo -E tools/perf/perf script \
-s tools/perf/scripts/python/flamegraph.py -i myfile.data
dumping data to flamegraph.html

$ sudo -E tools/perf/perf script record flamegraph \
-o - -a -F999 -- sleep 1 \
| tools/perf/perf script report flamegraph -i - -- -o manual.html
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 2.936 MB - ]
dumping data to manual.html


Stephen Brennan (2):
tools: perf: add perf_input_name() helper
tools: perf: flamegraph.py: fix "Error reading report header"

.../perf/Documentation/perf-script-python.txt | 1 +
.../scripts/python/Perf-Trace-Util/Context.c | 16 ++++++++++++++
tools/perf/scripts/python/flamegraph.py | 22 +++++++++----------
3 files changed, 27 insertions(+), 12 deletions(-)

--
2.52.0