Read perf data file header from the file user specified with -i option for perf script flamegraph
A message that is not in the archive (sent off-list or not yet received): aEeIN_u4KpLZXDBx () google ! com
PATCH 1/2 Read perf data file header from the file user specified with -i option for perf script flamegraph
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.
--- tools/perf/scripts/python/flamegraph.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/scripts/python/flamegraph.py +7 -1
@@ -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)
Signature · 1 line
2.47.1
PATCH 2/2 Add -e option to focus on the specific event for generating the flamegraph
When processing the perf data file generated with multiple events, the flamegraph script will count all the events regardless of different event names.
This patch tries to add a -e option to specify the event name that the flamegraph will be generated accordingly. If the -e option omitted, the behavior remains unchanged.
--- tools/perf/scripts/python/flamegraph.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
tools/perf/scripts/python/flamegraph.py +14 -1
@@ -94,6 +94,11 @@ class FlameGraphCLI: return child def process_event(self, event): + # ignore events where the event name does not match + # the one specified by the user + if self.args.event_name and event.get("ev_name") != self.args.event_name: + return + pid = event.get("sample", {}).get("pid", 0) # event["dso"] sometimes contains /usr/lib/debug/lib/modules/*/vmlinux # for user-space processes; let's use pid for kernel or user-space distinction
@@ -130,7 +135,10 @@ class FlameGraphCLI: else: output = subprocess.check_output(["perf", "report", "--header-only"]) - return output.decode("utf-8") + result = output.decode("utf-8") + if self.args.event_name: + result += "\nFocused event: " + self.args.event_name + return result except Exception as err: # pylint: disable=broad-except print("Error reading report header: {}".format(err), file=sys.stderr) return ""
@@ -241,6 +249,11 @@ if __name__ == "__main__": default=False, action="store_true", help="allow unprompted downloading of HTML template") + parser.add_argument("-e", "--event", + default="", + dest="event_name", + type=str, + help="specify the event to generate flamegraph for") cli_args = parser.parse_args() cli = FlameGraphCLI(cli_args)
Signature · 1 line
2.47.1
Quoted 5 lines · Tianyou Li
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.
Applied to perf-tools-next, thanks!
Best regards,
Namhyung
Li, Tianyou
AppliedAppreciated for your kindly review. Thanks.
-----Original Message-----
From: Namhyung Kim <[email protected]>
Sent: Wednesday, June 25, 2025 1:53 AM
To: Peter Zijlstra <[email protected]>; Ingo Molnar <[email protected]>; Arnaldo Carvalho de Melo <[email protected]>; Li, Tianyou <[email protected]>
Cc: Mark Rutland <[email protected]>; Alexander Shishkin <[email protected]>; Jiri Olsa <[email protected]>; Ian Rogers <[email protected]>; Hunter, Adrian <[email protected]>; Kan Liang <[email protected]>; Guo, Wangyang <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph
Quoted 5 lines · Tianyou Li
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.
Applied to perf-tools-next, thanks!
Best regards,
Namhyung