builtin-annotate.c 17 KB

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