Skip to content

Commit 4183a8d

Browse files
olsajiriacmel
authored andcommitted
perf tools: Allow synthesizing the build id for kernel/modules/tasks 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 <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexei Budankov <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Michael Petlan <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e0dbf18 commit 4183a8d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tools/perf/util/synthetic-events.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,31 @@ static bool read_proc_maps_line(struct io *io, __u64 *start, __u64 *end,
347347
}
348348
}
349349

350+
static void perf_record_mmap2__read_build_id(struct perf_record_mmap2 *event,
351+
bool is_kernel)
352+
{
353+
struct build_id bid;
354+
int rc;
355+
356+
if (is_kernel)
357+
rc = sysfs__read_build_id("/sys/kernel/notes", &bid);
358+
else
359+
rc = filename__read_build_id(event->filename, &bid) > 0 ? 0 : -1;
360+
361+
if (rc == 0) {
362+
memcpy(event->build_id, bid.data, sizeof(bid.data));
363+
event->build_id_size = (u8) bid.size;
364+
event->header.misc |= PERF_RECORD_MISC_MMAP_BUILD_ID;
365+
event->__reserved_1 = 0;
366+
event->__reserved_2 = 0;
367+
} else {
368+
if (event->filename[0] == '/') {
369+
pr_debug2("Failed to read build ID for %s\n",
370+
event->filename);
371+
}
372+
}
373+
}
374+
350375
int perf_event__synthesize_mmap_events(struct perf_tool *tool,
351376
union perf_event *event,
352377
pid_t pid, pid_t tgid,
@@ -453,6 +478,9 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
453478
event->mmap2.pid = tgid;
454479
event->mmap2.tid = pid;
455480

481+
if (symbol_conf.buildid_mmap2)
482+
perf_record_mmap2__read_build_id(&event->mmap2, false);
483+
456484
if (perf_tool__process_synth_event(tool, event, machine, process) != 0) {
457485
rc = -1;
458486
break;
@@ -633,6 +661,8 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t
633661

634662
memcpy(event->mmap2.filename, pos->dso->long_name,
635663
pos->dso->long_name_len + 1);
664+
665+
perf_record_mmap2__read_build_id(&event->mmap2, false);
636666
} else {
637667
size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
638668
event->mmap.header.type = PERF_RECORD_MMAP;
@@ -1053,6 +1083,8 @@ static int __perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
10531083
event->mmap2.start = map->start;
10541084
event->mmap2.len = map->end - event->mmap.start;
10551085
event->mmap2.pid = machine->pid;
1086+
1087+
perf_record_mmap2__read_build_id(&event->mmap2, true);
10561088
} else {
10571089
size = snprintf(event->mmap.filename, sizeof(event->mmap.filename),
10581090
"%s%s", machine->mmap_name, kmap->ref_reloc_sym->name) + 1;

0 commit comments

Comments
 (0)