builtin-report.c 23 KB

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