Skip to content

Commit

Permalink
perf_counter tools: Enable kernel module symbol loading in tools
Browse files Browse the repository at this point in the history
Add the -m/--modules option to perf report and perf annotate,
which enables live module symbol/image loading. To be used
with -k/--vmlinux.

(Also give perf annotate a -P/--full-paths option.)

Signed-off-by: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1246514986.13293.48.camel@marge.simson.net>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Mike Galbraith authored and Ingo Molnar committed Jul 2, 2009
1 parent 6cfcc53 commit 4297648
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
25 changes: 20 additions & 5 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ static int dump_trace = 0;

static int verbose;

static int modules;

static int full_paths;

static int print_line;

static unsigned long page_size;
Expand Down Expand Up @@ -171,7 +175,7 @@ static int load_kernel(void)
if (!kernel_dso)
return -1;

err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, 0);
err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, modules);
if (err <= 0) {
dso__delete(kernel_dso);
kernel_dso = NULL;
Expand Down Expand Up @@ -1268,19 +1272,25 @@ static void print_summary(char *filename)

static void annotate_sym(struct dso *dso, struct symbol *sym)
{
char *filename = dso->name;
char *filename = dso->name, *d_filename;
u64 start, end, len;
char command[PATH_MAX*2];
FILE *file;

if (!filename)
return;
if (dso == kernel_dso)
if (sym->module)
filename = sym->module->path;
else if (dso == kernel_dso)
filename = vmlinux;

start = sym->obj_start;
if (!start)
start = sym->start;
if (full_paths)
d_filename = filename;
else
d_filename = basename(filename);

end = start + sym->end - sym->start + 1;
len = sym->end - sym->start;
Expand All @@ -1291,13 +1301,14 @@ static void annotate_sym(struct dso *dso, struct symbol *sym)
}

printf("\n\n------------------------------------------------\n");
printf(" Percent | Source code & Disassembly of %s\n", filename);
printf(" Percent | Source code & Disassembly of %s\n", d_filename);
printf("------------------------------------------------\n");

if (verbose >= 2)
printf("annotating [%p] %30s : [%p] %30s\n", dso, dso->name, sym, sym->name);

sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s", (u64)start, (u64)end, filename);
sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s",
(u64)start, (u64)end, filename, filename);

if (verbose >= 3)
printf("doing: %s\n", command);
Expand Down Expand Up @@ -1472,8 +1483,12 @@ static const struct option options[] = {
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
"dump raw trace in ASCII"),
OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
OPT_BOOLEAN('m', "modules", &modules,
"load module symbols - WARNING: use only with -k and LIVE kernel"),
OPT_BOOLEAN('l', "print-line", &print_line,
"print matching source lines (may be slow)"),
OPT_BOOLEAN('P', "full-paths", &full_paths,
"Don't shorten the displayed pathnames"),
OPT_END()
};

Expand Down
9 changes: 8 additions & 1 deletion tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ static int dump_trace = 0;
static int verbose;
#define eprintf(x...) do { if (verbose) fprintf(stderr, x); } while (0)

static int modules;

static int full_paths;

static unsigned long page_size;
Expand Down Expand Up @@ -188,7 +190,7 @@ static int load_kernel(void)
if (!kernel_dso)
return -1;

err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, 0);
err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, modules);
if (err <= 0) {
dso__delete(kernel_dso);
kernel_dso = NULL;
Expand Down Expand Up @@ -648,6 +650,9 @@ sort__sym_print(FILE *fp, struct hist_entry *self)
ret += fprintf(fp, "[%c] %s",
self->dso == kernel_dso ? 'k' :
self->dso == hypervisor_dso ? 'h' : '.', self->sym->name);

if (self->sym->module)
ret += fprintf(fp, "\t[%s]", self->sym->module->name);
} else {
ret += fprintf(fp, "%#016llx", (u64)self->ip);
}
Expand Down Expand Up @@ -1710,6 +1715,8 @@ static const struct option options[] = {
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
"dump raw trace in ASCII"),
OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
OPT_BOOLEAN('m', "modules", &modules,
"load module symbols - WARNING: use only with -k and LIVE kernel"),
OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
"sort by key(s): pid, comm, dso, symbol, parent"),
OPT_BOOLEAN('P', "full-paths", &full_paths,
Expand Down
12 changes: 10 additions & 2 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static unsigned int page_size;
static unsigned int mmap_pages = 16;
static int freq = 0;
static int verbose = 0;
static char *vmlinux = NULL;

static char *sym_filter;
static unsigned long filter_start;
Expand Down Expand Up @@ -265,7 +266,10 @@ static void print_sym_table(void)
printf("%9.1f %10ld - ", syme->weight, syme->snap_count);

color_fprintf(stdout, color, "%4.1f%%", pcnt);
printf(" - %016llx : %s\n", sym->start, sym->name);
printf(" - %016llx : %s", sym->start, sym->name);
if (sym->module)
printf("\t[%s]", sym->module->name);
printf("\n");
}
}

Expand Down Expand Up @@ -359,12 +363,13 @@ static int parse_symbols(void)
{
struct rb_node *node;
struct symbol *sym;
int modules = vmlinux ? 1 : 0;

kernel_dso = dso__new("[kernel]", sizeof(struct sym_entry));
if (kernel_dso == NULL)
return -1;

if (dso__load_kernel(kernel_dso, NULL, symbol_filter, 1, 0) <= 0)
if (dso__load_kernel(kernel_dso, vmlinux, symbol_filter, verbose, modules) <= 0)
goto out_delete_dso;

node = rb_first(&kernel_dso->syms);
Expand Down Expand Up @@ -680,6 +685,7 @@ static const struct option options[] = {
"system-wide collection from all CPUs"),
OPT_INTEGER('C', "CPU", &profile_cpu,
"CPU to profile on"),
OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
OPT_INTEGER('m', "mmap-pages", &mmap_pages,
"number of mmap data pages"),
OPT_INTEGER('r', "realtime", &realtime_prio,
Expand Down Expand Up @@ -709,6 +715,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
{
int counter;

symbol__init();

page_size = sysconf(_SC_PAGE_SIZE);

argc = parse_options(argc, argv, options, top_usage, 0);
Expand Down

0 comments on commit 4297648

Please sign in to comment.