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 <linux/list.h>
14 #include "util/cache.h"
15 #include <linux/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";
30 static char default_sort_order[] = "comm,symbol";
31 static char *sort_order = default_sort_order;
34 static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
36 static int dump_trace = 0;
37 #define dprintf(x...) do { if (dump_trace) printf(x); } while (0)
40 static int full_paths;
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;
73 typedef union event_union {
74 struct perf_event_header header;
76 struct mmap_event mmap;
77 struct comm_event comm;
78 struct fork_event fork;
89 struct list_head node;
93 u64 (*map_ip)(struct map *, u64);
97 static u64 map__map_ip(struct map *map, u64 ip)
99 return ip - map->start + map->pgoff;
102 static u64 vdso__map_ip(struct map *map __used, u64 ip)
107 static struct map *map__new(struct mmap_event *event)
109 struct map *self = malloc(sizeof(*self));
112 const char *filename = event->filename;
114 self->start = event->start;
115 self->end = event->start + event->len;
116 self->pgoff = event->pgoff;
118 self->dso = dsos__findnew(filename);
119 if (self->dso == NULL)
122 if (self->dso == vdso)
123 self->map_ip = vdso__map_ip;
125 self->map_ip = map__map_ip;
133 static struct map *map__clone(struct map *self)
135 struct map *map = malloc(sizeof(*self));
140 memcpy(map, self, sizeof(*self));
145 static int map__overlap(struct map *l, struct map *r)
147 if (l->start > r->start) {
153 if (l->end > r->start)
159 static size_t map__fprintf(struct map *self, FILE *fp)
161 return fprintf(fp, " %Lx-%Lx %Lx %s\n",
162 self->start, self->end, self->pgoff, self->dso->name);
167 struct rb_node rb_node;
168 struct list_head maps;
173 static struct thread *thread__new(pid_t pid)
175 struct thread *self = malloc(sizeof(*self));
179 self->comm = malloc(32);
181 snprintf(self->comm, 32, ":%d", self->pid);
182 INIT_LIST_HEAD(&self->maps);
188 static int thread__set_comm(struct thread *self, const char *comm)
192 self->comm = strdup(comm);
193 return self->comm ? 0 : -ENOMEM;
196 static size_t thread__fprintf(struct thread *self, FILE *fp)
199 size_t ret = fprintf(fp, "Thread %d %s\n", self->pid, self->comm);
201 list_for_each_entry(pos, &self->maps, node)
202 ret += map__fprintf(pos, fp);
208 static struct rb_root threads;
209 static struct thread *last_match;
211 static struct thread *threads__findnew(pid_t pid)
213 struct rb_node **p = &threads.rb_node;
214 struct rb_node *parent = NULL;
218 * Font-end cache - PID lookups come in blocks,
219 * so most of the time we dont have to look up
222 if (last_match && last_match->pid == pid)
227 th = rb_entry(parent, struct thread, rb_node);
229 if (th->pid == pid) {
240 th = thread__new(pid);
242 rb_link_node(&th->rb_node, parent, p);
243 rb_insert_color(&th->rb_node, &threads);
250 static void thread__insert_map(struct thread *self, struct map *map)
252 struct map *pos, *tmp;
254 list_for_each_entry_safe(pos, tmp, &self->maps, node) {
255 if (map__overlap(pos, map)) {
256 list_del_init(&pos->node);
262 list_add_tail(&map->node, &self->maps);
265 static int thread__fork(struct thread *self, struct thread *parent)
271 self->comm = strdup(parent->comm);
275 list_for_each_entry(map, &parent->maps, node) {
276 struct map *new = map__clone(map);
279 thread__insert_map(self, new);
285 static struct map *thread__find_map(struct thread *self, u64 ip)
292 list_for_each_entry(pos, &self->maps, node)
293 if (ip >= pos->start && ip <= pos->end)
299 static size_t threads__fprintf(FILE *fp)
304 for (nd = rb_first(&threads); nd; nd = rb_next(nd)) {
305 struct thread *pos = rb_entry(nd, struct thread, rb_node);
307 ret += thread__fprintf(pos, fp);
314 * histogram, sorted on item, collects counts
317 static struct rb_root hist;
320 struct rb_node rb_node;
322 struct thread *thread;
333 * configurable sorting bits
337 struct list_head list;
341 int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
342 int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
343 size_t (*print)(FILE *fp, struct hist_entry *);
349 sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
351 return right->thread->pid - left->thread->pid;
355 sort__thread_print(FILE *fp, struct hist_entry *self)
357 return fprintf(fp, "%16s:%5d", self->thread->comm ?: "", self->thread->pid);
360 static struct sort_entry sort_thread = {
361 .header = " Command: Pid",
362 .cmp = sort__thread_cmp,
363 .print = sort__thread_print,
369 sort__comm_cmp(struct hist_entry *left, struct hist_entry *right)
371 return right->thread->pid - left->thread->pid;
375 sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
377 char *comm_l = left->thread->comm;
378 char *comm_r = right->thread->comm;
380 if (!comm_l || !comm_r) {
381 if (!comm_l && !comm_r)
389 return strcmp(comm_l, comm_r);
393 sort__comm_print(FILE *fp, struct hist_entry *self)
395 return fprintf(fp, "%16s", self->thread->comm);
398 static struct sort_entry sort_comm = {
399 .header = " Command",
400 .cmp = sort__comm_cmp,
401 .collapse = sort__comm_collapse,
402 .print = sort__comm_print,
408 sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
410 struct dso *dso_l = left->dso;
411 struct dso *dso_r = right->dso;
413 if (!dso_l || !dso_r) {
414 if (!dso_l && !dso_r)
422 return strcmp(dso_l->name, dso_r->name);
426 sort__dso_print(FILE *fp, struct hist_entry *self)
429 return fprintf(fp, "%-25s", self->dso->name);
431 return fprintf(fp, "%016llx ", (u64)self->ip);
434 static struct sort_entry sort_dso = {
435 .header = "Shared Object ",
436 .cmp = sort__dso_cmp,
437 .print = sort__dso_print,
443 sort__sym_cmp(struct hist_entry *left, struct hist_entry *right)
447 if (left->sym == right->sym)
450 ip_l = left->sym ? left->sym->start : left->ip;
451 ip_r = right->sym ? right->sym->start : right->ip;
453 return (int64_t)(ip_r - ip_l);
457 sort__sym_print(FILE *fp, struct hist_entry *self)
462 ret += fprintf(fp, "%#018llx ", (u64)self->ip);
465 ret += fprintf(fp, "[%c] %s",
466 self->dso == kernel_dso ? 'k' : '.', self->sym->name);
468 ret += fprintf(fp, "%#016llx", (u64)self->ip);
474 static struct sort_entry sort_sym = {
476 .cmp = sort__sym_cmp,
477 .print = sort__sym_print,
480 static int sort__need_collapse = 0;
482 struct sort_dimension {
484 struct sort_entry *entry;
488 static struct sort_dimension sort_dimensions[] = {
489 { .name = "pid", .entry = &sort_thread, },
490 { .name = "comm", .entry = &sort_comm, },
491 { .name = "dso", .entry = &sort_dso, },
492 { .name = "symbol", .entry = &sort_sym, },
495 static LIST_HEAD(hist_entry__sort_list);
497 static int sort_dimension__add(char *tok)
501 for (i = 0; i < ARRAY_SIZE(sort_dimensions); i++) {
502 struct sort_dimension *sd = &sort_dimensions[i];
507 if (strncasecmp(tok, sd->name, strlen(tok)))
510 if (sd->entry->collapse)
511 sort__need_collapse = 1;
513 list_add_tail(&sd->entry->list, &hist_entry__sort_list);
523 hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
525 struct sort_entry *se;
528 list_for_each_entry(se, &hist_entry__sort_list, list) {
529 cmp = se->cmp(left, right);
538 hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
540 struct sort_entry *se;
543 list_for_each_entry(se, &hist_entry__sort_list, list) {
544 int64_t (*f)(struct hist_entry *, struct hist_entry *);
546 f = se->collapse ?: se->cmp;
548 cmp = f(left, right);
557 * collect histogram counts
559 static void hist_hit(struct hist_entry *he, u64 ip)
561 unsigned int sym_size, offset;
562 struct symbol *sym = he->sym;
566 if (!sym || !sym->hist)
569 sym_size = sym->end - sym->start;
570 offset = ip - sym->start;
572 if (offset >= sym_size)
579 printf("%p %s: count++ [ip: %p, %08Lx] => %Ld\n",
580 (void *)(unsigned long)he->sym->start,
582 (void *)(unsigned long)ip, ip - he->sym->start,
587 hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
588 struct symbol *sym, u64 ip, char level)
590 struct rb_node **p = &hist.rb_node;
591 struct rb_node *parent = NULL;
592 struct hist_entry *he;
593 struct hist_entry entry = {
606 he = rb_entry(parent, struct hist_entry, rb_node);
608 cmp = hist_entry__cmp(&entry, he);
622 he = malloc(sizeof(*he));
626 rb_link_node(&he->rb_node, parent, p);
627 rb_insert_color(&he->rb_node, &hist);
632 static void hist_entry__free(struct hist_entry *he)
638 * collapse the histogram
641 static struct rb_root collapse_hists;
643 static void collapse__insert_entry(struct hist_entry *he)
645 struct rb_node **p = &collapse_hists.rb_node;
646 struct rb_node *parent = NULL;
647 struct hist_entry *iter;
652 iter = rb_entry(parent, struct hist_entry, rb_node);
654 cmp = hist_entry__collapse(iter, he);
657 iter->count += he->count;
658 hist_entry__free(he);
668 rb_link_node(&he->rb_node, parent, p);
669 rb_insert_color(&he->rb_node, &collapse_hists);
672 static void collapse__resort(void)
674 struct rb_node *next;
675 struct hist_entry *n;
677 if (!sort__need_collapse)
680 next = rb_first(&hist);
682 n = rb_entry(next, struct hist_entry, rb_node);
683 next = rb_next(&n->rb_node);
685 rb_erase(&n->rb_node, &hist);
686 collapse__insert_entry(n);
691 * reverse the map, sort on count.
694 static struct rb_root output_hists;
696 static void output__insert_entry(struct hist_entry *he)
698 struct rb_node **p = &output_hists.rb_node;
699 struct rb_node *parent = NULL;
700 struct hist_entry *iter;
704 iter = rb_entry(parent, struct hist_entry, rb_node);
706 if (he->count > iter->count)
712 rb_link_node(&he->rb_node, parent, p);
713 rb_insert_color(&he->rb_node, &output_hists);
716 static void output__resort(void)
718 struct rb_node *next;
719 struct hist_entry *n;
720 struct rb_root *tree = &hist;
722 if (sort__need_collapse)
723 tree = &collapse_hists;
725 next = rb_first(tree);
728 n = rb_entry(next, struct hist_entry, rb_node);
729 next = rb_next(&n->rb_node);
731 rb_erase(&n->rb_node, tree);
732 output__insert_entry(n);
736 static void register_idle_thread(void)
738 struct thread *thread = threads__findnew(0);
740 if (thread == NULL ||
741 thread__set_comm(thread, "[idle]")) {
742 fprintf(stderr, "problem inserting idle task.\n");
747 static unsigned long total = 0,
754 process_sample_event(event_t *event, unsigned long offset, unsigned long head)
758 struct dso *dso = NULL;
759 struct thread *thread = threads__findnew(event->ip.pid);
760 u64 ip = event->ip.ip;
761 struct map *map = NULL;
763 dprintf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n",
764 (void *)(offset + head),
765 (void *)(long)(event->header.size),
770 dprintf(" ... thread: %s:%d\n", thread->comm, thread->pid);
772 if (thread == NULL) {
773 fprintf(stderr, "problem processing %d event, skipping it.\n",
778 if (event->header.misc & PERF_EVENT_MISC_KERNEL) {
784 dprintf(" ...... dso: %s\n", dso->name);
786 } else if (event->header.misc & PERF_EVENT_MISC_USER) {
791 map = thread__find_map(thread, ip);
793 ip = map->map_ip(map, ip);
797 * If this is outside of all known maps,
798 * and is a negative address, try to look it
799 * up in the kernel dso, as it might be a
800 * vsyscall (which executes in user-mode):
802 if ((long long)ip < 0)
805 dprintf(" ...... dso: %s\n", dso ? dso->name : "<not found>");
810 dprintf(" ...... dso: [hypervisor]\n");
813 if (show & show_mask) {
814 struct symbol *sym = NULL;
817 sym = dso->find_symbol(dso, ip);
819 if (hist_entry__add(thread, map, dso, sym, ip, level)) {
821 "problem incrementing symbol count, skipping event\n");
831 process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
833 struct thread *thread = threads__findnew(event->mmap.pid);
834 struct map *map = map__new(&event->mmap);
836 dprintf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n",
837 (void *)(offset + head),
838 (void *)(long)(event->header.size),
840 (void *)(long)event->mmap.start,
841 (void *)(long)event->mmap.len,
842 (void *)(long)event->mmap.pgoff,
843 event->mmap.filename);
845 if (thread == NULL || map == NULL) {
846 dprintf("problem processing PERF_EVENT_MMAP, skipping event.\n");
850 thread__insert_map(thread, map);
857 process_comm_event(event_t *event, unsigned long offset, unsigned long head)
859 struct thread *thread = threads__findnew(event->comm.pid);
861 dprintf("%p [%p]: PERF_EVENT_COMM: %s:%d\n",
862 (void *)(offset + head),
863 (void *)(long)(event->header.size),
864 event->comm.comm, event->comm.pid);
866 if (thread == NULL ||
867 thread__set_comm(thread, event->comm.comm)) {
868 dprintf("problem processing PERF_EVENT_COMM, skipping event.\n");
877 process_fork_event(event_t *event, unsigned long offset, unsigned long head)
879 struct thread *thread = threads__findnew(event->fork.pid);
880 struct thread *parent = threads__findnew(event->fork.ppid);
882 dprintf("%p [%p]: PERF_EVENT_FORK: %d:%d\n",
883 (void *)(offset + head),
884 (void *)(long)(event->header.size),
885 event->fork.pid, event->fork.ppid);
887 if (!thread || !parent || thread__fork(thread, parent)) {
888 dprintf("problem processing PERF_EVENT_FORK, skipping event.\n");
897 process_event(event_t *event, unsigned long offset, unsigned long head)
899 switch (event->header.type) {
900 case PERF_EVENT_SAMPLE:
901 return process_sample_event(event, offset, head);
903 case PERF_EVENT_MMAP:
904 return process_mmap_event(event, offset, head);
906 case PERF_EVENT_COMM:
907 return process_comm_event(event, offset, head);
909 case PERF_EVENT_FORK:
910 return process_fork_event(event, offset, head);
912 * We dont process them right now but they are fine:
915 case PERF_EVENT_THROTTLE:
916 case PERF_EVENT_UNTHROTTLE:
927 parse_line(FILE *file, struct symbol *sym, u64 start, u64 len)
929 char *line = NULL, *tmp, *tmp2;
930 static const char *prev_line;
931 static const char *prev_color;
938 if (getline(&line, &line_len, file) < 0)
943 c = strchr(line, '\n');
952 * Strip leading spaces:
963 * Parse hexa addresses followed by ':'
965 line_ip = strtoull(tmp, &tmp2, 16);
971 const char *path = NULL;
972 unsigned int hits = 0;
973 double percent = 0.0;
975 struct sym_ext *sym_ext = sym->priv;
977 offset = line_ip - start;
979 hits = sym->hist[offset];
981 if (offset < len && sym_ext) {
982 path = sym_ext[offset].path;
983 percent = sym_ext[offset].percent;
984 } else if (sym->hist_sum)
985 percent = 100.0 * hits / sym->hist_sum;
987 color = get_percent_color(percent);
990 * Also color the filename and line if needed, with
991 * the same color than the percentage. Don't print it
992 * twice for close colored ip with the same filename:line
995 if (!prev_line || strcmp(prev_line, path)
996 || color != prev_color) {
997 color_fprintf(stdout, color, " %s", path);
1003 color_fprintf(stdout, color, " %7.2f", percent);
1005 color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", line);
1010 printf(" : %s\n", line);
1016 static struct rb_root root_sym_ext;
1018 static void insert_source_line(struct sym_ext *sym_ext)
1020 struct sym_ext *iter;
1021 struct rb_node **p = &root_sym_ext.rb_node;
1022 struct rb_node *parent = NULL;
1024 while (*p != NULL) {
1026 iter = rb_entry(parent, struct sym_ext, node);
1028 if (sym_ext->percent > iter->percent)
1031 p = &(*p)->rb_right;
1034 rb_link_node(&sym_ext->node, parent, p);
1035 rb_insert_color(&sym_ext->node, &root_sym_ext);
1038 static void free_source_line(struct symbol *sym, int len)
1040 struct sym_ext *sym_ext = sym->priv;
1046 for (i = 0; i < len; i++)
1047 free(sym_ext[i].path);
1051 root_sym_ext = RB_ROOT;
1054 /* Get the filename:line for the colored entries */
1056 get_source_line(struct symbol *sym, u64 start, int len, char *filename)
1059 char cmd[PATH_MAX * 2];
1060 struct sym_ext *sym_ext;
1065 sym->priv = calloc(len, sizeof(struct sym_ext));
1069 sym_ext = sym->priv;
1071 for (i = 0; i < len; i++) {
1077 sym_ext[i].percent = 100.0 * sym->hist[i] / sym->hist_sum;
1078 if (sym_ext[i].percent <= 0.5)
1082 sprintf(cmd, "addr2line -e %s %016llx", filename, offset);
1083 fp = popen(cmd, "r");
1087 if (getline(&path, &line_len, fp) < 0 || !line_len)
1090 sym_ext[i].path = malloc(sizeof(char) * line_len + 1);
1091 if (!sym_ext[i].path)
1094 strcpy(sym_ext[i].path, path);
1095 insert_source_line(&sym_ext[i]);
1102 static void print_summary(char *filename)
1104 struct sym_ext *sym_ext;
1105 struct rb_node *node;
1107 printf("\nSorted summary for file %s\n", filename);
1108 printf("----------------------------------------------\n\n");
1110 if (RB_EMPTY_ROOT(&root_sym_ext)) {
1111 printf(" Nothing higher than %1.1f%%\n", MIN_GREEN);
1115 node = rb_first(&root_sym_ext);
1121 sym_ext = rb_entry(node, struct sym_ext, node);
1122 percent = sym_ext->percent;
1123 color = get_percent_color(percent);
1124 path = sym_ext->path;
1126 color_fprintf(stdout, color, " %7.2f %s", percent, path);
1127 node = rb_next(node);
1131 static void annotate_sym(struct dso *dso, struct symbol *sym)
1133 char *filename = dso->name, *d_filename;
1134 u64 start, end, len;
1135 char command[PATH_MAX*2];
1141 filename = sym->module->path;
1142 else if (dso == kernel_dso)
1145 start = sym->obj_start;
1149 d_filename = filename;
1151 d_filename = basename(filename);
1153 end = start + sym->end - sym->start + 1;
1154 len = sym->end - sym->start;
1157 get_source_line(sym, start, len, filename);
1158 print_summary(filename);
1161 printf("\n\n------------------------------------------------\n");
1162 printf(" Percent | Source code & Disassembly of %s\n", d_filename);
1163 printf("------------------------------------------------\n");
1166 printf("annotating [%p] %30s : [%p] %30s\n", dso, dso->name, sym, sym->name);
1168 sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s",
1169 (u64)start, (u64)end, filename, filename);
1172 printf("doing: %s\n", command);
1174 file = popen(command, "r");
1178 while (!feof(file)) {
1179 if (parse_line(file, sym, start, len) < 0)
1185 free_source_line(sym, len);
1188 static void find_annotations(void)
1194 list_for_each_entry(dso, &dsos, node) {
1196 for (nd = rb_first(&dso->syms); nd; nd = rb_next(nd)) {
1197 struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
1200 annotate_sym(dso, sym);
1207 printf(" Error: symbol '%s' not present amongst the samples.\n", sym_hist_filter);
1210 static int __cmd_annotate(void)
1212 int ret, rc = EXIT_FAILURE;
1213 unsigned long offset = 0;
1214 unsigned long head = 0;
1220 register_idle_thread();
1222 input = open(input_name, O_RDONLY);
1224 perror("failed to open file");
1228 ret = fstat(input, &stat);
1230 perror("failed to stat file");
1234 if (!stat.st_size) {
1235 fprintf(stderr, "zero-sized file, nothing to do!\n");
1239 if (load_kernel() < 0) {
1240 perror("failed to load kernel symbols");
1241 return EXIT_FAILURE;
1245 buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
1246 MAP_SHARED, input, offset);
1247 if (buf == MAP_FAILED) {
1248 perror("failed to mmap file");
1253 event = (event_t *)(buf + head);
1255 size = event->header.size;
1259 if (head + event->header.size >= page_size * mmap_window) {
1260 unsigned long shift = page_size * (head / page_size);
1263 ret = munmap(buf, page_size * mmap_window);
1271 size = event->header.size;
1273 dprintf("%p [%p]: event: %d\n",
1274 (void *)(offset + head),
1275 (void *)(long)event->header.size,
1276 event->header.type);
1278 if (!size || process_event(event, offset, head) < 0) {
1280 dprintf("%p [%p]: skipping unknown header type: %d\n",
1281 (void *)(offset + head),
1282 (void *)(long)(event->header.size),
1283 event->header.type);
1288 * assume we lost track of the stream, check alignment, and
1289 * increment a single u64 in the hope to catch on again 'soon'.
1292 if (unlikely(head & 7))
1300 if (offset + head < (unsigned long)stat.st_size)
1306 dprintf(" IP events: %10ld\n", total);
1307 dprintf(" mmap events: %10ld\n", total_mmap);
1308 dprintf(" comm events: %10ld\n", total_comm);
1309 dprintf(" fork events: %10ld\n", total_fork);
1310 dprintf(" unknown events: %10ld\n", total_unknown);
1316 threads__fprintf(stdout);
1319 dsos__fprintf(stdout);
1329 static const char * const annotate_usage[] = {
1330 "perf annotate [<options>] <command>",
1334 static const struct option options[] = {
1335 OPT_STRING('i', "input", &input_name, "file",
1337 OPT_STRING('s', "symbol", &sym_hist_filter, "symbol",
1338 "symbol to annotate"),
1339 OPT_BOOLEAN('v', "verbose", &verbose,
1340 "be more verbose (show symbol address, etc)"),
1341 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
1342 "dump raw trace in ASCII"),
1343 OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"),
1344 OPT_BOOLEAN('m', "modules", &modules,
1345 "load module symbols - WARNING: use only with -k and LIVE kernel"),
1346 OPT_BOOLEAN('l', "print-line", &print_line,
1347 "print matching source lines (may be slow)"),
1348 OPT_BOOLEAN('P', "full-paths", &full_paths,
1349 "Don't shorten the displayed pathnames"),
1353 static void setup_sorting(void)
1355 char *tmp, *tok, *str = strdup(sort_order);
1357 for (tok = strtok_r(str, ", ", &tmp);
1358 tok; tok = strtok_r(NULL, ", ", &tmp)) {
1359 if (sort_dimension__add(tok) < 0) {
1360 error("Unknown --sort key: `%s'", tok);
1361 usage_with_options(annotate_usage, options);
1368 int cmd_annotate(int argc, const char **argv, const char *prefix __used)
1372 page_size = getpagesize();
1374 argc = parse_options(argc, argv, options, annotate_usage, 0);
1380 * Special case: if there's an argument left then assume tha
1381 * it's a symbol filter:
1384 usage_with_options(annotate_usage, options);
1386 sym_hist_filter = argv[0];
1389 if (!sym_hist_filter)
1390 usage_with_options(annotate_usage, options);
1394 return __cmd_annotate();