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 | |
| 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" |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 27 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 28 | static char const *input_name = "perf.data"; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 29 | |
Peter Zijlstra | fa6963b | 2009-08-19 11:18:26 +0200 | [diff] [blame] | 30 | static int force; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 31 | static int input; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 32 | |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 33 | static int full_paths; |
| 34 | |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 35 | static int print_line; |
| 36 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 37 | static unsigned long page_size; |
| 38 | static unsigned long mmap_window = 32; |
| 39 | |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 40 | struct sym_ext { |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 41 | struct rb_node node; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 42 | double percent; |
| 43 | char *path; |
| 44 | }; |
| 45 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 46 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 47 | /* |
| 48 | * collect histogram counts |
| 49 | */ |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 50 | static void hist_hit(struct hist_entry *he, u64 ip) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 51 | { |
| 52 | unsigned int sym_size, offset; |
| 53 | struct symbol *sym = he->sym; |
| 54 | |
| 55 | he->count++; |
| 56 | |
| 57 | if (!sym || !sym->hist) |
| 58 | return; |
| 59 | |
| 60 | sym_size = sym->end - sym->start; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 61 | ip = he->map->map_ip(he->map, ip); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 62 | offset = ip - sym->start; |
| 63 | |
| 64 | if (offset >= sym_size) |
| 65 | return; |
| 66 | |
| 67 | sym->hist_sum++; |
| 68 | sym->hist[offset]++; |
| 69 | |
| 70 | if (verbose >= 3) |
| 71 | printf("%p %s: count++ [ip: %p, %08Lx] => %Ld\n", |
Arjan van de Ven | 7d37a0c | 2009-06-06 20:36:38 +0200 | [diff] [blame] | 72 | (void *)(unsigned long)he->sym->start, |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 73 | he->sym->name, |
Arjan van de Ven | 7d37a0c | 2009-06-06 20:36:38 +0200 | [diff] [blame] | 74 | (void *)(unsigned long)ip, ip - he->sym->start, |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 75 | sym->hist[offset]); |
| 76 | } |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 77 | |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 78 | static int hist_entry__add(struct thread *thread, struct map *map, |
| 79 | struct symbol *sym, u64 ip, u64 count, char level) |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 80 | { |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 81 | bool hit; |
| 82 | struct hist_entry *he = __hist_entry__add(thread, map, sym, NULL, ip, |
| 83 | count, level, &hit); |
| 84 | if (he == NULL) |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 85 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 86 | if (hit) |
| 87 | hist_hit(he, ip); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 88 | return 0; |
| 89 | } |
| 90 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 91 | static int |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 92 | process_sample_event(event_t *event, unsigned long offset, unsigned long head) |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 93 | { |
| 94 | char level; |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 95 | u64 ip = event->ip.ip; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 96 | struct map *map = NULL; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 97 | struct symbol *sym = NULL; |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame^] | 98 | struct thread *thread = threads__findnew(event->ip.pid); |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 99 | |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 100 | dump_printf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n", |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 101 | (void *)(offset + head), |
| 102 | (void *)(long)(event->header.size), |
| 103 | event->header.misc, |
| 104 | event->ip.pid, |
| 105 | (void *)(long)ip); |
| 106 | |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 107 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 108 | |
| 109 | if (thread == NULL) { |
| 110 | fprintf(stderr, "problem processing %d event, skipping it.\n", |
| 111 | event->header.type); |
| 112 | return -1; |
| 113 | } |
| 114 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 115 | if (event->header.misc & PERF_RECORD_MISC_KERNEL) { |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 116 | level = 'k'; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 117 | sym = kernel_maps__find_symbol(ip, &map); |
| 118 | dump_printf(" ...... dso: %s\n", |
| 119 | map ? map->dso->long_name : "<not found>"); |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 120 | } else if (event->header.misc & PERF_RECORD_MISC_USER) { |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 121 | level = '.'; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 122 | map = thread__find_map(thread, ip); |
| 123 | if (map != NULL) { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 124 | got_map: |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 125 | ip = map->map_ip(map, ip); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 126 | sym = map->dso->find_symbol(map->dso, ip); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 127 | } else { |
| 128 | /* |
| 129 | * If this is outside of all known maps, |
| 130 | * and is a negative address, try to look it |
| 131 | * up in the kernel dso, as it might be a |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 132 | * vsyscall or vdso (which executes in user-mode). |
| 133 | * |
| 134 | * XXX This is nasty, we should have a symbol list in |
| 135 | * the "[vdso]" dso, but for now lets use the old |
| 136 | * trick of looking in the whole kernel symbol list. |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 137 | */ |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 138 | if ((long long)ip < 0) { |
| 139 | map = kernel_map; |
| 140 | goto got_map; |
| 141 | } |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 142 | } |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 143 | dump_printf(" ...... dso: %s\n", |
| 144 | map ? map->dso->long_name : "<not found>"); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 145 | } else { |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 146 | level = 'H'; |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 147 | dump_printf(" ...... dso: [hypervisor]\n"); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 148 | } |
| 149 | |
Arnaldo Carvalho de Melo | ec218fc | 2009-10-03 20:30:48 -0300 | [diff] [blame] | 150 | if (hist_entry__add(thread, map, sym, ip, 1, level)) { |
| 151 | fprintf(stderr, "problem incrementing symbol count, " |
| 152 | "skipping event\n"); |
| 153 | return -1; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 154 | } |
| 155 | total++; |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | static int |
| 161 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) |
| 162 | { |
Frederic Weisbecker | 66e274f | 2009-08-12 11:07:25 +0200 | [diff] [blame] | 163 | struct map *map = map__new(&event->mmap, NULL, 0); |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame^] | 164 | struct thread *thread = threads__findnew(event->mmap.pid); |
Frederic Weisbecker | 6baa0a5 | 2009-08-14 12:21:53 +0200 | [diff] [blame] | 165 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 166 | dump_printf("%p [%p]: PERF_RECORD_MMAP %d: [%p(%p) @ %p]: %s\n", |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 167 | (void *)(offset + head), |
| 168 | (void *)(long)(event->header.size), |
| 169 | event->mmap.pid, |
| 170 | (void *)(long)event->mmap.start, |
| 171 | (void *)(long)event->mmap.len, |
| 172 | (void *)(long)event->mmap.pgoff, |
| 173 | event->mmap.filename); |
| 174 | |
| 175 | if (thread == NULL || map == NULL) { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 176 | dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n"); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | thread__insert_map(thread, map); |
| 181 | total_mmap++; |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static int |
| 187 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) |
| 188 | { |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame^] | 189 | struct thread *thread = threads__findnew(event->comm.pid); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 190 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 191 | dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n", |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 192 | (void *)(offset + head), |
| 193 | (void *)(long)(event->header.size), |
| 194 | event->comm.comm, event->comm.pid); |
| 195 | |
| 196 | if (thread == NULL || |
| 197 | thread__set_comm(thread, event->comm.comm)) { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 198 | dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n"); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 199 | return -1; |
| 200 | } |
| 201 | total_comm++; |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | static int |
| 207 | process_fork_event(event_t *event, unsigned long offset, unsigned long head) |
| 208 | { |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame^] | 209 | struct thread *thread = threads__findnew(event->fork.pid); |
| 210 | struct thread *parent = threads__findnew(event->fork.ppid); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 211 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 212 | dump_printf("%p [%p]: PERF_RECORD_FORK: %d:%d\n", |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 213 | (void *)(offset + head), |
| 214 | (void *)(long)(event->header.size), |
| 215 | event->fork.pid, event->fork.ppid); |
| 216 | |
Ingo Molnar | 15f3fa4 | 2009-08-18 13:52:28 +0200 | [diff] [blame] | 217 | /* |
| 218 | * A thread clone will have the same PID for both |
| 219 | * parent and child. |
| 220 | */ |
| 221 | if (thread == parent) |
| 222 | return 0; |
| 223 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 224 | if (!thread || !parent || thread__fork(thread, parent)) { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 225 | dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n"); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 226 | return -1; |
| 227 | } |
| 228 | total_fork++; |
| 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | static int |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 234 | process_event(event_t *event, unsigned long offset, unsigned long head) |
| 235 | { |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 236 | switch (event->header.type) { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 237 | case PERF_RECORD_SAMPLE: |
Peter Zijlstra | e6e18ec | 2009-06-25 11:27:12 +0200 | [diff] [blame] | 238 | return process_sample_event(event, offset, head); |
| 239 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 240 | case PERF_RECORD_MMAP: |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 241 | return process_mmap_event(event, offset, head); |
| 242 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 243 | case PERF_RECORD_COMM: |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 244 | return process_comm_event(event, offset, head); |
| 245 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 246 | case PERF_RECORD_FORK: |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 247 | return process_fork_event(event, offset, head); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 248 | /* |
| 249 | * We dont process them right now but they are fine: |
| 250 | */ |
| 251 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 252 | case PERF_RECORD_THROTTLE: |
| 253 | case PERF_RECORD_UNTHROTTLE: |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 254 | return 0; |
| 255 | |
| 256 | default: |
| 257 | return -1; |
| 258 | } |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 263 | static int |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 264 | parse_line(FILE *file, struct symbol *sym, u64 len) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 265 | { |
| 266 | char *line = NULL, *tmp, *tmp2; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 267 | static const char *prev_line; |
| 268 | static const char *prev_color; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 269 | unsigned int offset; |
| 270 | size_t line_len; |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 271 | s64 line_ip; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 272 | int ret; |
| 273 | char *c; |
| 274 | |
| 275 | if (getline(&line, &line_len, file) < 0) |
| 276 | return -1; |
| 277 | if (!line) |
| 278 | return -1; |
| 279 | |
| 280 | c = strchr(line, '\n'); |
| 281 | if (c) |
| 282 | *c = 0; |
| 283 | |
| 284 | line_ip = -1; |
| 285 | offset = 0; |
| 286 | ret = -2; |
| 287 | |
| 288 | /* |
| 289 | * Strip leading spaces: |
| 290 | */ |
| 291 | tmp = line; |
| 292 | while (*tmp) { |
| 293 | if (*tmp != ' ') |
| 294 | break; |
| 295 | tmp++; |
| 296 | } |
| 297 | |
| 298 | if (*tmp) { |
| 299 | /* |
| 300 | * Parse hexa addresses followed by ':' |
| 301 | */ |
| 302 | line_ip = strtoull(tmp, &tmp2, 16); |
| 303 | if (*tmp2 != ':') |
| 304 | line_ip = -1; |
| 305 | } |
| 306 | |
| 307 | if (line_ip != -1) { |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 308 | const char *path = NULL; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 309 | unsigned int hits = 0; |
| 310 | double percent = 0.0; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 311 | const char *color; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 312 | struct sym_ext *sym_ext = sym->priv; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 313 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 314 | offset = line_ip - sym->start; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 315 | if (offset < len) |
| 316 | hits = sym->hist[offset]; |
| 317 | |
Frederic Weisbecker | c17c2db1 | 2009-06-13 17:39:23 +0200 | [diff] [blame] | 318 | if (offset < len && sym_ext) { |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 319 | path = sym_ext[offset].path; |
| 320 | percent = sym_ext[offset].percent; |
| 321 | } else if (sym->hist_sum) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 322 | percent = 100.0 * hits / sym->hist_sum; |
| 323 | |
Frederic Weisbecker | 1e11fd8 | 2009-07-02 20:14:34 +0200 | [diff] [blame] | 324 | color = get_percent_color(percent); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 325 | |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 326 | /* |
| 327 | * Also color the filename and line if needed, with |
| 328 | * the same color than the percentage. Don't print it |
| 329 | * twice for close colored ip with the same filename:line |
| 330 | */ |
| 331 | if (path) { |
| 332 | if (!prev_line || strcmp(prev_line, path) |
| 333 | || color != prev_color) { |
| 334 | color_fprintf(stdout, color, " %s", path); |
| 335 | prev_line = path; |
| 336 | prev_color = color; |
| 337 | } |
| 338 | } |
| 339 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 340 | color_fprintf(stdout, color, " %7.2f", percent); |
| 341 | printf(" : "); |
| 342 | color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", line); |
| 343 | } else { |
| 344 | if (!*line) |
| 345 | printf(" :\n"); |
| 346 | else |
| 347 | printf(" : %s\n", line); |
| 348 | } |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 353 | static struct rb_root root_sym_ext; |
| 354 | |
| 355 | static void insert_source_line(struct sym_ext *sym_ext) |
| 356 | { |
| 357 | struct sym_ext *iter; |
| 358 | struct rb_node **p = &root_sym_ext.rb_node; |
| 359 | struct rb_node *parent = NULL; |
| 360 | |
| 361 | while (*p != NULL) { |
| 362 | parent = *p; |
| 363 | iter = rb_entry(parent, struct sym_ext, node); |
| 364 | |
| 365 | if (sym_ext->percent > iter->percent) |
| 366 | p = &(*p)->rb_left; |
| 367 | else |
| 368 | p = &(*p)->rb_right; |
| 369 | } |
| 370 | |
| 371 | rb_link_node(&sym_ext->node, parent, p); |
| 372 | rb_insert_color(&sym_ext->node, &root_sym_ext); |
| 373 | } |
| 374 | |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 375 | static void free_source_line(struct symbol *sym, int len) |
| 376 | { |
| 377 | struct sym_ext *sym_ext = sym->priv; |
| 378 | int i; |
| 379 | |
| 380 | if (!sym_ext) |
| 381 | return; |
| 382 | |
| 383 | for (i = 0; i < len; i++) |
| 384 | free(sym_ext[i].path); |
| 385 | free(sym_ext); |
| 386 | |
| 387 | sym->priv = NULL; |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 388 | root_sym_ext = RB_ROOT; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /* Get the filename:line for the colored entries */ |
Frederic Weisbecker | c17c2db1 | 2009-06-13 17:39:23 +0200 | [diff] [blame] | 392 | static void |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 393 | get_source_line(struct symbol *sym, int len, const char *filename) |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 394 | { |
| 395 | int i; |
| 396 | char cmd[PATH_MAX * 2]; |
| 397 | struct sym_ext *sym_ext; |
| 398 | |
| 399 | if (!sym->hist_sum) |
| 400 | return; |
| 401 | |
| 402 | sym->priv = calloc(len, sizeof(struct sym_ext)); |
| 403 | if (!sym->priv) |
| 404 | return; |
| 405 | |
| 406 | sym_ext = sym->priv; |
| 407 | |
| 408 | for (i = 0; i < len; i++) { |
| 409 | char *path = NULL; |
| 410 | size_t line_len; |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 411 | u64 offset; |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 412 | FILE *fp; |
| 413 | |
| 414 | sym_ext[i].percent = 100.0 * sym->hist[i] / sym->hist_sum; |
| 415 | if (sym_ext[i].percent <= 0.5) |
| 416 | continue; |
| 417 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 418 | offset = sym->start + i; |
Frederic Weisbecker | c17c2db1 | 2009-06-13 17:39:23 +0200 | [diff] [blame] | 419 | sprintf(cmd, "addr2line -e %s %016llx", filename, offset); |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 420 | fp = popen(cmd, "r"); |
| 421 | if (!fp) |
| 422 | continue; |
| 423 | |
| 424 | if (getline(&path, &line_len, fp) < 0 || !line_len) |
| 425 | goto next; |
| 426 | |
Frederic Weisbecker | c17c2db1 | 2009-06-13 17:39:23 +0200 | [diff] [blame] | 427 | sym_ext[i].path = malloc(sizeof(char) * line_len + 1); |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 428 | if (!sym_ext[i].path) |
| 429 | goto next; |
| 430 | |
| 431 | strcpy(sym_ext[i].path, path); |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 432 | insert_source_line(&sym_ext[i]); |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 433 | |
| 434 | next: |
| 435 | pclose(fp); |
| 436 | } |
| 437 | } |
| 438 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 439 | static void print_summary(const char *filename) |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 440 | { |
| 441 | struct sym_ext *sym_ext; |
| 442 | struct rb_node *node; |
| 443 | |
| 444 | printf("\nSorted summary for file %s\n", filename); |
| 445 | printf("----------------------------------------------\n\n"); |
| 446 | |
| 447 | if (RB_EMPTY_ROOT(&root_sym_ext)) { |
| 448 | printf(" Nothing higher than %1.1f%%\n", MIN_GREEN); |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | node = rb_first(&root_sym_ext); |
| 453 | while (node) { |
| 454 | double percent; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 455 | const char *color; |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 456 | char *path; |
| 457 | |
| 458 | sym_ext = rb_entry(node, struct sym_ext, node); |
| 459 | percent = sym_ext->percent; |
Frederic Weisbecker | 1e11fd8 | 2009-07-02 20:14:34 +0200 | [diff] [blame] | 460 | color = get_percent_color(percent); |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 461 | path = sym_ext->path; |
| 462 | |
| 463 | color_fprintf(stdout, color, " %7.2f %s", percent, path); |
| 464 | node = rb_next(node); |
| 465 | } |
| 466 | } |
| 467 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 468 | static void annotate_sym(struct dso *dso, struct symbol *sym) |
| 469 | { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 470 | const char *filename = dso->long_name, *d_filename; |
| 471 | u64 len; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 472 | char command[PATH_MAX*2]; |
| 473 | FILE *file; |
| 474 | |
| 475 | if (!filename) |
| 476 | return; |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 477 | |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 478 | if (full_paths) |
| 479 | d_filename = filename; |
| 480 | else |
| 481 | d_filename = basename(filename); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 482 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 483 | len = sym->end - sym->start; |
| 484 | |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 485 | if (print_line) { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 486 | get_source_line(sym, len, filename); |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 487 | print_summary(filename); |
| 488 | } |
| 489 | |
| 490 | printf("\n\n------------------------------------------------\n"); |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 491 | printf(" Percent | Source code & Disassembly of %s\n", d_filename); |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 492 | printf("------------------------------------------------\n"); |
| 493 | |
| 494 | if (verbose >= 2) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 495 | printf("annotating [%p] %30s : [%p] %30s\n", |
| 496 | dso, dso->long_name, sym, sym->name); |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 497 | |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 498 | sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s", |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 499 | sym->start, sym->end, filename, filename); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 500 | |
| 501 | if (verbose >= 3) |
| 502 | printf("doing: %s\n", command); |
| 503 | |
| 504 | file = popen(command, "r"); |
| 505 | if (!file) |
| 506 | return; |
| 507 | |
| 508 | while (!feof(file)) { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 509 | if (parse_line(file, sym, len) < 0) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 510 | break; |
| 511 | } |
| 512 | |
| 513 | pclose(file); |
Frederic Weisbecker | 971738f | 2009-06-13 00:11:22 +0200 | [diff] [blame] | 514 | if (print_line) |
| 515 | free_source_line(sym, len); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static void find_annotations(void) |
| 519 | { |
| 520 | struct rb_node *nd; |
| 521 | struct dso *dso; |
| 522 | int count = 0; |
| 523 | |
| 524 | list_for_each_entry(dso, &dsos, node) { |
| 525 | |
| 526 | for (nd = rb_first(&dso->syms); nd; nd = rb_next(nd)) { |
| 527 | struct symbol *sym = rb_entry(nd, struct symbol, rb_node); |
| 528 | |
| 529 | if (sym->hist) { |
| 530 | annotate_sym(dso, sym); |
| 531 | count++; |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | if (!count) |
| 537 | printf(" Error: symbol '%s' not present amongst the samples.\n", sym_hist_filter); |
| 538 | } |
| 539 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 540 | static int __cmd_annotate(void) |
| 541 | { |
| 542 | int ret, rc = EXIT_FAILURE; |
| 543 | unsigned long offset = 0; |
| 544 | unsigned long head = 0; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 545 | struct stat input_stat; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 546 | event_t *event; |
| 547 | uint32_t size; |
| 548 | char *buf; |
| 549 | |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame^] | 550 | register_idle_thread(); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 551 | |
| 552 | input = open(input_name, O_RDONLY); |
| 553 | if (input < 0) { |
| 554 | perror("failed to open file"); |
| 555 | exit(-1); |
| 556 | } |
| 557 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 558 | ret = fstat(input, &input_stat); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 559 | if (ret < 0) { |
| 560 | perror("failed to stat file"); |
| 561 | exit(-1); |
| 562 | } |
| 563 | |
Pierre Habouzit | 119e7a2 | 2009-08-27 09:59:02 +0200 | [diff] [blame] | 564 | if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) { |
| 565 | fprintf(stderr, "file: %s not owned by current user or root\n", input_name); |
Peter Zijlstra | fa6963b | 2009-08-19 11:18:26 +0200 | [diff] [blame] | 566 | exit(-1); |
| 567 | } |
| 568 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 569 | if (!input_stat.st_size) { |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 570 | fprintf(stderr, "zero-sized file, nothing to do!\n"); |
| 571 | exit(0); |
| 572 | } |
| 573 | |
| 574 | if (load_kernel() < 0) { |
| 575 | perror("failed to load kernel symbols"); |
| 576 | return EXIT_FAILURE; |
| 577 | } |
| 578 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 579 | remap: |
| 580 | buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ, |
| 581 | MAP_SHARED, input, offset); |
| 582 | if (buf == MAP_FAILED) { |
| 583 | perror("failed to mmap file"); |
| 584 | exit(-1); |
| 585 | } |
| 586 | |
| 587 | more: |
| 588 | event = (event_t *)(buf + head); |
| 589 | |
| 590 | size = event->header.size; |
| 591 | if (!size) |
| 592 | size = 8; |
| 593 | |
| 594 | if (head + event->header.size >= page_size * mmap_window) { |
| 595 | unsigned long shift = page_size * (head / page_size); |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 596 | int munmap_ret; |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 597 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 598 | munmap_ret = munmap(buf, page_size * mmap_window); |
| 599 | assert(munmap_ret == 0); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 600 | |
| 601 | offset += shift; |
| 602 | head -= shift; |
| 603 | goto remap; |
| 604 | } |
| 605 | |
| 606 | size = event->header.size; |
| 607 | |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 608 | dump_printf("%p [%p]: event: %d\n", |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 609 | (void *)(offset + head), |
| 610 | (void *)(long)event->header.size, |
| 611 | event->header.type); |
| 612 | |
| 613 | if (!size || process_event(event, offset, head) < 0) { |
| 614 | |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 615 | dump_printf("%p [%p]: skipping unknown header type: %d\n", |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 616 | (void *)(offset + head), |
| 617 | (void *)(long)(event->header.size), |
| 618 | event->header.type); |
| 619 | |
| 620 | total_unknown++; |
| 621 | |
| 622 | /* |
| 623 | * assume we lost track of the stream, check alignment, and |
| 624 | * increment a single u64 in the hope to catch on again 'soon'. |
| 625 | */ |
| 626 | |
| 627 | if (unlikely(head & 7)) |
| 628 | head &= ~7ULL; |
| 629 | |
| 630 | size = 8; |
| 631 | } |
| 632 | |
| 633 | head += size; |
| 634 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 635 | if (offset + head < (unsigned long)input_stat.st_size) |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 636 | goto more; |
| 637 | |
| 638 | rc = EXIT_SUCCESS; |
| 639 | close(input); |
| 640 | |
Frederic Weisbecker | 2cec19d | 2009-08-16 19:24:21 +0200 | [diff] [blame] | 641 | dump_printf(" IP events: %10ld\n", total); |
| 642 | dump_printf(" mmap events: %10ld\n", total_mmap); |
| 643 | dump_printf(" comm events: %10ld\n", total_comm); |
| 644 | dump_printf(" fork events: %10ld\n", total_fork); |
| 645 | dump_printf(" unknown events: %10ld\n", total_unknown); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 646 | |
| 647 | if (dump_trace) |
| 648 | return 0; |
| 649 | |
Arnaldo Carvalho de Melo | da21d1b | 2009-10-07 10:49:00 -0300 | [diff] [blame] | 650 | if (verbose > 3) |
Arnaldo Carvalho de Melo | d5b889f | 2009-10-13 11:16:29 -0300 | [diff] [blame^] | 651 | threads__fprintf(stdout); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 652 | |
Arnaldo Carvalho de Melo | da21d1b | 2009-10-07 10:49:00 -0300 | [diff] [blame] | 653 | if (verbose > 2) |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 654 | dsos__fprintf(stdout); |
| 655 | |
| 656 | collapse__resort(); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 657 | output__resort(total); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 658 | |
| 659 | find_annotations(); |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 660 | |
| 661 | return rc; |
| 662 | } |
| 663 | |
| 664 | static const char * const annotate_usage[] = { |
| 665 | "perf annotate [<options>] <command>", |
| 666 | NULL |
| 667 | }; |
| 668 | |
| 669 | static const struct option options[] = { |
| 670 | OPT_STRING('i', "input", &input_name, "file", |
| 671 | "input file name"), |
Ingo Molnar | 23b8711 | 2009-06-06 21:25:29 +0200 | [diff] [blame] | 672 | OPT_STRING('s', "symbol", &sym_hist_filter, "symbol", |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 673 | "symbol to annotate"), |
Peter Zijlstra | fa6963b | 2009-08-19 11:18:26 +0200 | [diff] [blame] | 674 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 675 | OPT_BOOLEAN('v', "verbose", &verbose, |
| 676 | "be more verbose (show symbol address, etc)"), |
| 677 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
| 678 | "dump raw trace in ASCII"), |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 679 | OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"), |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 680 | OPT_BOOLEAN('m', "modules", &modules, |
| 681 | "load module symbols - WARNING: use only with -k and LIVE kernel"), |
Frederic Weisbecker | 301406b | 2009-06-13 00:11:21 +0200 | [diff] [blame] | 682 | OPT_BOOLEAN('l', "print-line", &print_line, |
| 683 | "print matching source lines (may be slow)"), |
Mike Galbraith | 4297648 | 2009-07-02 08:09:46 +0200 | [diff] [blame] | 684 | OPT_BOOLEAN('P', "full-paths", &full_paths, |
| 685 | "Don't shorten the displayed pathnames"), |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 686 | OPT_END() |
| 687 | }; |
| 688 | |
| 689 | static void setup_sorting(void) |
| 690 | { |
| 691 | char *tmp, *tok, *str = strdup(sort_order); |
| 692 | |
| 693 | for (tok = strtok_r(str, ", ", &tmp); |
| 694 | tok; tok = strtok_r(NULL, ", ", &tmp)) { |
| 695 | if (sort_dimension__add(tok) < 0) { |
| 696 | error("Unknown --sort key: `%s'", tok); |
| 697 | usage_with_options(annotate_usage, options); |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | free(str); |
| 702 | } |
| 703 | |
Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 704 | int cmd_annotate(int argc, const char **argv, const char *prefix __used) |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 705 | { |
| 706 | symbol__init(); |
| 707 | |
| 708 | page_size = getpagesize(); |
| 709 | |
| 710 | argc = parse_options(argc, argv, options, annotate_usage, 0); |
| 711 | |
| 712 | setup_sorting(); |
| 713 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 714 | if (argc) { |
| 715 | /* |
| 716 | * Special case: if there's an argument left then assume tha |
| 717 | * it's a symbol filter: |
| 718 | */ |
| 719 | if (argc > 1) |
| 720 | usage_with_options(annotate_usage, options); |
| 721 | |
| 722 | sym_hist_filter = argv[0]; |
| 723 | } |
| 724 | |
| 725 | if (!sym_hist_filter) |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 726 | usage_with_options(annotate_usage, options); |
| 727 | |
| 728 | setup_pager(); |
| 729 | |
John Kacur | dd68ada | 2009-09-24 18:02:49 +0200 | [diff] [blame] | 730 | if (field_sep && *field_sep == '.') { |
| 731 | fputs("'.' is the only non valid --field-separator argument\n", |
| 732 | stderr); |
| 733 | exit(129); |
| 734 | } |
| 735 | |
Ingo Molnar | 8035e42 | 2009-06-06 15:19:13 +0200 | [diff] [blame] | 736 | return __cmd_annotate(); |
| 737 | } |