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.
10 #include "util/util.h"
12 #include "util/color.h"
13 #include "util/list.h"
14 #include "util/cache.h"
15 #include "util/rbtree.h"
16 #include "util/symbol.h"
17 #include "util/string.h"
21 #include "util/parse-options.h"
22 #include "util/parse-events.h"
28 static char const *input_name = "perf.data";
29 static char *vmlinux = "vmlinux";
31 static char default_sort_order[] = "comm,symbol";
32 static char *sort_order = default_sort_order;
35 static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
37 static int dump_trace = 0;
38 #define dprintf(x...) do { if (dump_trace) printf(x); } while (0)
42 static int print_line;
44 static unsigned long page_size;
45 static unsigned long mmap_window = 32;
48 struct perf_event_header header;
54 struct perf_event_header header;
59 char filename[PATH_MAX];
63 struct perf_event_header header;
69 struct perf_event_header header;
74 struct perf_event_header header;
80 typedef union event_union {
81 struct perf_event_header header;
83 struct mmap_event mmap;
84 struct comm_event comm;
85 struct fork_event fork;
86 struct period_event period;
95 static LIST_HEAD(dsos);
96 static struct dso *kernel_dso;
97 static struct dso *vdso;
100 static void dsos__add(struct dso *dso)
102 list_add_tail(&dso->node, &dsos);
105 static struct dso *dsos__find(const char *name)
109 list_for_each_entry(pos, &dsos, node)
110 if (strcmp(pos->name, name) == 0)
115 static struct dso *dsos__findnew(const char *name)
117 struct dso *dso = dsos__find(name);
123 dso = dso__new(name, 0);
127 nr = dso__load(dso, NULL, verbose);
130 fprintf(stderr, "Failed to open: %s\n", name);
133 if (!nr && verbose) {
135 "No symbols found in: %s, maybe install a debug package?\n",
148 static void dsos__fprintf(FILE *fp)
152 list_for_each_entry(pos, &dsos, node)
153 dso__fprintf(pos, fp);
156 static struct symbol *vdso__find_symbol(struct dso *dso, __u64 ip)
158 return dso__find_symbol(kernel_dso, ip);
161 static int load_kernel(void)
165 kernel_dso = dso__new("[kernel]", 0);
169 err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose);
171 dso__delete(kernel_dso);
174 dsos__add(kernel_dso);
176 vdso = dso__new("[vdso]", 0);
180 vdso->find_symbol = vdso__find_symbol;
188 struct list_head node;
192 __u64 (*map_ip)(struct map *, __u64);
196 static __u64 map__map_ip(struct map *map, __u64 ip)
198 return ip - map->start + map->pgoff;
201 static __u64 vdso__map_ip(struct map *map, __u64 ip)
206 static struct map *map__new(struct mmap_event *event)
208 struct map *self = malloc(sizeof(*self));
211 const char *filename = event->filename;
213 self->start = event->start;
214 self->end = event->start + event->len;
215 self->pgoff = event->pgoff;
217 self->dso = dsos__findnew(filename);
218 if (self->dso == NULL)
221 if (self->dso == vdso)
222 self->map_ip = vdso__map_ip;
224 self->map_ip = map__map_ip;
232 static struct map *map__clone(struct map *self)
234 struct map *map = malloc(sizeof(*self));
239 memcpy(map, self, sizeof(*self));
244 static int map__overlap(struct map *l, struct map *r)
246 if (l->start > r->start) {
252 if (l->end > r->start)
258 static size_t map__fprintf(struct map *self, FILE *fp)
260 return fprintf(fp, " %Lx-%Lx %Lx %s\n",
261 self->start, self->end, self->pgoff, self->dso->name);
266 struct rb_node rb_node;
267 struct list_head maps;
272 static struct thread *thread__new(pid_t pid)
274 struct thread *self = malloc(sizeof(*self));
278 self->comm = malloc(32);
280 snprintf(self->comm, 32, ":%d", self->pid);
281 INIT_LIST_HEAD(&self->maps);
287 static int thread__set_comm(struct thread *self, const char *comm)
291 self->comm = strdup(comm);
292 return self->comm ? 0 : -ENOMEM;
295 static size_t thread__fprintf(struct thread *self, FILE *fp)
298 size_t ret = fprintf(fp, "Thread %d %s\n", self->pid, self->comm);
300 list_for_each_entry(pos, &self->maps, node)
301 ret += map__fprintf(pos, fp);
307 static struct rb_root threads;
308 static struct thread *last_match;
310 static struct thread *threads__findnew(pid_t pid)
312 struct rb_node **p = &threads.rb_node;
313 struct rb_node *parent = NULL;
317 * Font-end cache - PID lookups come in blocks,
318 * so most of the time we dont have to look up
321 if (last_match && last_match->pid == pid)
326 th = rb_entry(parent, struct thread, rb_node);
328 if (th->pid == pid) {
339 th = thread__new(pid);
341 rb_link_node(&th->rb_node, parent, p);
342 rb_insert_color(&th->rb_node, &threads);
349 static void thread__insert_map(struct thread *self, struct map *map)
351 struct map *pos, *tmp;
353 list_for_each_entry_safe(pos, tmp, &self->maps, node) {
354 if (map__overlap(pos, map)) {
355 list_del_init(&pos->node);
361 list_add_tail(&map->node, &self->maps);
364 static int thread__fork(struct thread *self, struct thread *parent)
370 self->comm = strdup(parent->comm);
374 list_for_each_entry(map, &parent->maps, node) {
375 struct map *new = map__clone(map);
378 thread__insert_map(self, new);
384 static struct map *thread__find_map(struct thread *self, __u64 ip)
391 list_for_each_entry(pos, &self->maps, node)
392 if (ip >= pos->start && ip <= pos->end)
398 static size_t threads__fprintf(FILE *fp)
403 for (nd = rb_first(&threads); nd; nd = rb_next(nd)) {
404 struct thread *pos = rb_entry(nd, struct thread, rb_node);
406 ret += thread__fprintf(pos, fp);
413 * histogram, sorted on item, collects counts
416 static struct rb_root hist;
419 struct rb_node rb_node;
421 struct thread *thread;
432 * configurable sorting bits
436 struct list_head list;
440 int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
441 int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
442 size_t (*print)(FILE *fp, struct hist_entry *);
448 sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
450 return right->thread->pid - left->thread->pid;
454 sort__thread_print(FILE *fp, struct hist_entry *self)
456 return fprintf(fp, "%16s:%5d", self->thread->comm ?: "", self->thread->pid);
459 static struct sort_entry sort_thread = {
460 .header = " Command: Pid",
461 .cmp = sort__thread_cmp,
462 .print = sort__thread_print,
468 sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
470 return right->thread->pid - left->thread->pid;
474 sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
476 char *comm_l = left->thread->comm;
477 char *comm_r = right->thread->comm;
479 if (!comm_l || !comm_r) {
480 if (!comm_l && !comm_r)
488 return strcmp(comm_l, comm_r);
492 sort__comm_print(FILE *fp, struct hist_entry *self)
494 return fprintf(fp, "%16s", self->thread->comm);
497 static struct sort_entry sort_comm = {
498 .header = " Command",
499 .cmp = sort__comm_cmp,
500 .collapse = sort__comm_collapse,
501 .print = sort__comm_print,
507 sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
509 struct dso *dso_l = left->dso;
510 struct dso *dso_r = right->dso;
512 if (!dso_l || !dso_r) {
513 if (!dso_l && !dso_r)
521 return strcmp(dso_l->name, dso_r->name);
525 sort__dso_print(FILE *fp, struct hist_entry *self)
528 return fprintf(fp, "%-25s", self->dso->name);
530 return fprintf(fp, "%016llx ", (__u64)self->ip);
533 static struct sort_entry sort_dso = {
534 .header = "Shared Object ",
535 .cmp = sort__dso_cmp,
536 .print = sort__dso_print,
542 sort__sym_cmp(struct hist_entry *left, struct hist_entry *right)
546 if (left->sym == right->sym)
549 ip_l = left->sym ? left->sym->start : left->ip;
550 ip_r = right->sym ? right->sym->start : right->ip;
552 return (int64_t)(ip_r - ip_l);
556 sort__sym_print(FILE *fp, struct hist_entry *self)
561 ret += fprintf(fp, "%#018llx ", (__u64)self->ip);
564 ret += fprintf(fp, "[%c] %s",
565 self->dso == kernel_dso ? 'k' : '.', self->sym->name);
567 ret += fprintf(fp, "%#016llx", (__u64)self->ip);
573 static struct sort_entry sort_sym = {
575 .cmp = sort__sym_cmp,
576 .print = sort__sym_print,
579 static int sort__need_collapse = 0;
581 struct sort_dimension {
583 struct sort_entry *entry;
587 static struct sort_dimension sort_dimensions[] = {
588 { .name = "pid", .entry = &sort_thread, },
589 { .name = "comm", .entry = &sort_comm, },
590 { .name = "dso", .entry = &sort_dso, },
591 { .name = "symbol", .entry = &sort_sym, },
594 static LIST_HEAD(hist_entry__sort_list);
596 static int sort_dimension__add(char *tok)
600 for (i = 0; i < ARRAY_SIZE(sort_dimensions); i++) {
601 struct sort_dimension *sd = &sort_dimensions[i];
606 if (strncasecmp(tok, sd->name, strlen(tok)))
609 if (sd->entry->collapse)
610 sort__need_collapse = 1;
612 list_add_tail(&sd->entry->list, &hist_entry__sort_list);
622 hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
624 struct sort_entry *se;
627 list_for_each_entry(se, &hist_entry__sort_list, list) {
628 cmp = se->cmp(left, right);
637 hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
639 struct sort_entry *se;
642 list_for_each_entry(se, &hist_entry__sort_list, list) {
643 int64_t (*f)(struct hist_entry *, struct hist_entry *);
645 f = se->collapse ?: se->cmp;
647 cmp = f(left, right);
656 * collect histogram counts
658 static void hist_hit(struct hist_entry *he, __u64 ip)
660 unsigned int sym_size, offset;
661 struct symbol *sym = he->sym;
665 if (!sym || !sym->hist)
668 sym_size = sym->end - sym->start;
669 offset = ip - sym->start;
671 if (offset >= sym_size)
678 printf("%p %s: count++ [ip: %p, %08Lx] => %Ld\n",
679 (void *)(unsigned long)he->sym->start,
681 (void *)(unsigned long)ip, ip - he->sym->start,
686 hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
687 struct symbol *sym, __u64 ip, char level)
689 struct rb_node **p = &hist.rb_node;
690 struct rb_node *parent = NULL;
691 struct hist_entry *he;
692 struct hist_entry entry = {
705 he = rb_entry(parent, struct hist_entry, rb_node);
707 cmp = hist_entry__cmp(&entry, he);
721 he = malloc(sizeof(*he));
725 rb_link_node(&he->rb_node, parent, p);
726 rb_insert_color(&he->rb_node, &hist);
731 static void hist_entry__free(struct hist_entry *he)
737 * collapse the histogram
740 static struct rb_root collapse_hists;
742 static void collapse__insert_entry(struct hist_entry *he)
744 struct rb_node **p = &collapse_hists.rb_node;
745 struct rb_node *parent = NULL;
746 struct hist_entry *iter;
751 iter = rb_entry(parent, struct hist_entry, rb_node);
753 cmp = hist_entry__collapse(iter, he);
756 iter->count += he->count;
757 hist_entry__free(he);
767 rb_link_node(&he->rb_node, parent, p);
768 rb_insert_color(&he->rb_node, &collapse_hists);
771 static void collapse__resort(void)
773 struct rb_node *next;
774 struct hist_entry *n;
776 if (!sort__need_collapse)
779 next = rb_first(&hist);
781 n = rb_entry(next, struct hist_entry, rb_node);
782 next = rb_next(&n->rb_node);
784 rb_erase(&n->rb_node, &hist);
785 collapse__insert_entry(n);
790 * reverse the map, sort on count.
793 static struct rb_root output_hists;
795 static void output__insert_entry(struct hist_entry *he)
797 struct rb_node **p = &output_hists.rb_node;
798 struct rb_node *parent = NULL;
799 struct hist_entry *iter;
803 iter = rb_entry(parent, struct hist_entry, rb_node);
805 if (he->count > iter->count)
811 rb_link_node(&he->rb_node, parent, p);
812 rb_insert_color(&he->rb_node, &output_hists);
815 static void output__resort(void)
817 struct rb_node *next;
818 struct hist_entry *n;
819 struct rb_root *tree = &hist;
821 if (sort__need_collapse)
822 tree = &collapse_hists;
824 next = rb_first(tree);
827 n = rb_entry(next, struct hist_entry, rb_node);
828 next = rb_next(&n->rb_node);
830 rb_erase(&n->rb_node, tree);
831 output__insert_entry(n);
835 static void register_idle_thread(void)
837 struct thread *thread = threads__findnew(0);
839 if (thread == NULL ||
840 thread__set_comm(thread, "[idle]")) {
841 fprintf(stderr, "problem inserting idle task.\n");
846 static unsigned long total = 0,
853 process_overflow_event(event_t *event, unsigned long offset, unsigned long head)
857 struct dso *dso = NULL;
858 struct thread *thread = threads__findnew(event->ip.pid);
859 __u64 ip = event->ip.ip;
860 struct map *map = NULL;
862 dprintf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n",
863 (void *)(offset + head),
864 (void *)(long)(event->header.size),
869 dprintf(" ... thread: %s:%d\n", thread->comm, thread->pid);
871 if (thread == NULL) {
872 fprintf(stderr, "problem processing %d event, skipping it.\n",
877 if (event->header.misc & PERF_EVENT_MISC_KERNEL) {
883 dprintf(" ...... dso: %s\n", dso->name);
885 } else if (event->header.misc & PERF_EVENT_MISC_USER) {
890 map = thread__find_map(thread, ip);
892 ip = map->map_ip(map, ip);
896 * If this is outside of all known maps,
897 * and is a negative address, try to look it
898 * up in the kernel dso, as it might be a
899 * vsyscall (which executes in user-mode):
901 if ((long long)ip < 0)
904 dprintf(" ...... dso: %s\n", dso ? dso->name : "<not found>");
909 dprintf(" ...... dso: [hypervisor]\n");
912 if (show & show_mask) {
913 struct symbol *sym = NULL;
916 sym = dso->find_symbol(dso, ip);
918 if (hist_entry__add(thread, map, dso, sym, ip, level)) {
920 "problem incrementing symbol count, skipping event\n");
930 process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
932 struct thread *thread = threads__findnew(event->mmap.pid);
933 struct map *map = map__new(&event->mmap);
935 dprintf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n",
936 (void *)(offset + head),
937 (void *)(long)(event->header.size),
939 (void *)(long)event->mmap.start,
940 (void *)(long)event->mmap.len,
941 (void *)(long)event->mmap.pgoff,
942 event->mmap.filename);
944 if (thread == NULL || map == NULL) {
945 dprintf("problem processing PERF_EVENT_MMAP, skipping event.\n");
949 thread__insert_map(thread, map);
956 process_comm_event(event_t *event, unsigned long offset, unsigned long head)
958 struct thread *thread = threads__findnew(event->comm.pid);
960 dprintf("%p [%p]: PERF_EVENT_COMM: %s:%d\n",
961 (void *)(offset + head),
962 (void *)(long)(event->header.size),
963 event->comm.comm, event->comm.pid);
965 if (thread == NULL ||
966 thread__set_comm(thread, event->comm.comm)) {
967 dprintf("problem processing PERF_EVENT_COMM, skipping event.\n");
976 process_fork_event(event_t *event, unsigned long offset, unsigned long head)
978 struct thread *thread = threads__findnew(event->fork.pid);
979 struct thread *parent = threads__findnew(event->fork.ppid);
981 dprintf("%p [%p]: PERF_EVENT_FORK: %d:%d\n",
982 (void *)(offset + head),
983 (void *)(long)(event->header.size),
984 event->fork.pid, event->fork.ppid);
986 if (!thread || !parent || thread__fork(thread, parent)) {
987 dprintf("problem processing PERF_EVENT_FORK, skipping event.\n");
996 process_period_event(event_t *event, unsigned long offset, unsigned long head)
998 dprintf("%p [%p]: PERF_EVENT_PERIOD: time:%Ld, id:%Ld: period:%Ld\n",
999 (void *)(offset + head),
1000 (void *)(long)(event->header.size),
1003 event->period.sample_period);
1009 process_event(event_t *event, unsigned long offset, unsigned long head)
1011 if (event->header.misc & PERF_EVENT_MISC_OVERFLOW)
1012 return process_overflow_event(event, offset, head);
1014 switch (event->header.type) {
1015 case PERF_EVENT_MMAP:
1016 return process_mmap_event(event, offset, head);
1018 case PERF_EVENT_COMM:
1019 return process_comm_event(event, offset, head);
1021 case PERF_EVENT_FORK:
1022 return process_fork_event(event, offset, head);
1024 case PERF_EVENT_PERIOD:
1025 return process_period_event(event, offset, head);
1027 * We dont process them right now but they are fine:
1030 case PERF_EVENT_THROTTLE:
1031 case PERF_EVENT_UNTHROTTLE:
1042 parse_line(FILE *file, struct symbol *sym, __u64 start, __u64 len)
1044 char *line = NULL, *tmp, *tmp2;
1045 static const char *prev_line;
1046 static const char *prev_color;
1047 unsigned int offset;
1053 if (getline(&line, &line_len, file) < 0)
1058 c = strchr(line, '\n');
1067 * Strip leading spaces:
1078 * Parse hexa addresses followed by ':'
1080 line_ip = strtoull(tmp, &tmp2, 16);
1085 if (line_ip != -1) {
1086 const char *path = NULL;
1087 unsigned int hits = 0;
1088 double percent = 0.0;
1089 char *color = PERF_COLOR_NORMAL;
1090 struct sym_ext *sym_ext = sym->priv;
1092 offset = line_ip - start;
1094 hits = sym->hist[offset];
1097 path = sym_ext[offset].path;
1098 percent = sym_ext[offset].percent;
1099 } else if (sym->hist_sum)
1100 percent = 100.0 * hits / sym->hist_sum;
1103 * We color high-overhead entries in red, mid-overhead
1104 * entries in green - and keep the low overhead places
1108 color = PERF_COLOR_RED;
1111 color = PERF_COLOR_GREEN;
1115 * Also color the filename and line if needed, with
1116 * the same color than the percentage. Don't print it
1117 * twice for close colored ip with the same filename:line
1120 if (!prev_line || strcmp(prev_line, path)
1121 || color != prev_color) {
1122 color_fprintf(stdout, color, " %s", path);
1128 color_fprintf(stdout, color, " %7.2f", percent);
1130 color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", line);
1135 printf(" : %s\n", line);
1141 static void free_source_line(struct symbol *sym, int len)
1143 struct sym_ext *sym_ext = sym->priv;
1149 for (i = 0; i < len; i++)
1150 free(sym_ext[i].path);
1156 /* Get the filename:line for the colored entries */
1157 static void get_source_line(struct symbol *sym, __u64 start, int len)
1160 char cmd[PATH_MAX * 2];
1161 struct sym_ext *sym_ext;
1166 sym->priv = calloc(len, sizeof(struct sym_ext));
1170 sym_ext = sym->priv;
1172 for (i = 0; i < len; i++) {
1178 sym_ext[i].percent = 100.0 * sym->hist[i] / sym->hist_sum;
1179 if (sym_ext[i].percent <= 0.5)
1183 sprintf(cmd, "addr2line -e %s %016llx", vmlinux, offset);
1184 fp = popen(cmd, "r");
1188 if (getline(&path, &line_len, fp) < 0 || !line_len)
1191 sym_ext[i].path = malloc(sizeof(char) * line_len);
1192 if (!sym_ext[i].path)
1195 strcpy(sym_ext[i].path, path);
1202 static void annotate_sym(struct dso *dso, struct symbol *sym)
1204 char *filename = dso->name;
1205 __u64 start, end, len;
1206 char command[PATH_MAX*2];
1211 if (dso == kernel_dso)
1214 printf("\n------------------------------------------------\n");
1215 printf(" Percent | Source code & Disassembly of %s\n", filename);
1216 printf("------------------------------------------------\n");
1219 printf("annotating [%p] %30s : [%p] %30s\n", dso, dso->name, sym, sym->name);
1221 start = sym->obj_start;
1225 end = start + sym->end - sym->start + 1;
1226 len = sym->end - sym->start;
1229 get_source_line(sym, start, len);
1231 sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s", (__u64)start, (__u64)end, filename);
1234 printf("doing: %s\n", command);
1236 file = popen(command, "r");
1240 while (!feof(file)) {
1241 if (parse_line(file, sym, start, len) < 0)
1246 free_source_line(sym, len);
1249 static void find_annotations(void)
1255 list_for_each_entry(dso, &dsos, node) {
1257 for (nd = rb_first(&dso->syms); nd; nd = rb_next(nd)) {
1258 struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
1261 annotate_sym(dso, sym);
1268 printf(" Error: symbol '%s' not present amongst the samples.\n", sym_hist_filter);
1271 static int __cmd_annotate(void)
1273 int ret, rc = EXIT_FAILURE;
1274 unsigned long offset = 0;
1275 unsigned long head = 0;
1281 register_idle_thread();
1283 input = open(input_name, O_RDONLY);
1285 perror("failed to open file");
1289 ret = fstat(input, &stat);
1291 perror("failed to stat file");
1295 if (!stat.st_size) {
1296 fprintf(stderr, "zero-sized file, nothing to do!\n");
1300 if (load_kernel() < 0) {
1301 perror("failed to load kernel symbols");
1302 return EXIT_FAILURE;
1306 buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
1307 MAP_SHARED, input, offset);
1308 if (buf == MAP_FAILED) {
1309 perror("failed to mmap file");
1314 event = (event_t *)(buf + head);
1316 size = event->header.size;
1320 if (head + event->header.size >= page_size * mmap_window) {
1321 unsigned long shift = page_size * (head / page_size);
1324 ret = munmap(buf, page_size * mmap_window);
1332 size = event->header.size;
1334 dprintf("%p [%p]: event: %d\n",
1335 (void *)(offset + head),
1336 (void *)(long)event->header.size,
1337 event->header.type);
1339 if (!size || process_event(event, offset, head) < 0) {
1341 dprintf("%p [%p]: skipping unknown header type: %d\n",
1342 (void *)(offset + head),
1343 (void *)(long)(event->header.size),
1344 event->header.type);
1349 * assume we lost track of the stream, check alignment, and
1350 * increment a single u64 in the hope to catch on again 'soon'.
1353 if (unlikely(head & 7))
1361 if (offset + head < stat.st_size)
1367 dprintf(" IP events: %10ld\n", total);
1368 dprintf(" mmap events: %10ld\n", total_mmap);
1369 dprintf(" comm events: %10ld\n", total_comm);
1370 dprintf(" fork events: %10ld\n", total_fork);
1371 dprintf(" unknown events: %10ld\n", total_unknown);
1377 threads__fprintf(stdout);
1380 dsos__fprintf(stdout);
1390 static const char * const annotate_usage[] = {
1391 "perf annotate [<options>] <command>",
1395 static const struct option options[] = {
1396 OPT_STRING('i', "input", &input_name, "file",
1398 OPT_STRING('s', "symbol", &sym_hist_filter, "symbol",
1399 "symbol to annotate"),
1400 OPT_BOOLEAN('v', "verbose", &verbose,
1401 "be more verbose (show symbol address, etc)"),
1402 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
1403 "dump raw trace in ASCII"),
1404 OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
1405 OPT_BOOLEAN('l', "print-line", &print_line,
1406 "print matching source lines (may be slow)"),
1410 static void setup_sorting(void)
1412 char *tmp, *tok, *str = strdup(sort_order);
1414 for (tok = strtok_r(str, ", ", &tmp);
1415 tok; tok = strtok_r(NULL, ", ", &tmp)) {
1416 if (sort_dimension__add(tok) < 0) {
1417 error("Unknown --sort key: `%s'", tok);
1418 usage_with_options(annotate_usage, options);
1425 int cmd_annotate(int argc, const char **argv, const char *prefix)
1429 page_size = getpagesize();
1431 argc = parse_options(argc, argv, options, annotate_usage, 0);
1437 * Special case: if there's an argument left then assume tha
1438 * it's a symbol filter:
1441 usage_with_options(annotate_usage, options);
1443 sym_hist_filter = argv[0];
1446 if (!sym_hist_filter)
1447 usage_with_options(annotate_usage, options);
1451 return __cmd_annotate();