builtin-annotate.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * builtin-annotate.c
  4. *
  5. * Builtin annotate command: Analyze the perf.data input file,
  6. * look up and read DSOs and symbol information and display
  7. * a histogram of results, along various sorting keys.
  8. */
  9. #include "builtin.h"
  10. #include "util/color.h"
  11. #include <linux/list.h>
  12. #include "util/cache.h"
  13. #include <linux/rbtree.h>
  14. #include <linux/zalloc.h>
  15. #include "util/symbol.h"
  16. #include "perf.h"
  17. #include "util/debug.h"
  18. #include "util/evlist.h"
  19. #include "util/evsel.h"
  20. #include "util/annotate.h"
  21. #include "util/event.h"
  22. #include <subcmd/parse-options.h>
  23. #include "util/parse-events.h"
  24. #include "util/sort.h"
  25. #include "util/hist.h"
  26. #include "util/dso.h"
  27. #include "util/machine.h"
  28. #include "util/map.h"
  29. #include "util/session.h"
  30. #include "util/tool.h"
  31. #include "util/data.h"
  32. #include "arch/common.h"
  33. #include "util/block-range.h"
  34. #include "util/map_symbol.h"
  35. #include "util/branch.h"
  36. #include <dlfcn.h>
  37. #include <errno.h>
  38. #include <linux/bitmap.h>
  39. #include <linux/err.h>
  40. struct perf_annotate {
  41. struct perf_tool tool;
  42. struct perf_session *session;
  43. struct annotation_options opts;
  44. #ifdef HAVE_SLANG_SUPPORT
  45. bool use_tui;
  46. #endif
  47. bool use_stdio, use_stdio2;
  48. #ifdef HAVE_GTK2_SUPPORT
  49. bool use_gtk;
  50. #endif
  51. bool skip_missing;
  52. bool has_br_stack;
  53. bool group_set;
  54. float min_percent;
  55. const char *sym_hist_filter;
  56. const char *cpu_list;
  57. DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
  58. };
  59. /*
  60. * Given one basic block:
  61. *
  62. * from to branch_i
  63. * * ----> *
  64. * |
  65. * | block
  66. * v
  67. * * ----> *
  68. * from to branch_i+1
  69. *
  70. * where the horizontal are the branches and the vertical is the executed
  71. * block of instructions.
  72. *
  73. * We count, for each 'instruction', the number of blocks that covered it as
  74. * well as count the ratio each branch is taken.
  75. *
  76. * We can do this without knowing the actual instruction stream by keeping
  77. * track of the address ranges. We break down ranges such that there is no
  78. * overlap and iterate from the start until the end.
  79. *
  80. * @acme: once we parse the objdump output _before_ processing the samples,
  81. * we can easily fold the branch.cycles IPC bits in.
  82. */
  83. static void process_basic_block(struct addr_map_symbol *start,
  84. struct addr_map_symbol *end,
  85. struct branch_flags *flags)
  86. {
  87. struct symbol *sym = start->ms.sym;
  88. struct annotation *notes = sym ? symbol__annotation(sym) : NULL;
  89. struct block_range_iter iter;
  90. struct block_range *entry;
  91. /*
  92. * Sanity; NULL isn't executable and the CPU cannot execute backwards
  93. */
  94. if (!start->addr || start->addr > end->addr)
  95. return;
  96. iter = block_range__create(start->addr, end->addr);
  97. if (!block_range_iter__valid(&iter))
  98. return;
  99. /*
  100. * First block in range is a branch target.
  101. */
  102. entry = block_range_iter(&iter);
  103. assert(entry->is_target);
  104. entry->entry++;
  105. do {
  106. entry = block_range_iter(&iter);
  107. entry->coverage++;
  108. entry->sym = sym;
  109. if (notes)
  110. notes->max_coverage = max(notes->max_coverage, entry->coverage);
  111. } while (block_range_iter__next(&iter));
  112. /*
  113. * Last block in rage is a branch.
  114. */
  115. entry = block_range_iter(&iter);
  116. assert(entry->is_branch);
  117. entry->taken++;
  118. if (flags->predicted)
  119. entry->pred++;
  120. }
  121. static void process_branch_stack(struct branch_stack *bs, struct addr_location *al,
  122. struct perf_sample *sample)
  123. {
  124. struct addr_map_symbol *prev = NULL;
  125. struct branch_info *bi;
  126. int i;
  127. if (!bs || !bs->nr)
  128. return;
  129. bi = sample__resolve_bstack(sample, al);
  130. if (!bi)
  131. return;
  132. for (i = bs->nr - 1; i >= 0; i--) {
  133. /*
  134. * XXX filter against symbol
  135. */
  136. if (prev)
  137. process_basic_block(prev, &bi[i].from, &bi[i].flags);
  138. prev = &bi[i].to;
  139. }
  140. free(bi);
  141. }
  142. static int hist_iter__branch_callback(struct hist_entry_iter *iter,
  143. struct addr_location *al __maybe_unused,
  144. bool single __maybe_unused,
  145. void *arg __maybe_unused)
  146. {
  147. struct hist_entry *he = iter->he;
  148. struct branch_info *bi;
  149. struct perf_sample *sample = iter->sample;
  150. struct evsel *evsel = iter->evsel;
  151. int err;
  152. bi = he->branch_info;
  153. err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
  154. if (err)
  155. goto out;
  156. err = addr_map_symbol__inc_samples(&bi->to, sample, evsel);
  157. out:
  158. return err;
  159. }
  160. static int process_branch_callback(struct evsel *evsel,
  161. struct perf_sample *sample,
  162. struct addr_location *al __maybe_unused,
  163. struct perf_annotate *ann,
  164. struct machine *machine)
  165. {
  166. struct hist_entry_iter iter = {
  167. .evsel = evsel,
  168. .sample = sample,
  169. .add_entry_cb = hist_iter__branch_callback,
  170. .hide_unresolved = symbol_conf.hide_unresolved,
  171. .ops = &hist_iter_branch,
  172. };
  173. struct addr_location a;
  174. if (machine__resolve(machine, &a, sample) < 0)
  175. return -1;
  176. if (a.sym == NULL)
  177. return 0;
  178. if (a.map != NULL)
  179. a.map->dso->hit = 1;
  180. hist__account_cycles(sample->branch_stack, al, sample, false, NULL);
  181. return hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
  182. }
  183. static bool has_annotation(struct perf_annotate *ann)
  184. {
  185. return ui__has_annotation() || ann->use_stdio2;
  186. }
  187. static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample,
  188. struct addr_location *al, struct perf_annotate *ann,
  189. struct machine *machine)
  190. {
  191. struct hists *hists = evsel__hists(evsel);
  192. struct hist_entry *he;
  193. int ret;
  194. if ((!ann->has_br_stack || !has_annotation(ann)) &&
  195. ann->sym_hist_filter != NULL &&
  196. (al->sym == NULL ||
  197. strcmp(ann->sym_hist_filter, al->sym->name) != 0)) {
  198. /* We're only interested in a symbol named sym_hist_filter */
  199. /*
  200. * FIXME: why isn't this done in the symbol_filter when loading
  201. * the DSO?
  202. */
  203. if (al->sym != NULL) {
  204. rb_erase_cached(&al->sym->rb_node,
  205. &al->map->dso->symbols);
  206. symbol__delete(al->sym);
  207. dso__reset_find_symbol_cache(al->map->dso);
  208. }
  209. return 0;
  210. }
  211. /*
  212. * XXX filtered samples can still have branch entries pointing into our
  213. * symbol and are missed.
  214. */
  215. process_branch_stack(sample->branch_stack, al, sample);
  216. if (ann->has_br_stack && has_annotation(ann))
  217. return process_branch_callback(evsel, sample, al, ann, machine);
  218. he = hists__add_entry(hists, al, NULL, NULL, NULL, sample, true);
  219. if (he == NULL)
  220. return -ENOMEM;
  221. ret = hist_entry__inc_addr_samples(he, sample, evsel, al->addr);
  222. hists__inc_nr_samples(hists, true);
  223. return ret;
  224. }
  225. static int process_sample_event(struct perf_tool *tool,
  226. union perf_event *event,
  227. struct perf_sample *sample,
  228. struct evsel *evsel,
  229. struct machine *machine)
  230. {
  231. struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool);
  232. struct addr_location al;
  233. int ret = 0;
  234. if (machine__resolve(machine, &al, sample) < 0) {
  235. pr_warning("problem processing %d event, skipping it.\n",
  236. event->header.type);
  237. return -1;
  238. }
  239. if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap))
  240. goto out_put;
  241. if (!al.filtered &&
  242. evsel__add_sample(evsel, sample, &al, ann, machine)) {
  243. pr_warning("problem incrementing symbol count, "
  244. "skipping event\n");
  245. ret = -1;
  246. }
  247. out_put:
  248. addr_location__put(&al);
  249. return ret;
  250. }
  251. static int process_feature_event(struct perf_session *session,
  252. union perf_event *event)
  253. {
  254. if (event->feat.feat_id < HEADER_LAST_FEATURE)
  255. return perf_event__process_feature(session, event);
  256. return 0;
  257. }
  258. static int hist_entry__tty_annotate(struct hist_entry *he,
  259. struct evsel *evsel,
  260. struct perf_annotate *ann)
  261. {
  262. if (!ann->use_stdio2)
  263. return symbol__tty_annotate(&he->ms, evsel, &ann->opts);
  264. return symbol__tty_annotate2(&he->ms, evsel, &ann->opts);
  265. }
  266. static void hists__find_annotations(struct hists *hists,
  267. struct evsel *evsel,
  268. struct perf_annotate *ann)
  269. {
  270. struct rb_node *nd = rb_first_cached(&hists->entries), *next;
  271. int key = K_RIGHT;
  272. while (nd) {
  273. struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
  274. struct annotation *notes;
  275. if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned)
  276. goto find_next;
  277. if (ann->sym_hist_filter &&
  278. (strcmp(he->ms.sym->name, ann->sym_hist_filter) != 0))
  279. goto find_next;
  280. if (ann->min_percent) {
  281. float percent = 0;
  282. u64 total = hists__total_period(hists);
  283. if (total)
  284. percent = 100.0 * he->stat.period / total;
  285. if (percent < ann->min_percent)
  286. goto find_next;
  287. }
  288. notes = symbol__annotation(he->ms.sym);
  289. if (notes->src == NULL) {
  290. find_next:
  291. if (key == K_LEFT)
  292. nd = rb_prev(nd);
  293. else
  294. nd = rb_next(nd);
  295. continue;
  296. }
  297. if (use_browser == 2) {
  298. int ret;
  299. int (*annotate)(struct hist_entry *he,
  300. struct evsel *evsel,
  301. struct hist_browser_timer *hbt);
  302. annotate = dlsym(perf_gtk_handle,
  303. "hist_entry__gtk_annotate");
  304. if (annotate == NULL) {
  305. ui__error("GTK browser not found!\n");
  306. return;
  307. }
  308. ret = annotate(he, evsel, NULL);
  309. if (!ret || !ann->skip_missing)
  310. return;
  311. /* skip missing symbols */
  312. nd = rb_next(nd);
  313. } else if (use_browser == 1) {
  314. key = hist_entry__tui_annotate(he, evsel, NULL, &ann->opts);
  315. switch (key) {
  316. case -1:
  317. if (!ann->skip_missing)
  318. return;
  319. /* fall through */
  320. case K_RIGHT:
  321. next = rb_next(nd);
  322. break;
  323. case K_LEFT:
  324. next = rb_prev(nd);
  325. break;
  326. default:
  327. return;
  328. }
  329. if (next != NULL)
  330. nd = next;
  331. } else {
  332. hist_entry__tty_annotate(he, evsel, ann);
  333. nd = rb_next(nd);
  334. }
  335. }
  336. }
  337. static int __cmd_annotate(struct perf_annotate *ann)
  338. {
  339. int ret;
  340. struct perf_session *session = ann->session;
  341. struct evsel *pos;
  342. u64 total_nr_samples;
  343. if (ann->cpu_list) {
  344. ret = perf_session__cpu_bitmap(session, ann->cpu_list,
  345. ann->cpu_bitmap);
  346. if (ret)
  347. goto out;
  348. }
  349. if (!ann->opts.objdump_path) {
  350. ret = perf_env__lookup_objdump(&session->header.env,
  351. &ann->opts.objdump_path);
  352. if (ret)
  353. goto out;
  354. }
  355. ret = perf_session__process_events(session);
  356. if (ret)
  357. goto out;
  358. if (dump_trace) {
  359. perf_session__fprintf_nr_events(session, stdout, false);
  360. evlist__fprintf_nr_events(session->evlist, stdout, false);
  361. goto out;
  362. }
  363. if (verbose > 3)
  364. perf_session__fprintf(session, stdout);
  365. if (verbose > 2)
  366. perf_session__fprintf_dsos(session, stdout);
  367. total_nr_samples = 0;
  368. evlist__for_each_entry(session->evlist, pos) {
  369. struct hists *hists = evsel__hists(pos);
  370. u32 nr_samples = hists->stats.nr_samples;
  371. if (nr_samples > 0) {
  372. total_nr_samples += nr_samples;
  373. hists__collapse_resort(hists, NULL);
  374. /* Don't sort callchain */
  375. evsel__reset_sample_bit(pos, CALLCHAIN);
  376. evsel__output_resort(pos, NULL);
  377. if (symbol_conf.event_group && !evsel__is_group_leader(pos))
  378. continue;
  379. hists__find_annotations(hists, pos, ann);
  380. }
  381. }
  382. if (total_nr_samples == 0) {
  383. ui__error("The %s data has no samples!\n", session->data->path);
  384. goto out;
  385. }
  386. if (use_browser == 2) {
  387. void (*show_annotations)(void);
  388. show_annotations = dlsym(perf_gtk_handle,
  389. "perf_gtk__show_annotations");
  390. if (show_annotations == NULL) {
  391. ui__error("GTK browser not found!\n");
  392. goto out;
  393. }
  394. show_annotations();
  395. }
  396. out:
  397. return ret;
  398. }
  399. static int parse_percent_limit(const struct option *opt, const char *str,
  400. int unset __maybe_unused)
  401. {
  402. struct perf_annotate *ann = opt->value;
  403. double pcnt = strtof(str, NULL);
  404. ann->min_percent = pcnt;
  405. return 0;
  406. }
  407. static const char * const annotate_usage[] = {
  408. "perf annotate [<options>]",
  409. NULL
  410. };
  411. int cmd_annotate(int argc, const char **argv)
  412. {
  413. struct perf_annotate annotate = {
  414. .tool = {
  415. .sample = process_sample_event,
  416. .mmap = perf_event__process_mmap,
  417. .mmap2 = perf_event__process_mmap2,
  418. .comm = perf_event__process_comm,
  419. .exit = perf_event__process_exit,
  420. .fork = perf_event__process_fork,
  421. .namespaces = perf_event__process_namespaces,
  422. .attr = perf_event__process_attr,
  423. .build_id = perf_event__process_build_id,
  424. .tracing_data = perf_event__process_tracing_data,
  425. .id_index = perf_event__process_id_index,
  426. .auxtrace_info = perf_event__process_auxtrace_info,
  427. .auxtrace = perf_event__process_auxtrace,
  428. .feature = process_feature_event,
  429. .ordered_events = true,
  430. .ordering_requires_timestamps = true,
  431. },
  432. .opts = annotation__default_options,
  433. };
  434. struct perf_data data = {
  435. .mode = PERF_DATA_MODE_READ,
  436. };
  437. struct itrace_synth_opts itrace_synth_opts = {
  438. .set = 0,
  439. };
  440. struct option options[] = {
  441. OPT_STRING('i', "input", &input_name, "file",
  442. "input file name"),
  443. OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
  444. "only consider symbols in these dsos"),
  445. OPT_STRING('s', "symbol", &annotate.sym_hist_filter, "symbol",
  446. "symbol to annotate"),
  447. OPT_BOOLEAN('f', "force", &data.force, "don't complain, do it"),
  448. OPT_INCR('v', "verbose", &verbose,
  449. "be more verbose (show symbol address, etc)"),
  450. OPT_BOOLEAN('q', "quiet", &quiet, "do now show any warnings or messages"),
  451. OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
  452. "dump raw trace in ASCII"),
  453. #ifdef HAVE_GTK2_SUPPORT
  454. OPT_BOOLEAN(0, "gtk", &annotate.use_gtk, "Use the GTK interface"),
  455. #endif
  456. #ifdef HAVE_SLANG_SUPPORT
  457. OPT_BOOLEAN(0, "tui", &annotate.use_tui, "Use the TUI interface"),
  458. #endif
  459. OPT_BOOLEAN(0, "stdio", &annotate.use_stdio, "Use the stdio interface"),
  460. OPT_BOOLEAN(0, "stdio2", &annotate.use_stdio2, "Use the stdio interface"),
  461. OPT_BOOLEAN(0, "ignore-vmlinux", &symbol_conf.ignore_vmlinux,
  462. "don't load vmlinux even if found"),
  463. OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
  464. "file", "vmlinux pathname"),
  465. OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
  466. "load module symbols - WARNING: use only with -k and LIVE kernel"),
  467. OPT_BOOLEAN('l', "print-line", &annotate.opts.print_lines,
  468. "print matching source lines (may be slow)"),
  469. OPT_BOOLEAN('P', "full-paths", &annotate.opts.full_path,
  470. "Don't shorten the displayed pathnames"),
  471. OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing,
  472. "Skip symbols that cannot be annotated"),
  473. OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group,
  474. &annotate.group_set,
  475. "Show event group information together"),
  476. OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
  477. OPT_CALLBACK(0, "symfs", NULL, "directory",
  478. "Look for files with symbols relative to this directory",
  479. symbol__config_symfs),
  480. OPT_BOOLEAN(0, "source", &annotate.opts.annotate_src,
  481. "Interleave source code with assembly code (default)"),
  482. OPT_BOOLEAN(0, "asm-raw", &annotate.opts.show_asm_raw,
  483. "Display raw encoding of assembly instructions (default)"),
  484. OPT_STRING('M', "disassembler-style", &annotate.opts.disassembler_style, "disassembler style",
  485. "Specify disassembler style (e.g. -M intel for intel syntax)"),
  486. OPT_STRING(0, "prefix", &annotate.opts.prefix, "prefix",
  487. "Add prefix to source file path names in programs (with --prefix-strip)"),
  488. OPT_STRING(0, "prefix-strip", &annotate.opts.prefix_strip, "N",
  489. "Strip first N entries of source file path name in programs (with --prefix)"),
  490. OPT_STRING(0, "objdump", &annotate.opts.objdump_path, "path",
  491. "objdump binary to use for disassembly and annotations"),
  492. OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
  493. "Enable symbol demangling"),
  494. OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
  495. "Enable kernel symbol demangling"),
  496. OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
  497. "Show event group information together"),
  498. OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
  499. "Show a column with the sum of periods"),
  500. OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
  501. "Show a column with the number of samples"),
  502. OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
  503. "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
  504. stdio__config_color, "always"),
  505. OPT_CALLBACK(0, "percent-type", &annotate.opts, "local-period",
  506. "Set percent type local/global-period/hits",
  507. annotate_parse_percent_type),
  508. OPT_CALLBACK(0, "percent-limit", &annotate, "percent",
  509. "Don't show entries under that percent", parse_percent_limit),
  510. OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
  511. "Instruction Tracing options\n" ITRACE_HELP,
  512. itrace_parse_synth_opts),
  513. OPT_END()
  514. };
  515. int ret;
  516. set_option_flag(options, 0, "show-total-period", PARSE_OPT_EXCLUSIVE);
  517. set_option_flag(options, 0, "show-nr-samples", PARSE_OPT_EXCLUSIVE);
  518. ret = hists__init();
  519. if (ret < 0)
  520. return ret;
  521. annotation_config__init(&annotate.opts);
  522. argc = parse_options(argc, argv, options, annotate_usage, 0);
  523. if (argc) {
  524. /*
  525. * Special case: if there's an argument left then assume that
  526. * it's a symbol filter:
  527. */
  528. if (argc > 1)
  529. usage_with_options(annotate_usage, options);
  530. annotate.sym_hist_filter = argv[0];
  531. }
  532. if (annotate_check_args(&annotate.opts) < 0)
  533. return -EINVAL;
  534. #ifdef HAVE_GTK2_SUPPORT
  535. if (symbol_conf.show_nr_samples && annotate.use_gtk) {
  536. pr_err("--show-nr-samples is not available in --gtk mode at this time\n");
  537. return ret;
  538. }
  539. #endif
  540. ret = symbol__validate_sym_arguments();
  541. if (ret)
  542. return ret;
  543. if (quiet)
  544. perf_quiet_option();
  545. data.path = input_name;
  546. annotate.session = perf_session__new(&data, &annotate.tool);
  547. if (IS_ERR(annotate.session))
  548. return PTR_ERR(annotate.session);
  549. annotate.session->itrace_synth_opts = &itrace_synth_opts;
  550. annotate.has_br_stack = perf_header__has_feat(&annotate.session->header,
  551. HEADER_BRANCH_STACK);
  552. if (annotate.group_set)
  553. evlist__force_leader(annotate.session->evlist);
  554. ret = symbol__annotation_init();
  555. if (ret < 0)
  556. goto out_delete;
  557. symbol_conf.try_vmlinux_path = true;
  558. ret = symbol__init(&annotate.session->header.env);
  559. if (ret < 0)
  560. goto out_delete;
  561. if (annotate.use_stdio || annotate.use_stdio2)
  562. use_browser = 0;
  563. #ifdef HAVE_SLANG_SUPPORT
  564. else if (annotate.use_tui)
  565. use_browser = 1;
  566. #endif
  567. #ifdef HAVE_GTK2_SUPPORT
  568. else if (annotate.use_gtk)
  569. use_browser = 2;
  570. #endif
  571. setup_browser(true);
  572. /*
  573. * Events of different processes may correspond to the same
  574. * symbol, we do not care about the processes in annotate,
  575. * set sort order to avoid repeated output.
  576. */
  577. sort_order = "dso,symbol";
  578. /*
  579. * Set SORT_MODE__BRANCH so that annotate display IPC/Cycle
  580. * if branch info is in perf data in TUI mode.
  581. */
  582. if ((use_browser == 1 || annotate.use_stdio2) && annotate.has_br_stack)
  583. sort__mode = SORT_MODE__BRANCH;
  584. if (setup_sorting(NULL) < 0)
  585. usage_with_options(annotate_usage, options);
  586. ret = __cmd_annotate(&annotate);
  587. out_delete:
  588. /*
  589. * Speed up the exit process, for large files this can
  590. * take quite a while.
  591. *
  592. * XXX Enable this when using valgrind or if we ever
  593. * librarize this command.
  594. *
  595. * Also experiment with obstacks to see how much speed
  596. * up we'll get here.
  597. *
  598. * perf_session__delete(session);
  599. */
  600. return ret;
  601. }