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