Skip to content

Commit 3556377

Browse files
committed
perf kallsyms: Introduce tool to look for extended symbol information on the running kernel
Its similar to doing grep on a /proc/kallsyms, but it also shows extra information like the path to the kernel module and the unrelocated addresses in it, to help in diagnosing problems. It is also helps demonstrate the use of the symbols routines so that tool writers can use them more effectively. Using it: $ perf kallsyms e1000_xmit_frame netif_rx usb_stor_set_xfer_buf e1000_xmit_frame: [e1000e] /lib/modules/4.9.0+/kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko 0xffffffffc046fc10-0xffffffffc0470bb0 (0x19c80-0x1ac20) netif_rx: [kernel] [kernel.kallsyms] 0xffffffff916f03a0-0xffffffff916f0410 (0xffffffff916f03a0-0xffffffff916f0410) usb_stor_set_xfer_buf: [usb_storage] /lib/modules/4.9.0+/kernel/drivers/usb/storage/usb-storage.ko 0xffffffffc057aea0-0xffffffffc057af19 (0xf10-0xf89) $ Cc: Adrian Hunter <[email protected]> Cc: David Ahern <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 7d132ca commit 3556377

File tree

7 files changed

+96
-1
lines changed

7 files changed

+96
-1
lines changed

tools/perf/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ perf-y += builtin-help.o
77
perf-y += builtin-sched.o
88
perf-y += builtin-buildid-list.o
99
perf-y += builtin-buildid-cache.o
10+
perf-y += builtin-kallsyms.o
1011
perf-y += builtin-list.o
1112
perf-y += builtin-record.o
1213
perf-y += builtin-report.o
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
perf-kallsyms(1)
2+
==============
3+
4+
NAME
5+
----
6+
perf-kallsyms - Searches running kernel for symbols
7+
8+
SYNOPSIS
9+
--------
10+
[verse]
11+
'perf kallsyms <options> symbol_name[,symbol_name...]'
12+
13+
DESCRIPTION
14+
-----------
15+
This command searches the running kernel kallsyms file for the given symbol(s)
16+
and prints information about it, including the DSO, the kallsyms begin/end
17+
addresses and the addresses in the ELF kallsyms symbol table (for symbols in
18+
modules).
19+
20+
OPTIONS
21+
-------
22+
-v::
23+
--verbose=::
24+
Increase verbosity level, showing details about symbol table loading, etc.

tools/perf/builtin-help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
434434
const char * const builtin_help_subcommands[] = {
435435
"buildid-cache", "buildid-list", "diff", "evlist", "help", "list",
436436
"record", "report", "bench", "stat", "timechart", "top", "annotate",
437-
"script", "sched", "kmem", "lock", "kvm", "test", "inject", "mem", "data",
437+
"script", "sched", "kallsyms", "kmem", "lock", "kvm", "test", "inject", "mem", "data",
438438
#ifdef HAVE_LIBELF_SUPPORT
439439
"probe",
440440
#endif

tools/perf/builtin-kallsyms.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* builtin-kallsyms.c
3+
*
4+
* Builtin command: Look for a symbol in the running kernel and its modules
5+
*
6+
* Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <[email protected]>
7+
*
8+
* Released under the GPL v2. (and only v2, not any later version)
9+
*/
10+
#include "builtin.h"
11+
#include <linux/compiler.h>
12+
#include <subcmd/parse-options.h>
13+
#include "debug.h"
14+
#include "machine.h"
15+
#include "symbol.h"
16+
17+
static int __cmd_kallsyms(int argc, const char **argv)
18+
{
19+
int i;
20+
struct machine *machine = machine__new_kallsyms();
21+
22+
if (machine == NULL) {
23+
pr_err("Couldn't read /proc/kallsyms\n");
24+
return -1;
25+
}
26+
27+
for (i = 0; i < argc; ++i) {
28+
struct map *map;
29+
struct symbol *symbol = machine__find_kernel_function_by_name(machine, argv[i], &map);
30+
31+
if (symbol == NULL) {
32+
printf("%s: not found\n", argv[i]);
33+
continue;
34+
}
35+
36+
printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n",
37+
symbol->name, map->dso->short_name, map->dso->long_name,
38+
map->unmap_ip(map, symbol->start), map->unmap_ip(map, symbol->end),
39+
symbol->start, symbol->end);
40+
}
41+
42+
machine__delete(machine);
43+
return 0;
44+
}
45+
46+
int cmd_kallsyms(int argc, const char **argv, const char *prefix __maybe_unused)
47+
{
48+
const struct option options[] = {
49+
OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"),
50+
OPT_END()
51+
};
52+
const char * const kallsyms_usage[] = {
53+
"perf kallsyms [<options>] symbol_name",
54+
NULL
55+
};
56+
57+
argc = parse_options(argc, argv, options, kallsyms_usage, 0);
58+
if (argc < 1)
59+
usage_with_options(kallsyms_usage, options);
60+
61+
symbol_conf.sort_by_name = true;
62+
symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
63+
if (symbol__init(NULL) < 0)
64+
return -1;
65+
66+
return __cmd_kallsyms(argc, argv);
67+
}

tools/perf/builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix);
2323
int cmd_evlist(int argc, const char **argv, const char *prefix);
2424
int cmd_help(int argc, const char **argv, const char *prefix);
2525
int cmd_sched(int argc, const char **argv, const char *prefix);
26+
int cmd_kallsyms(int argc, const char **argv, const char *prefix);
2627
int cmd_list(int argc, const char **argv, const char *prefix);
2728
int cmd_record(int argc, const char **argv, const char *prefix);
2829
int cmd_report(int argc, const char **argv, const char *prefix);

tools/perf/command-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ perf-diff mainporcelain common
1212
perf-config mainporcelain common
1313
perf-evlist mainporcelain common
1414
perf-inject mainporcelain common
15+
perf-kallsyms mainporcelain common
1516
perf-kmem mainporcelain common
1617
perf-kvm mainporcelain common
1718
perf-list mainporcelain common

tools/perf/perf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static struct cmd_struct commands[] = {
4747
{ "diff", cmd_diff, 0 },
4848
{ "evlist", cmd_evlist, 0 },
4949
{ "help", cmd_help, 0 },
50+
{ "kallsyms", cmd_kallsyms, 0 },
5051
{ "list", cmd_list, 0 },
5152
{ "record", cmd_record, 0 },
5253
{ "report", cmd_report, 0 },

0 commit comments

Comments
 (0)