builtin-report.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. /*
  2. * builtin-report.c
  3. *
  4. * Builtin report 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/annotate.h"
  11. #include "util/color.h"
  12. #include <linux/list.h>
  13. #include "util/cache.h"
  14. #include <linux/rbtree.h>
  15. #include "util/symbol.h"
  16. #include "util/callchain.h"
  17. #include "util/strlist.h"
  18. #include "util/values.h"
  19. #include "perf.h"
  20. #include "util/debug.h"
  21. #include "util/evlist.h"
  22. #include "util/evsel.h"
  23. #include "util/header.h"
  24. #include "util/session.h"
  25. #include "util/tool.h"
  26. #include "util/parse-options.h"
  27. #include "util/parse-events.h"
  28. #include "util/thread.h"
  29. #include "util/sort.h"
  30. #include "util/hist.h"
  31. #include <linux/bitmap.h>
  32. struct perf_report {
  33. struct perf_tool tool;
  34. struct perf_session *session;
  35. char const *input_name;
  36. bool force, use_tui, use_gtk, use_stdio;
  37. bool hide_unresolved;
  38. bool dont_use_callchains;
  39. bool show_full_info;
  40. bool show_threads;
  41. bool inverted_callchain;
  42. struct perf_read_values show_threads_values;
  43. const char *pretty_printing_style;
  44. symbol_filter_t annotate_init;
  45. const char *cpu_list;
  46. const char *symbol_filter_str;
  47. DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
  48. };
  49. static int perf_report__add_branch_hist_entry(struct perf_tool *tool,
  50. struct addr_location *al,
  51. struct perf_sample *sample,
  52. struct perf_evsel *evsel,
  53. struct machine *machine)
  54. {
  55. struct perf_report *rep = container_of(tool, struct perf_report, tool);
  56. struct symbol *parent = NULL;
  57. int err = 0;
  58. unsigned i;
  59. struct hist_entry *he;
  60. struct branch_info *bi, *bx;
  61. if ((sort__has_parent || symbol_conf.use_callchain)
  62. && sample->callchain) {
  63. err = machine__resolve_callchain(machine, evsel, al->thread,
  64. sample, &parent);
  65. if (err)
  66. return err;
  67. }
  68. bi = machine__resolve_bstack(machine, al->thread,
  69. sample->branch_stack);
  70. if (!bi)
  71. return -ENOMEM;
  72. for (i = 0; i < sample->branch_stack->nr; i++) {
  73. if (rep->hide_unresolved && !(bi[i].from.sym && bi[i].to.sym))
  74. continue;
  75. /*
  76. * The report shows the percentage of total branches captured
  77. * and not events sampled. Thus we use a pseudo period of 1.
  78. */
  79. he = __hists__add_branch_entry(&evsel->hists, al, parent,
  80. &bi[i], 1);
  81. if (he) {
  82. struct annotation *notes;
  83. err = -ENOMEM;
  84. bx = he->branch_info;
  85. if (bx->from.sym && use_browser == 1 && sort__has_sym) {
  86. notes = symbol__annotation(bx->from.sym);
  87. if (!notes->src
  88. && symbol__alloc_hist(bx->from.sym) < 0)
  89. goto out;
  90. err = symbol__inc_addr_samples(bx->from.sym,
  91. bx->from.map,
  92. evsel->idx,
  93. bx->from.al_addr);
  94. if (err)
  95. goto out;
  96. }
  97. if (bx->to.sym && use_browser == 1 && sort__has_sym) {
  98. notes = symbol__annotation(bx->to.sym);
  99. if (!notes->src
  100. && symbol__alloc_hist(bx->to.sym) < 0)
  101. goto out;
  102. err = symbol__inc_addr_samples(bx->to.sym,
  103. bx->to.map,
  104. evsel->idx,
  105. bx->to.al_addr);
  106. if (err)
  107. goto out;
  108. }
  109. evsel->hists.stats.total_period += 1;
  110. hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
  111. err = 0;
  112. } else
  113. return -ENOMEM;
  114. }
  115. out:
  116. return err;
  117. }
  118. static int perf_evsel__add_hist_entry(struct perf_evsel *evsel,
  119. struct addr_location *al,
  120. struct perf_sample *sample,
  121. struct machine *machine)
  122. {
  123. struct symbol *parent = NULL;
  124. int err = 0;
  125. struct hist_entry *he;
  126. if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) {
  127. err = machine__resolve_callchain(machine, evsel, al->thread,
  128. sample, &parent);
  129. if (err)
  130. return err;
  131. }
  132. he = __hists__add_entry(&evsel->hists, al, parent, sample->period);
  133. if (he == NULL)
  134. return -ENOMEM;
  135. if (symbol_conf.use_callchain) {
  136. err = callchain_append(he->callchain,
  137. &callchain_cursor,
  138. sample->period);
  139. if (err)
  140. return err;
  141. }
  142. /*
  143. * Only in the newt browser we are doing integrated annotation,
  144. * so we don't allocated the extra space needed because the stdio
  145. * code will not use it.
  146. */
  147. if (he->ms.sym != NULL && use_browser == 1 && sort__has_sym) {
  148. struct annotation *notes = symbol__annotation(he->ms.sym);
  149. assert(evsel != NULL);
  150. err = -ENOMEM;
  151. if (notes->src == NULL && symbol__alloc_hist(he->ms.sym) < 0)
  152. goto out;
  153. err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
  154. }
  155. evsel->hists.stats.total_period += sample->period;
  156. hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
  157. out:
  158. return err;
  159. }
  160. static int process_sample_event(struct perf_tool *tool,
  161. union perf_event *event,
  162. struct perf_sample *sample,
  163. struct perf_evsel *evsel,
  164. struct machine *machine)
  165. {
  166. struct perf_report *rep = container_of(tool, struct perf_report, tool);
  167. struct addr_location al;
  168. if (perf_event__preprocess_sample(event, machine, &al, sample,
  169. rep->annotate_init) < 0) {
  170. fprintf(stderr, "problem processing %d event, skipping it.\n",
  171. event->header.type);
  172. return -1;
  173. }
  174. if (al.filtered || (rep->hide_unresolved && al.sym == NULL))
  175. return 0;
  176. if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
  177. return 0;
  178. if (sort__branch_mode == 1) {
  179. if (perf_report__add_branch_hist_entry(tool, &al, sample,
  180. evsel, machine)) {
  181. pr_debug("problem adding lbr entry, skipping event\n");
  182. return -1;
  183. }
  184. } else {
  185. if (al.map != NULL)
  186. al.map->dso->hit = 1;
  187. if (perf_evsel__add_hist_entry(evsel, &al, sample, machine)) {
  188. pr_debug("problem incrementing symbol period, skipping event\n");
  189. return -1;
  190. }
  191. }
  192. return 0;
  193. }
  194. static int process_read_event(struct perf_tool *tool,
  195. union perf_event *event,
  196. struct perf_sample *sample __maybe_unused,
  197. struct perf_evsel *evsel,
  198. struct machine *machine __maybe_unused)
  199. {
  200. struct perf_report *rep = container_of(tool, struct perf_report, tool);
  201. if (rep->show_threads) {
  202. const char *name = evsel ? perf_evsel__name(evsel) : "unknown";
  203. perf_read_values_add_value(&rep->show_threads_values,
  204. event->read.pid, event->read.tid,
  205. event->read.id,
  206. name,
  207. event->read.value);
  208. }
  209. dump_printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid,
  210. evsel ? perf_evsel__name(evsel) : "FAIL",
  211. event->read.value);
  212. return 0;
  213. }
  214. /* For pipe mode, sample_type is not currently set */
  215. static int perf_report__setup_sample_type(struct perf_report *rep)
  216. {
  217. struct perf_session *self = rep->session;
  218. u64 sample_type = perf_evlist__sample_type(self->evlist);
  219. if (!self->fd_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) {
  220. if (sort__has_parent) {
  221. ui__error("Selected --sort parent, but no "
  222. "callchain data. Did you call "
  223. "'perf record' without -g?\n");
  224. return -EINVAL;
  225. }
  226. if (symbol_conf.use_callchain) {
  227. ui__error("Selected -g but no callchain data. Did "
  228. "you call 'perf record' without -g?\n");
  229. return -1;
  230. }
  231. } else if (!rep->dont_use_callchains &&
  232. callchain_param.mode != CHAIN_NONE &&
  233. !symbol_conf.use_callchain) {
  234. symbol_conf.use_callchain = true;
  235. if (callchain_register_param(&callchain_param) < 0) {
  236. ui__error("Can't register callchain params.\n");
  237. return -EINVAL;
  238. }
  239. }
  240. if (sort__branch_mode == 1) {
  241. if (!self->fd_pipe &&
  242. !(sample_type & PERF_SAMPLE_BRANCH_STACK)) {
  243. ui__error("Selected -b but no branch data. "
  244. "Did you call perf record without -b?\n");
  245. return -1;
  246. }
  247. }
  248. return 0;
  249. }
  250. extern volatile int session_done;
  251. static void sig_handler(int sig __maybe_unused)
  252. {
  253. session_done = 1;
  254. }
  255. static size_t hists__fprintf_nr_sample_events(struct hists *self,
  256. const char *evname, FILE *fp)
  257. {
  258. size_t ret;
  259. char unit;
  260. unsigned long nr_samples = self->stats.nr_events[PERF_RECORD_SAMPLE];
  261. u64 nr_events = self->stats.total_period;
  262. nr_samples = convert_unit(nr_samples, &unit);
  263. ret = fprintf(fp, "# Samples: %lu%c", nr_samples, unit);
  264. if (evname != NULL)
  265. ret += fprintf(fp, " of event '%s'", evname);
  266. ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events);
  267. return ret + fprintf(fp, "\n#\n");
  268. }
  269. static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
  270. struct perf_report *rep,
  271. const char *help)
  272. {
  273. struct perf_evsel *pos;
  274. list_for_each_entry(pos, &evlist->entries, node) {
  275. struct hists *hists = &pos->hists;
  276. const char *evname = perf_evsel__name(pos);
  277. hists__fprintf_nr_sample_events(hists, evname, stdout);
  278. hists__fprintf(hists, NULL, false, true, 0, 0, stdout);
  279. fprintf(stdout, "\n\n");
  280. }
  281. if (sort_order == default_sort_order &&
  282. parent_pattern == default_parent_pattern) {
  283. fprintf(stdout, "#\n# (%s)\n#\n", help);
  284. if (rep->show_threads) {
  285. bool style = !strcmp(rep->pretty_printing_style, "raw");
  286. perf_read_values_display(stdout, &rep->show_threads_values,
  287. style);
  288. perf_read_values_destroy(&rep->show_threads_values);
  289. }
  290. }
  291. return 0;
  292. }
  293. static int __cmd_report(struct perf_report *rep)
  294. {
  295. int ret = -EINVAL;
  296. u64 nr_samples;
  297. struct perf_session *session = rep->session;
  298. struct perf_evsel *pos;
  299. struct map *kernel_map;
  300. struct kmap *kernel_kmap;
  301. const char *help = "For a higher level overview, try: perf report --sort comm,dso";
  302. signal(SIGINT, sig_handler);
  303. if (rep->cpu_list) {
  304. ret = perf_session__cpu_bitmap(session, rep->cpu_list,
  305. rep->cpu_bitmap);
  306. if (ret)
  307. goto out_delete;
  308. }
  309. if (use_browser <= 0)
  310. perf_session__fprintf_info(session, stdout, rep->show_full_info);
  311. if (rep->show_threads)
  312. perf_read_values_init(&rep->show_threads_values);
  313. ret = perf_report__setup_sample_type(rep);
  314. if (ret)
  315. goto out_delete;
  316. ret = perf_session__process_events(session, &rep->tool);
  317. if (ret)
  318. goto out_delete;
  319. kernel_map = session->host_machine.vmlinux_maps[MAP__FUNCTION];
  320. kernel_kmap = map__kmap(kernel_map);
  321. if (kernel_map == NULL ||
  322. (kernel_map->dso->hit &&
  323. (kernel_kmap->ref_reloc_sym == NULL ||
  324. kernel_kmap->ref_reloc_sym->addr == 0))) {
  325. const char *desc =
  326. "As no suitable kallsyms nor vmlinux was found, kernel samples\n"
  327. "can't be resolved.";
  328. if (kernel_map) {
  329. const struct dso *kdso = kernel_map->dso;
  330. if (!RB_EMPTY_ROOT(&kdso->symbols[MAP__FUNCTION])) {
  331. desc = "If some relocation was applied (e.g. "
  332. "kexec) symbols may be misresolved.";
  333. }
  334. }
  335. ui__warning(
  336. "Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n"
  337. "Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n"
  338. "Samples in kernel modules can't be resolved as well.\n\n",
  339. desc);
  340. }
  341. if (verbose > 3)
  342. perf_session__fprintf(session, stdout);
  343. if (verbose > 2)
  344. perf_session__fprintf_dsos(session, stdout);
  345. if (dump_trace) {
  346. perf_session__fprintf_nr_events(session, stdout);
  347. goto out_delete;
  348. }
  349. nr_samples = 0;
  350. list_for_each_entry(pos, &session->evlist->entries, node) {
  351. struct hists *hists = &pos->hists;
  352. if (pos->idx == 0)
  353. hists->symbol_filter_str = rep->symbol_filter_str;
  354. hists__collapse_resort(hists);
  355. hists__output_resort(hists);
  356. nr_samples += hists->stats.nr_events[PERF_RECORD_SAMPLE];
  357. }
  358. if (nr_samples == 0) {
  359. ui__error("The %s file has no samples!\n", session->filename);
  360. goto out_delete;
  361. }
  362. if (use_browser > 0) {
  363. if (use_browser == 1) {
  364. perf_evlist__tui_browse_hists(session->evlist, help,
  365. NULL, NULL, 0);
  366. } else if (use_browser == 2) {
  367. perf_evlist__gtk_browse_hists(session->evlist, help,
  368. NULL, NULL, 0);
  369. }
  370. } else
  371. perf_evlist__tty_browse_hists(session->evlist, rep, help);
  372. out_delete:
  373. /*
  374. * Speed up the exit process, for large files this can
  375. * take quite a while.
  376. *
  377. * XXX Enable this when using valgrind or if we ever
  378. * librarize this command.
  379. *
  380. * Also experiment with obstacks to see how much speed
  381. * up we'll get here.
  382. *
  383. * perf_session__delete(session);
  384. */
  385. return ret;
  386. }
  387. static int
  388. parse_callchain_opt(const struct option *opt, const char *arg, int unset)
  389. {
  390. struct perf_report *rep = (struct perf_report *)opt->value;
  391. char *tok, *tok2;
  392. char *endptr;
  393. /*
  394. * --no-call-graph
  395. */
  396. if (unset) {
  397. rep->dont_use_callchains = true;
  398. return 0;
  399. }
  400. symbol_conf.use_callchain = true;
  401. if (!arg)
  402. return 0;
  403. tok = strtok((char *)arg, ",");
  404. if (!tok)
  405. return -1;
  406. /* get the output mode */
  407. if (!strncmp(tok, "graph", strlen(arg)))
  408. callchain_param.mode = CHAIN_GRAPH_ABS;
  409. else if (!strncmp(tok, "flat", strlen(arg)))
  410. callchain_param.mode = CHAIN_FLAT;
  411. else if (!strncmp(tok, "fractal", strlen(arg)))
  412. callchain_param.mode = CHAIN_GRAPH_REL;
  413. else if (!strncmp(tok, "none", strlen(arg))) {
  414. callchain_param.mode = CHAIN_NONE;
  415. symbol_conf.use_callchain = false;
  416. return 0;
  417. }
  418. else
  419. return -1;
  420. /* get the min percentage */
  421. tok = strtok(NULL, ",");
  422. if (!tok)
  423. goto setup;
  424. callchain_param.min_percent = strtod(tok, &endptr);
  425. if (tok == endptr)
  426. return -1;
  427. /* get the print limit */
  428. tok2 = strtok(NULL, ",");
  429. if (!tok2)
  430. goto setup;
  431. if (tok2[0] != 'c') {
  432. callchain_param.print_limit = strtoul(tok2, &endptr, 0);
  433. tok2 = strtok(NULL, ",");
  434. if (!tok2)
  435. goto setup;
  436. }
  437. /* get the call chain order */
  438. if (!strcmp(tok2, "caller"))
  439. callchain_param.order = ORDER_CALLER;
  440. else if (!strcmp(tok2, "callee"))
  441. callchain_param.order = ORDER_CALLEE;
  442. else
  443. return -1;
  444. setup:
  445. if (callchain_register_param(&callchain_param) < 0) {
  446. fprintf(stderr, "Can't register callchain params\n");
  447. return -1;
  448. }
  449. return 0;
  450. }
  451. static int
  452. parse_branch_mode(const struct option *opt __maybe_unused,
  453. const char *str __maybe_unused, int unset)
  454. {
  455. sort__branch_mode = !unset;
  456. return 0;
  457. }
  458. int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
  459. {
  460. struct perf_session *session;
  461. struct stat st;
  462. bool has_br_stack = false;
  463. int ret = -1;
  464. char callchain_default_opt[] = "fractal,0.5,callee";
  465. const char * const report_usage[] = {
  466. "perf report [<options>]",
  467. NULL
  468. };
  469. struct perf_report report = {
  470. .tool = {
  471. .sample = process_sample_event,
  472. .mmap = perf_event__process_mmap,
  473. .comm = perf_event__process_comm,
  474. .exit = perf_event__process_task,
  475. .fork = perf_event__process_task,
  476. .lost = perf_event__process_lost,
  477. .read = process_read_event,
  478. .attr = perf_event__process_attr,
  479. .event_type = perf_event__process_event_type,
  480. .tracing_data = perf_event__process_tracing_data,
  481. .build_id = perf_event__process_build_id,
  482. .ordered_samples = true,
  483. .ordering_requires_timestamps = true,
  484. },
  485. .pretty_printing_style = "normal",
  486. };
  487. const struct option options[] = {
  488. OPT_STRING('i', "input", &report.input_name, "file",
  489. "input file name"),
  490. OPT_INCR('v', "verbose", &verbose,
  491. "be more verbose (show symbol address, etc)"),
  492. OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
  493. "dump raw trace in ASCII"),
  494. OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
  495. "file", "vmlinux pathname"),
  496. OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
  497. "file", "kallsyms pathname"),
  498. OPT_BOOLEAN('f', "force", &report.force, "don't complain, do it"),
  499. OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
  500. "load module symbols - WARNING: use only with -k and LIVE kernel"),
  501. OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
  502. "Show a column with the number of samples"),
  503. OPT_BOOLEAN('T', "threads", &report.show_threads,
  504. "Show per-thread event counters"),
  505. OPT_STRING(0, "pretty", &report.pretty_printing_style, "key",
  506. "pretty printing style key: normal raw"),
  507. OPT_BOOLEAN(0, "tui", &report.use_tui, "Use the TUI interface"),
  508. OPT_BOOLEAN(0, "gtk", &report.use_gtk, "Use the GTK2 interface"),
  509. OPT_BOOLEAN(0, "stdio", &report.use_stdio,
  510. "Use the stdio interface"),
  511. OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
  512. "sort by key(s): pid, comm, dso, symbol, parent, dso_to,"
  513. " dso_from, symbol_to, symbol_from, mispredict"),
  514. OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
  515. "Show sample percentage for different cpu modes"),
  516. OPT_STRING('p', "parent", &parent_pattern, "regex",
  517. "regex filter to identify parent, see: '--sort parent'"),
  518. OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
  519. "Only display entries with parent-match"),
  520. OPT_CALLBACK_DEFAULT('g', "call-graph", &report, "output_type,min_percent[,print_limit],call_order",
  521. "Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold, optional print limit and callchain order. "
  522. "Default: fractal,0.5,callee", &parse_callchain_opt, callchain_default_opt),
  523. OPT_BOOLEAN('G', "inverted", &report.inverted_callchain,
  524. "alias for inverted call graph"),
  525. OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
  526. "only consider symbols in these dsos"),
  527. OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
  528. "only consider symbols in these comms"),
  529. OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
  530. "only consider these symbols"),
  531. OPT_STRING(0, "symbol-filter", &report.symbol_filter_str, "filter",
  532. "only show symbols that (partially) match with this filter"),
  533. OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str,
  534. "width[,width...]",
  535. "don't try to adjust column width, use these fixed values"),
  536. OPT_STRING('t', "field-separator", &symbol_conf.field_sep, "separator",
  537. "separator for columns, no spaces will be added between "
  538. "columns '.' is reserved."),
  539. OPT_BOOLEAN('U', "hide-unresolved", &report.hide_unresolved,
  540. "Only display entries resolved to a symbol"),
  541. OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
  542. "Look for files with symbols relative to this directory"),
  543. OPT_STRING('C', "cpu", &report.cpu_list, "cpu",
  544. "list of cpus to profile"),
  545. OPT_BOOLEAN('I', "show-info", &report.show_full_info,
  546. "Display extended information about perf.data file"),
  547. OPT_BOOLEAN(0, "source", &symbol_conf.annotate_src,
  548. "Interleave source code with assembly code (default)"),
  549. OPT_BOOLEAN(0, "asm-raw", &symbol_conf.annotate_asm_raw,
  550. "Display raw encoding of assembly instructions (default)"),
  551. OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
  552. "Specify disassembler style (e.g. -M intel for intel syntax)"),
  553. OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
  554. "Show a column with the sum of periods"),
  555. OPT_CALLBACK_NOOPT('b', "branch-stack", &sort__branch_mode, "",
  556. "use branch records for histogram filling", parse_branch_mode),
  557. OPT_STRING(0, "objdump", &objdump_path, "path",
  558. "objdump binary to use for disassembly and annotations"),
  559. OPT_END()
  560. };
  561. argc = parse_options(argc, argv, options, report_usage, 0);
  562. if (report.use_stdio)
  563. use_browser = 0;
  564. else if (report.use_tui)
  565. use_browser = 1;
  566. else if (report.use_gtk)
  567. use_browser = 2;
  568. if (report.inverted_callchain)
  569. callchain_param.order = ORDER_CALLER;
  570. if (!report.input_name || !strlen(report.input_name)) {
  571. if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))
  572. report.input_name = "-";
  573. else
  574. report.input_name = "perf.data";
  575. }
  576. session = perf_session__new(report.input_name, O_RDONLY,
  577. report.force, false, &report.tool);
  578. if (session == NULL)
  579. return -ENOMEM;
  580. report.session = session;
  581. has_br_stack = perf_header__has_feat(&session->header,
  582. HEADER_BRANCH_STACK);
  583. if (sort__branch_mode == -1 && has_br_stack)
  584. sort__branch_mode = 1;
  585. /* sort__branch_mode could be 0 if --no-branch-stack */
  586. if (sort__branch_mode == 1) {
  587. /*
  588. * if no sort_order is provided, then specify
  589. * branch-mode specific order
  590. */
  591. if (sort_order == default_sort_order)
  592. sort_order = "comm,dso_from,symbol_from,"
  593. "dso_to,symbol_to";
  594. }
  595. if (strcmp(report.input_name, "-") != 0)
  596. setup_browser(true);
  597. else {
  598. use_browser = 0;
  599. perf_hpp__init(false, false);
  600. }
  601. setup_sorting(report_usage, options);
  602. /*
  603. * Only in the newt browser we are doing integrated annotation,
  604. * so don't allocate extra space that won't be used in the stdio
  605. * implementation.
  606. */
  607. if (use_browser == 1 && sort__has_sym) {
  608. symbol_conf.priv_size = sizeof(struct annotation);
  609. report.annotate_init = symbol__annotate_init;
  610. /*
  611. * For searching by name on the "Browse map details".
  612. * providing it only in verbose mode not to bloat too
  613. * much struct symbol.
  614. */
  615. if (verbose) {
  616. /*
  617. * XXX: Need to provide a less kludgy way to ask for
  618. * more space per symbol, the u32 is for the index on
  619. * the ui browser.
  620. * See symbol__browser_index.
  621. */
  622. symbol_conf.priv_size += sizeof(u32);
  623. symbol_conf.sort_by_name = true;
  624. }
  625. }
  626. if (symbol__init() < 0)
  627. goto error;
  628. if (parent_pattern != default_parent_pattern) {
  629. if (sort_dimension__add("parent") < 0)
  630. goto error;
  631. /*
  632. * Only show the parent fields if we explicitly
  633. * sort that way. If we only use parent machinery
  634. * for filtering, we don't want it.
  635. */
  636. if (!strstr(sort_order, "parent"))
  637. sort_parent.elide = 1;
  638. } else
  639. symbol_conf.exclude_other = false;
  640. if (argc) {
  641. /*
  642. * Special case: if there's an argument left then assume that
  643. * it's a symbol filter:
  644. */
  645. if (argc > 1)
  646. usage_with_options(report_usage, options);
  647. report.symbol_filter_str = argv[0];
  648. }
  649. sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list, "comm", stdout);
  650. if (sort__branch_mode == 1) {
  651. sort_entry__setup_elide(&sort_dso_from, symbol_conf.dso_from_list, "dso_from", stdout);
  652. sort_entry__setup_elide(&sort_dso_to, symbol_conf.dso_to_list, "dso_to", stdout);
  653. sort_entry__setup_elide(&sort_sym_from, symbol_conf.sym_from_list, "sym_from", stdout);
  654. sort_entry__setup_elide(&sort_sym_to, symbol_conf.sym_to_list, "sym_to", stdout);
  655. } else {
  656. sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "dso", stdout);
  657. sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list, "symbol", stdout);
  658. }
  659. ret = __cmd_report(&report);
  660. error:
  661. perf_session__delete(session);
  662. return ret;
  663. }