builtin-report.c 22 KB

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