[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230110055859.685-3-ravi.bangoria@amd.com>
Date: Tue, 10 Jan 2023 11:28:57 +0530
From: Ravi Bangoria <ravi.bangoria@....com>
To: <acme@...nel.org>
CC: <ravi.bangoria@....com>, <jolsa@...nel.org>, <namhyung@...nel.org>,
<irogers@...gle.com>, <kan.liang@...ux.intel.com>,
<peterz@...radead.org>, <mark.rutland@....com>, <mingo@...hat.com>,
<alexander.shishkin@...ux.intel.com>, <james.clark@....com>,
<german.gomez@....com>, <leo.yan@...aro.org>,
<adrian.hunter@...el.com>, <alexey.v.bayduraev@...ux.intel.com>,
<linux-perf-users@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<sandipan.das@....com>, <ananth.narayan@....com>,
<santosh.shukla@....com>
Subject: [RFC 2/4] perf tool: Refactor perf_event__synthesize_modules()
perf_event__synthesize_modules() synthesizes MMAP2 and MMAP events.
Split them into separate functions.
Signed-off-by: Ravi Bangoria <ravi.bangoria@....com>
---
tools/perf/util/synthetic-events.c | 77 +++++++++++++++++++-----------
1 file changed, 48 insertions(+), 29 deletions(-)
diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
index 3ab6a92b1a6d..2e145517f192 100644
--- a/tools/perf/util/synthetic-events.c
+++ b/tools/perf/util/synthetic-events.c
@@ -665,6 +665,50 @@ int perf_event__synthesize_cgroups(struct perf_tool *tool __maybe_unused,
}
#endif
+static void __perf_event__synthesize_modules_mmap2(struct machine *machine,
+ struct map *map,
+ union perf_event *event)
+{
+ size_t size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+
+ event->mmap2.header.type = PERF_RECORD_MMAP2;
+ event->mmap2.header.size = sizeof(event->mmap2)
+ - sizeof(event->mmap2.filename)
+ + size
+ + machine->id_hdr_size;
+
+ memset(event->mmap2.filename + size, 0, machine->id_hdr_size);
+ event->mmap2.start = map->start;
+ event->mmap2.len = map->end - map->start;
+ event->mmap2.pid = machine->pid;
+
+ memcpy(event->mmap2.filename, map->dso->long_name,
+ map->dso->long_name_len + 1);
+
+ perf_record_mmap2__read_build_id(&event->mmap2, machine, false);
+}
+
+static void __perf_event__synthesize_modules_mmap(struct machine *machine,
+ struct map *map,
+ union perf_event *event)
+{
+ size_t size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+
+ event->mmap.header.type = PERF_RECORD_MMAP;
+ event->mmap.header.size = sizeof(event->mmap)
+ - sizeof(event->mmap.filename)
+ + size
+ + machine->id_hdr_size;
+
+ memset(event->mmap.filename + size, 0, machine->id_hdr_size);
+ event->mmap.start = map->start;
+ event->mmap.len = map->end - map->start;
+ event->mmap.pid = machine->pid;
+
+ memcpy(event->mmap.filename, map->dso->long_name,
+ map->dso->long_name_len + 1);
+}
+
int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t process,
struct machine *machine)
{
@@ -695,35 +739,10 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t
if (!__map__is_kmodule(pos))
continue;
- if (symbol_conf.buildid_mmap2) {
- size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
- event->mmap2.header.type = PERF_RECORD_MMAP2;
- event->mmap2.header.size = (sizeof(event->mmap2) -
- (sizeof(event->mmap2.filename) - size));
- memset(event->mmap2.filename + size, 0, machine->id_hdr_size);
- event->mmap2.header.size += machine->id_hdr_size;
- event->mmap2.start = pos->start;
- event->mmap2.len = pos->end - pos->start;
- event->mmap2.pid = machine->pid;
-
- memcpy(event->mmap2.filename, pos->dso->long_name,
- pos->dso->long_name_len + 1);
-
- perf_record_mmap2__read_build_id(&event->mmap2, machine, false);
- } else {
- size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
- event->mmap.header.type = PERF_RECORD_MMAP;
- event->mmap.header.size = (sizeof(event->mmap) -
- (sizeof(event->mmap.filename) - size));
- memset(event->mmap.filename + size, 0, machine->id_hdr_size);
- event->mmap.header.size += machine->id_hdr_size;
- event->mmap.start = pos->start;
- event->mmap.len = pos->end - pos->start;
- event->mmap.pid = machine->pid;
-
- memcpy(event->mmap.filename, pos->dso->long_name,
- pos->dso->long_name_len + 1);
- }
+ if (symbol_conf.buildid_mmap2)
+ __perf_event__synthesize_modules_mmap2(machine, pos, event);
+ else
+ __perf_event__synthesize_modules_mmap(machine, pos, event);
if (perf_tool__process_synth_event(tool, event, machine, process) != 0) {
rc = -1;
--
2.39.0
Powered by blists - more mailing lists