summaryrefslogtreecommitdiff
path: root/tools/perf/scripts/python/flamegraph.py
diff options
context:
space:
mode:
authorTianyou Li <tianyou.li@intel.com>2025-06-10 12:04:23 +0800
committerNamhyung Kim <namhyung@kernel.org>2025-06-24 10:27:51 -0700
commit9a79c50c2a95887859d5ac133180775b708b850a (patch)
tree31075fd8fe517e8af76a6d158e6043662f4acd2f /tools/perf/scripts/python/flamegraph.py
parentdf9c299371054cb725eef730fd0f1d0fe2ed6bb0 (diff)
perf script: Add -e option to flamegraph script
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 <tianyou.li@intel.com> Reviewed-by: Pan Deng <pan.deng@intel.com> Reviewed-by: Zhiguo Zhou <zhiguo.zhou@intel.com> Reviewed-by: Wangyang Guo <wangyang.guo@intel.com> Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com> Link: https://lore.kernel.org/r/20250610040536.2390060-2-tianyou.li@intel.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools/perf/scripts/python/flamegraph.py')
-rwxr-xr-xtools/perf/scripts/python/flamegraph.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tools/perf/scripts/python/flamegraph.py b/tools/perf/scripts/python/flamegraph.py
index 4f82dfea0a70..e49ff242b779 100755
--- a/tools/perf/scripts/python/flamegraph.py
+++ b/tools/perf/scripts/python/flamegraph.py
@@ -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)