builtin-report.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * builtin-report.c
  4. *
  5. * Builtin report command: Analyze the perf.data input file,
  6. * look up and read DSOs and symbol information and display
  7. * a histogram of results, along various sorting keys.
  8. */
  9. #include "builtin.h"
  10. #include "util/config.h"
  11. #include "util/annotate.h"
  12. #include "util/color.h"
  13. #include "util/dso.h"
  14. #include <linux/list.h>
  15. #include <linux/rbtree.h>
  16. #include <linux/err.h>
  17. #include <linux/zalloc.h>
  18. #include "util/map.h"
  19. #include "util/symbol.h"
  20. #include "util/map_symbol.h"
  21. #include "util/mem-events.h"
  22. #include "util/branch.h"
  23. #include "util/callchain.h"
  24. #include "util/values.h"
  25. #include "perf.h"
  26. #include "util/debug.h"
  27. #include "util/evlist.h"
  28. #include "util/evsel.h"
  29. #include "util/evswitch.h"
  30. #include "util/header.h"
  31. #include "util/mem-info.h"
  32. #include "util/session.h"
  33. #include "util/srcline.h"
  34. #include "util/tool.h"
  35. #include <subcmd/parse-options.h>
  36. #include <subcmd/exec-cmd.h>
  37. #include "util/parse-events.h"
  38. #include "util/thread.h"
  39. #include "util/sort.h"
  40. #include "util/hist.h"
  41. #include "util/data.h"
  42. #include "arch/common.h"
  43. #include "util/time-utils.h"
  44. #include "util/auxtrace.h"
  45. #include "util/units.h"
  46. #include "util/util.h" // perf_tip()
  47. #include "ui/ui.h"
  48. #include "ui/progress.h"
  49. #include "util/block-info.h"
  50. #include <dlfcn.h>
  51. #include <errno.h>
  52. #include <inttypes.h>
  53. #include <regex.h>
  54. #include <linux/ctype.h>
  55. #include <signal.h>
  56. #include <linux/bitmap.h>
  57. #include <linux/list_sort.h>
  58. #include <linux/string.h>
  59. #include <linux/stringify.h>
  60. #include <linux/time64.h>
  61. #include <sys/types.h>
  62. #include <sys/stat.h>
  63. #include <unistd.h>
  64. #include <linux/mman.h>
  65. #ifdef HAVE_LIBTRACEEVENT
  66. #include <traceevent/event-parse.h>
  67. #endif
  68. struct report {
  69. struct perf_tool tool;
  70. struct perf_session *session;
  71. struct evswitch evswitch;
  72. #ifdef HAVE_SLANG_SUPPORT
  73. bool use_tui;
  74. #endif
  75. #ifdef HAVE_GTK2_SUPPORT
  76. bool use_gtk;
  77. #endif
  78. bool use_stdio;
  79. bool show_full_info;
  80. bool show_threads;
  81. bool inverted_callchain;
  82. bool mem_mode;
  83. bool stats_mode;
  84. bool tasks_mode;
  85. bool mmaps_mode;
  86. bool header;
  87. bool header_only;
  88. bool nonany_branch_mode;
  89. bool group_set;
  90. bool stitch_lbr;
  91. bool disable_order;
  92. bool skip_empty;
  93. bool data_type;
  94. int max_stack;
  95. struct perf_read_values show_threads_values;
  96. const char *pretty_printing_style;
  97. const char *cpu_list;
  98. const char *symbol_filter_str;
  99. const char *time_str;
  100. struct perf_time_interval *ptime_range;
  101. int range_size;
  102. int range_num;
  103. float min_percent;
  104. u64 nr_entries;
  105. u64 queue_size;
  106. u64 total_cycles;
  107. int socket_filter;
  108. DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
  109. struct branch_type_stat brtype_stat;
  110. bool symbol_ipc;
  111. bool total_cycles_mode;
  112. struct block_report *block_reports;
  113. int nr_block_reports;
  114. };
  115. static int report__config(const char *var, const char *value, void *cb)
  116. {
  117. struct report *rep = cb;
  118. if (!strcmp(var, "report.group")) {
  119. symbol_conf.event_group = perf_config_bool(var, value);
  120. return 0;
  121. }
  122. if (!strcmp(var, "report.percent-limit")) {
  123. double pcnt = strtof(value, NULL);
  124. rep->min_percent = pcnt;
  125. callchain_param.min_percent = pcnt;
  126. return 0;
  127. }
  128. if (!strcmp(var, "report.children")) {
  129. symbol_conf.cumulate_callchain = perf_config_bool(var, value);
  130. return 0;
  131. }
  132. if (!strcmp(var, "report.queue-size"))
  133. return perf_config_u64(&rep->queue_size, var, value);
  134. if (!strcmp(var, "report.sort_order")) {
  135. default_sort_order = strdup(value);
  136. if (!default_sort_order) {
  137. pr_err("Not enough memory for report.sort_order\n");
  138. return -1;
  139. }
  140. return 0;
  141. }
  142. if (!strcmp(var, "report.skip-empty")) {
  143. rep->skip_empty = perf_config_bool(var, value);
  144. return 0;
  145. }
  146. pr_debug("%s variable unknown, ignoring...", var);
  147. return 0;
  148. }
  149. static int hist_iter__report_callback(struct hist_entry_iter *iter,
  150. struct addr_location *al, bool single,
  151. void *arg)
  152. {
  153. int err = 0;
  154. struct report *rep = arg;
  155. struct hist_entry *he = iter->he;
  156. struct evsel *evsel = iter->evsel;
  157. struct perf_sample *sample = iter->sample;
  158. struct mem_info *mi;
  159. struct branch_info *bi;
  160. if (!ui__has_annotation() && !rep->symbol_ipc)
  161. return 0;
  162. if (sort__mode == SORT_MODE__BRANCH) {
  163. bi = he->branch_info;
  164. err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
  165. if (err)
  166. goto out;
  167. err = addr_map_symbol__inc_samples(&bi->to, sample, evsel);
  168. } else if (rep->mem_mode) {
  169. mi = he->mem_info;
  170. err = addr_map_symbol__inc_samples(mem_info__daddr(mi), sample, evsel);
  171. if (err)
  172. goto out;
  173. err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr);
  174. } else if (symbol_conf.cumulate_callchain) {
  175. if (single)
  176. err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr);
  177. } else {
  178. err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr);
  179. }
  180. out:
  181. return err;
  182. }
  183. static int hist_iter__branch_callback(struct hist_entry_iter *iter,
  184. struct addr_location *al __maybe_unused,
  185. bool single __maybe_unused,
  186. void *arg)
  187. {
  188. struct hist_entry *he = iter->he;
  189. struct report *rep = arg;
  190. struct branch_info *bi = he->branch_info;
  191. struct perf_sample *sample = iter->sample;
  192. struct evsel *evsel = iter->evsel;
  193. int err;
  194. branch_type_count(&rep->brtype_stat, &bi->flags,
  195. bi->from.addr, bi->to.addr);
  196. if (!ui__has_annotation() && !rep->symbol_ipc)
  197. return 0;
  198. err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
  199. if (err)
  200. goto out;
  201. err = addr_map_symbol__inc_samples(&bi->to, sample, evsel);
  202. out:
  203. return err;
  204. }
  205. static void setup_forced_leader(struct report *report,
  206. struct evlist *evlist)
  207. {
  208. if (report->group_set)
  209. evlist__force_leader(evlist);
  210. }
  211. static int process_feature_event(struct perf_session *session,
  212. union perf_event *event)
  213. {
  214. struct report *rep = container_of(session->tool, struct report, tool);
  215. if (event->feat.feat_id < HEADER_LAST_FEATURE)
  216. return perf_event__process_feature(session, event);
  217. if (event->feat.feat_id != HEADER_LAST_FEATURE) {
  218. pr_err("failed: wrong feature ID: %" PRI_lu64 "\n",
  219. event->feat.feat_id);
  220. return -1;
  221. } else if (rep->header_only) {
  222. session_done = 1;
  223. }
  224. /*
  225. * (feat_id = HEADER_LAST_FEATURE) is the end marker which
  226. * means all features are received, now we can force the
  227. * group if needed.
  228. */
  229. setup_forced_leader(rep, session->evlist);
  230. return 0;
  231. }
  232. static int process_sample_event(const struct perf_tool *tool,
  233. union perf_event *event,
  234. struct perf_sample *sample,
  235. struct evsel *evsel,
  236. struct machine *machine)
  237. {
  238. struct report *rep = container_of(tool, struct report, tool);
  239. struct addr_location al;
  240. struct hist_entry_iter iter = {
  241. .evsel = evsel,
  242. .sample = sample,
  243. .hide_unresolved = symbol_conf.hide_unresolved,
  244. .add_entry_cb = hist_iter__report_callback,
  245. };
  246. int ret = 0;
  247. if (perf_time__ranges_skip_sample(rep->ptime_range, rep->range_num,
  248. sample->time)) {
  249. return 0;
  250. }
  251. if (evswitch__discard(&rep->evswitch, evsel))
  252. return 0;
  253. addr_location__init(&al);
  254. if (machine__resolve(machine, &al, sample) < 0) {
  255. pr_debug("problem processing %d event, skipping it.\n",
  256. event->header.type);
  257. ret = -1;
  258. goto out_put;
  259. }
  260. if (rep->stitch_lbr)
  261. thread__set_lbr_stitch_enable(al.thread, true);
  262. if (symbol_conf.hide_unresolved && al.sym == NULL)
  263. goto out_put;
  264. if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
  265. goto out_put;
  266. if (sort__mode == SORT_MODE__BRANCH) {
  267. /*
  268. * A non-synthesized event might not have a branch stack if
  269. * branch stacks have been synthesized (using itrace options).
  270. */
  271. if (!sample->branch_stack)
  272. goto out_put;
  273. iter.add_entry_cb = hist_iter__branch_callback;
  274. iter.ops = &hist_iter_branch;
  275. } else if (rep->mem_mode) {
  276. iter.ops = &hist_iter_mem;
  277. } else if (symbol_conf.cumulate_callchain) {
  278. iter.ops = &hist_iter_cumulative;
  279. } else {
  280. iter.ops = &hist_iter_normal;
  281. }
  282. if (al.map != NULL)
  283. dso__set_hit(map__dso(al.map));
  284. if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) {
  285. hist__account_cycles(sample->branch_stack, &al, sample,
  286. rep->nonany_branch_mode,
  287. &rep->total_cycles, evsel);
  288. }
  289. ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep);
  290. if (ret < 0)
  291. pr_debug("problem adding hist entry, skipping event\n");
  292. out_put:
  293. addr_location__exit(&al);
  294. return ret;
  295. }
  296. static int process_read_event(const struct perf_tool *tool,
  297. union perf_event *event,
  298. struct perf_sample *sample __maybe_unused,
  299. struct evsel *evsel,
  300. struct machine *machine __maybe_unused)
  301. {
  302. struct report *rep = container_of(tool, struct report, tool);
  303. if (rep->show_threads) {
  304. const char *name = evsel__name(evsel);
  305. int err = perf_read_values_add_value(&rep->show_threads_values,
  306. event->read.pid, event->read.tid,
  307. evsel->core.idx,
  308. name,
  309. event->read.value);
  310. if (err)
  311. return err;
  312. }
  313. return 0;
  314. }
  315. /* For pipe mode, sample_type is not currently set */
  316. static int report__setup_sample_type(struct report *rep)
  317. {
  318. struct perf_session *session = rep->session;
  319. u64 sample_type = evlist__combined_sample_type(session->evlist);
  320. bool is_pipe = perf_data__is_pipe(session->data);
  321. struct evsel *evsel;
  322. if (session->itrace_synth_opts->callchain ||
  323. session->itrace_synth_opts->add_callchain ||
  324. (!is_pipe &&
  325. perf_header__has_feat(&session->header, HEADER_AUXTRACE) &&
  326. !session->itrace_synth_opts->set))
  327. sample_type |= PERF_SAMPLE_CALLCHAIN;
  328. if (session->itrace_synth_opts->last_branch ||
  329. session->itrace_synth_opts->add_last_branch)
  330. sample_type |= PERF_SAMPLE_BRANCH_STACK;
  331. if (!is_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) {
  332. if (perf_hpp_list.parent) {
  333. ui__error("Selected --sort parent, but no "
  334. "callchain data. Did you call "
  335. "'perf record' without -g?\n");
  336. return -EINVAL;
  337. }
  338. if (symbol_conf.use_callchain &&
  339. !symbol_conf.show_branchflag_count) {
  340. ui__error("Selected -g or --branch-history.\n"
  341. "But no callchain or branch data.\n"
  342. "Did you call 'perf record' without -g or -b?\n");
  343. return -1;
  344. }
  345. } else if (!callchain_param.enabled &&
  346. callchain_param.mode != CHAIN_NONE &&
  347. !symbol_conf.use_callchain) {
  348. symbol_conf.use_callchain = true;
  349. if (callchain_register_param(&callchain_param) < 0) {
  350. ui__error("Can't register callchain params.\n");
  351. return -EINVAL;
  352. }
  353. }
  354. if (symbol_conf.cumulate_callchain) {
  355. /* Silently ignore if callchain is missing */
  356. if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) {
  357. symbol_conf.cumulate_callchain = false;
  358. perf_hpp__cancel_cumulate();
  359. }
  360. }
  361. if (sort__mode == SORT_MODE__BRANCH) {
  362. if (!is_pipe &&
  363. !(sample_type & PERF_SAMPLE_BRANCH_STACK)) {
  364. ui__error("Selected -b but no branch data. "
  365. "Did you call perf record without -b?\n");
  366. return -1;
  367. }
  368. }
  369. if (sort__mode == SORT_MODE__MEMORY) {
  370. /*
  371. * FIXUP: prior to kernel 5.18, Arm SPE missed to set
  372. * PERF_SAMPLE_DATA_SRC bit in sample type. For backward
  373. * compatibility, set the bit if it's an old perf data file.
  374. */
  375. evlist__for_each_entry(session->evlist, evsel) {
  376. if (strstr(evsel__name(evsel), "arm_spe") &&
  377. !(sample_type & PERF_SAMPLE_DATA_SRC)) {
  378. evsel->core.attr.sample_type |= PERF_SAMPLE_DATA_SRC;
  379. sample_type |= PERF_SAMPLE_DATA_SRC;
  380. }
  381. }
  382. if (!is_pipe && !(sample_type & PERF_SAMPLE_DATA_SRC)) {
  383. ui__error("Selected --mem-mode but no mem data. "
  384. "Did you call perf record without -d?\n");
  385. return -1;
  386. }
  387. }
  388. callchain_param_setup(sample_type, perf_env__arch(&rep->session->header.env));
  389. if (rep->stitch_lbr && (callchain_param.record_mode != CALLCHAIN_LBR)) {
  390. ui__warning("Can't find LBR callchain. Switch off --stitch-lbr.\n"
  391. "Please apply --call-graph lbr when recording.\n");
  392. rep->stitch_lbr = false;
  393. }
  394. /* ??? handle more cases than just ANY? */
  395. if (!(evlist__combined_branch_type(session->evlist) & PERF_SAMPLE_BRANCH_ANY))
  396. rep->nonany_branch_mode = true;
  397. #if !defined(HAVE_LIBUNWIND_SUPPORT) && !defined(HAVE_DWARF_SUPPORT)
  398. if (dwarf_callchain_users) {
  399. ui__warning("Please install libunwind or libdw "
  400. "development packages during the perf build.\n");
  401. }
  402. #endif
  403. return 0;
  404. }
  405. static void sig_handler(int sig __maybe_unused)
  406. {
  407. session_done = 1;
  408. }
  409. static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report *rep,
  410. const char *evname, FILE *fp)
  411. {
  412. size_t ret;
  413. char unit;
  414. unsigned long nr_samples = hists->stats.nr_samples;
  415. u64 nr_events = hists->stats.total_period;
  416. struct evsel *evsel = hists_to_evsel(hists);
  417. char buf[512];
  418. size_t size = sizeof(buf);
  419. int socked_id = hists->socket_filter;
  420. if (quiet)
  421. return 0;
  422. if (symbol_conf.filter_relative) {
  423. nr_samples = hists->stats.nr_non_filtered_samples;
  424. nr_events = hists->stats.total_non_filtered_period;
  425. }
  426. if (evsel__is_group_event(evsel)) {
  427. struct evsel *pos;
  428. evsel__group_desc(evsel, buf, size);
  429. evname = buf;
  430. for_each_group_member(pos, evsel) {
  431. const struct hists *pos_hists = evsel__hists(pos);
  432. if (symbol_conf.filter_relative) {
  433. nr_samples += pos_hists->stats.nr_non_filtered_samples;
  434. nr_events += pos_hists->stats.total_non_filtered_period;
  435. } else {
  436. nr_samples += pos_hists->stats.nr_samples;
  437. nr_events += pos_hists->stats.total_period;
  438. }
  439. }
  440. }
  441. nr_samples = convert_unit(nr_samples, &unit);
  442. ret = fprintf(fp, "# Samples: %lu%c", nr_samples, unit);
  443. if (evname != NULL) {
  444. ret += fprintf(fp, " of event%s '%s'",
  445. evsel->core.nr_members > 1 ? "s" : "", evname);
  446. }
  447. if (rep->time_str)
  448. ret += fprintf(fp, " (time slices: %s)", rep->time_str);
  449. if (symbol_conf.show_ref_callgraph && evname && strstr(evname, "call-graph=no")) {
  450. ret += fprintf(fp, ", show reference callgraph");
  451. }
  452. if (rep->mem_mode) {
  453. ret += fprintf(fp, "\n# Total weight : %" PRIu64, nr_events);
  454. ret += fprintf(fp, "\n# Sort order : %s", sort_order ? : default_mem_sort_order);
  455. } else
  456. ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events);
  457. if (socked_id > -1)
  458. ret += fprintf(fp, "\n# Processor Socket: %d", socked_id);
  459. return ret + fprintf(fp, "\n#\n");
  460. }
  461. static int evlist__tui_block_hists_browse(struct evlist *evlist, struct report *rep)
  462. {
  463. struct evsel *pos;
  464. int i = 0, ret;
  465. evlist__for_each_entry(evlist, pos) {
  466. ret = report__browse_block_hists(&rep->block_reports[i++].hist,
  467. rep->min_percent, pos,
  468. &rep->session->header.env);
  469. if (ret != 0)
  470. return ret;
  471. }
  472. return 0;
  473. }
  474. static int evlist__tty_browse_hists(struct evlist *evlist, struct report *rep, const char *help)
  475. {
  476. struct evsel *pos;
  477. int i = 0;
  478. if (!quiet) {
  479. fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n",
  480. evlist->stats.total_lost_samples);
  481. }
  482. evlist__for_each_entry(evlist, pos) {
  483. struct hists *hists = evsel__hists(pos);
  484. const char *evname = evsel__name(pos);
  485. i++;
  486. if (symbol_conf.event_group && !evsel__is_group_leader(pos))
  487. continue;
  488. if (rep->skip_empty && !hists->stats.nr_samples)
  489. continue;
  490. hists__fprintf_nr_sample_events(hists, rep, evname, stdout);
  491. if (rep->total_cycles_mode) {
  492. char *buf;
  493. if (!annotation_br_cntr_abbr_list(&buf, pos, true)) {
  494. fprintf(stdout, "%s", buf);
  495. fprintf(stdout, "#\n");
  496. free(buf);
  497. }
  498. report__browse_block_hists(&rep->block_reports[i - 1].hist,
  499. rep->min_percent, pos, NULL);
  500. continue;
  501. }
  502. hists__fprintf(hists, !quiet, 0, 0, rep->min_percent, stdout,
  503. !(symbol_conf.use_callchain ||
  504. symbol_conf.show_branchflag_count));
  505. fprintf(stdout, "\n\n");
  506. }
  507. if (!quiet)
  508. fprintf(stdout, "#\n# (%s)\n#\n", help);
  509. if (rep->show_threads) {
  510. bool style = !strcmp(rep->pretty_printing_style, "raw");
  511. perf_read_values_display(stdout, &rep->show_threads_values,
  512. style);
  513. perf_read_values_destroy(&rep->show_threads_values);
  514. }
  515. if (sort__mode == SORT_MODE__BRANCH)
  516. branch_type_stat_display(stdout, &rep->brtype_stat);
  517. return 0;
  518. }
  519. static void report__warn_kptr_restrict(const struct report *rep)
  520. {
  521. struct map *kernel_map = machine__kernel_map(&rep->session->machines.host);
  522. struct kmap *kernel_kmap = kernel_map ? map__kmap(kernel_map) : NULL;
  523. if (evlist__exclude_kernel(rep->session->evlist))
  524. return;
  525. if (kernel_map == NULL ||
  526. (dso__hit(map__dso(kernel_map)) &&
  527. (kernel_kmap->ref_reloc_sym == NULL ||
  528. kernel_kmap->ref_reloc_sym->addr == 0))) {
  529. const char *desc =
  530. "As no suitable kallsyms nor vmlinux was found, kernel samples\n"
  531. "can't be resolved.";
  532. if (kernel_map && map__has_symbols(kernel_map)) {
  533. desc = "If some relocation was applied (e.g. "
  534. "kexec) symbols may be misresolved.";
  535. }
  536. ui__warning(
  537. "Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n"
  538. "Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n"
  539. "Samples in kernel modules can't be resolved as well.\n\n",
  540. desc);
  541. }
  542. }
  543. static int report__gtk_browse_hists(struct report *rep, const char *help)
  544. {
  545. int (*hist_browser)(struct evlist *evlist, const char *help,
  546. struct hist_browser_timer *timer, float min_pcnt);
  547. hist_browser = dlsym(perf_gtk_handle, "evlist__gtk_browse_hists");
  548. if (hist_browser == NULL) {
  549. ui__error("GTK browser not found!\n");
  550. return -1;
  551. }
  552. return hist_browser(rep->session->evlist, help, NULL, rep->min_percent);
  553. }
  554. static int report__browse_hists(struct report *rep)
  555. {
  556. int ret;
  557. struct perf_session *session = rep->session;
  558. struct evlist *evlist = session->evlist;
  559. char *help = NULL, *path = NULL;
  560. path = system_path(TIPDIR);
  561. if (perf_tip(&help, path) || help == NULL) {
  562. /* fallback for people who don't install perf ;-) */
  563. free(path);
  564. path = system_path(DOCDIR);
  565. if (perf_tip(&help, path) || help == NULL)
  566. help = strdup("Cannot load tips.txt file, please install perf!");
  567. }
  568. free(path);
  569. switch (use_browser) {
  570. case 1:
  571. if (rep->total_cycles_mode) {
  572. ret = evlist__tui_block_hists_browse(evlist, rep);
  573. break;
  574. }
  575. ret = evlist__tui_browse_hists(evlist, help, NULL, rep->min_percent,
  576. &session->header.env, true);
  577. /*
  578. * Usually "ret" is the last pressed key, and we only
  579. * care if the key notifies us to switch data file.
  580. */
  581. if (ret != K_SWITCH_INPUT_DATA && ret != K_RELOAD)
  582. ret = 0;
  583. break;
  584. case 2:
  585. ret = report__gtk_browse_hists(rep, help);
  586. break;
  587. default:
  588. ret = evlist__tty_browse_hists(evlist, rep, help);
  589. break;
  590. }
  591. free(help);
  592. return ret;
  593. }
  594. static int report__collapse_hists(struct report *rep)
  595. {
  596. struct perf_session *session = rep->session;
  597. struct evlist *evlist = session->evlist;
  598. struct ui_progress prog;
  599. struct evsel *pos;
  600. int ret = 0;
  601. /*
  602. * The pipe data needs to setup hierarchy hpp formats now, because it
  603. * cannot know about evsels in the data before reading the data. The
  604. * normal file data saves the event (attribute) info in the header
  605. * section, but pipe does not have the luxury.
  606. */
  607. if (perf_data__is_pipe(session->data)) {
  608. if (perf_hpp__setup_hists_formats(&perf_hpp_list, evlist) < 0) {
  609. ui__error("Failed to setup hierarchy output formats\n");
  610. return -1;
  611. }
  612. }
  613. ui_progress__init(&prog, rep->nr_entries, "Merging related events...");
  614. evlist__for_each_entry(rep->session->evlist, pos) {
  615. struct hists *hists = evsel__hists(pos);
  616. if (pos->core.idx == 0)
  617. hists->symbol_filter_str = rep->symbol_filter_str;
  618. hists->socket_filter = rep->socket_filter;
  619. ret = hists__collapse_resort(hists, &prog);
  620. if (ret < 0)
  621. break;
  622. /* Non-group events are considered as leader */
  623. if (symbol_conf.event_group && !evsel__is_group_leader(pos)) {
  624. struct hists *leader_hists = evsel__hists(evsel__leader(pos));
  625. hists__match(leader_hists, hists);
  626. hists__link(leader_hists, hists);
  627. }
  628. }
  629. ui_progress__finish();
  630. return ret;
  631. }
  632. static int hists__resort_cb(struct hist_entry *he, void *arg)
  633. {
  634. struct report *rep = arg;
  635. struct symbol *sym = he->ms.sym;
  636. if (rep->symbol_ipc && sym && !sym->annotate2) {
  637. struct evsel *evsel = hists_to_evsel(he->hists);
  638. symbol__annotate2(&he->ms, evsel, NULL);
  639. }
  640. return 0;
  641. }
  642. static void report__output_resort(struct report *rep)
  643. {
  644. struct ui_progress prog;
  645. struct evsel *pos;
  646. ui_progress__init(&prog, rep->nr_entries, "Sorting events for output...");
  647. evlist__for_each_entry(rep->session->evlist, pos) {
  648. evsel__output_resort_cb(pos, &prog, hists__resort_cb, rep);
  649. }
  650. ui_progress__finish();
  651. }
  652. static int count_sample_event(const struct perf_tool *tool __maybe_unused,
  653. union perf_event *event __maybe_unused,
  654. struct perf_sample *sample __maybe_unused,
  655. struct evsel *evsel,
  656. struct machine *machine __maybe_unused)
  657. {
  658. struct hists *hists = evsel__hists(evsel);
  659. hists__inc_nr_events(hists);
  660. return 0;
  661. }
  662. static int count_lost_samples_event(const struct perf_tool *tool,
  663. union perf_event *event,
  664. struct perf_sample *sample,
  665. struct machine *machine __maybe_unused)
  666. {
  667. struct report *rep = container_of(tool, struct report, tool);
  668. struct evsel *evsel;
  669. evsel = evlist__id2evsel(rep->session->evlist, sample->id);
  670. if (evsel) {
  671. struct hists *hists = evsel__hists(evsel);
  672. u32 count = event->lost_samples.lost;
  673. if (event->header.misc & PERF_RECORD_MISC_LOST_SAMPLES_BPF)
  674. hists__inc_nr_dropped_samples(hists, count);
  675. else
  676. hists__inc_nr_lost_samples(hists, count);
  677. }
  678. return 0;
  679. }
  680. static int process_attr(const struct perf_tool *tool __maybe_unused,
  681. union perf_event *event,
  682. struct evlist **pevlist);
  683. static void stats_setup(struct report *rep)
  684. {
  685. perf_tool__init(&rep->tool, /*ordered_events=*/false);
  686. rep->tool.attr = process_attr;
  687. rep->tool.sample = count_sample_event;
  688. rep->tool.lost_samples = count_lost_samples_event;
  689. rep->tool.event_update = perf_event__process_event_update;
  690. rep->tool.no_warn = true;
  691. }
  692. static int stats_print(struct report *rep)
  693. {
  694. struct perf_session *session = rep->session;
  695. perf_session__fprintf_nr_events(session, stdout);
  696. evlist__fprintf_nr_events(session->evlist, stdout);
  697. return 0;
  698. }
  699. static void tasks_setup(struct report *rep)
  700. {
  701. perf_tool__init(&rep->tool, /*ordered_events=*/true);
  702. if (rep->mmaps_mode) {
  703. rep->tool.mmap = perf_event__process_mmap;
  704. rep->tool.mmap2 = perf_event__process_mmap2;
  705. }
  706. rep->tool.attr = process_attr;
  707. rep->tool.comm = perf_event__process_comm;
  708. rep->tool.exit = perf_event__process_exit;
  709. rep->tool.fork = perf_event__process_fork;
  710. rep->tool.no_warn = true;
  711. }
  712. struct maps__fprintf_task_args {
  713. int indent;
  714. FILE *fp;
  715. size_t printed;
  716. };
  717. static int maps__fprintf_task_cb(struct map *map, void *data)
  718. {
  719. struct maps__fprintf_task_args *args = data;
  720. const struct dso *dso = map__dso(map);
  721. u32 prot = map__prot(map);
  722. int ret;
  723. ret = fprintf(args->fp,
  724. "%*s %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n",
  725. args->indent, "", map__start(map), map__end(map),
  726. prot & PROT_READ ? 'r' : '-',
  727. prot & PROT_WRITE ? 'w' : '-',
  728. prot & PROT_EXEC ? 'x' : '-',
  729. map__flags(map) ? 's' : 'p',
  730. map__pgoff(map),
  731. dso__id_const(dso)->ino, dso__name(dso));
  732. if (ret < 0)
  733. return ret;
  734. args->printed += ret;
  735. return 0;
  736. }
  737. static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)
  738. {
  739. struct maps__fprintf_task_args args = {
  740. .indent = indent,
  741. .fp = fp,
  742. .printed = 0,
  743. };
  744. maps__for_each_map(maps, maps__fprintf_task_cb, &args);
  745. return args.printed;
  746. }
  747. static int thread_level(struct machine *machine, const struct thread *thread)
  748. {
  749. struct thread *parent_thread;
  750. int res;
  751. if (thread__tid(thread) <= 0)
  752. return 0;
  753. if (thread__ppid(thread) <= 0)
  754. return 1;
  755. parent_thread = machine__find_thread(machine, -1, thread__ppid(thread));
  756. if (!parent_thread) {
  757. pr_err("Missing parent thread of %d\n", thread__tid(thread));
  758. return 0;
  759. }
  760. res = 1 + thread_level(machine, parent_thread);
  761. thread__put(parent_thread);
  762. return res;
  763. }
  764. static void task__print_level(struct machine *machine, struct thread *thread, FILE *fp)
  765. {
  766. int level = thread_level(machine, thread);
  767. int comm_indent = fprintf(fp, " %8d %8d %8d |%*s",
  768. thread__pid(thread), thread__tid(thread),
  769. thread__ppid(thread), level, "");
  770. fprintf(fp, "%s\n", thread__comm_str(thread));
  771. maps__fprintf_task(thread__maps(thread), comm_indent, fp);
  772. }
  773. /*
  774. * Sort two thread list nodes such that they form a tree. The first node is the
  775. * root of the tree, its children are ordered numerically after it. If a child
  776. * has children itself then they appear immediately after their parent. For
  777. * example, the 4 threads in the order they'd appear in the list:
  778. * - init with a TID 1 and a parent of 0
  779. * - systemd with a TID 3000 and a parent of init/1
  780. * - systemd child thread with TID 4000, the parent is 3000
  781. * - NetworkManager is a child of init with a TID of 3500.
  782. */
  783. static int task_list_cmp(void *priv, const struct list_head *la, const struct list_head *lb)
  784. {
  785. struct machine *machine = priv;
  786. struct thread_list *task_a = list_entry(la, struct thread_list, list);
  787. struct thread_list *task_b = list_entry(lb, struct thread_list, list);
  788. struct thread *a = task_a->thread;
  789. struct thread *b = task_b->thread;
  790. int level_a, level_b, res;
  791. /* Same thread? */
  792. if (thread__tid(a) == thread__tid(b))
  793. return 0;
  794. /* Compare a and b to root. */
  795. if (thread__tid(a) == 0)
  796. return -1;
  797. if (thread__tid(b) == 0)
  798. return 1;
  799. /* If parents match sort by tid. */
  800. if (thread__ppid(a) == thread__ppid(b))
  801. return thread__tid(a) < thread__tid(b) ? -1 : 1;
  802. /*
  803. * Find a and b such that if they are a child of each other a and b's
  804. * tid's match, otherwise a and b have a common parent and distinct
  805. * tid's to sort by. First make the depths of the threads match.
  806. */
  807. level_a = thread_level(machine, a);
  808. level_b = thread_level(machine, b);
  809. a = thread__get(a);
  810. b = thread__get(b);
  811. for (int i = level_a; i > level_b; i--) {
  812. struct thread *parent = machine__find_thread(machine, -1, thread__ppid(a));
  813. thread__put(a);
  814. if (!parent) {
  815. pr_err("Missing parent thread of %d\n", thread__tid(a));
  816. thread__put(b);
  817. return -1;
  818. }
  819. a = parent;
  820. }
  821. for (int i = level_b; i > level_a; i--) {
  822. struct thread *parent = machine__find_thread(machine, -1, thread__ppid(b));
  823. thread__put(b);
  824. if (!parent) {
  825. pr_err("Missing parent thread of %d\n", thread__tid(b));
  826. thread__put(a);
  827. return 1;
  828. }
  829. b = parent;
  830. }
  831. /* Search up to a common parent. */
  832. while (thread__ppid(a) != thread__ppid(b)) {
  833. struct thread *parent;
  834. parent = machine__find_thread(machine, -1, thread__ppid(a));
  835. thread__put(a);
  836. if (!parent)
  837. pr_err("Missing parent thread of %d\n", thread__tid(a));
  838. a = parent;
  839. parent = machine__find_thread(machine, -1, thread__ppid(b));
  840. thread__put(b);
  841. if (!parent)
  842. pr_err("Missing parent thread of %d\n", thread__tid(b));
  843. b = parent;
  844. if (!a || !b) {
  845. /* Handle missing parent (unexpected) with some sanity. */
  846. thread__put(a);
  847. thread__put(b);
  848. return !a && !b ? 0 : (!a ? -1 : 1);
  849. }
  850. }
  851. if (thread__tid(a) == thread__tid(b)) {
  852. /* a is a child of b or vice-versa, deeper levels appear later. */
  853. res = level_a < level_b ? -1 : (level_a > level_b ? 1 : 0);
  854. } else {
  855. /* Sort by tid now the parent is the same. */
  856. res = thread__tid(a) < thread__tid(b) ? -1 : 1;
  857. }
  858. thread__put(a);
  859. thread__put(b);
  860. return res;
  861. }
  862. static int tasks_print(struct report *rep, FILE *fp)
  863. {
  864. struct machine *machine = &rep->session->machines.host;
  865. LIST_HEAD(tasks);
  866. int ret;
  867. ret = machine__thread_list(machine, &tasks);
  868. if (!ret) {
  869. struct thread_list *task;
  870. list_sort(machine, &tasks, task_list_cmp);
  871. fprintf(fp, "# %8s %8s %8s %s\n", "pid", "tid", "ppid", "comm");
  872. list_for_each_entry(task, &tasks, list)
  873. task__print_level(machine, task->thread, fp);
  874. }
  875. thread_list__delete(&tasks);
  876. return ret;
  877. }
  878. static int __cmd_report(struct report *rep)
  879. {
  880. int ret;
  881. struct perf_session *session = rep->session;
  882. struct evsel *pos;
  883. struct perf_data *data = session->data;
  884. signal(SIGINT, sig_handler);
  885. if (rep->cpu_list) {
  886. ret = perf_session__cpu_bitmap(session, rep->cpu_list,
  887. rep->cpu_bitmap);
  888. if (ret) {
  889. ui__error("failed to set cpu bitmap\n");
  890. return ret;
  891. }
  892. session->itrace_synth_opts->cpu_bitmap = rep->cpu_bitmap;
  893. }
  894. if (rep->show_threads) {
  895. ret = perf_read_values_init(&rep->show_threads_values);
  896. if (ret)
  897. return ret;
  898. }
  899. ret = report__setup_sample_type(rep);
  900. if (ret) {
  901. /* report__setup_sample_type() already showed error message */
  902. return ret;
  903. }
  904. if (rep->stats_mode)
  905. stats_setup(rep);
  906. if (rep->tasks_mode)
  907. tasks_setup(rep);
  908. ret = perf_session__process_events(session);
  909. if (ret) {
  910. ui__error("failed to process sample\n");
  911. return ret;
  912. }
  913. evlist__check_mem_load_aux(session->evlist);
  914. if (rep->stats_mode)
  915. return stats_print(rep);
  916. if (rep->tasks_mode)
  917. return tasks_print(rep, stdout);
  918. report__warn_kptr_restrict(rep);
  919. evlist__for_each_entry(session->evlist, pos)
  920. rep->nr_entries += evsel__hists(pos)->nr_entries;
  921. if (use_browser == 0) {
  922. if (verbose > 3)
  923. perf_session__fprintf(session, stdout);
  924. if (verbose > 2)
  925. perf_session__fprintf_dsos(session, stdout);
  926. if (dump_trace) {
  927. stats_print(rep);
  928. return 0;
  929. }
  930. }
  931. ret = report__collapse_hists(rep);
  932. if (ret) {
  933. ui__error("failed to process hist entry\n");
  934. return ret;
  935. }
  936. if (session_done())
  937. return 0;
  938. /*
  939. * recalculate number of entries after collapsing since it
  940. * might be changed during the collapse phase.
  941. */
  942. rep->nr_entries = 0;
  943. evlist__for_each_entry(session->evlist, pos)
  944. rep->nr_entries += evsel__hists(pos)->nr_entries;
  945. if (rep->nr_entries == 0) {
  946. ui__error("The %s data has no samples!\n", data->path);
  947. return 0;
  948. }
  949. report__output_resort(rep);
  950. if (rep->total_cycles_mode) {
  951. int nr_hpps = 4;
  952. int block_hpps[PERF_HPP_REPORT__BLOCK_MAX_INDEX] = {
  953. PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT,
  954. PERF_HPP_REPORT__BLOCK_LBR_CYCLES,
  955. PERF_HPP_REPORT__BLOCK_CYCLES_PCT,
  956. PERF_HPP_REPORT__BLOCK_AVG_CYCLES,
  957. };
  958. if (session->evlist->nr_br_cntr > 0)
  959. block_hpps[nr_hpps++] = PERF_HPP_REPORT__BLOCK_BRANCH_COUNTER;
  960. block_hpps[nr_hpps++] = PERF_HPP_REPORT__BLOCK_RANGE;
  961. block_hpps[nr_hpps++] = PERF_HPP_REPORT__BLOCK_DSO;
  962. rep->block_reports = block_info__create_report(session->evlist,
  963. rep->total_cycles,
  964. block_hpps, nr_hpps,
  965. &rep->nr_block_reports);
  966. if (!rep->block_reports)
  967. return -1;
  968. }
  969. return report__browse_hists(rep);
  970. }
  971. static int
  972. report_parse_callchain_opt(const struct option *opt, const char *arg, int unset)
  973. {
  974. struct callchain_param *callchain = opt->value;
  975. callchain->enabled = !unset;
  976. /*
  977. * --no-call-graph
  978. */
  979. if (unset) {
  980. symbol_conf.use_callchain = false;
  981. callchain->mode = CHAIN_NONE;
  982. return 0;
  983. }
  984. return parse_callchain_report_opt(arg);
  985. }
  986. static int
  987. parse_time_quantum(const struct option *opt, const char *arg,
  988. int unset __maybe_unused)
  989. {
  990. unsigned long *time_q = opt->value;
  991. char *end;
  992. *time_q = strtoul(arg, &end, 0);
  993. if (end == arg)
  994. goto parse_err;
  995. if (*time_q == 0) {
  996. pr_err("time quantum cannot be 0");
  997. return -1;
  998. }
  999. end = skip_spaces(end);
  1000. if (*end == 0)
  1001. return 0;
  1002. if (!strcmp(end, "s")) {
  1003. *time_q *= NSEC_PER_SEC;
  1004. return 0;
  1005. }
  1006. if (!strcmp(end, "ms")) {
  1007. *time_q *= NSEC_PER_MSEC;
  1008. return 0;
  1009. }
  1010. if (!strcmp(end, "us")) {
  1011. *time_q *= NSEC_PER_USEC;
  1012. return 0;
  1013. }
  1014. if (!strcmp(end, "ns"))
  1015. return 0;
  1016. parse_err:
  1017. pr_err("Cannot parse time quantum `%s'\n", arg);
  1018. return -1;
  1019. }
  1020. int
  1021. report_parse_ignore_callees_opt(const struct option *opt __maybe_unused,
  1022. const char *arg, int unset __maybe_unused)
  1023. {
  1024. if (arg) {
  1025. int err = regcomp(&ignore_callees_regex, arg, REG_EXTENDED);
  1026. if (err) {
  1027. char buf[BUFSIZ];
  1028. regerror(err, &ignore_callees_regex, buf, sizeof(buf));
  1029. pr_err("Invalid --ignore-callees regex: %s\n%s", arg, buf);
  1030. return -1;
  1031. }
  1032. have_ignore_callees = 1;
  1033. }
  1034. return 0;
  1035. }
  1036. static int
  1037. parse_branch_mode(const struct option *opt,
  1038. const char *str __maybe_unused, int unset)
  1039. {
  1040. int *branch_mode = opt->value;
  1041. *branch_mode = !unset;
  1042. return 0;
  1043. }
  1044. static int
  1045. parse_percent_limit(const struct option *opt, const char *str,
  1046. int unset __maybe_unused)
  1047. {
  1048. struct report *rep = opt->value;
  1049. double pcnt = strtof(str, NULL);
  1050. rep->min_percent = pcnt;
  1051. callchain_param.min_percent = pcnt;
  1052. return 0;
  1053. }
  1054. static int process_attr(const struct perf_tool *tool __maybe_unused,
  1055. union perf_event *event,
  1056. struct evlist **pevlist)
  1057. {
  1058. u64 sample_type;
  1059. int err;
  1060. err = perf_event__process_attr(tool, event, pevlist);
  1061. if (err)
  1062. return err;
  1063. /*
  1064. * Check if we need to enable callchains based
  1065. * on events sample_type.
  1066. */
  1067. sample_type = evlist__combined_sample_type(*pevlist);
  1068. callchain_param_setup(sample_type, perf_env__arch((*pevlist)->env));
  1069. return 0;
  1070. }
  1071. int cmd_report(int argc, const char **argv)
  1072. {
  1073. struct perf_session *session;
  1074. struct itrace_synth_opts itrace_synth_opts = { .set = 0, };
  1075. struct stat st;
  1076. bool has_br_stack = false;
  1077. int branch_mode = -1;
  1078. int last_key = 0;
  1079. bool branch_call_mode = false;
  1080. #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent"
  1081. static const char report_callchain_help[] = "Display call graph (stack chain/backtrace):\n\n"
  1082. CALLCHAIN_REPORT_HELP
  1083. "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT;
  1084. char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT;
  1085. const char * const report_usage[] = {
  1086. "perf report [<options>]",
  1087. NULL
  1088. };
  1089. struct report report = {
  1090. .max_stack = PERF_MAX_STACK_DEPTH,
  1091. .pretty_printing_style = "normal",
  1092. .socket_filter = -1,
  1093. .skip_empty = true,
  1094. };
  1095. char *sort_order_help = sort_help("sort by key(s):", SORT_MODE__NORMAL);
  1096. char *field_order_help = sort_help("output field(s):", SORT_MODE__NORMAL);
  1097. const char *disassembler_style = NULL, *objdump_path = NULL, *addr2line_path = NULL;
  1098. const struct option options[] = {
  1099. OPT_STRING('i', "input", &input_name, "file",
  1100. "input file name"),
  1101. OPT_INCR('v', "verbose", &verbose,
  1102. "be more verbose (show symbol address, etc)"),
  1103. OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any warnings or messages"),
  1104. OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
  1105. "dump raw trace in ASCII"),
  1106. OPT_BOOLEAN(0, "stats", &report.stats_mode, "Display event stats"),
  1107. OPT_BOOLEAN(0, "tasks", &report.tasks_mode, "Display recorded tasks"),
  1108. OPT_BOOLEAN(0, "mmaps", &report.mmaps_mode, "Display recorded tasks memory maps"),
  1109. OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
  1110. "file", "vmlinux pathname"),
  1111. OPT_BOOLEAN(0, "ignore-vmlinux", &symbol_conf.ignore_vmlinux,
  1112. "don't load vmlinux even if found"),
  1113. OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
  1114. "file", "kallsyms pathname"),
  1115. OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
  1116. OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
  1117. "load module symbols - WARNING: use only with -k and LIVE kernel"),
  1118. OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
  1119. "Show a column with the number of samples"),
  1120. OPT_BOOLEAN('T', "threads", &report.show_threads,
  1121. "Show per-thread event counters"),
  1122. OPT_STRING(0, "pretty", &report.pretty_printing_style, "key",
  1123. "pretty printing style key: normal raw"),
  1124. #ifdef HAVE_SLANG_SUPPORT
  1125. OPT_BOOLEAN(0, "tui", &report.use_tui, "Use the TUI interface"),
  1126. #endif
  1127. #ifdef HAVE_GTK2_SUPPORT
  1128. OPT_BOOLEAN(0, "gtk", &report.use_gtk, "Use the GTK2 interface"),
  1129. #endif
  1130. OPT_BOOLEAN(0, "stdio", &report.use_stdio,
  1131. "Use the stdio interface"),
  1132. OPT_BOOLEAN(0, "header", &report.header, "Show data header."),
  1133. OPT_BOOLEAN(0, "header-only", &report.header_only,
  1134. "Show only data header."),
  1135. OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
  1136. sort_order_help),
  1137. OPT_STRING('F', "fields", &field_order, "key[,keys...]",
  1138. field_order_help),
  1139. OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization,
  1140. "Show sample percentage for different cpu modes"),
  1141. OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
  1142. "Show sample percentage for different cpu modes", PARSE_OPT_HIDDEN),
  1143. OPT_STRING('p', "parent", &parent_pattern, "regex",
  1144. "regex filter to identify parent, see: '--sort parent'"),
  1145. OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
  1146. "Only display entries with parent-match"),
  1147. OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param,
  1148. "print_type,threshold[,print_limit],order,sort_key[,branch],value",
  1149. report_callchain_help, &report_parse_callchain_opt,
  1150. callchain_default_opt),
  1151. OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain,
  1152. "Accumulate callchains of children and show total overhead as well. "
  1153. "Enabled by default, use --no-children to disable."),
  1154. OPT_INTEGER(0, "max-stack", &report.max_stack,
  1155. "Set the maximum stack depth when parsing the callchain, "
  1156. "anything beyond the specified depth will be ignored. "
  1157. "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
  1158. OPT_BOOLEAN('G', "inverted", &report.inverted_callchain,
  1159. "alias for inverted call graph"),
  1160. OPT_CALLBACK(0, "ignore-callees", NULL, "regex",
  1161. "ignore callees of these functions in call graphs",
  1162. report_parse_ignore_callees_opt),
  1163. OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
  1164. "only consider symbols in these dsos"),
  1165. OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
  1166. "only consider symbols in these comms"),
  1167. OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]",
  1168. "only consider symbols in these pids"),
  1169. OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
  1170. "only consider symbols in these tids"),
  1171. OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
  1172. "only consider these symbols"),
  1173. OPT_STRING(0, "symbol-filter", &report.symbol_filter_str, "filter",
  1174. "only show symbols that (partially) match with this filter"),
  1175. OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str,
  1176. "width[,width...]",
  1177. "don't try to adjust column width, use these fixed values"),
  1178. OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
  1179. "separator for columns, no spaces will be added between "
  1180. "columns '.' is reserved."),
  1181. OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved,
  1182. "Only display entries resolved to a symbol"),
  1183. OPT_CALLBACK(0, "symfs", NULL, "directory",
  1184. "Look for files with symbols relative to this directory",
  1185. symbol__config_symfs),
  1186. OPT_STRING('C', "cpu", &report.cpu_list, "cpu",
  1187. "list of cpus to profile"),
  1188. OPT_BOOLEAN('I', "show-info", &report.show_full_info,
  1189. "Display extended information about perf.data file"),
  1190. OPT_BOOLEAN(0, "source", &annotate_opts.annotate_src,
  1191. "Interleave source code with assembly code (default)"),
  1192. OPT_BOOLEAN(0, "asm-raw", &annotate_opts.show_asm_raw,
  1193. "Display raw encoding of assembly instructions (default)"),
  1194. OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
  1195. "Specify disassembler style (e.g. -M intel for intel syntax)"),
  1196. OPT_STRING(0, "prefix", &annotate_opts.prefix, "prefix",
  1197. "Add prefix to source file path names in programs (with --prefix-strip)"),
  1198. OPT_STRING(0, "prefix-strip", &annotate_opts.prefix_strip, "N",
  1199. "Strip first N entries of source file path name in programs (with --prefix)"),
  1200. OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
  1201. "Show a column with the sum of periods"),
  1202. OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &report.group_set,
  1203. "Show event group information together"),
  1204. OPT_INTEGER(0, "group-sort-idx", &symbol_conf.group_sort_idx,
  1205. "Sort the output by the event at the index n in group. "
  1206. "If n is invalid, sort by the first event. "
  1207. "WARNING: should be used on grouped events."),
  1208. OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "",
  1209. "use branch records for per branch histogram filling",
  1210. parse_branch_mode),
  1211. OPT_BOOLEAN(0, "branch-history", &branch_call_mode,
  1212. "add last branch records to call history"),
  1213. OPT_STRING(0, "objdump", &objdump_path, "path",
  1214. "objdump binary to use for disassembly and annotations"),
  1215. OPT_STRING(0, "addr2line", &addr2line_path, "path",
  1216. "addr2line binary to use for line numbers"),
  1217. OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
  1218. "Symbol demangling. Enabled by default, use --no-demangle to disable."),
  1219. OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
  1220. "Enable kernel symbol demangling"),
  1221. OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"),
  1222. OPT_INTEGER(0, "samples", &symbol_conf.res_sample,
  1223. "Number of samples to save per histogram entry for individual browsing"),
  1224. OPT_CALLBACK(0, "percent-limit", &report, "percent",
  1225. "Don't show entries under that percent", parse_percent_limit),
  1226. OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
  1227. "how to display percentage of filtered entries", parse_filter_percentage),
  1228. OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
  1229. "Instruction Tracing options\n" ITRACE_HELP,
  1230. itrace_parse_synth_opts),
  1231. OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
  1232. "Show full source file name path for source lines"),
  1233. OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf.show_ref_callgraph,
  1234. "Show callgraph from reference event"),
  1235. OPT_BOOLEAN(0, "stitch-lbr", &report.stitch_lbr,
  1236. "Enable LBR callgraph stitching approach"),
  1237. OPT_INTEGER(0, "socket-filter", &report.socket_filter,
  1238. "only show processor socket that match with this filter"),
  1239. OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace,
  1240. "Show raw trace event output (do not use print fmt or plugins)"),
  1241. OPT_BOOLEAN('H', "hierarchy", &symbol_conf.report_hierarchy,
  1242. "Show entries in a hierarchy"),
  1243. OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
  1244. "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
  1245. stdio__config_color, "always"),
  1246. OPT_STRING(0, "time", &report.time_str, "str",
  1247. "Time span of interest (start,stop)"),
  1248. OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name,
  1249. "Show inline function"),
  1250. OPT_CALLBACK(0, "percent-type", &annotate_opts, "local-period",
  1251. "Set percent type local/global-period/hits",
  1252. annotate_parse_percent_type),
  1253. OPT_BOOLEAN(0, "ns", &symbol_conf.nanosecs, "Show times in nanosecs"),
  1254. OPT_CALLBACK(0, "time-quantum", &symbol_conf.time_quantum, "time (ms|us|ns|s)",
  1255. "Set time quantum for time sort key (default 100ms)",
  1256. parse_time_quantum),
  1257. OPTS_EVSWITCH(&report.evswitch),
  1258. OPT_BOOLEAN(0, "total-cycles", &report.total_cycles_mode,
  1259. "Sort all blocks by 'Sampled Cycles%'"),
  1260. OPT_BOOLEAN(0, "disable-order", &report.disable_order,
  1261. "Disable raw trace ordering"),
  1262. OPT_BOOLEAN(0, "skip-empty", &report.skip_empty,
  1263. "Do not display empty (or dummy) events in the output"),
  1264. OPT_END()
  1265. };
  1266. struct perf_data data = {
  1267. .mode = PERF_DATA_MODE_READ,
  1268. };
  1269. int ret = hists__init();
  1270. char sort_tmp[128];
  1271. bool ordered_events = true;
  1272. if (ret < 0)
  1273. goto exit;
  1274. /*
  1275. * tasks_mode require access to exited threads to list those that are in
  1276. * the data file. Off-cpu events are synthesized after other events and
  1277. * reference exited threads.
  1278. */
  1279. symbol_conf.keep_exited_threads = true;
  1280. annotation_options__init();
  1281. ret = perf_config(report__config, &report);
  1282. if (ret)
  1283. goto exit;
  1284. argc = parse_options(argc, argv, options, report_usage, 0);
  1285. if (argc) {
  1286. /*
  1287. * Special case: if there's an argument left then assume that
  1288. * it's a symbol filter:
  1289. */
  1290. if (argc > 1)
  1291. usage_with_options(report_usage, options);
  1292. report.symbol_filter_str = argv[0];
  1293. }
  1294. if (disassembler_style) {
  1295. annotate_opts.disassembler_style = strdup(disassembler_style);
  1296. if (!annotate_opts.disassembler_style)
  1297. return -ENOMEM;
  1298. }
  1299. if (objdump_path) {
  1300. annotate_opts.objdump_path = strdup(objdump_path);
  1301. if (!annotate_opts.objdump_path)
  1302. return -ENOMEM;
  1303. }
  1304. if (addr2line_path) {
  1305. symbol_conf.addr2line_path = strdup(addr2line_path);
  1306. if (!symbol_conf.addr2line_path)
  1307. return -ENOMEM;
  1308. }
  1309. if (annotate_check_args() < 0) {
  1310. ret = -EINVAL;
  1311. goto exit;
  1312. }
  1313. if (report.mmaps_mode)
  1314. report.tasks_mode = true;
  1315. if (dump_trace && report.disable_order)
  1316. ordered_events = false;
  1317. if (quiet)
  1318. perf_quiet_option();
  1319. ret = symbol__validate_sym_arguments();
  1320. if (ret)
  1321. goto exit;
  1322. if (report.inverted_callchain)
  1323. callchain_param.order = ORDER_CALLER;
  1324. if (symbol_conf.cumulate_callchain && !callchain_param.order_set)
  1325. callchain_param.order = ORDER_CALLER;
  1326. if ((itrace_synth_opts.callchain || itrace_synth_opts.add_callchain) &&
  1327. (int)itrace_synth_opts.callchain_sz > report.max_stack)
  1328. report.max_stack = itrace_synth_opts.callchain_sz;
  1329. if (!input_name || !strlen(input_name)) {
  1330. if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))
  1331. input_name = "-";
  1332. else
  1333. input_name = "perf.data";
  1334. }
  1335. repeat:
  1336. data.path = input_name;
  1337. data.force = symbol_conf.force;
  1338. symbol_conf.skip_empty = report.skip_empty;
  1339. perf_tool__init(&report.tool, ordered_events);
  1340. report.tool.sample = process_sample_event;
  1341. report.tool.mmap = perf_event__process_mmap;
  1342. report.tool.mmap2 = perf_event__process_mmap2;
  1343. report.tool.comm = perf_event__process_comm;
  1344. report.tool.namespaces = perf_event__process_namespaces;
  1345. report.tool.cgroup = perf_event__process_cgroup;
  1346. report.tool.exit = perf_event__process_exit;
  1347. report.tool.fork = perf_event__process_fork;
  1348. report.tool.lost = perf_event__process_lost;
  1349. report.tool.read = process_read_event;
  1350. report.tool.attr = process_attr;
  1351. #ifdef HAVE_LIBTRACEEVENT
  1352. report.tool.tracing_data = perf_event__process_tracing_data;
  1353. #endif
  1354. report.tool.build_id = perf_event__process_build_id;
  1355. report.tool.id_index = perf_event__process_id_index;
  1356. report.tool.auxtrace_info = perf_event__process_auxtrace_info;
  1357. report.tool.auxtrace = perf_event__process_auxtrace;
  1358. report.tool.event_update = perf_event__process_event_update;
  1359. report.tool.feature = process_feature_event;
  1360. report.tool.ordering_requires_timestamps = true;
  1361. session = perf_session__new(&data, &report.tool);
  1362. if (IS_ERR(session)) {
  1363. ret = PTR_ERR(session);
  1364. goto exit;
  1365. }
  1366. ret = evswitch__init(&report.evswitch, session->evlist, stderr);
  1367. if (ret)
  1368. goto exit;
  1369. if (zstd_init(&(session->zstd_data), 0) < 0)
  1370. pr_warning("Decompression initialization failed. Reported data may be incomplete.\n");
  1371. if (report.queue_size) {
  1372. ordered_events__set_alloc_size(&session->ordered_events,
  1373. report.queue_size);
  1374. }
  1375. session->itrace_synth_opts = &itrace_synth_opts;
  1376. report.session = session;
  1377. has_br_stack = perf_header__has_feat(&session->header,
  1378. HEADER_BRANCH_STACK);
  1379. if (evlist__combined_sample_type(session->evlist) & PERF_SAMPLE_STACK_USER)
  1380. has_br_stack = false;
  1381. setup_forced_leader(&report, session->evlist);
  1382. if (symbol_conf.group_sort_idx && evlist__nr_groups(session->evlist) == 0) {
  1383. parse_options_usage(NULL, options, "group-sort-idx", 0);
  1384. ret = -EINVAL;
  1385. goto error;
  1386. }
  1387. if (itrace_synth_opts.last_branch || itrace_synth_opts.add_last_branch)
  1388. has_br_stack = true;
  1389. if (has_br_stack && branch_call_mode)
  1390. symbol_conf.show_branchflag_count = true;
  1391. memset(&report.brtype_stat, 0, sizeof(struct branch_type_stat));
  1392. /*
  1393. * Branch mode is a tristate:
  1394. * -1 means default, so decide based on the file having branch data.
  1395. * 0/1 means the user chose a mode.
  1396. */
  1397. if (((branch_mode == -1 && has_br_stack) || branch_mode == 1) &&
  1398. !branch_call_mode) {
  1399. sort__mode = SORT_MODE__BRANCH;
  1400. symbol_conf.cumulate_callchain = false;
  1401. }
  1402. if (branch_call_mode) {
  1403. callchain_param.key = CCKEY_ADDRESS;
  1404. callchain_param.branch_callstack = true;
  1405. symbol_conf.use_callchain = true;
  1406. callchain_register_param(&callchain_param);
  1407. if (sort_order == NULL)
  1408. sort_order = "srcline,symbol,dso";
  1409. }
  1410. if (report.mem_mode) {
  1411. if (sort__mode == SORT_MODE__BRANCH) {
  1412. pr_err("branch and mem mode incompatible\n");
  1413. goto error;
  1414. }
  1415. sort__mode = SORT_MODE__MEMORY;
  1416. symbol_conf.cumulate_callchain = false;
  1417. }
  1418. if (symbol_conf.report_hierarchy) {
  1419. /* disable incompatible options */
  1420. symbol_conf.cumulate_callchain = false;
  1421. if (field_order) {
  1422. pr_err("Error: --hierarchy and --fields options cannot be used together\n");
  1423. parse_options_usage(report_usage, options, "F", 1);
  1424. parse_options_usage(NULL, options, "hierarchy", 0);
  1425. goto error;
  1426. }
  1427. perf_hpp_list.need_collapse = true;
  1428. }
  1429. if (report.use_stdio)
  1430. use_browser = 0;
  1431. #ifdef HAVE_SLANG_SUPPORT
  1432. else if (report.use_tui)
  1433. use_browser = 1;
  1434. #endif
  1435. #ifdef HAVE_GTK2_SUPPORT
  1436. else if (report.use_gtk)
  1437. use_browser = 2;
  1438. #endif
  1439. /* Force tty output for header output and per-thread stat. */
  1440. if (report.header || report.header_only || report.show_threads)
  1441. use_browser = 0;
  1442. if (report.header || report.header_only)
  1443. report.tool.show_feat_hdr = SHOW_FEAT_HEADER;
  1444. if (report.show_full_info)
  1445. report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO;
  1446. if (report.stats_mode || report.tasks_mode)
  1447. use_browser = 0;
  1448. if (report.stats_mode && report.tasks_mode) {
  1449. pr_err("Error: --tasks and --mmaps can't be used together with --stats\n");
  1450. goto error;
  1451. }
  1452. if (report.total_cycles_mode) {
  1453. if (sort__mode != SORT_MODE__BRANCH)
  1454. report.total_cycles_mode = false;
  1455. else
  1456. sort_order = NULL;
  1457. }
  1458. if (sort_order && strstr(sort_order, "type")) {
  1459. report.data_type = true;
  1460. annotate_opts.annotate_src = false;
  1461. #ifndef HAVE_DWARF_GETLOCATIONS_SUPPORT
  1462. pr_err("Error: Data type profiling is disabled due to missing DWARF support\n");
  1463. goto error;
  1464. #endif
  1465. }
  1466. if (strcmp(input_name, "-") != 0)
  1467. setup_browser(true);
  1468. else
  1469. use_browser = 0;
  1470. if (report.data_type && use_browser == 1) {
  1471. symbol_conf.annotate_data_member = true;
  1472. symbol_conf.annotate_data_sample = true;
  1473. }
  1474. if (sort_order && strstr(sort_order, "ipc")) {
  1475. parse_options_usage(report_usage, options, "s", 1);
  1476. goto error;
  1477. }
  1478. if (sort_order && strstr(sort_order, "symbol")) {
  1479. if (sort__mode == SORT_MODE__BRANCH) {
  1480. snprintf(sort_tmp, sizeof(sort_tmp), "%s,%s",
  1481. sort_order, "ipc_lbr");
  1482. report.symbol_ipc = true;
  1483. } else {
  1484. snprintf(sort_tmp, sizeof(sort_tmp), "%s,%s",
  1485. sort_order, "ipc_null");
  1486. }
  1487. sort_order = sort_tmp;
  1488. }
  1489. if ((last_key != K_SWITCH_INPUT_DATA && last_key != K_RELOAD) &&
  1490. (setup_sorting(session->evlist) < 0)) {
  1491. if (sort_order)
  1492. parse_options_usage(report_usage, options, "s", 1);
  1493. if (field_order)
  1494. parse_options_usage(sort_order ? NULL : report_usage,
  1495. options, "F", 1);
  1496. goto error;
  1497. }
  1498. if ((report.header || report.header_only) && !quiet) {
  1499. perf_session__fprintf_info(session, stdout,
  1500. report.show_full_info);
  1501. if (report.header_only) {
  1502. if (data.is_pipe) {
  1503. /*
  1504. * we need to process first few records
  1505. * which contains PERF_RECORD_HEADER_FEATURE.
  1506. */
  1507. perf_session__process_events(session);
  1508. }
  1509. ret = 0;
  1510. goto error;
  1511. }
  1512. } else if (use_browser == 0 && !quiet &&
  1513. !report.stats_mode && !report.tasks_mode) {
  1514. fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
  1515. stdout);
  1516. }
  1517. /*
  1518. * Only in the TUI browser we are doing integrated annotation,
  1519. * so don't allocate extra space that won't be used in the stdio
  1520. * implementation.
  1521. */
  1522. if (ui__has_annotation() || report.symbol_ipc || report.data_type ||
  1523. report.total_cycles_mode) {
  1524. ret = symbol__annotation_init();
  1525. if (ret < 0)
  1526. goto error;
  1527. /*
  1528. * For searching by name on the "Browse map details".
  1529. * providing it only in verbose mode not to bloat too
  1530. * much struct symbol.
  1531. */
  1532. if (verbose > 0) {
  1533. /*
  1534. * XXX: Need to provide a less kludgy way to ask for
  1535. * more space per symbol, the u32 is for the index on
  1536. * the ui browser.
  1537. * See symbol__browser_index.
  1538. */
  1539. symbol_conf.priv_size += sizeof(u32);
  1540. }
  1541. annotation_config__init();
  1542. }
  1543. if (symbol__init(&session->header.env) < 0)
  1544. goto error;
  1545. if (report.time_str) {
  1546. ret = perf_time__parse_for_ranges(report.time_str, session,
  1547. &report.ptime_range,
  1548. &report.range_size,
  1549. &report.range_num);
  1550. if (ret < 0)
  1551. goto error;
  1552. itrace_synth_opts__set_time_range(&itrace_synth_opts,
  1553. report.ptime_range,
  1554. report.range_num);
  1555. }
  1556. #ifdef HAVE_LIBTRACEEVENT
  1557. if (session->tevent.pevent &&
  1558. tep_set_function_resolver(session->tevent.pevent,
  1559. machine__resolve_kernel_addr,
  1560. &session->machines.host) < 0) {
  1561. pr_err("%s: failed to set libtraceevent function resolver\n",
  1562. __func__);
  1563. return -1;
  1564. }
  1565. #endif
  1566. sort__setup_elide(stdout);
  1567. ret = __cmd_report(&report);
  1568. if (ret == K_SWITCH_INPUT_DATA || ret == K_RELOAD) {
  1569. perf_session__delete(session);
  1570. last_key = K_SWITCH_INPUT_DATA;
  1571. goto repeat;
  1572. } else
  1573. ret = 0;
  1574. if (!use_browser && (verbose > 2 || debug_kmaps))
  1575. perf_session__dump_kmaps(session);
  1576. error:
  1577. if (report.ptime_range) {
  1578. itrace_synth_opts__clear_time_range(&itrace_synth_opts);
  1579. zfree(&report.ptime_range);
  1580. }
  1581. if (report.block_reports) {
  1582. block_info__free_report(report.block_reports,
  1583. report.nr_block_reports);
  1584. report.block_reports = NULL;
  1585. }
  1586. zstd_fini(&(session->zstd_data));
  1587. perf_session__delete(session);
  1588. exit:
  1589. annotation_options__exit();
  1590. free(sort_order_help);
  1591. free(field_order_help);
  1592. return ret;
  1593. }