Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf record: Save DSO build-ID for synthesizing

When synthesizing MMAP2 with build-id, it'd read the same file repeatedly as
it has no idea if it's done already. Maintain a dsos to check that and skip
the file access if possible.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220920222822.2171056-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
fd643afc fa2edc07

+22 -3
+22 -3
tools/perf/util/synthetic-events.c
··· 364 364 } 365 365 366 366 static void perf_record_mmap2__read_build_id(struct perf_record_mmap2 *event, 367 + struct machine *machine, 367 368 bool is_kernel) 368 369 { 369 370 struct build_id bid; 370 371 struct nsinfo *nsi; 371 372 struct nscookie nc; 373 + struct dso *dso = NULL; 374 + struct dso_id id; 372 375 int rc; 373 376 374 377 if (is_kernel) { 375 378 rc = sysfs__read_build_id("/sys/kernel/notes", &bid); 379 + goto out; 380 + } 381 + 382 + id.maj = event->maj; 383 + id.min = event->min; 384 + id.ino = event->ino; 385 + id.ino_generation = event->ino_generation; 386 + 387 + dso = dsos__findnew_id(&machine->dsos, event->filename, &id); 388 + if (dso && dso->has_build_id) { 389 + bid = dso->bid; 390 + rc = 0; 376 391 goto out; 377 392 } 378 393 ··· 406 391 event->header.misc |= PERF_RECORD_MISC_MMAP_BUILD_ID; 407 392 event->__reserved_1 = 0; 408 393 event->__reserved_2 = 0; 394 + 395 + if (dso && !dso->has_build_id) 396 + dso__set_build_id(dso, &bid); 409 397 } else { 410 398 if (event->filename[0] == '/') { 411 399 pr_debug2("Failed to read build ID for %s\n", 412 400 event->filename); 413 401 } 414 402 } 403 + dso__put(dso); 415 404 } 416 405 417 406 int perf_event__synthesize_mmap_events(struct perf_tool *tool, ··· 526 507 event->mmap2.tid = pid; 527 508 528 509 if (symbol_conf.buildid_mmap2) 529 - perf_record_mmap2__read_build_id(&event->mmap2, false); 510 + perf_record_mmap2__read_build_id(&event->mmap2, machine, false); 530 511 531 512 if (perf_tool__process_synth_event(tool, event, machine, process) != 0) { 532 513 rc = -1; ··· 709 690 memcpy(event->mmap2.filename, pos->dso->long_name, 710 691 pos->dso->long_name_len + 1); 711 692 712 - perf_record_mmap2__read_build_id(&event->mmap2, false); 693 + perf_record_mmap2__read_build_id(&event->mmap2, machine, false); 713 694 } else { 714 695 size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64)); 715 696 event->mmap.header.type = PERF_RECORD_MMAP; ··· 1145 1126 event->mmap2.len = map->end - event->mmap.start; 1146 1127 event->mmap2.pid = machine->pid; 1147 1128 1148 - perf_record_mmap2__read_build_id(&event->mmap2, true); 1129 + perf_record_mmap2__read_build_id(&event->mmap2, machine, true); 1149 1130 } else { 1150 1131 size = snprintf(event->mmap.filename, sizeof(event->mmap.filename), 1151 1132 "%s%s", machine->mmap_name, kmap->ref_reloc_sym->name) + 1;