Re: [PATCH 0/2] perf script flamegraph: Fix input file name errors
From: Stephen Brennan
Date: Fri Oct 02 2026 - 14:29:01 EST
Ian Rogers <irogers@xxxxxxxxxx> writes:
> On Thu, Oct 1, 2026 at 11:20 AM Stephen Brennan
> <stephen.s.brennan@xxxxxxxxxx> wrote:
>>
>> 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
>
> Hi Stephen,
>
> Thank you for the contribution! Unfortunately we recently deleted all
> of this code in this series:
> https://lore.kernel.org/linux-perf-users/20260926062029.800743-1-irogers@xxxxxxxxxx/
> You can find the latest code in the perf-tools-next branch:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/
Hi Ian,
Thanks, I should have checked there first.
> The flamegraph code that now uses perf's python module is here:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/python/flamegraph.py?h=perf-tools-next
That looks exciting! It makes things a lot easier to have perf as a
regular Python module rather than wrapping the interpreter. It will be
tricky for Oracle Linux which allows parallel installation of perf
versions, but I guess we made our own bed there :)
> and we even have some tests now:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/shell/test_flamegraph_python.sh?h=perf-tools-next
>
> You may also like to play with the console flamegraph that is part of treport:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/python/treport.py?h=perf-tools-next
This is quite slick! I'll definitely be playing more with the python
module.
Thanks,
Stephen
> Thanks,
> Ian
>
>
>> 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
>>