2009-06-06 21:19:13 +08:00
|
|
|
/*
|
|
|
|
* builtin-annotate.c
|
|
|
|
*
|
|
|
|
* Builtin annotate command: Analyze the perf.data input file,
|
|
|
|
* look up and read DSOs and symbol information and display
|
|
|
|
* a histogram of results, along various sorting keys.
|
|
|
|
*/
|
|
|
|
#include "builtin.h"
|
|
|
|
|
|
|
|
#include "util/util.h"
|
|
|
|
|
|
|
|
#include "util/color.h"
|
2009-07-02 01:46:08 +08:00
|
|
|
#include <linux/list.h>
|
2009-06-06 21:19:13 +08:00
|
|
|
#include "util/cache.h"
|
2009-07-01 23:28:37 +08:00
|
|
|
#include <linux/rbtree.h>
|
2009-06-06 21:19:13 +08:00
|
|
|
#include "util/symbol.h"
|
|
|
|
|
|
|
|
#include "perf.h"
|
2009-08-17 04:05:48 +08:00
|
|
|
#include "util/debug.h"
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2009-11-28 02:29:22 +08:00
|
|
|
#include "util/event.h"
|
2009-06-06 21:19:13 +08:00
|
|
|
#include "util/parse-options.h"
|
|
|
|
#include "util/parse-events.h"
|
2009-08-14 18:21:53 +08:00
|
|
|
#include "util/thread.h"
|
2009-09-25 00:02:49 +08:00
|
|
|
#include "util/sort.h"
|
2009-09-28 21:32:55 +08:00
|
|
|
#include "util/hist.h"
|
2009-12-12 07:24:02 +08:00
|
|
|
#include "util/session.h"
|
2009-06-06 21:19:13 +08:00
|
|
|
|
|
|
|
static char const *input_name = "perf.data";
|
|
|
|
|
2010-04-13 16:37:33 +08:00
|
|
|
static bool force;
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2010-04-13 16:37:33 +08:00
|
|
|
static bool full_paths;
|
2009-07-02 14:09:46 +08:00
|
|
|
|
2010-04-13 16:37:33 +08:00
|
|
|
static bool print_line;
|
2009-06-13 06:11:21 +08:00
|
|
|
|
2009-10-21 00:25:40 +08:00
|
|
|
struct sym_hist {
|
|
|
|
u64 sum;
|
|
|
|
u64 ip[0];
|
|
|
|
};
|
|
|
|
|
2009-06-13 06:11:21 +08:00
|
|
|
struct sym_ext {
|
2009-06-13 06:11:22 +08:00
|
|
|
struct rb_node node;
|
2009-06-13 06:11:21 +08:00
|
|
|
double percent;
|
|
|
|
char *path;
|
|
|
|
};
|
|
|
|
|
2009-10-21 00:25:40 +08:00
|
|
|
struct sym_priv {
|
|
|
|
struct sym_hist *hist;
|
|
|
|
struct sym_ext *ext;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *sym_hist_filter;
|
|
|
|
|
2010-02-25 23:57:40 +08:00
|
|
|
static int sym__alloc_hist(struct symbol *self)
|
2009-10-21 00:25:40 +08:00
|
|
|
{
|
2010-02-25 23:57:40 +08:00
|
|
|
struct sym_priv *priv = symbol__priv(self);
|
|
|
|
const int size = (sizeof(*priv->hist) +
|
|
|
|
(self->end - self->start) * sizeof(u64));
|
|
|
|
|
|
|
|
priv->hist = zalloc(size);
|
|
|
|
return priv->hist == NULL ? -1 : 0;
|
2009-10-21 00:25:40 +08:00
|
|
|
}
|
2009-06-06 21:19:13 +08:00
|
|
|
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
/*
|
|
|
|
* collect histogram counts
|
|
|
|
*/
|
2010-02-25 23:57:40 +08:00
|
|
|
static int annotate__hist_hit(struct hist_entry *he, u64 ip)
|
2009-06-06 21:19:13 +08:00
|
|
|
{
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
unsigned int sym_size, offset;
|
2010-03-25 03:40:17 +08:00
|
|
|
struct symbol *sym = he->ms.sym;
|
2009-10-21 00:25:40 +08:00
|
|
|
struct sym_priv *priv;
|
|
|
|
struct sym_hist *h;
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2010-03-25 03:40:17 +08:00
|
|
|
if (!sym || !he->ms.map)
|
2010-02-25 23:57:40 +08:00
|
|
|
return 0;
|
2009-10-21 00:25:40 +08:00
|
|
|
|
2009-10-31 02:28:24 +08:00
|
|
|
priv = symbol__priv(sym);
|
2010-02-25 23:57:40 +08:00
|
|
|
if (priv->hist == NULL && sym__alloc_hist(sym) < 0)
|
|
|
|
return -ENOMEM;
|
2009-06-06 21:19:13 +08:00
|
|
|
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
sym_size = sym->end - sym->start;
|
|
|
|
offset = ip - sym->start;
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2010-03-25 03:40:17 +08:00
|
|
|
pr_debug3("%s: ip=%#Lx\n", __func__, he->ms.map->unmap_ip(he->ms.map, ip));
|
2009-10-20 03:17:57 +08:00
|
|
|
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
if (offset >= sym_size)
|
2010-02-25 23:57:40 +08:00
|
|
|
return 0;
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2009-10-21 00:25:40 +08:00
|
|
|
h = priv->hist;
|
|
|
|
h->sum++;
|
|
|
|
h->ip[offset]++;
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2010-03-25 03:40:17 +08:00
|
|
|
pr_debug3("%#Lx %s: count++ [ip: %#Lx, %#Lx] => %Ld\n", he->ms.sym->start,
|
|
|
|
he->ms.sym->name, ip, ip - he->ms.sym->start, h->ip[offset]);
|
2010-02-25 23:57:40 +08:00
|
|
|
return 0;
|
2009-06-06 21:19:13 +08:00
|
|
|
}
|
|
|
|
|
perf hist: Introduce hists class and move lots of methods to it
In cbbc79a we introduced support for multiple events by introducing a
new "event_stat_id" struct and then made several perf_session methods
receive a point to it instead of a pointer to perf_session, and kept the
event_stats and hists rb_tree in perf_session.
While working on the new newt based browser, I realised that it would be
better to introduce a new class, "hists" (short for "histograms"),
renaming the "event_stat_id" struct and the perf_session methods that
were really "hists" methods, as they manipulate only struct hists
members, not touching anything in the other perf_session members.
Other optimizations, such as calculating the maximum lenght of a symbol
name present in an hists instance will be possible as we add them,
avoiding a re-traversal just for finding that information.
The rationale for the name "hists" to replace "event_stat_id" is that we
may have multiple sets of hists for the same event_stat id, as, for
instance, the 'perf diff' tool has, so event stat id is not what
characterizes what this struct and the functions that manipulate it do.
Cc: Eric B Munson <ebmunson@us.ibm.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-11 00:04:11 +08:00
|
|
|
static int hists__add_entry(struct hists *self, struct addr_location *al)
|
2009-06-06 21:19:13 +08:00
|
|
|
{
|
2010-02-25 23:57:40 +08:00
|
|
|
struct hist_entry *he;
|
|
|
|
|
|
|
|
if (sym_hist_filter != NULL &&
|
|
|
|
(al->sym == NULL || strcmp(sym_hist_filter, al->sym->name) != 0)) {
|
|
|
|
/* We're only interested in a symbol named sym_hist_filter */
|
|
|
|
if (al->sym != NULL) {
|
|
|
|
rb_erase(&al->sym->rb_node,
|
|
|
|
&al->map->dso->symbols[al->map->type]);
|
|
|
|
symbol__delete(al->sym);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
perf hist: Introduce hists class and move lots of methods to it
In cbbc79a we introduced support for multiple events by introducing a
new "event_stat_id" struct and then made several perf_session methods
receive a point to it instead of a pointer to perf_session, and kept the
event_stats and hists rb_tree in perf_session.
While working on the new newt based browser, I realised that it would be
better to introduce a new class, "hists" (short for "histograms"),
renaming the "event_stat_id" struct and the perf_session methods that
were really "hists" methods, as they manipulate only struct hists
members, not touching anything in the other perf_session members.
Other optimizations, such as calculating the maximum lenght of a symbol
name present in an hists instance will be possible as we add them,
avoiding a re-traversal just for finding that information.
The rationale for the name "hists" to replace "event_stat_id" is that we
may have multiple sets of hists for the same event_stat id, as, for
instance, the 'perf diff' tool has, so event stat id is not what
characterizes what this struct and the functions that manipulate it do.
Cc: Eric B Munson <ebmunson@us.ibm.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-11 00:04:11 +08:00
|
|
|
he = __hists__add_entry(self, al, NULL, 1);
|
2009-10-03 21:42:45 +08:00
|
|
|
if (he == NULL)
|
2009-06-06 21:19:13 +08:00
|
|
|
return -ENOMEM;
|
2010-02-25 23:57:40 +08:00
|
|
|
|
|
|
|
return annotate__hist_hit(he, al->addr);
|
2009-06-06 21:19:13 +08:00
|
|
|
}
|
|
|
|
|
2009-12-14 05:50:28 +08:00
|
|
|
static int process_sample_event(event_t *event, struct perf_session *session)
|
2009-06-06 21:19:13 +08:00
|
|
|
{
|
perf tools: Consolidate symbol resolving across all tools
Now we have a very high level routine for simple tools to
process IP sample events:
int event__preprocess_sample(const event_t *self,
struct addr_location *al,
symbol_filter_t filter)
It receives the event itself and will insert new threads in the
global threads list and resolve the map and symbol, filling all
this info into the new addr_location struct, so that tools like
annotate and report can further process the event by creating
hist_entries in their specific way (with or without callgraphs,
etc).
It in turn uses the new next layer function:
void thread__find_addr_location(struct thread *self, u8 cpumode,
enum map_type type, u64 addr,
struct addr_location *al,
symbol_filter_t filter)
This one will, given a thread (userspace or the kernel kthread
one), will find the given type (MAP__FUNCTION now, MAP__VARIABLE
too in the near future) at the given cpumode, taking vdsos into
account (userspace hit, but kernel symbol) and will fill all
these details in the addr_location given.
Tools that need a more compact API for plain function
resolution, like 'kmem', can use this other one:
struct symbol *thread__find_function(struct thread *self, u64 addr,
symbol_filter_t filter)
So, to resolve a kernel symbol, that is all the 'kmem' tool
needs, its just a matter of calling:
sym = thread__find_function(kthread, addr, NULL);
The 'filter' parameter is needed because we do lazy
parsing/loading of ELF symtabs or /proc/kallsyms.
With this we remove more code duplication all around, which is
always good, huh? :-)
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: John Kacur <jkacur@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1259346563-12568-12-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-28 02:29:23 +08:00
|
|
|
struct addr_location al;
|
2009-08-14 18:21:53 +08:00
|
|
|
|
2010-01-14 22:23:09 +08:00
|
|
|
dump_printf("(IP, %d): %d: %#Lx\n", event->header.misc,
|
|
|
|
event->ip.pid, event->ip.ip);
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2010-02-25 23:57:40 +08:00
|
|
|
if (event__preprocess_sample(event, session, &al, NULL) < 0) {
|
2010-02-04 02:52:06 +08:00
|
|
|
pr_warning("problem processing %d event, skipping it.\n",
|
|
|
|
event->header.type);
|
2009-06-06 21:19:13 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
perf hist: Introduce hists class and move lots of methods to it
In cbbc79a we introduced support for multiple events by introducing a
new "event_stat_id" struct and then made several perf_session methods
receive a point to it instead of a pointer to perf_session, and kept the
event_stats and hists rb_tree in perf_session.
While working on the new newt based browser, I realised that it would be
better to introduce a new class, "hists" (short for "histograms"),
renaming the "event_stat_id" struct and the perf_session methods that
were really "hists" methods, as they manipulate only struct hists
members, not touching anything in the other perf_session members.
Other optimizations, such as calculating the maximum lenght of a symbol
name present in an hists instance will be possible as we add them,
avoiding a re-traversal just for finding that information.
The rationale for the name "hists" to replace "event_stat_id" is that we
may have multiple sets of hists for the same event_stat id, as, for
instance, the 'perf diff' tool has, so event stat id is not what
characterizes what this struct and the functions that manipulate it do.
Cc: Eric B Munson <ebmunson@us.ibm.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-11 00:04:11 +08:00
|
|
|
if (!al.filtered && hists__add_entry(&session->hists, &al)) {
|
2010-02-04 02:52:06 +08:00
|
|
|
pr_warning("problem incrementing symbol count, "
|
|
|
|
"skipping event\n");
|
2009-10-04 07:30:48 +08:00
|
|
|
return -1;
|
2009-06-06 21:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
struct objdump_line {
|
|
|
|
struct list_head node;
|
|
|
|
s64 offset;
|
|
|
|
char *line;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct objdump_line *objdump_line__new(s64 offset, char *line)
|
|
|
|
{
|
|
|
|
struct objdump_line *self = malloc(sizeof(*self));
|
|
|
|
|
|
|
|
if (self != NULL) {
|
|
|
|
self->offset = offset;
|
|
|
|
self->line = line;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void objdump_line__free(struct objdump_line *self)
|
|
|
|
{
|
|
|
|
free(self->line);
|
|
|
|
free(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void objdump__add_line(struct list_head *head, struct objdump_line *line)
|
|
|
|
{
|
|
|
|
list_add_tail(&line->node, head);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct objdump_line *objdump__get_next_ip_line(struct list_head *head,
|
|
|
|
struct objdump_line *pos)
|
|
|
|
{
|
|
|
|
list_for_each_entry_continue(pos, head, node)
|
|
|
|
if (pos->offset >= 0)
|
|
|
|
return pos;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_line(FILE *file, struct hist_entry *he,
|
|
|
|
struct list_head *head)
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
{
|
2010-03-25 03:40:17 +08:00
|
|
|
struct symbol *sym = he->ms.sym;
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
struct objdump_line *objdump_line;
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
char *line = NULL, *tmp, *tmp2;
|
|
|
|
size_t line_len;
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
s64 line_ip, offset = -1;
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
char *c;
|
|
|
|
|
|
|
|
if (getline(&line, &line_len, file) < 0)
|
|
|
|
return -1;
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
if (!line)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
c = strchr(line, '\n');
|
|
|
|
if (c)
|
|
|
|
*c = 0;
|
|
|
|
|
|
|
|
line_ip = -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Strip leading spaces:
|
|
|
|
*/
|
|
|
|
tmp = line;
|
|
|
|
while (*tmp) {
|
|
|
|
if (*tmp != ' ')
|
|
|
|
break;
|
|
|
|
tmp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*tmp) {
|
|
|
|
/*
|
|
|
|
* Parse hexa addresses followed by ':'
|
|
|
|
*/
|
|
|
|
line_ip = strtoull(tmp, &tmp2, 16);
|
|
|
|
if (*tmp2 != ':')
|
|
|
|
line_ip = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line_ip != -1) {
|
2010-03-25 03:40:17 +08:00
|
|
|
u64 start = map__rip_2objdump(he->ms.map, sym->start);
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
offset = line_ip - start;
|
|
|
|
}
|
|
|
|
|
|
|
|
objdump_line = objdump_line__new(offset, line);
|
|
|
|
if (objdump_line == NULL) {
|
|
|
|
free(line);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
objdump__add_line(head, objdump_line);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int objdump_line__print(struct objdump_line *self,
|
|
|
|
struct list_head *head,
|
|
|
|
struct hist_entry *he, u64 len)
|
|
|
|
{
|
2010-03-25 03:40:17 +08:00
|
|
|
struct symbol *sym = he->ms.sym;
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
static const char *prev_line;
|
|
|
|
static const char *prev_color;
|
|
|
|
|
|
|
|
if (self->offset != -1) {
|
2009-06-13 06:11:21 +08:00
|
|
|
const char *path = NULL;
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
unsigned int hits = 0;
|
|
|
|
double percent = 0.0;
|
2009-08-15 18:26:57 +08:00
|
|
|
const char *color;
|
2009-10-31 02:28:24 +08:00
|
|
|
struct sym_priv *priv = symbol__priv(sym);
|
2009-10-21 00:25:40 +08:00
|
|
|
struct sym_ext *sym_ext = priv->ext;
|
|
|
|
struct sym_hist *h = priv->hist;
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
s64 offset = self->offset;
|
|
|
|
struct objdump_line *next = objdump__get_next_ip_line(head, self);
|
|
|
|
|
|
|
|
while (offset < (s64)len &&
|
|
|
|
(next == NULL || offset < next->offset)) {
|
|
|
|
if (sym_ext) {
|
|
|
|
if (path == NULL)
|
|
|
|
path = sym_ext[offset].path;
|
|
|
|
percent += sym_ext[offset].percent;
|
|
|
|
} else
|
|
|
|
hits += h->ip[offset];
|
|
|
|
|
|
|
|
++offset;
|
|
|
|
}
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
if (sym_ext == NULL && h->sum)
|
2009-10-21 00:25:40 +08:00
|
|
|
percent = 100.0 * hits / h->sum;
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
|
2009-07-03 02:14:34 +08:00
|
|
|
color = get_percent_color(percent);
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
|
2009-06-13 06:11:21 +08:00
|
|
|
/*
|
|
|
|
* Also color the filename and line if needed, with
|
|
|
|
* the same color than the percentage. Don't print it
|
|
|
|
* twice for close colored ip with the same filename:line
|
|
|
|
*/
|
|
|
|
if (path) {
|
|
|
|
if (!prev_line || strcmp(prev_line, path)
|
|
|
|
|| color != prev_color) {
|
|
|
|
color_fprintf(stdout, color, " %s", path);
|
|
|
|
prev_line = path;
|
|
|
|
prev_color = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
color_fprintf(stdout, color, " %7.2f", percent);
|
|
|
|
printf(" : ");
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", self->line);
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
} else {
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
if (!*self->line)
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
printf(" :\n");
|
|
|
|
else
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
printf(" : %s\n", self->line);
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-13 06:11:22 +08:00
|
|
|
static struct rb_root root_sym_ext;
|
|
|
|
|
|
|
|
static void insert_source_line(struct sym_ext *sym_ext)
|
|
|
|
{
|
|
|
|
struct sym_ext *iter;
|
|
|
|
struct rb_node **p = &root_sym_ext.rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
|
|
|
|
while (*p != NULL) {
|
|
|
|
parent = *p;
|
|
|
|
iter = rb_entry(parent, struct sym_ext, node);
|
|
|
|
|
|
|
|
if (sym_ext->percent > iter->percent)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_link_node(&sym_ext->node, parent, p);
|
|
|
|
rb_insert_color(&sym_ext->node, &root_sym_ext);
|
|
|
|
}
|
|
|
|
|
2009-10-21 00:25:40 +08:00
|
|
|
static void free_source_line(struct hist_entry *he, int len)
|
2009-06-13 06:11:21 +08:00
|
|
|
{
|
2010-03-25 03:40:17 +08:00
|
|
|
struct sym_priv *priv = symbol__priv(he->ms.sym);
|
2009-10-21 00:25:40 +08:00
|
|
|
struct sym_ext *sym_ext = priv->ext;
|
2009-06-13 06:11:21 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!sym_ext)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
free(sym_ext[i].path);
|
|
|
|
free(sym_ext);
|
|
|
|
|
2009-10-21 00:25:40 +08:00
|
|
|
priv->ext = NULL;
|
2009-06-13 06:11:22 +08:00
|
|
|
root_sym_ext = RB_ROOT;
|
2009-06-13 06:11:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the filename:line for the colored entries */
|
2009-06-13 23:39:23 +08:00
|
|
|
static void
|
2009-10-20 03:17:57 +08:00
|
|
|
get_source_line(struct hist_entry *he, int len, const char *filename)
|
2009-06-13 06:11:21 +08:00
|
|
|
{
|
2010-03-25 03:40:17 +08:00
|
|
|
struct symbol *sym = he->ms.sym;
|
2009-10-20 03:17:57 +08:00
|
|
|
u64 start;
|
2009-06-13 06:11:21 +08:00
|
|
|
int i;
|
|
|
|
char cmd[PATH_MAX * 2];
|
|
|
|
struct sym_ext *sym_ext;
|
2009-10-31 02:28:24 +08:00
|
|
|
struct sym_priv *priv = symbol__priv(sym);
|
2009-10-21 00:25:40 +08:00
|
|
|
struct sym_hist *h = priv->hist;
|
2009-06-13 06:11:21 +08:00
|
|
|
|
2009-10-21 00:25:40 +08:00
|
|
|
if (!h->sum)
|
2009-06-13 06:11:21 +08:00
|
|
|
return;
|
|
|
|
|
2009-10-21 00:25:40 +08:00
|
|
|
sym_ext = priv->ext = calloc(len, sizeof(struct sym_ext));
|
|
|
|
if (!priv->ext)
|
2009-06-13 06:11:21 +08:00
|
|
|
return;
|
|
|
|
|
2010-03-25 03:40:17 +08:00
|
|
|
start = he->ms.map->unmap_ip(he->ms.map, sym->start);
|
2009-06-13 06:11:21 +08:00
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
char *path = NULL;
|
|
|
|
size_t line_len;
|
perf_counter tools: Define and use our own u64, s64 etc. definitions
On 64-bit powerpc, __u64 is defined to be unsigned long rather than
unsigned long long. This causes compiler warnings every time we
print a __u64 value with %Lx.
Rather than changing __u64, we define our own u64 to be unsigned long
long on all architectures, and similarly s64 as signed long long.
For consistency we also define u32, s32, u16, s16, u8 and s8. These
definitions are put in a new header, types.h, because these definitions
are needed in util/string.h and util/symbol.h.
The main change here is the mechanical change of __[us]{64,32,16,8}
to remove the "__". The other changes are:
* Create types.h
* Include types.h in perf.h, util/string.h and util/symbol.h
* Add types.h to the LIB_H definition in Makefile
* Added (u64) casts in process_overflow_event() and print_sym_table()
to kill two remaining warnings.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: benh@kernel.crashing.org
LKML-Reference: <19003.33494.495844.956580@cargo.ozlabs.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-06-19 20:21:42 +08:00
|
|
|
u64 offset;
|
2009-06-13 06:11:21 +08:00
|
|
|
FILE *fp;
|
|
|
|
|
2009-10-21 00:25:40 +08:00
|
|
|
sym_ext[i].percent = 100.0 * h->ip[i] / h->sum;
|
2009-06-13 06:11:21 +08:00
|
|
|
if (sym_ext[i].percent <= 0.5)
|
|
|
|
continue;
|
|
|
|
|
2009-10-20 03:17:57 +08:00
|
|
|
offset = start + i;
|
2009-06-13 23:39:23 +08:00
|
|
|
sprintf(cmd, "addr2line -e %s %016llx", filename, offset);
|
2009-06-13 06:11:21 +08:00
|
|
|
fp = popen(cmd, "r");
|
|
|
|
if (!fp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (getline(&path, &line_len, fp) < 0 || !line_len)
|
|
|
|
goto next;
|
|
|
|
|
2009-06-13 23:39:23 +08:00
|
|
|
sym_ext[i].path = malloc(sizeof(char) * line_len + 1);
|
2009-06-13 06:11:21 +08:00
|
|
|
if (!sym_ext[i].path)
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
strcpy(sym_ext[i].path, path);
|
2009-06-13 06:11:22 +08:00
|
|
|
insert_source_line(&sym_ext[i]);
|
2009-06-13 06:11:21 +08:00
|
|
|
|
|
|
|
next:
|
|
|
|
pclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-15 18:26:57 +08:00
|
|
|
static void print_summary(const char *filename)
|
2009-06-13 06:11:22 +08:00
|
|
|
{
|
|
|
|
struct sym_ext *sym_ext;
|
|
|
|
struct rb_node *node;
|
|
|
|
|
|
|
|
printf("\nSorted summary for file %s\n", filename);
|
|
|
|
printf("----------------------------------------------\n\n");
|
|
|
|
|
|
|
|
if (RB_EMPTY_ROOT(&root_sym_ext)) {
|
|
|
|
printf(" Nothing higher than %1.1f%%\n", MIN_GREEN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = rb_first(&root_sym_ext);
|
|
|
|
while (node) {
|
|
|
|
double percent;
|
2009-08-15 18:26:57 +08:00
|
|
|
const char *color;
|
2009-06-13 06:11:22 +08:00
|
|
|
char *path;
|
|
|
|
|
|
|
|
sym_ext = rb_entry(node, struct sym_ext, node);
|
|
|
|
percent = sym_ext->percent;
|
2009-07-03 02:14:34 +08:00
|
|
|
color = get_percent_color(percent);
|
2009-06-13 06:11:22 +08:00
|
|
|
path = sym_ext->path;
|
|
|
|
|
|
|
|
color_fprintf(stdout, color, " %7.2f %s", percent, path);
|
|
|
|
node = rb_next(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
static void hist_entry__print_hits(struct hist_entry *self)
|
|
|
|
{
|
2010-03-25 03:40:17 +08:00
|
|
|
struct symbol *sym = self->ms.sym;
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
struct sym_priv *priv = symbol__priv(sym);
|
|
|
|
struct sym_hist *h = priv->hist;
|
|
|
|
u64 len = sym->end - sym->start, offset;
|
|
|
|
|
|
|
|
for (offset = 0; offset < len; ++offset)
|
|
|
|
if (h->ip[offset] != 0)
|
|
|
|
printf("%*Lx: %Lu\n", BITS_PER_LONG / 2,
|
|
|
|
sym->start + offset, h->ip[offset]);
|
|
|
|
printf("%*s: %Lu\n", BITS_PER_LONG / 2, "h->sum", h->sum);
|
|
|
|
}
|
|
|
|
|
2009-10-20 03:17:57 +08:00
|
|
|
static void annotate_sym(struct hist_entry *he)
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
{
|
2010-03-25 03:40:17 +08:00
|
|
|
struct map *map = he->ms.map;
|
2009-10-20 03:17:57 +08:00
|
|
|
struct dso *dso = map->dso;
|
2010-03-25 03:40:17 +08:00
|
|
|
struct symbol *sym = he->ms.sym;
|
2009-10-02 14:29:58 +08:00
|
|
|
const char *filename = dso->long_name, *d_filename;
|
|
|
|
u64 len;
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
char command[PATH_MAX*2];
|
|
|
|
FILE *file;
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
LIST_HEAD(head);
|
|
|
|
struct objdump_line *pos, *n;
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
return;
|
2009-10-02 14:29:58 +08:00
|
|
|
|
2010-03-16 00:04:33 +08:00
|
|
|
if (dso->origin == DSO__ORIG_KERNEL) {
|
|
|
|
if (dso->annotate_warned)
|
|
|
|
return;
|
|
|
|
dso->annotate_warned = 1;
|
|
|
|
pr_err("Can't annotate %s: No vmlinux file was found in the "
|
|
|
|
"path:\n", sym->name);
|
|
|
|
vmlinux_path__fprintf(stderr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-04 02:52:06 +08:00
|
|
|
pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__,
|
|
|
|
filename, sym->name, map->unmap_ip(map, sym->start),
|
|
|
|
map->unmap_ip(map, sym->end));
|
2009-10-20 03:17:57 +08:00
|
|
|
|
2009-07-02 14:09:46 +08:00
|
|
|
if (full_paths)
|
|
|
|
d_filename = filename;
|
|
|
|
else
|
|
|
|
d_filename = basename(filename);
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
|
|
|
|
len = sym->end - sym->start;
|
|
|
|
|
2009-06-13 06:11:22 +08:00
|
|
|
if (print_line) {
|
2009-10-20 03:17:57 +08:00
|
|
|
get_source_line(he, len, filename);
|
2009-06-13 06:11:22 +08:00
|
|
|
print_summary(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n\n------------------------------------------------\n");
|
2009-07-02 14:09:46 +08:00
|
|
|
printf(" Percent | Source code & Disassembly of %s\n", d_filename);
|
2009-06-13 06:11:22 +08:00
|
|
|
printf("------------------------------------------------\n");
|
|
|
|
|
|
|
|
if (verbose >= 2)
|
2009-10-02 14:29:58 +08:00
|
|
|
printf("annotating [%p] %30s : [%p] %30s\n",
|
|
|
|
dso, dso->long_name, sym, sym->name);
|
2009-06-13 06:11:21 +08:00
|
|
|
|
2009-07-02 14:09:46 +08:00
|
|
|
sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s",
|
perf annotate: Fix it for non-prelinked *.so
The problem was we were incorrectly calculating objdump
addresses for sym->start and sym->end, look:
For simple ET_DYN type DSO (*.so) with one function, objdump -dS
output is something like this:
000004ac <my_strlen>:
int my_strlen(const char *s)
4ac: 55 push %ebp
4ad: 89 e5 mov %esp,%ebp
4af: 83 ec 10 sub $0x10,%esp
{
i.e. we have relative-to-dso-mapping IPs (=RIP) there.
For ET_EXEC type and probably for prelinked libs as well (sorry
can't test - I don't use prelink) objdump outputs absolute IPs,
e.g.
08048604 <zz_strlen>:
extern "C"
int zz_strlen(const char *s)
8048604: 55 push %ebp
8048605: 89 e5 mov %esp,%ebp
8048607: 83 ec 10 sub $0x10,%esp
{
So, if sym->start is always relative to dso mapping(*), we'll
have to unmap it for ET_EXEC like cases, and leave as is for
ET_DYN cases.
(*) and it is - we've explicitely made it relative. Look for
adjust_symbols handling in dso__load_sym()
Previously we were always unmapping sym->start and for ET_DYN
dsos resulting addresses were wrong, and so objdump output was
empty.
The end result was that perf annotate output for symbols from
non-prelinked *.so had always 0.00% percents only, which is
wrong.
To fix it, let's introduce a helper for converting rip to
objdump address, and also let's document what map_ip() and
unmap_ip() do -- I had to study sources for several hours to
understand it.
Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
LKML-Reference: <1265223128-11786-8-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-04 02:52:07 +08:00
|
|
|
map__rip_2objdump(map, sym->start),
|
|
|
|
map__rip_2objdump(map, sym->end),
|
2009-10-20 03:17:57 +08:00
|
|
|
filename, filename);
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
|
|
|
|
if (verbose >= 3)
|
|
|
|
printf("doing: %s\n", command);
|
|
|
|
|
|
|
|
file = popen(command, "r");
|
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (!feof(file)) {
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
if (parse_line(file, he, &head) < 0)
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pclose(file);
|
perf annotate: Handle samples not at objdump output addr boundaries
Without this patch we get this for need_resched:
[root@mica ~]# perf annotate need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
0.00 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
0.00 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
But from the 'perf report' result we know that there are hits
for need_resched on a 4 way machine mostly doing nothing, so
after adding code to show what is in each hist offset and
collapsing IP hits for what happens between objdump lines we
get, for the same perf.data file:
[root@mica ~]# perf annotate -v need_resched
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
:
:
: Disassembly of section .text:
:
: ffffffff810095ed <need_resched>:
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095ed: 55 push %rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
52.78 : ffffffff810095ee: be 03 00 00 00 mov $0x3,%esi
:
: static inline struct thread_info *current_thread_info(void)
: {
: struct thread_info *ti;
: ti = (void *)(percpu_read_stable(kernel_stack) +
0.00 : ffffffff810095f3: 65 48 8b 3c 25 48 b5 mov %gs:0xb548,%rdi
0.00 : ffffffff810095fa: 00 00
: return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
: }
:
: static inline int need_resched(void)
: {
0.00 : ffffffff810095fc: 48 89 e5 mov %rsp,%rbp
: return unlikely(test_thread_flag(TIF_NEED_RESCHED));
9.72 : ffffffff810095ff: 48 81 ef d8 1f 00 00 sub $0x1fd8,%rdi
0.00 : ffffffff81009606: e8 9d ff ff ff callq ffffffff810095a8 <test_ti_thread_flag>
: }
0.00 : ffffffff8100960b: c9 leaveq
0.00 : ffffffff8100960c: 85 c0 test %eax,%eax
37.50 : ffffffff8100960e: 0f 95 c0 setne %al
0.00 : ffffffff81009611: 0f b6 c0 movzbl %al,%eax
: Disassembly of section .vsyscall_0:
: Disassembly of section .vsyscall_fn:
: Disassembly of section .vsyscall_1:
: Disassembly of section .vsyscall_2:
: Disassembly of section .init.text:
: Disassembly of section .altinstr_replacement:
: Disassembly of section .exit.text:
[root@mica ~]#
And now 'perf annotate -v', verbose mode, will show the hits per
precise IP, so that one can make sense of the attribution to
each objdumop line:
[root@mica ~]# perf annotate -v need_resched
Looking at the vmlinux_path (5 entries long)
Using /lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux
for symbols annotate_sym: filename=/lib/modules/2.6.33-rc8-tip-00784-g3471df5-dirty/build/vmlinux, sym=need_resched, start=0xffffffff810095ed, end=0xffffffff81009614
------------------------------------------------
Percent | Source code & Disassembly of vmlinux
------------------------------------------------
ffffffff810095f1: 152
ffffffff81009603: 28
ffffffff8100960f: 55
ffffffff81009610: 53
h->sum: 288
<SNIP same annotation>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1267194194-15670-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-02-26 22:23:14 +08:00
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
hist_entry__print_hits(he);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(pos, n, &head, node) {
|
|
|
|
objdump_line__print(pos, &head, he, len);
|
|
|
|
list_del(&pos->node);
|
|
|
|
objdump_line__free(pos);
|
|
|
|
}
|
|
|
|
|
2009-06-13 06:11:22 +08:00
|
|
|
if (print_line)
|
2009-10-21 00:25:40 +08:00
|
|
|
free_source_line(he, len);
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
}
|
|
|
|
|
perf hist: Introduce hists class and move lots of methods to it
In cbbc79a we introduced support for multiple events by introducing a
new "event_stat_id" struct and then made several perf_session methods
receive a point to it instead of a pointer to perf_session, and kept the
event_stats and hists rb_tree in perf_session.
While working on the new newt based browser, I realised that it would be
better to introduce a new class, "hists" (short for "histograms"),
renaming the "event_stat_id" struct and the perf_session methods that
were really "hists" methods, as they manipulate only struct hists
members, not touching anything in the other perf_session members.
Other optimizations, such as calculating the maximum lenght of a symbol
name present in an hists instance will be possible as we add them,
avoiding a re-traversal just for finding that information.
The rationale for the name "hists" to replace "event_stat_id" is that we
may have multiple sets of hists for the same event_stat id, as, for
instance, the 'perf diff' tool has, so event stat id is not what
characterizes what this struct and the functions that manipulate it do.
Cc: Eric B Munson <ebmunson@us.ibm.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-11 00:04:11 +08:00
|
|
|
static void hists__find_annotations(struct hists *self)
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
|
perf hist: Introduce hists class and move lots of methods to it
In cbbc79a we introduced support for multiple events by introducing a
new "event_stat_id" struct and then made several perf_session methods
receive a point to it instead of a pointer to perf_session, and kept the
event_stats and hists rb_tree in perf_session.
While working on the new newt based browser, I realised that it would be
better to introduce a new class, "hists" (short for "histograms"),
renaming the "event_stat_id" struct and the perf_session methods that
were really "hists" methods, as they manipulate only struct hists
members, not touching anything in the other perf_session members.
Other optimizations, such as calculating the maximum lenght of a symbol
name present in an hists instance will be possible as we add them,
avoiding a re-traversal just for finding that information.
The rationale for the name "hists" to replace "event_stat_id" is that we
may have multiple sets of hists for the same event_stat id, as, for
instance, the 'perf diff' tool has, so event stat id is not what
characterizes what this struct and the functions that manipulate it do.
Cc: Eric B Munson <ebmunson@us.ibm.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-11 00:04:11 +08:00
|
|
|
for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
|
2009-10-20 03:17:57 +08:00
|
|
|
struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
|
2009-10-21 00:25:40 +08:00
|
|
|
struct sym_priv *priv;
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
|
2010-03-25 03:40:17 +08:00
|
|
|
if (he->ms.sym == NULL)
|
2009-10-21 00:25:40 +08:00
|
|
|
continue;
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
|
2010-03-25 03:40:17 +08:00
|
|
|
priv = symbol__priv(he->ms.sym);
|
2009-10-21 00:25:40 +08:00
|
|
|
if (priv->hist == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
annotate_sym(he);
|
|
|
|
/*
|
|
|
|
* Since we have a hist_entry per IP for the same symbol, free
|
2010-03-25 03:40:17 +08:00
|
|
|
* he->ms.sym->hist to signal we already processed this symbol.
|
2009-10-21 00:25:40 +08:00
|
|
|
*/
|
|
|
|
free(priv->hist);
|
|
|
|
priv->hist = NULL;
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-14 05:50:25 +08:00
|
|
|
static struct perf_event_ops event_ops = {
|
2009-12-28 07:37:05 +08:00
|
|
|
.sample = process_sample_event,
|
|
|
|
.mmap = event__process_mmap,
|
|
|
|
.comm = event__process_comm,
|
|
|
|
.fork = event__process_task,
|
2009-12-01 14:04:49 +08:00
|
|
|
};
|
|
|
|
|
2009-06-06 21:19:13 +08:00
|
|
|
static int __cmd_annotate(void)
|
|
|
|
{
|
2009-12-01 14:04:49 +08:00
|
|
|
int ret;
|
2009-12-16 06:04:39 +08:00
|
|
|
struct perf_session *session;
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2010-05-01 14:41:20 +08:00
|
|
|
session = perf_session__new(input_name, O_RDONLY, force, false);
|
2009-12-12 07:24:02 +08:00
|
|
|
if (session == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2009-12-14 05:50:27 +08:00
|
|
|
ret = perf_session__process_events(session, &event_ops);
|
2009-12-01 14:04:49 +08:00
|
|
|
if (ret)
|
2009-12-12 07:24:02 +08:00
|
|
|
goto out_delete;
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2009-11-28 02:29:22 +08:00
|
|
|
if (dump_trace) {
|
|
|
|
event__print_totals();
|
2009-12-12 07:24:02 +08:00
|
|
|
goto out_delete;
|
2009-11-28 02:29:22 +08:00
|
|
|
}
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2009-10-07 21:49:00 +08:00
|
|
|
if (verbose > 3)
|
2009-12-14 05:50:28 +08:00
|
|
|
perf_session__fprintf(session, stdout);
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2009-10-07 21:49:00 +08:00
|
|
|
if (verbose > 2)
|
2010-04-28 08:22:44 +08:00
|
|
|
perf_session__fprintf_dsos(session, stdout);
|
2009-06-06 21:19:13 +08:00
|
|
|
|
perf hist: Introduce hists class and move lots of methods to it
In cbbc79a we introduced support for multiple events by introducing a
new "event_stat_id" struct and then made several perf_session methods
receive a point to it instead of a pointer to perf_session, and kept the
event_stats and hists rb_tree in perf_session.
While working on the new newt based browser, I realised that it would be
better to introduce a new class, "hists" (short for "histograms"),
renaming the "event_stat_id" struct and the perf_session methods that
were really "hists" methods, as they manipulate only struct hists
members, not touching anything in the other perf_session members.
Other optimizations, such as calculating the maximum lenght of a symbol
name present in an hists instance will be possible as we add them,
avoiding a re-traversal just for finding that information.
The rationale for the name "hists" to replace "event_stat_id" is that we
may have multiple sets of hists for the same event_stat id, as, for
instance, the 'perf diff' tool has, so event stat id is not what
characterizes what this struct and the functions that manipulate it do.
Cc: Eric B Munson <ebmunson@us.ibm.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-05-11 00:04:11 +08:00
|
|
|
hists__collapse_resort(&session->hists);
|
|
|
|
hists__output_resort(&session->hists);
|
|
|
|
hists__find_annotations(&session->hists);
|
2009-12-12 07:24:02 +08:00
|
|
|
out_delete:
|
|
|
|
perf_session__delete(session);
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2009-12-01 14:04:49 +08:00
|
|
|
return ret;
|
2009-06-06 21:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char * const annotate_usage[] = {
|
|
|
|
"perf annotate [<options>] <command>",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct option options[] = {
|
|
|
|
OPT_STRING('i', "input", &input_name, "file",
|
|
|
|
"input file name"),
|
2010-03-25 03:40:16 +08:00
|
|
|
OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
|
|
|
|
"only consider symbols in these dsos"),
|
2009-06-07 03:25:29 +08:00
|
|
|
OPT_STRING('s', "symbol", &sym_hist_filter, "symbol",
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
"symbol to annotate"),
|
2009-08-19 17:18:26 +08:00
|
|
|
OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
|
2010-04-13 16:37:33 +08:00
|
|
|
OPT_INCR('v', "verbose", &verbose,
|
2009-06-06 21:19:13 +08:00
|
|
|
"be more verbose (show symbol address, etc)"),
|
|
|
|
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
|
|
|
|
"dump raw trace in ASCII"),
|
2009-11-24 22:05:15 +08:00
|
|
|
OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
|
|
|
|
"file", "vmlinux pathname"),
|
|
|
|
OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
|
2009-07-02 14:09:46 +08:00
|
|
|
"load module symbols - WARNING: use only with -k and LIVE kernel"),
|
2009-06-13 06:11:21 +08:00
|
|
|
OPT_BOOLEAN('l', "print-line", &print_line,
|
|
|
|
"print matching source lines (may be slow)"),
|
2009-07-02 14:09:46 +08:00
|
|
|
OPT_BOOLEAN('P', "full-paths", &full_paths,
|
|
|
|
"Don't shorten the displayed pathnames"),
|
2009-06-06 21:19:13 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2009-07-01 18:37:06 +08:00
|
|
|
int cmd_annotate(int argc, const char **argv, const char *prefix __used)
|
2009-06-06 21:19:13 +08:00
|
|
|
{
|
2009-12-16 06:04:40 +08:00
|
|
|
argc = parse_options(argc, argv, options, annotate_usage, 0);
|
|
|
|
|
2009-12-16 06:04:39 +08:00
|
|
|
symbol_conf.priv_size = sizeof(struct sym_priv);
|
|
|
|
symbol_conf.try_vmlinux_path = true;
|
|
|
|
|
|
|
|
if (symbol__init() < 0)
|
2009-11-24 22:05:15 +08:00
|
|
|
return -1;
|
2009-06-06 21:19:13 +08:00
|
|
|
|
2009-12-15 06:09:29 +08:00
|
|
|
setup_sorting(annotate_usage, options);
|
2009-06-06 21:19:13 +08:00
|
|
|
|
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>
2009-06-06 21:48:52 +08:00
|
|
|
if (argc) {
|
|
|
|
/*
|
|
|
|
* Special case: if there's an argument left then assume tha
|
|
|
|
* it's a symbol filter:
|
|
|
|
*/
|
|
|
|
if (argc > 1)
|
|
|
|
usage_with_options(annotate_usage, options);
|
|
|
|
|
|
|
|
sym_hist_filter = argv[0];
|
|
|
|
}
|
|
|
|
|
2009-06-06 21:19:13 +08:00
|
|
|
setup_pager();
|
|
|
|
|
2009-09-25 00:02:49 +08:00
|
|
|
if (field_sep && *field_sep == '.') {
|
2010-02-04 02:52:06 +08:00
|
|
|
pr_err("'.' is the only non valid --field-separator argument\n");
|
|
|
|
return -1;
|
2009-09-25 00:02:49 +08:00
|
|
|
}
|
|
|
|
|
2009-06-06 21:19:13 +08:00
|
|
|
return __cmd_annotate();
|
|
|
|
}
|