# flamegraph.py - create flame graphs from perf samples # SPDX-License-Identifier: GPL-2.0 # # Usage: # # perf record -a -g -F 99 sleep 60 # perf script report flamegraph # # Combined: # # perf script flamegraph -a -F 99 sleep 60 # # Written by Andreas Gerstmayr # Flame Graphs invented by Brendan Gregg # Works in tandem with d3-flame-graph by Martin Spier from __future__ import print_function import sys import os import io import argparse import json class Node: def __init__(self, name, libtype=""): self.name = name self.libtype = libtype self.value = 0 self.children = [] def toJSON(self): return { "n": self.name, "l": self.libtype, "v": self.value, "c": self.children } class FlameGraphCLI: def __init__(self, args): self.args = args self.stack = Node("root") if self.args.format == "html" and \ not os.path.isfile(self.args.template): print("Flame Graph template {} does not exist. Please install " "the js-d3-flame-graph (RPM) or libjs-d3-flame-graph (deb) " "package, specify an existing flame graph template " "(--template PATH) or another output format " "(--format FORMAT).".format(self.args.template), file=sys.stderr) sys.exit(1) def find_or_create_node(self, node, name, dso): libtype = "kernel" if dso == "[kernel.kallsyms]" else "" if name is None: name = "[unknown]" for child in node.children: if child.name == name and child.libtype == libtype: return child child = Node(name, libtype) node.children.append(child) return child def process_event(self, event): node = self.find_or_create_node(self.stack, event["comm"], None) if "callchain" in event: for entry in reversed(event['callchain']): node = self.find_or_create_node( node, entry.get("sym", {}).get("name"), event.get("dso")) else: node = self.find_or_create_node( node, entry.get("symbol"), event.get("dso")) node.value += 1 def trace_end(self): json_str = json.dumps(self.stack, default=lambda x: x.toJSON()) if self.args.format == "html": try: with io.open(self.args.template, encoding="utf-8") as f: output_str = f.read().replace("/** @flamegraph_json **/", json_str) except IOError as e: print("Error reading template file: {}".format(e), file=sys.stderr) sys.exit(1) output_fn = self.args.output or "flamegraph.html" else: output_str = json_str output_fn = self.args.output or "stacks.json" if output_fn == "-": with io.open(sys.stdout.fileno(), "w", encoding="utf-8", closefd=False) as out: out.write(output_str) else: print("dumping data to {}".format(output_fn)) try: with io.open(output_fn, "w", encoding="utf-8") as out: out.write(output_str) except IOError as e: print("Error writing output file: {}".format(e), file=sys.stderr) sys.exit(1) if __name__ == "__main__": parser = argparse.ArgumentParser(description="Create flame graphs.") parser.add_argument("-f", "--format", default="html", choices=["json", "html"], help="output file format") parser.add_argument("-o", "--output", help="output file name") parser.add_argument("--template", default="/usr/share/d3-flame-graph/d3-flamegraph-base.html", help="path to flamegraph HTML template") parser.add_argument("-i", "--input", help=argparse.SUPPRESS) args = parser.parse_args() cli = FlameGraphCLI(args) process_event = cli.process_event trace_end = cli.trace_end Hosts the 0x221E linux distro kernel.Ubuntu
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2024-11-29Merge tag 'char-misc-6.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/g...Linus Torvalds
2024-11-12firmware: Switch back to struct platform_driver::remove()Uwe Kleine-König
2024-10-02firmware: xilinx: fix feature check logic for TF-A specific APIsRonak Jain
2024-10-02firmware: xilinx: add support for new SMC call formatRonak Jain
2024-10-02firmware: xilinx: add a warning print for unsupported featureRonak Jain
2024-10-02firmware: xilinx: use u32 for reset ID in reset APIsRonak Jain
2024-10-02firmware: xilinx: Add missing debug firmware interfacesRonak Jain
2024-06-03firmware: xilinx: Move FIRMWARE_VERSION_MASK to xlnx-zynqmp.hRonak Jain
2024-03-07firmware: xilinx: Add ZynqMP efuse access APIPraveen Teja Kundanala
2024-01-04firmware: xilinx: Export function to use in other moduleJay Buddhabhatti
2024-01-04firmware: zynqmp: Convert to platform remove callback returning voidUwe Kleine-König
2023-12-15firmware: xilinx: Remove zynqmp_pm_pinctrl_get_function()Michal Simek
2023-12-15firmware: xilinx: Remove clock_setrate and clock_getrate apiMichal Simek
2023-12-07firmware: zynqmp: Add support to handle IPI CRC failureJay Buddhabhatti
2023-12-07drivers: soc: xilinx: Fix error message on SGI registration failureJay Buddhabhatti
2023-12-07firmware: xilinx: Register event manager driverJay Buddhabhatti
2023-12-07firmware: xilinx: Expand feature check to support all PLM modulesJay Buddhabhatti
2023-12-07firmware: xilinx: Update firmware call interface to support additional argsJay Buddhabhatti
2023-12-07firmware: xilinx: Use proper indentation in kernel-docMichal Simek
2023-10-27firmware: xilinx: Move EXPORT_SYMBOL_GPL next to zynqmp_pm_feature definitionRajan Vaja
2023-08-30Merge tag 'pinctrl-v6.6-1' of git://git.kernel.org/pub/scm/linux/kernel/git/l...Linus Torvalds
2023-08-12firmware: Explicitly include correct DT includesRob Herring
2023-08-07firmware: xilinx: Add version check for TRISTATE configurationSai Krishna Potthuri
2023-08-07firmware: xilinx: Add support to get platform informationDhaval Shah
2023-07-03Merge tag 'char-misc-6.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/gi...Linus Torvalds
2023-05-31firmware: xilinx: Switch Michal Simek's email to new oneMichal Simek
2023-05-12firmware: xilinx: Update the zynqmp_pm_fpga_load() APINava kishore Manne
2023-03-20Merge 6.3-rc3 into char-misc-nextGreg Kroah-Hartman
2023-03-09firmware: xilinx: don't make a sleepable memory allocation from an atomic con...Roman Gushchin
2023-03-09firmware: xilinx: Add pm api function for PL config reg readbackNava kishore Manne
2023-01-05firmware: xilinx: Clear IOCTL_SET_SD_TAPDELAY using PM_MMIO_WRITEMarek Vasut
2022-12-21Merge tag 'rproc-v6.2' of git://git.kernel.org/pub/scm/linux/kernel/git/remot...Linus Torvalds
2022-11-25firmware: xilinx: Add RPU configuration APIsBen Levinsky
2022-11-25firmware: xilinx: Add shutdown/wakeup APIsBen Levinsky
2022-10-19firmware: xilinx: Add qspi firmware interfaceRajan Vaja