diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-11 21:03:56 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-11 21:18:24 -0400 |
commit | fd4be13067ef65bf33b965a18c717889305d5fea (patch) | |
tree | 79dcf602f2ee0de4d64d643deef39c5aea228881 | |
parent | fde54b7860ffff1c93e6b9abb3fbc3b8b95f2695 (diff) |
perf evsel: Allow unresolved symbol names to be printed as addresses
The fprintf_sym() and fprintf_callchain() methods now allow users to
change the existing behaviour of showing "[unknown]" as the name of
unresolved symbols to instead show "[0x123456]", i.e. its address.
The current patch doesn't change tools to use this facility, the results
from 'perf trace' and 'perf script' cotinue like:
70.109 ( 0.001 ms): qemu-system-x8/10153 poll(ufds: 0x7f2d93ffe870, nfds: 1) = 0 Timeout
[unknown] (/usr/lib64/libc-2.22.so)
[unknown] (/usr/lib64/libspice-server.so.1.10.0)
[unknown] (/usr/lib64/libspice-server.so.1.10.0)
[unknown] (/usr/lib64/libspice-server.so.1.10.0)
start_thread+0xca (/usr/lib64/libpthread-2.22.so)
__clone+0x6d (/usr/lib64/libc-2.22.so)
The next patch will make 'perf trace' use the new formatting.
Suggested-by: Milian Wolff <milian.wolff@kdab.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-fja1ods5vqpg42mdz09xcz3r@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/session.c | 27 | ||||
-rw-r--r-- | tools/perf/util/session.h | 1 | ||||
-rw-r--r-- | tools/perf/util/symbol.c | 25 | ||||
-rw-r--r-- | tools/perf/util/symbol.h | 6 |
4 files changed, 46 insertions, 13 deletions
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index e384b651a3e8..0516d06a2741 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -1966,6 +1966,7 @@ int perf_evsel__fprintf_callchain(struct perf_evsel *evsel, struct perf_sample * | |||
1966 | int print_symoffset = print_opts & PRINT_IP_OPT_SYMOFFSET; | 1966 | int print_symoffset = print_opts & PRINT_IP_OPT_SYMOFFSET; |
1967 | int print_oneline = print_opts & PRINT_IP_OPT_ONELINE; | 1967 | int print_oneline = print_opts & PRINT_IP_OPT_ONELINE; |
1968 | int print_srcline = print_opts & PRINT_IP_OPT_SRCLINE; | 1968 | int print_srcline = print_opts & PRINT_IP_OPT_SRCLINE; |
1969 | int print_unknown_as_addr = print_opts & PRINT_IP_OPT_UNKNOWN_AS_ADDR; | ||
1969 | char s = print_oneline ? ' ' : '\t'; | 1970 | char s = print_oneline ? ' ' : '\t'; |
1970 | 1971 | ||
1971 | if (sample->callchain) { | 1972 | if (sample->callchain) { |
@@ -2003,12 +2004,16 @@ int perf_evsel__fprintf_callchain(struct perf_evsel *evsel, struct perf_sample * | |||
2003 | 2004 | ||
2004 | if (print_sym) { | 2005 | if (print_sym) { |
2005 | printed += fprintf(fp, " "); | 2006 | printed += fprintf(fp, " "); |
2007 | node_al.addr = addr; | ||
2008 | node_al.map = node->map; | ||
2009 | |||
2006 | if (print_symoffset) { | 2010 | if (print_symoffset) { |
2007 | node_al.addr = addr; | 2011 | printed += __symbol__fprintf_symname_offs(node->sym, &node_al, |
2008 | node_al.map = node->map; | 2012 | print_unknown_as_addr, fp); |
2009 | printed += symbol__fprintf_symname_offs(node->sym, &node_al, fp); | 2013 | } else { |
2010 | } else | 2014 | printed += __symbol__fprintf_symname(node->sym, &node_al, |
2011 | printed += symbol__fprintf_symname(node->sym, fp); | 2015 | print_unknown_as_addr, fp); |
2016 | } | ||
2012 | } | 2017 | } |
2013 | 2018 | ||
2014 | if (print_dso) { | 2019 | if (print_dso) { |
@@ -2043,6 +2048,7 @@ int perf_evsel__fprintf_sym(struct perf_evsel *evsel, struct perf_sample *sample | |||
2043 | int print_dso = print_opts & PRINT_IP_OPT_DSO; | 2048 | int print_dso = print_opts & PRINT_IP_OPT_DSO; |
2044 | int print_symoffset = print_opts & PRINT_IP_OPT_SYMOFFSET; | 2049 | int print_symoffset = print_opts & PRINT_IP_OPT_SYMOFFSET; |
2045 | int print_srcline = print_opts & PRINT_IP_OPT_SRCLINE; | 2050 | int print_srcline = print_opts & PRINT_IP_OPT_SRCLINE; |
2051 | int print_unknown_as_addr = print_opts & PRINT_IP_OPT_UNKNOWN_AS_ADDR; | ||
2046 | 2052 | ||
2047 | if (symbol_conf.use_callchain && sample->callchain) { | 2053 | if (symbol_conf.use_callchain && sample->callchain) { |
2048 | printed += perf_evsel__fprintf_callchain(evsel, sample, al, left_alignment, | 2054 | printed += perf_evsel__fprintf_callchain(evsel, sample, al, left_alignment, |
@@ -2055,10 +2061,13 @@ int perf_evsel__fprintf_sym(struct perf_evsel *evsel, struct perf_sample *sample | |||
2055 | 2061 | ||
2056 | if (print_sym) { | 2062 | if (print_sym) { |
2057 | printed += fprintf(fp, " "); | 2063 | printed += fprintf(fp, " "); |
2058 | if (print_symoffset) | 2064 | if (print_symoffset) { |
2059 | printed += symbol__fprintf_symname_offs(al->sym, al, fp); | 2065 | printed += __symbol__fprintf_symname_offs(al->sym, al, |
2060 | else | 2066 | print_unknown_as_addr, fp); |
2061 | printed += symbol__fprintf_symname(al->sym, fp); | 2067 | } else { |
2068 | printed += __symbol__fprintf_symname(al->sym, al, | ||
2069 | print_unknown_as_addr, fp); | ||
2070 | } | ||
2062 | } | 2071 | } |
2063 | 2072 | ||
2064 | if (print_dso) { | 2073 | if (print_dso) { |
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index ac834908bb35..4257fac56618 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -42,6 +42,7 @@ struct perf_session { | |||
42 | #define PRINT_IP_OPT_SYMOFFSET (1<<3) | 42 | #define PRINT_IP_OPT_SYMOFFSET (1<<3) |
43 | #define PRINT_IP_OPT_ONELINE (1<<4) | 43 | #define PRINT_IP_OPT_ONELINE (1<<4) |
44 | #define PRINT_IP_OPT_SRCLINE (1<<5) | 44 | #define PRINT_IP_OPT_SRCLINE (1<<5) |
45 | #define PRINT_IP_OPT_UNKNOWN_AS_ADDR (1<<6) | ||
45 | 46 | ||
46 | struct perf_tool; | 47 | struct perf_tool; |
47 | 48 | ||
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index e7588dc91518..bb162ee433c6 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -264,8 +264,9 @@ size_t symbol__fprintf(struct symbol *sym, FILE *fp) | |||
264 | sym->name); | 264 | sym->name); |
265 | } | 265 | } |
266 | 266 | ||
267 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, | 267 | size_t __symbol__fprintf_symname_offs(const struct symbol *sym, |
268 | const struct addr_location *al, FILE *fp) | 268 | const struct addr_location *al, |
269 | bool unknown_as_addr, FILE *fp) | ||
269 | { | 270 | { |
270 | unsigned long offset; | 271 | unsigned long offset; |
271 | size_t length; | 272 | size_t length; |
@@ -280,13 +281,29 @@ size_t symbol__fprintf_symname_offs(const struct symbol *sym, | |||
280 | length += fprintf(fp, "+0x%lx", offset); | 281 | length += fprintf(fp, "+0x%lx", offset); |
281 | } | 282 | } |
282 | return length; | 283 | return length; |
283 | } else | 284 | } else if (al && unknown_as_addr) |
285 | return fprintf(fp, "[%#" PRIx64 "]", al->addr); | ||
286 | else | ||
284 | return fprintf(fp, "[unknown]"); | 287 | return fprintf(fp, "[unknown]"); |
285 | } | 288 | } |
286 | 289 | ||
290 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, | ||
291 | const struct addr_location *al, | ||
292 | FILE *fp) | ||
293 | { | ||
294 | return __symbol__fprintf_symname_offs(sym, al, false, fp); | ||
295 | } | ||
296 | |||
297 | size_t __symbol__fprintf_symname(const struct symbol *sym, | ||
298 | const struct addr_location *al, | ||
299 | bool unknown_as_addr, FILE *fp) | ||
300 | { | ||
301 | return __symbol__fprintf_symname_offs(sym, al, unknown_as_addr, fp); | ||
302 | } | ||
303 | |||
287 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp) | 304 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp) |
288 | { | 305 | { |
289 | return symbol__fprintf_symname_offs(sym, NULL, fp); | 306 | return __symbol__fprintf_symname_offs(sym, NULL, false, fp); |
290 | } | 307 | } |
291 | 308 | ||
292 | void symbols__delete(struct rb_root *symbols) | 309 | void symbols__delete(struct rb_root *symbols) |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index c8b7544d9267..e2562568418d 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -262,8 +262,14 @@ int symbol__init(struct perf_env *env); | |||
262 | void symbol__exit(void); | 262 | void symbol__exit(void); |
263 | void symbol__elf_init(void); | 263 | void symbol__elf_init(void); |
264 | struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name); | 264 | struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name); |
265 | size_t __symbol__fprintf_symname_offs(const struct symbol *sym, | ||
266 | const struct addr_location *al, | ||
267 | bool unknown_as_addr, FILE *fp); | ||
265 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, | 268 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, |
266 | const struct addr_location *al, FILE *fp); | 269 | const struct addr_location *al, FILE *fp); |
270 | size_t __symbol__fprintf_symname(const struct symbol *sym, | ||
271 | const struct addr_location *al, | ||
272 | bool unknown_as_addr, FILE *fp); | ||
267 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp); | 273 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp); |
268 | size_t symbol__fprintf(struct symbol *sym, FILE *fp); | 274 | size_t symbol__fprintf(struct symbol *sym, FILE *fp); |
269 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); | 275 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); |