linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tcwzxx <tcwzxx@gmail.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	alexander.shishkin@linux.intel.com, jolsa@kernel.org
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	tcwzxx <tcwzxx@gmail.com>
Subject: [PATCH] perf tool: add skip_not_exec_file_map_events option
Date: Wed, 17 Aug 2022 13:43:24 +0000	[thread overview]
Message-ID: <20220817134324.702278-1-tcwzxx@gmail.com> (raw)

When generate the flame graph, the perf-script subcommand will
process all mmap event and add them to the rbtree. The 240,000
mmap region takes about 5 minutes, which is not useful for flame
graph. So add the skip-not-exec-file-map-events option to skip
not PROT_EXEC flag memory regions.

Signed-off-by: tcwzxx <tcwzxx@gmail.com>
---
 tools/perf/builtin-report.c | 2 ++
 tools/perf/builtin-script.c | 3 +++
 tools/perf/util/machine.c   | 3 +++
 tools/perf/util/map.c       | 5 +++++
 tools/perf/util/map.h       | 2 ++
 5 files changed, 15 insertions(+)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 91ed41cc7d88..c28eb9450a66 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1364,6 +1364,8 @@ int cmd_report(int argc, const char **argv)
 		    "Disable raw trace ordering"),
 	OPT_BOOLEAN(0, "skip-empty", &report.skip_empty,
 		    "Do not display empty (or dummy) events in the output"),
+	OPT_BOOLEAN(0, "skip-not-exec-file-map_events", &skip_not_exec_file_map_events,
+		    "skip not exec map events"),
 	OPT_END()
 	};
 	struct perf_data data = {
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 13580a9c50b8..e3f4e5e654c9 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -32,6 +32,7 @@
 #include "util/time-utils.h"
 #include "util/path.h"
 #include "util/event.h"
+#include "util/map.h"
 #include "ui/ui.h"
 #include "print_binary.h"
 #include "archinsn.h"
@@ -3936,6 +3937,8 @@ int cmd_script(int argc, const char **argv)
 		    "Guest code can be found in hypervisor process"),
 	OPT_BOOLEAN('\0', "stitch-lbr", &script.stitch_lbr,
 		    "Enable LBR callgraph stitching approach"),
+	OPT_BOOLEAN(0, "skip-not-exec-map_events", &skip_not_exec_file_map_events,
+		    "skip not exec map events"),
 	OPTS_EVSWITCH(&script.evswitch),
 	OPT_END()
 	};
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 2a16cae28407..21dde9f9935c 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1904,6 +1904,9 @@ int machine__process_mmap2_event(struct machine *machine,
 	if (thread == NULL)
 		goto out_problem;
 
+	if (skip_not_exec_file_map_events && !(event->mmap2.prot & PROT_EXEC))
+		goto out_problem;
+
 	map = map__new(machine, event->mmap2.start,
 			event->mmap2.len, event->mmap2.pgoff,
 			&dso_id, event->mmap2.prot,
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index e0aa4a254583..2b51ca012c91 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -16,6 +16,8 @@
 #include "thread.h"
 #include "vdso.h"
 
+bool skip_not_exec_file_map_events;
+
 static inline int is_android_lib(const char *filename)
 {
 	return strstarts(filename, "/data/app-lib/") ||
@@ -168,6 +170,9 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
 		if (dso == NULL)
 			goto out_delete;
 
+		if (skip_not_exec_file_map_events && dso__type(dso, machine) == DSO__TYPE_UNKNOWN)
+			goto out_delete;
+
 		map__init(map, start, start + len, pgoff, dso);
 
 		if (anon || no_dso) {
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 3dcfe06db6b3..67b0e0f9f0ae 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -11,6 +11,8 @@
 #include <stdbool.h>
 #include <linux/types.h>
 
+extern bool skip_not_exec_file_map_events;
+
 struct dso;
 struct maps;
 struct machine;
-- 
2.34.1


             reply	other threads:[~2022-08-17 13:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-17 13:43 tcwzxx [this message]
2022-08-17 18:13 ` [PATCH] perf tool: add skip_not_exec_file_map_events option Ian Rogers
2022-08-18  3:26   ` lika you
2022-08-18 15:00     ` Ian Rogers
2022-08-19  3:18       ` zhizhi xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220817134324.702278-1-tcwzxx@gmail.com \
    --to=tcwzxx@gmail.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).