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