Skip to content

Commit

Permalink
perf tools: Allow synthesizing the build id for kernel/modules/tasks …
Browse files Browse the repository at this point in the history
…in PERF_RECORD_MMAP2

Adding build id to synthesized mmap2 events for everything -
kernel/modules/tasks, when symbol_conf.buildid_mmap2 is true.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20201214105457.543111-11-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Dec 28, 2020
1 parent e0dbf18 commit 4183a8d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tools/perf/util/synthetic-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,31 @@ static bool read_proc_maps_line(struct io *io, __u64 *start, __u64 *end,
}
}

static void perf_record_mmap2__read_build_id(struct perf_record_mmap2 *event,
bool is_kernel)
{
struct build_id bid;
int rc;

if (is_kernel)
rc = sysfs__read_build_id("/sys/kernel/notes", &bid);
else
rc = filename__read_build_id(event->filename, &bid) > 0 ? 0 : -1;

if (rc == 0) {
memcpy(event->build_id, bid.data, sizeof(bid.data));
event->build_id_size = (u8) bid.size;
event->header.misc |= PERF_RECORD_MISC_MMAP_BUILD_ID;
event->__reserved_1 = 0;
event->__reserved_2 = 0;
} else {
if (event->filename[0] == '/') {
pr_debug2("Failed to read build ID for %s\n",
event->filename);
}
}
}

int perf_event__synthesize_mmap_events(struct perf_tool *tool,
union perf_event *event,
pid_t pid, pid_t tgid,
Expand Down Expand Up @@ -453,6 +478,9 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
event->mmap2.pid = tgid;
event->mmap2.tid = pid;

if (symbol_conf.buildid_mmap2)
perf_record_mmap2__read_build_id(&event->mmap2, false);

if (perf_tool__process_synth_event(tool, event, machine, process) != 0) {
rc = -1;
break;
Expand Down Expand Up @@ -633,6 +661,8 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t

memcpy(event->mmap2.filename, pos->dso->long_name,
pos->dso->long_name_len + 1);

perf_record_mmap2__read_build_id(&event->mmap2, false);
} else {
size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
event->mmap.header.type = PERF_RECORD_MMAP;
Expand Down Expand Up @@ -1053,6 +1083,8 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
event->mmap2.start = map->start;
event->mmap2.len = map->end - event->mmap.start;
event->mmap2.pid = machine->pid;

perf_record_mmap2__read_build_id(&event->mmap2, true);
} else {
size = snprintf(event->mmap.filename, sizeof(event->mmap.filename),
"%s%s", machine->mmap_name, kmap->ref_reloc_sym->name) + 1;
Expand Down

0 comments on commit 4183a8d

Please sign in to comment.