Skip to content

Commit f869097

Browse files
committed
perf session: Make read_build_id routines look at the host_machine too
The changes made to support host and guest machines in a session, that started when the 'perf kvm' tool was introduced ended up introducing a bug where the host_machine was not having its DSOs traversed for build-id processing. Fix it by moving some methods to the right classes and considering the host_machine when processing build-ids. Reported-by: Tom Zanussi <tzanussi@gmail.com> Reported-by: Stephane Eranian <eranian@google.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent f6e1467 commit f869097

5 files changed

Lines changed: 69 additions & 40 deletions

File tree

‎tools/perf/util/header.c‎

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -221,29 +221,38 @@ static int __dsos__write_buildid_table(struct list_head *head, pid_t pid,
221221
return 0;
222222
}
223223

224+
static int machine__write_buildid_table(struct machine *self, int fd)
225+
{
226+
int err;
227+
u16 kmisc = PERF_RECORD_MISC_KERNEL,
228+
umisc = PERF_RECORD_MISC_USER;
229+
230+
if (!machine__is_host(self)) {
231+
kmisc = PERF_RECORD_MISC_GUEST_KERNEL;
232+
umisc = PERF_RECORD_MISC_GUEST_USER;
233+
}
234+
235+
err = __dsos__write_buildid_table(&self->kernel_dsos, self->pid,
236+
kmisc, fd);
237+
if (err == 0)
238+
err = __dsos__write_buildid_table(&self->user_dsos,
239+
self->pid, umisc, fd);
240+
return err;
241+
}
242+
224243
static int dsos__write_buildid_table(struct perf_header *header, int fd)
225244
{
226245
struct perf_session *session = container_of(header,
227246
struct perf_session, header);
228247
struct rb_node *nd;
229-
int err = 0;
230-
u16 kmisc, umisc;
248+
int err = machine__write_buildid_table(&session->host_machine, fd);
249+
250+
if (err)
251+
return err;
231252

232253
for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) {
233254
struct machine *pos = rb_entry(nd, struct machine, rb_node);
234-
if (machine__is_host(pos)) {
235-
kmisc = PERF_RECORD_MISC_KERNEL;
236-
umisc = PERF_RECORD_MISC_USER;
237-
} else {
238-
kmisc = PERF_RECORD_MISC_GUEST_KERNEL;
239-
umisc = PERF_RECORD_MISC_GUEST_USER;
240-
}
241-
242-
err = __dsos__write_buildid_table(&pos->kernel_dsos, pos->pid,
243-
kmisc, fd);
244-
if (err == 0)
245-
err = __dsos__write_buildid_table(&pos->user_dsos,
246-
pos->pid, umisc, fd);
255+
err = machine__write_buildid_table(pos, fd);
247256
if (err)
248257
break;
249258
}
@@ -363,12 +372,17 @@ static int __dsos__cache_build_ids(struct list_head *head, const char *debugdir)
363372
return err;
364373
}
365374

366-
static int dsos__cache_build_ids(struct perf_header *self)
375+
static int machine__cache_build_ids(struct machine *self, const char *debugdir)
376+
{
377+
int ret = __dsos__cache_build_ids(&self->kernel_dsos, debugdir);
378+
ret |= __dsos__cache_build_ids(&self->user_dsos, debugdir);
379+
return ret;
380+
}
381+
382+
static int perf_session__cache_build_ids(struct perf_session *self)
367383
{
368-
struct perf_session *session = container_of(self,
369-
struct perf_session, header);
370384
struct rb_node *nd;
371-
int ret = 0;
385+
int ret;
372386
char debugdir[PATH_MAX];
373387

374388
snprintf(debugdir, sizeof(debugdir), "%s/%s", getenv("HOME"),
@@ -377,25 +391,30 @@ static int dsos__cache_build_ids(struct perf_header *self)
377391
if (mkdir(debugdir, 0755) != 0 && errno != EEXIST)
378392
return -1;
379393

380-
for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) {
394+
ret = machine__cache_build_ids(&self->host_machine, debugdir);
395+
396+
for (nd = rb_first(&self->machines); nd; nd = rb_next(nd)) {
381397
struct machine *pos = rb_entry(nd, struct machine, rb_node);
382-
ret |= __dsos__cache_build_ids(&pos->kernel_dsos, debugdir);
383-
ret |= __dsos__cache_build_ids(&pos->user_dsos, debugdir);
398+
ret |= machine__cache_build_ids(pos, debugdir);
384399
}
385400
return ret ? -1 : 0;
386401
}
387402

388-
static bool dsos__read_build_ids(struct perf_header *self, bool with_hits)
403+
static bool machine__read_build_ids(struct machine *self, bool with_hits)
404+
{
405+
bool ret = __dsos__read_build_ids(&self->kernel_dsos, with_hits);
406+
ret |= __dsos__read_build_ids(&self->user_dsos, with_hits);
407+
return ret;
408+
}
409+
410+
static bool perf_session__read_build_ids(struct perf_session *self, bool with_hits)
389411
{
390-
bool ret = false;
391-
struct perf_session *session = container_of(self,
392-
struct perf_session, header);
393412
struct rb_node *nd;
413+
bool ret = machine__read_build_ids(&self->host_machine, with_hits);
394414

395-
for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) {
415+
for (nd = rb_first(&self->machines); nd; nd = rb_next(nd)) {
396416
struct machine *pos = rb_entry(nd, struct machine, rb_node);
397-
ret |= __dsos__read_build_ids(&pos->kernel_dsos, with_hits);
398-
ret |= __dsos__read_build_ids(&pos->user_dsos, with_hits);
417+
ret |= machine__read_build_ids(pos, with_hits);
399418
}
400419

401420
return ret;
@@ -404,12 +423,14 @@ static bool dsos__read_build_ids(struct perf_header *self, bool with_hits)
404423
static int perf_header__adds_write(struct perf_header *self, int fd)
405424
{
406425
int nr_sections;
426+
struct perf_session *session;
407427
struct perf_file_section *feat_sec;
408428
int sec_size;
409429
u64 sec_start;
410430
int idx = 0, err;
411431

412-
if (dsos__read_build_ids(self, true))
432+
session = container_of(self, struct perf_session, header);
433+
if (perf_session__read_build_ids(session, true))
413434
perf_header__set_feat(self, HEADER_BUILD_ID);
414435

415436
nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS);
@@ -450,7 +471,7 @@ static int perf_header__adds_write(struct perf_header *self, int fd)
450471
}
451472
buildid_sec->size = lseek(fd, 0, SEEK_CUR) -
452473
buildid_sec->offset;
453-
dsos__cache_build_ids(self);
474+
perf_session__cache_build_ids(session);
454475
}
455476

456477
lseek(fd, sec_start, SEEK_SET);
@@ -490,7 +511,6 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit)
490511

491512
lseek(fd, sizeof(f_header), SEEK_SET);
492513

493-
494514
for (i = 0; i < self->attrs; i++) {
495515
attr = self->attr[i];
496516

‎tools/perf/util/session.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,3 +895,10 @@ size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp)
895895
__dsos__fprintf(&self->host_machine.user_dsos, fp) +
896896
machines__fprintf_dsos(&self->machines, fp);
897897
}
898+
899+
size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
900+
bool with_hits)
901+
{
902+
size_t ret = machine__fprintf_dsos_buildid(&self->host_machine, fp, with_hits);
903+
return ret + machines__fprintf_dsos_buildid(&self->machines, fp, with_hits);
904+
}

‎tools/perf/util/session.h‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,8 @@ void perf_session__process_machines(struct perf_session *self,
132132

133133
size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
134134

135-
static inline
136-
size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
137-
bool with_hits)
138-
{
139-
return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits);
140-
}
135+
size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
136+
FILE *fp, bool with_hits);
141137

142138
static inline
143139
size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp)

‎tools/perf/util/symbol.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,15 +1937,20 @@ static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
19371937
return ret;
19381938
}
19391939

1940+
size_t machine__fprintf_dsos_buildid(struct machine *self, FILE *fp, bool with_hits)
1941+
{
1942+
return __dsos__fprintf_buildid(&self->kernel_dsos, fp, with_hits) +
1943+
__dsos__fprintf_buildid(&self->user_dsos, fp, with_hits);
1944+
}
1945+
19401946
size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits)
19411947
{
19421948
struct rb_node *nd;
19431949
size_t ret = 0;
19441950

19451951
for (nd = rb_first(self); nd; nd = rb_next(nd)) {
19461952
struct machine *pos = rb_entry(nd, struct machine, rb_node);
1947-
ret += __dsos__fprintf_buildid(&pos->kernel_dsos, fp, with_hits);
1948-
ret += __dsos__fprintf_buildid(&pos->user_dsos, fp, with_hits);
1953+
ret += machine__fprintf_dsos_buildid(pos, fp, with_hits);
19491954
}
19501955
return ret;
19511956
}

‎tools/perf/util/symbol.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ int machine__load_vmlinux_path(struct machine *self, enum map_type type,
170170

171171
size_t __dsos__fprintf(struct list_head *head, FILE *fp);
172172

173+
size_t machine__fprintf_dsos_buildid(struct machine *self, FILE *fp, bool with_hits);
173174
size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp);
174175
size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits);
175176

0 commit comments

Comments
 (0)