perf tools: Store build id when available in PERF_RECORD_MMAP2 metadata events
When processing a PERF_RECORD_MMAP2 metadata event, check on the build id misc bit: PERF_RECORD_MISC_MMAP_BUILD_ID and if it is set, store the build id in mmap's dso object. Also adding the build id data to struct perf_record_mmap2 event definition. 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-8-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
29245ae8ff
commit
1ca6e80254
@ -23,10 +23,20 @@ struct perf_record_mmap2 {
|
||||
__u64 start;
|
||||
__u64 len;
|
||||
__u64 pgoff;
|
||||
__u32 maj;
|
||||
__u32 min;
|
||||
__u64 ino;
|
||||
__u64 ino_generation;
|
||||
union {
|
||||
struct {
|
||||
__u32 maj;
|
||||
__u32 min;
|
||||
__u64 ino;
|
||||
__u64 ino_generation;
|
||||
};
|
||||
struct {
|
||||
__u8 build_id_size;
|
||||
__u8 __reserved_1;
|
||||
__u16 __reserved_2;
|
||||
__u8 build_id[20];
|
||||
};
|
||||
};
|
||||
__u32 prot;
|
||||
__u32 flags;
|
||||
char filename[PATH_MAX];
|
||||
|
@ -1599,7 +1599,8 @@ static int machine__process_extra_kernel_map(struct machine *machine,
|
||||
}
|
||||
|
||||
static int machine__process_kernel_mmap_event(struct machine *machine,
|
||||
struct extra_kernel_map *xm)
|
||||
struct extra_kernel_map *xm,
|
||||
struct build_id *bid)
|
||||
{
|
||||
struct map *map;
|
||||
enum dso_space_type dso_space;
|
||||
@ -1624,6 +1625,10 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
|
||||
goto out_problem;
|
||||
|
||||
map->end = map->start + xm->end - xm->start;
|
||||
|
||||
if (build_id__is_defined(bid))
|
||||
dso__set_build_id(map->dso, bid);
|
||||
|
||||
} else if (is_kernel_mmap) {
|
||||
const char *symbol_name = (xm->name + strlen(machine->mmap_name));
|
||||
/*
|
||||
@ -1681,6 +1686,9 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
|
||||
|
||||
machine__update_kernel_mmap(machine, xm->start, xm->end);
|
||||
|
||||
if (build_id__is_defined(bid))
|
||||
dso__set_build_id(kernel, bid);
|
||||
|
||||
/*
|
||||
* Avoid using a zero address (kptr_restrict) for the ref reloc
|
||||
* symbol. Effectively having zero here means that at record
|
||||
@ -1718,11 +1726,17 @@ int machine__process_mmap2_event(struct machine *machine,
|
||||
.ino = event->mmap2.ino,
|
||||
.ino_generation = event->mmap2.ino_generation,
|
||||
};
|
||||
struct build_id __bid, *bid = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (dump_trace)
|
||||
perf_event__fprintf_mmap2(event, stdout);
|
||||
|
||||
if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) {
|
||||
bid = &__bid;
|
||||
build_id__init(bid, event->mmap2.build_id, event->mmap2.build_id_size);
|
||||
}
|
||||
|
||||
if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
|
||||
sample->cpumode == PERF_RECORD_MISC_KERNEL) {
|
||||
struct extra_kernel_map xm = {
|
||||
@ -1732,7 +1746,7 @@ int machine__process_mmap2_event(struct machine *machine,
|
||||
};
|
||||
|
||||
strlcpy(xm.name, event->mmap2.filename, KMAP_NAME_LEN);
|
||||
ret = machine__process_kernel_mmap_event(machine, &xm);
|
||||
ret = machine__process_kernel_mmap_event(machine, &xm, bid);
|
||||
if (ret < 0)
|
||||
goto out_problem;
|
||||
return 0;
|
||||
@ -1746,7 +1760,7 @@ int machine__process_mmap2_event(struct machine *machine,
|
||||
map = map__new(machine, event->mmap2.start,
|
||||
event->mmap2.len, event->mmap2.pgoff,
|
||||
&dso_id, event->mmap2.prot,
|
||||
event->mmap2.flags,
|
||||
event->mmap2.flags, bid,
|
||||
event->mmap2.filename, thread);
|
||||
|
||||
if (map == NULL)
|
||||
@ -1789,7 +1803,7 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
|
||||
};
|
||||
|
||||
strlcpy(xm.name, event->mmap.filename, KMAP_NAME_LEN);
|
||||
ret = machine__process_kernel_mmap_event(machine, &xm);
|
||||
ret = machine__process_kernel_mmap_event(machine, &xm, NULL);
|
||||
if (ret < 0)
|
||||
goto out_problem;
|
||||
return 0;
|
||||
@ -1805,7 +1819,7 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
|
||||
|
||||
map = map__new(machine, event->mmap.start,
|
||||
event->mmap.len, event->mmap.pgoff,
|
||||
NULL, prot, 0, event->mmap.filename, thread);
|
||||
NULL, prot, 0, NULL, event->mmap.filename, thread);
|
||||
|
||||
if (map == NULL)
|
||||
goto out_problem_map;
|
||||
|
@ -130,8 +130,8 @@ void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso)
|
||||
|
||||
struct map *map__new(struct machine *machine, u64 start, u64 len,
|
||||
u64 pgoff, struct dso_id *id,
|
||||
u32 prot, u32 flags, char *filename,
|
||||
struct thread *thread)
|
||||
u32 prot, u32 flags, struct build_id *bid,
|
||||
char *filename, struct thread *thread)
|
||||
{
|
||||
struct map *map = malloc(sizeof(*map));
|
||||
struct nsinfo *nsi = NULL;
|
||||
@ -194,6 +194,10 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
|
||||
dso__set_loaded(dso);
|
||||
}
|
||||
dso->nsinfo = nsi;
|
||||
|
||||
if (build_id__is_defined(bid))
|
||||
dso__set_build_id(dso, bid);
|
||||
|
||||
dso__put(dso);
|
||||
}
|
||||
return map;
|
||||
|
@ -104,10 +104,11 @@ void map__init(struct map *map,
|
||||
u64 start, u64 end, u64 pgoff, struct dso *dso);
|
||||
|
||||
struct dso_id;
|
||||
struct build_id;
|
||||
|
||||
struct map *map__new(struct machine *machine, u64 start, u64 len,
|
||||
u64 pgoff, struct dso_id *id, u32 prot, u32 flags,
|
||||
char *filename, struct thread *thread);
|
||||
struct build_id *bid, char *filename, struct thread *thread);
|
||||
struct map *map__new2(u64 start, struct dso *dso);
|
||||
void map__delete(struct map *map);
|
||||
struct map *map__clone(struct map *map);
|
||||
|
Loading…
Reference in New Issue
Block a user