2010-03-26 06:59:00 +08:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2011-01-23 06:37:02 +08:00
|
|
|
#include <inttypes.h>
|
2010-05-20 23:15:33 +08:00
|
|
|
#include "build-id.h"
|
2010-07-21 01:42:52 +08:00
|
|
|
#include "debug.h"
|
2009-05-29 01:55:04 +08:00
|
|
|
#include "symbol.h"
|
2010-03-26 06:59:00 +08:00
|
|
|
#include "strlist.h"
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
#include <libelf.h>
|
|
|
|
#include <gelf.h>
|
|
|
|
#include <elf.h>
|
2009-11-19 06:20:52 +08:00
|
|
|
#include <limits.h>
|
2009-10-02 14:29:58 +08:00
|
|
|
#include <sys/utsname.h>
|
2009-08-05 20:05:16 +08:00
|
|
|
|
2010-12-22 11:08:36 +08:00
|
|
|
#ifndef KSYM_NAME_LEN
|
|
|
|
#define KSYM_NAME_LEN 128
|
|
|
|
#endif
|
|
|
|
|
2009-11-22 00:31:25 +08:00
|
|
|
#ifndef NT_GNU_BUILD_ID
|
|
|
|
#define NT_GNU_BUILD_ID 3
|
|
|
|
#endif
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static bool dso__build_id_equal(const struct dso *dso, u8 *build_id);
|
2010-07-30 20:08:08 +08:00
|
|
|
static int elf_read_build_id(Elf *elf, void *bf, size_t size);
|
2009-11-28 02:29:14 +08:00
|
|
|
static void dsos__add(struct list_head *head, struct dso *dso);
|
2009-11-28 02:29:16 +08:00
|
|
|
static struct map *map__new2(u64 start, struct dso *dso, enum map_type type);
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_kernel_sym(struct dso *dso, struct map *map,
|
2010-02-04 02:52:00 +08:00
|
|
|
symbol_filter_t filter);
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
|
2010-04-19 13:32:50 +08:00
|
|
|
symbol_filter_t filter);
|
2009-11-24 02:39:10 +08:00
|
|
|
static int vmlinux_path__nr_entries;
|
|
|
|
static char **vmlinux_path;
|
2009-10-02 14:29:58 +08:00
|
|
|
|
2009-12-16 06:04:39 +08:00
|
|
|
struct symbol_conf symbol_conf = {
|
2009-12-16 06:04:42 +08:00
|
|
|
.exclude_other = true,
|
2009-11-24 22:05:15 +08:00
|
|
|
.use_modules = true,
|
|
|
|
.try_vmlinux_path = true,
|
2010-12-10 04:27:07 +08:00
|
|
|
.symfs = "",
|
2009-11-24 22:05:15 +08:00
|
|
|
};
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int dso__name_len(const struct dso *dso)
|
2010-07-21 01:42:52 +08:00
|
|
|
{
|
|
|
|
if (verbose)
|
2011-03-31 21:56:28 +08:00
|
|
|
return dso->long_name_len;
|
2010-07-21 01:42:52 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return dso->short_name_len;
|
2010-07-21 01:42:52 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
bool dso__loaded(const struct dso *dso, enum map_type type)
|
2009-11-28 02:29:16 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
return dso->loaded & (1 << type);
|
2009-11-28 02:29:16 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
bool dso__sorted_by_name(const struct dso *dso, enum map_type type)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
return dso->sorted_by_name & (1 << type);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static void dso__set_sorted_by_name(struct dso *dso, enum map_type type)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->sorted_by_name |= (1 << type);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
}
|
|
|
|
|
2010-01-05 02:19:27 +08:00
|
|
|
bool symbol_type__is_a(char symbol_type, enum map_type map_type)
|
2009-12-12 00:50:37 +08:00
|
|
|
{
|
|
|
|
switch (map_type) {
|
|
|
|
case MAP__FUNCTION:
|
|
|
|
return symbol_type == 'T' || symbol_type == 'W';
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
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: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 00:50:39 +08:00
|
|
|
case MAP__VARIABLE:
|
|
|
|
return symbol_type == 'D' || symbol_type == 'd';
|
2009-12-12 00:50:37 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static void symbols__fixup_end(struct rb_root *symbols)
|
2009-10-06 01:26:17 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_node *nd, *prevnd = rb_first(symbols);
|
2009-10-08 00:48:56 +08:00
|
|
|
struct symbol *curr, *prev;
|
2009-10-06 01:26:17 +08:00
|
|
|
|
|
|
|
if (prevnd == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-10-08 00:48:56 +08:00
|
|
|
curr = rb_entry(prevnd, struct symbol, rb_node);
|
|
|
|
|
2009-10-06 01:26:17 +08:00
|
|
|
for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) {
|
2009-10-08 00:48:56 +08:00
|
|
|
prev = curr;
|
|
|
|
curr = rb_entry(nd, struct symbol, rb_node);
|
2009-10-06 01:26:17 +08:00
|
|
|
|
2010-12-22 11:08:36 +08:00
|
|
|
if (prev->end == prev->start && prev->end != curr->start)
|
2009-10-06 01:26:17 +08:00
|
|
|
prev->end = curr->start - 1;
|
|
|
|
}
|
2009-10-08 00:48:56 +08:00
|
|
|
|
|
|
|
/* Last entry */
|
|
|
|
if (curr->end == curr->start)
|
|
|
|
curr->end = roundup(curr->start, 4096);
|
2009-10-06 01:26:17 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static void __map_groups__fixup_end(struct map_groups *mg, enum map_type type)
|
2009-10-06 01:26:17 +08:00
|
|
|
{
|
|
|
|
struct map *prev, *curr;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_node *nd, *prevnd = rb_first(&mg->maps[type]);
|
2009-10-06 01:26:17 +08:00
|
|
|
|
|
|
|
if (prevnd == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
curr = rb_entry(prevnd, struct map, rb_node);
|
|
|
|
|
|
|
|
for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) {
|
|
|
|
prev = curr;
|
|
|
|
curr = rb_entry(nd, struct map, rb_node);
|
|
|
|
prev->end = curr->start - 1;
|
2009-10-08 00:48:56 +08:00
|
|
|
}
|
2009-11-22 00:31:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We still haven't the actual symbols, so guess the
|
|
|
|
* last map final address.
|
|
|
|
*/
|
2010-11-25 12:12:53 +08:00
|
|
|
curr->end = ~0ULL;
|
2009-10-06 01:26:17 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static void map_groups__fixup_end(struct map_groups *mg)
|
2009-11-28 02:29:19 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAP__NR_TYPES; ++i)
|
2011-03-31 21:56:28 +08:00
|
|
|
__map_groups__fixup_end(mg, i);
|
2009-11-28 02:29:19 +08:00
|
|
|
}
|
|
|
|
|
2010-08-05 23:59:47 +08:00
|
|
|
static struct symbol *symbol__new(u64 start, u64 len, u8 binding,
|
|
|
|
const char *name)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2009-05-29 01:55:13 +08:00
|
|
|
size_t namelen = strlen(name) + 1;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct symbol *sym = calloc(1, (symbol_conf.priv_size +
|
|
|
|
sizeof(*sym) + namelen));
|
|
|
|
if (sym == NULL)
|
perf_counter tools: Add 'perf annotate' feature
Add new perf sub-command to display annotated source code:
$ perf annotate decode_tree_entry
------------------------------------------------
Percent | Source code & Disassembly of /home/mingo/git/git
------------------------------------------------
:
: /home/mingo/git/git: file format elf64-x86-64
:
:
: Disassembly of section .text:
:
: 00000000004a0da0 <decode_tree_entry>:
: *modep = mode;
: return str;
: }
:
: static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned long size)
: {
3.82 : 4a0da0: 41 54 push %r12
: const char *path;
: unsigned int mode, len;
:
: if (size < 24 || buf[size - 21])
0.17 : 4a0da2: 48 83 fa 17 cmp $0x17,%rdx
: *modep = mode;
: return str;
: }
:
: static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned long size)
: {
0.00 : 4a0da6: 49 89 fc mov %rdi,%r12
0.00 : 4a0da9: 55 push %rbp
3.37 : 4a0daa: 53 push %rbx
: const char *path;
: unsigned int mode, len;
:
: if (size < 24 || buf[size - 21])
0.08 : 4a0dab: 76 73 jbe 4a0e20 <decode_tree_entry+0x80>
0.00 : 4a0dad: 80 7c 16 eb 00 cmpb $0x0,-0x15(%rsi,%rdx,1)
3.48 : 4a0db2: 75 6c jne 4a0e20 <decode_tree_entry+0x80>
: static const char *get_mode(const char *str, unsigned int *modep)
: {
: unsigned char c;
: unsigned int mode = 0;
:
: if (*str == ' ')
1.94 : 4a0db4: 0f b6 06 movzbl (%rsi),%eax
0.39 : 4a0db7: 3c 20 cmp $0x20,%al
0.00 : 4a0db9: 74 65 je 4a0e20 <decode_tree_entry+0x80>
: return NULL;
:
: while ((c = *str++) != ' ') {
0.06 : 4a0dbb: 89 c2 mov %eax,%edx
: if (c < '0' || c > '7')
1.99 : 4a0dbd: 31 ed xor %ebp,%ebp
: unsigned int mode = 0;
:
: if (*str == ' ')
: return NULL;
:
: while ((c = *str++) != ' ') {
1.74 : 4a0dbf: 48 8d 5e 01 lea 0x1(%rsi),%rbx
: if (c < '0' || c > '7')
0.00 : 4a0dc3: 8d 42 d0 lea -0x30(%rdx),%eax
0.17 : 4a0dc6: 3c 07 cmp $0x7,%al
0.00 : 4a0dc8: 76 0d jbe 4a0dd7 <decode_tree_entry+0x37>
0.00 : 4a0dca: eb 54 jmp 4a0e20 <decode_tree_entry+0x80>
0.00 : 4a0dcc: 0f 1f 40 00 nopl 0x0(%rax)
16.57 : 4a0dd0: 8d 42 d0 lea -0x30(%rdx),%eax
0.14 : 4a0dd3: 3c 07 cmp $0x7,%al
0.00 : 4a0dd5: 77 49 ja 4a0e20 <decode_tree_entry+0x80>
: return NULL;
: mode = (mode << 3) + (c - '0');
3.12 : 4a0dd7: 0f b6 c2 movzbl %dl,%eax
: unsigned int mode = 0;
:
: if (*str == ' ')
: return NULL;
:
: while ((c = *str++) != ' ') {
0.00 : 4a0dda: 0f b6 13 movzbl (%rbx),%edx
16.74 : 4a0ddd: 48 83 c3 01 add $0x1,%rbx
: if (c < '0' || c > '7')
: return NULL;
: mode = (mode << 3) + (c - '0');
The first column is the percentage of samples that arrived on that
particular line - relative to the total cost of the function.
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-06-06 21:48:52 +08:00
|
|
|
return NULL;
|
|
|
|
|
2009-12-16 06:04:39 +08:00
|
|
|
if (symbol_conf.priv_size)
|
2011-03-31 21:56:28 +08:00
|
|
|
sym = ((void *)sym) + symbol_conf.priv_size;
|
2009-10-21 00:25:40 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
sym->start = start;
|
|
|
|
sym->end = len ? start + len - 1 : start;
|
|
|
|
sym->binding = binding;
|
|
|
|
sym->namelen = namelen - 1;
|
2009-10-21 00:25:40 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
pr_debug4("%s: %s %#" PRIx64 "-%#" PRIx64 "\n",
|
|
|
|
__func__, name, start, sym->end);
|
|
|
|
memcpy(sym->name, name, namelen);
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return sym;
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
void symbol__delete(struct symbol *sym)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
free(((void *)sym) - symbol_conf.priv_size);
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static size_t symbol__fprintf(struct symbol *sym, FILE *fp)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2011-01-23 06:37:02 +08:00
|
|
|
return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n",
|
2011-03-31 21:56:28 +08:00
|
|
|
sym->start, sym->end,
|
|
|
|
sym->binding == STB_GLOBAL ? 'g' :
|
|
|
|
sym->binding == STB_LOCAL ? 'l' : 'w',
|
|
|
|
sym->name);
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
void dso__set_long_name(struct dso *dso, char *name)
|
2009-11-18 01:40:53 +08:00
|
|
|
{
|
2009-11-21 06:51:29 +08:00
|
|
|
if (name == NULL)
|
|
|
|
return;
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->long_name = name;
|
|
|
|
dso->long_name_len = strlen(name);
|
2009-11-18 01:40:53 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static void dso__set_short_name(struct dso *dso, const char *name)
|
2010-03-16 02:03:50 +08:00
|
|
|
{
|
|
|
|
if (name == NULL)
|
|
|
|
return;
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->short_name = name;
|
|
|
|
dso->short_name_len = strlen(name);
|
2010-03-16 02:03:50 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static void dso__set_basename(struct dso *dso)
|
2009-11-18 01:40:53 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_short_name(dso, basename(dso->long_name));
|
2009-11-18 01:40:53 +08:00
|
|
|
}
|
|
|
|
|
2009-10-31 02:28:24 +08:00
|
|
|
struct dso *dso__new(const char *name)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct dso *dso = calloc(1, sizeof(*dso) + strlen(name) + 1);
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso != NULL) {
|
2009-11-28 02:29:17 +08:00
|
|
|
int i;
|
2011-03-31 21:56:28 +08:00
|
|
|
strcpy(dso->name, name);
|
|
|
|
dso__set_long_name(dso, dso->name);
|
|
|
|
dso__set_short_name(dso, dso->name);
|
2009-11-28 02:29:17 +08:00
|
|
|
for (i = 0; i < MAP__NR_TYPES; ++i)
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->symbols[i] = dso->symbol_names[i] = RB_ROOT;
|
|
|
|
dso->symtab_type = SYMTAB__NOT_FOUND;
|
|
|
|
dso->loaded = 0;
|
|
|
|
dso->sorted_by_name = 0;
|
|
|
|
dso->has_build_id = 0;
|
|
|
|
dso->kernel = DSO_TYPE_USER;
|
|
|
|
INIT_LIST_HEAD(&dso->node);
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return dso;
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static void symbols__delete(struct rb_root *symbols)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
|
|
|
struct symbol *pos;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_node *next = rb_first(symbols);
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
while (next) {
|
|
|
|
pos = rb_entry(next, struct symbol, rb_node);
|
|
|
|
next = rb_next(&pos->rb_node);
|
2011-03-31 21:56:28 +08:00
|
|
|
rb_erase(&pos->rb_node, symbols);
|
2009-10-31 02:28:24 +08:00
|
|
|
symbol__delete(pos);
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
void dso__delete(struct dso *dso)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2009-11-28 02:29:17 +08:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAP__NR_TYPES; ++i)
|
2011-03-31 21:56:28 +08:00
|
|
|
symbols__delete(&dso->symbols[i]);
|
|
|
|
if (dso->sname_alloc)
|
|
|
|
free((char *)dso->short_name);
|
|
|
|
if (dso->lname_alloc)
|
|
|
|
free(dso->long_name);
|
|
|
|
free(dso);
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
void dso__set_build_id(struct dso *dso, void *build_id)
|
perf symbols: Use the buildids if present
With this change 'perf record' will intercept PERF_RECORD_MMAP
calls, creating a linked list of DSOs, then when the session
finishes, it will traverse this list and read the buildids,
stashing them at the end of the file and will set up a new
feature bit in the header bitmask.
'perf report' will then notice this feature and populate the
'dsos' list and set the build ids.
When reading the symtabs it will refuse to load from a file that
doesn't have the same build id. This improves the
reliability of the profiler output, as symbols and profiling
data is more guaranteed to match.
Example:
[root@doppio ~]# perf report | head
/home/acme/bin/perf with build id b1ea544ac3746e7538972548a09aadecc5753868 not found, continuing without symbols
# Samples: 2621434559
#
# Overhead Command Shared Object Symbol
# ........ ............... ............................. ......
#
7.91% init [kernel] [k] read_hpet
7.64% init [kernel] [k] mwait_idle_with_hints
7.60% swapper [kernel] [k] read_hpet
7.60% swapper [kernel] [k] mwait_idle_with_hints
3.65% init [kernel] [k] 0xffffffffa02339d9
[root@doppio ~]#
In this case the 'perf' binary was an older one, vanished,
so its symbols probably wouldn't match or would cause subtly
different (and misleading) output.
Next patches will support the kernel as well, reading the build
id notes for it and the modules from /sys.
Another patch should also introduce a new plumbing command:
'perf list-buildids'
that will then be used in porcelain that is distro specific to
fetch -debuginfo packages where such buildids are present. This
will in turn allow for one to run 'perf record' in one machine
and 'perf report' in another.
Future work on having the buildid sent directly from the kernel
in the PERF_RECORD_MMAP event is needed to close races, as the
DSO can be changed during a 'perf record' session, but this
patch at least helps with non-corner cases and current/older
kernels.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: K. Prasad <prasad@linux.vnet.ibm.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roland McGrath <roland@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1257367843-26224-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-05 04:50:43 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
memcpy(dso->build_id, build_id, sizeof(dso->build_id));
|
|
|
|
dso->has_build_id = 1;
|
perf symbols: Use the buildids if present
With this change 'perf record' will intercept PERF_RECORD_MMAP
calls, creating a linked list of DSOs, then when the session
finishes, it will traverse this list and read the buildids,
stashing them at the end of the file and will set up a new
feature bit in the header bitmask.
'perf report' will then notice this feature and populate the
'dsos' list and set the build ids.
When reading the symtabs it will refuse to load from a file that
doesn't have the same build id. This improves the
reliability of the profiler output, as symbols and profiling
data is more guaranteed to match.
Example:
[root@doppio ~]# perf report | head
/home/acme/bin/perf with build id b1ea544ac3746e7538972548a09aadecc5753868 not found, continuing without symbols
# Samples: 2621434559
#
# Overhead Command Shared Object Symbol
# ........ ............... ............................. ......
#
7.91% init [kernel] [k] read_hpet
7.64% init [kernel] [k] mwait_idle_with_hints
7.60% swapper [kernel] [k] read_hpet
7.60% swapper [kernel] [k] mwait_idle_with_hints
3.65% init [kernel] [k] 0xffffffffa02339d9
[root@doppio ~]#
In this case the 'perf' binary was an older one, vanished,
so its symbols probably wouldn't match or would cause subtly
different (and misleading) output.
Next patches will support the kernel as well, reading the build
id notes for it and the modules from /sys.
Another patch should also introduce a new plumbing command:
'perf list-buildids'
that will then be used in porcelain that is distro specific to
fetch -debuginfo packages where such buildids are present. This
will in turn allow for one to run 'perf record' in one machine
and 'perf report' in another.
Future work on having the buildid sent directly from the kernel
in the PERF_RECORD_MMAP event is needed to close races, as the
DSO can be changed during a 'perf record' session, but this
patch at least helps with non-corner cases and current/older
kernels.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: K. Prasad <prasad@linux.vnet.ibm.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roland McGrath <roland@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1257367843-26224-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-05 04:50:43 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static void symbols__insert(struct rb_root *symbols, struct symbol *sym)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_node **p = &symbols->rb_node;
|
2009-05-29 01:55:04 +08:00
|
|
|
struct rb_node *parent = NULL;
|
perf_counter tools: Define and use our own u64, s64 etc. definitions
On 64-bit powerpc, __u64 is defined to be unsigned long rather than
unsigned long long. This causes compiler warnings every time we
print a __u64 value with %Lx.
Rather than changing __u64, we define our own u64 to be unsigned long
long on all architectures, and similarly s64 as signed long long.
For consistency we also define u32, s32, u16, s16, u8 and s8. These
definitions are put in a new header, types.h, because these definitions
are needed in util/string.h and util/symbol.h.
The main change here is the mechanical change of __[us]{64,32,16,8}
to remove the "__". The other changes are:
* Create types.h
* Include types.h in perf.h, util/string.h and util/symbol.h
* Add types.h to the LIB_H definition in Makefile
* Added (u64) casts in process_overflow_event() and print_sym_table()
to kill two remaining warnings.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: benh@kernel.crashing.org
LKML-Reference: <19003.33494.495844.956580@cargo.ozlabs.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-06-19 20:21:42 +08:00
|
|
|
const u64 ip = sym->start;
|
2009-05-29 01:55:04 +08:00
|
|
|
struct symbol *s;
|
|
|
|
|
|
|
|
while (*p != NULL) {
|
|
|
|
parent = *p;
|
|
|
|
s = rb_entry(parent, struct symbol, rb_node);
|
|
|
|
if (ip < s->start)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
rb_link_node(&sym->rb_node, parent, p);
|
2011-03-31 21:56:28 +08:00
|
|
|
rb_insert_color(&sym->rb_node, symbols);
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static struct symbol *symbols__find(struct rb_root *symbols, u64 ip)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
|
|
|
struct rb_node *n;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (symbols == NULL)
|
2009-05-29 01:55:04 +08:00
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
n = symbols->rb_node;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
while (n) {
|
|
|
|
struct symbol *s = rb_entry(n, struct symbol, rb_node);
|
|
|
|
|
|
|
|
if (ip < s->start)
|
|
|
|
n = n->rb_left;
|
|
|
|
else if (ip > s->end)
|
|
|
|
n = n->rb_right;
|
|
|
|
else
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
struct symbol_name_rb_node {
|
|
|
|
struct rb_node rb_node;
|
|
|
|
struct symbol sym;
|
|
|
|
};
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static void symbols__insert_by_name(struct rb_root *symbols, struct symbol *sym)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_node **p = &symbols->rb_node;
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
struct rb_node *parent = NULL;
|
2010-11-24 00:38:18 +08:00
|
|
|
struct symbol_name_rb_node *symn, *s;
|
|
|
|
|
|
|
|
symn = container_of(sym, struct symbol_name_rb_node, sym);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
|
|
|
|
while (*p != NULL) {
|
|
|
|
parent = *p;
|
|
|
|
s = rb_entry(parent, struct symbol_name_rb_node, rb_node);
|
|
|
|
if (strcmp(sym->name, s->sym.name) < 0)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
rb_link_node(&symn->rb_node, parent, p);
|
2011-03-31 21:56:28 +08:00
|
|
|
rb_insert_color(&symn->rb_node, symbols);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static void symbols__sort_by_name(struct rb_root *symbols,
|
|
|
|
struct rb_root *source)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
|
|
|
|
for (nd = rb_first(source); nd; nd = rb_next(nd)) {
|
|
|
|
struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
|
2011-03-31 21:56:28 +08:00
|
|
|
symbols__insert_by_name(symbols, pos);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static struct symbol *symbols__find_by_name(struct rb_root *symbols,
|
|
|
|
const char *name)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
{
|
|
|
|
struct rb_node *n;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (symbols == NULL)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
n = symbols->rb_node;
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
|
|
|
|
while (n) {
|
|
|
|
struct symbol_name_rb_node *s;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
s = rb_entry(n, struct symbol_name_rb_node, rb_node);
|
|
|
|
cmp = strcmp(name, s->sym.name);
|
|
|
|
|
|
|
|
if (cmp < 0)
|
|
|
|
n = n->rb_left;
|
|
|
|
else if (cmp > 0)
|
|
|
|
n = n->rb_right;
|
|
|
|
else
|
|
|
|
return &s->sym;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
struct symbol *dso__find_symbol(struct dso *dso,
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
enum map_type type, u64 addr)
|
2009-11-24 23:01:52 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
return symbols__find(&dso->symbols[type], addr);
|
2009-11-24 23:01:52 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
const char *name)
|
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
return symbols__find_by_name(&dso->symbol_names[type], name);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
void dso__sort_by_name(struct dso *dso, enum map_type type)
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_sorted_by_name(dso, type);
|
|
|
|
return symbols__sort_by_name(&dso->symbol_names[type],
|
|
|
|
&dso->symbols[type]);
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int build_id__sprintf(const u8 *build_id, int len, char *bf)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
perf symbols: Use the buildids if present
With this change 'perf record' will intercept PERF_RECORD_MMAP
calls, creating a linked list of DSOs, then when the session
finishes, it will traverse this list and read the buildids,
stashing them at the end of the file and will set up a new
feature bit in the header bitmask.
'perf report' will then notice this feature and populate the
'dsos' list and set the build ids.
When reading the symtabs it will refuse to load from a file that
doesn't have the same build id. This improves the
reliability of the profiler output, as symbols and profiling
data is more guaranteed to match.
Example:
[root@doppio ~]# perf report | head
/home/acme/bin/perf with build id b1ea544ac3746e7538972548a09aadecc5753868 not found, continuing without symbols
# Samples: 2621434559
#
# Overhead Command Shared Object Symbol
# ........ ............... ............................. ......
#
7.91% init [kernel] [k] read_hpet
7.64% init [kernel] [k] mwait_idle_with_hints
7.60% swapper [kernel] [k] read_hpet
7.60% swapper [kernel] [k] mwait_idle_with_hints
3.65% init [kernel] [k] 0xffffffffa02339d9
[root@doppio ~]#
In this case the 'perf' binary was an older one, vanished,
so its symbols probably wouldn't match or would cause subtly
different (and misleading) output.
Next patches will support the kernel as well, reading the build
id notes for it and the modules from /sys.
Another patch should also introduce a new plumbing command:
'perf list-buildids'
that will then be used in porcelain that is distro specific to
fetch -debuginfo packages where such buildids are present. This
will in turn allow for one to run 'perf record' in one machine
and 'perf report' in another.
Future work on having the buildid sent directly from the kernel
in the PERF_RECORD_MMAP event is needed to close races, as the
DSO can be changed during a 'perf record' session, but this
patch at least helps with non-corner cases and current/older
kernels.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: K. Prasad <prasad@linux.vnet.ibm.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roland McGrath <roland@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1257367843-26224-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-05 04:50:43 +08:00
|
|
|
char *bid = bf;
|
2011-03-31 21:56:28 +08:00
|
|
|
const u8 *raw = build_id;
|
perf symbols: Use the buildids if present
With this change 'perf record' will intercept PERF_RECORD_MMAP
calls, creating a linked list of DSOs, then when the session
finishes, it will traverse this list and read the buildids,
stashing them at the end of the file and will set up a new
feature bit in the header bitmask.
'perf report' will then notice this feature and populate the
'dsos' list and set the build ids.
When reading the symtabs it will refuse to load from a file that
doesn't have the same build id. This improves the
reliability of the profiler output, as symbols and profiling
data is more guaranteed to match.
Example:
[root@doppio ~]# perf report | head
/home/acme/bin/perf with build id b1ea544ac3746e7538972548a09aadecc5753868 not found, continuing without symbols
# Samples: 2621434559
#
# Overhead Command Shared Object Symbol
# ........ ............... ............................. ......
#
7.91% init [kernel] [k] read_hpet
7.64% init [kernel] [k] mwait_idle_with_hints
7.60% swapper [kernel] [k] read_hpet
7.60% swapper [kernel] [k] mwait_idle_with_hints
3.65% init [kernel] [k] 0xffffffffa02339d9
[root@doppio ~]#
In this case the 'perf' binary was an older one, vanished,
so its symbols probably wouldn't match or would cause subtly
different (and misleading) output.
Next patches will support the kernel as well, reading the build
id notes for it and the modules from /sys.
Another patch should also introduce a new plumbing command:
'perf list-buildids'
that will then be used in porcelain that is distro specific to
fetch -debuginfo packages where such buildids are present. This
will in turn allow for one to run 'perf record' in one machine
and 'perf report' in another.
Future work on having the buildid sent directly from the kernel
in the PERF_RECORD_MMAP event is needed to close races, as the
DSO can be changed during a 'perf record' session, but this
patch at least helps with non-corner cases and current/older
kernels.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: K. Prasad <prasad@linux.vnet.ibm.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roland McGrath <roland@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1257367843-26224-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-05 04:50:43 +08:00
|
|
|
int i;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
perf symbols: Use the buildids if present
With this change 'perf record' will intercept PERF_RECORD_MMAP
calls, creating a linked list of DSOs, then when the session
finishes, it will traverse this list and read the buildids,
stashing them at the end of the file and will set up a new
feature bit in the header bitmask.
'perf report' will then notice this feature and populate the
'dsos' list and set the build ids.
When reading the symtabs it will refuse to load from a file that
doesn't have the same build id. This improves the
reliability of the profiler output, as symbols and profiling
data is more guaranteed to match.
Example:
[root@doppio ~]# perf report | head
/home/acme/bin/perf with build id b1ea544ac3746e7538972548a09aadecc5753868 not found, continuing without symbols
# Samples: 2621434559
#
# Overhead Command Shared Object Symbol
# ........ ............... ............................. ......
#
7.91% init [kernel] [k] read_hpet
7.64% init [kernel] [k] mwait_idle_with_hints
7.60% swapper [kernel] [k] read_hpet
7.60% swapper [kernel] [k] mwait_idle_with_hints
3.65% init [kernel] [k] 0xffffffffa02339d9
[root@doppio ~]#
In this case the 'perf' binary was an older one, vanished,
so its symbols probably wouldn't match or would cause subtly
different (and misleading) output.
Next patches will support the kernel as well, reading the build
id notes for it and the modules from /sys.
Another patch should also introduce a new plumbing command:
'perf list-buildids'
that will then be used in porcelain that is distro specific to
fetch -debuginfo packages where such buildids are present. This
will in turn allow for one to run 'perf record' in one machine
and 'perf report' in another.
Future work on having the buildid sent directly from the kernel
in the PERF_RECORD_MMAP event is needed to close races, as the
DSO can be changed during a 'perf record' session, but this
patch at least helps with non-corner cases and current/older
kernels.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: K. Prasad <prasad@linux.vnet.ibm.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roland McGrath <roland@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1257367843-26224-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-05 04:50:43 +08:00
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
sprintf(bid, "%02x", *raw);
|
|
|
|
++raw;
|
|
|
|
bid += 2;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return raw - build_id;
|
perf symbols: Use the buildids if present
With this change 'perf record' will intercept PERF_RECORD_MMAP
calls, creating a linked list of DSOs, then when the session
finishes, it will traverse this list and read the buildids,
stashing them at the end of the file and will set up a new
feature bit in the header bitmask.
'perf report' will then notice this feature and populate the
'dsos' list and set the build ids.
When reading the symtabs it will refuse to load from a file that
doesn't have the same build id. This improves the
reliability of the profiler output, as symbols and profiling
data is more guaranteed to match.
Example:
[root@doppio ~]# perf report | head
/home/acme/bin/perf with build id b1ea544ac3746e7538972548a09aadecc5753868 not found, continuing without symbols
# Samples: 2621434559
#
# Overhead Command Shared Object Symbol
# ........ ............... ............................. ......
#
7.91% init [kernel] [k] read_hpet
7.64% init [kernel] [k] mwait_idle_with_hints
7.60% swapper [kernel] [k] read_hpet
7.60% swapper [kernel] [k] mwait_idle_with_hints
3.65% init [kernel] [k] 0xffffffffa02339d9
[root@doppio ~]#
In this case the 'perf' binary was an older one, vanished,
so its symbols probably wouldn't match or would cause subtly
different (and misleading) output.
Next patches will support the kernel as well, reading the build
id notes for it and the modules from /sys.
Another patch should also introduce a new plumbing command:
'perf list-buildids'
that will then be used in porcelain that is distro specific to
fetch -debuginfo packages where such buildids are present. This
will in turn allow for one to run 'perf record' in one machine
and 'perf report' in another.
Future work on having the buildid sent directly from the kernel
in the PERF_RECORD_MMAP event is needed to close races, as the
DSO can be changed during a 'perf record' session, but this
patch at least helps with non-corner cases and current/older
kernels.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: K. Prasad <prasad@linux.vnet.ibm.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roland McGrath <roland@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1257367843-26224-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-05 04:50:43 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t dso__fprintf_buildid(struct dso *dso, FILE *fp)
|
perf symbols: Use the buildids if present
With this change 'perf record' will intercept PERF_RECORD_MMAP
calls, creating a linked list of DSOs, then when the session
finishes, it will traverse this list and read the buildids,
stashing them at the end of the file and will set up a new
feature bit in the header bitmask.
'perf report' will then notice this feature and populate the
'dsos' list and set the build ids.
When reading the symtabs it will refuse to load from a file that
doesn't have the same build id. This improves the
reliability of the profiler output, as symbols and profiling
data is more guaranteed to match.
Example:
[root@doppio ~]# perf report | head
/home/acme/bin/perf with build id b1ea544ac3746e7538972548a09aadecc5753868 not found, continuing without symbols
# Samples: 2621434559
#
# Overhead Command Shared Object Symbol
# ........ ............... ............................. ......
#
7.91% init [kernel] [k] read_hpet
7.64% init [kernel] [k] mwait_idle_with_hints
7.60% swapper [kernel] [k] read_hpet
7.60% swapper [kernel] [k] mwait_idle_with_hints
3.65% init [kernel] [k] 0xffffffffa02339d9
[root@doppio ~]#
In this case the 'perf' binary was an older one, vanished,
so its symbols probably wouldn't match or would cause subtly
different (and misleading) output.
Next patches will support the kernel as well, reading the build
id notes for it and the modules from /sys.
Another patch should also introduce a new plumbing command:
'perf list-buildids'
that will then be used in porcelain that is distro specific to
fetch -debuginfo packages where such buildids are present. This
will in turn allow for one to run 'perf record' in one machine
and 'perf report' in another.
Future work on having the buildid sent directly from the kernel
in the PERF_RECORD_MMAP event is needed to close races, as the
DSO can be changed during a 'perf record' session, but this
patch at least helps with non-corner cases and current/older
kernels.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: K. Prasad <prasad@linux.vnet.ibm.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roland McGrath <roland@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1257367843-26224-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-05 04:50:43 +08:00
|
|
|
{
|
|
|
|
char sbuild_id[BUILD_ID_SIZE * 2 + 1];
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
|
2009-11-17 02:32:44 +08:00
|
|
|
return fprintf(fp, "%s", sbuild_id);
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t dso__fprintf_symbols_by_name(struct dso *dso,
|
|
|
|
enum map_type type, FILE *fp)
|
2010-08-25 21:43:29 +08:00
|
|
|
{
|
|
|
|
size_t ret = 0;
|
|
|
|
struct rb_node *nd;
|
|
|
|
struct symbol_name_rb_node *pos;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
for (nd = rb_first(&dso->symbol_names[type]); nd; nd = rb_next(nd)) {
|
2010-08-25 21:43:29 +08:00
|
|
|
pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
|
|
|
|
fprintf(fp, "%s\n", pos->sym.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp)
|
2009-11-17 02:32:44 +08:00
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t ret = fprintf(fp, "dso: %s (", dso->short_name);
|
2009-11-17 02:32:44 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->short_name != dso->long_name)
|
|
|
|
ret += fprintf(fp, "%s, ", dso->long_name);
|
2010-02-23 03:15:39 +08:00
|
|
|
ret += fprintf(fp, "%s, %sloaded, ", map_type__name[type],
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->loaded ? "" : "NOT ");
|
|
|
|
ret += dso__fprintf_buildid(dso, fp);
|
2009-11-28 02:29:17 +08:00
|
|
|
ret += fprintf(fp, ")\n");
|
2011-03-31 21:56:28 +08:00
|
|
|
for (nd = rb_first(&dso->symbols[type]); nd; nd = rb_next(nd)) {
|
2009-11-28 02:29:20 +08:00
|
|
|
struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
|
|
|
|
ret += symbol__fprintf(pos, fp);
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-15 04:30:06 +08:00
|
|
|
int kallsyms__parse(const char *filename, void *arg,
|
|
|
|
int (*process_symbol)(void *arg, const char *name,
|
2010-12-22 11:08:36 +08:00
|
|
|
char type, u64 start, u64 end))
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
2010-12-22 11:08:36 +08:00
|
|
|
int err = -1;
|
|
|
|
u64 prev_start = 0;
|
|
|
|
char prev_symbol_type = 0;
|
|
|
|
char *prev_symbol_name;
|
2010-01-15 04:30:06 +08:00
|
|
|
FILE *file = fopen(filename, "r");
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
if (file == NULL)
|
|
|
|
goto out_failure;
|
|
|
|
|
2010-12-22 11:08:36 +08:00
|
|
|
prev_symbol_name = malloc(KSYM_NAME_LEN);
|
|
|
|
if (prev_symbol_name == NULL)
|
|
|
|
goto out_close;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
2009-05-29 01:55:04 +08:00
|
|
|
while (!feof(file)) {
|
perf_counter tools: Define and use our own u64, s64 etc. definitions
On 64-bit powerpc, __u64 is defined to be unsigned long rather than
unsigned long long. This causes compiler warnings every time we
print a __u64 value with %Lx.
Rather than changing __u64, we define our own u64 to be unsigned long
long on all architectures, and similarly s64 as signed long long.
For consistency we also define u32, s32, u16, s16, u8 and s8. These
definitions are put in a new header, types.h, because these definitions
are needed in util/string.h and util/symbol.h.
The main change here is the mechanical change of __[us]{64,32,16,8}
to remove the "__". The other changes are:
* Create types.h
* Include types.h in perf.h, util/string.h and util/symbol.h
* Add types.h to the LIB_H definition in Makefile
* Added (u64) casts in process_overflow_event() and print_sym_table()
to kill two remaining warnings.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: benh@kernel.crashing.org
LKML-Reference: <19003.33494.495844.956580@cargo.ozlabs.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-06-19 20:21:42 +08:00
|
|
|
u64 start;
|
2009-05-29 01:55:04 +08:00
|
|
|
int line_len, len;
|
|
|
|
char symbol_type;
|
2009-10-08 00:48:56 +08:00
|
|
|
char *symbol_name;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
line_len = getline(&line, &n, file);
|
2010-04-19 13:32:50 +08:00
|
|
|
if (line_len < 0 || !line)
|
2009-05-29 01:55:04 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
line[--line_len] = '\0'; /* \n */
|
|
|
|
|
2009-06-02 04:50:19 +08:00
|
|
|
len = hex2u64(line, &start);
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
len++;
|
|
|
|
if (len + 2 >= line_len)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
symbol_type = toupper(line[len]);
|
2010-12-22 11:08:36 +08:00
|
|
|
len += 2;
|
|
|
|
symbol_name = line + len;
|
|
|
|
len = line_len - len;
|
2010-01-05 02:19:26 +08:00
|
|
|
|
2010-12-22 11:08:36 +08:00
|
|
|
if (len >= KSYM_NAME_LEN) {
|
|
|
|
err = -1;
|
2010-01-05 02:19:26 +08:00
|
|
|
break;
|
2010-12-22 11:08:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prev_symbol_type) {
|
|
|
|
u64 end = start;
|
|
|
|
if (end != prev_start)
|
|
|
|
--end;
|
|
|
|
err = process_symbol(arg, prev_symbol_name,
|
|
|
|
prev_symbol_type, prev_start, end);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(prev_symbol_name, symbol_name, len + 1);
|
|
|
|
prev_symbol_type = symbol_type;
|
|
|
|
prev_start = start;
|
2009-10-08 00:48:56 +08:00
|
|
|
}
|
|
|
|
|
2010-12-22 11:08:36 +08:00
|
|
|
free(prev_symbol_name);
|
2009-10-08 00:48:56 +08:00
|
|
|
free(line);
|
2010-12-22 11:08:36 +08:00
|
|
|
out_close:
|
2009-10-08 00:48:56 +08:00
|
|
|
fclose(file);
|
2010-01-05 02:19:26 +08:00
|
|
|
return err;
|
2009-10-08 00:48:56 +08:00
|
|
|
|
|
|
|
out_failure:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-05 02:19:26 +08:00
|
|
|
struct process_kallsyms_args {
|
|
|
|
struct map *map;
|
|
|
|
struct dso *dso;
|
|
|
|
};
|
|
|
|
|
2010-08-05 23:59:47 +08:00
|
|
|
static u8 kallsyms2elf_type(char type)
|
|
|
|
{
|
|
|
|
if (type == 'W')
|
|
|
|
return STB_WEAK;
|
|
|
|
|
|
|
|
return isupper(type) ? STB_GLOBAL : STB_LOCAL;
|
|
|
|
}
|
|
|
|
|
2010-01-05 02:19:26 +08:00
|
|
|
static int map__process_kallsym_symbol(void *arg, const char *name,
|
2010-12-22 11:08:36 +08:00
|
|
|
char type, u64 start, u64 end)
|
2010-01-05 02:19:26 +08:00
|
|
|
{
|
|
|
|
struct symbol *sym;
|
|
|
|
struct process_kallsyms_args *a = arg;
|
|
|
|
struct rb_root *root = &a->dso->symbols[a->map->type];
|
|
|
|
|
|
|
|
if (!symbol_type__is_a(type, a->map->type))
|
|
|
|
return 0;
|
|
|
|
|
2010-12-22 11:08:36 +08:00
|
|
|
sym = symbol__new(start, end - start + 1,
|
|
|
|
kallsyms2elf_type(type), name);
|
2010-01-05 02:19:26 +08:00
|
|
|
if (sym == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
/*
|
|
|
|
* We will pass the symbols to the filter later, in
|
|
|
|
* map__split_kallsyms, when we have split the maps per module
|
|
|
|
*/
|
|
|
|
symbols__insert(root, sym);
|
2010-04-19 13:32:50 +08:00
|
|
|
|
2010-01-05 02:19:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loads the function entries in /proc/kallsyms into kernel_map->dso,
|
|
|
|
* so that we can in the next step set the symbol ->end address and then
|
|
|
|
* call kernel_maps__split_kallsyms.
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_all_kallsyms(struct dso *dso, const char *filename,
|
2010-01-15 04:30:06 +08:00
|
|
|
struct map *map)
|
2010-01-05 02:19:26 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct process_kallsyms_args args = { .map = map, .dso = dso, };
|
2010-01-15 04:30:06 +08:00
|
|
|
return kallsyms__parse(filename, &args, map__process_kallsym_symbol);
|
2010-01-05 02:19:26 +08:00
|
|
|
}
|
|
|
|
|
2009-10-08 00:48:56 +08:00
|
|
|
/*
|
|
|
|
* Split the symbols into maps, making sure there are no overlaps, i.e. the
|
|
|
|
* kernel range is broken in several maps, named [kernel].N, as we don't have
|
|
|
|
* the original ELF section names vmlinux have.
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__split_kallsyms(struct dso *dso, struct map *map,
|
2010-02-04 02:52:00 +08:00
|
|
|
symbol_filter_t filter)
|
2009-10-08 00:48:56 +08:00
|
|
|
{
|
2010-02-04 02:52:00 +08:00
|
|
|
struct map_groups *kmaps = map__kmap(map)->kmaps;
|
2010-04-28 08:17:50 +08:00
|
|
|
struct machine *machine = kmaps->machine;
|
2009-11-28 02:29:18 +08:00
|
|
|
struct map *curr_map = map;
|
2009-10-08 00:48:56 +08:00
|
|
|
struct symbol *pos;
|
2010-11-29 22:44:15 +08:00
|
|
|
int count = 0, moved = 0;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_root *root = &dso->symbols[map->type];
|
2009-11-28 02:29:18 +08:00
|
|
|
struct rb_node *next = rb_first(root);
|
2009-10-08 00:48:56 +08:00
|
|
|
int kernel_range = 0;
|
|
|
|
|
|
|
|
while (next) {
|
|
|
|
char *module;
|
|
|
|
|
|
|
|
pos = rb_entry(next, struct symbol, rb_node);
|
|
|
|
next = rb_next(&pos->rb_node);
|
|
|
|
|
|
|
|
module = strchr(pos->name, '\t');
|
|
|
|
if (module) {
|
2009-12-16 06:04:39 +08:00
|
|
|
if (!symbol_conf.use_modules)
|
2009-11-28 02:29:21 +08:00
|
|
|
goto discard_symbol;
|
|
|
|
|
2009-10-08 00:48:56 +08:00
|
|
|
*module++ = '\0';
|
|
|
|
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
if (strcmp(curr_map->dso->short_name, module)) {
|
2010-04-19 13:32:50 +08:00
|
|
|
if (curr_map != map &&
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->kernel == DSO_TYPE_GUEST_KERNEL &&
|
2010-04-28 08:17:50 +08:00
|
|
|
machine__is_default_guest(machine)) {
|
2010-04-19 13:32:50 +08:00
|
|
|
/*
|
|
|
|
* We assume all symbols of a module are
|
|
|
|
* continuous in * kallsyms, so curr_map
|
|
|
|
* points to a module and all its
|
|
|
|
* symbols are in its kmap. Mark it as
|
|
|
|
* loaded.
|
|
|
|
*/
|
|
|
|
dso__set_loaded(curr_map->dso,
|
|
|
|
curr_map->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
curr_map = map_groups__find_by_name(kmaps,
|
|
|
|
map->type, module);
|
2009-11-28 02:29:18 +08:00
|
|
|
if (curr_map == NULL) {
|
2010-05-18 04:57:59 +08:00
|
|
|
pr_debug("%s/proc/{kallsyms,modules} "
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
"inconsistency while looking "
|
2010-04-19 13:32:50 +08:00
|
|
|
"for \"%s\" module!\n",
|
2010-04-28 08:17:50 +08:00
|
|
|
machine->root_dir, module);
|
2010-04-19 13:32:50 +08:00
|
|
|
curr_map = map;
|
|
|
|
goto discard_symbol;
|
2009-10-06 01:26:17 +08:00
|
|
|
}
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
if (curr_map->dso->loaded &&
|
2010-04-28 08:17:50 +08:00
|
|
|
!machine__is_default_guest(machine))
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
goto discard_symbol;
|
2009-10-06 01:26:17 +08:00
|
|
|
}
|
2009-10-08 00:48:56 +08:00
|
|
|
/*
|
|
|
|
* So that we look just like we get from .ko files,
|
|
|
|
* i.e. not prelinked, relative to map->start.
|
|
|
|
*/
|
2009-11-28 02:29:18 +08:00
|
|
|
pos->start = curr_map->map_ip(curr_map, pos->start);
|
|
|
|
pos->end = curr_map->map_ip(curr_map, pos->end);
|
|
|
|
} else if (curr_map != map) {
|
2009-10-08 00:48:56 +08:00
|
|
|
char dso_name[PATH_MAX];
|
2011-03-31 21:56:28 +08:00
|
|
|
struct dso *ndso;
|
2009-10-08 00:48:56 +08:00
|
|
|
|
2010-11-29 22:44:15 +08:00
|
|
|
if (count == 0) {
|
|
|
|
curr_map = map;
|
|
|
|
goto filter_symbol;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2010-04-19 13:32:50 +08:00
|
|
|
snprintf(dso_name, sizeof(dso_name),
|
|
|
|
"[guest.kernel].%d",
|
|
|
|
kernel_range++);
|
|
|
|
else
|
|
|
|
snprintf(dso_name, sizeof(dso_name),
|
|
|
|
"[kernel].%d",
|
|
|
|
kernel_range++);
|
2009-10-08 00:48:56 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
ndso = dso__new(dso_name);
|
|
|
|
if (ndso == NULL)
|
2009-10-08 00:48:56 +08:00
|
|
|
return -1;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
ndso->kernel = dso->kernel;
|
2010-04-19 13:32:50 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
curr_map = map__new2(pos->start, ndso, map->type);
|
2010-02-25 11:00:51 +08:00
|
|
|
if (curr_map == NULL) {
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__delete(ndso);
|
2009-10-08 00:48:56 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2009-11-28 02:29:18 +08:00
|
|
|
curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
|
2010-02-04 02:52:00 +08:00
|
|
|
map_groups__insert(kmaps, curr_map);
|
2009-10-08 00:48:56 +08:00
|
|
|
++kernel_range;
|
|
|
|
}
|
2010-11-29 22:44:15 +08:00
|
|
|
filter_symbol:
|
2009-11-28 02:29:18 +08:00
|
|
|
if (filter && filter(curr_map, pos)) {
|
2009-11-28 02:29:21 +08:00
|
|
|
discard_symbol: rb_erase(&pos->rb_node, root);
|
2009-10-31 02:28:24 +08:00
|
|
|
symbol__delete(pos);
|
2009-10-08 00:48:56 +08:00
|
|
|
} else {
|
2009-11-28 02:29:18 +08:00
|
|
|
if (curr_map != map) {
|
|
|
|
rb_erase(&pos->rb_node, root);
|
|
|
|
symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
|
2010-11-29 22:44:15 +08:00
|
|
|
++moved;
|
|
|
|
} else
|
|
|
|
++count;
|
2009-07-02 14:05:58 +08:00
|
|
|
}
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
if (curr_map != map &&
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->kernel == DSO_TYPE_GUEST_KERNEL &&
|
2010-04-28 08:17:50 +08:00
|
|
|
machine__is_default_guest(kmaps->machine)) {
|
2010-04-19 13:32:50 +08:00
|
|
|
dso__set_loaded(curr_map->dso, curr_map->type);
|
|
|
|
}
|
|
|
|
|
2010-11-29 22:44:15 +08:00
|
|
|
return count + moved;
|
2009-10-08 00:48:56 +08:00
|
|
|
}
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int dso__load_kallsyms(struct dso *dso, const char *filename,
|
2010-02-04 02:52:00 +08:00
|
|
|
struct map *map, symbol_filter_t filter)
|
2009-10-08 00:48:56 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso__load_all_kallsyms(dso, filename, map) < 0)
|
2009-10-08 00:48:56 +08:00
|
|
|
return -1;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
|
|
|
dso->symtab_type = SYMTAB__GUEST_KALLSYMS;
|
2010-04-19 13:32:50 +08:00
|
|
|
else
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->symtab_type = SYMTAB__KALLSYMS;
|
2009-10-08 00:48:56 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return dso__split_kallsyms(dso, map, filter);
|
2009-10-06 01:26:17 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_perf_map(struct dso *dso, struct map *map,
|
2009-10-22 03:34:06 +08:00
|
|
|
symbol_filter_t filter)
|
2009-06-09 02:12:48 +08:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
|
|
|
FILE *file;
|
|
|
|
int nr_syms = 0;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
file = fopen(dso->long_name, "r");
|
2009-06-09 02:12:48 +08:00
|
|
|
if (file == NULL)
|
|
|
|
goto out_failure;
|
|
|
|
|
|
|
|
while (!feof(file)) {
|
perf_counter tools: Define and use our own u64, s64 etc. definitions
On 64-bit powerpc, __u64 is defined to be unsigned long rather than
unsigned long long. This causes compiler warnings every time we
print a __u64 value with %Lx.
Rather than changing __u64, we define our own u64 to be unsigned long
long on all architectures, and similarly s64 as signed long long.
For consistency we also define u32, s32, u16, s16, u8 and s8. These
definitions are put in a new header, types.h, because these definitions
are needed in util/string.h and util/symbol.h.
The main change here is the mechanical change of __[us]{64,32,16,8}
to remove the "__". The other changes are:
* Create types.h
* Include types.h in perf.h, util/string.h and util/symbol.h
* Add types.h to the LIB_H definition in Makefile
* Added (u64) casts in process_overflow_event() and print_sym_table()
to kill two remaining warnings.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: benh@kernel.crashing.org
LKML-Reference: <19003.33494.495844.956580@cargo.ozlabs.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-06-19 20:21:42 +08:00
|
|
|
u64 start, size;
|
2009-06-09 02:12:48 +08:00
|
|
|
struct symbol *sym;
|
|
|
|
int line_len, len;
|
|
|
|
|
|
|
|
line_len = getline(&line, &n, file);
|
|
|
|
if (line_len < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!line)
|
|
|
|
goto out_failure;
|
|
|
|
|
|
|
|
line[--line_len] = '\0'; /* \n */
|
|
|
|
|
|
|
|
len = hex2u64(line, &start);
|
|
|
|
|
|
|
|
len++;
|
|
|
|
if (len + 2 >= line_len)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
len += hex2u64(line + len, &size);
|
|
|
|
|
|
|
|
len++;
|
|
|
|
if (len + 2 >= line_len)
|
|
|
|
continue;
|
|
|
|
|
2010-08-05 23:59:47 +08:00
|
|
|
sym = symbol__new(start, size, STB_GLOBAL, line + len);
|
2009-06-09 02:12:48 +08:00
|
|
|
|
|
|
|
if (sym == NULL)
|
|
|
|
goto out_delete_line;
|
|
|
|
|
2009-10-02 14:29:58 +08:00
|
|
|
if (filter && filter(map, sym))
|
2009-10-31 02:28:24 +08:00
|
|
|
symbol__delete(sym);
|
2009-06-09 02:12:48 +08:00
|
|
|
else {
|
2011-03-31 21:56:28 +08:00
|
|
|
symbols__insert(&dso->symbols[map->type], sym);
|
2009-06-09 02:12:48 +08:00
|
|
|
nr_syms++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
return nr_syms;
|
|
|
|
|
|
|
|
out_delete_line:
|
|
|
|
free(line);
|
|
|
|
out_failure:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-29 01:55:04 +08:00
|
|
|
/**
|
|
|
|
* elf_symtab__for_each_symbol - iterate thru all the symbols
|
|
|
|
*
|
2011-03-31 21:56:28 +08:00
|
|
|
* @syms: struct elf_symtab instance to iterate
|
2009-08-15 18:26:57 +08:00
|
|
|
* @idx: uint32_t idx
|
2009-05-29 01:55:04 +08:00
|
|
|
* @sym: GElf_Sym iterator
|
|
|
|
*/
|
2009-08-15 18:26:57 +08:00
|
|
|
#define elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) \
|
|
|
|
for (idx = 0, gelf_getsym(syms, idx, &sym);\
|
|
|
|
idx < nr_syms; \
|
|
|
|
idx++, gelf_getsym(syms, idx, &sym))
|
2009-05-29 01:55:04 +08:00
|
|
|
|
|
|
|
static inline uint8_t elf_sym__type(const GElf_Sym *sym)
|
|
|
|
{
|
|
|
|
return GELF_ST_TYPE(sym->st_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int elf_sym__is_function(const GElf_Sym *sym)
|
|
|
|
{
|
|
|
|
return elf_sym__type(sym) == STT_FUNC &&
|
|
|
|
sym->st_name != 0 &&
|
2009-10-06 10:35:03 +08:00
|
|
|
sym->st_shndx != SHN_UNDEF;
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
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: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 00:50:39 +08:00
|
|
|
static inline bool elf_sym__is_object(const GElf_Sym *sym)
|
|
|
|
{
|
|
|
|
return elf_sym__type(sym) == STT_OBJECT &&
|
|
|
|
sym->st_name != 0 &&
|
|
|
|
sym->st_shndx != SHN_UNDEF;
|
|
|
|
}
|
|
|
|
|
2009-07-02 14:08:36 +08:00
|
|
|
static inline int elf_sym__is_label(const GElf_Sym *sym)
|
|
|
|
{
|
|
|
|
return elf_sym__type(sym) == STT_NOTYPE &&
|
|
|
|
sym->st_name != 0 &&
|
|
|
|
sym->st_shndx != SHN_UNDEF &&
|
|
|
|
sym->st_shndx != SHN_ABS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const char *elf_sec__name(const GElf_Shdr *shdr,
|
|
|
|
const Elf_Data *secstrs)
|
|
|
|
{
|
|
|
|
return secstrs->d_buf + shdr->sh_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int elf_sec__is_text(const GElf_Shdr *shdr,
|
|
|
|
const Elf_Data *secstrs)
|
|
|
|
{
|
|
|
|
return strstr(elf_sec__name(shdr, secstrs), "text") != NULL;
|
|
|
|
}
|
|
|
|
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
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: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 00:50:39 +08:00
|
|
|
static inline bool elf_sec__is_data(const GElf_Shdr *shdr,
|
|
|
|
const Elf_Data *secstrs)
|
|
|
|
{
|
|
|
|
return strstr(elf_sec__name(shdr, secstrs), "data") != NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-29 01:55:04 +08:00
|
|
|
static inline const char *elf_sym__name(const GElf_Sym *sym,
|
|
|
|
const Elf_Data *symstrs)
|
|
|
|
{
|
|
|
|
return symstrs->d_buf + sym->st_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
|
|
|
|
GElf_Shdr *shp, const char *name,
|
2009-08-15 18:26:57 +08:00
|
|
|
size_t *idx)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
|
|
|
Elf_Scn *sec = NULL;
|
|
|
|
size_t cnt = 1;
|
|
|
|
|
|
|
|
while ((sec = elf_nextscn(elf, sec)) != NULL) {
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
gelf_getshdr(sec, shp);
|
|
|
|
str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
|
|
|
|
if (!strcmp(name, str)) {
|
2009-08-15 18:26:57 +08:00
|
|
|
if (idx)
|
|
|
|
*idx = cnt;
|
2009-05-29 01:55:04 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sec;
|
|
|
|
}
|
|
|
|
|
2009-06-03 11:54:33 +08:00
|
|
|
#define elf_section__for_each_rel(reldata, pos, pos_mem, idx, nr_entries) \
|
|
|
|
for (idx = 0, pos = gelf_getrel(reldata, 0, &pos_mem); \
|
|
|
|
idx < nr_entries; \
|
|
|
|
++idx, pos = gelf_getrel(reldata, idx, &pos_mem))
|
|
|
|
|
|
|
|
#define elf_section__for_each_rela(reldata, pos, pos_mem, idx, nr_entries) \
|
|
|
|
for (idx = 0, pos = gelf_getrela(reldata, 0, &pos_mem); \
|
|
|
|
idx < nr_entries; \
|
|
|
|
++idx, pos = gelf_getrela(reldata, idx, &pos_mem))
|
|
|
|
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
/*
|
|
|
|
* We need to check if we have a .dynsym, so that we can handle the
|
|
|
|
* .plt, synthesizing its symbols, that aren't on the symtabs (be it
|
|
|
|
* .dynsym or .symtab).
|
|
|
|
* And always look at the original dso, not at debuginfo packages, that
|
|
|
|
* have the PLT data stripped out (shdr_rel_plt.sh_type == SHT_NOBITS).
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__synthesize_plt_symbols(struct dso *dso, struct map *map,
|
2009-11-16 23:48:11 +08:00
|
|
|
symbol_filter_t filter)
|
2009-06-03 11:54:33 +08:00
|
|
|
{
|
|
|
|
uint32_t nr_rel_entries, idx;
|
|
|
|
GElf_Sym sym;
|
perf_counter tools: Define and use our own u64, s64 etc. definitions
On 64-bit powerpc, __u64 is defined to be unsigned long rather than
unsigned long long. This causes compiler warnings every time we
print a __u64 value with %Lx.
Rather than changing __u64, we define our own u64 to be unsigned long
long on all architectures, and similarly s64 as signed long long.
For consistency we also define u32, s32, u16, s16, u8 and s8. These
definitions are put in a new header, types.h, because these definitions
are needed in util/string.h and util/symbol.h.
The main change here is the mechanical change of __[us]{64,32,16,8}
to remove the "__". The other changes are:
* Create types.h
* Include types.h in perf.h, util/string.h and util/symbol.h
* Add types.h to the LIB_H definition in Makefile
* Added (u64) casts in process_overflow_event() and print_sym_table()
to kill two remaining warnings.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: benh@kernel.crashing.org
LKML-Reference: <19003.33494.495844.956580@cargo.ozlabs.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-06-19 20:21:42 +08:00
|
|
|
u64 plt_offset;
|
2009-06-03 11:54:33 +08:00
|
|
|
GElf_Shdr shdr_plt;
|
|
|
|
struct symbol *f;
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
GElf_Shdr shdr_rel_plt, shdr_dynsym;
|
2009-06-03 11:54:33 +08:00
|
|
|
Elf_Data *reldata, *syms, *symstrs;
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
Elf_Scn *scn_plt_rel, *scn_symstrs, *scn_dynsym;
|
|
|
|
size_t dynsym_idx;
|
|
|
|
GElf_Ehdr ehdr;
|
2009-06-03 11:54:33 +08:00
|
|
|
char sympltname[1024];
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
Elf *elf;
|
|
|
|
int nr = 0, symidx, fd, err = 0;
|
2010-12-10 04:27:07 +08:00
|
|
|
char name[PATH_MAX];
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
|
2010-12-10 04:27:07 +08:00
|
|
|
snprintf(name, sizeof(name), "%s%s",
|
2011-03-31 21:56:28 +08:00
|
|
|
symbol_conf.symfs, dso->long_name);
|
2010-12-10 04:27:07 +08:00
|
|
|
fd = open(name, O_RDONLY);
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
if (fd < 0)
|
|
|
|
goto out;
|
|
|
|
|
2009-10-25 00:10:36 +08:00
|
|
|
elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
if (elf == NULL)
|
|
|
|
goto out_close;
|
|
|
|
|
|
|
|
if (gelf_getehdr(elf, &ehdr) == NULL)
|
|
|
|
goto out_elf_end;
|
|
|
|
|
|
|
|
scn_dynsym = elf_section_by_name(elf, &ehdr, &shdr_dynsym,
|
|
|
|
".dynsym", &dynsym_idx);
|
|
|
|
if (scn_dynsym == NULL)
|
|
|
|
goto out_elf_end;
|
2009-06-03 11:54:33 +08:00
|
|
|
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt,
|
2009-06-03 11:54:33 +08:00
|
|
|
".rela.plt", NULL);
|
|
|
|
if (scn_plt_rel == NULL) {
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt,
|
2009-06-03 11:54:33 +08:00
|
|
|
".rel.plt", NULL);
|
|
|
|
if (scn_plt_rel == NULL)
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
goto out_elf_end;
|
2009-06-03 11:54:33 +08:00
|
|
|
}
|
|
|
|
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
err = -1;
|
|
|
|
|
2009-06-03 11:54:33 +08:00
|
|
|
if (shdr_rel_plt.sh_link != dynsym_idx)
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
goto out_elf_end;
|
2009-06-03 11:54:33 +08:00
|
|
|
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
if (elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL) == NULL)
|
|
|
|
goto out_elf_end;
|
2009-06-03 11:54:33 +08:00
|
|
|
|
|
|
|
/*
|
2009-08-15 18:26:57 +08:00
|
|
|
* Fetch the relocation section to find the idxes to the GOT
|
2009-06-03 11:54:33 +08:00
|
|
|
* and the symbols in the .dynsym they refer to.
|
|
|
|
*/
|
|
|
|
reldata = elf_getdata(scn_plt_rel, NULL);
|
|
|
|
if (reldata == NULL)
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
goto out_elf_end;
|
2009-06-03 11:54:33 +08:00
|
|
|
|
|
|
|
syms = elf_getdata(scn_dynsym, NULL);
|
|
|
|
if (syms == NULL)
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
goto out_elf_end;
|
2009-06-03 11:54:33 +08:00
|
|
|
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
scn_symstrs = elf_getscn(elf, shdr_dynsym.sh_link);
|
2009-06-03 11:54:33 +08:00
|
|
|
if (scn_symstrs == NULL)
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
goto out_elf_end;
|
2009-06-03 11:54:33 +08:00
|
|
|
|
|
|
|
symstrs = elf_getdata(scn_symstrs, NULL);
|
|
|
|
if (symstrs == NULL)
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
goto out_elf_end;
|
2009-06-03 11:54:33 +08:00
|
|
|
|
|
|
|
nr_rel_entries = shdr_rel_plt.sh_size / shdr_rel_plt.sh_entsize;
|
|
|
|
plt_offset = shdr_plt.sh_offset;
|
|
|
|
|
|
|
|
if (shdr_rel_plt.sh_type == SHT_RELA) {
|
|
|
|
GElf_Rela pos_mem, *pos;
|
|
|
|
|
|
|
|
elf_section__for_each_rela(reldata, pos, pos_mem, idx,
|
|
|
|
nr_rel_entries) {
|
|
|
|
symidx = GELF_R_SYM(pos->r_info);
|
|
|
|
plt_offset += shdr_plt.sh_entsize;
|
|
|
|
gelf_getsym(syms, symidx, &sym);
|
|
|
|
snprintf(sympltname, sizeof(sympltname),
|
|
|
|
"%s@plt", elf_sym__name(&sym, symstrs));
|
|
|
|
|
|
|
|
f = symbol__new(plt_offset, shdr_plt.sh_entsize,
|
2010-08-05 23:59:47 +08:00
|
|
|
STB_GLOBAL, sympltname);
|
2009-06-03 11:54:33 +08:00
|
|
|
if (!f)
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
goto out_elf_end;
|
2009-06-03 11:54:33 +08:00
|
|
|
|
2009-11-16 23:48:11 +08:00
|
|
|
if (filter && filter(map, f))
|
|
|
|
symbol__delete(f);
|
|
|
|
else {
|
2011-03-31 21:56:28 +08:00
|
|
|
symbols__insert(&dso->symbols[map->type], f);
|
2009-11-16 23:48:11 +08:00
|
|
|
++nr;
|
|
|
|
}
|
2009-06-03 11:54:33 +08:00
|
|
|
}
|
|
|
|
} else if (shdr_rel_plt.sh_type == SHT_REL) {
|
|
|
|
GElf_Rel pos_mem, *pos;
|
|
|
|
elf_section__for_each_rel(reldata, pos, pos_mem, idx,
|
|
|
|
nr_rel_entries) {
|
|
|
|
symidx = GELF_R_SYM(pos->r_info);
|
|
|
|
plt_offset += shdr_plt.sh_entsize;
|
|
|
|
gelf_getsym(syms, symidx, &sym);
|
|
|
|
snprintf(sympltname, sizeof(sympltname),
|
|
|
|
"%s@plt", elf_sym__name(&sym, symstrs));
|
|
|
|
|
|
|
|
f = symbol__new(plt_offset, shdr_plt.sh_entsize,
|
2010-08-05 23:59:47 +08:00
|
|
|
STB_GLOBAL, sympltname);
|
2009-06-03 11:54:33 +08:00
|
|
|
if (!f)
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
goto out_elf_end;
|
2009-06-03 11:54:33 +08:00
|
|
|
|
2009-11-16 23:48:11 +08:00
|
|
|
if (filter && filter(map, f))
|
|
|
|
symbol__delete(f);
|
|
|
|
else {
|
2011-03-31 21:56:28 +08:00
|
|
|
symbols__insert(&dso->symbols[map->type], f);
|
2009-11-16 23:48:11 +08:00
|
|
|
++nr;
|
|
|
|
}
|
2009-06-03 11:54:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
err = 0;
|
|
|
|
out_elf_end:
|
|
|
|
elf_end(elf);
|
|
|
|
out_close:
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (err == 0)
|
|
|
|
return nr;
|
|
|
|
out:
|
2010-03-12 07:12:40 +08:00
|
|
|
pr_debug("%s: problems reading %s PLT info.\n",
|
2011-03-31 21:56:28 +08:00
|
|
|
__func__, dso->long_name);
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
return 0;
|
2009-06-03 11:54:33 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static bool elf_sym__is_a(GElf_Sym *sym, enum map_type type)
|
2009-12-12 00:50:38 +08:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case MAP__FUNCTION:
|
2011-03-31 21:56:28 +08:00
|
|
|
return elf_sym__is_function(sym);
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
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: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 00:50:39 +08:00
|
|
|
case MAP__VARIABLE:
|
2011-03-31 21:56:28 +08:00
|
|
|
return elf_sym__is_object(sym);
|
2009-12-12 00:50:38 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static bool elf_sec__is_a(GElf_Shdr *shdr, Elf_Data *secstrs,
|
|
|
|
enum map_type type)
|
2009-12-12 00:50:38 +08:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case MAP__FUNCTION:
|
2011-03-31 21:56:28 +08:00
|
|
|
return elf_sec__is_text(shdr, secstrs);
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
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: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 00:50:39 +08:00
|
|
|
case MAP__VARIABLE:
|
2011-03-31 21:56:28 +08:00
|
|
|
return elf_sec__is_data(shdr, secstrs);
|
2009-12-12 00:50:38 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-14 21:56:33 +08:00
|
|
|
static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr)
|
|
|
|
{
|
|
|
|
Elf_Scn *sec = NULL;
|
|
|
|
GElf_Shdr shdr;
|
|
|
|
size_t cnt = 1;
|
|
|
|
|
|
|
|
while ((sec = elf_nextscn(elf, sec)) != NULL) {
|
|
|
|
gelf_getshdr(sec, &shdr);
|
|
|
|
|
|
|
|
if ((addr >= shdr.sh_addr) &&
|
|
|
|
(addr < (shdr.sh_addr + shdr.sh_size)))
|
|
|
|
return cnt;
|
|
|
|
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_sym(struct dso *dso, struct map *map, const char *name,
|
2010-07-30 20:50:09 +08:00
|
|
|
int fd, symbol_filter_t filter, int kmodule,
|
|
|
|
int want_symtab)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct kmap *kmap = dso->kernel ? map__kmap(map) : NULL;
|
2009-10-08 00:48:56 +08:00
|
|
|
struct map *curr_map = map;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct dso *curr_dso = dso;
|
2009-07-02 14:08:36 +08:00
|
|
|
Elf_Data *symstrs, *secstrs;
|
2009-05-29 01:55:04 +08:00
|
|
|
uint32_t nr_syms;
|
|
|
|
int err = -1;
|
2009-08-15 18:26:57 +08:00
|
|
|
uint32_t idx;
|
2009-05-29 01:55:04 +08:00
|
|
|
GElf_Ehdr ehdr;
|
2010-06-14 21:56:33 +08:00
|
|
|
GElf_Shdr shdr, opdshdr;
|
|
|
|
Elf_Data *syms, *opddata = NULL;
|
2009-05-29 01:55:04 +08:00
|
|
|
GElf_Sym sym;
|
2010-06-14 21:56:33 +08:00
|
|
|
Elf_Scn *sec, *sec_strndx, *opdsec;
|
2009-05-29 01:55:04 +08:00
|
|
|
Elf *elf;
|
2009-10-02 14:29:58 +08:00
|
|
|
int nr = 0;
|
2010-06-14 21:56:33 +08:00
|
|
|
size_t opdidx = 0;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2009-10-25 00:10:36 +08:00
|
|
|
elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
|
2009-05-29 01:55:04 +08:00
|
|
|
if (elf == NULL) {
|
2010-07-30 20:36:08 +08:00
|
|
|
pr_debug("%s: cannot read %s ELF file.\n", __func__, name);
|
2009-05-29 01:55:04 +08:00
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gelf_getehdr(elf, &ehdr) == NULL) {
|
2010-07-30 20:36:08 +08:00
|
|
|
pr_debug("%s: cannot get elf header.\n", __func__);
|
2009-05-29 01:55:04 +08:00
|
|
|
goto out_elf_end;
|
|
|
|
}
|
|
|
|
|
2010-07-30 20:50:09 +08:00
|
|
|
/* Always reject images with a mismatched build-id: */
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->has_build_id) {
|
2010-07-30 20:08:08 +08:00
|
|
|
u8 build_id[BUILD_ID_SIZE];
|
|
|
|
|
|
|
|
if (elf_read_build_id(elf, build_id,
|
|
|
|
BUILD_ID_SIZE) != BUILD_ID_SIZE)
|
|
|
|
goto out_elf_end;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (!dso__build_id_equal(dso, build_id))
|
2010-07-30 20:08:08 +08:00
|
|
|
goto out_elf_end;
|
|
|
|
}
|
|
|
|
|
2009-05-29 01:55:04 +08:00
|
|
|
sec = elf_section_by_name(elf, &ehdr, &shdr, ".symtab", NULL);
|
2009-06-03 11:54:33 +08:00
|
|
|
if (sec == NULL) {
|
2010-07-30 20:50:09 +08:00
|
|
|
if (want_symtab)
|
|
|
|
goto out_elf_end;
|
|
|
|
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
sec = elf_section_by_name(elf, &ehdr, &shdr, ".dynsym", NULL);
|
|
|
|
if (sec == NULL)
|
2009-06-03 11:54:33 +08:00
|
|
|
goto out_elf_end;
|
|
|
|
}
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2010-06-14 21:56:33 +08:00
|
|
|
opdsec = elf_section_by_name(elf, &ehdr, &opdshdr, ".opd", &opdidx);
|
|
|
|
if (opdsec)
|
|
|
|
opddata = elf_rawdata(opdsec, NULL);
|
|
|
|
|
2009-05-29 01:55:04 +08:00
|
|
|
syms = elf_getdata(sec, NULL);
|
|
|
|
if (syms == NULL)
|
|
|
|
goto out_elf_end;
|
|
|
|
|
|
|
|
sec = elf_getscn(elf, shdr.sh_link);
|
|
|
|
if (sec == NULL)
|
|
|
|
goto out_elf_end;
|
|
|
|
|
|
|
|
symstrs = elf_getdata(sec, NULL);
|
|
|
|
if (symstrs == NULL)
|
|
|
|
goto out_elf_end;
|
|
|
|
|
2009-07-02 14:08:36 +08:00
|
|
|
sec_strndx = elf_getscn(elf, ehdr.e_shstrndx);
|
|
|
|
if (sec_strndx == NULL)
|
|
|
|
goto out_elf_end;
|
|
|
|
|
|
|
|
secstrs = elf_getdata(sec_strndx, NULL);
|
2009-07-30 18:25:29 +08:00
|
|
|
if (secstrs == NULL)
|
2009-07-02 14:08:36 +08:00
|
|
|
goto out_elf_end;
|
|
|
|
|
2009-05-29 01:55:04 +08:00
|
|
|
nr_syms = shdr.sh_size / shdr.sh_entsize;
|
|
|
|
|
2009-06-07 03:22:33 +08:00
|
|
|
memset(&sym, 0, sizeof(sym));
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->kernel == DSO_TYPE_USER) {
|
|
|
|
dso->adjust_symbols = (ehdr.e_type == ET_EXEC ||
|
2009-07-03 08:24:14 +08:00
|
|
|
elf_section_by_name(elf, &ehdr, &shdr,
|
|
|
|
".gnu.prelink_undo",
|
|
|
|
NULL) != NULL);
|
2011-03-31 21:56:28 +08:00
|
|
|
} else {
|
|
|
|
dso->adjust_symbols = 0;
|
|
|
|
}
|
2009-08-15 18:26:57 +08:00
|
|
|
elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) {
|
2009-05-29 01:55:04 +08:00
|
|
|
struct symbol *f;
|
2010-01-06 02:50:31 +08:00
|
|
|
const char *elf_name = elf_sym__name(&sym, symstrs);
|
2009-10-08 00:48:56 +08:00
|
|
|
char *demangled = NULL;
|
2009-07-02 14:08:36 +08:00
|
|
|
int is_label = elf_sym__is_label(&sym);
|
|
|
|
const char *section_name;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2010-02-04 02:52:00 +08:00
|
|
|
if (kmap && kmap->ref_reloc_sym && kmap->ref_reloc_sym->name &&
|
|
|
|
strcmp(elf_name, kmap->ref_reloc_sym->name) == 0)
|
|
|
|
kmap->ref_reloc_sym->unrelocated_addr = sym.st_value;
|
2010-01-06 02:50:31 +08:00
|
|
|
|
2009-12-12 00:50:38 +08:00
|
|
|
if (!is_label && !elf_sym__is_a(&sym, map->type))
|
2009-05-29 01:55:04 +08:00
|
|
|
continue;
|
|
|
|
|
2010-08-09 19:21:18 +08:00
|
|
|
/* Reject ARM ELF "mapping symbols": these aren't unique and
|
|
|
|
* don't identify functions, so will confuse the profile
|
|
|
|
* output: */
|
|
|
|
if (ehdr.e_machine == EM_ARM) {
|
|
|
|
if (!strcmp(elf_name, "$a") ||
|
|
|
|
!strcmp(elf_name, "$d") ||
|
|
|
|
!strcmp(elf_name, "$t"))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-06-14 21:56:33 +08:00
|
|
|
if (opdsec && sym.st_shndx == opdidx) {
|
|
|
|
u32 offset = sym.st_value - opdshdr.sh_addr;
|
|
|
|
u64 *opd = opddata->d_buf + offset;
|
|
|
|
sym.st_value = *opd;
|
|
|
|
sym.st_shndx = elf_addr_to_index(elf, sym.st_value);
|
|
|
|
}
|
|
|
|
|
2009-05-29 01:55:04 +08:00
|
|
|
sec = elf_getscn(elf, sym.st_shndx);
|
|
|
|
if (!sec)
|
|
|
|
goto out_elf_end;
|
|
|
|
|
|
|
|
gelf_getshdr(sec, &shdr);
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2009-12-12 00:50:38 +08:00
|
|
|
if (is_label && !elf_sec__is_a(&shdr, secstrs, map->type))
|
2009-07-02 14:08:36 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
section_name = elf_sec__name(&shdr, secstrs);
|
perf_counter tools: Add 'perf annotate' feature
Add new perf sub-command to display annotated source code:
$ perf annotate decode_tree_entry
------------------------------------------------
Percent | Source code & Disassembly of /home/mingo/git/git
------------------------------------------------
:
: /home/mingo/git/git: file format elf64-x86-64
:
:
: Disassembly of section .text:
:
: 00000000004a0da0 <decode_tree_entry>:
: *modep = mode;
: return str;
: }
:
: static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned long size)
: {
3.82 : 4a0da0: 41 54 push %r12
: const char *path;
: unsigned int mode, len;
:
: if (size < 24 || buf[size - 21])
0.17 : 4a0da2: 48 83 fa 17 cmp $0x17,%rdx
: *modep = mode;
: return str;
: }
:
: static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned long size)
: {
0.00 : 4a0da6: 49 89 fc mov %rdi,%r12
0.00 : 4a0da9: 55 push %rbp
3.37 : 4a0daa: 53 push %rbx
: const char *path;
: unsigned int mode, len;
:
: if (size < 24 || buf[size - 21])
0.08 : 4a0dab: 76 73 jbe 4a0e20 <decode_tree_entry+0x80>
0.00 : 4a0dad: 80 7c 16 eb 00 cmpb $0x0,-0x15(%rsi,%rdx,1)
3.48 : 4a0db2: 75 6c jne 4a0e20 <decode_tree_entry+0x80>
: static const char *get_mode(const char *str, unsigned int *modep)
: {
: unsigned char c;
: unsigned int mode = 0;
:
: if (*str == ' ')
1.94 : 4a0db4: 0f b6 06 movzbl (%rsi),%eax
0.39 : 4a0db7: 3c 20 cmp $0x20,%al
0.00 : 4a0db9: 74 65 je 4a0e20 <decode_tree_entry+0x80>
: return NULL;
:
: while ((c = *str++) != ' ') {
0.06 : 4a0dbb: 89 c2 mov %eax,%edx
: if (c < '0' || c > '7')
1.99 : 4a0dbd: 31 ed xor %ebp,%ebp
: unsigned int mode = 0;
:
: if (*str == ' ')
: return NULL;
:
: while ((c = *str++) != ' ') {
1.74 : 4a0dbf: 48 8d 5e 01 lea 0x1(%rsi),%rbx
: if (c < '0' || c > '7')
0.00 : 4a0dc3: 8d 42 d0 lea -0x30(%rdx),%eax
0.17 : 4a0dc6: 3c 07 cmp $0x7,%al
0.00 : 4a0dc8: 76 0d jbe 4a0dd7 <decode_tree_entry+0x37>
0.00 : 4a0dca: eb 54 jmp 4a0e20 <decode_tree_entry+0x80>
0.00 : 4a0dcc: 0f 1f 40 00 nopl 0x0(%rax)
16.57 : 4a0dd0: 8d 42 d0 lea -0x30(%rdx),%eax
0.14 : 4a0dd3: 3c 07 cmp $0x7,%al
0.00 : 4a0dd5: 77 49 ja 4a0e20 <decode_tree_entry+0x80>
: return NULL;
: mode = (mode << 3) + (c - '0');
3.12 : 4a0dd7: 0f b6 c2 movzbl %dl,%eax
: unsigned int mode = 0;
:
: if (*str == ' ')
: return NULL;
:
: while ((c = *str++) != ' ') {
0.00 : 4a0dda: 0f b6 13 movzbl (%rbx),%edx
16.74 : 4a0ddd: 48 83 c3 01 add $0x1,%rbx
: if (c < '0' || c > '7')
: return NULL;
: mode = (mode << 3) + (c - '0');
The first column is the percentage of samples that arrived on that
particular line - relative to the total cost of the function.
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-06-06 21:48:52 +08:00
|
|
|
|
2011-01-22 00:40:19 +08:00
|
|
|
/* On ARM, symbols for thumb functions have 1 added to
|
|
|
|
* the symbol address as a flag - remove it */
|
|
|
|
if ((ehdr.e_machine == EM_ARM) &&
|
|
|
|
(map->type == MAP__FUNCTION) &&
|
|
|
|
(sym.st_value & 1))
|
|
|
|
--sym.st_value;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->kernel != DSO_TYPE_USER || kmodule) {
|
2009-10-08 00:48:56 +08:00
|
|
|
char dso_name[PATH_MAX];
|
|
|
|
|
|
|
|
if (strcmp(section_name,
|
2010-03-16 02:03:50 +08:00
|
|
|
(curr_dso->short_name +
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->short_name_len)) == 0)
|
2009-10-08 00:48:56 +08:00
|
|
|
goto new_symbol;
|
|
|
|
|
|
|
|
if (strcmp(section_name, ".text") == 0) {
|
|
|
|
curr_map = map;
|
2011-03-31 21:56:28 +08:00
|
|
|
curr_dso = dso;
|
2009-10-08 00:48:56 +08:00
|
|
|
goto new_symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(dso_name, sizeof(dso_name),
|
2011-03-31 21:56:28 +08:00
|
|
|
"%s%s", dso->short_name, section_name);
|
2009-10-08 00:48:56 +08:00
|
|
|
|
2010-02-04 02:52:00 +08:00
|
|
|
curr_map = map_groups__find_by_name(kmap->kmaps, map->type, dso_name);
|
2009-10-08 00:48:56 +08:00
|
|
|
if (curr_map == NULL) {
|
|
|
|
u64 start = sym.st_value;
|
|
|
|
|
|
|
|
if (kmodule)
|
|
|
|
start += map->start + shdr.sh_offset;
|
|
|
|
|
2009-10-31 02:28:24 +08:00
|
|
|
curr_dso = dso__new(dso_name);
|
2009-10-08 00:48:56 +08:00
|
|
|
if (curr_dso == NULL)
|
|
|
|
goto out_elf_end;
|
2011-03-31 21:56:28 +08:00
|
|
|
curr_dso->kernel = dso->kernel;
|
|
|
|
curr_dso->long_name = dso->long_name;
|
|
|
|
curr_dso->long_name_len = dso->long_name_len;
|
2009-11-28 02:29:16 +08:00
|
|
|
curr_map = map__new2(start, curr_dso,
|
2010-02-04 02:52:01 +08:00
|
|
|
map->type);
|
2009-10-08 00:48:56 +08:00
|
|
|
if (curr_map == NULL) {
|
|
|
|
dso__delete(curr_dso);
|
|
|
|
goto out_elf_end;
|
|
|
|
}
|
2009-10-20 03:17:57 +08:00
|
|
|
curr_map->map_ip = identity__map_ip;
|
|
|
|
curr_map->unmap_ip = identity__map_ip;
|
2011-03-31 21:56:28 +08:00
|
|
|
curr_dso->symtab_type = dso->symtab_type;
|
2010-02-04 02:52:00 +08:00
|
|
|
map_groups__insert(kmap->kmaps, curr_map);
|
2011-03-31 21:56:28 +08:00
|
|
|
dsos__add(&dso->node, curr_dso);
|
2010-02-04 02:52:01 +08:00
|
|
|
dso__set_loaded(curr_dso, map->type);
|
2009-10-08 00:48:56 +08:00
|
|
|
} else
|
|
|
|
curr_dso = curr_map->dso;
|
|
|
|
|
|
|
|
goto new_symbol;
|
2009-10-06 01:26:17 +08:00
|
|
|
}
|
|
|
|
|
2009-10-08 00:48:56 +08:00
|
|
|
if (curr_dso->adjust_symbols) {
|
2011-01-23 06:37:02 +08:00
|
|
|
pr_debug4("%s: adjusting symbol: st_value: %#" PRIx64 " "
|
|
|
|
"sh_addr: %#" PRIx64 " sh_offset: %#" PRIx64 "\n", __func__,
|
2010-02-04 02:52:06 +08:00
|
|
|
(u64)sym.st_value, (u64)shdr.sh_addr,
|
|
|
|
(u64)shdr.sh_offset);
|
2009-06-30 22:43:17 +08:00
|
|
|
sym.st_value -= shdr.sh_addr - shdr.sh_offset;
|
2009-10-06 01:26:17 +08:00
|
|
|
}
|
2009-07-21 01:14:12 +08:00
|
|
|
/*
|
|
|
|
* We need to figure out if the object was created from C++ sources
|
|
|
|
* DWARF DW_compile_unit has this, but we don't always have access
|
|
|
|
* to it...
|
|
|
|
*/
|
2009-08-15 18:26:57 +08:00
|
|
|
demangled = bfd_demangle(NULL, elf_name, DMGL_PARAMS | DMGL_ANSI);
|
2009-07-21 01:14:12 +08:00
|
|
|
if (demangled != NULL)
|
2009-08-15 18:26:57 +08:00
|
|
|
elf_name = demangled;
|
2009-10-08 00:48:56 +08:00
|
|
|
new_symbol:
|
2010-08-05 23:59:47 +08:00
|
|
|
f = symbol__new(sym.st_value, sym.st_size,
|
|
|
|
GELF_ST_BIND(sym.st_info), elf_name);
|
2009-07-21 01:14:12 +08:00
|
|
|
free(demangled);
|
2009-05-29 01:55:04 +08:00
|
|
|
if (!f)
|
|
|
|
goto out_elf_end;
|
|
|
|
|
2009-10-08 00:48:56 +08:00
|
|
|
if (filter && filter(curr_map, f))
|
2009-10-31 02:28:24 +08:00
|
|
|
symbol__delete(f);
|
2009-05-29 01:55:26 +08:00
|
|
|
else {
|
2009-11-28 02:29:17 +08:00
|
|
|
symbols__insert(&curr_dso->symbols[curr_map->type], f);
|
2009-05-29 01:55:26 +08:00
|
|
|
nr++;
|
|
|
|
}
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
|
|
|
|
2009-10-08 00:48:56 +08:00
|
|
|
/*
|
|
|
|
* For misannotated, zeroed, ASM function sizes.
|
|
|
|
*/
|
2010-02-04 02:52:01 +08:00
|
|
|
if (nr > 0) {
|
2011-03-31 21:56:28 +08:00
|
|
|
symbols__fixup_end(&dso->symbols[map->type]);
|
2010-02-04 02:52:01 +08:00
|
|
|
if (kmap) {
|
|
|
|
/*
|
|
|
|
* We need to fixup this here too because we create new
|
|
|
|
* maps here, for things like vsyscall sections.
|
|
|
|
*/
|
|
|
|
__map_groups__fixup_end(kmap->kmaps, map->type);
|
|
|
|
}
|
|
|
|
}
|
2009-05-29 01:55:04 +08:00
|
|
|
err = nr;
|
|
|
|
out_elf_end:
|
|
|
|
elf_end(elf);
|
|
|
|
out_close:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static bool dso__build_id_equal(const struct dso *dso, u8 *build_id)
|
2009-11-21 06:51:26 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
return memcmp(dso->build_id, build_id, sizeof(dso->build_id)) == 0;
|
2009-11-21 06:51:26 +08:00
|
|
|
}
|
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
|
2009-11-11 11:51:04 +08:00
|
|
|
{
|
2009-11-19 06:20:51 +08:00
|
|
|
bool have_build_id = false;
|
2009-11-11 11:51:04 +08:00
|
|
|
struct dso *pos;
|
|
|
|
|
2010-02-04 02:52:05 +08:00
|
|
|
list_for_each_entry(pos, head, node) {
|
|
|
|
if (with_hits && !pos->hit)
|
|
|
|
continue;
|
2010-05-19 22:13:02 +08:00
|
|
|
if (pos->has_build_id) {
|
|
|
|
have_build_id = true;
|
|
|
|
continue;
|
|
|
|
}
|
2009-11-19 06:20:51 +08:00
|
|
|
if (filename__read_build_id(pos->long_name, pos->build_id,
|
|
|
|
sizeof(pos->build_id)) > 0) {
|
|
|
|
have_build_id = true;
|
|
|
|
pos->has_build_id = true;
|
|
|
|
}
|
2010-02-04 02:52:05 +08:00
|
|
|
}
|
2009-11-11 11:51:04 +08:00
|
|
|
|
2009-11-19 06:20:51 +08:00
|
|
|
return have_build_id;
|
2009-11-11 11:51:04 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 06:51:25 +08:00
|
|
|
/*
|
|
|
|
* Align offset to 4 bytes as needed for note name and descriptor data.
|
|
|
|
*/
|
|
|
|
#define NOTE_ALIGN(n) (((n) + 3) & -4U)
|
|
|
|
|
2010-07-30 20:08:08 +08:00
|
|
|
static int elf_read_build_id(Elf *elf, void *bf, size_t size)
|
2009-08-06 06:02:49 +08:00
|
|
|
{
|
2010-07-30 20:08:08 +08:00
|
|
|
int err = -1;
|
2009-08-06 06:02:49 +08:00
|
|
|
GElf_Ehdr ehdr;
|
|
|
|
GElf_Shdr shdr;
|
2009-11-21 06:51:25 +08:00
|
|
|
Elf_Data *data;
|
2009-08-06 06:02:49 +08:00
|
|
|
Elf_Scn *sec;
|
2009-11-22 18:29:44 +08:00
|
|
|
Elf_Kind ek;
|
2009-11-21 06:51:25 +08:00
|
|
|
void *ptr;
|
2009-08-06 06:02:49 +08:00
|
|
|
|
2009-11-04 07:46:10 +08:00
|
|
|
if (size < BUILD_ID_SIZE)
|
|
|
|
goto out;
|
|
|
|
|
2009-11-22 18:29:44 +08:00
|
|
|
ek = elf_kind(elf);
|
|
|
|
if (ek != ELF_K_ELF)
|
2010-07-30 20:08:08 +08:00
|
|
|
goto out;
|
2009-11-22 18:29:44 +08:00
|
|
|
|
2009-08-06 06:02:49 +08:00
|
|
|
if (gelf_getehdr(elf, &ehdr) == NULL) {
|
2009-10-22 03:34:06 +08:00
|
|
|
pr_err("%s: cannot get elf header.\n", __func__);
|
2010-07-30 20:08:08 +08:00
|
|
|
goto out;
|
2009-08-06 06:02:49 +08:00
|
|
|
}
|
|
|
|
|
2009-11-04 07:46:10 +08:00
|
|
|
sec = elf_section_by_name(elf, &ehdr, &shdr,
|
|
|
|
".note.gnu.build-id", NULL);
|
2009-11-21 06:51:25 +08:00
|
|
|
if (sec == NULL) {
|
|
|
|
sec = elf_section_by_name(elf, &ehdr, &shdr,
|
|
|
|
".notes", NULL);
|
|
|
|
if (sec == NULL)
|
2010-07-30 20:08:08 +08:00
|
|
|
goto out;
|
2009-11-21 06:51:25 +08:00
|
|
|
}
|
2009-08-06 06:02:49 +08:00
|
|
|
|
2009-11-21 06:51:25 +08:00
|
|
|
data = elf_getdata(sec, NULL);
|
|
|
|
if (data == NULL)
|
2010-07-30 20:08:08 +08:00
|
|
|
goto out;
|
2009-11-21 06:51:25 +08:00
|
|
|
|
|
|
|
ptr = data->d_buf;
|
|
|
|
while (ptr < (data->d_buf + data->d_size)) {
|
|
|
|
GElf_Nhdr *nhdr = ptr;
|
|
|
|
int namesz = NOTE_ALIGN(nhdr->n_namesz),
|
|
|
|
descsz = NOTE_ALIGN(nhdr->n_descsz);
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
ptr += sizeof(*nhdr);
|
|
|
|
name = ptr;
|
|
|
|
ptr += namesz;
|
|
|
|
if (nhdr->n_type == NT_GNU_BUILD_ID &&
|
|
|
|
nhdr->n_namesz == sizeof("GNU")) {
|
|
|
|
if (memcmp(name, "GNU", sizeof("GNU")) == 0) {
|
|
|
|
memcpy(bf, ptr, BUILD_ID_SIZE);
|
|
|
|
err = BUILD_ID_SIZE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ptr += descsz;
|
|
|
|
}
|
2010-07-30 20:08:08 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int filename__read_build_id(const char *filename, void *bf, size_t size)
|
|
|
|
{
|
|
|
|
int fd, err = -1;
|
|
|
|
Elf *elf;
|
|
|
|
|
|
|
|
if (size < BUILD_ID_SIZE)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
|
|
|
|
if (elf == NULL) {
|
|
|
|
pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename);
|
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = elf_read_build_id(elf, bf, size);
|
|
|
|
|
2009-11-04 07:46:10 +08:00
|
|
|
elf_end(elf);
|
|
|
|
out_close:
|
|
|
|
close(fd);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2009-11-19 06:20:52 +08:00
|
|
|
int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
|
|
|
|
{
|
|
|
|
int fd, err = -1;
|
|
|
|
|
|
|
|
if (size < BUILD_ID_SIZE)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
char bf[BUFSIZ];
|
|
|
|
GElf_Nhdr nhdr;
|
|
|
|
int namesz, descsz;
|
|
|
|
|
|
|
|
if (read(fd, &nhdr, sizeof(nhdr)) != sizeof(nhdr))
|
|
|
|
break;
|
|
|
|
|
2009-11-21 06:51:25 +08:00
|
|
|
namesz = NOTE_ALIGN(nhdr.n_namesz);
|
|
|
|
descsz = NOTE_ALIGN(nhdr.n_descsz);
|
2009-11-19 06:20:52 +08:00
|
|
|
if (nhdr.n_type == NT_GNU_BUILD_ID &&
|
|
|
|
nhdr.n_namesz == sizeof("GNU")) {
|
|
|
|
if (read(fd, bf, namesz) != namesz)
|
|
|
|
break;
|
|
|
|
if (memcmp(bf, "GNU", sizeof("GNU")) == 0) {
|
|
|
|
if (read(fd, build_id,
|
|
|
|
BUILD_ID_SIZE) == BUILD_ID_SIZE) {
|
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (read(fd, bf, descsz) != descsz)
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
int n = namesz + descsz;
|
|
|
|
if (read(fd, bf, n) != n)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
char dso__symtab_origin(const struct dso *dso)
|
2009-08-07 01:43:17 +08:00
|
|
|
{
|
|
|
|
static const char origin[] = {
|
2011-03-12 00:13:36 +08:00
|
|
|
[SYMTAB__KALLSYMS] = 'k',
|
|
|
|
[SYMTAB__JAVA_JIT] = 'j',
|
|
|
|
[SYMTAB__BUILD_ID_CACHE] = 'B',
|
|
|
|
[SYMTAB__FEDORA_DEBUGINFO] = 'f',
|
|
|
|
[SYMTAB__UBUNTU_DEBUGINFO] = 'u',
|
|
|
|
[SYMTAB__BUILDID_DEBUGINFO] = 'b',
|
|
|
|
[SYMTAB__SYSTEM_PATH_DSO] = 'd',
|
|
|
|
[SYMTAB__SYSTEM_PATH_KMODULE] = 'K',
|
|
|
|
[SYMTAB__GUEST_KALLSYMS] = 'g',
|
|
|
|
[SYMTAB__GUEST_KMODULE] = 'G',
|
2009-08-07 01:43:17 +08:00
|
|
|
};
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso == NULL || dso->symtab_type == SYMTAB__NOT_FOUND)
|
2009-08-07 01:43:17 +08:00
|
|
|
return '!';
|
2011-03-31 21:56:28 +08:00
|
|
|
return origin[dso->symtab_type];
|
2009-08-07 01:43:17 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2009-08-06 06:02:49 +08:00
|
|
|
int size = PATH_MAX;
|
2009-11-21 06:51:27 +08:00
|
|
|
char *name;
|
2009-05-29 01:55:04 +08:00
|
|
|
int ret = -1;
|
|
|
|
int fd;
|
2010-04-28 08:17:50 +08:00
|
|
|
struct machine *machine;
|
2010-04-19 13:32:50 +08:00
|
|
|
const char *root_dir;
|
2010-07-30 20:50:09 +08:00
|
|
|
int want_symtab;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_loaded(dso, map->type);
|
2009-10-29 07:51:21 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->kernel == DSO_TYPE_KERNEL)
|
|
|
|
return dso__load_kernel_sym(dso, map, filter);
|
|
|
|
else if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
|
|
|
return dso__load_guest_kernel_sym(dso, map, filter);
|
2010-04-19 13:32:50 +08:00
|
|
|
|
2010-04-28 08:17:50 +08:00
|
|
|
if (map->groups && map->groups->machine)
|
|
|
|
machine = map->groups->machine;
|
2010-04-19 13:32:50 +08:00
|
|
|
else
|
2010-04-28 08:17:50 +08:00
|
|
|
machine = NULL;
|
2009-11-21 06:51:27 +08:00
|
|
|
|
|
|
|
name = malloc(size);
|
2009-05-29 01:55:04 +08:00
|
|
|
if (!name)
|
|
|
|
return -1;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->adjust_symbols = 0;
|
2009-06-30 22:43:17 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (strncmp(dso->name, "/tmp/perf-", 10) == 0) {
|
|
|
|
ret = dso__load_perf_map(dso, map, filter);
|
|
|
|
dso->symtab_type = ret > 0 ? SYMTAB__JAVA_JIT :
|
2011-03-12 00:13:36 +08:00
|
|
|
SYMTAB__NOT_FOUND;
|
2009-08-07 01:43:17 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-07-30 20:50:09 +08:00
|
|
|
/* Iterate over candidate debug images.
|
|
|
|
* On the first pass, only load images if they have a full symtab.
|
|
|
|
* Failing that, do a second pass where we accept .dynsym also
|
|
|
|
*/
|
2011-03-23 02:42:14 +08:00
|
|
|
want_symtab = 1;
|
|
|
|
restart:
|
2011-03-31 21:56:28 +08:00
|
|
|
for (dso->symtab_type = SYMTAB__BUILD_ID_CACHE;
|
|
|
|
dso->symtab_type != SYMTAB__NOT_FOUND;
|
|
|
|
dso->symtab_type++) {
|
|
|
|
switch (dso->symtab_type) {
|
2011-03-12 00:13:36 +08:00
|
|
|
case SYMTAB__BUILD_ID_CACHE:
|
2010-12-10 04:27:07 +08:00
|
|
|
/* skip the locally configured cache if a symfs is given */
|
|
|
|
if (symbol_conf.symfs[0] ||
|
2011-03-31 21:56:28 +08:00
|
|
|
(dso__build_id_filename(dso, name, size) == NULL)) {
|
2010-07-30 20:50:09 +08:00
|
|
|
continue;
|
2010-12-10 04:27:07 +08:00
|
|
|
}
|
2010-07-30 20:50:09 +08:00
|
|
|
break;
|
2011-03-12 00:13:36 +08:00
|
|
|
case SYMTAB__FEDORA_DEBUGINFO:
|
2010-12-10 04:27:07 +08:00
|
|
|
snprintf(name, size, "%s/usr/lib/debug%s.debug",
|
2011-03-31 21:56:28 +08:00
|
|
|
symbol_conf.symfs, dso->long_name);
|
2009-05-29 01:55:04 +08:00
|
|
|
break;
|
2011-03-12 00:13:36 +08:00
|
|
|
case SYMTAB__UBUNTU_DEBUGINFO:
|
2010-12-10 04:27:07 +08:00
|
|
|
snprintf(name, size, "%s/usr/lib/debug%s",
|
2011-03-31 21:56:28 +08:00
|
|
|
symbol_conf.symfs, dso->long_name);
|
2009-05-29 01:55:04 +08:00
|
|
|
break;
|
2011-03-12 00:13:36 +08:00
|
|
|
case SYMTAB__BUILDID_DEBUGINFO: {
|
2010-07-30 20:50:09 +08:00
|
|
|
char build_id_hex[BUILD_ID_SIZE * 2 + 1];
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (!dso->has_build_id)
|
2010-07-30 20:50:09 +08:00
|
|
|
continue;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
build_id__sprintf(dso->build_id,
|
|
|
|
sizeof(dso->build_id),
|
2010-07-30 20:50:09 +08:00
|
|
|
build_id_hex);
|
|
|
|
snprintf(name, size,
|
2010-12-10 04:27:07 +08:00
|
|
|
"%s/usr/lib/debug/.build-id/%.2s/%s.debug",
|
|
|
|
symbol_conf.symfs, build_id_hex, build_id_hex + 2);
|
2009-08-06 06:02:49 +08:00
|
|
|
}
|
2010-07-30 20:50:09 +08:00
|
|
|
break;
|
2011-03-12 00:13:36 +08:00
|
|
|
case SYMTAB__SYSTEM_PATH_DSO:
|
2010-12-10 04:27:07 +08:00
|
|
|
snprintf(name, size, "%s%s",
|
2011-03-31 21:56:28 +08:00
|
|
|
symbol_conf.symfs, dso->long_name);
|
2009-05-29 01:55:04 +08:00
|
|
|
break;
|
2011-03-12 00:13:36 +08:00
|
|
|
case SYMTAB__GUEST_KMODULE:
|
2011-01-25 00:13:04 +08:00
|
|
|
if (map->groups && machine)
|
|
|
|
root_dir = machine->root_dir;
|
2010-04-19 13:32:50 +08:00
|
|
|
else
|
|
|
|
root_dir = "";
|
2010-12-10 04:27:07 +08:00
|
|
|
snprintf(name, size, "%s%s%s", symbol_conf.symfs,
|
2011-03-31 21:56:28 +08:00
|
|
|
root_dir, dso->long_name);
|
2010-12-10 04:27:07 +08:00
|
|
|
break;
|
|
|
|
|
2011-03-12 00:13:36 +08:00
|
|
|
case SYMTAB__SYSTEM_PATH_KMODULE:
|
2010-12-10 04:27:07 +08:00
|
|
|
snprintf(name, size, "%s%s", symbol_conf.symfs,
|
2011-03-31 21:56:28 +08:00
|
|
|
dso->long_name);
|
2010-04-19 13:32:50 +08:00
|
|
|
break;
|
2011-03-23 02:42:14 +08:00
|
|
|
default:;
|
2009-05-29 01:55:04 +08:00
|
|
|
}
|
2010-07-30 20:50:09 +08:00
|
|
|
|
|
|
|
/* Name is now the name of the next image to try */
|
2009-05-29 01:55:04 +08:00
|
|
|
fd = open(name, O_RDONLY);
|
2010-07-30 20:50:09 +08:00
|
|
|
if (fd < 0)
|
|
|
|
continue;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
ret = dso__load_sym(dso, map, name, fd, filter, 0,
|
2010-07-30 20:50:09 +08:00
|
|
|
want_symtab);
|
|
|
|
close(fd);
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2010-07-30 20:50:09 +08:00
|
|
|
/*
|
|
|
|
* Some people seem to have debuginfo files _WITHOUT_ debug
|
|
|
|
* info!?!?
|
|
|
|
*/
|
|
|
|
if (!ret)
|
|
|
|
continue;
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2010-07-30 20:50:09 +08:00
|
|
|
if (ret > 0) {
|
2011-03-31 21:56:28 +08:00
|
|
|
int nr_plt = dso__synthesize_plt_symbols(dso, map,
|
|
|
|
filter);
|
2010-07-30 20:50:09 +08:00
|
|
|
if (nr_plt > 0)
|
|
|
|
ret += nr_plt;
|
|
|
|
break;
|
|
|
|
}
|
perf_counter tools: PLT info is stripped in -debuginfo packages
So we need to get the richer .symtab from the debuginfo
packages but the PLT info from the original DSO where we have
just the leaner .dynsym symtab.
Example:
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > before
| [acme@doppio pahole]$ perf report --sort comm,dso,symbol > after
| [acme@doppio pahole]$ diff -U1 before after
| --- before 2009-07-11 11:04:22.688595741 -0300
| +++ after 2009-07-11 11:04:33.380595676 -0300
| @@ -80,3 +80,2 @@
| 0.07% pahole ./build/pahole [.] pahole_stealer
| - 0.06% pahole /usr/lib64/libdw-0.141.so [.] 0x00000000007140
| 0.06% pahole /usr/lib64/libdw-0.141.so [.] __libdw_getabbrev
| @@ -91,2 +90,3 @@
| 0.06% pahole [kernel] [k] free_hot_cold_page
| + 0.06% pahole /usr/lib64/libdw-0.141.so [.] tfind@plt
| 0.05% pahole ./build/libdwarves.so.1.0.0 [.] ftype__add_parameter
| @@ -242,2 +242,3 @@
| 0.01% pahole [kernel] [k] account_group_user_time
| + 0.01% pahole /usr/lib64/libdw-0.141.so [.] strlen@plt
| 0.01% pahole ./build/pahole [.] strcmp@plt
| [acme@doppio pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1247325517-12272-4-git-send-email-acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-07-11 23:18:36 +08:00
|
|
|
}
|
2010-07-30 20:50:09 +08:00
|
|
|
|
2011-03-23 02:42:14 +08:00
|
|
|
/*
|
|
|
|
* If we wanted a full symtab but no image had one,
|
|
|
|
* relax our requirements and repeat the search.
|
|
|
|
*/
|
|
|
|
if (ret <= 0 && want_symtab) {
|
|
|
|
want_symtab = 0;
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
|
2009-05-29 01:55:04 +08:00
|
|
|
free(name);
|
2011-03-31 21:56:28 +08:00
|
|
|
if (ret < 0 && strstr(dso->name, " (deleted)") != NULL)
|
2009-08-12 04:04:36 +08:00
|
|
|
return 0;
|
2009-05-29 01:55:04 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
struct map *map_groups__find_by_name(struct map_groups *mg,
|
perf symbols: Allow lookups by symbol name too
Configurable via symbol_conf.sort_by_name, so that the cost of an
extra rb_node on all 'struct symbol' instances is not paid by tools
that only want to decode addresses.
How to use it:
symbol_conf.sort_by_name = true;
symbol_init(&symbol_conf);
struct map *map = map_groups__find_by_name(kmaps, MAP__VARIABLE, "[kernel.kallsyms]");
if (map == NULL) {
pr_err("couldn't find map!\n");
kernel_maps__fprintf(stdout);
} else {
struct symbol *sym = map__find_symbol_by_name(map, sym_filter, NULL);
if (sym == NULL)
pr_err("couldn't find symbol %s!\n", sym_filter);
else
pr_info("symbol %s: %#Lx-%#Lx \n", sym_filter, sym->start, sym->end);
}
Looking over the vmlinux/kallsyms is common enough that I'll add a
variable to the upcoming struct perf_session to avoid the need to
use map_groups__find_by_name to get the main vmlinux/kallsyms map.
The above example looks on the 'variable' symtab, but it is just
like that for the functions one.
Also the sort operation is done when we first use
map__find_symbol_by_name, in a lazy way.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260564622-12392-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 04:50:22 +08:00
|
|
|
enum map_type type, const char *name)
|
2009-10-02 14:29:58 +08:00
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
for (nd = rb_first(&mg->maps[type]); nd; nd = rb_next(nd)) {
|
2009-10-02 14:29:58 +08:00
|
|
|
struct map *map = rb_entry(nd, struct map, rb_node);
|
|
|
|
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
if (map->dso && strcmp(map->dso->short_name, name) == 0)
|
2009-10-02 14:29:58 +08:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__kernel_module_get_build_id(struct dso *dso,
|
|
|
|
const char *root_dir)
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
{
|
|
|
|
char filename[PATH_MAX];
|
|
|
|
/*
|
|
|
|
* kernel module short names are of the form "[module]" and
|
|
|
|
* we need just "module" here.
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
const char *name = dso->short_name + 1;
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
|
|
|
|
snprintf(filename, sizeof(filename),
|
2010-04-19 13:32:50 +08:00
|
|
|
"%s/sys/module/%.*s/notes/.note.gnu.build-id",
|
|
|
|
root_dir, (int)strlen(name) - 1, name);
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (sysfs__read_build_id(filename, dso->build_id,
|
|
|
|
sizeof(dso->build_id)) == 0)
|
|
|
|
dso->has_build_id = true;
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int map_groups__set_modules_path_dir(struct map_groups *mg,
|
2010-04-19 13:32:50 +08:00
|
|
|
const char *dir_name)
|
2009-07-02 14:08:36 +08:00
|
|
|
{
|
2009-10-02 14:29:58 +08:00
|
|
|
struct dirent *dent;
|
2010-03-26 06:59:00 +08:00
|
|
|
DIR *dir = opendir(dir_name);
|
2010-06-24 15:04:02 +08:00
|
|
|
int ret = 0;
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2009-10-02 14:29:58 +08:00
|
|
|
if (!dir) {
|
2010-03-26 06:59:00 +08:00
|
|
|
pr_debug("%s: cannot open %s dir\n", __func__, dir_name);
|
2009-10-02 14:29:58 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2009-10-02 14:29:58 +08:00
|
|
|
while ((dent = readdir(dir)) != NULL) {
|
|
|
|
char path[PATH_MAX];
|
2010-04-19 13:32:50 +08:00
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
/*sshfs might return bad dent->d_type, so we have to stat*/
|
|
|
|
sprintf(path, "%s/%s", dir_name, dent->d_name);
|
|
|
|
if (stat(path, &st))
|
|
|
|
continue;
|
2009-10-02 14:29:58 +08:00
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
if (S_ISDIR(st.st_mode)) {
|
2009-10-02 14:29:58 +08:00
|
|
|
if (!strcmp(dent->d_name, ".") ||
|
|
|
|
!strcmp(dent->d_name, ".."))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
snprintf(path, sizeof(path), "%s/%s",
|
2010-03-26 06:59:00 +08:00
|
|
|
dir_name, dent->d_name);
|
2011-03-31 21:56:28 +08:00
|
|
|
ret = map_groups__set_modules_path_dir(mg, path);
|
2010-06-24 15:04:02 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2009-10-02 14:29:58 +08:00
|
|
|
} else {
|
|
|
|
char *dot = strrchr(dent->d_name, '.'),
|
|
|
|
dso_name[PATH_MAX];
|
|
|
|
struct map *map;
|
2009-11-18 01:40:53 +08:00
|
|
|
char *long_name;
|
2009-10-02 14:29:58 +08:00
|
|
|
|
|
|
|
if (dot == NULL || strcmp(dot, ".ko"))
|
|
|
|
continue;
|
|
|
|
snprintf(dso_name, sizeof(dso_name), "[%.*s]",
|
|
|
|
(int)(dot - dent->d_name), dent->d_name);
|
|
|
|
|
2009-10-06 01:26:18 +08:00
|
|
|
strxfrchar(dso_name, '-', '_');
|
2011-03-31 21:56:28 +08:00
|
|
|
map = map_groups__find_by_name(mg, MAP__FUNCTION,
|
|
|
|
dso_name);
|
2009-10-02 14:29:58 +08:00
|
|
|
if (map == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
snprintf(path, sizeof(path), "%s/%s",
|
2010-03-26 06:59:00 +08:00
|
|
|
dir_name, dent->d_name);
|
2009-10-02 14:29:58 +08:00
|
|
|
|
2009-11-18 01:40:53 +08:00
|
|
|
long_name = strdup(path);
|
2010-06-24 15:04:02 +08:00
|
|
|
if (long_name == NULL) {
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-11-18 01:40:53 +08:00
|
|
|
dso__set_long_name(map->dso, long_name);
|
2010-07-30 02:11:30 +08:00
|
|
|
map->dso->lname_alloc = 1;
|
2010-04-19 13:32:50 +08:00
|
|
|
dso__kernel_module_get_build_id(map->dso, "");
|
2009-10-02 14:29:58 +08:00
|
|
|
}
|
|
|
|
}
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2010-06-24 15:04:02 +08:00
|
|
|
out:
|
2009-10-02 14:29:58 +08:00
|
|
|
closedir(dir);
|
2010-06-24 15:04:02 +08:00
|
|
|
return ret;
|
2009-10-02 14:29:58 +08:00
|
|
|
}
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
static char *get_kernel_version(const char *root_dir)
|
2009-10-02 14:29:58 +08:00
|
|
|
{
|
2010-04-19 13:32:50 +08:00
|
|
|
char version[PATH_MAX];
|
|
|
|
FILE *file;
|
|
|
|
char *name, *tmp;
|
|
|
|
const char *prefix = "Linux version ";
|
|
|
|
|
|
|
|
sprintf(version, "%s/proc/version", root_dir);
|
|
|
|
file = fopen(version, "r");
|
|
|
|
if (!file)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
version[0] = '\0';
|
|
|
|
tmp = fgets(version, sizeof(version), file);
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
name = strstr(version, prefix);
|
|
|
|
if (!name)
|
|
|
|
return NULL;
|
|
|
|
name += strlen(prefix);
|
|
|
|
tmp = strchr(name, ' ');
|
|
|
|
if (tmp)
|
|
|
|
*tmp = '\0';
|
|
|
|
|
|
|
|
return strdup(name);
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int machine__set_modules_path(struct machine *machine)
|
2010-04-19 13:32:50 +08:00
|
|
|
{
|
|
|
|
char *version;
|
2009-10-02 14:29:58 +08:00
|
|
|
char modules_path[PATH_MAX];
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
version = get_kernel_version(machine->root_dir);
|
2010-04-19 13:32:50 +08:00
|
|
|
if (!version)
|
2009-10-02 14:29:58 +08:00
|
|
|
return -1;
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s/kernel",
|
2011-03-31 21:56:28 +08:00
|
|
|
machine->root_dir, version);
|
2010-04-19 13:32:50 +08:00
|
|
|
free(version);
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return map_groups__set_modules_path_dir(&machine->kmaps, modules_path);
|
2009-07-02 14:08:36 +08:00
|
|
|
}
|
|
|
|
|
2009-10-02 14:29:58 +08:00
|
|
|
/*
|
|
|
|
* Constructor variant for modules (where we know from /proc/modules where
|
|
|
|
* they are loaded) and for vmlinux, where only after we load all the
|
|
|
|
* symbols we'll know where it starts and ends.
|
|
|
|
*/
|
2009-11-28 02:29:16 +08:00
|
|
|
static struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
|
2009-07-02 14:08:36 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct map *map = calloc(1, (sizeof(*map) +
|
|
|
|
(dso->kernel ? sizeof(struct kmap) : 0)));
|
|
|
|
if (map != NULL) {
|
2009-10-02 14:29:58 +08:00
|
|
|
/*
|
2009-10-31 02:28:23 +08:00
|
|
|
* ->end will be filled after we load all the symbols
|
2009-10-02 14:29:58 +08:00
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
map__init(map, type, start, 0, 0, dso);
|
2009-10-02 14:29:58 +08:00
|
|
|
}
|
2009-10-31 02:28:23 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return map;
|
2009-10-02 14:29:58 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
struct map *machine__new_module(struct machine *machine, u64 start,
|
2010-04-28 08:20:43 +08:00
|
|
|
const char *filename)
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
{
|
|
|
|
struct map *map;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct dso *dso = __dsos__findnew(&machine->kernel_dsos, filename);
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
|
|
|
|
if (dso == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
map = map__new2(start, dso, MAP__FUNCTION);
|
|
|
|
if (map == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (machine__is_host(machine))
|
2011-03-12 00:13:36 +08:00
|
|
|
dso->symtab_type = SYMTAB__SYSTEM_PATH_KMODULE;
|
2010-04-19 13:32:50 +08:00
|
|
|
else
|
2011-03-12 00:13:36 +08:00
|
|
|
dso->symtab_type = SYMTAB__GUEST_KMODULE;
|
2011-03-31 21:56:28 +08:00
|
|
|
map_groups__insert(&machine->kmaps, map);
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int machine__create_modules(struct machine *machine)
|
2009-10-02 14:29:58 +08:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
2010-04-19 13:32:50 +08:00
|
|
|
FILE *file;
|
2009-10-02 14:29:58 +08:00
|
|
|
struct map *map;
|
2010-04-19 13:32:50 +08:00
|
|
|
const char *modules;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (machine__is_default_guest(machine))
|
2010-04-19 13:32:50 +08:00
|
|
|
modules = symbol_conf.default_guest_modules;
|
|
|
|
else {
|
2011-03-31 21:56:28 +08:00
|
|
|
sprintf(path, "%s/proc/modules", machine->root_dir);
|
2010-04-19 13:32:50 +08:00
|
|
|
modules = path;
|
|
|
|
}
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
file = fopen(modules, "r");
|
2009-10-02 14:29:58 +08:00
|
|
|
if (file == NULL)
|
|
|
|
return -1;
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2009-10-02 14:29:58 +08:00
|
|
|
while (!feof(file)) {
|
|
|
|
char name[PATH_MAX];
|
|
|
|
u64 start;
|
|
|
|
char *sep;
|
|
|
|
int line_len;
|
2009-07-02 14:08:36 +08:00
|
|
|
|
2009-10-02 14:29:58 +08:00
|
|
|
line_len = getline(&line, &n, file);
|
|
|
|
if (line_len < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!line)
|
|
|
|
goto out_failure;
|
|
|
|
|
|
|
|
line[--line_len] = '\0'; /* \n */
|
|
|
|
|
|
|
|
sep = strrchr(line, 'x');
|
|
|
|
if (sep == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hex2u64(sep + 1, &start);
|
|
|
|
|
|
|
|
sep = strchr(line, ' ');
|
|
|
|
if (sep == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*sep = '\0';
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "[%s]", line);
|
2011-03-31 21:56:28 +08:00
|
|
|
map = machine__new_module(machine, start, name);
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
if (map == NULL)
|
2009-10-02 14:29:58 +08:00
|
|
|
goto out_delete_line;
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__kernel_module_get_build_id(map->dso, machine->root_dir);
|
2009-07-02 14:08:36 +08:00
|
|
|
}
|
2009-10-02 14:29:58 +08:00
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return machine__set_modules_path(machine);
|
2009-10-02 14:29:58 +08:00
|
|
|
|
|
|
|
out_delete_line:
|
|
|
|
free(line);
|
|
|
|
out_failure:
|
|
|
|
return -1;
|
2009-07-02 14:08:36 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int dso__load_vmlinux(struct dso *dso, struct map *map,
|
2010-12-10 21:06:03 +08:00
|
|
|
const char *vmlinux, symbol_filter_t filter)
|
2009-05-29 01:55:04 +08:00
|
|
|
{
|
2009-11-21 06:51:28 +08:00
|
|
|
int err = -1, fd;
|
2010-12-10 04:27:07 +08:00
|
|
|
char symfs_vmlinux[PATH_MAX];
|
2009-05-29 01:55:04 +08:00
|
|
|
|
2011-03-01 00:54:38 +08:00
|
|
|
snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s%s",
|
2010-12-10 04:27:07 +08:00
|
|
|
symbol_conf.symfs, vmlinux);
|
|
|
|
fd = open(symfs_vmlinux, O_RDONLY);
|
2009-05-29 01:55:04 +08:00
|
|
|
if (fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_long_name(dso, (char *)vmlinux);
|
|
|
|
dso__set_loaded(dso, map->type);
|
|
|
|
err = dso__load_sym(dso, map, symfs_vmlinux, fd, filter, 0, 0);
|
2009-05-29 01:55:04 +08:00
|
|
|
close(fd);
|
|
|
|
|
2010-02-23 03:15:39 +08:00
|
|
|
if (err > 0)
|
2010-12-10 04:27:07 +08:00
|
|
|
pr_debug("Using %s for symbols\n", symfs_vmlinux);
|
2010-02-23 03:15:39 +08:00
|
|
|
|
2009-05-29 01:55:04 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int dso__load_vmlinux_path(struct dso *dso, struct map *map,
|
2010-02-04 02:52:00 +08:00
|
|
|
symbol_filter_t filter)
|
2010-01-28 07:05:50 +08:00
|
|
|
{
|
|
|
|
int i, err = 0;
|
2010-05-27 00:26:02 +08:00
|
|
|
char *filename;
|
2010-01-28 07:05:50 +08:00
|
|
|
|
|
|
|
pr_debug("Looking at the vmlinux_path (%d entries long)\n",
|
2010-05-27 00:26:02 +08:00
|
|
|
vmlinux_path__nr_entries + 1);
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
filename = dso__build_id_filename(dso, NULL, 0);
|
2010-05-27 00:26:02 +08:00
|
|
|
if (filename != NULL) {
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_vmlinux(dso, map, filename, filter);
|
2010-05-27 00:26:02 +08:00
|
|
|
if (err > 0) {
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_long_name(dso, filename);
|
2010-05-27 00:26:02 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
free(filename);
|
|
|
|
}
|
2010-01-28 07:05:50 +08:00
|
|
|
|
|
|
|
for (i = 0; i < vmlinux_path__nr_entries; ++i) {
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_vmlinux(dso, map, vmlinux_path[i], filter);
|
2010-01-28 07:05:50 +08:00
|
|
|
if (err > 0) {
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_long_name(dso, strdup(vmlinux_path[i]));
|
2010-01-28 07:05:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-05-27 00:26:02 +08:00
|
|
|
out:
|
2010-01-28 07:05:50 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_kernel_sym(struct dso *dso, struct map *map,
|
2010-02-04 02:52:00 +08:00
|
|
|
symbol_filter_t filter)
|
2009-05-29 01:55:19 +08:00
|
|
|
{
|
2009-11-24 02:39:10 +08:00
|
|
|
int err;
|
2010-01-15 04:30:06 +08:00
|
|
|
const char *kallsyms_filename = NULL;
|
|
|
|
char *kallsyms_allocated_filename = NULL;
|
2010-01-19 20:36:14 +08:00
|
|
|
/*
|
2010-12-08 10:39:46 +08:00
|
|
|
* Step 1: if the user specified a kallsyms or vmlinux filename, use
|
|
|
|
* it and only it, reporting errors to the user if it cannot be used.
|
2010-01-19 20:36:14 +08:00
|
|
|
*
|
|
|
|
* For instance, try to analyse an ARM perf.data file _without_ a
|
|
|
|
* build-id, or if the user specifies the wrong path to the right
|
|
|
|
* vmlinux file, obviously we can't fallback to another vmlinux (a
|
|
|
|
* x86_86 one, on the machine where analysis is being performed, say),
|
|
|
|
* or worse, /proc/kallsyms.
|
|
|
|
*
|
|
|
|
* If the specified file _has_ a build-id and there is a build-id
|
|
|
|
* section in the perf.data file, we will still do the expected
|
|
|
|
* validation in dso__load_vmlinux and will bail out if they don't
|
|
|
|
* match.
|
|
|
|
*/
|
2010-12-08 10:39:46 +08:00
|
|
|
if (symbol_conf.kallsyms_name != NULL) {
|
|
|
|
kallsyms_filename = symbol_conf.kallsyms_name;
|
|
|
|
goto do_kallsyms;
|
|
|
|
}
|
|
|
|
|
2010-01-19 20:36:14 +08:00
|
|
|
if (symbol_conf.vmlinux_name != NULL) {
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_vmlinux(dso, map,
|
2010-01-19 20:36:14 +08:00
|
|
|
symbol_conf.vmlinux_name, filter);
|
2010-06-04 05:35:55 +08:00
|
|
|
if (err > 0) {
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_long_name(dso,
|
2010-06-04 05:35:55 +08:00
|
|
|
strdup(symbol_conf.vmlinux_name));
|
|
|
|
goto out_fixup;
|
|
|
|
}
|
|
|
|
return err;
|
2010-01-19 20:36:14 +08:00
|
|
|
}
|
2009-11-24 02:39:10 +08:00
|
|
|
|
|
|
|
if (vmlinux_path != NULL) {
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_vmlinux_path(dso, map, filter);
|
2010-01-28 07:05:50 +08:00
|
|
|
if (err > 0)
|
|
|
|
goto out_fixup;
|
2009-11-24 02:39:10 +08:00
|
|
|
}
|
|
|
|
|
2010-12-10 04:27:07 +08:00
|
|
|
/* do not try local files if a symfs was given */
|
|
|
|
if (symbol_conf.symfs[0] != 0)
|
|
|
|
return -1;
|
|
|
|
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
/*
|
|
|
|
* Say the kernel DSO was created when processing the build-id header table,
|
|
|
|
* we have a build-id, so check if it is the same as the running kernel,
|
|
|
|
* using it if it is.
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso->has_build_id) {
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
u8 kallsyms_build_id[BUILD_ID_SIZE];
|
2010-01-15 04:30:06 +08:00
|
|
|
char sbuild_id[BUILD_ID_SIZE * 2 + 1];
|
perf tools: Encode kernel module mappings in perf.data
We were always looking at the running machine /proc/modules,
even when processing a perf.data file, which only makes sense
when we're doing 'perf record' and 'perf report' on the same
machine, and in close sucession, or if we don't use modules at
all, right Peter? ;-)
Now, at 'perf record' time we read /proc/modules, find the long
path for modules, and put them as PERF_MMAP events, just like we
did to encode the reloc reference symbol for vmlinux. Talking
about that now it is encoded in .pgoff, so that we can use
.{start,len} to store the address boundaries for the kernel so
that when we reconstruct the kmaps tree we can do lookups right
away, without having to fixup the end of the kernel maps like we
did in the past (and now only in perf record).
One more step in the 'perf archive' direction when we'll finally
be able to collect data in one machine and analyse in another.
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: <1263396139-4798-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-01-13 23:22:17 +08:00
|
|
|
|
|
|
|
if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id,
|
2010-01-15 04:30:05 +08:00
|
|
|
sizeof(kallsyms_build_id)) == 0) {
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso__build_id_equal(dso, kallsyms_build_id)) {
|
2010-01-15 04:30:06 +08:00
|
|
|
kallsyms_filename = "/proc/kallsyms";
|
2010-01-15 04:30:05 +08:00
|
|
|
goto do_kallsyms;
|
2010-01-15 04:30:06 +08:00
|
|
|
}
|
2010-01-15 04:30:05 +08:00
|
|
|
}
|
2010-01-19 20:36:14 +08:00
|
|
|
/*
|
|
|
|
* Now look if we have it on the build-id cache in
|
|
|
|
* $HOME/.debug/[kernel.kallsyms].
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
build_id__sprintf(dso->build_id, sizeof(dso->build_id),
|
2010-01-15 04:30:06 +08:00
|
|
|
sbuild_id);
|
|
|
|
|
|
|
|
if (asprintf(&kallsyms_allocated_filename,
|
|
|
|
"%s/.debug/[kernel.kallsyms]/%s",
|
2010-02-23 03:15:39 +08:00
|
|
|
getenv("HOME"), sbuild_id) == -1) {
|
|
|
|
pr_err("Not enough memory for kallsyms file lookup\n");
|
2010-01-19 20:36:14 +08:00
|
|
|
return -1;
|
2010-02-23 03:15:39 +08:00
|
|
|
}
|
2010-01-19 20:36:14 +08:00
|
|
|
|
2010-01-23 00:35:02 +08:00
|
|
|
kallsyms_filename = kallsyms_allocated_filename;
|
|
|
|
|
2010-01-19 20:36:14 +08:00
|
|
|
if (access(kallsyms_filename, F_OK)) {
|
2010-02-23 03:15:39 +08:00
|
|
|
pr_err("No kallsyms or vmlinux with build-id %s "
|
|
|
|
"was found\n", sbuild_id);
|
2010-01-15 04:30:06 +08:00
|
|
|
free(kallsyms_allocated_filename);
|
2010-01-19 20:36:14 +08:00
|
|
|
return -1;
|
2010-01-15 04:30:06 +08:00
|
|
|
}
|
2010-01-19 20:36:14 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Last resort, if we don't have a build-id and couldn't find
|
|
|
|
* any vmlinux file, try the running kernel kallsyms table.
|
|
|
|
*/
|
2010-01-15 04:30:06 +08:00
|
|
|
kallsyms_filename = "/proc/kallsyms";
|
|
|
|
}
|
2009-10-02 14:29:58 +08:00
|
|
|
|
2009-11-24 02:39:10 +08:00
|
|
|
do_kallsyms:
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_kallsyms(dso, kallsyms_filename, map, filter);
|
2010-02-23 03:15:39 +08:00
|
|
|
if (err > 0)
|
|
|
|
pr_debug("Using %s for symbols\n", kallsyms_filename);
|
2010-01-19 20:36:14 +08:00
|
|
|
free(kallsyms_allocated_filename);
|
2009-10-02 14:29:58 +08:00
|
|
|
|
|
|
|
if (err > 0) {
|
2009-11-24 02:39:10 +08:00
|
|
|
out_fixup:
|
2010-01-23 00:35:01 +08:00
|
|
|
if (kallsyms_filename != NULL)
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_long_name(dso, strdup("[kernel.kallsyms]"));
|
2009-11-28 02:29:17 +08:00
|
|
|
map__fixup_start(map);
|
|
|
|
map__fixup_end(map);
|
2009-10-02 14:29:58 +08:00
|
|
|
}
|
2009-08-07 01:43:17 +08:00
|
|
|
|
2009-05-29 01:55:19 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
|
|
|
|
symbol_filter_t filter)
|
2010-04-19 13:32:50 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
const char *kallsyms_filename = NULL;
|
2010-04-28 08:17:50 +08:00
|
|
|
struct machine *machine;
|
2010-04-19 13:32:50 +08:00
|
|
|
char path[PATH_MAX];
|
|
|
|
|
|
|
|
if (!map->groups) {
|
|
|
|
pr_debug("Guest kernel map hasn't the point to groups\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2010-04-28 08:17:50 +08:00
|
|
|
machine = map->groups->machine;
|
2010-04-19 13:32:50 +08:00
|
|
|
|
2010-04-28 08:17:50 +08:00
|
|
|
if (machine__is_default_guest(machine)) {
|
2010-04-19 13:32:50 +08:00
|
|
|
/*
|
|
|
|
* if the user specified a vmlinux filename, use it and only
|
|
|
|
* it, reporting errors to the user if it cannot be used.
|
|
|
|
* Or use file guest_kallsyms inputted by user on commandline
|
|
|
|
*/
|
|
|
|
if (symbol_conf.default_guest_vmlinux_name != NULL) {
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_vmlinux(dso, map,
|
2010-04-19 13:32:50 +08:00
|
|
|
symbol_conf.default_guest_vmlinux_name, filter);
|
|
|
|
goto out_try_fixup;
|
|
|
|
}
|
|
|
|
|
|
|
|
kallsyms_filename = symbol_conf.default_guest_kallsyms;
|
|
|
|
if (!kallsyms_filename)
|
|
|
|
return -1;
|
|
|
|
} else {
|
2010-04-28 08:17:50 +08:00
|
|
|
sprintf(path, "%s/proc/kallsyms", machine->root_dir);
|
2010-04-19 13:32:50 +08:00
|
|
|
kallsyms_filename = path;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
err = dso__load_kallsyms(dso, kallsyms_filename, map, filter);
|
2010-04-19 13:32:50 +08:00
|
|
|
if (err > 0)
|
|
|
|
pr_debug("Using %s for symbols\n", kallsyms_filename);
|
|
|
|
|
|
|
|
out_try_fixup:
|
|
|
|
if (err > 0) {
|
|
|
|
if (kallsyms_filename != NULL) {
|
2010-04-28 08:19:05 +08:00
|
|
|
machine__mmap_name(machine, path, sizeof(path));
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__set_long_name(dso, strdup(path));
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
|
|
|
map__fixup_start(map);
|
|
|
|
map__fixup_end(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2009-08-12 16:03:49 +08:00
|
|
|
|
2009-11-28 02:29:14 +08:00
|
|
|
static void dsos__add(struct list_head *head, struct dso *dso)
|
2009-08-12 16:03:49 +08:00
|
|
|
{
|
2009-11-28 02:29:14 +08:00
|
|
|
list_add_tail(&dso->node, head);
|
2009-08-12 16:03:49 +08:00
|
|
|
}
|
|
|
|
|
2009-11-28 02:29:14 +08:00
|
|
|
static struct dso *dsos__find(struct list_head *head, const char *name)
|
2009-08-12 16:03:49 +08:00
|
|
|
{
|
|
|
|
struct dso *pos;
|
|
|
|
|
2009-11-28 02:29:14 +08:00
|
|
|
list_for_each_entry(pos, head, node)
|
2010-01-15 09:45:27 +08:00
|
|
|
if (strcmp(pos->long_name, name) == 0)
|
2009-08-12 16:03:49 +08:00
|
|
|
return pos;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-08 05:59:39 +08:00
|
|
|
struct dso *__dsos__findnew(struct list_head *head, const char *name)
|
2009-08-12 16:03:49 +08:00
|
|
|
{
|
2010-01-08 05:59:39 +08:00
|
|
|
struct dso *dso = dsos__find(head, name);
|
2009-08-12 16:03:49 +08:00
|
|
|
|
2009-10-21 00:25:40 +08:00
|
|
|
if (!dso) {
|
2009-10-31 02:28:24 +08:00
|
|
|
dso = dso__new(name);
|
2009-11-18 01:40:53 +08:00
|
|
|
if (dso != NULL) {
|
2010-01-08 05:59:39 +08:00
|
|
|
dsos__add(head, dso);
|
2009-11-18 01:40:53 +08:00
|
|
|
dso__set_basename(dso);
|
|
|
|
}
|
2009-10-29 07:51:21 +08:00
|
|
|
}
|
2009-08-12 16:03:49 +08:00
|
|
|
|
|
|
|
return dso;
|
|
|
|
}
|
|
|
|
|
2010-05-10 06:57:08 +08:00
|
|
|
size_t __dsos__fprintf(struct list_head *head, FILE *fp)
|
2009-08-12 16:03:49 +08:00
|
|
|
{
|
|
|
|
struct dso *pos;
|
2010-04-28 08:22:44 +08:00
|
|
|
size_t ret = 0;
|
2009-08-12 16:03:49 +08:00
|
|
|
|
2009-11-28 02:29:20 +08:00
|
|
|
list_for_each_entry(pos, head, node) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAP__NR_TYPES; ++i)
|
2010-04-28 08:22:44 +08:00
|
|
|
ret += dso__fprintf(pos, i, fp);
|
2009-11-28 02:29:20 +08:00
|
|
|
}
|
2010-04-28 08:22:44 +08:00
|
|
|
|
|
|
|
return ret;
|
2009-08-12 16:03:49 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp)
|
2009-11-28 02:29:14 +08:00
|
|
|
{
|
2010-04-19 13:32:50 +08:00
|
|
|
struct rb_node *nd;
|
2010-04-28 08:22:44 +08:00
|
|
|
size_t ret = 0;
|
2010-04-19 13:32:50 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
|
2010-04-28 08:17:50 +08:00
|
|
|
struct machine *pos = rb_entry(nd, struct machine, rb_node);
|
2010-04-28 08:22:44 +08:00
|
|
|
ret += __dsos__fprintf(&pos->kernel_dsos, fp);
|
|
|
|
ret += __dsos__fprintf(&pos->user_dsos, fp);
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
2010-04-28 08:22:44 +08:00
|
|
|
|
|
|
|
return ret;
|
2009-11-28 02:29:14 +08:00
|
|
|
}
|
|
|
|
|
2010-01-15 09:45:30 +08:00
|
|
|
static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
|
|
|
|
bool with_hits)
|
2009-11-17 02:32:44 +08:00
|
|
|
{
|
|
|
|
struct dso *pos;
|
|
|
|
size_t ret = 0;
|
|
|
|
|
2009-11-28 02:29:14 +08:00
|
|
|
list_for_each_entry(pos, head, node) {
|
2010-01-15 09:45:30 +08:00
|
|
|
if (with_hits && !pos->hit)
|
|
|
|
continue;
|
2009-11-17 02:32:44 +08:00
|
|
|
ret += dso__fprintf_buildid(pos, fp);
|
2009-11-17 07:45:25 +08:00
|
|
|
ret += fprintf(fp, " %s\n", pos->long_name);
|
2009-11-17 02:32:44 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
|
|
|
|
bool with_hits)
|
2010-05-20 00:41:23 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
return __dsos__fprintf_buildid(&machine->kernel_dsos, fp, with_hits) +
|
|
|
|
__dsos__fprintf_buildid(&machine->user_dsos, fp, with_hits);
|
2010-05-20 00:41:23 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
|
|
|
|
FILE *fp, bool with_hits)
|
2009-11-28 02:29:14 +08:00
|
|
|
{
|
2010-04-19 13:32:50 +08:00
|
|
|
struct rb_node *nd;
|
|
|
|
size_t ret = 0;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
|
2010-04-28 08:17:50 +08:00
|
|
|
struct machine *pos = rb_entry(nd, struct machine, rb_node);
|
2010-05-20 00:41:23 +08:00
|
|
|
ret += machine__fprintf_dsos_buildid(pos, fp, with_hits);
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
|
|
|
return ret;
|
2009-11-28 02:29:14 +08:00
|
|
|
}
|
|
|
|
|
2010-01-28 07:05:51 +08:00
|
|
|
struct dso *dso__new_kernel(const char *name)
|
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct dso *dso = dso__new(name ?: "[kernel.kallsyms]");
|
2010-01-28 07:05:51 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (dso != NULL) {
|
|
|
|
dso__set_short_name(dso, "[kernel]");
|
|
|
|
dso->kernel = DSO_TYPE_KERNEL;
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return dso;
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
|
|
|
|
2010-04-28 08:17:50 +08:00
|
|
|
static struct dso *dso__new_guest_kernel(struct machine *machine,
|
2010-04-19 13:32:50 +08:00
|
|
|
const char *name)
|
|
|
|
{
|
2010-04-28 08:19:05 +08:00
|
|
|
char bf[PATH_MAX];
|
2011-03-31 21:56:28 +08:00
|
|
|
struct dso *dso = dso__new(name ?: machine__mmap_name(machine, bf,
|
|
|
|
sizeof(bf)));
|
|
|
|
if (dso != NULL) {
|
|
|
|
dso__set_short_name(dso, "[guest.kernel]");
|
|
|
|
dso->kernel = DSO_TYPE_GUEST_KERNEL;
|
2010-01-28 07:05:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
return dso;
|
2010-01-28 07:05:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)
|
2010-01-28 07:05:51 +08:00
|
|
|
{
|
2010-04-19 13:32:50 +08:00
|
|
|
char path[PATH_MAX];
|
|
|
|
|
2010-04-28 08:17:50 +08:00
|
|
|
if (machine__is_default_guest(machine))
|
2010-04-19 13:32:50 +08:00
|
|
|
return;
|
2010-04-28 08:17:50 +08:00
|
|
|
sprintf(path, "%s/sys/kernel/notes", machine->root_dir);
|
2011-03-31 21:56:28 +08:00
|
|
|
if (sysfs__read_build_id(path, dso->build_id,
|
|
|
|
sizeof(dso->build_id)) == 0)
|
|
|
|
dso->has_build_id = true;
|
2010-01-28 07:05:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
static struct dso *machine__create_kernel(struct machine *machine)
|
2009-08-12 16:03:49 +08:00
|
|
|
{
|
2010-04-19 13:32:50 +08:00
|
|
|
const char *vmlinux_name = NULL;
|
|
|
|
struct dso *kernel;
|
2009-08-12 16:03:49 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (machine__is_host(machine)) {
|
2010-04-19 13:32:50 +08:00
|
|
|
vmlinux_name = symbol_conf.vmlinux_name;
|
|
|
|
kernel = dso__new_kernel(vmlinux_name);
|
|
|
|
} else {
|
2011-03-31 21:56:28 +08:00
|
|
|
if (machine__is_default_guest(machine))
|
2010-04-19 13:32:50 +08:00
|
|
|
vmlinux_name = symbol_conf.default_guest_vmlinux_name;
|
2011-03-31 21:56:28 +08:00
|
|
|
kernel = dso__new_guest_kernel(machine, vmlinux_name);
|
2010-02-04 02:52:02 +08:00
|
|
|
}
|
2009-08-12 16:03:49 +08:00
|
|
|
|
2010-04-19 13:32:50 +08:00
|
|
|
if (kernel != NULL) {
|
2011-03-31 21:56:28 +08:00
|
|
|
dso__read_running_kernel_build_id(kernel, machine);
|
|
|
|
dsos__add(&machine->kernel_dsos, kernel);
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
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: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 00:50:39 +08:00
|
|
|
return kernel;
|
|
|
|
}
|
|
|
|
|
2010-11-25 19:27:25 +08:00
|
|
|
struct process_args {
|
|
|
|
u64 start;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int symbol__in_kernel(void *arg, const char *name,
|
2010-12-22 11:08:36 +08:00
|
|
|
char type __used, u64 start, u64 end __used)
|
2010-11-25 19:27:25 +08:00
|
|
|
{
|
|
|
|
struct process_args *args = arg;
|
|
|
|
|
|
|
|
if (strchr(name, '['))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
args->start = start;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Figure out the start address of kernel map from /proc/kallsyms */
|
|
|
|
static u64 machine__get_kernel_start_addr(struct machine *machine)
|
|
|
|
{
|
|
|
|
const char *filename;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
struct process_args args;
|
|
|
|
|
|
|
|
if (machine__is_host(machine)) {
|
|
|
|
filename = "/proc/kallsyms";
|
|
|
|
} else {
|
|
|
|
if (machine__is_default_guest(machine))
|
|
|
|
filename = (char *)symbol_conf.default_guest_kallsyms;
|
|
|
|
else {
|
|
|
|
sprintf(path, "%s/proc/kallsyms", machine->root_dir);
|
|
|
|
filename = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return args.start;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
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: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 00:50:39 +08:00
|
|
|
{
|
2010-01-05 02:19:29 +08:00
|
|
|
enum map_type type;
|
2011-03-31 21:56:28 +08:00
|
|
|
u64 start = machine__get_kernel_start_addr(machine);
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
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: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 00:50:39 +08:00
|
|
|
|
2010-01-05 02:19:29 +08:00
|
|
|
for (type = 0; type < MAP__NR_TYPES; ++type) {
|
2010-02-04 02:52:00 +08:00
|
|
|
struct kmap *kmap;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
machine->vmlinux_maps[type] = map__new2(start, kernel, type);
|
|
|
|
if (machine->vmlinux_maps[type] == NULL)
|
2010-01-05 02:19:29 +08:00
|
|
|
return -1;
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
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: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 00:50:39 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
machine->vmlinux_maps[type]->map_ip =
|
|
|
|
machine->vmlinux_maps[type]->unmap_ip =
|
|
|
|
identity__map_ip;
|
|
|
|
kmap = map__kmap(machine->vmlinux_maps[type]);
|
|
|
|
kmap->kmaps = &machine->kmaps;
|
|
|
|
map_groups__insert(&machine->kmaps,
|
|
|
|
machine->vmlinux_maps[type]);
|
perf symbols: Add support for 'variable' symtabs
Example:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
Added just after symbol__init() call in 'perf top', then:
{
u64 addr = strtoull(sym_filter, NULL, 16);
struct map *map = map_groups__find(kmaps, MAP__VARIABLE, addr);
if (map == NULL)
pr_err("couldn't find map!\n");
else {
struct symbol *sym = map__find_symbol(map, addr, NULL);
if (sym == NULL)
pr_err("couldn't find addr!\n");
else
pr_info("addr %#Lx is in %s global var\n", addr, sym->name);
}
exit(0);
}
[root@doppio linux-2.6-tip]# grep ' [dD] ' /proc/kallsyms | grep ' sched'
ffffffff817827d8 d sched_nr_latency
ffffffff81782ce0 d sched_domains_mutex
ffffffff8178c070 d schedstr.22423
ffffffff817909a0 d sched_register_mutex
ffffffff81823490 d sched_feat_names
ffffffff81823558 d scheduler_running
ffffffff818235b8 d sched_clock_running
ffffffff818235bc D sched_clock_stable
ffffffff81824f00 d sched_switch_trace
[root@doppio linux-2.6-tip]# perf top -s 0xffffffff817827d9
addr 0xffffffff817827d9 is in sched_nr_latency global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0
addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]#
[root@doppio linux-2.6-tip]# perf top -s ffffffff81782ce0 --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff81782ce0 is in sched_domains_mutex global var
[root@doppio linux-2.6-tip]# perf top -s ffffffff818235bc --vmlinux OFF
The file OFF cannot be used, trying to use /proc/kallsyms...addr 0xffffffff818235bc is in sched_clock_stable global var
[root@doppio linux-2.6-tip]#
So it works with both /proc/kallsyms and with ELF symtabs, either
the one on the vmlinux explicitely passed via --vmlinux or in one
in the vmlinux_path that matches the buildid for the running kernel
or the one found in the buildid header section in a perf.data file.
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: <1260550239-5372-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-12 00:50:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-11-19 06:20:53 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
void machine__destroy_kernel_maps(struct machine *machine)
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
{
|
|
|
|
enum map_type type;
|
|
|
|
|
|
|
|
for (type = 0; type < MAP__NR_TYPES; ++type) {
|
|
|
|
struct kmap *kmap;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (machine->vmlinux_maps[type] == NULL)
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
continue;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
kmap = map__kmap(machine->vmlinux_maps[type]);
|
|
|
|
map_groups__remove(&machine->kmaps,
|
|
|
|
machine->vmlinux_maps[type]);
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
if (kmap->ref_reloc_sym) {
|
|
|
|
/*
|
|
|
|
* ref_reloc_sym is shared among all maps, so free just
|
|
|
|
* on one of them.
|
|
|
|
*/
|
|
|
|
if (type == MAP__FUNCTION) {
|
|
|
|
free((char *)kmap->ref_reloc_sym->name);
|
|
|
|
kmap->ref_reloc_sym->name = NULL;
|
|
|
|
free(kmap->ref_reloc_sym);
|
|
|
|
}
|
|
|
|
kmap->ref_reloc_sym = NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
map__delete(machine->vmlinux_maps[type]);
|
|
|
|
machine->vmlinux_maps[type] = NULL;
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int machine__create_kernel_maps(struct machine *machine)
|
2010-04-30 02:25:23 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct dso *kernel = machine__create_kernel(machine);
|
2010-04-30 02:25:23 +08:00
|
|
|
|
|
|
|
if (kernel == NULL ||
|
2011-03-31 21:56:28 +08:00
|
|
|
__machine__create_kernel_maps(machine, kernel) < 0)
|
2010-04-30 02:25:23 +08:00
|
|
|
return -1;
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
if (symbol_conf.use_modules && machine__create_modules(machine) < 0)
|
2010-04-30 02:25:23 +08:00
|
|
|
pr_debug("Problems creating module maps, continuing anyway...\n");
|
|
|
|
/*
|
|
|
|
* Now that we have all the maps created, just set the ->end of them:
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
map_groups__fixup_end(&machine->kmaps);
|
2010-04-30 02:25:23 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-24 02:39:10 +08:00
|
|
|
static void vmlinux_path__exit(void)
|
|
|
|
{
|
|
|
|
while (--vmlinux_path__nr_entries >= 0) {
|
|
|
|
free(vmlinux_path[vmlinux_path__nr_entries]);
|
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(vmlinux_path);
|
|
|
|
vmlinux_path = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vmlinux_path__init(void)
|
|
|
|
{
|
|
|
|
struct utsname uts;
|
|
|
|
char bf[PATH_MAX];
|
|
|
|
|
|
|
|
vmlinux_path = malloc(sizeof(char *) * 5);
|
|
|
|
if (vmlinux_path == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup("vmlinux");
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
goto out_fail;
|
|
|
|
++vmlinux_path__nr_entries;
|
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup("/boot/vmlinux");
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
goto out_fail;
|
|
|
|
++vmlinux_path__nr_entries;
|
2010-12-10 04:27:07 +08:00
|
|
|
|
|
|
|
/* only try running kernel version if no symfs was given */
|
|
|
|
if (symbol_conf.symfs[0] != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (uname(&uts) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2009-11-24 02:39:10 +08:00
|
|
|
snprintf(bf, sizeof(bf), "/boot/vmlinux-%s", uts.release);
|
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup(bf);
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
goto out_fail;
|
|
|
|
++vmlinux_path__nr_entries;
|
|
|
|
snprintf(bf, sizeof(bf), "/lib/modules/%s/build/vmlinux", uts.release);
|
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup(bf);
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
goto out_fail;
|
|
|
|
++vmlinux_path__nr_entries;
|
|
|
|
snprintf(bf, sizeof(bf), "/usr/lib/debug/lib/modules/%s/vmlinux",
|
|
|
|
uts.release);
|
|
|
|
vmlinux_path[vmlinux_path__nr_entries] = strdup(bf);
|
|
|
|
if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
|
|
|
|
goto out_fail;
|
|
|
|
++vmlinux_path__nr_entries;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_fail:
|
|
|
|
vmlinux_path__exit();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp)
|
2010-03-15 22:46:58 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
size_t printed = 0;
|
2011-03-31 21:56:28 +08:00
|
|
|
struct dso *kdso = machine->vmlinux_maps[MAP__FUNCTION]->dso;
|
2010-05-27 00:26:02 +08:00
|
|
|
|
|
|
|
if (kdso->has_build_id) {
|
|
|
|
char filename[PATH_MAX];
|
|
|
|
if (dso__build_id_filename(kdso, filename, sizeof(filename)))
|
|
|
|
printed += fprintf(fp, "[0] %s\n", filename);
|
|
|
|
}
|
2010-03-15 22:46:58 +08:00
|
|
|
|
|
|
|
for (i = 0; i < vmlinux_path__nr_entries; ++i)
|
2010-05-27 00:26:02 +08:00
|
|
|
printed += fprintf(fp, "[%d] %s\n",
|
|
|
|
i + kdso->has_build_id, vmlinux_path[i]);
|
2010-03-15 22:46:58 +08:00
|
|
|
|
|
|
|
return printed;
|
|
|
|
}
|
|
|
|
|
2009-12-16 06:04:40 +08:00
|
|
|
static int setup_list(struct strlist **list, const char *list_str,
|
|
|
|
const char *list_name)
|
|
|
|
{
|
|
|
|
if (list_str == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*list = strlist__new(true, list_str);
|
|
|
|
if (!*list) {
|
|
|
|
pr_err("problems parsing %s list\n", list_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-16 06:04:39 +08:00
|
|
|
int symbol__init(void)
|
2009-11-19 06:20:53 +08:00
|
|
|
{
|
2010-12-10 04:27:07 +08:00
|
|
|
const char *symfs;
|
|
|
|
|
2010-09-10 00:30:59 +08:00
|
|
|
if (symbol_conf.initialized)
|
|
|
|
return 0;
|
|
|
|
|
2011-03-30 01:18:39 +08:00
|
|
|
symbol_conf.priv_size = ALIGN(symbol_conf.priv_size, sizeof(u64));
|
|
|
|
|
2009-11-28 02:29:20 +08:00
|
|
|
elf_version(EV_CURRENT);
|
2009-12-16 06:04:39 +08:00
|
|
|
if (symbol_conf.sort_by_name)
|
|
|
|
symbol_conf.priv_size += (sizeof(struct symbol_name_rb_node) -
|
|
|
|
sizeof(struct symbol));
|
2009-11-24 22:05:15 +08:00
|
|
|
|
2009-12-16 06:04:39 +08:00
|
|
|
if (symbol_conf.try_vmlinux_path && vmlinux_path__init() < 0)
|
2009-11-19 06:20:53 +08:00
|
|
|
return -1;
|
|
|
|
|
2009-12-16 06:04:41 +08:00
|
|
|
if (symbol_conf.field_sep && *symbol_conf.field_sep == '.') {
|
|
|
|
pr_err("'.' is the only non valid --field-separator argument\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-12-16 06:04:40 +08:00
|
|
|
if (setup_list(&symbol_conf.dso_list,
|
|
|
|
symbol_conf.dso_list_str, "dso") < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (setup_list(&symbol_conf.comm_list,
|
|
|
|
symbol_conf.comm_list_str, "comm") < 0)
|
|
|
|
goto out_free_dso_list;
|
|
|
|
|
|
|
|
if (setup_list(&symbol_conf.sym_list,
|
|
|
|
symbol_conf.sym_list_str, "symbol") < 0)
|
|
|
|
goto out_free_comm_list;
|
|
|
|
|
2010-12-10 04:27:07 +08:00
|
|
|
/*
|
|
|
|
* A path to symbols of "/" is identical to ""
|
|
|
|
* reset here for simplicity.
|
|
|
|
*/
|
|
|
|
symfs = realpath(symbol_conf.symfs, NULL);
|
|
|
|
if (symfs == NULL)
|
|
|
|
symfs = symbol_conf.symfs;
|
|
|
|
if (strcmp(symfs, "/") == 0)
|
|
|
|
symbol_conf.symfs = "";
|
|
|
|
if (symfs != symbol_conf.symfs)
|
|
|
|
free((void *)symfs);
|
|
|
|
|
2010-09-10 00:30:59 +08:00
|
|
|
symbol_conf.initialized = true;
|
perf session: Move kmaps to perf_session
There is still some more work to do to disentangle map creation
from DSO loading, but this happens only for the kernel, and for
the early adopters of perf diff, where this disentanglement
matters most, we'll be testing different kernels, so no problem
here.
Further clarification: right now we create the kernel maps for
the various modules and discontiguous kernel text maps when
loading the DSO, we should do it as a two step process, first
creating the maps, for multiple mappings with the same DSO
store, then doing the dso load just once, for the first hit on
one of the maps sharing this DSO backing store.
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: <1260741029-4430-6-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-14 05:50:29 +08:00
|
|
|
return 0;
|
2009-12-16 06:04:40 +08:00
|
|
|
|
|
|
|
out_free_dso_list:
|
|
|
|
strlist__delete(symbol_conf.dso_list);
|
|
|
|
out_free_comm_list:
|
|
|
|
strlist__delete(symbol_conf.comm_list);
|
|
|
|
return -1;
|
perf session: Move kmaps to perf_session
There is still some more work to do to disentangle map creation
from DSO loading, but this happens only for the kernel, and for
the early adopters of perf diff, where this disentanglement
matters most, we'll be testing different kernels, so no problem
here.
Further clarification: right now we create the kernel maps for
the various modules and discontiguous kernel text maps when
loading the DSO, we should do it as a two step process, first
creating the maps, for multiple mappings with the same DSO
store, then doing the dso load just once, for the first hit on
one of the maps sharing this DSO backing store.
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: <1260741029-4430-6-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-14 05:50:29 +08:00
|
|
|
}
|
|
|
|
|
2010-07-31 05:31:28 +08:00
|
|
|
void symbol__exit(void)
|
|
|
|
{
|
2010-09-10 00:30:59 +08:00
|
|
|
if (!symbol_conf.initialized)
|
|
|
|
return;
|
2010-07-31 05:31:28 +08:00
|
|
|
strlist__delete(symbol_conf.sym_list);
|
|
|
|
strlist__delete(symbol_conf.dso_list);
|
|
|
|
strlist__delete(symbol_conf.comm_list);
|
|
|
|
vmlinux_path__exit();
|
|
|
|
symbol_conf.sym_list = symbol_conf.dso_list = symbol_conf.comm_list = NULL;
|
2010-09-10 00:30:59 +08:00
|
|
|
symbol_conf.initialized = false;
|
2010-07-31 05:31:28 +08:00
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int machines__create_kernel_maps(struct rb_root *machines, pid_t pid)
|
perf session: Move kmaps to perf_session
There is still some more work to do to disentangle map creation
from DSO loading, but this happens only for the kernel, and for
the early adopters of perf diff, where this disentanglement
matters most, we'll be testing different kernels, so no problem
here.
Further clarification: right now we create the kernel maps for
the various modules and discontiguous kernel text maps when
loading the DSO, we should do it as a two step process, first
creating the maps, for multiple mappings with the same DSO
store, then doing the dso load just once, for the first hit on
one of the maps sharing this DSO backing store.
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: <1260741029-4430-6-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-14 05:50:29 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct machine *machine = machines__findnew(machines, pid);
|
2010-02-04 02:52:00 +08:00
|
|
|
|
2010-04-28 08:17:50 +08:00
|
|
|
if (machine == NULL)
|
2010-04-19 13:32:50 +08:00
|
|
|
return -1;
|
2009-11-24 02:39:10 +08:00
|
|
|
|
2010-04-30 02:25:23 +08:00
|
|
|
return machine__create_kernel_maps(machine);
|
2009-08-12 16:03:49 +08:00
|
|
|
}
|
2010-03-26 06:59:00 +08:00
|
|
|
|
|
|
|
static int hex(char ch)
|
|
|
|
{
|
|
|
|
if ((ch >= '0') && (ch <= '9'))
|
|
|
|
return ch - '0';
|
|
|
|
if ((ch >= 'a') && (ch <= 'f'))
|
|
|
|
return ch - 'a' + 10;
|
|
|
|
if ((ch >= 'A') && (ch <= 'F'))
|
|
|
|
return ch - 'A' + 10;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* While we find nice hex chars, build a long_val.
|
|
|
|
* Return number of chars processed.
|
|
|
|
*/
|
|
|
|
int hex2u64(const char *ptr, u64 *long_val)
|
|
|
|
{
|
|
|
|
const char *p = ptr;
|
|
|
|
*long_val = 0;
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
const int hex_val = hex(*p);
|
|
|
|
|
|
|
|
if (hex_val < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
*long_val = (*long_val << 4) | hex_val;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return p - ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *strxfrchar(char *s, char from, char to)
|
|
|
|
{
|
|
|
|
char *p = s;
|
|
|
|
|
|
|
|
while ((p = strchr(p, from)) != NULL)
|
|
|
|
*p++ = to;
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2010-04-19 13:32:50 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int machines__create_guest_kernel_maps(struct rb_root *machines)
|
2010-04-19 13:32:50 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct dirent **namelist = NULL;
|
|
|
|
int i, items = 0;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
if (symbol_conf.default_guest_vmlinux_name ||
|
|
|
|
symbol_conf.default_guest_modules ||
|
|
|
|
symbol_conf.default_guest_kallsyms) {
|
2011-03-31 21:56:28 +08:00
|
|
|
machines__create_kernel_maps(machines, DEFAULT_GUEST_KERNEL_ID);
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (symbol_conf.guestmount) {
|
|
|
|
items = scandir(symbol_conf.guestmount, &namelist, NULL, NULL);
|
|
|
|
if (items <= 0)
|
|
|
|
return -ENOENT;
|
|
|
|
for (i = 0; i < items; i++) {
|
|
|
|
if (!isdigit(namelist[i]->d_name[0])) {
|
|
|
|
/* Filter out . and .. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pid = atoi(namelist[i]->d_name);
|
|
|
|
sprintf(path, "%s/%s/proc/kallsyms",
|
|
|
|
symbol_conf.guestmount,
|
|
|
|
namelist[i]->d_name);
|
|
|
|
ret = access(path, R_OK);
|
|
|
|
if (ret) {
|
|
|
|
pr_debug("Can't access file %s\n", path);
|
|
|
|
goto failure;
|
|
|
|
}
|
2011-03-31 21:56:28 +08:00
|
|
|
machines__create_kernel_maps(machines, pid);
|
2010-04-19 13:32:50 +08:00
|
|
|
}
|
|
|
|
failure:
|
|
|
|
free(namelist);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-04-30 02:25:23 +08:00
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
void machines__destroy_guest_kernel_maps(struct rb_root *machines)
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct rb_node *next = rb_first(machines);
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
|
|
|
|
while (next) {
|
|
|
|
struct machine *pos = rb_entry(next, struct machine, rb_node);
|
|
|
|
|
|
|
|
next = rb_next(&pos->rb_node);
|
2011-03-31 21:56:28 +08:00
|
|
|
rb_erase(&pos->rb_node, machines);
|
perf session: Free the ref_reloc_sym memory at the right place
Which is at perf_session__destroy_kernel_maps, counterpart to the
perf_session__create_kernel_maps where the kmap structure is located, just
after the vmlinux_maps.
Make it also check if the kernel maps were actually created, which may not
be the case if, for instance, perf_session__new can't complete due to
permission problems in, for instance, a 'perf report' case, when a
segfault will take place, that is how this was noticed.
The problem was introduced in d65a458, thus post .35.
This also adds code to release guest machines as them are also created
in perf_session__create_kernel_maps, so should be deleted on this newly
introduced counterpart, perf_session__destroy_kernel_maps.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-08-03 05:18:28 +08:00
|
|
|
machine__delete(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int machine__load_kallsyms(struct machine *machine, const char *filename,
|
2010-04-30 02:25:23 +08:00
|
|
|
enum map_type type, symbol_filter_t filter)
|
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct map *map = machine->vmlinux_maps[type];
|
2010-04-30 02:25:23 +08:00
|
|
|
int ret = dso__load_kallsyms(map->dso, filename, map, filter);
|
|
|
|
|
|
|
|
if (ret > 0) {
|
|
|
|
dso__set_loaded(map->dso, type);
|
|
|
|
/*
|
|
|
|
* Since /proc/kallsyms will have multiple sessions for the
|
|
|
|
* kernel, with modules between them, fixup the end of all
|
|
|
|
* sections.
|
|
|
|
*/
|
2011-03-31 21:56:28 +08:00
|
|
|
__map_groups__fixup_end(&machine->kmaps, type);
|
2010-04-30 02:25:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:56:28 +08:00
|
|
|
int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
|
2010-04-30 02:25:23 +08:00
|
|
|
symbol_filter_t filter)
|
|
|
|
{
|
2011-03-31 21:56:28 +08:00
|
|
|
struct map *map = machine->vmlinux_maps[type];
|
2010-04-30 02:25:23 +08:00
|
|
|
int ret = dso__load_vmlinux_path(map->dso, map, filter);
|
|
|
|
|
|
|
|
if (ret > 0) {
|
|
|
|
dso__set_loaded(map->dso, type);
|
|
|
|
map__reloc_vmlinux(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|