builtin-annotate.c 17 KB

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