diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-11-24 09:05:15 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-24 10:37:02 -0500 |
commit | b32d133aec5dc882cf783a293f393bfb3f4379e1 (patch) | |
tree | 41fc56a4aaec8892a235ffd530b36278d147dc4e /tools/perf/util/symbol.c | |
parent | 7cc017edb9459193d3b581155a14029e4bef0c49 (diff) |
perf symbols: Simplify symbol machinery setup
And also express its configuration toggles via a struct.
Now all one has to do is to call symbol__init(NULL) if the
defaults are OK, or pass a struct symbol_conf pointer with the
desired configuration.
If a tool uses kernel_maps__find_symbol() to look at the kernel
and modules mappings for a symbol but didn't call symbol__init()
first, that will generate a one time warning too, alerting the
subcommand developer that symbol__init() must be called.
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: <1259071517-3242-2-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.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 44d81d5ae8cf..c4ca974b36e3 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | #include "debug.h" | 7 | #include "debug.h" |
8 | 8 | ||
9 | #include <asm/bug.h> | ||
9 | #include <libelf.h> | 10 | #include <libelf.h> |
10 | #include <gelf.h> | 11 | #include <gelf.h> |
11 | #include <elf.h> | 12 | #include <elf.h> |
@@ -37,6 +38,11 @@ unsigned int symbol__priv_size; | |||
37 | static int vmlinux_path__nr_entries; | 38 | static int vmlinux_path__nr_entries; |
38 | static char **vmlinux_path; | 39 | static char **vmlinux_path; |
39 | 40 | ||
41 | static struct symbol_conf symbol_conf__defaults = { | ||
42 | .use_modules = true, | ||
43 | .try_vmlinux_path = true, | ||
44 | }; | ||
45 | |||
40 | static struct rb_root kernel_maps; | 46 | static struct rb_root kernel_maps; |
41 | 47 | ||
42 | static void dso__fixup_sym_end(struct dso *self) | 48 | static void dso__fixup_sym_end(struct dso *self) |
@@ -1166,7 +1172,9 @@ struct symbol *kernel_maps__find_symbol(u64 ip, struct map **mapp, | |||
1166 | if (map) { | 1172 | if (map) { |
1167 | ip = map->map_ip(map, ip); | 1173 | ip = map->map_ip(map, ip); |
1168 | return map__find_symbol(map, ip, filter); | 1174 | return map__find_symbol(map, ip, filter); |
1169 | } | 1175 | } else |
1176 | WARN_ONCE(RB_EMPTY_ROOT(&kernel_maps), | ||
1177 | "Empty kernel_maps, was symbol__init() called?\n"); | ||
1170 | 1178 | ||
1171 | return NULL; | 1179 | return NULL; |
1172 | } | 1180 | } |
@@ -1485,9 +1493,9 @@ size_t dsos__fprintf_buildid(FILE *fp) | |||
1485 | return ret; | 1493 | return ret; |
1486 | } | 1494 | } |
1487 | 1495 | ||
1488 | static int kernel_maps__create_kernel_map(const char *vmlinux_name) | 1496 | static int kernel_maps__create_kernel_map(const struct symbol_conf *conf) |
1489 | { | 1497 | { |
1490 | struct dso *kernel = dso__new(vmlinux_name ?: "[kernel.kallsyms]"); | 1498 | struct dso *kernel = dso__new(conf->vmlinux_name ?: "[kernel.kallsyms]"); |
1491 | 1499 | ||
1492 | if (kernel == NULL) | 1500 | if (kernel == NULL) |
1493 | return -1; | 1501 | return -1; |
@@ -1577,18 +1585,21 @@ out_fail: | |||
1577 | return -1; | 1585 | return -1; |
1578 | } | 1586 | } |
1579 | 1587 | ||
1580 | int kernel_maps__init(const char *vmlinux_name, bool try_vmlinux_path, | 1588 | static int kernel_maps__init(const struct symbol_conf *conf) |
1581 | bool use_modules) | ||
1582 | { | 1589 | { |
1583 | if (try_vmlinux_path && vmlinux_path__init() < 0) | 1590 | const struct symbol_conf *pconf = conf ?: &symbol_conf__defaults; |
1591 | |||
1592 | symbol__priv_size = pconf->priv_size; | ||
1593 | |||
1594 | if (pconf->try_vmlinux_path && vmlinux_path__init() < 0) | ||
1584 | return -1; | 1595 | return -1; |
1585 | 1596 | ||
1586 | if (kernel_maps__create_kernel_map(vmlinux_name) < 0) { | 1597 | if (kernel_maps__create_kernel_map(pconf) < 0) { |
1587 | vmlinux_path__exit(); | 1598 | vmlinux_path__exit(); |
1588 | return -1; | 1599 | return -1; |
1589 | } | 1600 | } |
1590 | 1601 | ||
1591 | if (use_modules && kernel_maps__create_module_maps() < 0) | 1602 | if (pconf->use_modules && kernel_maps__create_module_maps() < 0) |
1592 | pr_debug("Failed to load list of modules in use, " | 1603 | pr_debug("Failed to load list of modules in use, " |
1593 | "continuing...\n"); | 1604 | "continuing...\n"); |
1594 | /* | 1605 | /* |
@@ -1598,8 +1609,8 @@ int kernel_maps__init(const char *vmlinux_name, bool try_vmlinux_path, | |||
1598 | return 0; | 1609 | return 0; |
1599 | } | 1610 | } |
1600 | 1611 | ||
1601 | void symbol__init(unsigned int priv_size) | 1612 | int symbol__init(struct symbol_conf *conf) |
1602 | { | 1613 | { |
1603 | elf_version(EV_CURRENT); | 1614 | elf_version(EV_CURRENT); |
1604 | symbol__priv_size = priv_size; | 1615 | return kernel_maps__init(conf); |
1605 | } | 1616 | } |