2010-03-25 22:59:00 +00:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.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-22 22:37:02 +00:00
|
|
|
#include <inttypes.h>
|
2010-05-20 15:15:33 +00:00
|
|
|
#include "build-id.h"
|
2012-02-10 01:10:17 +00:00
|
|
|
#include "util.h"
|
2010-07-20 17:42:52 +00:00
|
|
|
#include "debug.h"
|
2009-05-28 17:55:04 +00:00
|
|
|
#include "symbol.h"
|
2010-03-25 22:59:00 +00:00
|
|
|
#include "strlist.h"
|
2009-05-28 17:55:04 +00:00
|
|
|
|
|
|
|
#include <libelf.h>
|
|
|
|
#include <gelf.h>
|
|
|
|
#include <elf.h>
|
2009-11-18 22:20:52 +00:00
|
|
|
#include <limits.h>
|
2009-10-02 06:29:58 +00:00
|
|
|
#include <sys/utsname.h>
|
2009-08-05 12:05:16 +00:00
|
|
|
|
2010-12-22 03:08:36 +00:00
|
|
|
#ifndef KSYM_NAME_LEN
|
2011-10-20 07:43:26 +00:00
|
|
|
#define KSYM_NAME_LEN 256
|
2010-12-22 03:08:36 +00:00
|
|
|
#endif
|
|
|
|
|
2009-11-21 16:31:25 +00:00
|
|
|
#ifndef NT_GNU_BUILD_ID
|
|
|
|
#define NT_GNU_BUILD_ID 3
|
|
|
|
#endif
|
|
|
|
|
2012-07-22 12:14:39 +00:00
|
|
|
static void dso_cache__free(struct rb_root *root);
|
2011-03-31 13:56:28 +00:00
|
|
|
static bool dso__build_id_equal(const struct dso *dso, u8 *build_id);
|
2010-07-30 12:08:08 +00:00
|
|
|
static int elf_read_build_id(Elf *elf, void *bf, size_t size);
|
2009-11-27 18:29:14 +00:00
|
|
|
static void dsos__add(struct list_head *head, struct dso *dso);
|
2009-11-27 18:29:16 +00:00
|
|
|
static struct map *map__new2(u64 start, struct dso *dso, enum map_type type);
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_kernel_sym(struct dso *dso, struct map *map,
|
2010-02-03 18:52:00 +00:00
|
|
|
symbol_filter_t filter);
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
|
2010-04-19 05:32:50 +00:00
|
|
|
symbol_filter_t filter);
|
2009-11-23 18:39:10 +00:00
|
|
|
static int vmlinux_path__nr_entries;
|
|
|
|
static char **vmlinux_path;
|
2009-10-02 06:29:58 +00:00
|
|
|
|
2009-12-15 22:04:39 +00:00
|
|
|
struct symbol_conf symbol_conf = {
|
2009-12-15 22:04:42 +00:00
|
|
|
.exclude_other = true,
|
2009-11-24 14:05:15 +00:00
|
|
|
.use_modules = true,
|
|
|
|
.try_vmlinux_path = true,
|
2011-05-17 15:32:07 +00:00
|
|
|
.annotate_src = true,
|
2010-12-09 20:27:07 +00:00
|
|
|
.symfs = "",
|
2009-11-24 14:05:15 +00:00
|
|
|
};
|
|
|
|
|
2012-07-22 12:14:32 +00:00
|
|
|
static enum dso_binary_type binary_type_symtab[] = {
|
|
|
|
DSO_BINARY_TYPE__KALLSYMS,
|
|
|
|
DSO_BINARY_TYPE__GUEST_KALLSYMS,
|
|
|
|
DSO_BINARY_TYPE__JAVA_JIT,
|
|
|
|
DSO_BINARY_TYPE__DEBUGLINK,
|
|
|
|
DSO_BINARY_TYPE__BUILD_ID_CACHE,
|
|
|
|
DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
|
|
|
|
DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
|
|
|
|
DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
|
|
|
|
DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
|
|
|
|
DSO_BINARY_TYPE__GUEST_KMODULE,
|
|
|
|
DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
|
|
|
|
DSO_BINARY_TYPE__NOT_FOUND,
|
|
|
|
};
|
|
|
|
|
2012-08-01 12:47:57 +00:00
|
|
|
#define DSO_BINARY_TYPE__SYMTAB_CNT ARRAY_SIZE(binary_type_symtab)
|
2012-07-22 12:14:32 +00:00
|
|
|
|
2012-07-22 12:14:33 +00:00
|
|
|
static enum dso_binary_type binary_type_data[] = {
|
|
|
|
DSO_BINARY_TYPE__BUILD_ID_CACHE,
|
|
|
|
DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
|
|
|
|
DSO_BINARY_TYPE__NOT_FOUND,
|
|
|
|
};
|
|
|
|
|
2012-08-01 12:47:57 +00:00
|
|
|
#define DSO_BINARY_TYPE__DATA_CNT ARRAY_SIZE(binary_type_data)
|
2012-07-22 12:14:33 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int dso__name_len(const struct dso *dso)
|
2010-07-20 17:42:52 +00:00
|
|
|
{
|
2012-03-25 20:28:22 +00:00
|
|
|
if (!dso)
|
|
|
|
return strlen("[unknown]");
|
2010-07-20 17:42:52 +00:00
|
|
|
if (verbose)
|
2011-03-31 13:56:28 +00:00
|
|
|
return dso->long_name_len;
|
2010-07-20 17:42:52 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
return dso->short_name_len;
|
2010-07-20 17:42:52 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
bool dso__loaded(const struct dso *dso, enum map_type type)
|
2009-11-27 18:29:16 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
return dso->loaded & (1 << type);
|
2009-11-27 18:29:16 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 18:19:27 +00:00
|
|
|
bool symbol_type__is_a(char symbol_type, enum map_type map_type)
|
2009-12-11 16:50:37 +00:00
|
|
|
{
|
2011-08-24 06:40:16 +00:00
|
|
|
symbol_type = toupper(symbol_type);
|
|
|
|
|
2009-12-11 16:50:37 +00: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-11 16:50:39 +00:00
|
|
|
case MAP__VARIABLE:
|
2011-08-24 06:40:16 +00:00
|
|
|
return symbol_type == 'D';
|
2009-12-11 16:50:37 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 06:40:17 +00:00
|
|
|
static int prefix_underscores_count(const char *str)
|
|
|
|
{
|
|
|
|
const char *tail = str;
|
|
|
|
|
|
|
|
while (*tail == '_')
|
|
|
|
tail++;
|
|
|
|
|
|
|
|
return tail - str;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SYMBOL_A 0
|
|
|
|
#define SYMBOL_B 1
|
|
|
|
|
|
|
|
static int choose_best_symbol(struct symbol *syma, struct symbol *symb)
|
|
|
|
{
|
|
|
|
s64 a;
|
|
|
|
s64 b;
|
|
|
|
|
|
|
|
/* Prefer a symbol with non zero length */
|
|
|
|
a = syma->end - syma->start;
|
|
|
|
b = symb->end - symb->start;
|
|
|
|
if ((b == 0) && (a > 0))
|
|
|
|
return SYMBOL_A;
|
|
|
|
else if ((a == 0) && (b > 0))
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
/* Prefer a non weak symbol over a weak one */
|
|
|
|
a = syma->binding == STB_WEAK;
|
|
|
|
b = symb->binding == STB_WEAK;
|
|
|
|
if (b && !a)
|
|
|
|
return SYMBOL_A;
|
|
|
|
if (a && !b)
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
/* Prefer a global symbol over a non global one */
|
|
|
|
a = syma->binding == STB_GLOBAL;
|
|
|
|
b = symb->binding == STB_GLOBAL;
|
|
|
|
if (a && !b)
|
|
|
|
return SYMBOL_A;
|
|
|
|
if (b && !a)
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
/* Prefer a symbol with less underscores */
|
|
|
|
a = prefix_underscores_count(syma->name);
|
|
|
|
b = prefix_underscores_count(symb->name);
|
|
|
|
if (b > a)
|
|
|
|
return SYMBOL_A;
|
|
|
|
else if (a > b)
|
|
|
|
return SYMBOL_B;
|
|
|
|
|
|
|
|
/* If all else fails, choose the symbol with the longest name */
|
|
|
|
if (strlen(syma->name) >= strlen(symb->name))
|
|
|
|
return SYMBOL_A;
|
|
|
|
else
|
|
|
|
return SYMBOL_B;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void symbols__fixup_duplicate(struct rb_root *symbols)
|
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
struct symbol *curr, *next;
|
|
|
|
|
|
|
|
nd = rb_first(symbols);
|
|
|
|
|
|
|
|
while (nd) {
|
|
|
|
curr = rb_entry(nd, struct symbol, rb_node);
|
|
|
|
again:
|
|
|
|
nd = rb_next(&curr->rb_node);
|
|
|
|
next = rb_entry(nd, struct symbol, rb_node);
|
|
|
|
|
|
|
|
if (!nd)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (curr->start != next->start)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (choose_best_symbol(curr, next) == SYMBOL_A) {
|
|
|
|
rb_erase(&next->rb_node, symbols);
|
|
|
|
goto again;
|
|
|
|
} else {
|
|
|
|
nd = rb_next(&curr->rb_node);
|
|
|
|
rb_erase(&curr->rb_node, symbols);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static void symbols__fixup_end(struct rb_root *symbols)
|
2009-10-05 17:26:17 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct rb_node *nd, *prevnd = rb_first(symbols);
|
2009-10-07 16:48:56 +00:00
|
|
|
struct symbol *curr, *prev;
|
2009-10-05 17:26:17 +00:00
|
|
|
|
|
|
|
if (prevnd == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-10-07 16:48:56 +00:00
|
|
|
curr = rb_entry(prevnd, struct symbol, rb_node);
|
|
|
|
|
2009-10-05 17:26:17 +00:00
|
|
|
for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) {
|
2009-10-07 16:48:56 +00:00
|
|
|
prev = curr;
|
|
|
|
curr = rb_entry(nd, struct symbol, rb_node);
|
2009-10-05 17:26:17 +00:00
|
|
|
|
2010-12-22 03:08:36 +00:00
|
|
|
if (prev->end == prev->start && prev->end != curr->start)
|
2009-10-05 17:26:17 +00:00
|
|
|
prev->end = curr->start - 1;
|
|
|
|
}
|
2009-10-07 16:48:56 +00:00
|
|
|
|
|
|
|
/* Last entry */
|
|
|
|
if (curr->end == curr->start)
|
|
|
|
curr->end = roundup(curr->start, 4096);
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static void __map_groups__fixup_end(struct map_groups *mg, enum map_type type)
|
2009-10-05 17:26:17 +00:00
|
|
|
{
|
|
|
|
struct map *prev, *curr;
|
2011-03-31 13:56:28 +00:00
|
|
|
struct rb_node *nd, *prevnd = rb_first(&mg->maps[type]);
|
2009-10-05 17:26:17 +00: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-07 16:48:56 +00:00
|
|
|
}
|
2009-11-21 16:31:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We still haven't the actual symbols, so guess the
|
|
|
|
* last map final address.
|
|
|
|
*/
|
2010-11-25 04:12:53 +00:00
|
|
|
curr->end = ~0ULL;
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static void map_groups__fixup_end(struct map_groups *mg)
|
2009-11-27 18:29:19 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAP__NR_TYPES; ++i)
|
2011-03-31 13:56:28 +00:00
|
|
|
__map_groups__fixup_end(mg, i);
|
2009-11-27 18:29:19 +00:00
|
|
|
}
|
|
|
|
|
2010-08-05 15:59:47 +00:00
|
|
|
static struct symbol *symbol__new(u64 start, u64 len, u8 binding,
|
|
|
|
const char *name)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2009-05-28 17:55:13 +00:00
|
|
|
size_t namelen = strlen(name) + 1;
|
2011-03-31 13:56:28 +00: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 13:48:52 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-12-15 22:04:39 +00:00
|
|
|
if (symbol_conf.priv_size)
|
2011-03-31 13:56:28 +00:00
|
|
|
sym = ((void *)sym) + symbol_conf.priv_size;
|
2009-10-20 16:25:40 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
sym->start = start;
|
|
|
|
sym->end = len ? start + len - 1 : start;
|
|
|
|
sym->binding = binding;
|
|
|
|
sym->namelen = namelen - 1;
|
2009-10-20 16:25:40 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
pr_debug4("%s: %s %#" PRIx64 "-%#" PRIx64 "\n",
|
|
|
|
__func__, name, start, sym->end);
|
|
|
|
memcpy(sym->name, name, namelen);
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
return sym;
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
void symbol__delete(struct symbol *sym)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
free(((void *)sym) - symbol_conf.priv_size);
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static size_t symbol__fprintf(struct symbol *sym, FILE *fp)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2011-01-22 22:37:02 +00:00
|
|
|
return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n",
|
2011-03-31 13:56:28 +00:00
|
|
|
sym->start, sym->end,
|
|
|
|
sym->binding == STB_GLOBAL ? 'g' :
|
|
|
|
sym->binding == STB_LOCAL ? 'l' : 'w',
|
|
|
|
sym->name);
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2012-01-30 04:43:15 +00:00
|
|
|
size_t symbol__fprintf_symname_offs(const struct symbol *sym,
|
|
|
|
const struct addr_location *al, FILE *fp)
|
2012-01-30 04:42:57 +00:00
|
|
|
{
|
2012-01-30 04:43:15 +00:00
|
|
|
unsigned long offset;
|
|
|
|
size_t length;
|
|
|
|
|
|
|
|
if (sym && sym->name) {
|
|
|
|
length = fprintf(fp, "%s", sym->name);
|
|
|
|
if (al) {
|
|
|
|
offset = al->addr - sym->start;
|
|
|
|
length += fprintf(fp, "+0x%lx", offset);
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
} else
|
|
|
|
return fprintf(fp, "[unknown]");
|
|
|
|
}
|
2012-01-30 04:42:57 +00:00
|
|
|
|
2012-01-30 04:43:15 +00:00
|
|
|
size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp)
|
|
|
|
{
|
|
|
|
return symbol__fprintf_symname_offs(sym, NULL, fp);
|
2012-01-30 04:42:57 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
void dso__set_long_name(struct dso *dso, char *name)
|
2009-11-17 17:40:53 +00:00
|
|
|
{
|
2009-11-20 22:51:29 +00:00
|
|
|
if (name == NULL)
|
|
|
|
return;
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->long_name = name;
|
|
|
|
dso->long_name_len = strlen(name);
|
2009-11-17 17:40:53 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static void dso__set_short_name(struct dso *dso, const char *name)
|
2010-03-15 18:03:50 +00:00
|
|
|
{
|
|
|
|
if (name == NULL)
|
|
|
|
return;
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->short_name = name;
|
|
|
|
dso->short_name_len = strlen(name);
|
2010-03-15 18:03:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static void dso__set_basename(struct dso *dso)
|
2009-11-17 17:40:53 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__set_short_name(dso, basename(dso->long_name));
|
2009-11-17 17:40:53 +00:00
|
|
|
}
|
|
|
|
|
2009-10-30 18:28:24 +00:00
|
|
|
struct dso *dso__new(const char *name)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct dso *dso = calloc(1, sizeof(*dso) + strlen(name) + 1);
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso != NULL) {
|
2009-11-27 18:29:17 +00:00
|
|
|
int i;
|
2011-03-31 13:56:28 +00:00
|
|
|
strcpy(dso->name, name);
|
|
|
|
dso__set_long_name(dso, dso->name);
|
|
|
|
dso__set_short_name(dso, dso->name);
|
2009-11-27 18:29:17 +00:00
|
|
|
for (i = 0; i < MAP__NR_TYPES; ++i)
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->symbols[i] = dso->symbol_names[i] = RB_ROOT;
|
2012-07-22 12:14:39 +00:00
|
|
|
dso->cache = RB_ROOT;
|
2012-07-22 12:14:32 +00:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND;
|
2012-07-22 12:14:33 +00:00
|
|
|
dso->data_type = DSO_BINARY_TYPE__NOT_FOUND;
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->loaded = 0;
|
|
|
|
dso->sorted_by_name = 0;
|
|
|
|
dso->has_build_id = 0;
|
|
|
|
dso->kernel = DSO_TYPE_USER;
|
2012-05-30 12:23:42 +00:00
|
|
|
dso->needs_swap = DSO_SWAP__UNSET;
|
2011-03-31 13:56:28 +00:00
|
|
|
INIT_LIST_HEAD(&dso->node);
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
return dso;
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static void symbols__delete(struct rb_root *symbols)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
|
|
|
struct symbol *pos;
|
2011-03-31 13:56:28 +00:00
|
|
|
struct rb_node *next = rb_first(symbols);
|
2009-05-28 17:55:04 +00:00
|
|
|
|
|
|
|
while (next) {
|
|
|
|
pos = rb_entry(next, struct symbol, rb_node);
|
|
|
|
next = rb_next(&pos->rb_node);
|
2011-03-31 13:56:28 +00:00
|
|
|
rb_erase(&pos->rb_node, symbols);
|
2009-10-30 18:28:24 +00:00
|
|
|
symbol__delete(pos);
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
void dso__delete(struct dso *dso)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2009-11-27 18:29:17 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAP__NR_TYPES; ++i)
|
2011-03-31 13:56:28 +00:00
|
|
|
symbols__delete(&dso->symbols[i]);
|
|
|
|
if (dso->sname_alloc)
|
|
|
|
free((char *)dso->short_name);
|
|
|
|
if (dso->lname_alloc)
|
|
|
|
free(dso->long_name);
|
2012-07-22 12:14:39 +00:00
|
|
|
dso_cache__free(&dso->cache);
|
2011-03-31 13:56:28 +00:00
|
|
|
free(dso);
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-04 20:50:43 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00: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-04 20:50:43 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static void symbols__insert(struct rb_root *symbols, struct symbol *sym)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct rb_node **p = &symbols->rb_node;
|
2009-05-28 17:55:04 +00: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 12:21:42 +00:00
|
|
|
const u64 ip = sym->start;
|
2009-05-28 17:55:04 +00: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 13:56:28 +00:00
|
|
|
rb_insert_color(&sym->rb_node, symbols);
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static struct symbol *symbols__find(struct rb_root *symbols, u64 ip)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
|
|
|
struct rb_node *n;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (symbols == NULL)
|
2009-05-28 17:55:04 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
n = symbols->rb_node;
|
2009-05-28 17:55:04 +00: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-11 20:50:22 +00:00
|
|
|
struct symbol_name_rb_node {
|
|
|
|
struct rb_node rb_node;
|
|
|
|
struct symbol sym;
|
|
|
|
};
|
|
|
|
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
struct rb_node *parent = NULL;
|
2010-11-23 16:38:18 +00: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-11 20:50:22 +00: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 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00: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 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
{
|
|
|
|
struct rb_node *n;
|
|
|
|
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00: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 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
enum map_type type, u64 addr)
|
2009-11-24 15:01:52 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
return symbols__find(&dso->symbols[type], addr);
|
2009-11-24 15:01:52 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int build_id__sprintf(const u8 *build_id, int len, char *bf)
|
2009-05-28 17:55:04 +00: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-04 20:50:43 +00:00
|
|
|
char *bid = bf;
|
2011-03-31 13:56:28 +00: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-04 20:50:43 +00:00
|
|
|
int i;
|
2009-05-28 17:55:04 +00: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-04 20:50:43 +00:00
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
sprintf(bid, "%02x", *raw);
|
|
|
|
++raw;
|
|
|
|
bid += 2;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-04 20:50:43 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-04 20:50:43 +00:00
|
|
|
{
|
|
|
|
char sbuild_id[BUILD_ID_SIZE * 2 + 1];
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
|
2009-11-16 18:32:44 +00:00
|
|
|
return fprintf(fp, "%s", sbuild_id);
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
size_t dso__fprintf_symbols_by_name(struct dso *dso,
|
|
|
|
enum map_type type, FILE *fp)
|
2010-08-25 13:43:29 +00:00
|
|
|
{
|
|
|
|
size_t ret = 0;
|
|
|
|
struct rb_node *nd;
|
|
|
|
struct symbol_name_rb_node *pos;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
for (nd = rb_first(&dso->symbol_names[type]); nd; nd = rb_next(nd)) {
|
2010-08-25 13:43:29 +00:00
|
|
|
pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
|
|
|
|
fprintf(fp, "%s\n", pos->sym.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp)
|
2009-11-16 18:32:44 +00:00
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
2011-03-31 13:56:28 +00:00
|
|
|
size_t ret = fprintf(fp, "dso: %s (", dso->short_name);
|
2009-11-16 18:32:44 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso->short_name != dso->long_name)
|
|
|
|
ret += fprintf(fp, "%s, ", dso->long_name);
|
2010-02-22 19:15:39 +00:00
|
|
|
ret += fprintf(fp, "%s, %sloaded, ", map_type__name[type],
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->loaded ? "" : "NOT ");
|
|
|
|
ret += dso__fprintf_buildid(dso, fp);
|
2009-11-27 18:29:17 +00:00
|
|
|
ret += fprintf(fp, ")\n");
|
2011-03-31 13:56:28 +00:00
|
|
|
for (nd = rb_first(&dso->symbols[type]); nd; nd = rb_next(nd)) {
|
2009-11-27 18:29:20 +00:00
|
|
|
struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
|
|
|
|
ret += symbol__fprintf(pos, fp);
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-14 20:30:06 +00:00
|
|
|
int kallsyms__parse(const char *filename, void *arg,
|
|
|
|
int (*process_symbol)(void *arg, const char *name,
|
2010-12-22 03:08:36 +00:00
|
|
|
char type, u64 start, u64 end))
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
2010-12-22 03:08:36 +00:00
|
|
|
int err = -1;
|
2010-01-14 20:30:06 +00:00
|
|
|
FILE *file = fopen(filename, "r");
|
2009-05-28 17:55:04 +00:00
|
|
|
|
|
|
|
if (file == NULL)
|
|
|
|
goto out_failure;
|
|
|
|
|
2010-12-22 03:08:36 +00:00
|
|
|
err = 0;
|
|
|
|
|
2009-05-28 17:55:04 +00: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 12:21:42 +00:00
|
|
|
u64 start;
|
2009-05-28 17:55:04 +00:00
|
|
|
int line_len, len;
|
|
|
|
char symbol_type;
|
2009-10-07 16:48:56 +00:00
|
|
|
char *symbol_name;
|
2009-05-28 17:55:04 +00:00
|
|
|
|
|
|
|
line_len = getline(&line, &n, file);
|
2010-04-19 05:32:50 +00:00
|
|
|
if (line_len < 0 || !line)
|
2009-05-28 17:55:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
line[--line_len] = '\0'; /* \n */
|
|
|
|
|
2009-06-01 20:50:19 +00:00
|
|
|
len = hex2u64(line, &start);
|
2009-05-28 17:55:04 +00:00
|
|
|
|
|
|
|
len++;
|
|
|
|
if (len + 2 >= line_len)
|
|
|
|
continue;
|
|
|
|
|
2011-08-24 06:40:16 +00:00
|
|
|
symbol_type = line[len];
|
2010-12-22 03:08:36 +00:00
|
|
|
len += 2;
|
|
|
|
symbol_name = line + len;
|
|
|
|
len = line_len - len;
|
2010-01-04 18:19:26 +00:00
|
|
|
|
2010-12-22 03:08:36 +00:00
|
|
|
if (len >= KSYM_NAME_LEN) {
|
|
|
|
err = -1;
|
2010-01-04 18:19:26 +00:00
|
|
|
break;
|
2010-12-22 03:08:36 +00:00
|
|
|
}
|
|
|
|
|
2011-08-24 06:40:15 +00:00
|
|
|
/*
|
|
|
|
* module symbols are not sorted so we add all
|
|
|
|
* symbols with zero length and rely on
|
|
|
|
* symbols__fixup_end() to fix it up.
|
|
|
|
*/
|
|
|
|
err = process_symbol(arg, symbol_name,
|
|
|
|
symbol_type, start, start);
|
|
|
|
if (err)
|
|
|
|
break;
|
2009-10-07 16:48:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
2010-01-04 18:19:26 +00:00
|
|
|
return err;
|
2009-10-07 16:48:56 +00:00
|
|
|
|
|
|
|
out_failure:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-04 18:19:26 +00:00
|
|
|
struct process_kallsyms_args {
|
|
|
|
struct map *map;
|
|
|
|
struct dso *dso;
|
|
|
|
};
|
|
|
|
|
2010-08-05 15:59:47 +00:00
|
|
|
static u8 kallsyms2elf_type(char type)
|
|
|
|
{
|
|
|
|
if (type == 'W')
|
|
|
|
return STB_WEAK;
|
|
|
|
|
|
|
|
return isupper(type) ? STB_GLOBAL : STB_LOCAL;
|
|
|
|
}
|
|
|
|
|
2010-01-04 18:19:26 +00:00
|
|
|
static int map__process_kallsym_symbol(void *arg, const char *name,
|
2010-12-22 03:08:36 +00:00
|
|
|
char type, u64 start, u64 end)
|
2010-01-04 18:19:26 +00: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 03:08:36 +00:00
|
|
|
sym = symbol__new(start, end - start + 1,
|
|
|
|
kallsyms2elf_type(type), name);
|
2010-01-04 18:19:26 +00: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 05:32:50 +00:00
|
|
|
|
2010-01-04 18:19:26 +00: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 13:56:28 +00:00
|
|
|
static int dso__load_all_kallsyms(struct dso *dso, const char *filename,
|
2010-01-14 20:30:06 +00:00
|
|
|
struct map *map)
|
2010-01-04 18:19:26 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct process_kallsyms_args args = { .map = map, .dso = dso, };
|
2010-01-14 20:30:06 +00:00
|
|
|
return kallsyms__parse(filename, &args, map__process_kallsym_symbol);
|
2010-01-04 18:19:26 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 16:48:56 +00: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 13:56:28 +00:00
|
|
|
static int dso__split_kallsyms(struct dso *dso, struct map *map,
|
2010-02-03 18:52:00 +00:00
|
|
|
symbol_filter_t filter)
|
2009-10-07 16:48:56 +00:00
|
|
|
{
|
2010-02-03 18:52:00 +00:00
|
|
|
struct map_groups *kmaps = map__kmap(map)->kmaps;
|
2010-04-28 00:17:50 +00:00
|
|
|
struct machine *machine = kmaps->machine;
|
2009-11-27 18:29:18 +00:00
|
|
|
struct map *curr_map = map;
|
2009-10-07 16:48:56 +00:00
|
|
|
struct symbol *pos;
|
2010-11-29 14:44:15 +00:00
|
|
|
int count = 0, moved = 0;
|
2011-03-31 13:56:28 +00:00
|
|
|
struct rb_root *root = &dso->symbols[map->type];
|
2009-11-27 18:29:18 +00:00
|
|
|
struct rb_node *next = rb_first(root);
|
2009-10-07 16:48:56 +00: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-15 22:04:39 +00:00
|
|
|
if (!symbol_conf.use_modules)
|
2009-11-27 18:29:21 +00:00
|
|
|
goto discard_symbol;
|
|
|
|
|
2009-10-07 16:48:56 +00: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 15:22:17 +00:00
|
|
|
if (strcmp(curr_map->dso->short_name, module)) {
|
2010-04-19 05:32:50 +00:00
|
|
|
if (curr_map != map &&
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->kernel == DSO_TYPE_GUEST_KERNEL &&
|
2010-04-28 00:17:50 +00:00
|
|
|
machine__is_default_guest(machine)) {
|
2010-04-19 05:32:50 +00: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-27 18:29:18 +00:00
|
|
|
if (curr_map == NULL) {
|
2010-05-17 20:57:59 +00: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 15:22:17 +00:00
|
|
|
"inconsistency while looking "
|
2010-04-19 05:32:50 +00:00
|
|
|
"for \"%s\" module!\n",
|
2010-04-28 00:17:50 +00:00
|
|
|
machine->root_dir, module);
|
2010-04-19 05:32:50 +00:00
|
|
|
curr_map = map;
|
|
|
|
goto discard_symbol;
|
2009-10-05 17:26:17 +00: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 15:22:17 +00:00
|
|
|
|
2010-04-19 05:32:50 +00:00
|
|
|
if (curr_map->dso->loaded &&
|
2010-04-28 00:17:50 +00: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 15:22:17 +00:00
|
|
|
goto discard_symbol;
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
2009-10-07 16:48:56 +00:00
|
|
|
/*
|
|
|
|
* So that we look just like we get from .ko files,
|
|
|
|
* i.e. not prelinked, relative to map->start.
|
|
|
|
*/
|
2009-11-27 18:29:18 +00: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-07 16:48:56 +00:00
|
|
|
char dso_name[PATH_MAX];
|
2011-03-31 13:56:28 +00:00
|
|
|
struct dso *ndso;
|
2009-10-07 16:48:56 +00:00
|
|
|
|
2010-11-29 14:44:15 +00:00
|
|
|
if (count == 0) {
|
|
|
|
curr_map = map;
|
|
|
|
goto filter_symbol;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2010-04-19 05:32:50 +00: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-07 16:48:56 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
ndso = dso__new(dso_name);
|
|
|
|
if (ndso == NULL)
|
2009-10-07 16:48:56 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
ndso->kernel = dso->kernel;
|
2010-04-19 05:32:50 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
curr_map = map__new2(pos->start, ndso, map->type);
|
2010-02-25 03:00:51 +00:00
|
|
|
if (curr_map == NULL) {
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__delete(ndso);
|
2009-10-07 16:48:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2009-11-27 18:29:18 +00:00
|
|
|
curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
|
2010-02-03 18:52:00 +00:00
|
|
|
map_groups__insert(kmaps, curr_map);
|
2009-10-07 16:48:56 +00:00
|
|
|
++kernel_range;
|
|
|
|
}
|
2010-11-29 14:44:15 +00:00
|
|
|
filter_symbol:
|
2009-11-27 18:29:18 +00:00
|
|
|
if (filter && filter(curr_map, pos)) {
|
2009-11-27 18:29:21 +00:00
|
|
|
discard_symbol: rb_erase(&pos->rb_node, root);
|
2009-10-30 18:28:24 +00:00
|
|
|
symbol__delete(pos);
|
2009-10-07 16:48:56 +00:00
|
|
|
} else {
|
2009-11-27 18:29:18 +00:00
|
|
|
if (curr_map != map) {
|
|
|
|
rb_erase(&pos->rb_node, root);
|
|
|
|
symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
|
2010-11-29 14:44:15 +00:00
|
|
|
++moved;
|
|
|
|
} else
|
|
|
|
++count;
|
2009-07-02 06:05:58 +00:00
|
|
|
}
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2010-04-19 05:32:50 +00:00
|
|
|
if (curr_map != map &&
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->kernel == DSO_TYPE_GUEST_KERNEL &&
|
2010-04-28 00:17:50 +00:00
|
|
|
machine__is_default_guest(kmaps->machine)) {
|
2010-04-19 05:32:50 +00:00
|
|
|
dso__set_loaded(curr_map->dso, curr_map->type);
|
|
|
|
}
|
|
|
|
|
2010-11-29 14:44:15 +00:00
|
|
|
return count + moved;
|
2009-10-07 16:48:56 +00:00
|
|
|
}
|
2009-05-28 17:55:04 +00:00
|
|
|
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 12:53:51 +00:00
|
|
|
static bool symbol__restricted_filename(const char *filename,
|
|
|
|
const char *restricted_filename)
|
|
|
|
{
|
|
|
|
bool restricted = false;
|
|
|
|
|
|
|
|
if (symbol_conf.kptr_restrict) {
|
|
|
|
char *r = realpath(filename, NULL);
|
|
|
|
|
|
|
|
if (r != NULL) {
|
|
|
|
restricted = strcmp(r, restricted_filename) == 0;
|
|
|
|
free(r);
|
|
|
|
return restricted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return restricted;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int dso__load_kallsyms(struct dso *dso, const char *filename,
|
2010-02-03 18:52:00 +00:00
|
|
|
struct map *map, symbol_filter_t filter)
|
2009-10-07 16:48:56 +00:00
|
|
|
{
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 12:53:51 +00:00
|
|
|
if (symbol__restricted_filename(filename, "/proc/kallsyms"))
|
|
|
|
return -1;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso__load_all_kallsyms(dso, filename, map) < 0)
|
2009-10-07 16:48:56 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-08-24 06:40:17 +00:00
|
|
|
symbols__fixup_duplicate(&dso->symbols[map->type]);
|
2011-08-24 06:40:15 +00:00
|
|
|
symbols__fixup_end(&dso->symbols[map->type]);
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
|
2012-07-22 12:14:32 +00:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__GUEST_KALLSYMS;
|
2010-04-19 05:32:50 +00:00
|
|
|
else
|
2012-07-22 12:14:32 +00:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__KALLSYMS;
|
2009-10-07 16:48:56 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
return dso__split_kallsyms(dso, map, filter);
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_perf_map(struct dso *dso, struct map *map,
|
2009-10-21 19:34:06 +00:00
|
|
|
symbol_filter_t filter)
|
2009-06-08 18:12:48 +00:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
|
|
|
FILE *file;
|
|
|
|
int nr_syms = 0;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
file = fopen(dso->long_name, "r");
|
2009-06-08 18:12:48 +00: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 12:21:42 +00:00
|
|
|
u64 start, size;
|
2009-06-08 18:12:48 +00: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 15:59:47 +00:00
|
|
|
sym = symbol__new(start, size, STB_GLOBAL, line + len);
|
2009-06-08 18:12:48 +00:00
|
|
|
|
|
|
|
if (sym == NULL)
|
|
|
|
goto out_delete_line;
|
|
|
|
|
2009-10-02 06:29:58 +00:00
|
|
|
if (filter && filter(map, sym))
|
2009-10-30 18:28:24 +00:00
|
|
|
symbol__delete(sym);
|
2009-06-08 18:12:48 +00:00
|
|
|
else {
|
2011-03-31 13:56:28 +00:00
|
|
|
symbols__insert(&dso->symbols[map->type], sym);
|
2009-06-08 18:12:48 +00:00
|
|
|
nr_syms++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
|
|
|
|
return nr_syms;
|
|
|
|
|
|
|
|
out_delete_line:
|
|
|
|
free(line);
|
|
|
|
out_failure:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-28 17:55:04 +00:00
|
|
|
/**
|
|
|
|
* elf_symtab__for_each_symbol - iterate thru all the symbols
|
|
|
|
*
|
2011-03-31 13:56:28 +00:00
|
|
|
* @syms: struct elf_symtab instance to iterate
|
2009-08-15 10:26:57 +00:00
|
|
|
* @idx: uint32_t idx
|
2009-05-28 17:55:04 +00:00
|
|
|
* @sym: GElf_Sym iterator
|
|
|
|
*/
|
2009-08-15 10:26:57 +00: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-28 17:55:04 +00: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 02:35:03 +00:00
|
|
|
sym->st_shndx != SHN_UNDEF;
|
2009-05-28 17:55:04 +00: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-11 16:50:39 +00: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 06:08:36 +00: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-11 16:50:39 +00: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-28 17:55:04 +00: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 10:26:57 +00:00
|
|
|
size_t *idx)
|
2009-05-28 17:55:04 +00: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 10:26:57 +00:00
|
|
|
if (idx)
|
|
|
|
*idx = cnt;
|
2009-05-28 17:55:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sec;
|
|
|
|
}
|
|
|
|
|
2009-06-03 03:54:33 +00: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 15:18:36 +00: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).
|
|
|
|
*/
|
2012-04-18 13:46:58 +00:00
|
|
|
static int
|
|
|
|
dso__synthesize_plt_symbols(struct dso *dso, char *name, struct map *map,
|
|
|
|
symbol_filter_t filter)
|
2009-06-03 03:54:33 +00: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 12:21:42 +00:00
|
|
|
u64 plt_offset;
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
GElf_Shdr shdr_rel_plt, shdr_dynsym;
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
Elf_Scn *scn_plt_rel, *scn_symstrs, *scn_dynsym;
|
|
|
|
size_t dynsym_idx;
|
|
|
|
GElf_Ehdr ehdr;
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
Elf *elf;
|
|
|
|
int nr = 0, symidx, fd, err = 0;
|
|
|
|
|
2010-12-09 20:27:07 +00: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 15:18:36 +00:00
|
|
|
if (fd < 0)
|
|
|
|
goto out;
|
|
|
|
|
2009-10-24 16:10:36 +00: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 15:18:36 +00: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 03:54:33 +00: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 15:18:36 +00:00
|
|
|
scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt,
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt,
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
goto out_elf_end;
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
err = -1;
|
|
|
|
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
goto out_elf_end;
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
if (elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL) == NULL)
|
|
|
|
goto out_elf_end;
|
2009-06-03 03:54:33 +00:00
|
|
|
|
|
|
|
/*
|
2009-08-15 10:26:57 +00:00
|
|
|
* Fetch the relocation section to find the idxes to the GOT
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
goto out_elf_end;
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
goto out_elf_end;
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
scn_symstrs = elf_getscn(elf, shdr_dynsym.sh_link);
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
goto out_elf_end;
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
goto out_elf_end;
|
2009-06-03 03:54:33 +00: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 15:59:47 +00:00
|
|
|
STB_GLOBAL, sympltname);
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
goto out_elf_end;
|
2009-06-03 03:54:33 +00:00
|
|
|
|
2009-11-16 15:48:11 +00:00
|
|
|
if (filter && filter(map, f))
|
|
|
|
symbol__delete(f);
|
|
|
|
else {
|
2011-03-31 13:56:28 +00:00
|
|
|
symbols__insert(&dso->symbols[map->type], f);
|
2009-11-16 15:48:11 +00:00
|
|
|
++nr;
|
|
|
|
}
|
2009-06-03 03:54:33 +00: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 15:59:47 +00:00
|
|
|
STB_GLOBAL, sympltname);
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
goto out_elf_end;
|
2009-06-03 03:54:33 +00:00
|
|
|
|
2009-11-16 15:48:11 +00:00
|
|
|
if (filter && filter(map, f))
|
|
|
|
symbol__delete(f);
|
|
|
|
else {
|
2011-03-31 13:56:28 +00:00
|
|
|
symbols__insert(&dso->symbols[map->type], f);
|
2009-11-16 15:48:11 +00:00
|
|
|
++nr;
|
|
|
|
}
|
2009-06-03 03:54:33 +00: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 15:18:36 +00:00
|
|
|
err = 0;
|
|
|
|
out_elf_end:
|
|
|
|
elf_end(elf);
|
|
|
|
out_close:
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (err == 0)
|
|
|
|
return nr;
|
|
|
|
out:
|
2010-03-11 23:12:40 +00:00
|
|
|
pr_debug("%s: problems reading %s PLT info.\n",
|
2011-03-31 13:56:28 +00: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 15:18:36 +00:00
|
|
|
return 0;
|
2009-06-03 03:54:33 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static bool elf_sym__is_a(GElf_Sym *sym, enum map_type type)
|
2009-12-11 16:50:38 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case MAP__FUNCTION:
|
2011-03-31 13:56:28 +00: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-11 16:50:39 +00:00
|
|
|
case MAP__VARIABLE:
|
2011-03-31 13:56:28 +00:00
|
|
|
return elf_sym__is_object(sym);
|
2009-12-11 16:50:38 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static bool elf_sec__is_a(GElf_Shdr *shdr, Elf_Data *secstrs,
|
|
|
|
enum map_type type)
|
2009-12-11 16:50:38 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case MAP__FUNCTION:
|
2011-03-31 13:56:28 +00: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-11 16:50:39 +00:00
|
|
|
case MAP__VARIABLE:
|
2011-03-31 13:56:28 +00:00
|
|
|
return elf_sec__is_data(shdr, secstrs);
|
2009-12-11 16:50:38 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-14 13:56:33 +00: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;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:42 +00:00
|
|
|
static int dso__swap_init(struct dso *dso, unsigned char eidata)
|
|
|
|
{
|
|
|
|
static unsigned int const endian = 1;
|
|
|
|
|
|
|
|
dso->needs_swap = DSO_SWAP__NO;
|
|
|
|
|
|
|
|
switch (eidata) {
|
|
|
|
case ELFDATA2LSB:
|
|
|
|
/* We are big endian, DSO is little endian. */
|
|
|
|
if (*(unsigned char const *)&endian != 1)
|
|
|
|
dso->needs_swap = DSO_SWAP__YES;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ELFDATA2MSB:
|
|
|
|
/* We are little endian, DSO is big endian. */
|
|
|
|
if (*(unsigned char const *)&endian != 0)
|
|
|
|
dso->needs_swap = DSO_SWAP__YES;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
pr_err("unrecognized DSO data encoding %d\n", eidata);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_sym(struct dso *dso, struct map *map, const char *name,
|
2010-07-30 12:50:09 +00:00
|
|
|
int fd, symbol_filter_t filter, int kmodule,
|
|
|
|
int want_symtab)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct kmap *kmap = dso->kernel ? map__kmap(map) : NULL;
|
2009-10-07 16:48:56 +00:00
|
|
|
struct map *curr_map = map;
|
2011-03-31 13:56:28 +00:00
|
|
|
struct dso *curr_dso = dso;
|
2009-07-02 06:08:36 +00:00
|
|
|
Elf_Data *symstrs, *secstrs;
|
2009-05-28 17:55:04 +00:00
|
|
|
uint32_t nr_syms;
|
|
|
|
int err = -1;
|
2009-08-15 10:26:57 +00:00
|
|
|
uint32_t idx;
|
2009-05-28 17:55:04 +00:00
|
|
|
GElf_Ehdr ehdr;
|
2010-06-14 13:56:33 +00:00
|
|
|
GElf_Shdr shdr, opdshdr;
|
|
|
|
Elf_Data *syms, *opddata = NULL;
|
2009-05-28 17:55:04 +00:00
|
|
|
GElf_Sym sym;
|
2010-06-14 13:56:33 +00:00
|
|
|
Elf_Scn *sec, *sec_strndx, *opdsec;
|
2009-05-28 17:55:04 +00:00
|
|
|
Elf *elf;
|
2009-10-02 06:29:58 +00:00
|
|
|
int nr = 0;
|
2010-06-14 13:56:33 +00:00
|
|
|
size_t opdidx = 0;
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2009-10-24 16:10:36 +00:00
|
|
|
elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
|
2009-05-28 17:55:04 +00:00
|
|
|
if (elf == NULL) {
|
2010-07-30 12:36:08 +00:00
|
|
|
pr_debug("%s: cannot read %s ELF file.\n", __func__, name);
|
2009-05-28 17:55:04 +00:00
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gelf_getehdr(elf, &ehdr) == NULL) {
|
2010-07-30 12:36:08 +00:00
|
|
|
pr_debug("%s: cannot get elf header.\n", __func__);
|
2009-05-28 17:55:04 +00:00
|
|
|
goto out_elf_end;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:42 +00:00
|
|
|
if (dso__swap_init(dso, ehdr.e_ident[EI_DATA]))
|
|
|
|
goto out_elf_end;
|
|
|
|
|
2010-07-30 12:50:09 +00:00
|
|
|
/* Always reject images with a mismatched build-id: */
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso->has_build_id) {
|
2010-07-30 12:08:08 +00:00
|
|
|
u8 build_id[BUILD_ID_SIZE];
|
|
|
|
|
2010-10-22 15:25:01 +00:00
|
|
|
if (elf_read_build_id(elf, build_id, BUILD_ID_SIZE) < 0)
|
2010-07-30 12:08:08 +00:00
|
|
|
goto out_elf_end;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (!dso__build_id_equal(dso, build_id))
|
2010-07-30 12:08:08 +00:00
|
|
|
goto out_elf_end;
|
|
|
|
}
|
|
|
|
|
2009-05-28 17:55:04 +00:00
|
|
|
sec = elf_section_by_name(elf, &ehdr, &shdr, ".symtab", NULL);
|
2009-06-03 03:54:33 +00:00
|
|
|
if (sec == NULL) {
|
2010-07-30 12:50:09 +00: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 15:18:36 +00:00
|
|
|
sec = elf_section_by_name(elf, &ehdr, &shdr, ".dynsym", NULL);
|
|
|
|
if (sec == NULL)
|
2009-06-03 03:54:33 +00:00
|
|
|
goto out_elf_end;
|
|
|
|
}
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2010-06-14 13:56:33 +00:00
|
|
|
opdsec = elf_section_by_name(elf, &ehdr, &opdshdr, ".opd", &opdidx);
|
2011-08-24 06:40:14 +00:00
|
|
|
if (opdshdr.sh_type != SHT_PROGBITS)
|
|
|
|
opdsec = NULL;
|
2010-06-14 13:56:33 +00:00
|
|
|
if (opdsec)
|
|
|
|
opddata = elf_rawdata(opdsec, NULL);
|
|
|
|
|
2009-05-28 17:55:04 +00: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 06:08:36 +00: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 10:25:29 +00:00
|
|
|
if (secstrs == NULL)
|
2009-07-02 06:08:36 +00:00
|
|
|
goto out_elf_end;
|
|
|
|
|
2009-05-28 17:55:04 +00:00
|
|
|
nr_syms = shdr.sh_size / shdr.sh_entsize;
|
|
|
|
|
2009-06-06 19:22:33 +00:00
|
|
|
memset(&sym, 0, sizeof(sym));
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso->kernel == DSO_TYPE_USER) {
|
|
|
|
dso->adjust_symbols = (ehdr.e_type == ET_EXEC ||
|
2009-07-03 00:24:14 +00:00
|
|
|
elf_section_by_name(elf, &ehdr, &shdr,
|
|
|
|
".gnu.prelink_undo",
|
|
|
|
NULL) != NULL);
|
2011-03-31 13:56:28 +00:00
|
|
|
} else {
|
|
|
|
dso->adjust_symbols = 0;
|
|
|
|
}
|
2009-08-15 10:26:57 +00:00
|
|
|
elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) {
|
2009-05-28 17:55:04 +00:00
|
|
|
struct symbol *f;
|
2010-01-05 18:50:31 +00:00
|
|
|
const char *elf_name = elf_sym__name(&sym, symstrs);
|
2009-10-07 16:48:56 +00:00
|
|
|
char *demangled = NULL;
|
2009-07-02 06:08:36 +00:00
|
|
|
int is_label = elf_sym__is_label(&sym);
|
|
|
|
const char *section_name;
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2010-02-03 18:52:00 +00: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-05 18:50:31 +00:00
|
|
|
|
2009-12-11 16:50:38 +00:00
|
|
|
if (!is_label && !elf_sym__is_a(&sym, map->type))
|
2009-05-28 17:55:04 +00:00
|
|
|
continue;
|
|
|
|
|
2010-08-09 11:21:18 +00: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 13:56:33 +00:00
|
|
|
if (opdsec && sym.st_shndx == opdidx) {
|
|
|
|
u32 offset = sym.st_value - opdshdr.sh_addr;
|
|
|
|
u64 *opd = opddata->d_buf + offset;
|
2012-05-30 12:23:42 +00:00
|
|
|
sym.st_value = DSO__SWAP(dso, u64, *opd);
|
2010-06-14 13:56:33 +00:00
|
|
|
sym.st_shndx = elf_addr_to_index(elf, sym.st_value);
|
|
|
|
}
|
|
|
|
|
2009-05-28 17:55:04 +00:00
|
|
|
sec = elf_getscn(elf, sym.st_shndx);
|
|
|
|
if (!sec)
|
|
|
|
goto out_elf_end;
|
|
|
|
|
|
|
|
gelf_getshdr(sec, &shdr);
|
2009-07-02 06:08:36 +00:00
|
|
|
|
2009-12-11 16:50:38 +00:00
|
|
|
if (is_label && !elf_sec__is_a(&shdr, secstrs, map->type))
|
2009-07-02 06:08:36 +00: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 13:48:52 +00:00
|
|
|
|
2011-01-21 16:40:19 +00: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 13:56:28 +00:00
|
|
|
if (dso->kernel != DSO_TYPE_USER || kmodule) {
|
2009-10-07 16:48:56 +00:00
|
|
|
char dso_name[PATH_MAX];
|
|
|
|
|
|
|
|
if (strcmp(section_name,
|
2010-03-15 18:03:50 +00:00
|
|
|
(curr_dso->short_name +
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->short_name_len)) == 0)
|
2009-10-07 16:48:56 +00:00
|
|
|
goto new_symbol;
|
|
|
|
|
|
|
|
if (strcmp(section_name, ".text") == 0) {
|
|
|
|
curr_map = map;
|
2011-03-31 13:56:28 +00:00
|
|
|
curr_dso = dso;
|
2009-10-07 16:48:56 +00:00
|
|
|
goto new_symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(dso_name, sizeof(dso_name),
|
2011-03-31 13:56:28 +00:00
|
|
|
"%s%s", dso->short_name, section_name);
|
2009-10-07 16:48:56 +00:00
|
|
|
|
2010-02-03 18:52:00 +00:00
|
|
|
curr_map = map_groups__find_by_name(kmap->kmaps, map->type, dso_name);
|
2009-10-07 16:48:56 +00:00
|
|
|
if (curr_map == NULL) {
|
|
|
|
u64 start = sym.st_value;
|
|
|
|
|
|
|
|
if (kmodule)
|
|
|
|
start += map->start + shdr.sh_offset;
|
|
|
|
|
2009-10-30 18:28:24 +00:00
|
|
|
curr_dso = dso__new(dso_name);
|
2009-10-07 16:48:56 +00:00
|
|
|
if (curr_dso == NULL)
|
|
|
|
goto out_elf_end;
|
2011-03-31 13:56:28 +00:00
|
|
|
curr_dso->kernel = dso->kernel;
|
|
|
|
curr_dso->long_name = dso->long_name;
|
|
|
|
curr_dso->long_name_len = dso->long_name_len;
|
2009-11-27 18:29:16 +00:00
|
|
|
curr_map = map__new2(start, curr_dso,
|
2010-02-03 18:52:01 +00:00
|
|
|
map->type);
|
2009-10-07 16:48:56 +00:00
|
|
|
if (curr_map == NULL) {
|
|
|
|
dso__delete(curr_dso);
|
|
|
|
goto out_elf_end;
|
|
|
|
}
|
2009-10-19 19:17:57 +00:00
|
|
|
curr_map->map_ip = identity__map_ip;
|
|
|
|
curr_map->unmap_ip = identity__map_ip;
|
2011-03-31 13:56:28 +00:00
|
|
|
curr_dso->symtab_type = dso->symtab_type;
|
2010-02-03 18:52:00 +00:00
|
|
|
map_groups__insert(kmap->kmaps, curr_map);
|
2011-03-31 13:56:28 +00:00
|
|
|
dsos__add(&dso->node, curr_dso);
|
2010-02-03 18:52:01 +00:00
|
|
|
dso__set_loaded(curr_dso, map->type);
|
2009-10-07 16:48:56 +00:00
|
|
|
} else
|
|
|
|
curr_dso = curr_map->dso;
|
|
|
|
|
|
|
|
goto new_symbol;
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 16:48:56 +00:00
|
|
|
if (curr_dso->adjust_symbols) {
|
2011-01-22 22:37:02 +00:00
|
|
|
pr_debug4("%s: adjusting symbol: st_value: %#" PRIx64 " "
|
|
|
|
"sh_addr: %#" PRIx64 " sh_offset: %#" PRIx64 "\n", __func__,
|
2010-02-03 18:52:06 +00:00
|
|
|
(u64)sym.st_value, (u64)shdr.sh_addr,
|
|
|
|
(u64)shdr.sh_offset);
|
2009-06-30 14:43:17 +00:00
|
|
|
sym.st_value -= shdr.sh_addr - shdr.sh_offset;
|
2009-10-05 17:26:17 +00:00
|
|
|
}
|
2009-07-20 17:14:12 +00: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 10:26:57 +00:00
|
|
|
demangled = bfd_demangle(NULL, elf_name, DMGL_PARAMS | DMGL_ANSI);
|
2009-07-20 17:14:12 +00:00
|
|
|
if (demangled != NULL)
|
2009-08-15 10:26:57 +00:00
|
|
|
elf_name = demangled;
|
2009-10-07 16:48:56 +00:00
|
|
|
new_symbol:
|
2010-08-05 15:59:47 +00:00
|
|
|
f = symbol__new(sym.st_value, sym.st_size,
|
|
|
|
GELF_ST_BIND(sym.st_info), elf_name);
|
2009-07-20 17:14:12 +00:00
|
|
|
free(demangled);
|
2009-05-28 17:55:04 +00:00
|
|
|
if (!f)
|
|
|
|
goto out_elf_end;
|
|
|
|
|
2009-10-07 16:48:56 +00:00
|
|
|
if (filter && filter(curr_map, f))
|
2009-10-30 18:28:24 +00:00
|
|
|
symbol__delete(f);
|
2009-05-28 17:55:26 +00:00
|
|
|
else {
|
2009-11-27 18:29:17 +00:00
|
|
|
symbols__insert(&curr_dso->symbols[curr_map->type], f);
|
2009-05-28 17:55:26 +00:00
|
|
|
nr++;
|
|
|
|
}
|
2009-05-28 17:55:04 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 16:48:56 +00:00
|
|
|
/*
|
|
|
|
* For misannotated, zeroed, ASM function sizes.
|
|
|
|
*/
|
2010-02-03 18:52:01 +00:00
|
|
|
if (nr > 0) {
|
2011-08-24 06:40:17 +00:00
|
|
|
symbols__fixup_duplicate(&dso->symbols[map->type]);
|
2011-03-31 13:56:28 +00:00
|
|
|
symbols__fixup_end(&dso->symbols[map->type]);
|
2010-02-03 18:52:01 +00: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-28 17:55:04 +00:00
|
|
|
err = nr;
|
|
|
|
out_elf_end:
|
|
|
|
elf_end(elf);
|
|
|
|
out_close:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-08-06 04:41:19 +00:00
|
|
|
void symbol__elf_init(void)
|
|
|
|
{
|
|
|
|
elf_version(EV_CURRENT);
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static bool dso__build_id_equal(const struct dso *dso, u8 *build_id)
|
2009-11-20 22:51:26 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
return memcmp(dso->build_id, build_id, sizeof(dso->build_id)) == 0;
|
2009-11-20 22:51:26 +00:00
|
|
|
}
|
|
|
|
|
2010-04-19 05:32:50 +00:00
|
|
|
bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
|
2009-11-11 03:51:04 +00:00
|
|
|
{
|
2009-11-18 22:20:51 +00:00
|
|
|
bool have_build_id = false;
|
2009-11-11 03:51:04 +00:00
|
|
|
struct dso *pos;
|
|
|
|
|
2010-02-03 18:52:05 +00:00
|
|
|
list_for_each_entry(pos, head, node) {
|
|
|
|
if (with_hits && !pos->hit)
|
|
|
|
continue;
|
2010-05-19 14:13:02 +00:00
|
|
|
if (pos->has_build_id) {
|
|
|
|
have_build_id = true;
|
|
|
|
continue;
|
|
|
|
}
|
2009-11-18 22:20:51 +00: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-03 18:52:05 +00:00
|
|
|
}
|
2009-11-11 03:51:04 +00:00
|
|
|
|
2009-11-18 22:20:51 +00:00
|
|
|
return have_build_id;
|
2009-11-11 03:51:04 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 22:51:25 +00:00
|
|
|
/*
|
|
|
|
* Align offset to 4 bytes as needed for note name and descriptor data.
|
|
|
|
*/
|
|
|
|
#define NOTE_ALIGN(n) (((n) + 3) & -4U)
|
|
|
|
|
2010-07-30 12:08:08 +00:00
|
|
|
static int elf_read_build_id(Elf *elf, void *bf, size_t size)
|
2009-08-05 22:02:49 +00:00
|
|
|
{
|
2010-07-30 12:08:08 +00:00
|
|
|
int err = -1;
|
2009-08-05 22:02:49 +00:00
|
|
|
GElf_Ehdr ehdr;
|
|
|
|
GElf_Shdr shdr;
|
2009-11-20 22:51:25 +00:00
|
|
|
Elf_Data *data;
|
2009-08-05 22:02:49 +00:00
|
|
|
Elf_Scn *sec;
|
2009-11-22 10:29:44 +00:00
|
|
|
Elf_Kind ek;
|
2009-11-20 22:51:25 +00:00
|
|
|
void *ptr;
|
2009-08-05 22:02:49 +00:00
|
|
|
|
2009-11-03 23:46:10 +00:00
|
|
|
if (size < BUILD_ID_SIZE)
|
|
|
|
goto out;
|
|
|
|
|
2009-11-22 10:29:44 +00:00
|
|
|
ek = elf_kind(elf);
|
|
|
|
if (ek != ELF_K_ELF)
|
2010-07-30 12:08:08 +00:00
|
|
|
goto out;
|
2009-11-22 10:29:44 +00:00
|
|
|
|
2009-08-05 22:02:49 +00:00
|
|
|
if (gelf_getehdr(elf, &ehdr) == NULL) {
|
2009-10-21 19:34:06 +00:00
|
|
|
pr_err("%s: cannot get elf header.\n", __func__);
|
2010-07-30 12:08:08 +00:00
|
|
|
goto out;
|
2009-08-05 22:02:49 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 15:48:05 +00:00
|
|
|
/*
|
|
|
|
* Check following sections for notes:
|
|
|
|
* '.note.gnu.build-id'
|
|
|
|
* '.notes'
|
|
|
|
* '.note' (VDSO specific)
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
sec = elf_section_by_name(elf, &ehdr, &shdr,
|
|
|
|
".note.gnu.build-id", NULL);
|
|
|
|
if (sec)
|
|
|
|
break;
|
|
|
|
|
2009-11-20 22:51:25 +00:00
|
|
|
sec = elf_section_by_name(elf, &ehdr, &shdr,
|
|
|
|
".notes", NULL);
|
2012-06-19 15:48:05 +00:00
|
|
|
if (sec)
|
|
|
|
break;
|
|
|
|
|
|
|
|
sec = elf_section_by_name(elf, &ehdr, &shdr,
|
|
|
|
".note", NULL);
|
|
|
|
if (sec)
|
|
|
|
break;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
} while (0);
|
2009-08-05 22:02:49 +00:00
|
|
|
|
2009-11-20 22:51:25 +00:00
|
|
|
data = elf_getdata(sec, NULL);
|
|
|
|
if (data == NULL)
|
2010-07-30 12:08:08 +00:00
|
|
|
goto out;
|
2009-11-20 22:51:25 +00:00
|
|
|
|
|
|
|
ptr = data->d_buf;
|
|
|
|
while (ptr < (data->d_buf + data->d_size)) {
|
|
|
|
GElf_Nhdr *nhdr = ptr;
|
2010-10-22 15:25:01 +00:00
|
|
|
size_t namesz = NOTE_ALIGN(nhdr->n_namesz),
|
|
|
|
descsz = NOTE_ALIGN(nhdr->n_descsz);
|
2009-11-20 22:51:25 +00:00
|
|
|
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) {
|
2010-10-22 15:25:01 +00:00
|
|
|
size_t sz = min(size, descsz);
|
|
|
|
memcpy(bf, ptr, sz);
|
|
|
|
memset(bf + sz, 0, size - sz);
|
|
|
|
err = descsz;
|
2009-11-20 22:51:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ptr += descsz;
|
|
|
|
}
|
2010-07-30 12:08:08 +00: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-03 23:46:10 +00:00
|
|
|
elf_end(elf);
|
|
|
|
out_close:
|
|
|
|
close(fd);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2009-11-18 22:20:52 +00: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;
|
2010-10-22 15:25:01 +00:00
|
|
|
size_t namesz, descsz;
|
2009-11-18 22:20:52 +00:00
|
|
|
|
|
|
|
if (read(fd, &nhdr, sizeof(nhdr)) != sizeof(nhdr))
|
|
|
|
break;
|
|
|
|
|
2009-11-20 22:51:25 +00:00
|
|
|
namesz = NOTE_ALIGN(nhdr.n_namesz);
|
|
|
|
descsz = NOTE_ALIGN(nhdr.n_descsz);
|
2009-11-18 22:20:52 +00:00
|
|
|
if (nhdr.n_type == NT_GNU_BUILD_ID &&
|
|
|
|
nhdr.n_namesz == sizeof("GNU")) {
|
2010-10-22 15:25:01 +00:00
|
|
|
if (read(fd, bf, namesz) != (ssize_t)namesz)
|
2009-11-18 22:20:52 +00:00
|
|
|
break;
|
|
|
|
if (memcmp(bf, "GNU", sizeof("GNU")) == 0) {
|
2010-10-22 15:25:01 +00:00
|
|
|
size_t sz = min(descsz, size);
|
|
|
|
if (read(fd, build_id, sz) == (ssize_t)sz) {
|
|
|
|
memset(build_id + sz, 0, size - sz);
|
2009-11-18 22:20:52 +00:00
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-22 15:25:01 +00:00
|
|
|
} else if (read(fd, bf, descsz) != (ssize_t)descsz)
|
2009-11-18 22:20:52 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
int n = namesz + descsz;
|
|
|
|
if (read(fd, bf, n) != n)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-06-22 18:38:13 +00:00
|
|
|
static int filename__read_debuglink(const char *filename,
|
|
|
|
char *debuglink, size_t size)
|
|
|
|
{
|
|
|
|
int fd, err = -1;
|
|
|
|
Elf *elf;
|
|
|
|
GElf_Ehdr ehdr;
|
|
|
|
GElf_Shdr shdr;
|
|
|
|
Elf_Data *data;
|
|
|
|
Elf_Scn *sec;
|
|
|
|
Elf_Kind ek;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ek = elf_kind(elf);
|
|
|
|
if (ek != ELF_K_ELF)
|
|
|
|
goto out_close;
|
|
|
|
|
|
|
|
if (gelf_getehdr(elf, &ehdr) == NULL) {
|
|
|
|
pr_err("%s: cannot get elf header.\n", __func__);
|
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
sec = elf_section_by_name(elf, &ehdr, &shdr,
|
|
|
|
".gnu_debuglink", NULL);
|
|
|
|
if (sec == NULL)
|
|
|
|
goto out_close;
|
|
|
|
|
|
|
|
data = elf_getdata(sec, NULL);
|
|
|
|
if (data == NULL)
|
|
|
|
goto out_close;
|
|
|
|
|
|
|
|
/* the start of this section is a zero-terminated string */
|
|
|
|
strncpy(debuglink, data->d_buf, size);
|
|
|
|
|
|
|
|
elf_end(elf);
|
|
|
|
|
|
|
|
out_close:
|
|
|
|
close(fd);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
char dso__symtab_origin(const struct dso *dso)
|
2009-08-06 17:43:17 +00:00
|
|
|
{
|
|
|
|
static const char origin[] = {
|
2012-07-22 12:14:32 +00:00
|
|
|
[DSO_BINARY_TYPE__KALLSYMS] = 'k',
|
|
|
|
[DSO_BINARY_TYPE__JAVA_JIT] = 'j',
|
|
|
|
[DSO_BINARY_TYPE__DEBUGLINK] = 'l',
|
|
|
|
[DSO_BINARY_TYPE__BUILD_ID_CACHE] = 'B',
|
|
|
|
[DSO_BINARY_TYPE__FEDORA_DEBUGINFO] = 'f',
|
|
|
|
[DSO_BINARY_TYPE__UBUNTU_DEBUGINFO] = 'u',
|
|
|
|
[DSO_BINARY_TYPE__BUILDID_DEBUGINFO] = 'b',
|
|
|
|
[DSO_BINARY_TYPE__SYSTEM_PATH_DSO] = 'd',
|
|
|
|
[DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE] = 'K',
|
|
|
|
[DSO_BINARY_TYPE__GUEST_KALLSYMS] = 'g',
|
|
|
|
[DSO_BINARY_TYPE__GUEST_KMODULE] = 'G',
|
2009-08-06 17:43:17 +00:00
|
|
|
};
|
|
|
|
|
2012-07-22 12:14:32 +00:00
|
|
|
if (dso == NULL || dso->symtab_type == DSO_BINARY_TYPE__NOT_FOUND)
|
2009-08-06 17:43:17 +00:00
|
|
|
return '!';
|
2011-03-31 13:56:28 +00:00
|
|
|
return origin[dso->symtab_type];
|
2009-08-06 17:43:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 12:14:32 +00:00
|
|
|
int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
|
|
|
|
char *root_dir, char *file, size_t size)
|
|
|
|
{
|
|
|
|
char build_id_hex[BUILD_ID_SIZE * 2 + 1];
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DSO_BINARY_TYPE__DEBUGLINK: {
|
|
|
|
char *debuglink;
|
|
|
|
|
|
|
|
strncpy(file, dso->long_name, size);
|
|
|
|
debuglink = file + dso->long_name_len;
|
|
|
|
while (debuglink != file && *debuglink != '/')
|
|
|
|
debuglink--;
|
|
|
|
if (*debuglink == '/')
|
|
|
|
debuglink++;
|
|
|
|
filename__read_debuglink(dso->long_name, debuglink,
|
|
|
|
size - (debuglink - file));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DSO_BINARY_TYPE__BUILD_ID_CACHE:
|
|
|
|
/* skip the locally configured cache if a symfs is given */
|
|
|
|
if (symbol_conf.symfs[0] ||
|
|
|
|
(dso__build_id_filename(dso, file, size) == NULL))
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
|
|
|
|
snprintf(file, size, "%s/usr/lib/debug%s.debug",
|
|
|
|
symbol_conf.symfs, dso->long_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
|
|
|
|
snprintf(file, size, "%s/usr/lib/debug%s",
|
|
|
|
symbol_conf.symfs, dso->long_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
|
|
|
|
if (!dso->has_build_id) {
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
build_id__sprintf(dso->build_id,
|
|
|
|
sizeof(dso->build_id),
|
|
|
|
build_id_hex);
|
|
|
|
snprintf(file, size,
|
|
|
|
"%s/usr/lib/debug/.build-id/%.2s/%s.debug",
|
|
|
|
symbol_conf.symfs, build_id_hex, build_id_hex + 2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
|
|
|
|
snprintf(file, size, "%s%s",
|
|
|
|
symbol_conf.symfs, dso->long_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__GUEST_KMODULE:
|
|
|
|
snprintf(file, size, "%s%s%s", symbol_conf.symfs,
|
|
|
|
root_dir, dso->long_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
|
|
|
|
snprintf(file, size, "%s%s", symbol_conf.symfs,
|
|
|
|
dso->long_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case DSO_BINARY_TYPE__KALLSYMS:
|
|
|
|
case DSO_BINARY_TYPE__GUEST_KALLSYMS:
|
|
|
|
case DSO_BINARY_TYPE__JAVA_JIT:
|
|
|
|
case DSO_BINARY_TYPE__NOT_FOUND:
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2009-11-20 22:51:27 +00:00
|
|
|
char *name;
|
2009-05-28 17:55:04 +00:00
|
|
|
int ret = -1;
|
|
|
|
int fd;
|
2012-07-22 12:14:32 +00:00
|
|
|
u_int i;
|
2010-04-28 00:17:50 +00:00
|
|
|
struct machine *machine;
|
2012-07-22 12:14:32 +00:00
|
|
|
char *root_dir = (char *) "";
|
2010-07-30 12:50:09 +00:00
|
|
|
int want_symtab;
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__set_loaded(dso, map->type);
|
2009-10-28 23:51:21 +00:00
|
|
|
|
2011-03-31 13:56:28 +00: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 05:32:50 +00:00
|
|
|
|
2010-04-28 00:17:50 +00:00
|
|
|
if (map->groups && map->groups->machine)
|
|
|
|
machine = map->groups->machine;
|
2010-04-19 05:32:50 +00:00
|
|
|
else
|
2010-04-28 00:17:50 +00:00
|
|
|
machine = NULL;
|
2009-11-20 22:51:27 +00:00
|
|
|
|
2012-07-22 12:14:32 +00:00
|
|
|
name = malloc(PATH_MAX);
|
2009-05-28 17:55:04 +00:00
|
|
|
if (!name)
|
|
|
|
return -1;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
dso->adjust_symbols = 0;
|
2009-06-30 14:43:17 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (strncmp(dso->name, "/tmp/perf-", 10) == 0) {
|
2011-08-09 19:54:18 +00:00
|
|
|
struct stat st;
|
|
|
|
|
2011-08-11 20:55:37 +00:00
|
|
|
if (lstat(dso->name, &st) < 0)
|
2011-08-09 19:54:18 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (st.st_uid && (st.st_uid != geteuid())) {
|
|
|
|
pr_warning("File %s not owned by current user or root, "
|
|
|
|
"ignoring it.\n", dso->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
ret = dso__load_perf_map(dso, map, filter);
|
2012-07-22 12:14:32 +00:00
|
|
|
dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT :
|
|
|
|
DSO_BINARY_TYPE__NOT_FOUND;
|
2009-08-06 17:43:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-22 12:14:32 +00:00
|
|
|
if (machine)
|
|
|
|
root_dir = machine->root_dir;
|
|
|
|
|
2010-07-30 12:50:09 +00: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-22 18:42:14 +00:00
|
|
|
want_symtab = 1;
|
|
|
|
restart:
|
2012-07-22 12:14:32 +00:00
|
|
|
for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
|
2010-07-30 12:50:09 +00:00
|
|
|
|
2012-07-22 12:14:32 +00:00
|
|
|
dso->symtab_type = binary_type_symtab[i];
|
2010-12-09 20:27:07 +00:00
|
|
|
|
2012-07-22 12:14:32 +00:00
|
|
|
if (dso__binary_type_file(dso, dso->symtab_type,
|
|
|
|
root_dir, name, PATH_MAX))
|
|
|
|
continue;
|
2010-07-30 12:50:09 +00:00
|
|
|
|
|
|
|
/* Name is now the name of the next image to try */
|
2009-05-28 17:55:04 +00:00
|
|
|
fd = open(name, O_RDONLY);
|
2010-07-30 12:50:09 +00:00
|
|
|
if (fd < 0)
|
|
|
|
continue;
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
ret = dso__load_sym(dso, map, name, fd, filter, 0,
|
2010-07-30 12:50:09 +00:00
|
|
|
want_symtab);
|
|
|
|
close(fd);
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2010-07-30 12:50:09 +00:00
|
|
|
/*
|
|
|
|
* Some people seem to have debuginfo files _WITHOUT_ debug
|
|
|
|
* info!?!?
|
|
|
|
*/
|
|
|
|
if (!ret)
|
|
|
|
continue;
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2010-07-30 12:50:09 +00:00
|
|
|
if (ret > 0) {
|
2012-04-18 13:46:58 +00:00
|
|
|
int nr_plt;
|
|
|
|
|
|
|
|
nr_plt = dso__synthesize_plt_symbols(dso, name, map, filter);
|
2010-07-30 12:50:09 +00: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 15:18:36 +00:00
|
|
|
}
|
2010-07-30 12:50:09 +00:00
|
|
|
|
2011-03-22 18:42:14 +00: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-28 17:55:04 +00:00
|
|
|
free(name);
|
2011-03-31 13:56:28 +00:00
|
|
|
if (ret < 0 && strstr(dso->name, " (deleted)") != NULL)
|
2009-08-11 20:04:36 +00:00
|
|
|
return 0;
|
2009-05-28 17:55:04 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-11 20:50:22 +00:00
|
|
|
enum map_type type, const char *name)
|
2009-10-02 06:29:58 +00:00
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
for (nd = rb_first(&mg->maps[type]); nd; nd = rb_next(nd)) {
|
2009-10-02 06:29:58 +00: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 15:22:17 +00:00
|
|
|
if (map->dso && strcmp(map->dso->short_name, name) == 0)
|
2009-10-02 06:29:58 +00:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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 15:22:17 +00:00
|
|
|
{
|
|
|
|
char filename[PATH_MAX];
|
|
|
|
/*
|
|
|
|
* kernel module short names are of the form "[module]" and
|
|
|
|
* we need just "module" here.
|
|
|
|
*/
|
2011-03-31 13:56:28 +00: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 15:22:17 +00:00
|
|
|
|
|
|
|
snprintf(filename, sizeof(filename),
|
2010-04-19 05:32:50 +00: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 15:22:17 +00:00
|
|
|
|
2011-03-31 13:56:28 +00: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 15:22:17 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static int map_groups__set_modules_path_dir(struct map_groups *mg,
|
2010-04-19 05:32:50 +00:00
|
|
|
const char *dir_name)
|
2009-07-02 06:08:36 +00:00
|
|
|
{
|
2009-10-02 06:29:58 +00:00
|
|
|
struct dirent *dent;
|
2010-03-25 22:59:00 +00:00
|
|
|
DIR *dir = opendir(dir_name);
|
2010-06-24 07:04:02 +00:00
|
|
|
int ret = 0;
|
2009-07-02 06:08:36 +00:00
|
|
|
|
2009-10-02 06:29:58 +00:00
|
|
|
if (!dir) {
|
2010-03-25 22:59:00 +00:00
|
|
|
pr_debug("%s: cannot open %s dir\n", __func__, dir_name);
|
2009-10-02 06:29:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-07-02 06:08:36 +00:00
|
|
|
|
2009-10-02 06:29:58 +00:00
|
|
|
while ((dent = readdir(dir)) != NULL) {
|
|
|
|
char path[PATH_MAX];
|
2010-04-19 05:32:50 +00:00
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
/*sshfs might return bad dent->d_type, so we have to stat*/
|
2011-12-12 15:16:51 +00:00
|
|
|
snprintf(path, sizeof(path), "%s/%s", dir_name, dent->d_name);
|
2010-04-19 05:32:50 +00:00
|
|
|
if (stat(path, &st))
|
|
|
|
continue;
|
2009-10-02 06:29:58 +00:00
|
|
|
|
2010-04-19 05:32:50 +00:00
|
|
|
if (S_ISDIR(st.st_mode)) {
|
2009-10-02 06:29:58 +00:00
|
|
|
if (!strcmp(dent->d_name, ".") ||
|
|
|
|
!strcmp(dent->d_name, ".."))
|
|
|
|
continue;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
ret = map_groups__set_modules_path_dir(mg, path);
|
2010-06-24 07:04:02 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2009-10-02 06:29:58 +00:00
|
|
|
} else {
|
|
|
|
char *dot = strrchr(dent->d_name, '.'),
|
|
|
|
dso_name[PATH_MAX];
|
|
|
|
struct map *map;
|
2009-11-17 17:40:53 +00:00
|
|
|
char *long_name;
|
2009-10-02 06:29:58 +00: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-05 17:26:18 +00:00
|
|
|
strxfrchar(dso_name, '-', '_');
|
2011-03-31 13:56:28 +00:00
|
|
|
map = map_groups__find_by_name(mg, MAP__FUNCTION,
|
|
|
|
dso_name);
|
2009-10-02 06:29:58 +00:00
|
|
|
if (map == NULL)
|
|
|
|
continue;
|
|
|
|
|
2009-11-17 17:40:53 +00:00
|
|
|
long_name = strdup(path);
|
2010-06-24 07:04:02 +00:00
|
|
|
if (long_name == NULL) {
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-11-17 17:40:53 +00:00
|
|
|
dso__set_long_name(map->dso, long_name);
|
2010-07-29 18:11:30 +00:00
|
|
|
map->dso->lname_alloc = 1;
|
2010-04-19 05:32:50 +00:00
|
|
|
dso__kernel_module_get_build_id(map->dso, "");
|
2009-10-02 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-02 06:08:36 +00:00
|
|
|
|
2010-06-24 07:04:02 +00:00
|
|
|
out:
|
2009-10-02 06:29:58 +00:00
|
|
|
closedir(dir);
|
2010-06-24 07:04:02 +00:00
|
|
|
return ret;
|
2009-10-02 06:29:58 +00:00
|
|
|
}
|
2009-07-02 06:08:36 +00:00
|
|
|
|
2010-04-19 05:32:50 +00:00
|
|
|
static char *get_kernel_version(const char *root_dir)
|
2009-10-02 06:29:58 +00:00
|
|
|
{
|
2010-04-19 05:32:50 +00: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 13:56:28 +00:00
|
|
|
static int machine__set_modules_path(struct machine *machine)
|
2010-04-19 05:32:50 +00:00
|
|
|
{
|
|
|
|
char *version;
|
2009-10-02 06:29:58 +00:00
|
|
|
char modules_path[PATH_MAX];
|
2009-07-02 06:08:36 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
version = get_kernel_version(machine->root_dir);
|
2010-04-19 05:32:50 +00:00
|
|
|
if (!version)
|
2009-10-02 06:29:58 +00:00
|
|
|
return -1;
|
2009-07-02 06:08:36 +00:00
|
|
|
|
2010-04-19 05:32:50 +00:00
|
|
|
snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s/kernel",
|
2011-03-31 13:56:28 +00:00
|
|
|
machine->root_dir, version);
|
2010-04-19 05:32:50 +00:00
|
|
|
free(version);
|
2009-07-02 06:08:36 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
return map_groups__set_modules_path_dir(&machine->kmaps, modules_path);
|
2009-07-02 06:08:36 +00:00
|
|
|
}
|
|
|
|
|
2009-10-02 06:29:58 +00: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-27 18:29:16 +00:00
|
|
|
static struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
|
2009-07-02 06:08:36 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct map *map = calloc(1, (sizeof(*map) +
|
|
|
|
(dso->kernel ? sizeof(struct kmap) : 0)));
|
|
|
|
if (map != NULL) {
|
2009-10-02 06:29:58 +00:00
|
|
|
/*
|
2009-10-30 18:28:23 +00:00
|
|
|
* ->end will be filled after we load all the symbols
|
2009-10-02 06:29:58 +00:00
|
|
|
*/
|
2011-03-31 13:56:28 +00:00
|
|
|
map__init(map, type, start, 0, 0, dso);
|
2009-10-02 06:29:58 +00:00
|
|
|
}
|
2009-10-30 18:28:23 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
return map;
|
2009-10-02 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
struct map *machine__new_module(struct machine *machine, u64 start,
|
2010-04-28 00:20:43 +00: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 15:22:17 +00:00
|
|
|
{
|
|
|
|
struct map *map;
|
2011-03-31 13:56:28 +00: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 15:22:17 +00:00
|
|
|
|
|
|
|
if (dso == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
map = map__new2(start, dso, MAP__FUNCTION);
|
|
|
|
if (map == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (machine__is_host(machine))
|
2012-07-22 12:14:32 +00:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE;
|
2010-04-19 05:32:50 +00:00
|
|
|
else
|
2012-07-22 12:14:32 +00:00
|
|
|
dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
|
2011-03-31 13:56:28 +00: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 15:22:17 +00:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static int machine__create_modules(struct machine *machine)
|
2009-10-02 06:29:58 +00:00
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n;
|
2010-04-19 05:32:50 +00:00
|
|
|
FILE *file;
|
2009-10-02 06:29:58 +00:00
|
|
|
struct map *map;
|
2010-04-19 05:32:50 +00:00
|
|
|
const char *modules;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (machine__is_default_guest(machine))
|
2010-04-19 05:32:50 +00:00
|
|
|
modules = symbol_conf.default_guest_modules;
|
|
|
|
else {
|
2011-03-31 13:56:28 +00:00
|
|
|
sprintf(path, "%s/proc/modules", machine->root_dir);
|
2010-04-19 05:32:50 +00:00
|
|
|
modules = path;
|
|
|
|
}
|
2009-07-02 06:08:36 +00:00
|
|
|
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 12:53:51 +00:00
|
|
|
if (symbol__restricted_filename(path, "/proc/modules"))
|
|
|
|
return -1;
|
|
|
|
|
2010-04-19 05:32:50 +00:00
|
|
|
file = fopen(modules, "r");
|
2009-10-02 06:29:58 +00:00
|
|
|
if (file == NULL)
|
|
|
|
return -1;
|
2009-07-02 06:08:36 +00:00
|
|
|
|
2009-10-02 06:29:58 +00:00
|
|
|
while (!feof(file)) {
|
|
|
|
char name[PATH_MAX];
|
|
|
|
u64 start;
|
|
|
|
char *sep;
|
|
|
|
int line_len;
|
2009-07-02 06:08:36 +00:00
|
|
|
|
2009-10-02 06:29:58 +00: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 13:56:28 +00: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 15:22:17 +00:00
|
|
|
if (map == NULL)
|
2009-10-02 06:29:58 +00:00
|
|
|
goto out_delete_line;
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__kernel_module_get_build_id(map->dso, machine->root_dir);
|
2009-07-02 06:08:36 +00:00
|
|
|
}
|
2009-10-02 06:29:58 +00:00
|
|
|
|
|
|
|
free(line);
|
|
|
|
fclose(file);
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
return machine__set_modules_path(machine);
|
2009-10-02 06:29:58 +00:00
|
|
|
|
|
|
|
out_delete_line:
|
|
|
|
free(line);
|
|
|
|
out_failure:
|
|
|
|
return -1;
|
2009-07-02 06:08:36 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int dso__load_vmlinux(struct dso *dso, struct map *map,
|
2010-12-10 13:06:03 +00:00
|
|
|
const char *vmlinux, symbol_filter_t filter)
|
2009-05-28 17:55:04 +00:00
|
|
|
{
|
2009-11-20 22:51:28 +00:00
|
|
|
int err = -1, fd;
|
2010-12-09 20:27:07 +00:00
|
|
|
char symfs_vmlinux[PATH_MAX];
|
2009-05-28 17:55:04 +00:00
|
|
|
|
2011-02-28 16:54:38 +00:00
|
|
|
snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s%s",
|
2010-12-09 20:27:07 +00:00
|
|
|
symbol_conf.symfs, vmlinux);
|
|
|
|
fd = open(symfs_vmlinux, O_RDONLY);
|
2009-05-28 17:55:04 +00:00
|
|
|
if (fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
2011-03-31 13:56:28 +00: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-28 17:55:04 +00:00
|
|
|
close(fd);
|
|
|
|
|
2010-02-22 19:15:39 +00:00
|
|
|
if (err > 0)
|
2010-12-09 20:27:07 +00:00
|
|
|
pr_debug("Using %s for symbols\n", symfs_vmlinux);
|
2010-02-22 19:15:39 +00:00
|
|
|
|
2009-05-28 17:55:04 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int dso__load_vmlinux_path(struct dso *dso, struct map *map,
|
2010-02-03 18:52:00 +00:00
|
|
|
symbol_filter_t filter)
|
2010-01-27 23:05:50 +00:00
|
|
|
{
|
|
|
|
int i, err = 0;
|
2010-05-26 16:26:02 +00:00
|
|
|
char *filename;
|
2010-01-27 23:05:50 +00:00
|
|
|
|
|
|
|
pr_debug("Looking at the vmlinux_path (%d entries long)\n",
|
2010-05-26 16:26:02 +00:00
|
|
|
vmlinux_path__nr_entries + 1);
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
filename = dso__build_id_filename(dso, NULL, 0);
|
2010-05-26 16:26:02 +00:00
|
|
|
if (filename != NULL) {
|
2011-03-31 13:56:28 +00:00
|
|
|
err = dso__load_vmlinux(dso, map, filename, filter);
|
2010-05-26 16:26:02 +00:00
|
|
|
if (err > 0) {
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__set_long_name(dso, filename);
|
2010-05-26 16:26:02 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
free(filename);
|
|
|
|
}
|
2010-01-27 23:05:50 +00:00
|
|
|
|
|
|
|
for (i = 0; i < vmlinux_path__nr_entries; ++i) {
|
2011-03-31 13:56:28 +00:00
|
|
|
err = dso__load_vmlinux(dso, map, vmlinux_path[i], filter);
|
2010-01-27 23:05:50 +00:00
|
|
|
if (err > 0) {
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__set_long_name(dso, strdup(vmlinux_path[i]));
|
2010-01-27 23:05:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-05-26 16:26:02 +00:00
|
|
|
out:
|
2010-01-27 23:05:50 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_kernel_sym(struct dso *dso, struct map *map,
|
2010-02-03 18:52:00 +00:00
|
|
|
symbol_filter_t filter)
|
2009-05-28 17:55:19 +00:00
|
|
|
{
|
2009-11-23 18:39:10 +00:00
|
|
|
int err;
|
2010-01-14 20:30:06 +00:00
|
|
|
const char *kallsyms_filename = NULL;
|
|
|
|
char *kallsyms_allocated_filename = NULL;
|
2010-01-19 12:36:14 +00:00
|
|
|
/*
|
2010-12-08 02:39:46 +00: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 12:36:14 +00: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 02:39:46 +00:00
|
|
|
if (symbol_conf.kallsyms_name != NULL) {
|
|
|
|
kallsyms_filename = symbol_conf.kallsyms_name;
|
|
|
|
goto do_kallsyms;
|
|
|
|
}
|
|
|
|
|
2010-01-19 12:36:14 +00:00
|
|
|
if (symbol_conf.vmlinux_name != NULL) {
|
2011-03-31 13:56:28 +00:00
|
|
|
err = dso__load_vmlinux(dso, map,
|
2010-01-19 12:36:14 +00:00
|
|
|
symbol_conf.vmlinux_name, filter);
|
2010-06-03 21:35:55 +00:00
|
|
|
if (err > 0) {
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__set_long_name(dso,
|
2010-06-03 21:35:55 +00:00
|
|
|
strdup(symbol_conf.vmlinux_name));
|
|
|
|
goto out_fixup;
|
|
|
|
}
|
|
|
|
return err;
|
2010-01-19 12:36:14 +00:00
|
|
|
}
|
2009-11-23 18:39:10 +00:00
|
|
|
|
|
|
|
if (vmlinux_path != NULL) {
|
2011-03-31 13:56:28 +00:00
|
|
|
err = dso__load_vmlinux_path(dso, map, filter);
|
2010-01-27 23:05:50 +00:00
|
|
|
if (err > 0)
|
|
|
|
goto out_fixup;
|
2009-11-23 18:39:10 +00:00
|
|
|
}
|
|
|
|
|
2010-12-09 20:27:07 +00: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 15:22:17 +00: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 13:56:28 +00: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 15:22:17 +00:00
|
|
|
u8 kallsyms_build_id[BUILD_ID_SIZE];
|
2010-01-14 20:30:06 +00: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 15:22:17 +00:00
|
|
|
|
|
|
|
if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id,
|
2010-01-14 20:30:05 +00:00
|
|
|
sizeof(kallsyms_build_id)) == 0) {
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso__build_id_equal(dso, kallsyms_build_id)) {
|
2010-01-14 20:30:06 +00:00
|
|
|
kallsyms_filename = "/proc/kallsyms";
|
2010-01-14 20:30:05 +00:00
|
|
|
goto do_kallsyms;
|
2010-01-14 20:30:06 +00:00
|
|
|
}
|
2010-01-14 20:30:05 +00:00
|
|
|
}
|
2010-01-19 12:36:14 +00:00
|
|
|
/*
|
|
|
|
* Now look if we have it on the build-id cache in
|
|
|
|
* $HOME/.debug/[kernel.kallsyms].
|
|
|
|
*/
|
2011-03-31 13:56:28 +00:00
|
|
|
build_id__sprintf(dso->build_id, sizeof(dso->build_id),
|
2010-01-14 20:30:06 +00:00
|
|
|
sbuild_id);
|
|
|
|
|
|
|
|
if (asprintf(&kallsyms_allocated_filename,
|
|
|
|
"%s/.debug/[kernel.kallsyms]/%s",
|
2010-02-22 19:15:39 +00:00
|
|
|
getenv("HOME"), sbuild_id) == -1) {
|
|
|
|
pr_err("Not enough memory for kallsyms file lookup\n");
|
2010-01-19 12:36:14 +00:00
|
|
|
return -1;
|
2010-02-22 19:15:39 +00:00
|
|
|
}
|
2010-01-19 12:36:14 +00:00
|
|
|
|
2010-01-22 16:35:02 +00:00
|
|
|
kallsyms_filename = kallsyms_allocated_filename;
|
|
|
|
|
2010-01-19 12:36:14 +00:00
|
|
|
if (access(kallsyms_filename, F_OK)) {
|
2010-02-22 19:15:39 +00:00
|
|
|
pr_err("No kallsyms or vmlinux with build-id %s "
|
|
|
|
"was found\n", sbuild_id);
|
2010-01-14 20:30:06 +00:00
|
|
|
free(kallsyms_allocated_filename);
|
2010-01-19 12:36:14 +00:00
|
|
|
return -1;
|
2010-01-14 20:30:06 +00:00
|
|
|
}
|
2010-01-19 12:36:14 +00: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-14 20:30:06 +00:00
|
|
|
kallsyms_filename = "/proc/kallsyms";
|
|
|
|
}
|
2009-10-02 06:29:58 +00:00
|
|
|
|
2009-11-23 18:39:10 +00:00
|
|
|
do_kallsyms:
|
2011-03-31 13:56:28 +00:00
|
|
|
err = dso__load_kallsyms(dso, kallsyms_filename, map, filter);
|
2010-02-22 19:15:39 +00:00
|
|
|
if (err > 0)
|
|
|
|
pr_debug("Using %s for symbols\n", kallsyms_filename);
|
2010-01-19 12:36:14 +00:00
|
|
|
free(kallsyms_allocated_filename);
|
2009-10-02 06:29:58 +00:00
|
|
|
|
|
|
|
if (err > 0) {
|
2009-11-23 18:39:10 +00:00
|
|
|
out_fixup:
|
2010-01-22 16:35:01 +00:00
|
|
|
if (kallsyms_filename != NULL)
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__set_long_name(dso, strdup("[kernel.kallsyms]"));
|
2009-11-27 18:29:17 +00:00
|
|
|
map__fixup_start(map);
|
|
|
|
map__fixup_end(map);
|
2009-10-02 06:29:58 +00:00
|
|
|
}
|
2009-08-06 17:43:17 +00:00
|
|
|
|
2009-05-28 17:55:19 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
|
|
|
|
symbol_filter_t filter)
|
2010-04-19 05:32:50 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
const char *kallsyms_filename = NULL;
|
2010-04-28 00:17:50 +00:00
|
|
|
struct machine *machine;
|
2010-04-19 05:32:50 +00: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 00:17:50 +00:00
|
|
|
machine = map->groups->machine;
|
2010-04-19 05:32:50 +00:00
|
|
|
|
2010-04-28 00:17:50 +00:00
|
|
|
if (machine__is_default_guest(machine)) {
|
2010-04-19 05:32:50 +00: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 13:56:28 +00:00
|
|
|
err = dso__load_vmlinux(dso, map,
|
2010-04-19 05:32:50 +00: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 00:17:50 +00:00
|
|
|
sprintf(path, "%s/proc/kallsyms", machine->root_dir);
|
2010-04-19 05:32:50 +00:00
|
|
|
kallsyms_filename = path;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
err = dso__load_kallsyms(dso, kallsyms_filename, map, filter);
|
2010-04-19 05:32:50 +00: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 00:19:05 +00:00
|
|
|
machine__mmap_name(machine, path, sizeof(path));
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__set_long_name(dso, strdup(path));
|
2010-04-19 05:32:50 +00:00
|
|
|
}
|
|
|
|
map__fixup_start(map);
|
|
|
|
map__fixup_end(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2009-08-12 08:03:49 +00:00
|
|
|
|
2009-11-27 18:29:14 +00:00
|
|
|
static void dsos__add(struct list_head *head, struct dso *dso)
|
2009-08-12 08:03:49 +00:00
|
|
|
{
|
2009-11-27 18:29:14 +00:00
|
|
|
list_add_tail(&dso->node, head);
|
2009-08-12 08:03:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-27 18:29:14 +00:00
|
|
|
static struct dso *dsos__find(struct list_head *head, const char *name)
|
2009-08-12 08:03:49 +00:00
|
|
|
{
|
|
|
|
struct dso *pos;
|
|
|
|
|
2009-11-27 18:29:14 +00:00
|
|
|
list_for_each_entry(pos, head, node)
|
2010-01-15 01:45:27 +00:00
|
|
|
if (strcmp(pos->long_name, name) == 0)
|
2009-08-12 08:03:49 +00:00
|
|
|
return pos;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-07 21:59:39 +00:00
|
|
|
struct dso *__dsos__findnew(struct list_head *head, const char *name)
|
2009-08-12 08:03:49 +00:00
|
|
|
{
|
2010-01-07 21:59:39 +00:00
|
|
|
struct dso *dso = dsos__find(head, name);
|
2009-08-12 08:03:49 +00:00
|
|
|
|
2009-10-20 16:25:40 +00:00
|
|
|
if (!dso) {
|
2009-10-30 18:28:24 +00:00
|
|
|
dso = dso__new(name);
|
2009-11-17 17:40:53 +00:00
|
|
|
if (dso != NULL) {
|
2010-01-07 21:59:39 +00:00
|
|
|
dsos__add(head, dso);
|
2009-11-17 17:40:53 +00:00
|
|
|
dso__set_basename(dso);
|
|
|
|
}
|
2009-10-28 23:51:21 +00:00
|
|
|
}
|
2009-08-12 08:03:49 +00:00
|
|
|
|
|
|
|
return dso;
|
|
|
|
}
|
|
|
|
|
2010-05-09 22:57:08 +00:00
|
|
|
size_t __dsos__fprintf(struct list_head *head, FILE *fp)
|
2009-08-12 08:03:49 +00:00
|
|
|
{
|
|
|
|
struct dso *pos;
|
2010-04-28 00:22:44 +00:00
|
|
|
size_t ret = 0;
|
2009-08-12 08:03:49 +00:00
|
|
|
|
2009-11-27 18:29:20 +00:00
|
|
|
list_for_each_entry(pos, head, node) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAP__NR_TYPES; ++i)
|
2010-04-28 00:22:44 +00:00
|
|
|
ret += dso__fprintf(pos, i, fp);
|
2009-11-27 18:29:20 +00:00
|
|
|
}
|
2010-04-28 00:22:44 +00:00
|
|
|
|
|
|
|
return ret;
|
2009-08-12 08:03:49 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp)
|
2009-11-27 18:29:14 +00:00
|
|
|
{
|
2010-04-19 05:32:50 +00:00
|
|
|
struct rb_node *nd;
|
2010-04-28 00:22:44 +00:00
|
|
|
size_t ret = 0;
|
2010-04-19 05:32:50 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
|
2010-04-28 00:17:50 +00:00
|
|
|
struct machine *pos = rb_entry(nd, struct machine, rb_node);
|
2010-04-28 00:22:44 +00:00
|
|
|
ret += __dsos__fprintf(&pos->kernel_dsos, fp);
|
|
|
|
ret += __dsos__fprintf(&pos->user_dsos, fp);
|
2010-04-19 05:32:50 +00:00
|
|
|
}
|
2010-04-28 00:22:44 +00:00
|
|
|
|
|
|
|
return ret;
|
2009-11-27 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 01:45:30 +00:00
|
|
|
static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
|
|
|
|
bool with_hits)
|
2009-11-16 18:32:44 +00:00
|
|
|
{
|
|
|
|
struct dso *pos;
|
|
|
|
size_t ret = 0;
|
|
|
|
|
2009-11-27 18:29:14 +00:00
|
|
|
list_for_each_entry(pos, head, node) {
|
2010-01-15 01:45:30 +00:00
|
|
|
if (with_hits && !pos->hit)
|
|
|
|
continue;
|
2009-11-16 18:32:44 +00:00
|
|
|
ret += dso__fprintf_buildid(pos, fp);
|
2009-11-16 23:45:25 +00:00
|
|
|
ret += fprintf(fp, " %s\n", pos->long_name);
|
2009-11-16 18:32:44 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
|
|
|
|
bool with_hits)
|
2010-05-19 16:41:23 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
return __dsos__fprintf_buildid(&machine->kernel_dsos, fp, with_hits) +
|
|
|
|
__dsos__fprintf_buildid(&machine->user_dsos, fp, with_hits);
|
2010-05-19 16:41:23 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
|
|
|
|
FILE *fp, bool with_hits)
|
2009-11-27 18:29:14 +00:00
|
|
|
{
|
2010-04-19 05:32:50 +00:00
|
|
|
struct rb_node *nd;
|
|
|
|
size_t ret = 0;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
|
2010-04-28 00:17:50 +00:00
|
|
|
struct machine *pos = rb_entry(nd, struct machine, rb_node);
|
2010-05-19 16:41:23 +00:00
|
|
|
ret += machine__fprintf_dsos_buildid(pos, fp, with_hits);
|
2010-04-19 05:32:50 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2009-11-27 18:29:14 +00:00
|
|
|
}
|
|
|
|
|
2011-06-01 19:43:46 +00:00
|
|
|
static struct dso*
|
|
|
|
dso__kernel_findnew(struct machine *machine, const char *name,
|
|
|
|
const char *short_name, int dso_type)
|
2010-01-27 23:05:51 +00:00
|
|
|
{
|
2011-06-01 19:43:46 +00:00
|
|
|
/*
|
|
|
|
* The kernel dso could be created by build_id processing.
|
|
|
|
*/
|
|
|
|
struct dso *dso = __dsos__findnew(&machine->kernel_dsos, name);
|
2010-04-19 05:32:50 +00:00
|
|
|
|
2011-06-01 19:43:46 +00:00
|
|
|
/*
|
|
|
|
* We need to run this in all cases, since during the build_id
|
|
|
|
* processing we had no idea this was the kernel dso.
|
|
|
|
*/
|
2011-03-31 13:56:28 +00:00
|
|
|
if (dso != NULL) {
|
2011-06-01 19:43:46 +00:00
|
|
|
dso__set_short_name(dso, short_name);
|
|
|
|
dso->kernel = dso_type;
|
2010-01-27 23:05:51 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
return dso;
|
2010-01-27 23:05:51 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)
|
2010-01-27 23:05:51 +00:00
|
|
|
{
|
2010-04-19 05:32:50 +00:00
|
|
|
char path[PATH_MAX];
|
|
|
|
|
2010-04-28 00:17:50 +00:00
|
|
|
if (machine__is_default_guest(machine))
|
2010-04-19 05:32:50 +00:00
|
|
|
return;
|
2010-04-28 00:17:50 +00:00
|
|
|
sprintf(path, "%s/sys/kernel/notes", machine->root_dir);
|
2011-03-31 13:56:28 +00:00
|
|
|
if (sysfs__read_build_id(path, dso->build_id,
|
|
|
|
sizeof(dso->build_id)) == 0)
|
|
|
|
dso->has_build_id = true;
|
2010-01-27 23:05:51 +00:00
|
|
|
}
|
|
|
|
|
2011-06-01 19:43:46 +00:00
|
|
|
static struct dso *machine__get_kernel(struct machine *machine)
|
2009-08-12 08:03:49 +00:00
|
|
|
{
|
2010-04-19 05:32:50 +00:00
|
|
|
const char *vmlinux_name = NULL;
|
|
|
|
struct dso *kernel;
|
2009-08-12 08:03:49 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (machine__is_host(machine)) {
|
2010-04-19 05:32:50 +00:00
|
|
|
vmlinux_name = symbol_conf.vmlinux_name;
|
2011-06-01 19:43:46 +00:00
|
|
|
if (!vmlinux_name)
|
|
|
|
vmlinux_name = "[kernel.kallsyms]";
|
|
|
|
|
|
|
|
kernel = dso__kernel_findnew(machine, vmlinux_name,
|
|
|
|
"[kernel]",
|
|
|
|
DSO_TYPE_KERNEL);
|
2010-04-19 05:32:50 +00:00
|
|
|
} else {
|
2011-06-01 19:43:46 +00:00
|
|
|
char bf[PATH_MAX];
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
if (machine__is_default_guest(machine))
|
2010-04-19 05:32:50 +00:00
|
|
|
vmlinux_name = symbol_conf.default_guest_vmlinux_name;
|
2011-06-01 19:43:46 +00:00
|
|
|
if (!vmlinux_name)
|
|
|
|
vmlinux_name = machine__mmap_name(machine, bf,
|
|
|
|
sizeof(bf));
|
|
|
|
|
|
|
|
kernel = dso__kernel_findnew(machine, vmlinux_name,
|
|
|
|
"[guest.kernel]",
|
|
|
|
DSO_TYPE_GUEST_KERNEL);
|
2010-02-03 18:52:02 +00:00
|
|
|
}
|
2009-08-12 08:03:49 +00:00
|
|
|
|
2011-06-01 19:43:46 +00:00
|
|
|
if (kernel != NULL && (!kernel->has_build_id))
|
2011-03-31 13:56:28 +00:00
|
|
|
dso__read_running_kernel_build_id(kernel, machine);
|
2011-06-01 19:43:46 +00: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-11 16:50:39 +00:00
|
|
|
return kernel;
|
|
|
|
}
|
|
|
|
|
2010-11-25 11:27:25 +00:00
|
|
|
struct process_args {
|
|
|
|
u64 start;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int symbol__in_kernel(void *arg, const char *name,
|
2010-12-22 03:08:36 +00:00
|
|
|
char type __used, u64 start, u64 end __used)
|
2010-11-25 11:27:25 +00: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 12:53:51 +00:00
|
|
|
if (symbol__restricted_filename(filename, "/proc/kallsyms"))
|
|
|
|
return 0;
|
|
|
|
|
2010-11-25 11:27:25 +00:00
|
|
|
if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return args.start;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-11 16:50:39 +00:00
|
|
|
{
|
2010-01-04 18:19:29 +00:00
|
|
|
enum map_type type;
|
2011-03-31 13:56:28 +00: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-11 16:50:39 +00:00
|
|
|
|
2010-01-04 18:19:29 +00:00
|
|
|
for (type = 0; type < MAP__NR_TYPES; ++type) {
|
2010-02-03 18:52:00 +00:00
|
|
|
struct kmap *kmap;
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
machine->vmlinux_maps[type] = map__new2(start, kernel, type);
|
|
|
|
if (machine->vmlinux_maps[type] == NULL)
|
2010-01-04 18:19:29 +00: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-11 16:50:39 +00:00
|
|
|
|
2011-03-31 13:56:28 +00: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-11 16:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-11-18 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-02 21:18:28 +00:00
|
|
|
{
|
|
|
|
enum map_type type;
|
|
|
|
|
|
|
|
for (type = 0; type < MAP__NR_TYPES; ++type) {
|
|
|
|
struct kmap *kmap;
|
|
|
|
|
2011-03-31 13:56:28 +00: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-02 21:18:28 +00:00
|
|
|
continue;
|
|
|
|
|
2011-03-31 13:56:28 +00: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-02 21:18:28 +00: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 13:56:28 +00: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-02 21:18:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int machine__create_kernel_maps(struct machine *machine)
|
2010-04-29 18:25:23 +00:00
|
|
|
{
|
2011-06-01 19:43:46 +00:00
|
|
|
struct dso *kernel = machine__get_kernel(machine);
|
2010-04-29 18:25:23 +00:00
|
|
|
|
|
|
|
if (kernel == NULL ||
|
2011-03-31 13:56:28 +00:00
|
|
|
__machine__create_kernel_maps(machine, kernel) < 0)
|
2010-04-29 18:25:23 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-07-20 23:25:46 +00:00
|
|
|
if (symbol_conf.use_modules && machine__create_modules(machine) < 0) {
|
|
|
|
if (machine__is_host(machine))
|
|
|
|
pr_debug("Problems creating module maps, "
|
|
|
|
"continuing anyway...\n");
|
|
|
|
else
|
|
|
|
pr_debug("Problems creating module maps for guest %d, "
|
|
|
|
"continuing anyway...\n", machine->pid);
|
|
|
|
}
|
|
|
|
|
2010-04-29 18:25:23 +00:00
|
|
|
/*
|
|
|
|
* Now that we have all the maps created, just set the ->end of them:
|
|
|
|
*/
|
2011-03-31 13:56:28 +00:00
|
|
|
map_groups__fixup_end(&machine->kmaps);
|
2010-04-29 18:25:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-23 18:39:10 +00: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-09 20:27:07 +00: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-23 18:39:10 +00: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 13:56:28 +00:00
|
|
|
size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp)
|
2010-03-15 14:46:58 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
size_t printed = 0;
|
2011-03-31 13:56:28 +00:00
|
|
|
struct dso *kdso = machine->vmlinux_maps[MAP__FUNCTION]->dso;
|
2010-05-26 16:26:02 +00: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 14:46:58 +00:00
|
|
|
|
|
|
|
for (i = 0; i < vmlinux_path__nr_entries; ++i)
|
2010-05-26 16:26:02 +00:00
|
|
|
printed += fprintf(fp, "[%d] %s\n",
|
|
|
|
i + kdso->has_build_id, vmlinux_path[i]);
|
2010-03-15 14:46:58 +00:00
|
|
|
|
|
|
|
return printed;
|
|
|
|
}
|
|
|
|
|
2009-12-15 22:04:40 +00: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;
|
|
|
|
}
|
|
|
|
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 12:53:51 +00:00
|
|
|
static bool symbol__read_kptr_restrict(void)
|
|
|
|
{
|
|
|
|
bool value = false;
|
|
|
|
|
|
|
|
if (geteuid() != 0) {
|
|
|
|
FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r");
|
|
|
|
if (fp != NULL) {
|
|
|
|
char line[8];
|
|
|
|
|
|
|
|
if (fgets(line, sizeof(line), fp) != NULL)
|
|
|
|
value = atoi(line) != 0;
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2009-12-15 22:04:39 +00:00
|
|
|
int symbol__init(void)
|
2009-11-18 22:20:53 +00:00
|
|
|
{
|
2010-12-09 20:27:07 +00:00
|
|
|
const char *symfs;
|
|
|
|
|
2010-09-09 16:30:59 +00:00
|
|
|
if (symbol_conf.initialized)
|
|
|
|
return 0;
|
|
|
|
|
2011-03-29 17:18:39 +00:00
|
|
|
symbol_conf.priv_size = ALIGN(symbol_conf.priv_size, sizeof(u64));
|
|
|
|
|
2012-08-06 04:41:19 +00:00
|
|
|
symbol__elf_init();
|
|
|
|
|
2009-12-15 22:04:39 +00:00
|
|
|
if (symbol_conf.sort_by_name)
|
|
|
|
symbol_conf.priv_size += (sizeof(struct symbol_name_rb_node) -
|
|
|
|
sizeof(struct symbol));
|
2009-11-24 14:05:15 +00:00
|
|
|
|
2009-12-15 22:04:39 +00:00
|
|
|
if (symbol_conf.try_vmlinux_path && vmlinux_path__init() < 0)
|
2009-11-18 22:20:53 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-12-15 22:04:41 +00: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-15 22:04:40 +00: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-09 20:27:07 +00: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);
|
|
|
|
|
perf symbols: Handle /proc/sys/kernel/kptr_restrict
Perf uses /proc/modules to figure out where kernel modules are loaded.
With the advent of kptr_restrict, non root users get zeroes for all module
start addresses.
So check if kptr_restrict is non zero and don't generate the syntethic
PERF_RECORD_MMAP events for them.
Warn the user about it in perf record and in perf report.
In perf report the reference relocation symbol being zero means that
kptr_restrict was set, thus /proc/kallsyms has only zeroed addresses, so don't
use it to fixup symbol addresses when using a valid kallsyms (in the buildid
cache) or vmlinux (in the vmlinux path) build-id located automatically or
specified by the user.
Provide an explanation about it in 'perf report' if kernel samples were taken,
checking if a suitable vmlinux or kallsyms was found/specified.
Restricted /proc/kallsyms don't go to the buildid cache anymore.
Example:
[acme@emilia ~]$ perf record -F 100000 sleep 1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted, check
/proc/sys/kernel/kptr_restrict.
Samples in kernel functions may not be resolved if a suitable vmlinux file is
not found in the buildid cache or in the vmlinux path.
Samples in kernel modules won't be resolved at all.
If some relocation was applied (e.g. kexec) symbols may be misresolved even
with a suitable vmlinux or kallsyms file.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.005 MB perf.data (~231 samples) ]
[acme@emilia ~]$
[acme@emilia ~]$ perf report --stdio
Kernel address maps (/proc/{kallsyms,modules}) were restricted,
check /proc/sys/kernel/kptr_restrict before running 'perf record'.
If some relocation was applied (e.g. kexec) symbols may be misresolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. .....................
#
20.24% sleep [kernel.kallsyms] [k] page_fault
20.04% sleep [kernel.kallsyms] [k] filemap_fault
19.78% sleep [kernel.kallsyms] [k] __lru_cache_add
19.69% sleep ld-2.12.so [.] memcpy
14.71% sleep [kernel.kallsyms] [k] dput
4.70% sleep [kernel.kallsyms] [k] flush_signal_handlers
0.73% sleep [kernel.kallsyms] [k] perf_event_comm
0.11% sleep [kernel.kallsyms] [k] native_write_msr_safe
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
This is because it found a suitable vmlinux (build-id checked) in
/lib/modules/2.6.39-rc7+/build/vmlinux (use -v in perf report to see the long
file name).
If we remove that file from the vmlinux path:
[root@emilia ~]# mv /lib/modules/2.6.39-rc7+/build/vmlinux \
/lib/modules/2.6.39-rc7+/build/vmlinux.OFF
[acme@emilia ~]$ perf report --stdio
[kernel.kallsyms] with build id 57298cdbe0131f6871667ec0eaab4804dcf6f562
not found, continuing without symbols
Kernel address maps (/proc/{kallsyms,modules}) were restricted, check
/proc/sys/kernel/kptr_restrict before running 'perf record'.
As no suitable kallsyms nor vmlinux was found, kernel samples can't be
resolved.
Samples in kernel modules can't be resolved as well.
# Events: 13 cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ......
#
80.31% sleep [kernel.kallsyms] [k] 0xffffffff8103425a
19.69% sleep ld-2.12.so [.] memcpy
#
# (For a higher level overview, try: perf report --sort comm,dso)
#
[acme@emilia ~]$
Reported-by: Stephane Eranian <eranian@google.com>
Suggested-by: David Miller <davem@davemloft.net>
Cc: Dave Jones <davej@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Kees Cook <kees.cook@canonical.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Link: http://lkml.kernel.org/n/tip-mt512joaxxbhhp1odop04yit@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2011-05-26 12:53:51 +00:00
|
|
|
symbol_conf.kptr_restrict = symbol__read_kptr_restrict();
|
|
|
|
|
2010-09-09 16:30:59 +00: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-13 21:50:29 +00:00
|
|
|
return 0;
|
2009-12-15 22:04:40 +00:00
|
|
|
|
|
|
|
out_free_comm_list:
|
|
|
|
strlist__delete(symbol_conf.comm_list);
|
2011-12-12 15:16:52 +00:00
|
|
|
out_free_dso_list:
|
|
|
|
strlist__delete(symbol_conf.dso_list);
|
2009-12-15 22:04:40 +00:00
|
|
|
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-13 21:50:29 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 21:31:28 +00:00
|
|
|
void symbol__exit(void)
|
|
|
|
{
|
2010-09-09 16:30:59 +00:00
|
|
|
if (!symbol_conf.initialized)
|
|
|
|
return;
|
2010-07-30 21:31:28 +00: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-09 16:30:59 +00:00
|
|
|
symbol_conf.initialized = false;
|
2010-07-30 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00: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-13 21:50:29 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct machine *machine = machines__findnew(machines, pid);
|
2010-02-03 18:52:00 +00:00
|
|
|
|
2010-04-28 00:17:50 +00:00
|
|
|
if (machine == NULL)
|
2010-04-19 05:32:50 +00:00
|
|
|
return -1;
|
2009-11-23 18:39:10 +00:00
|
|
|
|
2010-04-29 18:25:23 +00:00
|
|
|
return machine__create_kernel_maps(machine);
|
2009-08-12 08:03:49 +00:00
|
|
|
}
|
2010-03-25 22:59:00 +00: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 05:32:50 +00:00
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int machines__create_guest_kernel_maps(struct rb_root *machines)
|
2010-04-19 05:32:50 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct dirent **namelist = NULL;
|
|
|
|
int i, items = 0;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
pid_t pid;
|
2012-07-30 02:54:35 +00:00
|
|
|
char *endp;
|
2010-04-19 05:32:50 +00:00
|
|
|
|
|
|
|
if (symbol_conf.default_guest_vmlinux_name ||
|
|
|
|
symbol_conf.default_guest_modules ||
|
|
|
|
symbol_conf.default_guest_kallsyms) {
|
2011-03-31 13:56:28 +00:00
|
|
|
machines__create_kernel_maps(machines, DEFAULT_GUEST_KERNEL_ID);
|
2010-04-19 05:32:50 +00: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;
|
|
|
|
}
|
2012-07-30 02:54:35 +00:00
|
|
|
pid = (pid_t)strtol(namelist[i]->d_name, &endp, 10);
|
|
|
|
if ((*endp != '\0') ||
|
|
|
|
(endp == namelist[i]->d_name) ||
|
|
|
|
(errno == ERANGE)) {
|
|
|
|
pr_debug("invalid directory (%s). Skipping.\n",
|
|
|
|
namelist[i]->d_name);
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-19 05:32:50 +00:00
|
|
|
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 13:56:28 +00:00
|
|
|
machines__create_kernel_maps(machines, pid);
|
2010-04-19 05:32:50 +00:00
|
|
|
}
|
|
|
|
failure:
|
|
|
|
free(namelist);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-04-29 18:25:23 +00:00
|
|
|
|
2011-03-31 13:56:28 +00: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-02 21:18:28 +00:00
|
|
|
{
|
2011-03-31 13:56:28 +00: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-02 21:18:28 +00:00
|
|
|
|
|
|
|
while (next) {
|
|
|
|
struct machine *pos = rb_entry(next, struct machine, rb_node);
|
|
|
|
|
|
|
|
next = rb_next(&pos->rb_node);
|
2011-03-31 13:56:28 +00: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-02 21:18:28 +00:00
|
|
|
machine__delete(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int machine__load_kallsyms(struct machine *machine, const char *filename,
|
2010-04-29 18:25:23 +00:00
|
|
|
enum map_type type, symbol_filter_t filter)
|
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct map *map = machine->vmlinux_maps[type];
|
2010-04-29 18:25:23 +00: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 13:56:28 +00:00
|
|
|
__map_groups__fixup_end(&machine->kmaps, type);
|
2010-04-29 18:25:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:56:28 +00:00
|
|
|
int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
|
2010-04-29 18:25:23 +00:00
|
|
|
symbol_filter_t filter)
|
|
|
|
{
|
2011-03-31 13:56:28 +00:00
|
|
|
struct map *map = machine->vmlinux_maps[type];
|
2010-04-29 18:25:23 +00: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;
|
|
|
|
}
|
2012-04-16 12:09:09 +00:00
|
|
|
|
|
|
|
struct map *dso__new_map(const char *name)
|
|
|
|
{
|
2012-05-31 11:46:56 +00:00
|
|
|
struct map *map = NULL;
|
2012-04-16 12:09:09 +00:00
|
|
|
struct dso *dso = dso__new(name);
|
2012-05-31 11:46:56 +00:00
|
|
|
|
|
|
|
if (dso)
|
|
|
|
map = map__new2(0, dso, MAP__FUNCTION);
|
2012-04-16 12:09:09 +00:00
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
2012-07-22 12:14:33 +00:00
|
|
|
|
|
|
|
static int open_dso(struct dso *dso, struct machine *machine)
|
|
|
|
{
|
|
|
|
char *root_dir = (char *) "";
|
|
|
|
char *name;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
name = malloc(PATH_MAX);
|
|
|
|
if (!name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (machine)
|
|
|
|
root_dir = machine->root_dir;
|
|
|
|
|
|
|
|
if (dso__binary_type_file(dso, dso->data_type,
|
|
|
|
root_dir, name, PATH_MAX)) {
|
|
|
|
free(name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = open(name, O_RDONLY);
|
|
|
|
free(name);
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dso__data_fd(struct dso *dso, struct machine *machine)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND)
|
|
|
|
return open_dso(dso, machine);
|
|
|
|
|
|
|
|
do {
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
dso->data_type = binary_type_data[i++];
|
|
|
|
|
|
|
|
fd = open_dso(dso, machine);
|
|
|
|
if (fd >= 0)
|
|
|
|
return fd;
|
|
|
|
|
|
|
|
} while (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND);
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-07-22 12:14:39 +00:00
|
|
|
static void
|
|
|
|
dso_cache__free(struct rb_root *root)
|
2012-07-22 12:14:33 +00:00
|
|
|
{
|
2012-07-22 12:14:39 +00:00
|
|
|
struct rb_node *next = rb_first(root);
|
|
|
|
|
|
|
|
while (next) {
|
|
|
|
struct dso_cache *cache;
|
|
|
|
|
|
|
|
cache = rb_entry(next, struct dso_cache, rb_node);
|
|
|
|
next = rb_next(&cache->rb_node);
|
|
|
|
rb_erase(&cache->rb_node, root);
|
|
|
|
free(cache);
|
|
|
|
}
|
2012-07-22 12:14:33 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 12:14:39 +00:00
|
|
|
static struct dso_cache*
|
|
|
|
dso_cache__find(struct rb_root *root, u64 offset)
|
2012-07-22 12:14:33 +00:00
|
|
|
{
|
2012-07-22 12:14:39 +00:00
|
|
|
struct rb_node **p = &root->rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct dso_cache *cache;
|
|
|
|
|
|
|
|
while (*p != NULL) {
|
|
|
|
u64 end;
|
|
|
|
|
|
|
|
parent = *p;
|
|
|
|
cache = rb_entry(parent, struct dso_cache, rb_node);
|
|
|
|
end = cache->offset + DSO__DATA_CACHE_SIZE;
|
|
|
|
|
|
|
|
if (offset < cache->offset)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else if (offset >= end)
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
else
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dso_cache__insert(struct rb_root *root, struct dso_cache *new)
|
|
|
|
{
|
|
|
|
struct rb_node **p = &root->rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct dso_cache *cache;
|
|
|
|
u64 offset = new->offset;
|
|
|
|
|
|
|
|
while (*p != NULL) {
|
|
|
|
u64 end;
|
|
|
|
|
|
|
|
parent = *p;
|
|
|
|
cache = rb_entry(parent, struct dso_cache, rb_node);
|
|
|
|
end = cache->offset + DSO__DATA_CACHE_SIZE;
|
|
|
|
|
|
|
|
if (offset < cache->offset)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else if (offset >= end)
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_link_node(&new->rb_node, parent, p);
|
|
|
|
rb_insert_color(&new->rb_node, root);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
dso_cache__memcpy(struct dso_cache *cache, u64 offset,
|
|
|
|
u8 *data, u64 size)
|
|
|
|
{
|
|
|
|
u64 cache_offset = offset - cache->offset;
|
|
|
|
u64 cache_size = min(cache->size - cache_offset, size);
|
|
|
|
|
|
|
|
memcpy(data, cache->data + cache_offset, cache_size);
|
|
|
|
return cache_size;
|
2012-07-22 12:14:33 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 12:14:39 +00:00
|
|
|
static ssize_t
|
|
|
|
dso_cache__read(struct dso *dso, struct machine *machine,
|
|
|
|
u64 offset, u8 *data, ssize_t size)
|
2012-07-22 12:14:33 +00:00
|
|
|
{
|
2012-07-22 12:14:39 +00:00
|
|
|
struct dso_cache *cache;
|
|
|
|
ssize_t ret;
|
2012-07-22 12:14:33 +00:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = dso__data_fd(dso, machine);
|
|
|
|
if (fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
do {
|
2012-07-22 12:14:39 +00:00
|
|
|
u64 cache_offset;
|
|
|
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
|
|
|
|
cache = zalloc(sizeof(*cache) + DSO__DATA_CACHE_SIZE);
|
|
|
|
if (!cache)
|
2012-07-22 12:14:33 +00:00
|
|
|
break;
|
|
|
|
|
2012-07-22 12:14:39 +00:00
|
|
|
cache_offset = offset & DSO__DATA_CACHE_MASK;
|
|
|
|
ret = -EINVAL;
|
|
|
|
|
|
|
|
if (-1 == lseek(fd, cache_offset, SEEK_SET))
|
2012-07-22 12:14:33 +00:00
|
|
|
break;
|
|
|
|
|
2012-07-22 12:14:39 +00:00
|
|
|
ret = read(fd, cache->data, DSO__DATA_CACHE_SIZE);
|
|
|
|
if (ret <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
cache->offset = cache_offset;
|
|
|
|
cache->size = ret;
|
|
|
|
dso_cache__insert(&dso->cache, cache);
|
|
|
|
|
|
|
|
ret = dso_cache__memcpy(cache, offset, data, size);
|
2012-07-22 12:14:33 +00:00
|
|
|
|
|
|
|
} while (0);
|
|
|
|
|
2012-07-22 12:14:39 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
free(cache);
|
|
|
|
|
2012-07-22 12:14:33 +00:00
|
|
|
close(fd);
|
2012-07-22 12:14:39 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dso_cache_read(struct dso *dso, struct machine *machine,
|
|
|
|
u64 offset, u8 *data, ssize_t size)
|
|
|
|
{
|
|
|
|
struct dso_cache *cache;
|
|
|
|
|
|
|
|
cache = dso_cache__find(&dso->cache, offset);
|
|
|
|
if (cache)
|
|
|
|
return dso_cache__memcpy(cache, offset, data, size);
|
|
|
|
else
|
|
|
|
return dso_cache__read(dso, machine, offset, data, size);
|
2012-07-22 12:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
|
|
|
|
u64 offset, u8 *data, ssize_t size)
|
|
|
|
{
|
2012-07-22 12:14:39 +00:00
|
|
|
ssize_t r = 0;
|
|
|
|
u8 *p = data;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = dso_cache_read(dso, machine, offset, p, size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Reached EOF, return what we have. */
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
BUG_ON(ret > size);
|
|
|
|
|
|
|
|
r += ret;
|
|
|
|
p += ret;
|
|
|
|
offset += ret;
|
|
|
|
size -= ret;
|
|
|
|
|
|
|
|
} while (size);
|
|
|
|
|
|
|
|
return r;
|
2012-07-22 12:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
|
|
|
|
struct machine *machine, u64 addr,
|
|
|
|
u8 *data, ssize_t size)
|
|
|
|
{
|
|
|
|
u64 offset = map->map_ip(map, addr);
|
|
|
|
return dso__data_read_offset(dso, machine, offset, data, size);
|
|
|
|
}
|