History

perf script: Handle -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.

Tianyou Li committed 1 year ago

Commit df9c2991 parent 317fa411 file · +7 −1Browse files

Showing the changes to tools/perf/scripts/python/flamegraph.py (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/flamegraph.py+7−1
@@ -123,7 +123,13 @@ class FlameGraphCLI: · 122 unmodified lines
123 return ""123 return ""
124 124
125 try:125 try:
126 output = subprocess.check_output(["perf", "report", "--header-only"])126 # if the file name other than perf.data is given,
127 # we read the header of that file
128 if self.args.input:
129 output = subprocess.check_output(["perf", "report", "--header-only", "-i", self.args.input])
130 else:
131 output = subprocess.check_output(["perf", "report", "--header-only"])
132
127 return output.decode("utf-8")133 return output.decode("utf-8")
128 except Exception as err: # pylint: disable=broad-except134 except Exception as err: # pylint: disable=broad-except
129 print("Error reading report header: {}".format(err), file=sys.stderr)135 print("Error reading report header: {}".format(err), file=sys.stderr)