Skip to content

Commit 1ca6e80

Browse files
olsajiriacmel
authored andcommitted
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 <[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 29245ae commit 1ca6e80

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

tools/lib/perf/include/perf/event.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@ struct perf_record_mmap2 {
2323
__u64 start;
2424
__u64 len;
2525
__u64 pgoff;
26-
__u32 maj;
27-
__u32 min;
28-
__u64 ino;
29-
__u64 ino_generation;
26+
union {
27+
struct {
28+
__u32 maj;
29+
__u32 min;
30+
__u64 ino;
31+
__u64 ino_generation;
32+
};
33+
struct {
34+
__u8 build_id_size;
35+
__u8 __reserved_1;
36+
__u16 __reserved_2;
37+
__u8 build_id[20];
38+
};
39+
};
3040
__u32 prot;
3141
__u32 flags;
3242
char filename[PATH_MAX];

tools/perf/util/machine.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,8 @@ static int machine__process_extra_kernel_map(struct machine *machine,
15991599
}
16001600

16011601
static int machine__process_kernel_mmap_event(struct machine *machine,
1602-
struct extra_kernel_map *xm)
1602+
struct extra_kernel_map *xm,
1603+
struct build_id *bid)
16031604
{
16041605
struct map *map;
16051606
enum dso_space_type dso_space;
@@ -1624,6 +1625,10 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
16241625
goto out_problem;
16251626

16261627
map->end = map->start + xm->end - xm->start;
1628+
1629+
if (build_id__is_defined(bid))
1630+
dso__set_build_id(map->dso, bid);
1631+
16271632
} else if (is_kernel_mmap) {
16281633
const char *symbol_name = (xm->name + strlen(machine->mmap_name));
16291634
/*
@@ -1681,6 +1686,9 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
16811686

16821687
machine__update_kernel_mmap(machine, xm->start, xm->end);
16831688

1689+
if (build_id__is_defined(bid))
1690+
dso__set_build_id(kernel, bid);
1691+
16841692
/*
16851693
* Avoid using a zero address (kptr_restrict) for the ref reloc
16861694
* symbol. Effectively having zero here means that at record
@@ -1718,11 +1726,17 @@ int machine__process_mmap2_event(struct machine *machine,
17181726
.ino = event->mmap2.ino,
17191727
.ino_generation = event->mmap2.ino_generation,
17201728
};
1729+
struct build_id __bid, *bid = NULL;
17211730
int ret = 0;
17221731

17231732
if (dump_trace)
17241733
perf_event__fprintf_mmap2(event, stdout);
17251734

1735+
if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) {
1736+
bid = &__bid;
1737+
build_id__init(bid, event->mmap2.build_id, event->mmap2.build_id_size);
1738+
}
1739+
17261740
if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
17271741
sample->cpumode == PERF_RECORD_MISC_KERNEL) {
17281742
struct extra_kernel_map xm = {
@@ -1732,7 +1746,7 @@ int machine__process_mmap2_event(struct machine *machine,
17321746
};
17331747

17341748
strlcpy(xm.name, event->mmap2.filename, KMAP_NAME_LEN);
1735-
ret = machine__process_kernel_mmap_event(machine, &xm);
1749+
ret = machine__process_kernel_mmap_event(machine, &xm, bid);
17361750
if (ret < 0)
17371751
goto out_problem;
17381752
return 0;
@@ -1746,7 +1760,7 @@ int machine__process_mmap2_event(struct machine *machine,
17461760
map = map__new(machine, event->mmap2.start,
17471761
event->mmap2.len, event->mmap2.pgoff,
17481762
&dso_id, event->mmap2.prot,
1749-
event->mmap2.flags,
1763+
event->mmap2.flags, bid,
17501764
event->mmap2.filename, thread);
17511765

17521766
if (map == NULL)
@@ -1789,7 +1803,7 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
17891803
};
17901804

17911805
strlcpy(xm.name, event->mmap.filename, KMAP_NAME_LEN);
1792-
ret = machine__process_kernel_mmap_event(machine, &xm);
1806+
ret = machine__process_kernel_mmap_event(machine, &xm, NULL);
17931807
if (ret < 0)
17941808
goto out_problem;
17951809
return 0;
@@ -1805,7 +1819,7 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
18051819

18061820
map = map__new(machine, event->mmap.start,
18071821
event->mmap.len, event->mmap.pgoff,
1808-
NULL, prot, 0, event->mmap.filename, thread);
1822+
NULL, prot, 0, NULL, event->mmap.filename, thread);
18091823

18101824
if (map == NULL)
18111825
goto out_problem_map;

tools/perf/util/map.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso)
130130

131131
struct map *map__new(struct machine *machine, u64 start, u64 len,
132132
u64 pgoff, struct dso_id *id,
133-
u32 prot, u32 flags, char *filename,
134-
struct thread *thread)
133+
u32 prot, u32 flags, struct build_id *bid,
134+
char *filename, struct thread *thread)
135135
{
136136
struct map *map = malloc(sizeof(*map));
137137
struct nsinfo *nsi = NULL;
@@ -194,6 +194,10 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
194194
dso__set_loaded(dso);
195195
}
196196
dso->nsinfo = nsi;
197+
198+
if (build_id__is_defined(bid))
199+
dso__set_build_id(dso, bid);
200+
197201
dso__put(dso);
198202
}
199203
return map;

tools/perf/util/map.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ void map__init(struct map *map,
104104
u64 start, u64 end, u64 pgoff, struct dso *dso);
105105

106106
struct dso_id;
107+
struct build_id;
107108

108109
struct map *map__new(struct machine *machine, u64 start, u64 len,
109110
u64 pgoff, struct dso_id *id, u32 prot, u32 flags,
110-
char *filename, struct thread *thread);
111+
struct build_id *bid, char *filename, struct thread *thread);
111112
struct map *map__new2(u64 start, struct dso *dso);
112113
void map__delete(struct map *map);
113114
struct map *map__clone(struct map *map);

0 commit comments

Comments
 (0)