builtin-report.c 23 KB

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