1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
286470930SIngo Molnar /*
386470930SIngo Molnar * builtin-report.c
486470930SIngo Molnar *
586470930SIngo Molnar * Builtin report command: Analyze the perf.data input file,
686470930SIngo Molnar * look up and read DSOs and symbol information and display
786470930SIngo Molnar * a histogram of results, along various sorting keys.
886470930SIngo Molnar */
986470930SIngo Molnar #include "builtin.h"
1086470930SIngo Molnar
1141840d21STaeung Song #include "util/config.h"
1286470930SIngo Molnar
1378f7defeSArnaldo Carvalho de Melo #include "util/annotate.h"
1486470930SIngo Molnar #include "util/color.h"
154a3cec84SArnaldo Carvalho de Melo #include "util/dso.h"
165da50258SArnaldo Carvalho de Melo #include <linux/list.h>
1743cbcd8aSArnaldo Carvalho de Melo #include <linux/rbtree.h>
18930f8b34SJiri Olsa #include <linux/err.h>
197f7c536fSArnaldo Carvalho de Melo #include <linux/zalloc.h>
201101f69aSArnaldo Carvalho de Melo #include "util/map.h"
2186470930SIngo Molnar #include "util/symbol.h"
22d3300a3cSArnaldo Carvalho de Melo #include "util/map_symbol.h"
23d3300a3cSArnaldo Carvalho de Melo #include "util/mem-events.h"
24d3300a3cSArnaldo Carvalho de Melo #include "util/branch.h"
25f55c5552SFrederic Weisbecker #include "util/callchain.h"
268d513270SBrice Goglin #include "util/values.h"
2786470930SIngo Molnar
2886470930SIngo Molnar #include "perf.h"
298f28827aSFrederic Weisbecker #include "util/debug.h"
30e248de33SArnaldo Carvalho de Melo #include "util/evlist.h"
31e248de33SArnaldo Carvalho de Melo #include "util/evsel.h"
32ef4b1a53SArnaldo Carvalho de Melo #include "util/evswitch.h"
337c6a1c65SPeter Zijlstra #include "util/header.h"
3494c744b6SArnaldo Carvalho de Melo #include "util/session.h"
3597b9d866SArnaldo Carvalho de Melo #include "util/srcline.h"
3645694aa7SArnaldo Carvalho de Melo #include "util/tool.h"
3786470930SIngo Molnar
384b6ab94eSJosh Poimboeuf #include <subcmd/parse-options.h>
3934b7b0f9SNamhyung Kim #include <subcmd/exec-cmd.h>
4086470930SIngo Molnar #include "util/parse-events.h"
4186470930SIngo Molnar
426baa0a5aSFrederic Weisbecker #include "util/thread.h"
43dd68ada2SJohn Kacur #include "util/sort.h"
443d1d07ecSJohn Kacur #include "util/hist.h"
45f5fc1412SJiri Olsa #include "util/data.h"
4668e94f4eSIrina Tirdea #include "arch/common.h"
4746690a80SDavid Ahern #include "util/time-utils.h"
48520a2ebcSAdrian Hunter #include "util/auxtrace.h"
4958db1d6eSArnaldo Carvalho de Melo #include "util/units.h"
50fb71c86cSArnaldo Carvalho de Melo #include "util/util.h" // perf_tip()
518520a98dSArnaldo Carvalho de Melo #include "ui/ui.h"
52171f7474SArnaldo Carvalho de Melo #include "ui/progress.h"
536f7164faSJin Yao #include "util/block-info.h"
54520a2ebcSAdrian Hunter
55fc67297bSNamhyung Kim #include <dlfcn.h>
56a43783aeSArnaldo Carvalho de Melo #include <errno.h>
57fd20e811SArnaldo Carvalho de Melo #include <inttypes.h>
581eae20c1SArnaldo Carvalho de Melo #include <regex.h>
593052ba56SArnaldo Carvalho de Melo #include <linux/ctype.h>
609607ad3aSArnaldo Carvalho de Melo #include <signal.h>
615d67be97SAnton Blanchard #include <linux/bitmap.h>
628520a98dSArnaldo Carvalho de Melo #include <linux/string.h>
63531d2410SArnaldo Carvalho de Melo #include <linux/stringify.h>
642a1292cbSAndi Kleen #include <linux/time64.h>
657a8ef4c4SArnaldo Carvalho de Melo #include <sys/types.h>
667a8ef4c4SArnaldo Carvalho de Melo #include <sys/stat.h>
677a8ef4c4SArnaldo Carvalho de Melo #include <unistd.h>
686439d7d1SArnaldo Carvalho de Melo #include <linux/mman.h>
695d67be97SAnton Blanchard
70378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
71378ef0f5SIan Rogers #include <traceevent/event-parse.h>
72378ef0f5SIan Rogers #endif
73378ef0f5SIan Rogers
7428b21393SArnaldo Carvalho de Melo struct report {
7545694aa7SArnaldo Carvalho de Melo struct perf_tool tool;
76d20deb64SArnaldo Carvalho de Melo struct perf_session *session;
77ef4b1a53SArnaldo Carvalho de Melo struct evswitch evswitch;
783402ae0aSIan Rogers #ifdef HAVE_SLANG_SUPPORT
793402ae0aSIan Rogers bool use_tui;
803402ae0aSIan Rogers #endif
81557cc18eSIan Rogers #ifdef HAVE_GTK2_SUPPORT
823402ae0aSIan Rogers bool use_gtk;
83557cc18eSIan Rogers #endif
843402ae0aSIan Rogers bool use_stdio;
85fa372aaeSArnaldo Carvalho de Melo bool show_full_info;
86fa372aaeSArnaldo Carvalho de Melo bool show_threads;
87fa372aaeSArnaldo Carvalho de Melo bool inverted_callchain;
88f4f7e28dSStephane Eranian bool mem_mode;
89a4a4d0a7SJiri Olsa bool stats_mode;
90930f8b34SJiri Olsa bool tasks_mode;
916439d7d1SArnaldo Carvalho de Melo bool mmaps_mode;
925cfe2c82SJiri Olsa bool header;
935cfe2c82SJiri Olsa bool header_only;
9498df858eSAndi Kleen bool nonany_branch_mode;
9557b5de46SJiri Olsa bool group_set;
96b1d1429bSKan Liang bool stitch_lbr;
972e989f82SJin Yao bool disable_order;
982775de0bSNamhyung Kim bool skip_empty;
9991e95617SWaiman Long int max_stack;
100fa372aaeSArnaldo Carvalho de Melo struct perf_read_values show_threads_values;
101fa372aaeSArnaldo Carvalho de Melo const char *pretty_printing_style;
102fa372aaeSArnaldo Carvalho de Melo const char *cpu_list;
103b14ffacaSNamhyung Kim const char *symbol_filter_str;
10446690a80SDavid Ahern const char *time_str;
1050a3cc3aeSJin Yao struct perf_time_interval *ptime_range;
1060a3cc3aeSJin Yao int range_size;
1075b969bc7SJin Yao int range_num;
108064f1981SNamhyung Kim float min_percent;
10958c311daSNamhyung Kim u64 nr_entries;
11094786b67SJiri Olsa u64 queue_size;
1116f7164faSJin Yao u64 total_cycles;
11221394d94SKan Liang int socket_filter;
113fa372aaeSArnaldo Carvalho de Melo DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
1142d78b189SJin Yao struct branch_type_stat brtype_stat;
115ec6ae74fSJin Yao bool symbol_ipc;
1166f7164faSJin Yao bool total_cycles_mode;
1176f7164faSJin Yao struct block_report *block_reports;
118cca0cc76SJin Yao int nr_block_reports;
119d20deb64SArnaldo Carvalho de Melo };
1205d67be97SAnton Blanchard
report__config(const char * var,const char * value,void * cb)12128b21393SArnaldo Carvalho de Melo static int report__config(const char *var, const char *value, void *cb)
12200c7e1f1SNamhyung Kim {
12394786b67SJiri Olsa struct report *rep = cb;
12494786b67SJiri Olsa
12500c7e1f1SNamhyung Kim if (!strcmp(var, "report.group")) {
12600c7e1f1SNamhyung Kim symbol_conf.event_group = perf_config_bool(var, value);
12700c7e1f1SNamhyung Kim return 0;
12800c7e1f1SNamhyung Kim }
129eec574e6SNamhyung Kim if (!strcmp(var, "report.percent-limit")) {
1302665b452SNamhyung Kim double pcnt = strtof(value, NULL);
1312665b452SNamhyung Kim
1322665b452SNamhyung Kim rep->min_percent = pcnt;
1332665b452SNamhyung Kim callchain_param.min_percent = pcnt;
134eec574e6SNamhyung Kim return 0;
135eec574e6SNamhyung Kim }
1368d8e645cSNamhyung Kim if (!strcmp(var, "report.children")) {
1378d8e645cSNamhyung Kim symbol_conf.cumulate_callchain = perf_config_bool(var, value);
1388d8e645cSNamhyung Kim return 0;
1398d8e645cSNamhyung Kim }
14025ce4bb8SArnaldo Carvalho de Melo if (!strcmp(var, "report.queue-size"))
14125ce4bb8SArnaldo Carvalho de Melo return perf_config_u64(&rep->queue_size, var, value);
14225ce4bb8SArnaldo Carvalho de Melo
143fa1f4565SArnaldo Carvalho de Melo if (!strcmp(var, "report.sort_order")) {
144fa1f4565SArnaldo Carvalho de Melo default_sort_order = strdup(value);
1458f08c363SIan Rogers if (!default_sort_order) {
1468f08c363SIan Rogers pr_err("Not enough memory for report.sort_order\n");
1478f08c363SIan Rogers return -1;
1488f08c363SIan Rogers }
149fa1f4565SArnaldo Carvalho de Melo return 0;
150fa1f4565SArnaldo Carvalho de Melo }
15100c7e1f1SNamhyung Kim
1528f08cf33SNamhyung Kim if (!strcmp(var, "report.skip-empty")) {
1538f08cf33SNamhyung Kim rep->skip_empty = perf_config_bool(var, value);
1548f08cf33SNamhyung Kim return 0;
1558f08cf33SNamhyung Kim }
1568f08cf33SNamhyung Kim
1578f08c363SIan Rogers pr_debug("%s variable unknown, ignoring...", var);
158b8cbb349SWang Nan return 0;
15900c7e1f1SNamhyung Kim }
16000c7e1f1SNamhyung Kim
hist_iter__report_callback(struct hist_entry_iter * iter,struct addr_location * al,bool single,void * arg)1619d3c02d7SNamhyung Kim static int hist_iter__report_callback(struct hist_entry_iter *iter,
1629d3c02d7SNamhyung Kim struct addr_location *al, bool single,
1639d3c02d7SNamhyung Kim void *arg)
1649d3c02d7SNamhyung Kim {
1659d3c02d7SNamhyung Kim int err = 0;
1669d3c02d7SNamhyung Kim struct report *rep = arg;
1679d3c02d7SNamhyung Kim struct hist_entry *he = iter->he;
16832dcd021SJiri Olsa struct evsel *evsel = iter->evsel;
169bab89f6aSTaeung Song struct perf_sample *sample = iter->sample;
1709d3c02d7SNamhyung Kim struct mem_info *mi;
1719d3c02d7SNamhyung Kim struct branch_info *bi;
1729d3c02d7SNamhyung Kim
173ec6ae74fSJin Yao if (!ui__has_annotation() && !rep->symbol_ipc)
1749d3c02d7SNamhyung Kim return 0;
1759d3c02d7SNamhyung Kim
1769d3c02d7SNamhyung Kim if (sort__mode == SORT_MODE__BRANCH) {
1779d3c02d7SNamhyung Kim bi = he->branch_info;
178e345f3bdSArnaldo Carvalho de Melo err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
1799d3c02d7SNamhyung Kim if (err)
1809d3c02d7SNamhyung Kim goto out;
1819d3c02d7SNamhyung Kim
182e345f3bdSArnaldo Carvalho de Melo err = addr_map_symbol__inc_samples(&bi->to, sample, evsel);
1839d3c02d7SNamhyung Kim
1849d3c02d7SNamhyung Kim } else if (rep->mem_mode) {
1859d3c02d7SNamhyung Kim mi = he->mem_info;
186e345f3bdSArnaldo Carvalho de Melo err = addr_map_symbol__inc_samples(&mi->daddr, sample, evsel);
1879d3c02d7SNamhyung Kim if (err)
1889d3c02d7SNamhyung Kim goto out;
1899d3c02d7SNamhyung Kim
190e345f3bdSArnaldo Carvalho de Melo err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr);
1919d3c02d7SNamhyung Kim
1929d3c02d7SNamhyung Kim } else if (symbol_conf.cumulate_callchain) {
1939d3c02d7SNamhyung Kim if (single)
194e345f3bdSArnaldo Carvalho de Melo err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr);
1959d3c02d7SNamhyung Kim } else {
196e345f3bdSArnaldo Carvalho de Melo err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr);
1979d3c02d7SNamhyung Kim }
1989d3c02d7SNamhyung Kim
1999d3c02d7SNamhyung Kim out:
2009d3c02d7SNamhyung Kim return err;
2019d3c02d7SNamhyung Kim }
2029d3c02d7SNamhyung Kim
hist_iter__branch_callback(struct hist_entry_iter * iter,struct addr_location * al __maybe_unused,bool single __maybe_unused,void * arg)2032d78b189SJin Yao static int hist_iter__branch_callback(struct hist_entry_iter *iter,
2042d78b189SJin Yao struct addr_location *al __maybe_unused,
2052d78b189SJin Yao bool single __maybe_unused,
2062d78b189SJin Yao void *arg)
2072d78b189SJin Yao {
2082d78b189SJin Yao struct hist_entry *he = iter->he;
2092d78b189SJin Yao struct report *rep = arg;
210c3b10649SJin Yao struct branch_info *bi = he->branch_info;
21140c39e30SJin Yao struct perf_sample *sample = iter->sample;
21232dcd021SJiri Olsa struct evsel *evsel = iter->evsel;
21340c39e30SJin Yao int err;
21440c39e30SJin Yao
215c3b10649SJin Yao branch_type_count(&rep->brtype_stat, &bi->flags,
216c3b10649SJin Yao bi->from.addr, bi->to.addr);
217c3b10649SJin Yao
218ec6ae74fSJin Yao if (!ui__has_annotation() && !rep->symbol_ipc)
21940c39e30SJin Yao return 0;
22040c39e30SJin Yao
221e345f3bdSArnaldo Carvalho de Melo err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
22240c39e30SJin Yao if (err)
22340c39e30SJin Yao goto out;
22440c39e30SJin Yao
225e345f3bdSArnaldo Carvalho de Melo err = addr_map_symbol__inc_samples(&bi->to, sample, evsel);
22640c39e30SJin Yao
22740c39e30SJin Yao out:
22840c39e30SJin Yao return err;
2292d78b189SJin Yao }
2302d78b189SJin Yao
setup_forced_leader(struct report * report,struct evlist * evlist)23157b5de46SJiri Olsa static void setup_forced_leader(struct report *report,
23263503dbaSJiri Olsa struct evlist *evlist)
23357b5de46SJiri Olsa {
234a26bb0baSJin Yao if (report->group_set)
23564b4778bSArnaldo Carvalho de Melo evlist__force_leader(evlist);
23657b5de46SJiri Olsa }
23757b5de46SJiri Olsa
process_feature_event(struct perf_session * session,union perf_event * event)23889f1688aSJiri Olsa static int process_feature_event(struct perf_session *session,
23989f1688aSJiri Olsa union perf_event *event)
24057b5de46SJiri Olsa {
24189f1688aSJiri Olsa struct report *rep = container_of(session->tool, struct report, tool);
24257b5de46SJiri Olsa
24357b5de46SJiri Olsa if (event->feat.feat_id < HEADER_LAST_FEATURE)
24489f1688aSJiri Olsa return perf_event__process_feature(session, event);
24557b5de46SJiri Olsa
24657b5de46SJiri Olsa if (event->feat.feat_id != HEADER_LAST_FEATURE) {
2471b8896fbSJiri Olsa pr_err("failed: wrong feature ID: %" PRI_lu64 "\n",
24857b5de46SJiri Olsa event->feat.feat_id);
24957b5de46SJiri Olsa return -1;
25003de8656SNamhyung Kim } else if (rep->header_only) {
25103de8656SNamhyung Kim session_done = 1;
25257b5de46SJiri Olsa }
25357b5de46SJiri Olsa
25457b5de46SJiri Olsa /*
25592ead7eeSRavi Bangoria * (feat_id = HEADER_LAST_FEATURE) is the end marker which
25692ead7eeSRavi Bangoria * means all features are received, now we can force the
25757b5de46SJiri Olsa * group if needed.
25857b5de46SJiri Olsa */
25957b5de46SJiri Olsa setup_forced_leader(rep, session->evlist);
26057b5de46SJiri Olsa return 0;
26157b5de46SJiri Olsa }
26257b5de46SJiri Olsa
process_sample_event(struct perf_tool * tool,union perf_event * event,struct perf_sample * sample,struct evsel * evsel,struct machine * machine)26345694aa7SArnaldo Carvalho de Melo static int process_sample_event(struct perf_tool *tool,
264d20deb64SArnaldo Carvalho de Melo union perf_event *event,
2658115d60cSArnaldo Carvalho de Melo struct perf_sample *sample,
26632dcd021SJiri Olsa struct evsel *evsel,
267743eb868SArnaldo Carvalho de Melo struct machine *machine)
26886470930SIngo Molnar {
26928b21393SArnaldo Carvalho de Melo struct report *rep = container_of(tool, struct report, tool);
2701ed091c4SArnaldo Carvalho de Melo struct addr_location al;
27169bcb019SNamhyung Kim struct hist_entry_iter iter = {
272063bd936SNamhyung Kim .evsel = evsel,
273063bd936SNamhyung Kim .sample = sample,
274b49a8fe5SNamhyung Kim .hide_unresolved = symbol_conf.hide_unresolved,
2759d3c02d7SNamhyung Kim .add_entry_cb = hist_iter__report_callback,
27669bcb019SNamhyung Kim };
277b91fc39fSArnaldo Carvalho de Melo int ret = 0;
278180f95e2SOGAWA Hirofumi
2795b969bc7SJin Yao if (perf_time__ranges_skip_sample(rep->ptime_range, rep->range_num,
2805b969bc7SJin Yao sample->time)) {
28146690a80SDavid Ahern return 0;
2825b969bc7SJin Yao }
28346690a80SDavid Ahern
284ef4b1a53SArnaldo Carvalho de Melo if (evswitch__discard(&rep->evswitch, evsel))
285ef4b1a53SArnaldo Carvalho de Melo return 0;
286ef4b1a53SArnaldo Carvalho de Melo
2870dd5041cSIan Rogers addr_location__init(&al);
288bb3eb566SArnaldo Carvalho de Melo if (machine__resolve(machine, &al, sample) < 0) {
289a4210141SNamhyung Kim pr_debug("problem processing %d event, skipping it.\n",
29086470930SIngo Molnar event->header.type);
2910dd5041cSIan Rogers ret = -1;
2920dd5041cSIan Rogers goto out_put;
29386470930SIngo Molnar }
29486470930SIngo Molnar
295b1d1429bSKan Liang if (rep->stitch_lbr)
296ee84a303SIan Rogers thread__set_lbr_stitch_enable(al.thread, true);
297b1d1429bSKan Liang
298b49a8fe5SNamhyung Kim if (symbol_conf.hide_unresolved && al.sym == NULL)
299b91fc39fSArnaldo Carvalho de Melo goto out_put;
3007bec7a91SArnaldo Carvalho de Melo
301fa372aaeSArnaldo Carvalho de Melo if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
302b91fc39fSArnaldo Carvalho de Melo goto out_put;
3035d67be97SAnton Blanchard
304f86225dbSAdrian Hunter if (sort__mode == SORT_MODE__BRANCH) {
305f86225dbSAdrian Hunter /*
306f86225dbSAdrian Hunter * A non-synthesized event might not have a branch stack if
307f86225dbSAdrian Hunter * branch stacks have been synthesized (using itrace options).
308f86225dbSAdrian Hunter */
309f86225dbSAdrian Hunter if (!sample->branch_stack)
310f86225dbSAdrian Hunter goto out_put;
3112d78b189SJin Yao
3122d78b189SJin Yao iter.add_entry_cb = hist_iter__branch_callback;
31369bcb019SNamhyung Kim iter.ops = &hist_iter_branch;
314f86225dbSAdrian Hunter } else if (rep->mem_mode) {
31569bcb019SNamhyung Kim iter.ops = &hist_iter_mem;
316f86225dbSAdrian Hunter } else if (symbol_conf.cumulate_callchain) {
3177a13aa28SNamhyung Kim iter.ops = &hist_iter_cumulative;
318f86225dbSAdrian Hunter } else {
31969bcb019SNamhyung Kim iter.ops = &hist_iter_normal;
320f86225dbSAdrian Hunter }
32169bcb019SNamhyung Kim
322ec80fde7SArnaldo Carvalho de Melo if (al.map != NULL)
32363df0e4bSIan Rogers map__dso(al.map)->hit = 1;
324ec80fde7SArnaldo Carvalho de Melo
3256f7164faSJin Yao if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) {
326bdd1666bSJin Yao hist__account_cycles(sample->branch_stack, &al, sample,
3276f7164faSJin Yao rep->nonany_branch_mode,
3286f7164faSJin Yao &rep->total_cycles);
329bdd1666bSJin Yao }
330bdd1666bSJin Yao
331063bd936SNamhyung Kim ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep);
33227a0dcb7SNamhyung Kim if (ret < 0)
33369bcb019SNamhyung Kim pr_debug("problem adding hist entry, skipping event\n");
334b91fc39fSArnaldo Carvalho de Melo out_put:
3350dd5041cSIan Rogers addr_location__exit(&al);
33627a0dcb7SNamhyung Kim return ret;
33786470930SIngo Molnar }
33886470930SIngo Molnar
process_read_event(struct perf_tool * tool,union perf_event * event,struct perf_sample * sample __maybe_unused,struct evsel * evsel,struct machine * machine __maybe_unused)33945694aa7SArnaldo Carvalho de Melo static int process_read_event(struct perf_tool *tool,
340d20deb64SArnaldo Carvalho de Melo union perf_event *event,
3411d037ca1SIrina Tirdea struct perf_sample *sample __maybe_unused,
34232dcd021SJiri Olsa struct evsel *evsel,
3431d037ca1SIrina Tirdea struct machine *machine __maybe_unused)
344e9ea2fdeSPeter Zijlstra {
34528b21393SArnaldo Carvalho de Melo struct report *rep = container_of(tool, struct report, tool);
346743eb868SArnaldo Carvalho de Melo
347fa372aaeSArnaldo Carvalho de Melo if (rep->show_threads) {
3488ab2e96dSArnaldo Carvalho de Melo const char *name = evsel__name(evsel);
34989973506SArnaldo Carvalho de Melo int err = perf_read_values_add_value(&rep->show_threads_values,
3508d513270SBrice Goglin event->read.pid, event->read.tid,
35138fe0e01SJiri Olsa evsel->core.idx,
3528d513270SBrice Goglin name,
3538d513270SBrice Goglin event->read.value);
35489973506SArnaldo Carvalho de Melo
35589973506SArnaldo Carvalho de Melo if (err)
35689973506SArnaldo Carvalho de Melo return err;
3578d513270SBrice Goglin }
3588d513270SBrice Goglin
359e9ea2fdeSPeter Zijlstra return 0;
360e9ea2fdeSPeter Zijlstra }
361e9ea2fdeSPeter Zijlstra
362300aa941SDavid Ahern /* For pipe mode, sample_type is not currently set */
report__setup_sample_type(struct report * rep)36328b21393SArnaldo Carvalho de Melo static int report__setup_sample_type(struct report *rep)
36486470930SIngo Molnar {
365c824c433SArnaldo Carvalho de Melo struct perf_session *session = rep->session;
366b3c2cc2bSArnaldo Carvalho de Melo u64 sample_type = evlist__combined_sample_type(session->evlist);
3678ceb41d7SJiri Olsa bool is_pipe = perf_data__is_pipe(session->data);
368ccb17caeSLeo Yan struct evsel *evsel;
369d20deb64SArnaldo Carvalho de Melo
370d062ac16SAdrian Hunter if (session->itrace_synth_opts->callchain ||
3711c5c25b3SAdrian Hunter session->itrace_synth_opts->add_callchain ||
372d062ac16SAdrian Hunter (!is_pipe &&
373d062ac16SAdrian Hunter perf_header__has_feat(&session->header, HEADER_AUXTRACE) &&
374d062ac16SAdrian Hunter !session->itrace_synth_opts->set))
375d062ac16SAdrian Hunter sample_type |= PERF_SAMPLE_CALLCHAIN;
376d062ac16SAdrian Hunter
377ec90e42cSAdrian Hunter if (session->itrace_synth_opts->last_branch ||
378ec90e42cSAdrian Hunter session->itrace_synth_opts->add_last_branch)
379c7eced63SAdrian Hunter sample_type |= PERF_SAMPLE_BRANCH_STACK;
380c7eced63SAdrian Hunter
381cc9784bdSJiri Olsa if (!is_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) {
382de7e6a7cSJiri Olsa if (perf_hpp_list.parent) {
3833780f488SNamhyung Kim ui__error("Selected --sort parent, but no "
384016e92fbSFrederic Weisbecker "callchain data. Did you call "
38500894ce9SArnaldo Carvalho de Melo "'perf record' without -g?\n");
386d549c769SArnaldo Carvalho de Melo return -EINVAL;
38786470930SIngo Molnar }
388b49a821eSJin Yao if (symbol_conf.use_callchain &&
389b49a821eSJin Yao !symbol_conf.show_branchflag_count) {
390b49a821eSJin Yao ui__error("Selected -g or --branch-history.\n"
391b49a821eSJin Yao "But no callchain or branch data.\n"
392b49a821eSJin Yao "Did you call 'perf record' without -g or -b?\n");
393016e92fbSFrederic Weisbecker return -1;
394016e92fbSFrederic Weisbecker }
3951cc83815SArnaldo Carvalho de Melo } else if (!callchain_param.enabled &&
396fa372aaeSArnaldo Carvalho de Melo callchain_param.mode != CHAIN_NONE &&
397b9a63b9bSArnaldo Carvalho de Melo !symbol_conf.use_callchain) {
398d599db3fSArnaldo Carvalho de Melo symbol_conf.use_callchain = true;
39916537f13SFrederic Weisbecker if (callchain_register_param(&callchain_param) < 0) {
4003780f488SNamhyung Kim ui__error("Can't register callchain params.\n");
401d549c769SArnaldo Carvalho de Melo return -EINVAL;
402016e92fbSFrederic Weisbecker }
403016e92fbSFrederic Weisbecker }
40486470930SIngo Molnar
405793aaaabSNamhyung Kim if (symbol_conf.cumulate_callchain) {
406793aaaabSNamhyung Kim /* Silently ignore if callchain is missing */
407793aaaabSNamhyung Kim if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) {
408793aaaabSNamhyung Kim symbol_conf.cumulate_callchain = false;
409793aaaabSNamhyung Kim perf_hpp__cancel_cumulate();
410793aaaabSNamhyung Kim }
411793aaaabSNamhyung Kim }
412793aaaabSNamhyung Kim
41355369fc1SNamhyung Kim if (sort__mode == SORT_MODE__BRANCH) {
414cc9784bdSJiri Olsa if (!is_pipe &&
4157f3be652SArnaldo Carvalho de Melo !(sample_type & PERF_SAMPLE_BRANCH_STACK)) {
4163780f488SNamhyung Kim ui__error("Selected -b but no branch data. "
4173780f488SNamhyung Kim "Did you call perf record without -b?\n");
418b50311dcSRoberto Agostino Vitillo return -1;
419b50311dcSRoberto Agostino Vitillo }
420b50311dcSRoberto Agostino Vitillo }
421b50311dcSRoberto Agostino Vitillo
422bb30acaeSRavi Bangoria if (sort__mode == SORT_MODE__MEMORY) {
423ccb17caeSLeo Yan /*
424ccb17caeSLeo Yan * FIXUP: prior to kernel 5.18, Arm SPE missed to set
425ccb17caeSLeo Yan * PERF_SAMPLE_DATA_SRC bit in sample type. For backward
426ccb17caeSLeo Yan * compatibility, set the bit if it's an old perf data file.
427ccb17caeSLeo Yan */
428ccb17caeSLeo Yan evlist__for_each_entry(session->evlist, evsel) {
4299029a775SIan Rogers if (strstr(evsel__name(evsel), "arm_spe") &&
430ccb17caeSLeo Yan !(sample_type & PERF_SAMPLE_DATA_SRC)) {
431ccb17caeSLeo Yan evsel->core.attr.sample_type |= PERF_SAMPLE_DATA_SRC;
432ccb17caeSLeo Yan sample_type |= PERF_SAMPLE_DATA_SRC;
433ccb17caeSLeo Yan }
434ccb17caeSLeo Yan }
435ccb17caeSLeo Yan
436bb30acaeSRavi Bangoria if (!is_pipe && !(sample_type & PERF_SAMPLE_DATA_SRC)) {
437bb30acaeSRavi Bangoria ui__error("Selected --mem-mode but no mem data. "
438bb30acaeSRavi Bangoria "Did you call perf record without -d?\n");
439bb30acaeSRavi Bangoria return -1;
440bb30acaeSRavi Bangoria }
441bb30acaeSRavi Bangoria }
442bb30acaeSRavi Bangoria
443aa8db3e4SAlexandre Truong callchain_param_setup(sample_type, perf_env__arch(&rep->session->header.env));
44498df858eSAndi Kleen
445b1d1429bSKan Liang if (rep->stitch_lbr && (callchain_param.record_mode != CALLCHAIN_LBR)) {
446b1d1429bSKan Liang ui__warning("Can't find LBR callchain. Switch off --stitch-lbr.\n"
447b1d1429bSKan Liang "Please apply --call-graph lbr when recording.\n");
448b1d1429bSKan Liang rep->stitch_lbr = false;
449b1d1429bSKan Liang }
450b1d1429bSKan Liang
45198df858eSAndi Kleen /* ??? handle more cases than just ANY? */
45292c7d7cdSArnaldo Carvalho de Melo if (!(evlist__combined_branch_type(session->evlist) & PERF_SAMPLE_BRANCH_ANY))
45398df858eSAndi Kleen rep->nonany_branch_mode = true;
45498df858eSAndi Kleen
455c3314a74SJin Yao #if !defined(HAVE_LIBUNWIND_SUPPORT) && !defined(HAVE_DWARF_SUPPORT)
456800d3f56SJin Yao if (dwarf_callchain_users) {
457c3314a74SJin Yao ui__warning("Please install libunwind or libdw "
458c3314a74SJin Yao "development packages during the perf build.\n");
459800d3f56SJin Yao }
460800d3f56SJin Yao #endif
461800d3f56SJin Yao
46286470930SIngo Molnar return 0;
46386470930SIngo Molnar }
46486470930SIngo Molnar
sig_handler(int sig __maybe_unused)4651d037ca1SIrina Tirdea static void sig_handler(int sig __maybe_unused)
46646656ac7STom Zanussi {
46746656ac7STom Zanussi session_done = 1;
46846656ac7STom Zanussi }
46946656ac7STom Zanussi
hists__fprintf_nr_sample_events(struct hists * hists,struct report * rep,const char * evname,FILE * fp)47028b21393SArnaldo Carvalho de Melo static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report *rep,
471c82ee828SArnaldo Carvalho de Melo const char *evname, FILE *fp)
472c82ee828SArnaldo Carvalho de Melo {
473c82ee828SArnaldo Carvalho de Melo size_t ret;
474c82ee828SArnaldo Carvalho de Melo char unit;
4750f0abbacSNamhyung Kim unsigned long nr_samples = hists->stats.nr_samples;
476c824c433SArnaldo Carvalho de Melo u64 nr_events = hists->stats.total_period;
47732dcd021SJiri Olsa struct evsel *evsel = hists_to_evsel(hists);
478717e263fSNamhyung Kim char buf[512];
479717e263fSNamhyung Kim size_t size = sizeof(buf);
48084734b06SKan Liang int socked_id = hists->socket_filter;
481717e263fSNamhyung Kim
48227fafab5SNamhyung Kim if (quiet)
48327fafab5SNamhyung Kim return 0;
48427fafab5SNamhyung Kim
485f2148330SNamhyung Kim if (symbol_conf.filter_relative) {
486f2148330SNamhyung Kim nr_samples = hists->stats.nr_non_filtered_samples;
487f2148330SNamhyung Kim nr_events = hists->stats.total_non_filtered_period;
488f2148330SNamhyung Kim }
489f2148330SNamhyung Kim
490c754c382SArnaldo Carvalho de Melo if (evsel__is_group_event(evsel)) {
49132dcd021SJiri Olsa struct evsel *pos;
492717e263fSNamhyung Kim
493347c751aSArnaldo Carvalho de Melo evsel__group_desc(evsel, buf, size);
494717e263fSNamhyung Kim evname = buf;
495717e263fSNamhyung Kim
496717e263fSNamhyung Kim for_each_group_member(pos, evsel) {
4974ea062edSArnaldo Carvalho de Melo const struct hists *pos_hists = evsel__hists(pos);
4984ea062edSArnaldo Carvalho de Melo
499f2148330SNamhyung Kim if (symbol_conf.filter_relative) {
5004ea062edSArnaldo Carvalho de Melo nr_samples += pos_hists->stats.nr_non_filtered_samples;
5014ea062edSArnaldo Carvalho de Melo nr_events += pos_hists->stats.total_non_filtered_period;
502f2148330SNamhyung Kim } else {
5030f0abbacSNamhyung Kim nr_samples += pos_hists->stats.nr_samples;
5044ea062edSArnaldo Carvalho de Melo nr_events += pos_hists->stats.total_period;
505717e263fSNamhyung Kim }
506717e263fSNamhyung Kim }
507f2148330SNamhyung Kim }
508c82ee828SArnaldo Carvalho de Melo
509cc686280SAshay Rane nr_samples = convert_unit(nr_samples, &unit);
510cc686280SAshay Rane ret = fprintf(fp, "# Samples: %lu%c", nr_samples, unit);
5118ef278bbSJiri Olsa if (evname != NULL) {
5128ef278bbSJiri Olsa ret += fprintf(fp, " of event%s '%s'",
5135643b1a5SJiri Olsa evsel->core.nr_members > 1 ? "s" : "", evname);
5148ef278bbSJiri Olsa }
515cc686280SAshay Rane
5167425664bSJin Yao if (rep->time_str)
5177425664bSJin Yao ret += fprintf(fp, " (time slices: %s)", rep->time_str);
5187425664bSJin Yao
51911b6e548SGaurav Singh if (symbol_conf.show_ref_callgraph && evname && strstr(evname, "call-graph=no")) {
5209e207ddfSKan Liang ret += fprintf(fp, ", show reference callgraph");
5219e207ddfSKan Liang }
5229e207ddfSKan Liang
523f4f7e28dSStephane Eranian if (rep->mem_mode) {
524f4f7e28dSStephane Eranian ret += fprintf(fp, "\n# Total weight : %" PRIu64, nr_events);
525228f14f2SYunlong Song ret += fprintf(fp, "\n# Sort order : %s", sort_order ? : default_mem_sort_order);
526f4f7e28dSStephane Eranian } else
52704480d01SJiri Olsa ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events);
52821394d94SKan Liang
52984734b06SKan Liang if (socked_id > -1)
53084734b06SKan Liang ret += fprintf(fp, "\n# Processor Socket: %d", socked_id);
53121394d94SKan Liang
532c82ee828SArnaldo Carvalho de Melo return ret + fprintf(fp, "\n#\n");
533c82ee828SArnaldo Carvalho de Melo }
534c82ee828SArnaldo Carvalho de Melo
evlist__tui_block_hists_browse(struct evlist * evlist,struct report * rep)535f4bd0b4aSArnaldo Carvalho de Melo static int evlist__tui_block_hists_browse(struct evlist *evlist, struct report *rep)
5367fa46cbfSJin Yao {
5377fa46cbfSJin Yao struct evsel *pos;
5387fa46cbfSJin Yao int i = 0, ret;
5397fa46cbfSJin Yao
5407fa46cbfSJin Yao evlist__for_each_entry(evlist, pos) {
5417fa46cbfSJin Yao ret = report__browse_block_hists(&rep->block_reports[i++].hist,
542848a5e50SJin Yao rep->min_percent, pos,
543297871cbSNamhyung Kim &rep->session->header.env);
5447fa46cbfSJin Yao if (ret != 0)
5457fa46cbfSJin Yao return ret;
5467fa46cbfSJin Yao }
5477fa46cbfSJin Yao
5487fa46cbfSJin Yao return 0;
5497fa46cbfSJin Yao }
5507fa46cbfSJin Yao
evlist__tty_browse_hists(struct evlist * evlist,struct report * rep,const char * help)551f4bd0b4aSArnaldo Carvalho de Melo static int evlist__tty_browse_hists(struct evlist *evlist, struct report *rep, const char *help)
552d67f088eSArnaldo Carvalho de Melo {
55332dcd021SJiri Olsa struct evsel *pos;
5546f7164faSJin Yao int i = 0;
555d67f088eSArnaldo Carvalho de Melo
55627fafab5SNamhyung Kim if (!quiet) {
55727fafab5SNamhyung Kim fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n",
55827fafab5SNamhyung Kim evlist->stats.total_lost_samples);
55927fafab5SNamhyung Kim }
56027fafab5SNamhyung Kim
561e5cadb93SArnaldo Carvalho de Melo evlist__for_each_entry(evlist, pos) {
5624ea062edSArnaldo Carvalho de Melo struct hists *hists = evsel__hists(pos);
5638ab2e96dSArnaldo Carvalho de Melo const char *evname = evsel__name(pos);
564d67f088eSArnaldo Carvalho de Melo
56588c4b5ddSKan Liang i++;
566c754c382SArnaldo Carvalho de Melo if (symbol_conf.event_group && !evsel__is_group_leader(pos))
567fc24d7c2SNamhyung Kim continue;
568fc24d7c2SNamhyung Kim
5692775de0bSNamhyung Kim if (rep->skip_empty && !hists->stats.nr_samples)
5702775de0bSNamhyung Kim continue;
5712775de0bSNamhyung Kim
57228b21393SArnaldo Carvalho de Melo hists__fprintf_nr_sample_events(hists, rep, evname, stdout);
5736f7164faSJin Yao
5746f7164faSJin Yao if (rep->total_cycles_mode) {
57588c4b5ddSKan Liang report__browse_block_hists(&rep->block_reports[i - 1].hist,
576297871cbSNamhyung Kim rep->min_percent, pos, NULL);
5776f7164faSJin Yao continue;
5786f7164faSJin Yao }
5796f7164faSJin Yao
58027fafab5SNamhyung Kim hists__fprintf(hists, !quiet, 0, 0, rep->min_percent, stdout,
581e9de7e2fSArnaldo Carvalho de Melo !(symbol_conf.use_callchain ||
582e9de7e2fSArnaldo Carvalho de Melo symbol_conf.show_branchflag_count));
583d67f088eSArnaldo Carvalho de Melo fprintf(stdout, "\n\n");
584d67f088eSArnaldo Carvalho de Melo }
585d67f088eSArnaldo Carvalho de Melo
5868b53dbefSNamhyung Kim if (!quiet)
587d67f088eSArnaldo Carvalho de Melo fprintf(stdout, "#\n# (%s)\n#\n", help);
588d67f088eSArnaldo Carvalho de Melo
589fa372aaeSArnaldo Carvalho de Melo if (rep->show_threads) {
590fa372aaeSArnaldo Carvalho de Melo bool style = !strcmp(rep->pretty_printing_style, "raw");
591fa372aaeSArnaldo Carvalho de Melo perf_read_values_display(stdout, &rep->show_threads_values,
592d67f088eSArnaldo Carvalho de Melo style);
593fa372aaeSArnaldo Carvalho de Melo perf_read_values_destroy(&rep->show_threads_values);
594d67f088eSArnaldo Carvalho de Melo }
595d67f088eSArnaldo Carvalho de Melo
5962d78b189SJin Yao if (sort__mode == SORT_MODE__BRANCH)
5972d78b189SJin Yao branch_type_stat_display(stdout, &rep->brtype_stat);
5982d78b189SJin Yao
599d67f088eSArnaldo Carvalho de Melo return 0;
600d67f088eSArnaldo Carvalho de Melo }
601d67f088eSArnaldo Carvalho de Melo
report__warn_kptr_restrict(const struct report * rep)602fad2918eSArnaldo Carvalho de Melo static void report__warn_kptr_restrict(const struct report *rep)
603fad2918eSArnaldo Carvalho de Melo {
604a5e813c6SArnaldo Carvalho de Melo struct map *kernel_map = machine__kernel_map(&rep->session->machines.host);
605f6fcc143SWang Nan struct kmap *kernel_kmap = kernel_map ? map__kmap(kernel_map) : NULL;
606fad2918eSArnaldo Carvalho de Melo
60778e1bc25SArnaldo Carvalho de Melo if (evlist__exclude_kernel(rep->session->evlist))
6089c39ed90SArnaldo Carvalho de Melo return;
6099c39ed90SArnaldo Carvalho de Melo
610fad2918eSArnaldo Carvalho de Melo if (kernel_map == NULL ||
61163df0e4bSIan Rogers (map__dso(kernel_map)->hit &&
612fad2918eSArnaldo Carvalho de Melo (kernel_kmap->ref_reloc_sym == NULL ||
613fad2918eSArnaldo Carvalho de Melo kernel_kmap->ref_reloc_sym->addr == 0))) {
614fad2918eSArnaldo Carvalho de Melo const char *desc =
615fad2918eSArnaldo Carvalho de Melo "As no suitable kallsyms nor vmlinux was found, kernel samples\n"
616fad2918eSArnaldo Carvalho de Melo "can't be resolved.";
617fad2918eSArnaldo Carvalho de Melo
618e94b861aSArnaldo Carvalho de Melo if (kernel_map && map__has_symbols(kernel_map)) {
619fad2918eSArnaldo Carvalho de Melo desc = "If some relocation was applied (e.g. "
620fad2918eSArnaldo Carvalho de Melo "kexec) symbols may be misresolved.";
621fad2918eSArnaldo Carvalho de Melo }
622fad2918eSArnaldo Carvalho de Melo
623fad2918eSArnaldo Carvalho de Melo ui__warning(
624fad2918eSArnaldo Carvalho de Melo "Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n"
625fad2918eSArnaldo Carvalho de Melo "Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n"
626fad2918eSArnaldo Carvalho de Melo "Samples in kernel modules can't be resolved as well.\n\n",
627fad2918eSArnaldo Carvalho de Melo desc);
628fad2918eSArnaldo Carvalho de Melo }
629fad2918eSArnaldo Carvalho de Melo }
630fad2918eSArnaldo Carvalho de Melo
report__gtk_browse_hists(struct report * rep,const char * help)6318362951bSArnaldo Carvalho de Melo static int report__gtk_browse_hists(struct report *rep, const char *help)
6328362951bSArnaldo Carvalho de Melo {
63363503dbaSJiri Olsa int (*hist_browser)(struct evlist *evlist, const char *help,
6348362951bSArnaldo Carvalho de Melo struct hist_browser_timer *timer, float min_pcnt);
6358362951bSArnaldo Carvalho de Melo
636f4bd0b4aSArnaldo Carvalho de Melo hist_browser = dlsym(perf_gtk_handle, "evlist__gtk_browse_hists");
6378362951bSArnaldo Carvalho de Melo
6388362951bSArnaldo Carvalho de Melo if (hist_browser == NULL) {
6398362951bSArnaldo Carvalho de Melo ui__error("GTK browser not found!\n");
6408362951bSArnaldo Carvalho de Melo return -1;
6418362951bSArnaldo Carvalho de Melo }
6428362951bSArnaldo Carvalho de Melo
6438362951bSArnaldo Carvalho de Melo return hist_browser(rep->session->evlist, help, NULL, rep->min_percent);
6448362951bSArnaldo Carvalho de Melo }
6458362951bSArnaldo Carvalho de Melo
report__browse_hists(struct report * rep)6468362951bSArnaldo Carvalho de Melo static int report__browse_hists(struct report *rep)
6478362951bSArnaldo Carvalho de Melo {
6488362951bSArnaldo Carvalho de Melo int ret;
6498362951bSArnaldo Carvalho de Melo struct perf_session *session = rep->session;
65063503dbaSJiri Olsa struct evlist *evlist = session->evlist;
651d9fc7061SIan Rogers char *help = NULL, *path = NULL;
65234b7b0f9SNamhyung Kim
653d9fc7061SIan Rogers path = system_path(TIPDIR);
654d9fc7061SIan Rogers if (perf_tip(&help, path) || help == NULL) {
65534b7b0f9SNamhyung Kim /* fallback for people who don't install perf ;-) */
656d9fc7061SIan Rogers free(path);
657d9fc7061SIan Rogers path = system_path(DOCDIR);
658d9fc7061SIan Rogers if (perf_tip(&help, path) || help == NULL)
659d9fc7061SIan Rogers help = strdup("Cannot load tips.txt file, please install perf!");
66034b7b0f9SNamhyung Kim }
661d9fc7061SIan Rogers free(path);
6628362951bSArnaldo Carvalho de Melo
6638362951bSArnaldo Carvalho de Melo switch (use_browser) {
6648362951bSArnaldo Carvalho de Melo case 1:
6657fa46cbfSJin Yao if (rep->total_cycles_mode) {
666f4bd0b4aSArnaldo Carvalho de Melo ret = evlist__tui_block_hists_browse(evlist, rep);
6677fa46cbfSJin Yao break;
6687fa46cbfSJin Yao }
6697fa46cbfSJin Yao
670f4bd0b4aSArnaldo Carvalho de Melo ret = evlist__tui_browse_hists(evlist, help, NULL, rep->min_percent,
671297871cbSNamhyung Kim &session->header.env, true);
6728362951bSArnaldo Carvalho de Melo /*
6738362951bSArnaldo Carvalho de Melo * Usually "ret" is the last pressed key, and we only
6748362951bSArnaldo Carvalho de Melo * care if the key notifies us to switch data file.
6758362951bSArnaldo Carvalho de Melo */
6765e3b810aSJin Yao if (ret != K_SWITCH_INPUT_DATA && ret != K_RELOAD)
6778362951bSArnaldo Carvalho de Melo ret = 0;
6788362951bSArnaldo Carvalho de Melo break;
6798362951bSArnaldo Carvalho de Melo case 2:
6808362951bSArnaldo Carvalho de Melo ret = report__gtk_browse_hists(rep, help);
6818362951bSArnaldo Carvalho de Melo break;
6828362951bSArnaldo Carvalho de Melo default:
683f4bd0b4aSArnaldo Carvalho de Melo ret = evlist__tty_browse_hists(evlist, rep, help);
6848362951bSArnaldo Carvalho de Melo break;
6858362951bSArnaldo Carvalho de Melo }
686d9fc7061SIan Rogers free(help);
6878362951bSArnaldo Carvalho de Melo return ret;
6888362951bSArnaldo Carvalho de Melo }
6898362951bSArnaldo Carvalho de Melo
report__collapse_hists(struct report * rep)6905b2ea6f2SNamhyung Kim static int report__collapse_hists(struct report *rep)
691f6d8b057SArnaldo Carvalho de Melo {
692f6d8b057SArnaldo Carvalho de Melo struct ui_progress prog;
69332dcd021SJiri Olsa struct evsel *pos;
6945b2ea6f2SNamhyung Kim int ret = 0;
695f6d8b057SArnaldo Carvalho de Melo
69658c311daSNamhyung Kim ui_progress__init(&prog, rep->nr_entries, "Merging related events...");
697f6d8b057SArnaldo Carvalho de Melo
698e5cadb93SArnaldo Carvalho de Melo evlist__for_each_entry(rep->session->evlist, pos) {
6994ea062edSArnaldo Carvalho de Melo struct hists *hists = evsel__hists(pos);
700f6d8b057SArnaldo Carvalho de Melo
70138fe0e01SJiri Olsa if (pos->core.idx == 0)
702f6d8b057SArnaldo Carvalho de Melo hists->symbol_filter_str = rep->symbol_filter_str;
703f6d8b057SArnaldo Carvalho de Melo
70421394d94SKan Liang hists->socket_filter = rep->socket_filter;
70521394d94SKan Liang
7065b2ea6f2SNamhyung Kim ret = hists__collapse_resort(hists, &prog);
7075b2ea6f2SNamhyung Kim if (ret < 0)
7085b2ea6f2SNamhyung Kim break;
709f6d8b057SArnaldo Carvalho de Melo
710f6d8b057SArnaldo Carvalho de Melo /* Non-group events are considered as leader */
711c754c382SArnaldo Carvalho de Melo if (symbol_conf.event_group && !evsel__is_group_leader(pos)) {
712fba7c866SJiri Olsa struct hists *leader_hists = evsel__hists(evsel__leader(pos));
713f6d8b057SArnaldo Carvalho de Melo
714f6d8b057SArnaldo Carvalho de Melo hists__match(leader_hists, hists);
715f6d8b057SArnaldo Carvalho de Melo hists__link(leader_hists, hists);
716f6d8b057SArnaldo Carvalho de Melo }
717f6d8b057SArnaldo Carvalho de Melo }
718f6d8b057SArnaldo Carvalho de Melo
719f6d8b057SArnaldo Carvalho de Melo ui_progress__finish();
7205b2ea6f2SNamhyung Kim return ret;
721f6d8b057SArnaldo Carvalho de Melo }
722f6d8b057SArnaldo Carvalho de Melo
hists__resort_cb(struct hist_entry * he,void * arg)723dbd2a1d5SJiri Olsa static int hists__resort_cb(struct hist_entry *he, void *arg)
724dbd2a1d5SJiri Olsa {
725dbd2a1d5SJiri Olsa struct report *rep = arg;
726dbd2a1d5SJiri Olsa struct symbol *sym = he->ms.sym;
727dbd2a1d5SJiri Olsa
728dbd2a1d5SJiri Olsa if (rep->symbol_ipc && sym && !sym->annotate2) {
72932dcd021SJiri Olsa struct evsel *evsel = hists_to_evsel(he->hists);
730dbd2a1d5SJiri Olsa
73180e06e54SNamhyung Kim symbol__annotate2(&he->ms, evsel, NULL);
732dbd2a1d5SJiri Olsa }
733dbd2a1d5SJiri Olsa
734dbd2a1d5SJiri Olsa return 0;
735dbd2a1d5SJiri Olsa }
736dbd2a1d5SJiri Olsa
report__output_resort(struct report * rep)737740b97f9SNamhyung Kim static void report__output_resort(struct report *rep)
738740b97f9SNamhyung Kim {
739740b97f9SNamhyung Kim struct ui_progress prog;
74032dcd021SJiri Olsa struct evsel *pos;
741740b97f9SNamhyung Kim
742740b97f9SNamhyung Kim ui_progress__init(&prog, rep->nr_entries, "Sorting events for output...");
743740b97f9SNamhyung Kim
744dbd2a1d5SJiri Olsa evlist__for_each_entry(rep->session->evlist, pos) {
74510c513f7SArnaldo Carvalho de Melo evsel__output_resort_cb(pos, &prog, hists__resort_cb, rep);
746dbd2a1d5SJiri Olsa }
747740b97f9SNamhyung Kim
748740b97f9SNamhyung Kim ui_progress__finish();
749740b97f9SNamhyung Kim }
750740b97f9SNamhyung Kim
count_sample_event(struct perf_tool * tool __maybe_unused,union perf_event * event __maybe_unused,struct perf_sample * sample __maybe_unused,struct evsel * evsel,struct machine * machine __maybe_unused)75155f75444SNamhyung Kim static int count_sample_event(struct perf_tool *tool __maybe_unused,
75255f75444SNamhyung Kim union perf_event *event __maybe_unused,
75355f75444SNamhyung Kim struct perf_sample *sample __maybe_unused,
75455f75444SNamhyung Kim struct evsel *evsel,
75555f75444SNamhyung Kim struct machine *machine __maybe_unused)
75655f75444SNamhyung Kim {
75755f75444SNamhyung Kim struct hists *hists = evsel__hists(evsel);
75855f75444SNamhyung Kim
75955f75444SNamhyung Kim hists__inc_nr_events(hists);
76055f75444SNamhyung Kim return 0;
76155f75444SNamhyung Kim }
76255f75444SNamhyung Kim
count_lost_samples_event(struct perf_tool * tool,union perf_event * event,struct perf_sample * sample,struct machine * machine __maybe_unused)763d7ba22d4SNamhyung Kim static int count_lost_samples_event(struct perf_tool *tool,
764d7ba22d4SNamhyung Kim union perf_event *event,
765d7ba22d4SNamhyung Kim struct perf_sample *sample,
766d7ba22d4SNamhyung Kim struct machine *machine __maybe_unused)
767d7ba22d4SNamhyung Kim {
768d7ba22d4SNamhyung Kim struct report *rep = container_of(tool, struct report, tool);
769d7ba22d4SNamhyung Kim struct evsel *evsel;
770d7ba22d4SNamhyung Kim
771d7ba22d4SNamhyung Kim evsel = evlist__id2evsel(rep->session->evlist, sample->id);
772d7ba22d4SNamhyung Kim if (evsel) {
773d7ba22d4SNamhyung Kim hists__inc_nr_lost_samples(evsel__hists(evsel),
774d7ba22d4SNamhyung Kim event->lost_samples.lost);
775d7ba22d4SNamhyung Kim }
776d7ba22d4SNamhyung Kim return 0;
777d7ba22d4SNamhyung Kim }
778d7ba22d4SNamhyung Kim
779892ba7f1SNamhyung Kim static int process_attr(struct perf_tool *tool __maybe_unused,
780892ba7f1SNamhyung Kim union perf_event *event,
781892ba7f1SNamhyung Kim struct evlist **pevlist);
782892ba7f1SNamhyung Kim
stats_setup(struct report * rep)783a4a4d0a7SJiri Olsa static void stats_setup(struct report *rep)
784a4a4d0a7SJiri Olsa {
785a4a4d0a7SJiri Olsa memset(&rep->tool, 0, sizeof(rep->tool));
786892ba7f1SNamhyung Kim rep->tool.attr = process_attr;
78755f75444SNamhyung Kim rep->tool.sample = count_sample_event;
788d7ba22d4SNamhyung Kim rep->tool.lost_samples = count_lost_samples_event;
789a4a4d0a7SJiri Olsa rep->tool.no_warn = true;
790a4a4d0a7SJiri Olsa }
791a4a4d0a7SJiri Olsa
stats_print(struct report * rep)792a4a4d0a7SJiri Olsa static int stats_print(struct report *rep)
793a4a4d0a7SJiri Olsa {
794a4a4d0a7SJiri Olsa struct perf_session *session = rep->session;
795a4a4d0a7SJiri Olsa
7962775de0bSNamhyung Kim perf_session__fprintf_nr_events(session, stdout, rep->skip_empty);
7972775de0bSNamhyung Kim evlist__fprintf_nr_events(session->evlist, stdout, rep->skip_empty);
798a4a4d0a7SJiri Olsa return 0;
799a4a4d0a7SJiri Olsa }
800a4a4d0a7SJiri Olsa
tasks_setup(struct report * rep)801930f8b34SJiri Olsa static void tasks_setup(struct report *rep)
802930f8b34SJiri Olsa {
803930f8b34SJiri Olsa memset(&rep->tool, 0, sizeof(rep->tool));
8048614ada0SJiri Olsa rep->tool.ordered_events = true;
8056439d7d1SArnaldo Carvalho de Melo if (rep->mmaps_mode) {
8066439d7d1SArnaldo Carvalho de Melo rep->tool.mmap = perf_event__process_mmap;
8076439d7d1SArnaldo Carvalho de Melo rep->tool.mmap2 = perf_event__process_mmap2;
8086439d7d1SArnaldo Carvalho de Melo }
809892ba7f1SNamhyung Kim rep->tool.attr = process_attr;
810930f8b34SJiri Olsa rep->tool.comm = perf_event__process_comm;
811930f8b34SJiri Olsa rep->tool.exit = perf_event__process_exit;
812930f8b34SJiri Olsa rep->tool.fork = perf_event__process_fork;
813930f8b34SJiri Olsa rep->tool.no_warn = true;
814930f8b34SJiri Olsa }
815930f8b34SJiri Olsa
816930f8b34SJiri Olsa struct task {
817930f8b34SJiri Olsa struct thread *thread;
818930f8b34SJiri Olsa struct list_head list;
819930f8b34SJiri Olsa struct list_head children;
820930f8b34SJiri Olsa };
821930f8b34SJiri Olsa
tasks_list(struct task * task,struct machine * machine)822930f8b34SJiri Olsa static struct task *tasks_list(struct task *task, struct machine *machine)
823930f8b34SJiri Olsa {
824930f8b34SJiri Olsa struct thread *parent_thread, *thread = task->thread;
825930f8b34SJiri Olsa struct task *parent_task;
826930f8b34SJiri Olsa
827930f8b34SJiri Olsa /* Already listed. */
828930f8b34SJiri Olsa if (!list_empty(&task->list))
829930f8b34SJiri Olsa return NULL;
830930f8b34SJiri Olsa
831930f8b34SJiri Olsa /* Last one in the chain. */
832ee84a303SIan Rogers if (thread__ppid(thread) == -1)
833930f8b34SJiri Olsa return task;
834930f8b34SJiri Olsa
835ee84a303SIan Rogers parent_thread = machine__find_thread(machine, -1, thread__ppid(thread));
836930f8b34SJiri Olsa if (!parent_thread)
837930f8b34SJiri Olsa return ERR_PTR(-ENOENT);
838930f8b34SJiri Olsa
839930f8b34SJiri Olsa parent_task = thread__priv(parent_thread);
8402c9f7bd7SIan Rogers thread__put(parent_thread);
841930f8b34SJiri Olsa list_add_tail(&task->list, &parent_task->children);
842930f8b34SJiri Olsa return tasks_list(parent_task, machine);
843930f8b34SJiri Olsa }
844930f8b34SJiri Olsa
maps__fprintf_task(struct maps * maps,int indent,FILE * fp)8456439d7d1SArnaldo Carvalho de Melo static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)
8466439d7d1SArnaldo Carvalho de Melo {
8476439d7d1SArnaldo Carvalho de Melo size_t printed = 0;
848ff583dc4SIan Rogers struct map_rb_node *rb_node;
8496439d7d1SArnaldo Carvalho de Melo
850ff583dc4SIan Rogers maps__for_each_entry(maps, rb_node) {
851ff583dc4SIan Rogers struct map *map = rb_node->map;
85263df0e4bSIan Rogers const struct dso *dso = map__dso(map);
853ddee3f2bSIan Rogers u32 prot = map__prot(map);
854ff583dc4SIan Rogers
8556439d7d1SArnaldo Carvalho de Melo printed += fprintf(fp, "%*s %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n",
856e5116f46SIan Rogers indent, "", map__start(map), map__end(map),
857ddee3f2bSIan Rogers prot & PROT_READ ? 'r' : '-',
858ddee3f2bSIan Rogers prot & PROT_WRITE ? 'w' : '-',
859ddee3f2bSIan Rogers prot & PROT_EXEC ? 'x' : '-',
860ddee3f2bSIan Rogers map__flags(map) ? 's' : 'p',
8612a6e5e8aSIan Rogers map__pgoff(map),
86263df0e4bSIan Rogers dso->id.ino, dso->name);
8636439d7d1SArnaldo Carvalho de Melo }
8646439d7d1SArnaldo Carvalho de Melo
8656439d7d1SArnaldo Carvalho de Melo return printed;
8666439d7d1SArnaldo Carvalho de Melo }
8676439d7d1SArnaldo Carvalho de Melo
task__print_level(struct task * task,FILE * fp,int level)868930f8b34SJiri Olsa static void task__print_level(struct task *task, FILE *fp, int level)
869930f8b34SJiri Olsa {
870930f8b34SJiri Olsa struct thread *thread = task->thread;
871930f8b34SJiri Olsa struct task *child;
8726439d7d1SArnaldo Carvalho de Melo int comm_indent = fprintf(fp, " %8d %8d %8d |%*s",
873ee84a303SIan Rogers thread__pid(thread), thread__tid(thread),
874ee84a303SIan Rogers thread__ppid(thread), level, "");
8756439d7d1SArnaldo Carvalho de Melo
8766439d7d1SArnaldo Carvalho de Melo fprintf(fp, "%s\n", thread__comm_str(thread));
8776439d7d1SArnaldo Carvalho de Melo
878ee84a303SIan Rogers maps__fprintf_task(thread__maps(thread), comm_indent, fp);
879930f8b34SJiri Olsa
880930f8b34SJiri Olsa if (!list_empty(&task->children)) {
881930f8b34SJiri Olsa list_for_each_entry(child, &task->children, list)
882930f8b34SJiri Olsa task__print_level(child, fp, level + 1);
883930f8b34SJiri Olsa }
884930f8b34SJiri Olsa }
885930f8b34SJiri Olsa
tasks_print(struct report * rep,FILE * fp)886930f8b34SJiri Olsa static int tasks_print(struct report *rep, FILE *fp)
887930f8b34SJiri Olsa {
888930f8b34SJiri Olsa struct perf_session *session = rep->session;
889930f8b34SJiri Olsa struct machine *machine = &session->machines.host;
890930f8b34SJiri Olsa struct task *tasks, *task;
891930f8b34SJiri Olsa unsigned int nr = 0, itask = 0, i;
892930f8b34SJiri Olsa struct rb_node *nd;
893930f8b34SJiri Olsa LIST_HEAD(list);
894930f8b34SJiri Olsa
895930f8b34SJiri Olsa /*
896930f8b34SJiri Olsa * No locking needed while accessing machine->threads,
897930f8b34SJiri Olsa * because --tasks is single threaded command.
898930f8b34SJiri Olsa */
899930f8b34SJiri Olsa
900930f8b34SJiri Olsa /* Count all the threads. */
901930f8b34SJiri Olsa for (i = 0; i < THREADS__TABLE_SIZE; i++)
902930f8b34SJiri Olsa nr += machine->threads[i].nr;
903930f8b34SJiri Olsa
904930f8b34SJiri Olsa tasks = malloc(sizeof(*tasks) * nr);
905930f8b34SJiri Olsa if (!tasks)
906930f8b34SJiri Olsa return -ENOMEM;
907930f8b34SJiri Olsa
908930f8b34SJiri Olsa for (i = 0; i < THREADS__TABLE_SIZE; i++) {
909930f8b34SJiri Olsa struct threads *threads = &machine->threads[i];
910930f8b34SJiri Olsa
911f3acb3a8SDavidlohr Bueso for (nd = rb_first_cached(&threads->entries); nd;
912f3acb3a8SDavidlohr Bueso nd = rb_next(nd)) {
913930f8b34SJiri Olsa task = tasks + itask++;
914930f8b34SJiri Olsa
9157ee227f6SIan Rogers task->thread = rb_entry(nd, struct thread_rb_node, rb_node)->thread;
916930f8b34SJiri Olsa INIT_LIST_HEAD(&task->children);
917930f8b34SJiri Olsa INIT_LIST_HEAD(&task->list);
918930f8b34SJiri Olsa thread__set_priv(task->thread, task);
919930f8b34SJiri Olsa }
920930f8b34SJiri Olsa }
921930f8b34SJiri Olsa
922930f8b34SJiri Olsa /*
923930f8b34SJiri Olsa * Iterate every task down to the unprocessed parent
924930f8b34SJiri Olsa * and link all in task children list. Task with no
925930f8b34SJiri Olsa * parent is added into 'list'.
926930f8b34SJiri Olsa */
927930f8b34SJiri Olsa for (itask = 0; itask < nr; itask++) {
928930f8b34SJiri Olsa task = tasks + itask;
929930f8b34SJiri Olsa
930930f8b34SJiri Olsa if (!list_empty(&task->list))
931930f8b34SJiri Olsa continue;
932930f8b34SJiri Olsa
933930f8b34SJiri Olsa task = tasks_list(task, machine);
934930f8b34SJiri Olsa if (IS_ERR(task)) {
935930f8b34SJiri Olsa pr_err("Error: failed to process tasks\n");
936930f8b34SJiri Olsa free(tasks);
937930f8b34SJiri Olsa return PTR_ERR(task);
938930f8b34SJiri Olsa }
939930f8b34SJiri Olsa
940930f8b34SJiri Olsa if (task)
941930f8b34SJiri Olsa list_add_tail(&task->list, &list);
942930f8b34SJiri Olsa }
943930f8b34SJiri Olsa
944930f8b34SJiri Olsa fprintf(fp, "# %8s %8s %8s %s\n", "pid", "tid", "ppid", "comm");
945930f8b34SJiri Olsa
946930f8b34SJiri Olsa list_for_each_entry(task, &list, list)
947930f8b34SJiri Olsa task__print_level(task, fp, 0);
948930f8b34SJiri Olsa
949930f8b34SJiri Olsa free(tasks);
950930f8b34SJiri Olsa return 0;
951930f8b34SJiri Olsa }
952930f8b34SJiri Olsa
__cmd_report(struct report * rep)95328b21393SArnaldo Carvalho de Melo static int __cmd_report(struct report *rep)
95486470930SIngo Molnar {
955f6d8b057SArnaldo Carvalho de Melo int ret;
956993ac88dSStephane Eranian struct perf_session *session = rep->session;
95732dcd021SJiri Olsa struct evsel *pos;
9588ceb41d7SJiri Olsa struct perf_data *data = session->data;
95986470930SIngo Molnar
96046656ac7STom Zanussi signal(SIGINT, sig_handler);
96146656ac7STom Zanussi
962fa372aaeSArnaldo Carvalho de Melo if (rep->cpu_list) {
963fa372aaeSArnaldo Carvalho de Melo ret = perf_session__cpu_bitmap(session, rep->cpu_list,
964fa372aaeSArnaldo Carvalho de Melo rep->cpu_bitmap);
96525b1606bSNamhyung Kim if (ret) {
96625b1606bSNamhyung Kim ui__error("failed to set cpu bitmap\n");
967d4ae0a6fSJiri Olsa return ret;
9685d67be97SAnton Blanchard }
969644e0840SAdrian Hunter session->itrace_synth_opts->cpu_bitmap = rep->cpu_bitmap;
97025b1606bSNamhyung Kim }
9715d67be97SAnton Blanchard
97289973506SArnaldo Carvalho de Melo if (rep->show_threads) {
97389973506SArnaldo Carvalho de Melo ret = perf_read_values_init(&rep->show_threads_values);
97489973506SArnaldo Carvalho de Melo if (ret)
97589973506SArnaldo Carvalho de Melo return ret;
97689973506SArnaldo Carvalho de Melo }
9778d513270SBrice Goglin
97828b21393SArnaldo Carvalho de Melo ret = report__setup_sample_type(rep);
97925b1606bSNamhyung Kim if (ret) {
98025b1606bSNamhyung Kim /* report__setup_sample_type() already showed error message */
981d4ae0a6fSJiri Olsa return ret;
98225b1606bSNamhyung Kim }
983d549c769SArnaldo Carvalho de Melo
984a4a4d0a7SJiri Olsa if (rep->stats_mode)
985a4a4d0a7SJiri Olsa stats_setup(rep);
986a4a4d0a7SJiri Olsa
987930f8b34SJiri Olsa if (rep->tasks_mode)
988930f8b34SJiri Olsa tasks_setup(rep);
989930f8b34SJiri Olsa
990b7b61cbeSArnaldo Carvalho de Melo ret = perf_session__process_events(session);
99125b1606bSNamhyung Kim if (ret) {
99225b1606bSNamhyung Kim ui__error("failed to process sample\n");
993d4ae0a6fSJiri Olsa return ret;
99425b1606bSNamhyung Kim }
99586470930SIngo Molnar
996d5a8bd0fSJin Yao evlist__check_mem_load_aux(session->evlist);
997d5a8bd0fSJin Yao
998a4a4d0a7SJiri Olsa if (rep->stats_mode)
999a4a4d0a7SJiri Olsa return stats_print(rep);
1000a4a4d0a7SJiri Olsa
1001930f8b34SJiri Olsa if (rep->tasks_mode)
1002930f8b34SJiri Olsa return tasks_print(rep, stdout);
1003930f8b34SJiri Olsa
1004fad2918eSArnaldo Carvalho de Melo report__warn_kptr_restrict(rep);
1005ec80fde7SArnaldo Carvalho de Melo
1006e5cadb93SArnaldo Carvalho de Melo evlist__for_each_entry(session->evlist, pos)
1007590cd344SNamhyung Kim rep->nr_entries += evsel__hists(pos)->nr_entries;
1008590cd344SNamhyung Kim
1009150e465aSNamhyung Kim if (use_browser == 0) {
1010da21d1b5SArnaldo Carvalho de Melo if (verbose > 3)
1011b3165f41SArnaldo Carvalho de Melo perf_session__fprintf(session, stdout);
101286470930SIngo Molnar
1013da21d1b5SArnaldo Carvalho de Melo if (verbose > 2)
1014cbf69680SArnaldo Carvalho de Melo perf_session__fprintf_dsos(session, stdout);
101586470930SIngo Molnar
101671ad0f5eSJiri Olsa if (dump_trace) {
10172775de0bSNamhyung Kim perf_session__fprintf_nr_events(session, stdout,
10182775de0bSNamhyung Kim rep->skip_empty);
10192775de0bSNamhyung Kim evlist__fprintf_nr_events(session->evlist, stdout,
10202775de0bSNamhyung Kim rep->skip_empty);
1021d4ae0a6fSJiri Olsa return 0;
102271ad0f5eSJiri Olsa }
1023150e465aSNamhyung Kim }
102471ad0f5eSJiri Olsa
10255b2ea6f2SNamhyung Kim ret = report__collapse_hists(rep);
10265b2ea6f2SNamhyung Kim if (ret) {
10275b2ea6f2SNamhyung Kim ui__error("failed to process hist entry\n");
10285b2ea6f2SNamhyung Kim return ret;
10295b2ea6f2SNamhyung Kim }
1030e248de33SArnaldo Carvalho de Melo
103133e940a2SArnaldo Carvalho de Melo if (session_done())
103233e940a2SArnaldo Carvalho de Melo return 0;
103333e940a2SArnaldo Carvalho de Melo
1034740b97f9SNamhyung Kim /*
1035740b97f9SNamhyung Kim * recalculate number of entries after collapsing since it
1036740b97f9SNamhyung Kim * might be changed during the collapse phase.
1037740b97f9SNamhyung Kim */
1038740b97f9SNamhyung Kim rep->nr_entries = 0;
1039e5cadb93SArnaldo Carvalho de Melo evlist__for_each_entry(session->evlist, pos)
1040740b97f9SNamhyung Kim rep->nr_entries += evsel__hists(pos)->nr_entries;
1041740b97f9SNamhyung Kim
104258c311daSNamhyung Kim if (rep->nr_entries == 0) {
10432d4f2799SJiri Olsa ui__error("The %s data has no samples!\n", data->path);
1044d4ae0a6fSJiri Olsa return 0;
104574cfc17dSArnaldo Carvalho de Melo }
104674cfc17dSArnaldo Carvalho de Melo
1047740b97f9SNamhyung Kim report__output_resort(rep);
10486e1f601aSNamhyung Kim
10496f7164faSJin Yao if (rep->total_cycles_mode) {
1050cca0cc76SJin Yao int block_hpps[6] = {
1051cca0cc76SJin Yao PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT,
1052cca0cc76SJin Yao PERF_HPP_REPORT__BLOCK_LBR_CYCLES,
1053cca0cc76SJin Yao PERF_HPP_REPORT__BLOCK_CYCLES_PCT,
1054cca0cc76SJin Yao PERF_HPP_REPORT__BLOCK_AVG_CYCLES,
1055cca0cc76SJin Yao PERF_HPP_REPORT__BLOCK_RANGE,
1056cca0cc76SJin Yao PERF_HPP_REPORT__BLOCK_DSO,
1057cca0cc76SJin Yao };
1058cca0cc76SJin Yao
10596f7164faSJin Yao rep->block_reports = block_info__create_report(session->evlist,
1060cca0cc76SJin Yao rep->total_cycles,
1061cca0cc76SJin Yao block_hpps, 6,
1062cca0cc76SJin Yao &rep->nr_block_reports);
10636f7164faSJin Yao if (!rep->block_reports)
10646f7164faSJin Yao return -1;
10656f7164faSJin Yao }
10666f7164faSJin Yao
10678362951bSArnaldo Carvalho de Melo return report__browse_hists(rep);
106886470930SIngo Molnar }
106986470930SIngo Molnar
10704eb3e478SFrederic Weisbecker static int
report_parse_callchain_opt(const struct option * opt,const char * arg,int unset)1071cff6bb46SDon Zickus report_parse_callchain_opt(const struct option *opt, const char *arg, int unset)
10724eb3e478SFrederic Weisbecker {
10731cc83815SArnaldo Carvalho de Melo struct callchain_param *callchain = opt->value;
1074c20ab37eSFrederic Weisbecker
10751cc83815SArnaldo Carvalho de Melo callchain->enabled = !unset;
1076b9a63b9bSArnaldo Carvalho de Melo /*
1077b9a63b9bSArnaldo Carvalho de Melo * --no-call-graph
1078b9a63b9bSArnaldo Carvalho de Melo */
1079b9a63b9bSArnaldo Carvalho de Melo if (unset) {
10801cc83815SArnaldo Carvalho de Melo symbol_conf.use_callchain = false;
10811cc83815SArnaldo Carvalho de Melo callchain->mode = CHAIN_NONE;
1082b9a63b9bSArnaldo Carvalho de Melo return 0;
1083b9a63b9bSArnaldo Carvalho de Melo }
1084b9a63b9bSArnaldo Carvalho de Melo
1085cff6bb46SDon Zickus return parse_callchain_report_opt(arg);
10864eb3e478SFrederic Weisbecker }
10874eb3e478SFrederic Weisbecker
10882a1292cbSAndi Kleen static int
parse_time_quantum(const struct option * opt,const char * arg,int unset __maybe_unused)10892a1292cbSAndi Kleen parse_time_quantum(const struct option *opt, const char *arg,
10902a1292cbSAndi Kleen int unset __maybe_unused)
10912a1292cbSAndi Kleen {
10922a1292cbSAndi Kleen unsigned long *time_q = opt->value;
10932a1292cbSAndi Kleen char *end;
10942a1292cbSAndi Kleen
10952a1292cbSAndi Kleen *time_q = strtoul(arg, &end, 0);
10962a1292cbSAndi Kleen if (end == arg)
10972a1292cbSAndi Kleen goto parse_err;
10982a1292cbSAndi Kleen if (*time_q == 0) {
10992a1292cbSAndi Kleen pr_err("time quantum cannot be 0");
11002a1292cbSAndi Kleen return -1;
11012a1292cbSAndi Kleen }
1102526bbbddSArnaldo Carvalho de Melo end = skip_spaces(end);
11032a1292cbSAndi Kleen if (*end == 0)
11042a1292cbSAndi Kleen return 0;
11052a1292cbSAndi Kleen if (!strcmp(end, "s")) {
11062a1292cbSAndi Kleen *time_q *= NSEC_PER_SEC;
11072a1292cbSAndi Kleen return 0;
11082a1292cbSAndi Kleen }
11092a1292cbSAndi Kleen if (!strcmp(end, "ms")) {
11102a1292cbSAndi Kleen *time_q *= NSEC_PER_MSEC;
11112a1292cbSAndi Kleen return 0;
11122a1292cbSAndi Kleen }
11132a1292cbSAndi Kleen if (!strcmp(end, "us")) {
11142a1292cbSAndi Kleen *time_q *= NSEC_PER_USEC;
11152a1292cbSAndi Kleen return 0;
11162a1292cbSAndi Kleen }
11172a1292cbSAndi Kleen if (!strcmp(end, "ns"))
11182a1292cbSAndi Kleen return 0;
11192a1292cbSAndi Kleen parse_err:
11202a1292cbSAndi Kleen pr_err("Cannot parse time quantum `%s'\n", arg);
11212a1292cbSAndi Kleen return -1;
11222a1292cbSAndi Kleen }
11232a1292cbSAndi Kleen
1124b21484f1SGreg Price int
report_parse_ignore_callees_opt(const struct option * opt __maybe_unused,const char * arg,int unset __maybe_unused)1125b21484f1SGreg Price report_parse_ignore_callees_opt(const struct option *opt __maybe_unused,
1126b21484f1SGreg Price const char *arg, int unset __maybe_unused)
1127b21484f1SGreg Price {
1128b21484f1SGreg Price if (arg) {
1129b21484f1SGreg Price int err = regcomp(&ignore_callees_regex, arg, REG_EXTENDED);
1130b21484f1SGreg Price if (err) {
1131b21484f1SGreg Price char buf[BUFSIZ];
1132b21484f1SGreg Price regerror(err, &ignore_callees_regex, buf, sizeof(buf));
1133b21484f1SGreg Price pr_err("Invalid --ignore-callees regex: %s\n%s", arg, buf);
1134b21484f1SGreg Price return -1;
1135b21484f1SGreg Price }
1136b21484f1SGreg Price have_ignore_callees = 1;
1137b21484f1SGreg Price }
1138b21484f1SGreg Price
1139b21484f1SGreg Price return 0;
1140b21484f1SGreg Price }
1141b21484f1SGreg Price
1142993ac88dSStephane Eranian static int
parse_branch_mode(const struct option * opt,const char * str __maybe_unused,int unset)11437e6a7998SArnaldo Carvalho de Melo parse_branch_mode(const struct option *opt,
11441d037ca1SIrina Tirdea const char *str __maybe_unused, int unset)
1145993ac88dSStephane Eranian {
114655369fc1SNamhyung Kim int *branch_mode = opt->value;
114755369fc1SNamhyung Kim
114855369fc1SNamhyung Kim *branch_mode = !unset;
1149993ac88dSStephane Eranian return 0;
1150993ac88dSStephane Eranian }
1151993ac88dSStephane Eranian
1152064f1981SNamhyung Kim static int
parse_percent_limit(const struct option * opt,const char * str,int unset __maybe_unused)1153064f1981SNamhyung Kim parse_percent_limit(const struct option *opt, const char *str,
1154064f1981SNamhyung Kim int unset __maybe_unused)
1155064f1981SNamhyung Kim {
115628b21393SArnaldo Carvalho de Melo struct report *rep = opt->value;
11572665b452SNamhyung Kim double pcnt = strtof(str, NULL);
1158064f1981SNamhyung Kim
11592665b452SNamhyung Kim rep->min_percent = pcnt;
11602665b452SNamhyung Kim callchain_param.min_percent = pcnt;
1161064f1981SNamhyung Kim return 0;
1162064f1981SNamhyung Kim }
1163064f1981SNamhyung Kim
process_attr(struct perf_tool * tool __maybe_unused,union perf_event * event,struct evlist ** pevlist)11640d71a2b2SJiri Olsa static int process_attr(struct perf_tool *tool __maybe_unused,
11650d71a2b2SJiri Olsa union perf_event *event,
11660d71a2b2SJiri Olsa struct evlist **pevlist)
11670d71a2b2SJiri Olsa {
11680d71a2b2SJiri Olsa u64 sample_type;
11690d71a2b2SJiri Olsa int err;
11700d71a2b2SJiri Olsa
11710d71a2b2SJiri Olsa err = perf_event__process_attr(tool, event, pevlist);
11720d71a2b2SJiri Olsa if (err)
11730d71a2b2SJiri Olsa return err;
11740d71a2b2SJiri Olsa
11750d71a2b2SJiri Olsa /*
11760d71a2b2SJiri Olsa * Check if we need to enable callchains based
11770d71a2b2SJiri Olsa * on events sample_type.
11780d71a2b2SJiri Olsa */
1179b3c2cc2bSArnaldo Carvalho de Melo sample_type = evlist__combined_sample_type(*pevlist);
1180aa8db3e4SAlexandre Truong callchain_param_setup(sample_type, perf_env__arch((*pevlist)->env));
11810d71a2b2SJiri Olsa return 0;
11820d71a2b2SJiri Olsa }
11830d71a2b2SJiri Olsa
cmd_report(int argc,const char ** argv)1184b0ad8ea6SArnaldo Carvalho de Melo int cmd_report(int argc, const char **argv)
1185d20deb64SArnaldo Carvalho de Melo {
1186993ac88dSStephane Eranian struct perf_session *session;
1187520a2ebcSAdrian Hunter struct itrace_synth_opts itrace_synth_opts = { .set = 0, };
1188efad1415SRobert Richter struct stat st;
1189993ac88dSStephane Eranian bool has_br_stack = false;
119055369fc1SNamhyung Kim int branch_mode = -1;
11910feba17bSJin Yao int last_key = 0;
1192fa94c36cSAndi Kleen bool branch_call_mode = false;
11939d0199cdSArnaldo Carvalho de Melo #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent"
119449b8e2beSRasmus Villemoes static const char report_callchain_help[] = "Display call graph (stack chain/backtrace):\n\n"
11959d0199cdSArnaldo Carvalho de Melo CALLCHAIN_REPORT_HELP
11969d0199cdSArnaldo Carvalho de Melo "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT;
119776a26549SNamhyung Kim char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT;
1198d20deb64SArnaldo Carvalho de Melo const char * const report_usage[] = {
1199fb2bacebSNamhyung Kim "perf report [<options>]",
120086470930SIngo Molnar NULL
120186470930SIngo Molnar };
120228b21393SArnaldo Carvalho de Melo struct report report = {
120345694aa7SArnaldo Carvalho de Melo .tool = {
1204d20deb64SArnaldo Carvalho de Melo .sample = process_sample_event,
1205d20deb64SArnaldo Carvalho de Melo .mmap = perf_event__process_mmap,
12065c5e854bSStephane Eranian .mmap2 = perf_event__process_mmap2,
1207d20deb64SArnaldo Carvalho de Melo .comm = perf_event__process_comm,
1208f3b3614aSHari Bathini .namespaces = perf_event__process_namespaces,
1209ba78c1c5SNamhyung Kim .cgroup = perf_event__process_cgroup,
1210f62d3f0fSArnaldo Carvalho de Melo .exit = perf_event__process_exit,
1211f62d3f0fSArnaldo Carvalho de Melo .fork = perf_event__process_fork,
1212d20deb64SArnaldo Carvalho de Melo .lost = perf_event__process_lost,
1213d20deb64SArnaldo Carvalho de Melo .read = process_read_event,
12140d71a2b2SJiri Olsa .attr = process_attr,
1215378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
1216d20deb64SArnaldo Carvalho de Melo .tracing_data = perf_event__process_tracing_data,
1217378ef0f5SIan Rogers #endif
1218d20deb64SArnaldo Carvalho de Melo .build_id = perf_event__process_build_id,
1219520a2ebcSAdrian Hunter .id_index = perf_event__process_id_index,
1220520a2ebcSAdrian Hunter .auxtrace_info = perf_event__process_auxtrace_info,
1221520a2ebcSAdrian Hunter .auxtrace = perf_event__process_auxtrace,
12224ab8455fSJiri Olsa .event_update = perf_event__process_event_update,
122357b5de46SJiri Olsa .feature = process_feature_event,
12240a8cb85cSJiri Olsa .ordered_events = true,
1225d20deb64SArnaldo Carvalho de Melo .ordering_requires_timestamps = true,
1226d20deb64SArnaldo Carvalho de Melo },
1227fe176085SArnaldo Carvalho de Melo .max_stack = PERF_MAX_STACK_DEPTH,
1228d20deb64SArnaldo Carvalho de Melo .pretty_printing_style = "normal",
122921394d94SKan Liang .socket_filter = -1,
12308f08cf33SNamhyung Kim .skip_empty = true,
1231d20deb64SArnaldo Carvalho de Melo };
1232a37338aaSRiccardo Mancini char *sort_order_help = sort_help("sort by key(s):");
1233a37338aaSRiccardo Mancini char *field_order_help = sort_help("output field(s): overhead period sample ");
123457594454SIan Rogers const char *disassembler_style = NULL, *objdump_path = NULL, *addr2line_path = NULL;
1235d20deb64SArnaldo Carvalho de Melo const struct option options[] = {
123670cb4e96SFeng Tang OPT_STRING('i', "input", &input_name, "file",
123786470930SIngo Molnar "input file name"),
1238c0555642SIan Munsie OPT_INCR('v', "verbose", &verbose,
123986470930SIngo Molnar "be more verbose (show symbol address, etc)"),
1240a527c2c1SJames Clark OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any warnings or messages"),
124186470930SIngo Molnar OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
124286470930SIngo Molnar "dump raw trace in ASCII"),
1243a4a4d0a7SJiri Olsa OPT_BOOLEAN(0, "stats", &report.stats_mode, "Display event stats"),
1244930f8b34SJiri Olsa OPT_BOOLEAN(0, "tasks", &report.tasks_mode, "Display recorded tasks"),
12456439d7d1SArnaldo Carvalho de Melo OPT_BOOLEAN(0, "mmaps", &report.mmaps_mode, "Display recorded tasks memory maps"),
1246b32d133aSArnaldo Carvalho de Melo OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
1247b32d133aSArnaldo Carvalho de Melo "file", "vmlinux pathname"),
124891340c51SArnaldo Carvalho de Melo OPT_BOOLEAN(0, "ignore-vmlinux", &symbol_conf.ignore_vmlinux,
124991340c51SArnaldo Carvalho de Melo "don't load vmlinux even if found"),
1250b226a5a7SDavid Ahern OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
1251b226a5a7SDavid Ahern "file", "kallsyms pathname"),
12522059fc7aSArnaldo Carvalho de Melo OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
1253b32d133aSArnaldo Carvalho de Melo OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
125442976487SMike Galbraith "load module symbols - WARNING: use only with -k and LIVE kernel"),
1255d599db3fSArnaldo Carvalho de Melo OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
1256e3d7e183SArnaldo Carvalho de Melo "Show a column with the number of samples"),
1257fa372aaeSArnaldo Carvalho de Melo OPT_BOOLEAN('T', "threads", &report.show_threads,
12588d513270SBrice Goglin "Show per-thread event counters"),
1259fa372aaeSArnaldo Carvalho de Melo OPT_STRING(0, "pretty", &report.pretty_printing_style, "key",
12609f866697SBrice Goglin "pretty printing style key: normal raw"),
12613402ae0aSIan Rogers #ifdef HAVE_SLANG_SUPPORT
1262fa372aaeSArnaldo Carvalho de Melo OPT_BOOLEAN(0, "tui", &report.use_tui, "Use the TUI interface"),
12633402ae0aSIan Rogers #endif
1264557cc18eSIan Rogers #ifdef HAVE_GTK2_SUPPORT
1265c31a9457SPekka Enberg OPT_BOOLEAN(0, "gtk", &report.use_gtk, "Use the GTK2 interface"),
1266557cc18eSIan Rogers #endif
1267fa372aaeSArnaldo Carvalho de Melo OPT_BOOLEAN(0, "stdio", &report.use_stdio,
1268fa372aaeSArnaldo Carvalho de Melo "Use the stdio interface"),
12695cfe2c82SJiri Olsa OPT_BOOLEAN(0, "header", &report.header, "Show data header."),
12705cfe2c82SJiri Olsa OPT_BOOLEAN(0, "header-only", &report.header_only,
12715cfe2c82SJiri Olsa "Show only data header."),
127286470930SIngo Molnar OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
1273a37338aaSRiccardo Mancini sort_order_help),
1274a7d945bcSNamhyung Kim OPT_STRING('F', "fields", &field_order, "key[,keys...]",
1275a37338aaSRiccardo Mancini field_order_help),
1276b272a59dSNamhyung Kim OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization,
1277a1645ce1SZhang, Yanmin "Show sample percentage for different cpu modes"),
1278b272a59dSNamhyung Kim OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
1279b272a59dSNamhyung Kim "Show sample percentage for different cpu modes", PARSE_OPT_HIDDEN),
1280b25bcf2fSIngo Molnar OPT_STRING('p', "parent", &parent_pattern, "regex",
1281b25bcf2fSIngo Molnar "regex filter to identify parent, see: '--sort parent'"),
1282d599db3fSArnaldo Carvalho de Melo OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
1283b8e6d829SIngo Molnar "Only display entries with parent-match"),
12841cc83815SArnaldo Carvalho de Melo OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param,
1285f2af0086SNamhyung Kim "print_type,threshold[,print_limit],order,sort_key[,branch],value",
128621cf6284SNamhyung Kim report_callchain_help, &report_parse_callchain_opt,
128721cf6284SNamhyung Kim callchain_default_opt),
1288793aaaabSNamhyung Kim OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain,
1289aa9d1f83SAndi Kleen "Accumulate callchains of children and show total overhead as well. "
1290aa9d1f83SAndi Kleen "Enabled by default, use --no-children to disable."),
129191e95617SWaiman Long OPT_INTEGER(0, "max-stack", &report.max_stack,
129291e95617SWaiman Long "Set the maximum stack depth when parsing the callchain, "
129391e95617SWaiman Long "anything beyond the specified depth will be ignored. "
12944cb93446SArnaldo Carvalho de Melo "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
1295fa372aaeSArnaldo Carvalho de Melo OPT_BOOLEAN('G', "inverted", &report.inverted_callchain,
1296fa372aaeSArnaldo Carvalho de Melo "alias for inverted call graph"),
1297b21484f1SGreg Price OPT_CALLBACK(0, "ignore-callees", NULL, "regex",
1298b21484f1SGreg Price "ignore callees of these functions in call graphs",
1299b21484f1SGreg Price report_parse_ignore_callees_opt),
1300655000e7SArnaldo Carvalho de Melo OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
130125903407SArnaldo Carvalho de Melo "only consider symbols in these dsos"),
1302c8e66720SDavid Ahern OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
1303cc8b88b1SArnaldo Carvalho de Melo "only consider symbols in these comms"),
1304e03eaa40SDavid Ahern OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]",
1305e03eaa40SDavid Ahern "only consider symbols in these pids"),
1306e03eaa40SDavid Ahern OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
1307e03eaa40SDavid Ahern "only consider symbols in these tids"),
1308655000e7SArnaldo Carvalho de Melo OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
13097bec7a91SArnaldo Carvalho de Melo "only consider these symbols"),
1310b14ffacaSNamhyung Kim OPT_STRING(0, "symbol-filter", &report.symbol_filter_str, "filter",
1311b14ffacaSNamhyung Kim "only show symbols that (partially) match with this filter"),
1312655000e7SArnaldo Carvalho de Melo OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str,
131352d422deSArnaldo Carvalho de Melo "width[,width...]",
131452d422deSArnaldo Carvalho de Melo "don't try to adjust column width, use these fixed values"),
13150c8c2077SWang Nan OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
131652d422deSArnaldo Carvalho de Melo "separator for columns, no spaces will be added between "
131752d422deSArnaldo Carvalho de Melo "columns '.' is reserved."),
1318b49a8fe5SNamhyung Kim OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved,
131971289be7SArnaldo Carvalho de Melo "Only display entries resolved to a symbol"),
1320a7066709SHe Kuang OPT_CALLBACK(0, "symfs", NULL, "directory",
1321a7066709SHe Kuang "Look for files with symbols relative to this directory",
1322a7066709SHe Kuang symbol__config_symfs),
1323c8e66720SDavid Ahern OPT_STRING('C', "cpu", &report.cpu_list, "cpu",
1324fa372aaeSArnaldo Carvalho de Melo "list of cpus to profile"),
1325fa372aaeSArnaldo Carvalho de Melo OPT_BOOLEAN('I', "show-info", &report.show_full_info,
1326fbe96f29SStephane Eranian "Display extended information about perf.data file"),
1327e0af85d6SNamhyung Kim OPT_BOOLEAN(0, "source", &annotate_opts.annotate_src,
132864c6f0c7SArnaldo Carvalho de Melo "Interleave source code with assembly code (default)"),
1329e0af85d6SNamhyung Kim OPT_BOOLEAN(0, "asm-raw", &annotate_opts.show_asm_raw,
133064c6f0c7SArnaldo Carvalho de Melo "Display raw encoding of assembly instructions (default)"),
133156d9117cSIan Rogers OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
1332f69b64f7SAndi Kleen "Specify disassembler style (e.g. -M intel for intel syntax)"),
1333e0af85d6SNamhyung Kim OPT_STRING(0, "prefix", &annotate_opts.prefix, "prefix",
13343b0b16bfSAndi Kleen "Add prefix to source file path names in programs (with --prefix-strip)"),
1335e0af85d6SNamhyung Kim OPT_STRING(0, "prefix-strip", &annotate_opts.prefix_strip, "N",
13363b0b16bfSAndi Kleen "Strip first N entries of source file path name in programs (with --prefix)"),
13373f2728bdSArnaldo Carvalho de Melo OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
13383f2728bdSArnaldo Carvalho de Melo "Show a column with the sum of periods"),
133957b5de46SJiri Olsa OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &report.group_set,
134001d14f16SNamhyung Kim "Show event group information together"),
1341429a5f9dSJin Yao OPT_INTEGER(0, "group-sort-idx", &symbol_conf.group_sort_idx,
1342429a5f9dSJin Yao "Sort the output by the event at the index n in group. "
1343429a5f9dSJin Yao "If n is invalid, sort by the first event. "
1344429a5f9dSJin Yao "WARNING: should be used on grouped events."),
134555369fc1SNamhyung Kim OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "",
1346fa94c36cSAndi Kleen "use branch records for per branch histogram filling",
1347fa94c36cSAndi Kleen parse_branch_mode),
1348fa94c36cSAndi Kleen OPT_BOOLEAN(0, "branch-history", &branch_call_mode,
1349fa94c36cSAndi Kleen "add last branch records to call history"),
135056d9117cSIan Rogers OPT_STRING(0, "objdump", &objdump_path, "path",
13517a4ec938SMaciek Borzecki "objdump binary to use for disassembly and annotations"),
135257594454SIan Rogers OPT_STRING(0, "addr2line", &addr2line_path, "path",
135357594454SIan Rogers "addr2line binary to use for line numbers"),
1354328ccdacSNamhyung Kim OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
1355*2e09336fSJiachen Zhang "Symbol demangling. Enabled by default, use --no-demangle to disable."),
1356763122adSAvi Kivity OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
1357763122adSAvi Kivity "Enable kernel symbol demangling"),
1358f4f7e28dSStephane Eranian OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"),
13594968ac8fSAndi Kleen OPT_INTEGER(0, "samples", &symbol_conf.res_sample,
13604968ac8fSAndi Kleen "Number of samples to save per histogram entry for individual browsing"),
1361064f1981SNamhyung Kim OPT_CALLBACK(0, "percent-limit", &report, "percent",
1362064f1981SNamhyung Kim "Don't show entries under that percent", parse_percent_limit),
1363f2148330SNamhyung Kim OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
136433db4568SNamhyung Kim "how to display percentage of filtered entries", parse_filter_percentage),
1365520a2ebcSAdrian Hunter OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
1366c12e039dSAndi Kleen "Instruction Tracing options\n" ITRACE_HELP,
1367520a2ebcSAdrian Hunter itrace_parse_synth_opts),
1368a9710ba0SAndi Kleen OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
1369a9710ba0SAndi Kleen "Show full source file name path for source lines"),
13709e207ddfSKan Liang OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf.show_ref_callgraph,
13719e207ddfSKan Liang "Show callgraph from reference event"),
1372b1d1429bSKan Liang OPT_BOOLEAN(0, "stitch-lbr", &report.stitch_lbr,
1373b1d1429bSKan Liang "Enable LBR callgraph stitching approach"),
137421394d94SKan Liang OPT_INTEGER(0, "socket-filter", &report.socket_filter,
137521394d94SKan Liang "only show processor socket that match with this filter"),
1376053a3989SNamhyung Kim OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace,
1377053a3989SNamhyung Kim "Show raw trace event output (do not use print fmt or plugins)"),
13784251446dSNamhyung Kim OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy,
13794251446dSNamhyung Kim "Show entries in a hierarchy"),
1380175b968bSArnaldo Carvalho de Melo OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
1381175b968bSArnaldo Carvalho de Melo "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
1382175b968bSArnaldo Carvalho de Melo stdio__config_color, "always"),
138346690a80SDavid Ahern OPT_STRING(0, "time", &report.time_str, "str",
138446690a80SDavid Ahern "Time span of interest (start,stop)"),
1385f3a60646SJin Yao OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name,
1386f3a60646SJin Yao "Show inline function"),
1387e0af85d6SNamhyung Kim OPT_CALLBACK(0, "percent-type", &annotate_opts, "local-period",
1388e6902d1bSJiri Olsa "Set percent type local/global-period/hits",
1389e6902d1bSJiri Olsa annotate_parse_percent_type),
139052bab886SAndi Kleen OPT_BOOLEAN(0, "ns", &symbol_conf.nanosecs, "Show times in nanosecs"),
13912a1292cbSAndi Kleen OPT_CALLBACK(0, "time-quantum", &symbol_conf.time_quantum, "time (ms|us|ns|s)",
13922a1292cbSAndi Kleen "Set time quantum for time sort key (default 100ms)",
13932a1292cbSAndi Kleen parse_time_quantum),
1394ef4b1a53SArnaldo Carvalho de Melo OPTS_EVSWITCH(&report.evswitch),
13956f7164faSJin Yao OPT_BOOLEAN(0, "total-cycles", &report.total_cycles_mode,
13966f7164faSJin Yao "Sort all blocks by 'Sampled Cycles%'"),
13972e989f82SJin Yao OPT_BOOLEAN(0, "disable-order", &report.disable_order,
13982e989f82SJin Yao "Disable raw trace ordering"),
13992775de0bSNamhyung Kim OPT_BOOLEAN(0, "skip-empty", &report.skip_empty,
14002775de0bSNamhyung Kim "Do not display empty (or dummy) events in the output"),
140186470930SIngo Molnar OPT_END()
140286470930SIngo Molnar };
14038ceb41d7SJiri Olsa struct perf_data data = {
1404f5fc1412SJiri Olsa .mode = PERF_DATA_MODE_READ,
1405f5fc1412SJiri Olsa };
1406a635fc51SArnaldo Carvalho de Melo int ret = hists__init();
1407ec6ae74fSJin Yao char sort_tmp[128];
1408a635fc51SArnaldo Carvalho de Melo
1409a635fc51SArnaldo Carvalho de Melo if (ret < 0)
1410a37338aaSRiccardo Mancini goto exit;
141186470930SIngo Molnar
14124ddf437cSIan Rogers /*
14134ddf437cSIan Rogers * tasks_mode require access to exited threads to list those that are in
14144ddf437cSIan Rogers * the data file. Off-cpu events are synthesized after other events and
14154ddf437cSIan Rogers * reference exited threads.
14164ddf437cSIan Rogers */
14174ddf437cSIan Rogers symbol_conf.keep_exited_threads = true;
14184ddf437cSIan Rogers
1419e0af85d6SNamhyung Kim annotation_options__init(&annotate_opts);
1420217b7d41SIan Rogers
1421ecc4c561SArnaldo Carvalho de Melo ret = perf_config(report__config, &report);
1422ecc4c561SArnaldo Carvalho de Melo if (ret)
1423a37338aaSRiccardo Mancini goto exit;
142400c7e1f1SNamhyung Kim
1425655000e7SArnaldo Carvalho de Melo argc = parse_options(argc, argv, options, report_usage, 0);
1426b3f38fc2SNamhyung Kim if (argc) {
1427b3f38fc2SNamhyung Kim /*
1428b3f38fc2SNamhyung Kim * Special case: if there's an argument left then assume that
1429b3f38fc2SNamhyung Kim * it's a symbol filter:
1430b3f38fc2SNamhyung Kim */
1431b3f38fc2SNamhyung Kim if (argc > 1)
1432b3f38fc2SNamhyung Kim usage_with_options(report_usage, options);
1433b3f38fc2SNamhyung Kim
1434b3f38fc2SNamhyung Kim report.symbol_filter_str = argv[0];
1435b3f38fc2SNamhyung Kim }
1436655000e7SArnaldo Carvalho de Melo
143756d9117cSIan Rogers if (disassembler_style) {
1438e0af85d6SNamhyung Kim annotate_opts.disassembler_style = strdup(disassembler_style);
1439e0af85d6SNamhyung Kim if (!annotate_opts.disassembler_style)
144056d9117cSIan Rogers return -ENOMEM;
144156d9117cSIan Rogers }
144256d9117cSIan Rogers if (objdump_path) {
1443e0af85d6SNamhyung Kim annotate_opts.objdump_path = strdup(objdump_path);
1444e0af85d6SNamhyung Kim if (!annotate_opts.objdump_path)
144556d9117cSIan Rogers return -ENOMEM;
144656d9117cSIan Rogers }
144757594454SIan Rogers if (addr2line_path) {
144857594454SIan Rogers symbol_conf.addr2line_path = strdup(addr2line_path);
144957594454SIan Rogers if (!symbol_conf.addr2line_path)
145057594454SIan Rogers return -ENOMEM;
145157594454SIan Rogers }
145256d9117cSIan Rogers
1453e0af85d6SNamhyung Kim if (annotate_check_args(&annotate_opts) < 0) {
1454a37338aaSRiccardo Mancini ret = -EINVAL;
1455a37338aaSRiccardo Mancini goto exit;
1456a37338aaSRiccardo Mancini }
14573b0b16bfSAndi Kleen
14586439d7d1SArnaldo Carvalho de Melo if (report.mmaps_mode)
14596439d7d1SArnaldo Carvalho de Melo report.tasks_mode = true;
14606439d7d1SArnaldo Carvalho de Melo
14612e989f82SJin Yao if (dump_trace && report.disable_order)
1462977f739bSJiri Olsa report.tool.ordered_events = false;
1463977f739bSJiri Olsa
146427fafab5SNamhyung Kim if (quiet)
146527fafab5SNamhyung Kim perf_quiet_option();
146627fafab5SNamhyung Kim
1467a3df50abSJames Clark ret = symbol__validate_sym_arguments();
1468a3df50abSJames Clark if (ret)
1469a37338aaSRiccardo Mancini goto exit;
147036c8bb56SLi Zhang
1471fa372aaeSArnaldo Carvalho de Melo if (report.inverted_callchain)
1472d797fdc5SSam Liao callchain_param.order = ORDER_CALLER;
1473792aeafaSNamhyung Kim if (symbol_conf.cumulate_callchain && !callchain_param.order_set)
1474792aeafaSNamhyung Kim callchain_param.order = ORDER_CALLER;
1475d797fdc5SSam Liao
14761c5c25b3SAdrian Hunter if ((itrace_synth_opts.callchain || itrace_synth_opts.add_callchain) &&
1477188bb5e2SAdrian Hunter (int)itrace_synth_opts.callchain_sz > report.max_stack)
1478188bb5e2SAdrian Hunter report.max_stack = itrace_synth_opts.callchain_sz;
1479188bb5e2SAdrian Hunter
148070cb4e96SFeng Tang if (!input_name || !strlen(input_name)) {
1481efad1415SRobert Richter if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))
148270cb4e96SFeng Tang input_name = "-";
1483efad1415SRobert Richter else
148470cb4e96SFeng Tang input_name = "perf.data";
1485efad1415SRobert Richter }
1486ad0de097SFeng Tang
14872d4f2799SJiri Olsa data.path = input_name;
14888ceb41d7SJiri Olsa data.force = symbol_conf.force;
1489f5fc1412SJiri Olsa
1490ad0de097SFeng Tang repeat:
14912681bd85SNamhyung Kim session = perf_session__new(&data, &report.tool);
1492a37338aaSRiccardo Mancini if (IS_ERR(session)) {
1493a37338aaSRiccardo Mancini ret = PTR_ERR(session);
1494a37338aaSRiccardo Mancini goto exit;
1495a37338aaSRiccardo Mancini }
1496efad1415SRobert Richter
1497ef4b1a53SArnaldo Carvalho de Melo ret = evswitch__init(&report.evswitch, session->evlist, stderr);
1498ef4b1a53SArnaldo Carvalho de Melo if (ret)
1499a37338aaSRiccardo Mancini goto exit;
1500ef4b1a53SArnaldo Carvalho de Melo
1501cb62c6f1SAlexey Budankov if (zstd_init(&(session->zstd_data), 0) < 0)
1502cb62c6f1SAlexey Budankov pr_warning("Decompression initialization failed. Reported data may be incomplete.\n");
1503cb62c6f1SAlexey Budankov
150494786b67SJiri Olsa if (report.queue_size) {
150594786b67SJiri Olsa ordered_events__set_alloc_size(&session->ordered_events,
150694786b67SJiri Olsa report.queue_size);
150794786b67SJiri Olsa }
150894786b67SJiri Olsa
1509520a2ebcSAdrian Hunter session->itrace_synth_opts = &itrace_synth_opts;
1510520a2ebcSAdrian Hunter
1511993ac88dSStephane Eranian report.session = session;
1512993ac88dSStephane Eranian
1513993ac88dSStephane Eranian has_br_stack = perf_header__has_feat(&session->header,
1514993ac88dSStephane Eranian HEADER_BRANCH_STACK);
1515b3c2cc2bSArnaldo Carvalho de Melo if (evlist__combined_sample_type(session->evlist) & PERF_SAMPLE_STACK_USER)
151610ccbc1cSAlexey Budankov has_br_stack = false;
1517993ac88dSStephane Eranian
151857b5de46SJiri Olsa setup_forced_leader(&report, session->evlist);
1519ad52b8cbSJiri Olsa
15209d2dc632SIan Rogers if (symbol_conf.group_sort_idx && evlist__nr_groups(session->evlist) == 0) {
1521429a5f9dSJin Yao parse_options_usage(NULL, options, "group-sort-idx", 0);
1522429a5f9dSJin Yao ret = -EINVAL;
1523429a5f9dSJin Yao goto error;
1524429a5f9dSJin Yao }
1525429a5f9dSJin Yao
1526ec90e42cSAdrian Hunter if (itrace_synth_opts.last_branch || itrace_synth_opts.add_last_branch)
1527fb9fab66SAdrian Hunter has_br_stack = true;
1528fb9fab66SAdrian Hunter
1529f9a7be7cSJin Yao if (has_br_stack && branch_call_mode)
1530f9a7be7cSJin Yao symbol_conf.show_branchflag_count = true;
1531f9a7be7cSJin Yao
15322d78b189SJin Yao memset(&report.brtype_stat, 0, sizeof(struct branch_type_stat));
15332d78b189SJin Yao
1534fa94c36cSAndi Kleen /*
1535fa94c36cSAndi Kleen * Branch mode is a tristate:
1536fa94c36cSAndi Kleen * -1 means default, so decide based on the file having branch data.
1537fa94c36cSAndi Kleen * 0/1 means the user chose a mode.
1538fa94c36cSAndi Kleen */
1539fa94c36cSAndi Kleen if (((branch_mode == -1 && has_br_stack) || branch_mode == 1) &&
1540fefd2d96SHe Kuang !branch_call_mode) {
154155369fc1SNamhyung Kim sort__mode = SORT_MODE__BRANCH;
1542793aaaabSNamhyung Kim symbol_conf.cumulate_callchain = false;
1543793aaaabSNamhyung Kim }
1544fa94c36cSAndi Kleen if (branch_call_mode) {
154509a6a1b0SAndi Kleen callchain_param.key = CCKEY_ADDRESS;
15466fa9c3e7SZou Wei callchain_param.branch_callstack = true;
1547fa94c36cSAndi Kleen symbol_conf.use_callchain = true;
1548fa94c36cSAndi Kleen callchain_register_param(&callchain_param);
1549fa94c36cSAndi Kleen if (sort_order == NULL)
1550fa94c36cSAndi Kleen sort_order = "srcline,symbol,dso";
1551fa94c36cSAndi Kleen }
1552993ac88dSStephane Eranian
1553f4f7e28dSStephane Eranian if (report.mem_mode) {
155455369fc1SNamhyung Kim if (sort__mode == SORT_MODE__BRANCH) {
1555a4210141SNamhyung Kim pr_err("branch and mem mode incompatible\n");
1556f4f7e28dSStephane Eranian goto error;
1557f4f7e28dSStephane Eranian }
1558afab87b9SNamhyung Kim sort__mode = SORT_MODE__MEMORY;
1559793aaaabSNamhyung Kim symbol_conf.cumulate_callchain = false;
1560f4f7e28dSStephane Eranian }
1561a68c2c58SStephane Eranian
15624251446dSNamhyung Kim if (symbol_conf.report_hierarchy) {
15634251446dSNamhyung Kim /* disable incompatible options */
15644251446dSNamhyung Kim symbol_conf.cumulate_callchain = false;
15654251446dSNamhyung Kim
15664251446dSNamhyung Kim if (field_order) {
15674251446dSNamhyung Kim pr_err("Error: --hierarchy and --fields options cannot be used together\n");
15684251446dSNamhyung Kim parse_options_usage(report_usage, options, "F", 1);
15694251446dSNamhyung Kim parse_options_usage(NULL, options, "hierarchy", 0);
15704251446dSNamhyung Kim goto error;
15714251446dSNamhyung Kim }
15724251446dSNamhyung Kim
157352225036SJiri Olsa perf_hpp_list.need_collapse = true;
15744251446dSNamhyung Kim }
15754251446dSNamhyung Kim
1576712d36dbSSeokho Song if (report.use_stdio)
1577712d36dbSSeokho Song use_browser = 0;
15783402ae0aSIan Rogers #ifdef HAVE_SLANG_SUPPORT
1579712d36dbSSeokho Song else if (report.use_tui)
1580712d36dbSSeokho Song use_browser = 1;
15813402ae0aSIan Rogers #endif
1582557cc18eSIan Rogers #ifdef HAVE_GTK2_SUPPORT
1583712d36dbSSeokho Song else if (report.use_gtk)
1584712d36dbSSeokho Song use_browser = 2;
1585557cc18eSIan Rogers #endif
1586712d36dbSSeokho Song
1587b138f42eSNamhyung Kim /* Force tty output for header output and per-thread stat. */
1588b138f42eSNamhyung Kim if (report.header || report.header_only || report.show_threads)
15895cfe2c82SJiri Olsa use_browser = 0;
1590114f709eSDavid Carrillo-Cisneros if (report.header || report.header_only)
1591114f709eSDavid Carrillo-Cisneros report.tool.show_feat_hdr = SHOW_FEAT_HEADER;
1592114f709eSDavid Carrillo-Cisneros if (report.show_full_info)
1593114f709eSDavid Carrillo-Cisneros report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO;
1594930f8b34SJiri Olsa if (report.stats_mode || report.tasks_mode)
1595a4a4d0a7SJiri Olsa use_browser = 0;
1596930f8b34SJiri Olsa if (report.stats_mode && report.tasks_mode) {
15976439d7d1SArnaldo Carvalho de Melo pr_err("Error: --tasks and --mmaps can't be used together with --stats\n");
1598930f8b34SJiri Olsa goto error;
1599930f8b34SJiri Olsa }
16005cfe2c82SJiri Olsa
16016f7164faSJin Yao if (report.total_cycles_mode) {
16026f7164faSJin Yao if (sort__mode != SORT_MODE__BRANCH)
16036f7164faSJin Yao report.total_cycles_mode = false;
16047fa46cbfSJin Yao else
1605848a5e50SJin Yao sort_order = NULL;
16066f7164faSJin Yao }
16076f7164faSJin Yao
16084bceffbcSNamhyung Kim if (strcmp(input_name, "-") != 0)
16094bceffbcSNamhyung Kim setup_browser(true);
161022af969eSNamhyung Kim else
16114bceffbcSNamhyung Kim use_browser = 0;
16124bceffbcSNamhyung Kim
1613ec6ae74fSJin Yao if (sort_order && strstr(sort_order, "ipc")) {
1614ec6ae74fSJin Yao parse_options_usage(report_usage, options, "s", 1);
1615ec6ae74fSJin Yao goto error;
1616ec6ae74fSJin Yao }
1617ec6ae74fSJin Yao
1618ec6ae74fSJin Yao if (sort_order && strstr(sort_order, "symbol")) {
1619ec6ae74fSJin Yao if (sort__mode == SORT_MODE__BRANCH) {
1620ec6ae74fSJin Yao snprintf(sort_tmp, sizeof(sort_tmp), "%s,%s",
1621ec6ae74fSJin Yao sort_order, "ipc_lbr");
1622ec6ae74fSJin Yao report.symbol_ipc = true;
1623ec6ae74fSJin Yao } else {
1624ec6ae74fSJin Yao snprintf(sort_tmp, sizeof(sort_tmp), "%s,%s",
1625ec6ae74fSJin Yao sort_order, "ipc_null");
1626ec6ae74fSJin Yao }
1627ec6ae74fSJin Yao
1628ec6ae74fSJin Yao sort_order = sort_tmp;
1629ec6ae74fSJin Yao }
1630ec6ae74fSJin Yao
16315e3b810aSJin Yao if ((last_key != K_SWITCH_INPUT_DATA && last_key != K_RELOAD) &&
16320feba17bSJin Yao (setup_sorting(session->evlist) < 0)) {
16339887804dSJiri Olsa if (sort_order)
16349887804dSJiri Olsa parse_options_usage(report_usage, options, "s", 1);
16359887804dSJiri Olsa if (field_order)
16369887804dSJiri Olsa parse_options_usage(sort_order ? NULL : report_usage,
16379887804dSJiri Olsa options, "F", 1);
16389887804dSJiri Olsa goto error;
16399887804dSJiri Olsa }
16409887804dSJiri Olsa
164127fafab5SNamhyung Kim if ((report.header || report.header_only) && !quiet) {
16425cfe2c82SJiri Olsa perf_session__fprintf_info(session, stdout,
16435cfe2c82SJiri Olsa report.show_full_info);
164407a716ffSTaeung Song if (report.header_only) {
164503de8656SNamhyung Kim if (data.is_pipe) {
164603de8656SNamhyung Kim /*
164703de8656SNamhyung Kim * we need to process first few records
164803de8656SNamhyung Kim * which contains PERF_RECORD_HEADER_FEATURE.
164903de8656SNamhyung Kim */
165003de8656SNamhyung Kim perf_session__process_events(session);
165103de8656SNamhyung Kim }
165207a716ffSTaeung Song ret = 0;
165307a716ffSTaeung Song goto error;
165407a716ffSTaeung Song }
1655930f8b34SJiri Olsa } else if (use_browser == 0 && !quiet &&
1656930f8b34SJiri Olsa !report.stats_mode && !report.tasks_mode) {
16575cfe2c82SJiri Olsa fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
16585cfe2c82SJiri Olsa stdout);
16595cfe2c82SJiri Olsa }
16605cfe2c82SJiri Olsa
1661ef7b93a1SArnaldo Carvalho de Melo /*
16626692c262SArnaldo Carvalho de Melo * Only in the TUI browser we are doing integrated annotation,
1663ef7b93a1SArnaldo Carvalho de Melo * so don't allocate extra space that won't be used in the stdio
1664ef7b93a1SArnaldo Carvalho de Melo * implementation.
1665ef7b93a1SArnaldo Carvalho de Melo */
16666f7164faSJin Yao if (ui__has_annotation() || report.symbol_ipc ||
16676f7164faSJin Yao report.total_cycles_mode) {
1668b01141f4SArnaldo Carvalho de Melo ret = symbol__annotation_init();
1669b01141f4SArnaldo Carvalho de Melo if (ret < 0)
1670b01141f4SArnaldo Carvalho de Melo goto error;
167180d50caeSArnaldo Carvalho de Melo /*
167280d50caeSArnaldo Carvalho de Melo * For searching by name on the "Browse map details".
167380d50caeSArnaldo Carvalho de Melo * providing it only in verbose mode not to bloat too
167480d50caeSArnaldo Carvalho de Melo * much struct symbol.
167580d50caeSArnaldo Carvalho de Melo */
1676bb963e16SNamhyung Kim if (verbose > 0) {
167780d50caeSArnaldo Carvalho de Melo /*
167880d50caeSArnaldo Carvalho de Melo * XXX: Need to provide a less kludgy way to ask for
167980d50caeSArnaldo Carvalho de Melo * more space per symbol, the u32 is for the index on
168080d50caeSArnaldo Carvalho de Melo * the ui browser.
168180d50caeSArnaldo Carvalho de Melo * See symbol__browser_index.
168280d50caeSArnaldo Carvalho de Melo */
168380d50caeSArnaldo Carvalho de Melo symbol_conf.priv_size += sizeof(u32);
168480d50caeSArnaldo Carvalho de Melo }
1685e0af85d6SNamhyung Kim annotation_config__init(&annotate_opts);
168680d50caeSArnaldo Carvalho de Melo }
1687655000e7SArnaldo Carvalho de Melo
16880a7e6d1bSNamhyung Kim if (symbol__init(&session->header.env) < 0)
1689993ac88dSStephane Eranian goto error;
169086470930SIngo Molnar
1691284c4e18SJin Yao if (report.time_str) {
1692284c4e18SJin Yao ret = perf_time__parse_for_ranges(report.time_str, session,
1693284c4e18SJin Yao &report.ptime_range,
1694284c4e18SJin Yao &report.range_size,
1695284c4e18SJin Yao &report.range_num);
1696284c4e18SJin Yao if (ret < 0)
16970a3cc3aeSJin Yao goto error;
16984885c90cSAdrian Hunter
16994885c90cSAdrian Hunter itrace_synth_opts__set_time_range(&itrace_synth_opts,
17004885c90cSAdrian Hunter report.ptime_range,
17014885c90cSAdrian Hunter report.range_num);
17020a3cc3aeSJin Yao }
17030a3cc3aeSJin Yao
1704378ef0f5SIan Rogers #ifdef HAVE_LIBTRACEEVENT
1705ea85ab24SWang YanQing if (session->tevent.pevent &&
1706ece2a4f4STzvetomir Stoyanov (VMware) tep_set_function_resolver(session->tevent.pevent,
1707ea85ab24SWang YanQing machine__resolve_kernel_addr,
1708ea85ab24SWang YanQing &session->machines.host) < 0) {
1709ea85ab24SWang YanQing pr_err("%s: failed to set libtraceevent function resolver\n",
1710ea85ab24SWang YanQing __func__);
1711ea85ab24SWang YanQing return -1;
1712ea85ab24SWang YanQing }
1713378ef0f5SIan Rogers #endif
171408e71542SNamhyung Kim sort__setup_elide(stdout);
171525903407SArnaldo Carvalho de Melo
1716993ac88dSStephane Eranian ret = __cmd_report(&report);
17175e3b810aSJin Yao if (ret == K_SWITCH_INPUT_DATA || ret == K_RELOAD) {
1718ad0de097SFeng Tang perf_session__delete(session);
17190feba17bSJin Yao last_key = K_SWITCH_INPUT_DATA;
1720ad0de097SFeng Tang goto repeat;
1721ad0de097SFeng Tang } else
1722ad0de097SFeng Tang ret = 0;
1723ad0de097SFeng Tang
1724993ac88dSStephane Eranian error:
17254885c90cSAdrian Hunter if (report.ptime_range) {
17264885c90cSAdrian Hunter itrace_synth_opts__clear_time_range(&itrace_synth_opts);
17270a3cc3aeSJin Yao zfree(&report.ptime_range);
17284885c90cSAdrian Hunter }
17296f7164faSJin Yao
1730cca0cc76SJin Yao if (report.block_reports) {
1731cca0cc76SJin Yao block_info__free_report(report.block_reports,
1732cca0cc76SJin Yao report.nr_block_reports);
1733cca0cc76SJin Yao report.block_reports = NULL;
1734cca0cc76SJin Yao }
17356f7164faSJin Yao
1736cb62c6f1SAlexey Budankov zstd_fini(&(session->zstd_data));
1737993ac88dSStephane Eranian perf_session__delete(session);
1738a37338aaSRiccardo Mancini exit:
1739e0af85d6SNamhyung Kim annotation_options__exit(&annotate_opts);
1740a37338aaSRiccardo Mancini free(sort_order_help);
1741a37338aaSRiccardo Mancini free(field_order_help);
1742993ac88dSStephane Eranian return ret;
174386470930SIngo Molnar }
1744