aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/perf_counter/util/symbol.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-06-06 09:48:52 -0400
committerIngo Molnar <mingo@elte.hu>2009-06-06 12:58:31 -0400
commit0b73da3f40128eab6ca2a07508f424029a1edaeb (patch)
tree06c6c2f92bb5dc0b8ae2b03e0fa7320171d6b492 /Documentation/perf_counter/util/symbol.c
parent8035e4288078cb806e7dd6bafe4d3e54d44cab3f (diff)
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>
Diffstat (limited to 'Documentation/perf_counter/util/symbol.c')
-rw-r--r--Documentation/perf_counter/util/symbol.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/Documentation/perf_counter/util/symbol.c b/Documentation/perf_counter/util/symbol.c
index a06bbfba8350..23f4f7b3b83d 100644
--- a/Documentation/perf_counter/util/symbol.c
+++ b/Documentation/perf_counter/util/symbol.c
@@ -7,21 +7,36 @@
7#include <gelf.h> 7#include <gelf.h>
8#include <elf.h> 8#include <elf.h>
9 9
10const char *sym_hist_filter;
11
10static struct symbol *symbol__new(uint64_t start, uint64_t len, 12static struct symbol *symbol__new(uint64_t start, uint64_t len,
11 const char *name, unsigned int priv_size) 13 const char *name, unsigned int priv_size,
14 uint64_t obj_start, int verbose)
12{ 15{
13 size_t namelen = strlen(name) + 1; 16 size_t namelen = strlen(name) + 1;
14 struct symbol *self = malloc(priv_size + sizeof(*self) + namelen); 17 struct symbol *self = calloc(1, priv_size + sizeof(*self) + namelen);
15 18
16 if (self != NULL) { 19 if (!self)
17 if (priv_size) { 20 return NULL;
18 memset(self, 0, priv_size); 21
19 self = ((void *)self) + priv_size; 22 if (verbose >= 2)
20 } 23 printf("new symbol: %016Lx [%08lx]: %s, hist: %p, obj_start: %p\n",
21 self->start = start; 24 (__u64)start, len, name, self->hist, (void *)obj_start);
22 self->end = start + len - 1; 25
23 memcpy(self->name, name, namelen); 26 self->obj_start= obj_start;
27 self->hist = NULL;
28 self->hist_sum = 0;
29
30 if (sym_hist_filter && !strcmp(name, sym_hist_filter))
31 self->hist = calloc(sizeof(__u64), len);
32
33 if (priv_size) {
34 memset(self, 0, priv_size);
35 self = ((void *)self) + priv_size;
24 } 36 }
37 self->start = start;
38 self->end = start + len - 1;
39 memcpy(self->name, name, namelen);
25 40
26 return self; 41 return self;
27} 42}
@@ -166,7 +181,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter, int verb
166 * Well fix up the end later, when we have all sorted. 181 * Well fix up the end later, when we have all sorted.
167 */ 182 */
168 sym = symbol__new(start, 0xdead, line + len + 2, 183 sym = symbol__new(start, 0xdead, line + len + 2,
169 self->sym_priv_size); 184 self->sym_priv_size, 0, verbose);
170 185
171 if (sym == NULL) 186 if (sym == NULL)
172 goto out_delete_line; 187 goto out_delete_line;
@@ -272,7 +287,7 @@ static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
272static int dso__synthesize_plt_symbols(struct dso *self, Elf *elf, 287static int dso__synthesize_plt_symbols(struct dso *self, Elf *elf,
273 GElf_Ehdr *ehdr, Elf_Scn *scn_dynsym, 288 GElf_Ehdr *ehdr, Elf_Scn *scn_dynsym,
274 GElf_Shdr *shdr_dynsym, 289 GElf_Shdr *shdr_dynsym,
275 size_t dynsym_idx) 290 size_t dynsym_idx, int verbose)
276{ 291{
277 uint32_t nr_rel_entries, idx; 292 uint32_t nr_rel_entries, idx;
278 GElf_Sym sym; 293 GElf_Sym sym;
@@ -335,7 +350,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, Elf *elf,
335 "%s@plt", elf_sym__name(&sym, symstrs)); 350 "%s@plt", elf_sym__name(&sym, symstrs));
336 351
337 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 352 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
338 sympltname, self->sym_priv_size); 353 sympltname, self->sym_priv_size, 0, verbose);
339 if (!f) 354 if (!f)
340 return -1; 355 return -1;
341 356
@@ -353,7 +368,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, Elf *elf,
353 "%s@plt", elf_sym__name(&sym, symstrs)); 368 "%s@plt", elf_sym__name(&sym, symstrs));
354 369
355 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 370 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
356 sympltname, self->sym_priv_size); 371 sympltname, self->sym_priv_size, 0, verbose);
357 if (!f) 372 if (!f)
358 return -1; 373 return -1;
359 374
@@ -410,7 +425,7 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
410 if (sec_dynsym != NULL) { 425 if (sec_dynsym != NULL) {
411 nr = dso__synthesize_plt_symbols(self, elf, &ehdr, 426 nr = dso__synthesize_plt_symbols(self, elf, &ehdr,
412 sec_dynsym, &shdr, 427 sec_dynsym, &shdr,
413 dynsym_idx); 428 dynsym_idx, verbose);
414 if (nr < 0) 429 if (nr < 0)
415 goto out_elf_end; 430 goto out_elf_end;
416 } 431 }
@@ -444,6 +459,7 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
444 459
445 elf_symtab__for_each_symbol(syms, nr_syms, index, sym) { 460 elf_symtab__for_each_symbol(syms, nr_syms, index, sym) {
446 struct symbol *f; 461 struct symbol *f;
462 uint64_t obj_start;
447 463
448 if (!elf_sym__is_function(&sym)) 464 if (!elf_sym__is_function(&sym))
449 continue; 465 continue;
@@ -453,11 +469,13 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
453 goto out_elf_end; 469 goto out_elf_end;
454 470
455 gelf_getshdr(sec, &shdr); 471 gelf_getshdr(sec, &shdr);
472 obj_start = sym.st_value;
473
456 sym.st_value -= shdr.sh_addr - shdr.sh_offset; 474 sym.st_value -= shdr.sh_addr - shdr.sh_offset;
457 475
458 f = symbol__new(sym.st_value, sym.st_size, 476 f = symbol__new(sym.st_value, sym.st_size,
459 elf_sym__name(&sym, symstrs), 477 elf_sym__name(&sym, symstrs),
460 self->sym_priv_size); 478 self->sym_priv_size, obj_start, verbose);
461 if (!f) 479 if (!f)
462 goto out_elf_end; 480 goto out_elf_end;
463 481