aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/symbol.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-01-14 15:30:06 -0500
committerIngo Molnar <mingo@elte.hu>2010-01-16 04:58:47 -0500
commit9e201442de7c954f03710ac76f28c1927d07550c (patch)
tree7682ebe87ca85468e0ecd28b277013e9359605c0 /tools/perf/util/symbol.c
parent8d0591f6ad9edf66697ce29de176fb6f3213b9e3 (diff)
perf symbols: Cache /proc/kallsyms files by build-id
So that when we don't have a vmlinux handy we can store the kallsyms for later use by 'perf report'. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1263501006-14185-3-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/symbol.c')
-rw-r--r--tools/perf/util/symbol.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 71d23e1e30e8..ae61e9f4d6eb 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -383,13 +383,14 @@ size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp)
383 return ret; 383 return ret;
384} 384}
385 385
386int kallsyms__parse(void *arg, int (*process_symbol)(void *arg, const char *name, 386int kallsyms__parse(const char *filename, void *arg,
387 int (*process_symbol)(void *arg, const char *name,
387 char type, u64 start)) 388 char type, u64 start))
388{ 389{
389 char *line = NULL; 390 char *line = NULL;
390 size_t n; 391 size_t n;
391 int err = 0; 392 int err = 0;
392 FILE *file = fopen("/proc/kallsyms", "r"); 393 FILE *file = fopen(filename, "r");
393 394
394 if (file == NULL) 395 if (file == NULL)
395 goto out_failure; 396 goto out_failure;
@@ -466,10 +467,11 @@ static int map__process_kallsym_symbol(void *arg, const char *name,
466 * so that we can in the next step set the symbol ->end address and then 467 * so that we can in the next step set the symbol ->end address and then
467 * call kernel_maps__split_kallsyms. 468 * call kernel_maps__split_kallsyms.
468 */ 469 */
469static int dso__load_all_kallsyms(struct dso *self, struct map *map) 470static int dso__load_all_kallsyms(struct dso *self, const char *filename,
471 struct map *map)
470{ 472{
471 struct process_kallsyms_args args = { .map = map, .dso = self, }; 473 struct process_kallsyms_args args = { .map = map, .dso = self, };
472 return kallsyms__parse(&args, map__process_kallsym_symbol); 474 return kallsyms__parse(filename, &args, map__process_kallsym_symbol);
473} 475}
474 476
475/* 477/*
@@ -556,10 +558,10 @@ discard_symbol: rb_erase(&pos->rb_node, root);
556} 558}
557 559
558 560
559static int dso__load_kallsyms(struct dso *self, struct map *map, 561static int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map,
560 struct perf_session *session, symbol_filter_t filter) 562 struct perf_session *session, symbol_filter_t filter)
561{ 563{
562 if (dso__load_all_kallsyms(self, map) < 0) 564 if (dso__load_all_kallsyms(self, filename, map) < 0)
563 return -1; 565 return -1;
564 566
565 symbols__fixup_end(&self->symbols[map->type]); 567 symbols__fixup_end(&self->symbols[map->type]);
@@ -1580,7 +1582,8 @@ static int dso__load_kernel_sym(struct dso *self, struct map *map,
1580 struct perf_session *session, symbol_filter_t filter) 1582 struct perf_session *session, symbol_filter_t filter)
1581{ 1583{
1582 int err; 1584 int err;
1583 bool is_kallsyms; 1585 const char *kallsyms_filename = NULL;
1586 char *kallsyms_allocated_filename = NULL;
1584 1587
1585 if (vmlinux_path != NULL) { 1588 if (vmlinux_path != NULL) {
1586 int i; 1589 int i;
@@ -1606,19 +1609,37 @@ static int dso__load_kernel_sym(struct dso *self, struct map *map,
1606 */ 1609 */
1607 if (self->has_build_id) { 1610 if (self->has_build_id) {
1608 u8 kallsyms_build_id[BUILD_ID_SIZE]; 1611 u8 kallsyms_build_id[BUILD_ID_SIZE];
1612 char sbuild_id[BUILD_ID_SIZE * 2 + 1];
1609 1613
1610 if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id, 1614 if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id,
1611 sizeof(kallsyms_build_id)) == 0) { 1615 sizeof(kallsyms_build_id)) == 0) {
1612 is_kallsyms = dso__build_id_equal(self, kallsyms_build_id); 1616 if (dso__build_id_equal(self, kallsyms_build_id)) {
1613 if (is_kallsyms) 1617 kallsyms_filename = "/proc/kallsyms";
1614 goto do_kallsyms; 1618 goto do_kallsyms;
1619 }
1615 } 1620 }
1621
1622 build_id__sprintf(self->build_id, sizeof(self->build_id),
1623 sbuild_id);
1624
1625 if (asprintf(&kallsyms_allocated_filename,
1626 "%s/.debug/[kernel.kallsyms]/%s",
1627 getenv("HOME"), sbuild_id) != -1) {
1628 if (access(kallsyms_filename, F_OK)) {
1629 kallsyms_filename = kallsyms_allocated_filename;
1630 goto do_kallsyms;
1631 }
1632 free(kallsyms_allocated_filename);
1633 kallsyms_allocated_filename = NULL;
1634 }
1635
1616 goto do_vmlinux; 1636 goto do_vmlinux;
1617 } 1637 }
1618 1638
1619 is_kallsyms = self->long_name[0] == '['; 1639 if (self->long_name[0] == '[') {
1620 if (is_kallsyms) 1640 kallsyms_filename = "/proc/kallsyms";
1621 goto do_kallsyms; 1641 goto do_kallsyms;
1642 }
1622 1643
1623do_vmlinux: 1644do_vmlinux:
1624 err = dso__load_vmlinux(self, map, session, self->long_name, filter); 1645 err = dso__load_vmlinux(self, map, session, self->long_name, filter);
@@ -1629,9 +1650,10 @@ do_vmlinux:
1629 pr_info("The file %s cannot be used, " 1650 pr_info("The file %s cannot be used, "
1630 "trying to use /proc/kallsyms...", self->long_name); 1651 "trying to use /proc/kallsyms...", self->long_name);
1631do_kallsyms: 1652do_kallsyms:
1632 err = dso__load_kallsyms(self, map, session, filter); 1653 err = dso__load_kallsyms(self, kallsyms_filename, map, session, filter);
1633 if (err > 0 && !is_kallsyms) 1654 if (err > 0 && kallsyms_filename == NULL)
1634 dso__set_long_name(self, strdup("[kernel.kallsyms]")); 1655 dso__set_long_name(self, strdup("[kernel.kallsyms]"));
1656 free(kallsyms_allocated_filename);
1635 } 1657 }
1636 1658
1637 if (err > 0) { 1659 if (err > 0) {