From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Masahiro Yamada <masahiroy@kernel.org>,
Arnd Bergmann <arnd@arndb.de>, Jann Horn <jannh@google.com>,
Colin Ian King <colin.i.king@gmail.com>,
Casey Chen <cachen@purestorage.com>,
Athira Rajeev <atrajeev@linux.vnet.ibm.com>,
Chaitanya S Prakash <chaitanyas.prakash@arm.com>,
James Clark <james.clark@linaro.org>,
Ze Gao <zegao2021@gmail.com>,
Yang Jihong <yangjihong1@huawei.com>,
Yunseong Kim <yskelg@gmail.com>,
Weilin Wang <weilin.wang@intel.com>,
Dominique Martinet <asmadeus@codewreck.org>,
Anne Macedo <retpolanne@posteo.net>,
Sun Haiyong <sunhaiyong@loongson.cn>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1 12/13] perf inject: Lazy build-id mmap2 event insertion
Date: Fri, 16 Aug 2024 23:44:41 -0700 [thread overview]
Message-ID: <20240817064442.2152089-13-irogers@google.com> (raw)
In-Reply-To: <20240817064442.2152089-1-irogers@google.com>
Add -B option that lazily inserts mmap2 events thereby dropping all
mmap events without samples. This is similar to the behavior of -b
where only build_id events are inserted when a dso is accessed in a
sample.
File size savings can be significant in system-wide mode, consider:
```
$ perf record -g -a -o perf.data sleep 1
$ perf inject -B -i perf.data -o perf.new.data
$ ls -al perf.data perf.new.data
5147049 perf.data
2248493 perf.new.data
```
Give test coverage of the new option in pipe test.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/builtin-inject.c | 62 +++++++++++++++++++++++------
tools/perf/tests/shell/pipe_test.sh | 1 +
tools/perf/util/map.c | 1 +
tools/perf/util/map.h | 11 +++++
4 files changed, 63 insertions(+), 12 deletions(-)
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 86425cade30e..2ff246f56a44 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -108,6 +108,7 @@ enum build_id_rewrite_style {
BID_RWS__INJECT_HEADER_LAZY,
BID_RWS__INJECT_HEADER_ALL,
BID_RWS__MMAP2_BUILDID_ALL,
+ BID_RWS__MMAP2_BUILDID_LAZY,
};
struct perf_inject {
@@ -527,7 +528,8 @@ static int perf_event__repipe_common_mmap(const struct perf_tool *tool,
* Remember the evsel for lazy build id generation. It is used
* for the sample id header type.
*/
- if (inject->build_id_style == BID_RWS__INJECT_HEADER_LAZY &&
+ if ((inject->build_id_style == BID_RWS__INJECT_HEADER_LAZY ||
+ inject->build_id_style == BID_RWS__MMAP2_BUILDID_LAZY) &&
!inject->mmap_evsel)
inject->mmap_evsel = evlist__event2evsel(inject->session->evlist, event);
@@ -560,6 +562,9 @@ static int perf_event__repipe_common_mmap(const struct perf_tool *tool,
}
}
dso__put(dso);
+ if (inject->build_id_style == BID_RWS__MMAP2_BUILDID_LAZY)
+ return 0;
+
return perf_event__repipe(tool, event, sample, machine);
}
@@ -825,7 +830,8 @@ static int dso__inject_mmap2_build_id(const struct perf_tool *tool,
return 0;
}
-static int mark_dso_hit(const struct perf_tool *tool,
+static int mark_dso_hit(const struct perf_inject *inject,
+ const struct perf_tool *tool,
struct perf_sample *sample,
struct machine *machine,
const struct evsel *mmap_evsel,
@@ -854,16 +860,39 @@ static int mark_dso_hit(const struct perf_tool *tool,
}
}
dso = map__dso(map);
- if (dso && !dso__hit(dso)) {
- dso__set_hit(dso);
- dso__inject_build_id(tool, sample, machine,
- mmap_evsel, misc, dso__long_name(dso), dso,
- map__flags(map));
+ if (inject->build_id_style == BID_RWS__INJECT_HEADER_LAZY) {
+ if (dso && !dso__hit(dso)) {
+ dso__set_hit(dso);
+ dso__inject_build_id(tool, sample, machine,
+ mmap_evsel, misc, dso__long_name(dso), dso,
+ map__flags(map));
+ }
+ } else if (inject->build_id_style == BID_RWS__MMAP2_BUILDID_LAZY) {
+ if (!map__hit(map)) {
+ const struct build_id null_bid = { .size = 0 };
+ const struct build_id *bid = dso ? dso__bid(dso) : &null_bid;
+ const char *filename = dso ? dso__long_name(dso) : "";
+
+ map__set_hit(map);
+ perf_event__synthesize_mmap2_build_id(tool, sample, machine,
+ perf_event__repipe,
+ mmap_evsel,
+ misc,
+ sample->pid, sample->tid,
+ map__start(map),
+ map__end(map) - map__start(map),
+ map__pgoff(map),
+ bid,
+ map__prot(map),
+ map__flags(map),
+ filename);
+ }
}
return 0;
}
struct mark_dso_hit_args {
+ const struct perf_inject *inject;
const struct perf_tool *tool;
struct perf_sample *sample;
struct machine *machine;
@@ -875,7 +904,7 @@ static int mark_dso_hit_callback(struct callchain_cursor_node *node, void *data)
struct mark_dso_hit_args *args = data;
struct map *map = node->ms.map;
- return mark_dso_hit(args->tool, args->sample, args->machine,
+ return mark_dso_hit(args->inject, args->tool, args->sample, args->machine,
args->mmap_evsel, map, /*sample_in_dso=*/false);
}
@@ -888,6 +917,7 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e
struct thread *thread;
struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
struct mark_dso_hit_args args = {
+ .inject = inject,
.tool = tool,
/*
* Use the parsed sample data of the sample event, which will
@@ -907,7 +937,7 @@ int perf_event__inject_buildid(const struct perf_tool *tool, union perf_event *e
}
if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
- mark_dso_hit(tool, sample, machine, args.mmap_evsel, al.map,
+ mark_dso_hit(inject, tool, sample, machine, args.mmap_evsel, al.map,
/*sample_in_dso=*/true);
}
@@ -2151,7 +2181,8 @@ static int __cmd_inject(struct perf_inject *inject)
output_data_offset = perf_session__data_offset(session->evlist);
- if (inject->build_id_style == BID_RWS__INJECT_HEADER_LAZY) {
+ if (inject->build_id_style == BID_RWS__INJECT_HEADER_LAZY ||
+ inject->build_id_style == BID_RWS__MMAP2_BUILDID_LAZY) {
inject->tool.sample = perf_event__inject_buildid;
} else if (inject->sched_stat) {
struct evsel *evsel;
@@ -2334,6 +2365,7 @@ int cmd_inject(int argc, const char **argv)
const char *known_build_ids = NULL;
bool build_ids;
bool build_id_all;
+ bool mmap2_build_ids;
bool mmap2_build_id_all;
struct option options[] = {
@@ -2341,6 +2373,8 @@ int cmd_inject(int argc, const char **argv)
"Inject build-ids into the output stream"),
OPT_BOOLEAN(0, "buildid-all", &build_id_all,
"Inject build-ids of all DSOs into the output stream"),
+ OPT_BOOLEAN('B', "mmap2-buildids", &mmap2_build_ids,
+ "Drop unused mmap events, make others mmap2 with build IDs"),
OPT_BOOLEAN(0, "mmap2-buildid-all", &mmap2_build_id_all,
"Rewrite all mmap events as mmap2 events with build IDs"),
OPT_STRING(0, "known-build-ids", &known_build_ids,
@@ -2439,6 +2473,8 @@ int cmd_inject(int argc, const char **argv)
return -1;
}
}
+ if (mmap2_build_ids)
+ inject.build_id_style = BID_RWS__MMAP2_BUILDID_LAZY;
if (mmap2_build_id_all)
inject.build_id_style = BID_RWS__MMAP2_BUILDID_ALL;
if (build_ids)
@@ -2458,7 +2494,8 @@ int cmd_inject(int argc, const char **argv)
repipe = false;
}
ordered_events = inject.jit_mode || inject.sched_stat ||
- (inject.build_id_style == BID_RWS__INJECT_HEADER_LAZY);
+ inject.build_id_style == BID_RWS__INJECT_HEADER_LAZY ||
+ inject.build_id_style == BID_RWS__MMAP2_BUILDID_LAZY;
perf_tool__init(&inject.tool, ordered_events);
inject.tool.sample = perf_event__repipe_sample;
inject.tool.read = perf_event__repipe_sample;
@@ -2530,7 +2567,8 @@ int cmd_inject(int argc, const char **argv)
goto out_delete;
}
- if (inject.build_id_style == BID_RWS__INJECT_HEADER_LAZY) {
+ if (inject.build_id_style == BID_RWS__INJECT_HEADER_LAZY ||
+ inject.build_id_style == BID_RWS__MMAP2_BUILDID_LAZY) {
/*
* to make sure the mmap records are ordered correctly
* and so that the correct especially due to jitted code
diff --git a/tools/perf/tests/shell/pipe_test.sh b/tools/perf/tests/shell/pipe_test.sh
index 1cacd6f15bcb..9b1fcbfeb837 100755
--- a/tools/perf/tests/shell/pipe_test.sh
+++ b/tools/perf/tests/shell/pipe_test.sh
@@ -90,6 +90,7 @@ test_inject_bids() {
}
test_record_report
+test_inject_bids -B
test_inject_bids -b
test_inject_bids --buildid-all
test_inject_bids --mmap2-buildid-all
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index e781c8d56a9a..d729438b7d65 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -116,6 +116,7 @@ static void map__init(struct map *map, u64 start, u64 end, u64 pgoff,
map__set_mapping_type(map, MAPPING_TYPE__DSO);
assert(map__erange_warned(map) == false);
assert(map__priv(map) == false);
+ assert(map__hit(map) == false);
}
struct map *map__new(struct machine *machine, u64 start, u64 len,
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 6c43f31a9fe0..4262f5a143be 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -35,6 +35,7 @@ DECLARE_RC_STRUCT(map) {
enum mapping_type mapping_type:8;
bool erange_warned;
bool priv;
+ bool hit;
};
struct kmap;
@@ -83,6 +84,11 @@ static inline bool map__priv(const struct map *map)
return RC_CHK_ACCESS(map)->priv;
}
+static inline bool map__hit(const struct map *map)
+{
+ return RC_CHK_ACCESS(map)->hit;
+}
+
static inline refcount_t *map__refcnt(struct map *map)
{
return &RC_CHK_ACCESS(map)->refcnt;
@@ -287,6 +293,11 @@ static inline void map__set_priv(struct map *map)
RC_CHK_ACCESS(map)->priv = true;
}
+static inline void map__set_hit(struct map *map)
+{
+ RC_CHK_ACCESS(map)->hit = true;
+}
+
static inline void map__set_erange_warned(struct map *map)
{
RC_CHK_ACCESS(map)->erange_warned = true;
--
2.46.0.184.g6999bdac58-goog
next prev parent reply other threads:[~2024-08-17 6:45 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-17 6:44 [PATCH v1 00/13] perf inject improvements Ian Rogers
2024-08-17 6:44 ` [PATCH v1 01/13] perf synthetic-events: Avoid unnecessary memset Ian Rogers
2024-08-17 6:44 ` [PATCH v1 02/13] perf map: API clean up Ian Rogers
2024-08-17 6:44 ` [PATCH v1 03/13] perf jit: Constify filename argument Ian Rogers
2024-08-17 6:44 ` [PATCH v1 04/13] perf dso: Constify dso_id Ian Rogers
2024-08-17 6:44 ` [PATCH v1 05/13] perf evsel: Constify evsel__id_hdr_size argument Ian Rogers
2024-08-17 6:44 ` [PATCH v1 06/13] perf test: Expand pipe/inject test Ian Rogers
2024-08-17 6:44 ` [PATCH v1 07/13] perf inject: Combine build_ids and build_id_all into enum Ian Rogers
2024-08-17 6:44 ` [PATCH v1 08/13] perf inject: Combine different mmap and mmap2 functions Ian Rogers
2024-08-17 6:44 ` [PATCH v1 09/13] perf inject: Combine mmap and mmap2 handling Ian Rogers
2024-08-17 6:44 ` [PATCH v1 10/13] perf inject: Fix build ID injection Ian Rogers
2024-08-19 18:01 ` Arnaldo Carvalho de Melo
2024-08-19 19:54 ` Ian Rogers
2024-08-28 15:15 ` Ian Rogers
2024-09-02 18:26 ` Namhyung Kim
2024-09-03 18:34 ` Arnaldo Carvalho de Melo
2024-08-17 6:44 ` [PATCH v1 11/13] perf inject: Add new mmap2-buildid-all option Ian Rogers
2024-08-17 6:44 ` Ian Rogers [this message]
2024-08-17 6:44 ` [PATCH v1 13/13] perf callchain: Allow symbols to be optional when resolving a callchain Ian Rogers
2024-09-02 18:27 ` [PATCH v1 00/13] perf inject improvements Namhyung Kim
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=20240817064442.2152089-13-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=arnd@arndb.de \
--cc=asmadeus@codewreck.org \
--cc=atrajeev@linux.vnet.ibm.com \
--cc=cachen@purestorage.com \
--cc=chaitanyas.prakash@arm.com \
--cc=colin.i.king@gmail.com \
--cc=james.clark@linaro.org \
--cc=jannh@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=masahiroy@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=retpolanne@posteo.net \
--cc=sunhaiyong@loongson.cn \
--cc=weilin.wang@intel.com \
--cc=yangjihong1@huawei.com \
--cc=yskelg@gmail.com \
--cc=zegao2021@gmail.com \
/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