diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-14 14:54:36 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-14 18:46:53 -0400 |
commit | bfbba189b681c86b9ae380358e5f50ce1e33d240 (patch) | |
tree | 8d11b05c2d700ec36fd7d43292edbe955cd6a7fa /tools/perf | |
parent | de446b40d5ddb2c3f1fe453ac405543663f9ac5d (diff) |
perf symbols: Move fprintf routines to separate object file
To disentangle symbol printing from all the code related to symbol
tables, resolution of addresses to symbols, etc.
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-eik9g3hbtdc7ddv57f1d4v3p@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/Build | 1 | ||||
-rw-r--r-- | tools/perf/util/python-ext-sources | 1 | ||||
-rw-r--r-- | tools/perf/util/symbol.c | 71 | ||||
-rw-r--r-- | tools/perf/util/symbol.h | 5 | ||||
-rw-r--r-- | tools/perf/util/symbol_fprintf.c | 71 |
5 files changed, 78 insertions, 71 deletions
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index ea4ac03c1ec8..61021334e958 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build | |||
@@ -29,6 +29,7 @@ libperf-y += usage.o | |||
29 | libperf-y += wrapper.o | 29 | libperf-y += wrapper.o |
30 | libperf-y += dso.o | 30 | libperf-y += dso.o |
31 | libperf-y += symbol.o | 31 | libperf-y += symbol.o |
32 | libperf-y += symbol_fprintf.o | ||
32 | libperf-y += color.o | 33 | libperf-y += color.o |
33 | libperf-y += header.o | 34 | libperf-y += header.o |
34 | libperf-y += callchain.o | 35 | libperf-y += callchain.o |
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index 8162ba0e2e57..36c6862119e3 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources | |||
@@ -23,3 +23,4 @@ util/strlist.c | |||
23 | util/trace-event.c | 23 | util/trace-event.c |
24 | ../lib/rbtree.c | 24 | ../lib/rbtree.c |
25 | util/string.c | 25 | util/string.c |
26 | util/symbol_fprintf.c | ||
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index bb162ee433c6..a36823c3b7c0 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -255,57 +255,6 @@ void symbol__delete(struct symbol *sym) | |||
255 | free(((void *)sym) - symbol_conf.priv_size); | 255 | free(((void *)sym) - symbol_conf.priv_size); |
256 | } | 256 | } |
257 | 257 | ||
258 | size_t symbol__fprintf(struct symbol *sym, FILE *fp) | ||
259 | { | ||
260 | return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n", | ||
261 | sym->start, sym->end, | ||
262 | sym->binding == STB_GLOBAL ? 'g' : | ||
263 | sym->binding == STB_LOCAL ? 'l' : 'w', | ||
264 | sym->name); | ||
265 | } | ||
266 | |||
267 | size_t __symbol__fprintf_symname_offs(const struct symbol *sym, | ||
268 | const struct addr_location *al, | ||
269 | bool unknown_as_addr, FILE *fp) | ||
270 | { | ||
271 | unsigned long offset; | ||
272 | size_t length; | ||
273 | |||
274 | if (sym && sym->name) { | ||
275 | length = fprintf(fp, "%s", sym->name); | ||
276 | if (al) { | ||
277 | if (al->addr < sym->end) | ||
278 | offset = al->addr - sym->start; | ||
279 | else | ||
280 | offset = al->addr - al->map->start - sym->start; | ||
281 | length += fprintf(fp, "+0x%lx", offset); | ||
282 | } | ||
283 | return length; | ||
284 | } else if (al && unknown_as_addr) | ||
285 | return fprintf(fp, "[%#" PRIx64 "]", al->addr); | ||
286 | else | ||
287 | return fprintf(fp, "[unknown]"); | ||
288 | } | ||
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 | |||
304 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp) | ||
305 | { | ||
306 | return __symbol__fprintf_symname_offs(sym, NULL, false, fp); | ||
307 | } | ||
308 | |||
309 | void symbols__delete(struct rb_root *symbols) | 258 | void symbols__delete(struct rb_root *symbols) |
310 | { | 259 | { |
311 | struct symbol *pos; | 260 | struct symbol *pos; |
@@ -381,11 +330,6 @@ static struct symbol *symbols__next(struct symbol *sym) | |||
381 | return NULL; | 330 | return NULL; |
382 | } | 331 | } |
383 | 332 | ||
384 | struct symbol_name_rb_node { | ||
385 | struct rb_node rb_node; | ||
386 | struct symbol sym; | ||
387 | }; | ||
388 | |||
389 | static void symbols__insert_by_name(struct rb_root *symbols, struct symbol *sym) | 333 | static void symbols__insert_by_name(struct rb_root *symbols, struct symbol *sym) |
390 | { | 334 | { |
391 | struct rb_node **p = &symbols->rb_node; | 335 | struct rb_node **p = &symbols->rb_node; |
@@ -514,21 +458,6 @@ void dso__sort_by_name(struct dso *dso, enum map_type type) | |||
514 | &dso->symbols[type]); | 458 | &dso->symbols[type]); |
515 | } | 459 | } |
516 | 460 | ||
517 | size_t dso__fprintf_symbols_by_name(struct dso *dso, | ||
518 | enum map_type type, FILE *fp) | ||
519 | { | ||
520 | size_t ret = 0; | ||
521 | struct rb_node *nd; | ||
522 | struct symbol_name_rb_node *pos; | ||
523 | |||
524 | for (nd = rb_first(&dso->symbol_names[type]); nd; nd = rb_next(nd)) { | ||
525 | pos = rb_entry(nd, struct symbol_name_rb_node, rb_node); | ||
526 | fprintf(fp, "%s\n", pos->sym.name); | ||
527 | } | ||
528 | |||
529 | return ret; | ||
530 | } | ||
531 | |||
532 | int modules__parse(const char *filename, void *arg, | 461 | int modules__parse(const char *filename, void *arg, |
533 | int (*process_module)(void *arg, const char *name, | 462 | int (*process_module)(void *arg, const char *name, |
534 | u64 start)) | 463 | u64 start)) |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index e2562568418d..1da7b101bc7f 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -140,6 +140,11 @@ struct symbol_conf { | |||
140 | 140 | ||
141 | extern struct symbol_conf symbol_conf; | 141 | extern struct symbol_conf symbol_conf; |
142 | 142 | ||
143 | struct symbol_name_rb_node { | ||
144 | struct rb_node rb_node; | ||
145 | struct symbol sym; | ||
146 | }; | ||
147 | |||
143 | static inline int __symbol__join_symfs(char *bf, size_t size, const char *path) | 148 | static inline int __symbol__join_symfs(char *bf, size_t size, const char *path) |
144 | { | 149 | { |
145 | return path__join(bf, size, symbol_conf.symfs, path); | 150 | return path__join(bf, size, symbol_conf.symfs, path); |
diff --git a/tools/perf/util/symbol_fprintf.c b/tools/perf/util/symbol_fprintf.c new file mode 100644 index 000000000000..a680bdaa65dc --- /dev/null +++ b/tools/perf/util/symbol_fprintf.c | |||
@@ -0,0 +1,71 @@ | |||
1 | #include <elf.h> | ||
2 | #include <inttypes.h> | ||
3 | #include <stdio.h> | ||
4 | |||
5 | #include "symbol.h" | ||
6 | |||
7 | size_t symbol__fprintf(struct symbol *sym, FILE *fp) | ||
8 | { | ||
9 | return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n", | ||
10 | sym->start, sym->end, | ||
11 | sym->binding == STB_GLOBAL ? 'g' : | ||
12 | sym->binding == STB_LOCAL ? 'l' : 'w', | ||
13 | sym->name); | ||
14 | } | ||
15 | |||
16 | size_t __symbol__fprintf_symname_offs(const struct symbol *sym, | ||
17 | const struct addr_location *al, | ||
18 | bool unknown_as_addr, FILE *fp) | ||
19 | { | ||
20 | unsigned long offset; | ||
21 | size_t length; | ||
22 | |||
23 | if (sym && sym->name) { | ||
24 | length = fprintf(fp, "%s", sym->name); | ||
25 | if (al) { | ||
26 | if (al->addr < sym->end) | ||
27 | offset = al->addr - sym->start; | ||
28 | else | ||
29 | offset = al->addr - al->map->start - sym->start; | ||
30 | length += fprintf(fp, "+0x%lx", offset); | ||
31 | } | ||
32 | return length; | ||
33 | } else if (al && unknown_as_addr) | ||
34 | return fprintf(fp, "[%#" PRIx64 "]", al->addr); | ||
35 | else | ||
36 | return fprintf(fp, "[unknown]"); | ||
37 | } | ||
38 | |||
39 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, | ||
40 | const struct addr_location *al, | ||
41 | FILE *fp) | ||
42 | { | ||
43 | return __symbol__fprintf_symname_offs(sym, al, false, fp); | ||
44 | } | ||
45 | |||
46 | size_t __symbol__fprintf_symname(const struct symbol *sym, | ||
47 | const struct addr_location *al, | ||
48 | bool unknown_as_addr, FILE *fp) | ||
49 | { | ||
50 | return __symbol__fprintf_symname_offs(sym, al, unknown_as_addr, fp); | ||
51 | } | ||
52 | |||
53 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp) | ||
54 | { | ||
55 | return __symbol__fprintf_symname_offs(sym, NULL, false, fp); | ||
56 | } | ||
57 | |||
58 | size_t dso__fprintf_symbols_by_name(struct dso *dso, | ||
59 | enum map_type type, FILE *fp) | ||
60 | { | ||
61 | size_t ret = 0; | ||
62 | struct rb_node *nd; | ||
63 | struct symbol_name_rb_node *pos; | ||
64 | |||
65 | for (nd = rb_first(&dso->symbol_names[type]); nd; nd = rb_next(nd)) { | ||
66 | pos = rb_entry(nd, struct symbol_name_rb_node, rb_node); | ||
67 | fprintf(fp, "%s\n", pos->sym.name); | ||
68 | } | ||
69 | |||
70 | return ret; | ||
71 | } | ||