[PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph

From: Tianyou Li
Date: Mon Jun 09 2025 - 23:12:39 EST


If specify the perf data file with -i option, the script will try to read the header information
regardless of the file name specified, instead it will try to access the perf.data. This simple
patch use the file name from -i option for command perf report --header-only to read the header.

Signed-off-by: Tianyou Li <tianyou.li@xxxxxxxxx>
Reviewed-by: Pan Deng <pan.deng@xxxxxxxxx>
Reviewed-by: Zhiguo Zhou <zhiguo.zhou@xxxxxxxxx>
Reviewed-by: Wangyang Guo <wangyang.guo@xxxxxxxxx>
Reviewed-by: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>
---
tools/perf/scripts/python/flamegraph.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/scripts/python/flamegraph.py b/tools/perf/scripts/python/flamegraph.py
index cf7ce8229a6c..4f82dfea0a70 100755
--- a/tools/perf/scripts/python/flamegraph.py
+++ b/tools/perf/scripts/python/flamegraph.py
@@ -123,7 +123,13 @@ class FlameGraphCLI:
return ""

try:
- output = subprocess.check_output(["perf", "report", "--header-only"])
+ # if the file name other than perf.data is given,
+ # we read the header of that file
+ if self.args.input:
+ output = subprocess.check_output(["perf", "report", "--header-only", "-i", self.args.input])
+ else:
+ output = subprocess.check_output(["perf", "report", "--header-only"])
+
return output.decode("utf-8")
except Exception as err: # pylint: disable=broad-except
print("Error reading report header: {}".format(err), file=sys.stderr)
--
2.47.1