builtin-annotate.c 17 KB

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