builtin-report.c 20 KB

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