* [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph [not found] <aEeIN_u4KpLZXDBx () google ! com> @ 2025-06-10 4:04 ` Tianyou Li 2025-06-10 4:04 ` [PATCH 2/2] Add -e option to focus on the specific event for generating the flamegraph Tianyou Li 2025-06-24 17:53 ` [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph Namhyung Kim 0 siblings, 2 replies; 4+ messages in thread From: Tianyou Li @ 2025-06-10 4:04 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, Kan Liang, tianyou.li, wangyang.guo, linux-perf-users, linux-kernel 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. 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> --- tools/perf/scripts/python/flamegraph.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/perf/scripts/python/flamegraph.py b/tools/perf/scripts/python/flamegraph.py index cf7ce8229a6c..4f82dfea0a70 100755 --- a/tools/perf/scripts/python/flamegraph.py +++ b/tools/perf/scripts/python/flamegraph.py @@ -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) -- 2.47.1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] Add -e option to focus on the specific event for generating the flamegraph 2025-06-10 4:04 ` [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph Tianyou Li @ 2025-06-10 4:04 ` Tianyou Li 2025-06-24 17:53 ` [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph Namhyung Kim 1 sibling, 0 replies; 4+ messages in thread From: Tianyou Li @ 2025-06-10 4:04 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, Kan Liang, tianyou.li, wangyang.guo, linux-perf-users, linux-kernel 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> --- tools/perf/scripts/python/flamegraph.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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) -- 2.47.1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph 2025-06-10 4:04 ` [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph Tianyou Li 2025-06-10 4:04 ` [PATCH 2/2] Add -e option to focus on the specific event for generating the flamegraph Tianyou Li @ 2025-06-24 17:53 ` Namhyung Kim 2025-06-25 15:24 ` Li, Tianyou 1 sibling, 1 reply; 4+ messages in thread From: Namhyung Kim @ 2025-06-24 17:53 UTC (permalink / raw) To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Tianyou Li Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, Kan Liang, wangyang.guo, linux-perf-users, linux-kernel On Tue, 10 Jun 2025 12:04:22 +0800, Tianyou Li wrote: > 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph 2025-06-24 17:53 ` [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph Namhyung Kim @ 2025-06-25 15:24 ` Li, Tianyou 0 siblings, 0 replies; 4+ messages in thread From: Li, Tianyou @ 2025-06-25 15:24 UTC (permalink / raw) To: Namhyung Kim, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers, Hunter, Adrian, Kan Liang, Guo, Wangyang, linux-perf-users, linux-kernel Appreciated for your kindly review. Thanks. -----Original Message----- From: Namhyung Kim <namhyung@kernel.org> Sent: Wednesday, June 25, 2025 1:53 AM To: Peter Zijlstra <peterz@infradead.org>; Ingo Molnar <mingo@redhat.com>; Arnaldo Carvalho de Melo <acme@kernel.org>; Li, Tianyou <tianyou.li@intel.com> Cc: Mark Rutland <mark.rutland@arm.com>; Alexander Shishkin <alexander.shishkin@linux.intel.com>; Jiri Olsa <jolsa@kernel.org>; Ian Rogers <irogers@google.com>; Hunter, Adrian <adrian.hunter@intel.com>; Kan Liang <kan.liang@linux.intel.com>; Guo, Wangyang <wangyang.guo@intel.com>; linux-perf-users@vger.kernel.org; linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph On Tue, 10 Jun 2025 12:04:22 +0800, Tianyou Li wrote: > 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-25 15:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <aEeIN_u4KpLZXDBx () google ! com>
2025-06-10 4:04 ` [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph Tianyou Li
2025-06-10 4:04 ` [PATCH 2/2] Add -e option to focus on the specific event for generating the flamegraph Tianyou Li
2025-06-24 17:53 ` [PATCH 1/2] Read perf data file header from the file user specified with -i option for perf script flamegraph Namhyung Kim
2025-06-25 15:24 ` Li, Tianyou
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®