Skip to content

Commit 5071105

Browse files
committed
perf script: Add -e option to flamegraph script
JIRA: https://issues.redhat.com/browse/RHEL-78200 upstream ======== commit 9a79c50 Author: Tianyou Li <[email protected]> Date: Tue Jun 10 12:04:23 2025 +0800 description =========== 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. Signed-off-by: Tianyou Li <[email protected]> Reviewed-by: Pan Deng <[email protected]> Reviewed-by: Zhiguo Zhou <[email protected]> Reviewed-by: Wangyang Guo <[email protected]> Reviewed-by: Tim Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]> Signed-off-by: Anubhav Shelat <[email protected]>
1 parent ba7b05f commit 5071105

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tools/perf/scripts/python/flamegraph.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ def find_or_create_node(node, name, libtype):
9494
return child
9595

9696
def process_event(self, event):
97+
# ignore events where the event name does not match
98+
# the one specified by the user
99+
if self.args.event_name and event.get("ev_name") != self.args.event_name:
100+
return
101+
97102
pid = event.get("sample", {}).get("pid", 0)
98103
# event["dso"] sometimes contains /usr/lib/debug/lib/modules/*/vmlinux
99104
# for user-space processes; let's use pid for kernel or user-space distinction
@@ -130,7 +135,10 @@ def get_report_header(self):
130135
else:
131136
output = subprocess.check_output(["perf", "report", "--header-only"])
132137

133-
return output.decode("utf-8")
138+
result = output.decode("utf-8")
139+
if self.args.event_name:
140+
result += "\nFocused event: " + self.args.event_name
141+
return result
134142
except Exception as err: # pylint: disable=broad-except
135143
print("Error reading report header: {}".format(err), file=sys.stderr)
136144
return ""
@@ -241,6 +249,11 @@ def trace_end(self):
241249
default=False,
242250
action="store_true",
243251
help="allow unprompted downloading of HTML template")
252+
parser.add_argument("-e", "--event",
253+
default="",
254+
dest="event_name",
255+
type=str,
256+
help="specify the event to generate flamegraph for")
244257

245258
cli_args = parser.parse_args()
246259
cli = FlameGraphCLI(cli_args)

0 commit comments

Comments
 (0)