Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * builtin-annotate.c |
| 3 | * |
| 4 | * Builtin annotate command: Analyze the perf.data input file, |
| 5 | * look up and read DSOs and symbol information and display |
| 6 | * a histogram of results, along various sorting keys. |
| 7 | */ |
| 8 | #include "builtin.h" |
| 9 | |
| 10 | #include "util/util.h" |
| 11 | |
| 12 | #include "util/color.h" |
Arnaldo Carvalho de Melo | 5da5025 | 2009-07-01 14:46:08 -0300 | [diff] [blame] | 13 | #include <linux/list.h> |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 14 | #include "util/cache.h" |
Arnaldo Carvalho de Melo | 43cbcd8 | 2009-07-01 12:28:37 -0300 | [diff] [blame] | 15 | #include <linux/rbtree.h> |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 16 | #include "util/symbol.h" |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 17 | |
| 18 | #include "perf.h" |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 19 | #include "util/debug.h" |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 20 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 21 | #include "util/event.h" |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 22 | #include "util/parse-options.h" |
| 23 | #include "util/parse-events.h" |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 24 | #include "util/thread.h" |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 25 | #include "util/sort.h" |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 26 | #include "util/hist.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 27 | #include "util/session.h" |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 28 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 29 | static char const *input_name = "perf.data"; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 30 | |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 31 | static bool force; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 32 | |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 33 | static bool full_paths; |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 34 | |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 35 | static bool print_line; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 36 | |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 37 | struct sym_hist { |
| 38 | u64 sum; |
| 39 | u64 ip[0]; |
| 40 | }; |
| 41 | |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 42 | struct sym_ext { |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 43 | struct rb_node node; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 44 | double percent; |
| 45 | char *path; |
| 46 | }; |
| 47 | |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 48 | struct sym_priv { |
| 49 | struct sym_hist *hist; |
| 50 | struct sym_ext *ext; |
| 51 | }; |
| 52 | |
| 53 | static const char *sym_hist_filter; |
| 54 | |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 55 | static int sym__alloc_hist(struct symbol *self) |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 56 | { |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 57 | struct sym_priv *priv = symbol__priv(self); |
| 58 | const int size = (sizeof(*priv->hist) + |
| 59 | (self->end - self->start) * sizeof(u64)); |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 60 | |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 61 | priv->hist = zalloc(size); |
| 62 | return priv->hist == NULL ? -1 : 0; |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 63 | } |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 64 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 65 | /* |
| 66 | * collect histogram counts |
| 67 | */ |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 68 | static int annotate__hist_hit(struct hist_entry *he, u64 ip) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 69 | { |
| 70 | unsigned int sym_size, offset; |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 71 | struct symbol *sym = he->ms.sym; |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 72 | struct sym_priv *priv; |
| 73 | struct sym_hist *h; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 74 | |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 75 | if (!sym || !he->ms.map) |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 76 | return 0; |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 77 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 78 | priv = symbol__priv(sym); |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 79 | if (priv->hist == NULL && sym__alloc_hist(sym) < 0) |
| 80 | return -ENOMEM; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 81 | |
| 82 | sym_size = sym->end - sym->start; |
| 83 | offset = ip - sym->start; |
| 84 | |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 85 | pr_debug3("%s: ip=%#Lx\n", __func__, he->ms.map->unmap_ip(he->ms.map, ip)); |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 86 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 87 | if (offset >= sym_size) |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 88 | return 0; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 89 | |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 90 | h = priv->hist; |
| 91 | h->sum++; |
| 92 | h->ip[offset]++; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 93 | |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 94 | pr_debug3("%#Lx %s: count++ [ip: %#Lx, %#Lx] => %Ld\n", he->ms.sym->start, |
| 95 | he->ms.sym->name, ip, ip - he->ms.sym->start, h->ip[offset]); |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 96 | return 0; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 97 | } |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 98 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame^] | 99 | static int hists__add_entry(struct hists *self, struct addr_location *al) |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 100 | { |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 101 | struct hist_entry *he; |
| 102 | |
| 103 | if (sym_hist_filter != NULL && |
| 104 | (al->sym == NULL || strcmp(sym_hist_filter, al->sym->name) != 0)) { |
| 105 | /* We're only interested in a symbol named sym_hist_filter */ |
| 106 | if (al->sym != NULL) { |
| 107 | rb_erase(&al->sym->rb_node, |
| 108 | &al->map->dso->symbols[al->map->type]); |
| 109 | symbol__delete(al->sym); |
| 110 | } |
| 111 | return 0; |
| 112 | } |
| 113 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame^] | 114 | he = __hists__add_entry(self, al, NULL, 1); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 115 | if (he == NULL) |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 116 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 117 | |
| 118 | return annotate__hist_hit(he, al->addr); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 119 | } |
| 120 | |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 121 | static int process_sample_event(event_t *event, struct perf_session *session) |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 122 | { |
Arnaldo Carvalho de Melo | 1ed091c | 2009-11-27 16:29:23 -0200 | [diff] [blame] | 123 | struct addr_location al; |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 124 | |
Arnaldo Carvalho de Melo | 0d75503 | 2010-01-14 12:23:09 -0200 | [diff] [blame] | 125 | dump_printf("(IP, %d): %d: %#Lx\n", event->header.misc, |
| 126 | event->ip.pid, event->ip.ip); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 127 | |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 128 | if (event__preprocess_sample(event, session, &al, NULL) < 0) { |
Arnaldo Carvalho de Melo | 29a9f66 | 2010-02-03 16:52:06 -0200 | [diff] [blame] | 129 | pr_warning("problem processing %d event, skipping it.\n", |
| 130 | event->header.type); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 131 | return -1; |
| 132 | } |
| 133 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame^] | 134 | if (!al.filtered && hists__add_entry(&session->hists, &al)) { |
Arnaldo Carvalho de Melo | 29a9f66 | 2010-02-03 16:52:06 -0200 | [diff] [blame] | 135 | pr_warning("problem incrementing symbol count, " |
| 136 | "skipping event\n"); |
Arnaldo Carvalho de Melo | ec218fc | 2009-10-03 20:30:48 -0300 | [diff] [blame] | 137 | return -1; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 138 | } |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 143 | struct objdump_line { |
| 144 | struct list_head node; |
| 145 | s64 offset; |
| 146 | char *line; |
| 147 | }; |
| 148 | |
| 149 | static struct objdump_line *objdump_line__new(s64 offset, char *line) |
| 150 | { |
| 151 | struct objdump_line *self = malloc(sizeof(*self)); |
| 152 | |
| 153 | if (self != NULL) { |
| 154 | self->offset = offset; |
| 155 | self->line = line; |
| 156 | } |
| 157 | |
| 158 | return self; |
| 159 | } |
| 160 | |
| 161 | static void objdump_line__free(struct objdump_line *self) |
| 162 | { |
| 163 | free(self->line); |
| 164 | free(self); |
| 165 | } |
| 166 | |
| 167 | static void objdump__add_line(struct list_head *head, struct objdump_line *line) |
| 168 | { |
| 169 | list_add_tail(&line->node, head); |
| 170 | } |
| 171 | |
| 172 | static struct objdump_line *objdump__get_next_ip_line(struct list_head *head, |
| 173 | struct objdump_line *pos) |
| 174 | { |
| 175 | list_for_each_entry_continue(pos, head, node) |
| 176 | if (pos->offset >= 0) |
| 177 | return pos; |
| 178 | |
| 179 | return NULL; |
| 180 | } |
| 181 | |
| 182 | static int parse_line(FILE *file, struct hist_entry *he, |
| 183 | struct list_head *head) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 184 | { |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 185 | struct symbol *sym = he->ms.sym; |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 186 | struct objdump_line *objdump_line; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 187 | char *line = NULL, *tmp, *tmp2; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 188 | size_t line_len; |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 189 | s64 line_ip, offset = -1; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 190 | char *c; |
| 191 | |
| 192 | if (getline(&line, &line_len, file) < 0) |
| 193 | return -1; |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 194 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 195 | if (!line) |
| 196 | return -1; |
| 197 | |
| 198 | c = strchr(line, '\n'); |
| 199 | if (c) |
| 200 | *c = 0; |
| 201 | |
| 202 | line_ip = -1; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * Strip leading spaces: |
| 206 | */ |
| 207 | tmp = line; |
| 208 | while (*tmp) { |
| 209 | if (*tmp != ' ') |
| 210 | break; |
| 211 | tmp++; |
| 212 | } |
| 213 | |
| 214 | if (*tmp) { |
| 215 | /* |
| 216 | * Parse hexa addresses followed by ':' |
| 217 | */ |
| 218 | line_ip = strtoull(tmp, &tmp2, 16); |
| 219 | if (*tmp2 != ':') |
| 220 | line_ip = -1; |
| 221 | } |
| 222 | |
| 223 | if (line_ip != -1) { |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 224 | u64 start = map__rip_2objdump(he->ms.map, sym->start); |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 225 | offset = line_ip - start; |
| 226 | } |
| 227 | |
| 228 | objdump_line = objdump_line__new(offset, line); |
| 229 | if (objdump_line == NULL) { |
| 230 | free(line); |
| 231 | return -1; |
| 232 | } |
| 233 | objdump__add_line(head, objdump_line); |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static int objdump_line__print(struct objdump_line *self, |
| 239 | struct list_head *head, |
| 240 | struct hist_entry *he, u64 len) |
| 241 | { |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 242 | struct symbol *sym = he->ms.sym; |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 243 | static const char *prev_line; |
| 244 | static const char *prev_color; |
| 245 | |
| 246 | if (self->offset != -1) { |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 247 | const char *path = NULL; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 248 | unsigned int hits = 0; |
| 249 | double percent = 0.0; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 250 | const char *color; |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 251 | struct sym_priv *priv = symbol__priv(sym); |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 252 | struct sym_ext *sym_ext = priv->ext; |
| 253 | struct sym_hist *h = priv->hist; |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 254 | s64 offset = self->offset; |
| 255 | struct objdump_line *next = objdump__get_next_ip_line(head, self); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 256 | |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 257 | while (offset < (s64)len && |
| 258 | (next == NULL || offset < next->offset)) { |
| 259 | if (sym_ext) { |
| 260 | if (path == NULL) |
| 261 | path = sym_ext[offset].path; |
| 262 | percent += sym_ext[offset].percent; |
| 263 | } else |
| 264 | hits += h->ip[offset]; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 265 | |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 266 | ++offset; |
| 267 | } |
| 268 | |
| 269 | if (sym_ext == NULL && h->sum) |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 270 | percent = 100.0 * hits / h->sum; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 271 | |
Frederic Weisbecker | 1e11fd8 | 2009-07-02 20:14:34 +0200 | [diff] [blame] | 272 | color = get_percent_color(percent); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 273 | |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 274 | /* |
| 275 | * Also color the filename and line if needed, with |
| 276 | * the same color than the percentage. Don't print it |
| 277 | * twice for close colored ip with the same filename:line |
| 278 | */ |
| 279 | if (path) { |
| 280 | if (!prev_line || strcmp(prev_line, path) |
| 281 | || color != prev_color) { |
| 282 | color_fprintf(stdout, color, " %s", path); |
| 283 | prev_line = path; |
| 284 | prev_color = color; |
| 285 | } |
| 286 | } |
| 287 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 288 | color_fprintf(stdout, color, " %7.2f", percent); |
| 289 | printf(" : "); |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 290 | color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", self->line); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 291 | } else { |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 292 | if (!*self->line) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 293 | printf(" :\n"); |
| 294 | else |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 295 | printf(" : %s\n", self->line); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 301 | static struct rb_root root_sym_ext; |
| 302 | |
| 303 | static void insert_source_line(struct sym_ext *sym_ext) |
| 304 | { |
| 305 | struct sym_ext *iter; |
| 306 | struct rb_node **p = &root_sym_ext.rb_node; |
| 307 | struct rb_node *parent = NULL; |
| 308 | |
| 309 | while (*p != NULL) { |
| 310 | parent = *p; |
| 311 | iter = rb_entry(parent, struct sym_ext, node); |
| 312 | |
| 313 | if (sym_ext->percent > iter->percent) |
| 314 | p = &(*p)->rb_left; |
| 315 | else |
| 316 | p = &(*p)->rb_right; |
| 317 | } |
| 318 | |
| 319 | rb_link_node(&sym_ext->node, parent, p); |
| 320 | rb_insert_color(&sym_ext->node, &root_sym_ext); |
| 321 | } |
| 322 | |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 323 | static void free_source_line(struct hist_entry *he, int len) |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 324 | { |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 325 | struct sym_priv *priv = symbol__priv(he->ms.sym); |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 326 | struct sym_ext *sym_ext = priv->ext; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 327 | int i; |
| 328 | |
| 329 | if (!sym_ext) |
| 330 | return; |
| 331 | |
| 332 | for (i = 0; i < len; i++) |
| 333 | free(sym_ext[i].path); |
| 334 | free(sym_ext); |
| 335 | |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 336 | priv->ext = NULL; |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 337 | root_sym_ext = RB_ROOT; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /* Get the filename:line for the colored entries */ |
Frederic Weisbecker | c17c2db | 2009-06-13 17:39:23 +0200 | [diff] [blame] | 341 | static void |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 342 | get_source_line(struct hist_entry *he, int len, const char *filename) |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 343 | { |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 344 | struct symbol *sym = he->ms.sym; |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 345 | u64 start; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 346 | int i; |
| 347 | char cmd[PATH_MAX * 2]; |
| 348 | struct sym_ext *sym_ext; |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 349 | struct sym_priv *priv = symbol__priv(sym); |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 350 | struct sym_hist *h = priv->hist; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 351 | |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 352 | if (!h->sum) |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 353 | return; |
| 354 | |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 355 | sym_ext = priv->ext = calloc(len, sizeof(struct sym_ext)); |
| 356 | if (!priv->ext) |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 357 | return; |
| 358 | |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 359 | start = he->ms.map->unmap_ip(he->ms.map, sym->start); |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 360 | |
| 361 | for (i = 0; i < len; i++) { |
| 362 | char *path = NULL; |
| 363 | size_t line_len; |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 364 | u64 offset; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 365 | FILE *fp; |
| 366 | |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 367 | sym_ext[i].percent = 100.0 * h->ip[i] / h->sum; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 368 | if (sym_ext[i].percent <= 0.5) |
| 369 | continue; |
| 370 | |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 371 | offset = start + i; |
Frederic Weisbecker | c17c2db | 2009-06-13 17:39:23 +0200 | [diff] [blame] | 372 | sprintf(cmd, "addr2line -e %s %016llx", filename, offset); |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 373 | fp = popen(cmd, "r"); |
| 374 | if (!fp) |
| 375 | continue; |
| 376 | |
| 377 | if (getline(&path, &line_len, fp) < 0 || !line_len) |
| 378 | goto next; |
| 379 | |
Frederic Weisbecker | c17c2db | 2009-06-13 17:39:23 +0200 | [diff] [blame] | 380 | sym_ext[i].path = malloc(sizeof(char) * line_len + 1); |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 381 | if (!sym_ext[i].path) |
| 382 | goto next; |
| 383 | |
| 384 | strcpy(sym_ext[i].path, path); |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 385 | insert_source_line(&sym_ext[i]); |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 386 | |
| 387 | next: |
| 388 | pclose(fp); |
| 389 | } |
| 390 | } |
| 391 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 392 | static void print_summary(const char *filename) |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 393 | { |
| 394 | struct sym_ext *sym_ext; |
| 395 | struct rb_node *node; |
| 396 | |
| 397 | printf("\nSorted summary for file %s\n", filename); |
| 398 | printf("----------------------------------------------\n\n"); |
| 399 | |
| 400 | if (RB_EMPTY_ROOT(&root_sym_ext)) { |
| 401 | printf(" Nothing higher than %1.1f%%\n", MIN_GREEN); |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | node = rb_first(&root_sym_ext); |
| 406 | while (node) { |
| 407 | double percent; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 408 | const char *color; |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 409 | char *path; |
| 410 | |
| 411 | sym_ext = rb_entry(node, struct sym_ext, node); |
| 412 | percent = sym_ext->percent; |
Frederic Weisbecker | 1e11fd8 | 2009-07-02 20:14:34 +0200 | [diff] [blame] | 413 | color = get_percent_color(percent); |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 414 | path = sym_ext->path; |
| 415 | |
| 416 | color_fprintf(stdout, color, " %7.2f %s", percent, path); |
| 417 | node = rb_next(node); |
| 418 | } |
| 419 | } |
| 420 | |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 421 | static void hist_entry__print_hits(struct hist_entry *self) |
| 422 | { |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 423 | struct symbol *sym = self->ms.sym; |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 424 | struct sym_priv *priv = symbol__priv(sym); |
| 425 | struct sym_hist *h = priv->hist; |
| 426 | u64 len = sym->end - sym->start, offset; |
| 427 | |
| 428 | for (offset = 0; offset < len; ++offset) |
| 429 | if (h->ip[offset] != 0) |
| 430 | printf("%*Lx: %Lu\n", BITS_PER_LONG / 2, |
| 431 | sym->start + offset, h->ip[offset]); |
| 432 | printf("%*s: %Lu\n", BITS_PER_LONG / 2, "h->sum", h->sum); |
| 433 | } |
| 434 | |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 435 | static void annotate_sym(struct hist_entry *he) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 436 | { |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 437 | struct map *map = he->ms.map; |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 438 | struct dso *dso = map->dso; |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 439 | struct symbol *sym = he->ms.sym; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 440 | const char *filename = dso->long_name, *d_filename; |
| 441 | u64 len; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 442 | char command[PATH_MAX*2]; |
| 443 | FILE *file; |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 444 | LIST_HEAD(head); |
| 445 | struct objdump_line *pos, *n; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 446 | |
| 447 | if (!filename) |
| 448 | return; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 449 | |
Arnaldo Carvalho de Melo | d06d92b | 2010-03-15 13:04:33 -0300 | [diff] [blame] | 450 | if (dso->origin == DSO__ORIG_KERNEL) { |
| 451 | if (dso->annotate_warned) |
| 452 | return; |
| 453 | dso->annotate_warned = 1; |
| 454 | pr_err("Can't annotate %s: No vmlinux file was found in the " |
| 455 | "path:\n", sym->name); |
| 456 | vmlinux_path__fprintf(stderr); |
| 457 | return; |
| 458 | } |
| 459 | |
Arnaldo Carvalho de Melo | 29a9f66 | 2010-02-03 16:52:06 -0200 | [diff] [blame] | 460 | pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__, |
| 461 | filename, sym->name, map->unmap_ip(map, sym->start), |
| 462 | map->unmap_ip(map, sym->end)); |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 463 | |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 464 | if (full_paths) |
| 465 | d_filename = filename; |
| 466 | else |
| 467 | d_filename = basename(filename); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 468 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 469 | len = sym->end - sym->start; |
| 470 | |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 471 | if (print_line) { |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 472 | get_source_line(he, len, filename); |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 473 | print_summary(filename); |
| 474 | } |
| 475 | |
| 476 | printf("\n\n------------------------------------------------\n"); |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 477 | printf(" Percent | Source code & Disassembly of %s\n", d_filename); |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 478 | printf("------------------------------------------------\n"); |
| 479 | |
| 480 | if (verbose >= 2) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 481 | printf("annotating [%p] %30s : [%p] %30s\n", |
| 482 | dso, dso->long_name, sym, sym->name); |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 483 | |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 484 | sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s", |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 485 | map__rip_2objdump(map, sym->start), |
| 486 | map__rip_2objdump(map, sym->end), |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 487 | filename, filename); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 488 | |
| 489 | if (verbose >= 3) |
| 490 | printf("doing: %s\n", command); |
| 491 | |
| 492 | file = popen(command, "r"); |
| 493 | if (!file) |
| 494 | return; |
| 495 | |
| 496 | while (!feof(file)) { |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 497 | if (parse_line(file, he, &head) < 0) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 498 | break; |
| 499 | } |
| 500 | |
| 501 | pclose(file); |
Arnaldo Carvalho de Melo | 48fb4fd | 2010-02-26 11:23:14 -0300 | [diff] [blame] | 502 | |
| 503 | if (verbose) |
| 504 | hist_entry__print_hits(he); |
| 505 | |
| 506 | list_for_each_entry_safe(pos, n, &head, node) { |
| 507 | objdump_line__print(pos, &head, he, len); |
| 508 | list_del(&pos->node); |
| 509 | objdump_line__free(pos); |
| 510 | } |
| 511 | |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 512 | if (print_line) |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 513 | free_source_line(he, len); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame^] | 516 | static void hists__find_annotations(struct hists *self) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 517 | { |
| 518 | struct rb_node *nd; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 519 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame^] | 520 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 521 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 522 | struct sym_priv *priv; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 523 | |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 524 | if (he->ms.sym == NULL) |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 525 | continue; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 526 | |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 527 | priv = symbol__priv(he->ms.sym); |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 528 | if (priv->hist == NULL) |
| 529 | continue; |
| 530 | |
| 531 | annotate_sym(he); |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 532 | /* |
| 533 | * Since we have a hist_entry per IP for the same symbol, free |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 534 | * he->ms.sym->hist to signal we already processed this symbol. |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 535 | */ |
| 536 | free(priv->hist); |
| 537 | priv->hist = NULL; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 538 | } |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 539 | } |
| 540 | |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 541 | static struct perf_event_ops event_ops = { |
Arnaldo Carvalho de Melo | 55aa640 | 2009-12-27 21:37:05 -0200 | [diff] [blame] | 542 | .sample = process_sample_event, |
| 543 | .mmap = event__process_mmap, |
| 544 | .comm = event__process_comm, |
| 545 | .fork = event__process_task, |
Li Zefan | bab81b6 | 2009-12-01 14:04:49 +0800 | [diff] [blame] | 546 | }; |
| 547 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 548 | static int __cmd_annotate(void) |
| 549 | { |
Li Zefan | bab81b6 | 2009-12-01 14:04:49 +0800 | [diff] [blame] | 550 | int ret; |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 551 | struct perf_session *session; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 552 | |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 553 | session = perf_session__new(input_name, O_RDONLY, force, false); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 554 | if (session == NULL) |
| 555 | return -ENOMEM; |
| 556 | |
Arnaldo Carvalho de Melo | ec91336 | 2009-12-13 19:50:27 -0200 | [diff] [blame] | 557 | ret = perf_session__process_events(session, &event_ops); |
Li Zefan | bab81b6 | 2009-12-01 14:04:49 +0800 | [diff] [blame] | 558 | if (ret) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 559 | goto out_delete; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 560 | |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 561 | if (dump_trace) { |
| 562 | event__print_totals(); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 563 | goto out_delete; |
Arnaldo Carvalho de Melo | 62daacb | 2009-11-27 16:29:22 -0200 | [diff] [blame] | 564 | } |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 565 | |
Arnaldo Carvalho de Melo | da21d1b | 2009-10-07 10:49:00 -0300 | [diff] [blame] | 566 | if (verbose > 3) |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 567 | perf_session__fprintf(session, stdout); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 568 | |
Arnaldo Carvalho de Melo | da21d1b | 2009-10-07 10:49:00 -0300 | [diff] [blame] | 569 | if (verbose > 2) |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 570 | perf_session__fprintf_dsos(session, stdout); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 571 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame^] | 572 | hists__collapse_resort(&session->hists); |
| 573 | hists__output_resort(&session->hists); |
| 574 | hists__find_annotations(&session->hists); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 575 | out_delete: |
| 576 | perf_session__delete(session); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 577 | |
Li Zefan | bab81b6 | 2009-12-01 14:04:49 +0800 | [diff] [blame] | 578 | return ret; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | static const char * const annotate_usage[] = { |
| 582 | "perf annotate [<options>] <command>", |
| 583 | NULL |
| 584 | }; |
| 585 | |
| 586 | static const struct option options[] = { |
| 587 | OPT_STRING('i', "input", &input_name, "file", |
| 588 | "input file name"), |
Arnaldo Carvalho de Melo | ac73c5a | 2010-03-24 16:40:16 -0300 | [diff] [blame] | 589 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", |
| 590 | "only consider symbols in these dsos"), |
Ingo Molnar | 23b8711 | 2009-06-06 21:25:29 +0200 | [diff] [blame] | 591 | OPT_STRING('s', "symbol", &sym_hist_filter, "symbol", |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 592 | "symbol to annotate"), |
Peter Zijlstra | fa6963b | 2009-08-19 11:18:26 +0200 | [diff] [blame] | 593 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 594 | OPT_INCR('v', "verbose", &verbose, |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 595 | "be more verbose (show symbol address, etc)"), |
| 596 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
| 597 | "dump raw trace in ASCII"), |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 598 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, |
| 599 | "file", "vmlinux pathname"), |
| 600 | OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 601 | "load module symbols - WARNING: use only with -k and LIVE kernel"), |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 602 | OPT_BOOLEAN('l', "print-line", &print_line, |
| 603 | "print matching source lines (may be slow)"), |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 604 | OPT_BOOLEAN('P', "full-paths", &full_paths, |
| 605 | "Don't shorten the displayed pathnames"), |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 606 | OPT_END() |
| 607 | }; |
| 608 | |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 609 | int cmd_annotate(int argc, const char **argv, const char *prefix __used) |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 610 | { |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 611 | argc = parse_options(argc, argv, options, annotate_usage, 0); |
| 612 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 613 | symbol_conf.priv_size = sizeof(struct sym_priv); |
| 614 | symbol_conf.try_vmlinux_path = true; |
| 615 | |
| 616 | if (symbol__init() < 0) |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 617 | return -1; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 618 | |
Arnaldo Carvalho de Melo | c8829c7 | 2009-12-14 20:09:29 -0200 | [diff] [blame] | 619 | setup_sorting(annotate_usage, options); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 620 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 621 | if (argc) { |
| 622 | /* |
| 623 | * Special case: if there's an argument left then assume tha |
| 624 | * it's a symbol filter: |
| 625 | */ |
| 626 | if (argc > 1) |
| 627 | usage_with_options(annotate_usage, options); |
| 628 | |
| 629 | sym_hist_filter = argv[0]; |
| 630 | } |
| 631 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 632 | setup_pager(); |
| 633 | |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 634 | if (field_sep && *field_sep == '.') { |
Arnaldo Carvalho de Melo | 29a9f66 | 2010-02-03 16:52:06 -0200 | [diff] [blame] | 635 | pr_err("'.' is the only non valid --field-separator argument\n"); |
| 636 | return -1; |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 637 | } |
| 638 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 639 | return __cmd_annotate(); |
| 640 | } |