builtin-report.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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 "util/data.h"
  32. #include "arch/common.h"
  33. #include "util/auxtrace.h"
  34. #include <dlfcn.h>
  35. #include <linux/bitmap.h>
  36. struct report {
  37. struct perf_tool tool;
  38. struct perf_session *session;
  39. bool force, use_tui, use_gtk, use_stdio;
  40. bool hide_unresolved;
  41. bool dont_use_callchains;
  42. bool show_full_info;
  43. bool show_threads;
  44. bool inverted_callchain;
  45. bool mem_mode;
  46. bool header;
  47. bool header_only;
  48. bool nonany_branch_mode;
  49. int max_stack;
  50. struct perf_read_values show_threads_values;
  51. const char *pretty_printing_style;
  52. const char *cpu_list;
  53. const char *symbol_filter_str;
  54. float min_percent;
  55. u64 nr_entries;
  56. u64 queue_size;
  57. DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
  58. };
  59. static int report__config(const char *var, const char *value, void *cb)
  60. {
  61. struct report *rep = cb;
  62. if (!strcmp(var, "report.group")) {
  63. symbol_conf.event_group = perf_config_bool(var, value);
  64. return 0;
  65. }
  66. if (!strcmp(var, "report.percent-limit")) {
  67. rep->min_percent = strtof(value, NULL);
  68. return 0;
  69. }
  70. if (!strcmp(var, "report.children")) {
  71. symbol_conf.cumulate_callchain = perf_config_bool(var, value);
  72. return 0;
  73. }
  74. if (!strcmp(var, "report.queue-size")) {
  75. rep->queue_size = perf_config_u64(var, value);
  76. return 0;
  77. }
  78. return perf_default_config(var, value, cb);
  79. }
  80. static int hist_iter__report_callback(struct hist_entry_iter *iter,
  81. struct addr_location *al, bool single,
  82. void *arg)
  83. {
  84. int err = 0;
  85. struct report *rep = arg;
  86. struct hist_entry *he = iter->he;
  87. struct perf_evsel *evsel = iter->evsel;
  88. struct mem_info *mi;
  89. struct branch_info *bi;
  90. if (!ui__has_annotation())
  91. return 0;
  92. hist__account_cycles(iter->sample->branch_stack, al, iter->sample,
  93. rep->nonany_branch_mode);
  94. if (sort__mode == SORT_MODE__BRANCH) {
  95. bi = he->branch_info;
  96. err = addr_map_symbol__inc_samples(&bi->from, evsel->idx);
  97. if (err)
  98. goto out;
  99. err = addr_map_symbol__inc_samples(&bi->to, evsel->idx);
  100. } else if (rep->mem_mode) {
  101. mi = he->mem_info;
  102. err = addr_map_symbol__inc_samples(&mi->daddr, evsel->idx);
  103. if (err)
  104. goto out;
  105. err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
  106. } else if (symbol_conf.cumulate_callchain) {
  107. if (single)
  108. err = hist_entry__inc_addr_samples(he, evsel->idx,
  109. al->addr);
  110. } else {
  111. err = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
  112. }
  113. out:
  114. return err;
  115. }
  116. static int process_sample_event(struct perf_tool *tool,
  117. union perf_event *event,
  118. struct perf_sample *sample,
  119. struct perf_evsel *evsel,
  120. struct machine *machine)
  121. {
  122. struct report *rep = container_of(tool, struct report, tool);
  123. struct addr_location al;
  124. struct hist_entry_iter iter = {
  125. .evsel = evsel,
  126. .sample = sample,
  127. .hide_unresolved = rep->hide_unresolved,
  128. .add_entry_cb = hist_iter__report_callback,
  129. };
  130. int ret = 0;
  131. if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
  132. pr_debug("problem processing %d event, skipping it.\n",
  133. event->header.type);
  134. return -1;
  135. }
  136. if (rep->hide_unresolved && al.sym == NULL)
  137. goto out_put;
  138. if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
  139. goto out_put;
  140. if (sort__mode == SORT_MODE__BRANCH)
  141. iter.ops = &hist_iter_branch;
  142. else if (rep->mem_mode)
  143. iter.ops = &hist_iter_mem;
  144. else if (symbol_conf.cumulate_callchain)
  145. iter.ops = &hist_iter_cumulative;
  146. else
  147. iter.ops = &hist_iter_normal;
  148. if (al.map != NULL)
  149. al.map->dso->hit = 1;
  150. ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep);
  151. if (ret < 0)
  152. pr_debug("problem adding hist entry, skipping event\n");
  153. out_put:
  154. addr_location__put(&al);
  155. return ret;
  156. }
  157. static int process_read_event(struct perf_tool *tool,
  158. union perf_event *event,
  159. struct perf_sample *sample __maybe_unused,
  160. struct perf_evsel *evsel,
  161. struct machine *machine __maybe_unused)
  162. {
  163. struct report *rep = container_of(tool, struct report, tool);
  164. if (rep->show_threads) {
  165. const char *name = evsel ? perf_evsel__name(evsel) : "unknown";
  166. perf_read_values_add_value(&rep->show_threads_values,
  167. event->read.pid, event->read.tid,
  168. event->read.id,
  169. name,
  170. event->read.value);
  171. }
  172. dump_printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid,
  173. evsel ? perf_evsel__name(evsel) : "FAIL",
  174. event->read.value);
  175. return 0;
  176. }
  177. /* For pipe mode, sample_type is not currently set */
  178. static int report__setup_sample_type(struct report *rep)
  179. {
  180. struct perf_session *session = rep->session;
  181. u64 sample_type = perf_evlist__combined_sample_type(session->evlist);
  182. bool is_pipe = perf_data_file__is_pipe(session->file);
  183. if (!is_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) {
  184. if (sort__has_parent) {
  185. ui__error("Selected --sort parent, but no "
  186. "callchain data. Did you call "
  187. "'perf record' without -g?\n");
  188. return -EINVAL;
  189. }
  190. if (symbol_conf.use_callchain) {
  191. ui__error("Selected -g or --branch-history but no "
  192. "callchain data. Did\n"
  193. "you call 'perf record' without -g?\n");
  194. return -1;
  195. }
  196. } else if (!rep->dont_use_callchains &&
  197. callchain_param.mode != CHAIN_NONE &&
  198. !symbol_conf.use_callchain) {
  199. symbol_conf.use_callchain = true;
  200. if (callchain_register_param(&callchain_param) < 0) {
  201. ui__error("Can't register callchain params.\n");
  202. return -EINVAL;
  203. }
  204. }
  205. if (symbol_conf.cumulate_callchain) {
  206. /* Silently ignore if callchain is missing */
  207. if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) {
  208. symbol_conf.cumulate_callchain = false;
  209. perf_hpp__cancel_cumulate();
  210. }
  211. }
  212. if (sort__mode == SORT_MODE__BRANCH) {
  213. if (!is_pipe &&
  214. !(sample_type & PERF_SAMPLE_BRANCH_STACK)) {
  215. ui__error("Selected -b but no branch data. "
  216. "Did you call perf record without -b?\n");
  217. return -1;
  218. }
  219. }
  220. if (symbol_conf.use_callchain || symbol_conf.cumulate_callchain) {
  221. if ((sample_type & PERF_SAMPLE_REGS_USER) &&
  222. (sample_type & PERF_SAMPLE_STACK_USER))
  223. callchain_param.record_mode = CALLCHAIN_DWARF;
  224. else if (sample_type & PERF_SAMPLE_BRANCH_STACK)
  225. callchain_param.record_mode = CALLCHAIN_LBR;
  226. else
  227. callchain_param.record_mode = CALLCHAIN_FP;
  228. }
  229. /* ??? handle more cases than just ANY? */
  230. if (!(perf_evlist__combined_branch_type(session->evlist) &
  231. PERF_SAMPLE_BRANCH_ANY))
  232. rep->nonany_branch_mode = true;
  233. return 0;
  234. }
  235. static void sig_handler(int sig __maybe_unused)
  236. {
  237. session_done = 1;
  238. }
  239. static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report *rep,
  240. const char *evname, FILE *fp)
  241. {
  242. size_t ret;
  243. char unit;
  244. unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
  245. u64 nr_events = hists->stats.total_period;
  246. struct perf_evsel *evsel = hists_to_evsel(hists);
  247. char buf[512];
  248. size_t size = sizeof(buf);
  249. if (symbol_conf.filter_relative) {
  250. nr_samples = hists->stats.nr_non_filtered_samples;
  251. nr_events = hists->stats.total_non_filtered_period;
  252. }
  253. if (perf_evsel__is_group_event(evsel)) {
  254. struct perf_evsel *pos;
  255. perf_evsel__group_desc(evsel, buf, size);
  256. evname = buf;
  257. for_each_group_member(pos, evsel) {
  258. const struct hists *pos_hists = evsel__hists(pos);
  259. if (symbol_conf.filter_relative) {
  260. nr_samples += pos_hists->stats.nr_non_filtered_samples;
  261. nr_events += pos_hists->stats.total_non_filtered_period;
  262. } else {
  263. nr_samples += pos_hists->stats.nr_events[PERF_RECORD_SAMPLE];
  264. nr_events += pos_hists->stats.total_period;
  265. }
  266. }
  267. }
  268. nr_samples = convert_unit(nr_samples, &unit);
  269. ret = fprintf(fp, "# Samples: %lu%c", nr_samples, unit);
  270. if (evname != NULL)
  271. ret += fprintf(fp, " of event '%s'", evname);
  272. if (symbol_conf.show_ref_callgraph &&
  273. strstr(evname, "call-graph=no")) {
  274. ret += fprintf(fp, ", show reference callgraph");
  275. }
  276. if (rep->mem_mode) {
  277. ret += fprintf(fp, "\n# Total weight : %" PRIu64, nr_events);
  278. ret += fprintf(fp, "\n# Sort order : %s", sort_order ? : default_mem_sort_order);
  279. } else
  280. ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events);
  281. return ret + fprintf(fp, "\n#\n");
  282. }
  283. static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
  284. struct report *rep,
  285. const char *help)
  286. {
  287. struct perf_evsel *pos;
  288. fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n", evlist->stats.total_lost_samples);
  289. evlist__for_each(evlist, pos) {
  290. struct hists *hists = evsel__hists(pos);
  291. const char *evname = perf_evsel__name(pos);
  292. if (symbol_conf.event_group &&
  293. !perf_evsel__is_group_leader(pos))
  294. continue;
  295. hists__fprintf_nr_sample_events(hists, rep, evname, stdout);
  296. hists__fprintf(hists, true, 0, 0, rep->min_percent, stdout);
  297. fprintf(stdout, "\n\n");
  298. }
  299. if (sort_order == NULL &&
  300. parent_pattern == default_parent_pattern)
  301. fprintf(stdout, "#\n# (%s)\n#\n", help);
  302. if (rep->show_threads) {
  303. bool style = !strcmp(rep->pretty_printing_style, "raw");
  304. perf_read_values_display(stdout, &rep->show_threads_values,
  305. style);
  306. perf_read_values_destroy(&rep->show_threads_values);
  307. }
  308. return 0;
  309. }
  310. static void report__warn_kptr_restrict(const struct report *rep)
  311. {
  312. struct map *kernel_map = rep->session->machines.host.vmlinux_maps[MAP__FUNCTION];
  313. struct kmap *kernel_kmap = kernel_map ? map__kmap(kernel_map) : NULL;
  314. if (kernel_map == NULL ||
  315. (kernel_map->dso->hit &&
  316. (kernel_kmap->ref_reloc_sym == NULL ||
  317. kernel_kmap->ref_reloc_sym->addr == 0))) {
  318. const char *desc =
  319. "As no suitable kallsyms nor vmlinux was found, kernel samples\n"
  320. "can't be resolved.";
  321. if (kernel_map) {
  322. const struct dso *kdso = kernel_map->dso;
  323. if (!RB_EMPTY_ROOT(&kdso->symbols[MAP__FUNCTION])) {
  324. desc = "If some relocation was applied (e.g. "
  325. "kexec) symbols may be misresolved.";
  326. }
  327. }
  328. ui__warning(
  329. "Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n"
  330. "Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n"
  331. "Samples in kernel modules can't be resolved as well.\n\n",
  332. desc);
  333. }
  334. }
  335. static int report__gtk_browse_hists(struct report *rep, const char *help)
  336. {
  337. int (*hist_browser)(struct perf_evlist *evlist, const char *help,
  338. struct hist_browser_timer *timer, float min_pcnt);
  339. hist_browser = dlsym(perf_gtk_handle, "perf_evlist__gtk_browse_hists");
  340. if (hist_browser == NULL) {
  341. ui__error("GTK browser not found!\n");
  342. return -1;
  343. }
  344. return hist_browser(rep->session->evlist, help, NULL, rep->min_percent);
  345. }
  346. static int report__browse_hists(struct report *rep)
  347. {
  348. int ret;
  349. struct perf_session *session = rep->session;
  350. struct perf_evlist *evlist = session->evlist;
  351. const char *help = "For a higher level overview, try: perf report --sort comm,dso";
  352. switch (use_browser) {
  353. case 1:
  354. ret = perf_evlist__tui_browse_hists(evlist, help, NULL,
  355. rep->min_percent,
  356. &session->header.env);
  357. /*
  358. * Usually "ret" is the last pressed key, and we only
  359. * care if the key notifies us to switch data file.
  360. */
  361. if (ret != K_SWITCH_INPUT_DATA)
  362. ret = 0;
  363. break;
  364. case 2:
  365. ret = report__gtk_browse_hists(rep, help);
  366. break;
  367. default:
  368. ret = perf_evlist__tty_browse_hists(evlist, rep, help);
  369. break;
  370. }
  371. return ret;
  372. }
  373. static void report__collapse_hists(struct report *rep)
  374. {
  375. struct ui_progress prog;
  376. struct perf_evsel *pos;
  377. ui_progress__init(&prog, rep->nr_entries, "Merging related events...");
  378. evlist__for_each(rep->session->evlist, pos) {
  379. struct hists *hists = evsel__hists(pos);
  380. if (pos->idx == 0)
  381. hists->symbol_filter_str = rep->symbol_filter_str;
  382. hists__collapse_resort(hists, &prog);
  383. /* Non-group events are considered as leader */
  384. if (symbol_conf.event_group &&
  385. !perf_evsel__is_group_leader(pos)) {
  386. struct hists *leader_hists = evsel__hists(pos->leader);
  387. hists__match(leader_hists, hists);
  388. hists__link(leader_hists, hists);
  389. }
  390. }
  391. ui_progress__finish();
  392. }
  393. static void report__output_resort(struct report *rep)
  394. {
  395. struct ui_progress prog;
  396. struct perf_evsel *pos;
  397. ui_progress__init(&prog, rep->nr_entries, "Sorting events for output...");
  398. evlist__for_each(rep->session->evlist, pos)
  399. hists__output_resort(evsel__hists(pos), &prog);
  400. ui_progress__finish();
  401. }
  402. static int __cmd_report(struct report *rep)
  403. {
  404. int ret;
  405. struct perf_session *session = rep->session;
  406. struct perf_evsel *pos;
  407. struct perf_data_file *file = session->file;
  408. signal(SIGINT, sig_handler);
  409. if (rep->cpu_list) {
  410. ret = perf_session__cpu_bitmap(session, rep->cpu_list,
  411. rep->cpu_bitmap);
  412. if (ret)
  413. return ret;
  414. }
  415. if (rep->show_threads)
  416. perf_read_values_init(&rep->show_threads_values);
  417. ret = report__setup_sample_type(rep);
  418. if (ret)
  419. return ret;
  420. ret = perf_session__process_events(session);
  421. if (ret)
  422. return ret;
  423. report__warn_kptr_restrict(rep);
  424. evlist__for_each(session->evlist, pos)
  425. rep->nr_entries += evsel__hists(pos)->nr_entries;
  426. if (use_browser == 0) {
  427. if (verbose > 3)
  428. perf_session__fprintf(session, stdout);
  429. if (verbose > 2)
  430. perf_session__fprintf_dsos(session, stdout);
  431. if (dump_trace) {
  432. perf_session__fprintf_nr_events(session, stdout);
  433. perf_evlist__fprintf_nr_events(session->evlist, stdout);
  434. return 0;
  435. }
  436. }
  437. report__collapse_hists(rep);
  438. if (session_done())
  439. return 0;
  440. /*
  441. * recalculate number of entries after collapsing since it
  442. * might be changed during the collapse phase.
  443. */
  444. rep->nr_entries = 0;
  445. evlist__for_each(session->evlist, pos)
  446. rep->nr_entries += evsel__hists(pos)->nr_entries;
  447. if (rep->nr_entries == 0) {
  448. ui__error("The %s file has no samples!\n", file->path);
  449. return 0;
  450. }
  451. report__output_resort(rep);
  452. return report__browse_hists(rep);
  453. }
  454. static int
  455. report_parse_callchain_opt(const struct option *opt, const char *arg, int unset)
  456. {
  457. struct report *rep = (struct report *)opt->value;
  458. /*
  459. * --no-call-graph
  460. */
  461. if (unset) {
  462. rep->dont_use_callchains = true;
  463. return 0;
  464. }
  465. return parse_callchain_report_opt(arg);
  466. }
  467. int
  468. report_parse_ignore_callees_opt(const struct option *opt __maybe_unused,
  469. const char *arg, int unset __maybe_unused)
  470. {
  471. if (arg) {
  472. int err = regcomp(&ignore_callees_regex, arg, REG_EXTENDED);
  473. if (err) {
  474. char buf[BUFSIZ];
  475. regerror(err, &ignore_callees_regex, buf, sizeof(buf));
  476. pr_err("Invalid --ignore-callees regex: %s\n%s", arg, buf);
  477. return -1;
  478. }
  479. have_ignore_callees = 1;
  480. }
  481. return 0;
  482. }
  483. static int
  484. parse_branch_mode(const struct option *opt __maybe_unused,
  485. const char *str __maybe_unused, int unset)
  486. {
  487. int *branch_mode = opt->value;
  488. *branch_mode = !unset;
  489. return 0;
  490. }
  491. static int
  492. parse_percent_limit(const struct option *opt, const char *str,
  493. int unset __maybe_unused)
  494. {
  495. struct report *rep = opt->value;
  496. rep->min_percent = strtof(str, NULL);
  497. return 0;
  498. }
  499. int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
  500. {
  501. struct perf_session *session;
  502. struct itrace_synth_opts itrace_synth_opts = { .set = 0, };
  503. struct stat st;
  504. bool has_br_stack = false;
  505. int branch_mode = -1;
  506. bool branch_call_mode = false;
  507. char callchain_default_opt[] = "fractal,0.5,callee";
  508. const char * const report_usage[] = {
  509. "perf report [<options>]",
  510. NULL
  511. };
  512. struct report report = {
  513. .tool = {
  514. .sample = process_sample_event,
  515. .mmap = perf_event__process_mmap,
  516. .mmap2 = perf_event__process_mmap2,
  517. .comm = perf_event__process_comm,
  518. .exit = perf_event__process_exit,
  519. .fork = perf_event__process_fork,
  520. .lost = perf_event__process_lost,
  521. .read = process_read_event,
  522. .attr = perf_event__process_attr,
  523. .tracing_data = perf_event__process_tracing_data,
  524. .build_id = perf_event__process_build_id,
  525. .id_index = perf_event__process_id_index,
  526. .auxtrace_info = perf_event__process_auxtrace_info,
  527. .auxtrace = perf_event__process_auxtrace,
  528. .ordered_events = true,
  529. .ordering_requires_timestamps = true,
  530. },
  531. .max_stack = PERF_MAX_STACK_DEPTH,
  532. .pretty_printing_style = "normal",
  533. };
  534. const struct option options[] = {
  535. OPT_STRING('i', "input", &input_name, "file",
  536. "input file name"),
  537. OPT_INCR('v', "verbose", &verbose,
  538. "be more verbose (show symbol address, etc)"),
  539. OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
  540. "dump raw trace in ASCII"),
  541. OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
  542. "file", "vmlinux pathname"),
  543. OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
  544. "file", "kallsyms pathname"),
  545. OPT_BOOLEAN('f', "force", &report.force, "don't complain, do it"),
  546. OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
  547. "load module symbols - WARNING: use only with -k and LIVE kernel"),
  548. OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
  549. "Show a column with the number of samples"),
  550. OPT_BOOLEAN('T', "threads", &report.show_threads,
  551. "Show per-thread event counters"),
  552. OPT_STRING(0, "pretty", &report.pretty_printing_style, "key",
  553. "pretty printing style key: normal raw"),
  554. OPT_BOOLEAN(0, "tui", &report.use_tui, "Use the TUI interface"),
  555. OPT_BOOLEAN(0, "gtk", &report.use_gtk, "Use the GTK2 interface"),
  556. OPT_BOOLEAN(0, "stdio", &report.use_stdio,
  557. "Use the stdio interface"),
  558. OPT_BOOLEAN(0, "header", &report.header, "Show data header."),
  559. OPT_BOOLEAN(0, "header-only", &report.header_only,
  560. "Show only data header."),
  561. OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
  562. "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..."
  563. " Please refer the man page for the complete list."),
  564. OPT_STRING('F', "fields", &field_order, "key[,keys...]",
  565. "output field(s): overhead, period, sample plus all of sort keys"),
  566. OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
  567. "Show sample percentage for different cpu modes"),
  568. OPT_STRING('p', "parent", &parent_pattern, "regex",
  569. "regex filter to identify parent, see: '--sort parent'"),
  570. OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
  571. "Only display entries with parent-match"),
  572. OPT_CALLBACK_DEFAULT('g', "call-graph", &report, "output_type,min_percent[,print_limit],call_order[,branch]",
  573. "Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold, optional print limit, callchain order, key (function or address), add branches. "
  574. "Default: fractal,0.5,callee,function", &report_parse_callchain_opt, callchain_default_opt),
  575. OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain,
  576. "Accumulate callchains of children and show total overhead as well"),
  577. OPT_INTEGER(0, "max-stack", &report.max_stack,
  578. "Set the maximum stack depth when parsing the callchain, "
  579. "anything beyond the specified depth will be ignored. "
  580. "Default: " __stringify(PERF_MAX_STACK_DEPTH)),
  581. OPT_BOOLEAN('G', "inverted", &report.inverted_callchain,
  582. "alias for inverted call graph"),
  583. OPT_CALLBACK(0, "ignore-callees", NULL, "regex",
  584. "ignore callees of these functions in call graphs",
  585. report_parse_ignore_callees_opt),
  586. OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
  587. "only consider symbols in these dsos"),
  588. OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
  589. "only consider symbols in these comms"),
  590. OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]",
  591. "only consider symbols in these pids"),
  592. OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
  593. "only consider symbols in these tids"),
  594. OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
  595. "only consider these symbols"),
  596. OPT_STRING(0, "symbol-filter", &report.symbol_filter_str, "filter",
  597. "only show symbols that (partially) match with this filter"),
  598. OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str,
  599. "width[,width...]",
  600. "don't try to adjust column width, use these fixed values"),
  601. OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
  602. "separator for columns, no spaces will be added between "
  603. "columns '.' is reserved."),
  604. OPT_BOOLEAN('U', "hide-unresolved", &report.hide_unresolved,
  605. "Only display entries resolved to a symbol"),
  606. OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
  607. "Look for files with symbols relative to this directory"),
  608. OPT_STRING('C', "cpu", &report.cpu_list, "cpu",
  609. "list of cpus to profile"),
  610. OPT_BOOLEAN('I', "show-info", &report.show_full_info,
  611. "Display extended information about perf.data file"),
  612. OPT_BOOLEAN(0, "source", &symbol_conf.annotate_src,
  613. "Interleave source code with assembly code (default)"),
  614. OPT_BOOLEAN(0, "asm-raw", &symbol_conf.annotate_asm_raw,
  615. "Display raw encoding of assembly instructions (default)"),
  616. OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
  617. "Specify disassembler style (e.g. -M intel for intel syntax)"),
  618. OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
  619. "Show a column with the sum of periods"),
  620. OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
  621. "Show event group information together"),
  622. OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "",
  623. "use branch records for per branch histogram filling",
  624. parse_branch_mode),
  625. OPT_BOOLEAN(0, "branch-history", &branch_call_mode,
  626. "add last branch records to call history"),
  627. OPT_STRING(0, "objdump", &objdump_path, "path",
  628. "objdump binary to use for disassembly and annotations"),
  629. OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
  630. "Disable symbol demangling"),
  631. OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
  632. "Enable kernel symbol demangling"),
  633. OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"),
  634. OPT_CALLBACK(0, "percent-limit", &report, "percent",
  635. "Don't show entries under that percent", parse_percent_limit),
  636. OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
  637. "how to display percentage of filtered entries", parse_filter_percentage),
  638. OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
  639. "Instruction Tracing options",
  640. itrace_parse_synth_opts),
  641. OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
  642. "Show full source file name path for source lines"),
  643. OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf.show_ref_callgraph,
  644. "Show callgraph from reference event"),
  645. OPT_END()
  646. };
  647. struct perf_data_file file = {
  648. .mode = PERF_DATA_MODE_READ,
  649. };
  650. int ret = hists__init();
  651. if (ret < 0)
  652. return ret;
  653. perf_config(report__config, &report);
  654. argc = parse_options(argc, argv, options, report_usage, 0);
  655. if (symbol_conf.vmlinux_name &&
  656. access(symbol_conf.vmlinux_name, R_OK)) {
  657. pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name);
  658. return -EINVAL;
  659. }
  660. if (symbol_conf.kallsyms_name &&
  661. access(symbol_conf.kallsyms_name, R_OK)) {
  662. pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name);
  663. return -EINVAL;
  664. }
  665. if (report.use_stdio)
  666. use_browser = 0;
  667. else if (report.use_tui)
  668. use_browser = 1;
  669. else if (report.use_gtk)
  670. use_browser = 2;
  671. if (report.inverted_callchain)
  672. callchain_param.order = ORDER_CALLER;
  673. if (!input_name || !strlen(input_name)) {
  674. if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))
  675. input_name = "-";
  676. else
  677. input_name = "perf.data";
  678. }
  679. file.path = input_name;
  680. file.force = report.force;
  681. repeat:
  682. session = perf_session__new(&file, false, &report.tool);
  683. if (session == NULL)
  684. return -1;
  685. if (report.queue_size) {
  686. ordered_events__set_alloc_size(&session->ordered_events,
  687. report.queue_size);
  688. }
  689. session->itrace_synth_opts = &itrace_synth_opts;
  690. report.session = session;
  691. has_br_stack = perf_header__has_feat(&session->header,
  692. HEADER_BRANCH_STACK);
  693. /*
  694. * Branch mode is a tristate:
  695. * -1 means default, so decide based on the file having branch data.
  696. * 0/1 means the user chose a mode.
  697. */
  698. if (((branch_mode == -1 && has_br_stack) || branch_mode == 1) &&
  699. !branch_call_mode) {
  700. sort__mode = SORT_MODE__BRANCH;
  701. symbol_conf.cumulate_callchain = false;
  702. }
  703. if (branch_call_mode) {
  704. callchain_param.key = CCKEY_ADDRESS;
  705. callchain_param.branch_callstack = 1;
  706. symbol_conf.use_callchain = true;
  707. callchain_register_param(&callchain_param);
  708. if (sort_order == NULL)
  709. sort_order = "srcline,symbol,dso";
  710. }
  711. if (report.mem_mode) {
  712. if (sort__mode == SORT_MODE__BRANCH) {
  713. pr_err("branch and mem mode incompatible\n");
  714. goto error;
  715. }
  716. sort__mode = SORT_MODE__MEMORY;
  717. symbol_conf.cumulate_callchain = false;
  718. }
  719. if (setup_sorting() < 0) {
  720. if (sort_order)
  721. parse_options_usage(report_usage, options, "s", 1);
  722. if (field_order)
  723. parse_options_usage(sort_order ? NULL : report_usage,
  724. options, "F", 1);
  725. goto error;
  726. }
  727. /* Force tty output for header output and per-thread stat. */
  728. if (report.header || report.header_only || report.show_threads)
  729. use_browser = 0;
  730. if (strcmp(input_name, "-") != 0)
  731. setup_browser(true);
  732. else
  733. use_browser = 0;
  734. if (report.header || report.header_only) {
  735. perf_session__fprintf_info(session, stdout,
  736. report.show_full_info);
  737. if (report.header_only) {
  738. ret = 0;
  739. goto error;
  740. }
  741. } else if (use_browser == 0) {
  742. fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
  743. stdout);
  744. }
  745. /*
  746. * Only in the TUI browser we are doing integrated annotation,
  747. * so don't allocate extra space that won't be used in the stdio
  748. * implementation.
  749. */
  750. if (ui__has_annotation()) {
  751. symbol_conf.priv_size = sizeof(struct annotation);
  752. machines__set_symbol_filter(&session->machines,
  753. symbol__annotate_init);
  754. /*
  755. * For searching by name on the "Browse map details".
  756. * providing it only in verbose mode not to bloat too
  757. * much struct symbol.
  758. */
  759. if (verbose) {
  760. /*
  761. * XXX: Need to provide a less kludgy way to ask for
  762. * more space per symbol, the u32 is for the index on
  763. * the ui browser.
  764. * See symbol__browser_index.
  765. */
  766. symbol_conf.priv_size += sizeof(u32);
  767. symbol_conf.sort_by_name = true;
  768. }
  769. }
  770. if (symbol__init(&session->header.env) < 0)
  771. goto error;
  772. if (argc) {
  773. /*
  774. * Special case: if there's an argument left then assume that
  775. * it's a symbol filter:
  776. */
  777. if (argc > 1)
  778. usage_with_options(report_usage, options);
  779. report.symbol_filter_str = argv[0];
  780. }
  781. sort__setup_elide(stdout);
  782. ret = __cmd_report(&report);
  783. if (ret == K_SWITCH_INPUT_DATA) {
  784. perf_session__delete(session);
  785. goto repeat;
  786. } else
  787. ret = 0;
  788. error:
  789. perf_session__delete(session);
  790. return ret;
  791. }