18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * builtin-report.c
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Builtin report command: Analyze the perf.data input file,
68c2ecf20Sopenharmony_ci * look up and read DSOs and symbol information and display
78c2ecf20Sopenharmony_ci * a histogram of results, along various sorting keys.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#include "builtin.h"
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include "util/config.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include "util/annotate.h"
148c2ecf20Sopenharmony_ci#include "util/color.h"
158c2ecf20Sopenharmony_ci#include "util/dso.h"
168c2ecf20Sopenharmony_ci#include <linux/list.h>
178c2ecf20Sopenharmony_ci#include <linux/rbtree.h>
188c2ecf20Sopenharmony_ci#include <linux/err.h>
198c2ecf20Sopenharmony_ci#include <linux/zalloc.h>
208c2ecf20Sopenharmony_ci#include "util/map.h"
218c2ecf20Sopenharmony_ci#include "util/symbol.h"
228c2ecf20Sopenharmony_ci#include "util/map_symbol.h"
238c2ecf20Sopenharmony_ci#include "util/mem-events.h"
248c2ecf20Sopenharmony_ci#include "util/branch.h"
258c2ecf20Sopenharmony_ci#include "util/callchain.h"
268c2ecf20Sopenharmony_ci#include "util/values.h"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#include "perf.h"
298c2ecf20Sopenharmony_ci#include "util/debug.h"
308c2ecf20Sopenharmony_ci#include "util/evlist.h"
318c2ecf20Sopenharmony_ci#include "util/evsel.h"
328c2ecf20Sopenharmony_ci#include "util/evswitch.h"
338c2ecf20Sopenharmony_ci#include "util/header.h"
348c2ecf20Sopenharmony_ci#include "util/session.h"
358c2ecf20Sopenharmony_ci#include "util/srcline.h"
368c2ecf20Sopenharmony_ci#include "util/tool.h"
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <subcmd/parse-options.h>
398c2ecf20Sopenharmony_ci#include <subcmd/exec-cmd.h>
408c2ecf20Sopenharmony_ci#include "util/parse-events.h"
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#include "util/thread.h"
438c2ecf20Sopenharmony_ci#include "util/sort.h"
448c2ecf20Sopenharmony_ci#include "util/hist.h"
458c2ecf20Sopenharmony_ci#include "util/data.h"
468c2ecf20Sopenharmony_ci#include "arch/common.h"
478c2ecf20Sopenharmony_ci#include "util/time-utils.h"
488c2ecf20Sopenharmony_ci#include "util/auxtrace.h"
498c2ecf20Sopenharmony_ci#include "util/units.h"
508c2ecf20Sopenharmony_ci#include "util/util.h" // perf_tip()
518c2ecf20Sopenharmony_ci#include "ui/ui.h"
528c2ecf20Sopenharmony_ci#include "ui/progress.h"
538c2ecf20Sopenharmony_ci#include "util/block-info.h"
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#include <dlfcn.h>
568c2ecf20Sopenharmony_ci#include <errno.h>
578c2ecf20Sopenharmony_ci#include <inttypes.h>
588c2ecf20Sopenharmony_ci#include <regex.h>
598c2ecf20Sopenharmony_ci#include <linux/ctype.h>
608c2ecf20Sopenharmony_ci#include <signal.h>
618c2ecf20Sopenharmony_ci#include <linux/bitmap.h>
628c2ecf20Sopenharmony_ci#include <linux/string.h>
638c2ecf20Sopenharmony_ci#include <linux/stringify.h>
648c2ecf20Sopenharmony_ci#include <linux/time64.h>
658c2ecf20Sopenharmony_ci#include <sys/types.h>
668c2ecf20Sopenharmony_ci#include <sys/stat.h>
678c2ecf20Sopenharmony_ci#include <unistd.h>
688c2ecf20Sopenharmony_ci#include <linux/mman.h>
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistruct report {
718c2ecf20Sopenharmony_ci	struct perf_tool	tool;
728c2ecf20Sopenharmony_ci	struct perf_session	*session;
738c2ecf20Sopenharmony_ci	struct evswitch		evswitch;
748c2ecf20Sopenharmony_ci	bool			use_tui, use_gtk, use_stdio;
758c2ecf20Sopenharmony_ci	bool			show_full_info;
768c2ecf20Sopenharmony_ci	bool			show_threads;
778c2ecf20Sopenharmony_ci	bool			inverted_callchain;
788c2ecf20Sopenharmony_ci	bool			mem_mode;
798c2ecf20Sopenharmony_ci	bool			stats_mode;
808c2ecf20Sopenharmony_ci	bool			tasks_mode;
818c2ecf20Sopenharmony_ci	bool			mmaps_mode;
828c2ecf20Sopenharmony_ci	bool			header;
838c2ecf20Sopenharmony_ci	bool			header_only;
848c2ecf20Sopenharmony_ci	bool			nonany_branch_mode;
858c2ecf20Sopenharmony_ci	bool			group_set;
868c2ecf20Sopenharmony_ci	bool			stitch_lbr;
878c2ecf20Sopenharmony_ci	int			max_stack;
888c2ecf20Sopenharmony_ci	struct perf_read_values	show_threads_values;
898c2ecf20Sopenharmony_ci	struct annotation_options annotation_opts;
908c2ecf20Sopenharmony_ci	const char		*pretty_printing_style;
918c2ecf20Sopenharmony_ci	const char		*cpu_list;
928c2ecf20Sopenharmony_ci	const char		*symbol_filter_str;
938c2ecf20Sopenharmony_ci	const char		*time_str;
948c2ecf20Sopenharmony_ci	struct perf_time_interval *ptime_range;
958c2ecf20Sopenharmony_ci	int			range_size;
968c2ecf20Sopenharmony_ci	int			range_num;
978c2ecf20Sopenharmony_ci	float			min_percent;
988c2ecf20Sopenharmony_ci	u64			nr_entries;
998c2ecf20Sopenharmony_ci	u64			queue_size;
1008c2ecf20Sopenharmony_ci	u64			total_cycles;
1018c2ecf20Sopenharmony_ci	int			socket_filter;
1028c2ecf20Sopenharmony_ci	DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
1038c2ecf20Sopenharmony_ci	struct branch_type_stat	brtype_stat;
1048c2ecf20Sopenharmony_ci	bool			symbol_ipc;
1058c2ecf20Sopenharmony_ci	bool			total_cycles_mode;
1068c2ecf20Sopenharmony_ci	struct block_report	*block_reports;
1078c2ecf20Sopenharmony_ci	int			nr_block_reports;
1088c2ecf20Sopenharmony_ci};
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic int report__config(const char *var, const char *value, void *cb)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	struct report *rep = cb;
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	if (!strcmp(var, "report.group")) {
1158c2ecf20Sopenharmony_ci		symbol_conf.event_group = perf_config_bool(var, value);
1168c2ecf20Sopenharmony_ci		return 0;
1178c2ecf20Sopenharmony_ci	}
1188c2ecf20Sopenharmony_ci	if (!strcmp(var, "report.percent-limit")) {
1198c2ecf20Sopenharmony_ci		double pcnt = strtof(value, NULL);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci		rep->min_percent = pcnt;
1228c2ecf20Sopenharmony_ci		callchain_param.min_percent = pcnt;
1238c2ecf20Sopenharmony_ci		return 0;
1248c2ecf20Sopenharmony_ci	}
1258c2ecf20Sopenharmony_ci	if (!strcmp(var, "report.children")) {
1268c2ecf20Sopenharmony_ci		symbol_conf.cumulate_callchain = perf_config_bool(var, value);
1278c2ecf20Sopenharmony_ci		return 0;
1288c2ecf20Sopenharmony_ci	}
1298c2ecf20Sopenharmony_ci	if (!strcmp(var, "report.queue-size"))
1308c2ecf20Sopenharmony_ci		return perf_config_u64(&rep->queue_size, var, value);
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	if (!strcmp(var, "report.sort_order")) {
1338c2ecf20Sopenharmony_ci		default_sort_order = strdup(value);
1348c2ecf20Sopenharmony_ci		return 0;
1358c2ecf20Sopenharmony_ci	}
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	return 0;
1388c2ecf20Sopenharmony_ci}
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic int hist_iter__report_callback(struct hist_entry_iter *iter,
1418c2ecf20Sopenharmony_ci				      struct addr_location *al, bool single,
1428c2ecf20Sopenharmony_ci				      void *arg)
1438c2ecf20Sopenharmony_ci{
1448c2ecf20Sopenharmony_ci	int err = 0;
1458c2ecf20Sopenharmony_ci	struct report *rep = arg;
1468c2ecf20Sopenharmony_ci	struct hist_entry *he = iter->he;
1478c2ecf20Sopenharmony_ci	struct evsel *evsel = iter->evsel;
1488c2ecf20Sopenharmony_ci	struct perf_sample *sample = iter->sample;
1498c2ecf20Sopenharmony_ci	struct mem_info *mi;
1508c2ecf20Sopenharmony_ci	struct branch_info *bi;
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	if (!ui__has_annotation() && !rep->symbol_ipc)
1538c2ecf20Sopenharmony_ci		return 0;
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	if (sort__mode == SORT_MODE__BRANCH) {
1568c2ecf20Sopenharmony_ci		bi = he->branch_info;
1578c2ecf20Sopenharmony_ci		err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
1588c2ecf20Sopenharmony_ci		if (err)
1598c2ecf20Sopenharmony_ci			goto out;
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci		err = addr_map_symbol__inc_samples(&bi->to, sample, evsel);
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	} else if (rep->mem_mode) {
1648c2ecf20Sopenharmony_ci		mi = he->mem_info;
1658c2ecf20Sopenharmony_ci		err = addr_map_symbol__inc_samples(&mi->daddr, sample, evsel);
1668c2ecf20Sopenharmony_ci		if (err)
1678c2ecf20Sopenharmony_ci			goto out;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci		err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr);
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	} else if (symbol_conf.cumulate_callchain) {
1728c2ecf20Sopenharmony_ci		if (single)
1738c2ecf20Sopenharmony_ci			err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr);
1748c2ecf20Sopenharmony_ci	} else {
1758c2ecf20Sopenharmony_ci		err = hist_entry__inc_addr_samples(he, sample, evsel, al->addr);
1768c2ecf20Sopenharmony_ci	}
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ciout:
1798c2ecf20Sopenharmony_ci	return err;
1808c2ecf20Sopenharmony_ci}
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic int hist_iter__branch_callback(struct hist_entry_iter *iter,
1838c2ecf20Sopenharmony_ci				      struct addr_location *al __maybe_unused,
1848c2ecf20Sopenharmony_ci				      bool single __maybe_unused,
1858c2ecf20Sopenharmony_ci				      void *arg)
1868c2ecf20Sopenharmony_ci{
1878c2ecf20Sopenharmony_ci	struct hist_entry *he = iter->he;
1888c2ecf20Sopenharmony_ci	struct report *rep = arg;
1898c2ecf20Sopenharmony_ci	struct branch_info *bi = he->branch_info;
1908c2ecf20Sopenharmony_ci	struct perf_sample *sample = iter->sample;
1918c2ecf20Sopenharmony_ci	struct evsel *evsel = iter->evsel;
1928c2ecf20Sopenharmony_ci	int err;
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	branch_type_count(&rep->brtype_stat, &bi->flags,
1958c2ecf20Sopenharmony_ci			  bi->from.addr, bi->to.addr);
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	if (!ui__has_annotation() && !rep->symbol_ipc)
1988c2ecf20Sopenharmony_ci		return 0;
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
2018c2ecf20Sopenharmony_ci	if (err)
2028c2ecf20Sopenharmony_ci		goto out;
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	err = addr_map_symbol__inc_samples(&bi->to, sample, evsel);
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ciout:
2078c2ecf20Sopenharmony_ci	return err;
2088c2ecf20Sopenharmony_ci}
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_cistatic void setup_forced_leader(struct report *report,
2118c2ecf20Sopenharmony_ci				struct evlist *evlist)
2128c2ecf20Sopenharmony_ci{
2138c2ecf20Sopenharmony_ci	if (report->group_set)
2148c2ecf20Sopenharmony_ci		perf_evlist__force_leader(evlist);
2158c2ecf20Sopenharmony_ci}
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_cistatic int process_feature_event(struct perf_session *session,
2188c2ecf20Sopenharmony_ci				 union perf_event *event)
2198c2ecf20Sopenharmony_ci{
2208c2ecf20Sopenharmony_ci	struct report *rep = container_of(session->tool, struct report, tool);
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci	if (event->feat.feat_id < HEADER_LAST_FEATURE)
2238c2ecf20Sopenharmony_ci		return perf_event__process_feature(session, event);
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	if (event->feat.feat_id != HEADER_LAST_FEATURE) {
2268c2ecf20Sopenharmony_ci		pr_err("failed: wrong feature ID: %" PRI_lu64 "\n",
2278c2ecf20Sopenharmony_ci		       event->feat.feat_id);
2288c2ecf20Sopenharmony_ci		return -1;
2298c2ecf20Sopenharmony_ci	}
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci	/*
2328c2ecf20Sopenharmony_ci	 * (feat_id = HEADER_LAST_FEATURE) is the end marker which
2338c2ecf20Sopenharmony_ci	 * means all features are received, now we can force the
2348c2ecf20Sopenharmony_ci	 * group if needed.
2358c2ecf20Sopenharmony_ci	 */
2368c2ecf20Sopenharmony_ci	setup_forced_leader(rep, session->evlist);
2378c2ecf20Sopenharmony_ci	return 0;
2388c2ecf20Sopenharmony_ci}
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_cistatic int process_sample_event(struct perf_tool *tool,
2418c2ecf20Sopenharmony_ci				union perf_event *event,
2428c2ecf20Sopenharmony_ci				struct perf_sample *sample,
2438c2ecf20Sopenharmony_ci				struct evsel *evsel,
2448c2ecf20Sopenharmony_ci				struct machine *machine)
2458c2ecf20Sopenharmony_ci{
2468c2ecf20Sopenharmony_ci	struct report *rep = container_of(tool, struct report, tool);
2478c2ecf20Sopenharmony_ci	struct addr_location al;
2488c2ecf20Sopenharmony_ci	struct hist_entry_iter iter = {
2498c2ecf20Sopenharmony_ci		.evsel 			= evsel,
2508c2ecf20Sopenharmony_ci		.sample 		= sample,
2518c2ecf20Sopenharmony_ci		.hide_unresolved 	= symbol_conf.hide_unresolved,
2528c2ecf20Sopenharmony_ci		.add_entry_cb 		= hist_iter__report_callback,
2538c2ecf20Sopenharmony_ci	};
2548c2ecf20Sopenharmony_ci	int ret = 0;
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	if (perf_time__ranges_skip_sample(rep->ptime_range, rep->range_num,
2578c2ecf20Sopenharmony_ci					  sample->time)) {
2588c2ecf20Sopenharmony_ci		return 0;
2598c2ecf20Sopenharmony_ci	}
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	if (evswitch__discard(&rep->evswitch, evsel))
2628c2ecf20Sopenharmony_ci		return 0;
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	if (machine__resolve(machine, &al, sample) < 0) {
2658c2ecf20Sopenharmony_ci		pr_debug("problem processing %d event, skipping it.\n",
2668c2ecf20Sopenharmony_ci			 event->header.type);
2678c2ecf20Sopenharmony_ci		return -1;
2688c2ecf20Sopenharmony_ci	}
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	if (rep->stitch_lbr)
2718c2ecf20Sopenharmony_ci		al.thread->lbr_stitch_enable = true;
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	if (symbol_conf.hide_unresolved && al.sym == NULL)
2748c2ecf20Sopenharmony_ci		goto out_put;
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
2778c2ecf20Sopenharmony_ci		goto out_put;
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	if (sort__mode == SORT_MODE__BRANCH) {
2808c2ecf20Sopenharmony_ci		/*
2818c2ecf20Sopenharmony_ci		 * A non-synthesized event might not have a branch stack if
2828c2ecf20Sopenharmony_ci		 * branch stacks have been synthesized (using itrace options).
2838c2ecf20Sopenharmony_ci		 */
2848c2ecf20Sopenharmony_ci		if (!sample->branch_stack)
2858c2ecf20Sopenharmony_ci			goto out_put;
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci		iter.add_entry_cb = hist_iter__branch_callback;
2888c2ecf20Sopenharmony_ci		iter.ops = &hist_iter_branch;
2898c2ecf20Sopenharmony_ci	} else if (rep->mem_mode) {
2908c2ecf20Sopenharmony_ci		iter.ops = &hist_iter_mem;
2918c2ecf20Sopenharmony_ci	} else if (symbol_conf.cumulate_callchain) {
2928c2ecf20Sopenharmony_ci		iter.ops = &hist_iter_cumulative;
2938c2ecf20Sopenharmony_ci	} else {
2948c2ecf20Sopenharmony_ci		iter.ops = &hist_iter_normal;
2958c2ecf20Sopenharmony_ci	}
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	if (al.map != NULL)
2988c2ecf20Sopenharmony_ci		al.map->dso->hit = 1;
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci	if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) {
3018c2ecf20Sopenharmony_ci		hist__account_cycles(sample->branch_stack, &al, sample,
3028c2ecf20Sopenharmony_ci				     rep->nonany_branch_mode,
3038c2ecf20Sopenharmony_ci				     &rep->total_cycles);
3048c2ecf20Sopenharmony_ci	}
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep);
3078c2ecf20Sopenharmony_ci	if (ret < 0)
3088c2ecf20Sopenharmony_ci		pr_debug("problem adding hist entry, skipping event\n");
3098c2ecf20Sopenharmony_ciout_put:
3108c2ecf20Sopenharmony_ci	addr_location__put(&al);
3118c2ecf20Sopenharmony_ci	return ret;
3128c2ecf20Sopenharmony_ci}
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_cistatic int process_read_event(struct perf_tool *tool,
3158c2ecf20Sopenharmony_ci			      union perf_event *event,
3168c2ecf20Sopenharmony_ci			      struct perf_sample *sample __maybe_unused,
3178c2ecf20Sopenharmony_ci			      struct evsel *evsel,
3188c2ecf20Sopenharmony_ci			      struct machine *machine __maybe_unused)
3198c2ecf20Sopenharmony_ci{
3208c2ecf20Sopenharmony_ci	struct report *rep = container_of(tool, struct report, tool);
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	if (rep->show_threads) {
3238c2ecf20Sopenharmony_ci		const char *name = evsel__name(evsel);
3248c2ecf20Sopenharmony_ci		int err = perf_read_values_add_value(&rep->show_threads_values,
3258c2ecf20Sopenharmony_ci					   event->read.pid, event->read.tid,
3268c2ecf20Sopenharmony_ci					   evsel->idx,
3278c2ecf20Sopenharmony_ci					   name,
3288c2ecf20Sopenharmony_ci					   event->read.value);
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci		if (err)
3318c2ecf20Sopenharmony_ci			return err;
3328c2ecf20Sopenharmony_ci	}
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci	return 0;
3358c2ecf20Sopenharmony_ci}
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci/* For pipe mode, sample_type is not currently set */
3388c2ecf20Sopenharmony_cistatic int report__setup_sample_type(struct report *rep)
3398c2ecf20Sopenharmony_ci{
3408c2ecf20Sopenharmony_ci	struct perf_session *session = rep->session;
3418c2ecf20Sopenharmony_ci	u64 sample_type = evlist__combined_sample_type(session->evlist);
3428c2ecf20Sopenharmony_ci	bool is_pipe = perf_data__is_pipe(session->data);
3438c2ecf20Sopenharmony_ci	struct evsel *evsel;
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	if (session->itrace_synth_opts->callchain ||
3468c2ecf20Sopenharmony_ci	    session->itrace_synth_opts->add_callchain ||
3478c2ecf20Sopenharmony_ci	    (!is_pipe &&
3488c2ecf20Sopenharmony_ci	     perf_header__has_feat(&session->header, HEADER_AUXTRACE) &&
3498c2ecf20Sopenharmony_ci	     !session->itrace_synth_opts->set))
3508c2ecf20Sopenharmony_ci		sample_type |= PERF_SAMPLE_CALLCHAIN;
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	if (session->itrace_synth_opts->last_branch ||
3538c2ecf20Sopenharmony_ci	    session->itrace_synth_opts->add_last_branch)
3548c2ecf20Sopenharmony_ci		sample_type |= PERF_SAMPLE_BRANCH_STACK;
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	if (!is_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) {
3578c2ecf20Sopenharmony_ci		if (perf_hpp_list.parent) {
3588c2ecf20Sopenharmony_ci			ui__error("Selected --sort parent, but no "
3598c2ecf20Sopenharmony_ci				    "callchain data. Did you call "
3608c2ecf20Sopenharmony_ci				    "'perf record' without -g?\n");
3618c2ecf20Sopenharmony_ci			return -EINVAL;
3628c2ecf20Sopenharmony_ci		}
3638c2ecf20Sopenharmony_ci		if (symbol_conf.use_callchain &&
3648c2ecf20Sopenharmony_ci			!symbol_conf.show_branchflag_count) {
3658c2ecf20Sopenharmony_ci			ui__error("Selected -g or --branch-history.\n"
3668c2ecf20Sopenharmony_ci				  "But no callchain or branch data.\n"
3678c2ecf20Sopenharmony_ci				  "Did you call 'perf record' without -g or -b?\n");
3688c2ecf20Sopenharmony_ci			return -1;
3698c2ecf20Sopenharmony_ci		}
3708c2ecf20Sopenharmony_ci	} else if (!callchain_param.enabled &&
3718c2ecf20Sopenharmony_ci		   callchain_param.mode != CHAIN_NONE &&
3728c2ecf20Sopenharmony_ci		   !symbol_conf.use_callchain) {
3738c2ecf20Sopenharmony_ci			symbol_conf.use_callchain = true;
3748c2ecf20Sopenharmony_ci			if (callchain_register_param(&callchain_param) < 0) {
3758c2ecf20Sopenharmony_ci				ui__error("Can't register callchain params.\n");
3768c2ecf20Sopenharmony_ci				return -EINVAL;
3778c2ecf20Sopenharmony_ci			}
3788c2ecf20Sopenharmony_ci	}
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	if (symbol_conf.cumulate_callchain) {
3818c2ecf20Sopenharmony_ci		/* Silently ignore if callchain is missing */
3828c2ecf20Sopenharmony_ci		if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) {
3838c2ecf20Sopenharmony_ci			symbol_conf.cumulate_callchain = false;
3848c2ecf20Sopenharmony_ci			perf_hpp__cancel_cumulate();
3858c2ecf20Sopenharmony_ci		}
3868c2ecf20Sopenharmony_ci	}
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	if (sort__mode == SORT_MODE__BRANCH) {
3898c2ecf20Sopenharmony_ci		if (!is_pipe &&
3908c2ecf20Sopenharmony_ci		    !(sample_type & PERF_SAMPLE_BRANCH_STACK)) {
3918c2ecf20Sopenharmony_ci			ui__error("Selected -b but no branch data. "
3928c2ecf20Sopenharmony_ci				  "Did you call perf record without -b?\n");
3938c2ecf20Sopenharmony_ci			return -1;
3948c2ecf20Sopenharmony_ci		}
3958c2ecf20Sopenharmony_ci	}
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	if (sort__mode == SORT_MODE__MEMORY) {
3988c2ecf20Sopenharmony_ci		/*
3998c2ecf20Sopenharmony_ci		 * FIXUP: prior to kernel 5.18, Arm SPE missed to set
4008c2ecf20Sopenharmony_ci		 * PERF_SAMPLE_DATA_SRC bit in sample type.  For backward
4018c2ecf20Sopenharmony_ci		 * compatibility, set the bit if it's an old perf data file.
4028c2ecf20Sopenharmony_ci		 */
4038c2ecf20Sopenharmony_ci		evlist__for_each_entry(session->evlist, evsel) {
4048c2ecf20Sopenharmony_ci			if (strstr(evsel->name, "arm_spe") &&
4058c2ecf20Sopenharmony_ci				!(sample_type & PERF_SAMPLE_DATA_SRC)) {
4068c2ecf20Sopenharmony_ci				evsel->core.attr.sample_type |= PERF_SAMPLE_DATA_SRC;
4078c2ecf20Sopenharmony_ci				sample_type |= PERF_SAMPLE_DATA_SRC;
4088c2ecf20Sopenharmony_ci			}
4098c2ecf20Sopenharmony_ci		}
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci		if (!is_pipe && !(sample_type & PERF_SAMPLE_DATA_SRC)) {
4128c2ecf20Sopenharmony_ci			ui__error("Selected --mem-mode but no mem data. "
4138c2ecf20Sopenharmony_ci				  "Did you call perf record without -d?\n");
4148c2ecf20Sopenharmony_ci			return -1;
4158c2ecf20Sopenharmony_ci		}
4168c2ecf20Sopenharmony_ci	}
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	callchain_param_setup(sample_type);
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_ci	if (rep->stitch_lbr && (callchain_param.record_mode != CALLCHAIN_LBR)) {
4218c2ecf20Sopenharmony_ci		ui__warning("Can't find LBR callchain. Switch off --stitch-lbr.\n"
4228c2ecf20Sopenharmony_ci			    "Please apply --call-graph lbr when recording.\n");
4238c2ecf20Sopenharmony_ci		rep->stitch_lbr = false;
4248c2ecf20Sopenharmony_ci	}
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci	/* ??? handle more cases than just ANY? */
4278c2ecf20Sopenharmony_ci	if (!(evlist__combined_branch_type(session->evlist) & PERF_SAMPLE_BRANCH_ANY))
4288c2ecf20Sopenharmony_ci		rep->nonany_branch_mode = true;
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci#if !defined(HAVE_LIBUNWIND_SUPPORT) && !defined(HAVE_DWARF_SUPPORT)
4318c2ecf20Sopenharmony_ci	if (dwarf_callchain_users) {
4328c2ecf20Sopenharmony_ci		ui__warning("Please install libunwind or libdw "
4338c2ecf20Sopenharmony_ci			    "development packages during the perf build.\n");
4348c2ecf20Sopenharmony_ci	}
4358c2ecf20Sopenharmony_ci#endif
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci	return 0;
4388c2ecf20Sopenharmony_ci}
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_cistatic void sig_handler(int sig __maybe_unused)
4418c2ecf20Sopenharmony_ci{
4428c2ecf20Sopenharmony_ci	session_done = 1;
4438c2ecf20Sopenharmony_ci}
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_cistatic size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report *rep,
4468c2ecf20Sopenharmony_ci					      const char *evname, FILE *fp)
4478c2ecf20Sopenharmony_ci{
4488c2ecf20Sopenharmony_ci	size_t ret;
4498c2ecf20Sopenharmony_ci	char unit;
4508c2ecf20Sopenharmony_ci	unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
4518c2ecf20Sopenharmony_ci	u64 nr_events = hists->stats.total_period;
4528c2ecf20Sopenharmony_ci	struct evsel *evsel = hists_to_evsel(hists);
4538c2ecf20Sopenharmony_ci	char buf[512];
4548c2ecf20Sopenharmony_ci	size_t size = sizeof(buf);
4558c2ecf20Sopenharmony_ci	int socked_id = hists->socket_filter;
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci	if (quiet)
4588c2ecf20Sopenharmony_ci		return 0;
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	if (symbol_conf.filter_relative) {
4618c2ecf20Sopenharmony_ci		nr_samples = hists->stats.nr_non_filtered_samples;
4628c2ecf20Sopenharmony_ci		nr_events = hists->stats.total_non_filtered_period;
4638c2ecf20Sopenharmony_ci	}
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	if (evsel__is_group_event(evsel)) {
4668c2ecf20Sopenharmony_ci		struct evsel *pos;
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci		evsel__group_desc(evsel, buf, size);
4698c2ecf20Sopenharmony_ci		evname = buf;
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci		for_each_group_member(pos, evsel) {
4728c2ecf20Sopenharmony_ci			const struct hists *pos_hists = evsel__hists(pos);
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci			if (symbol_conf.filter_relative) {
4758c2ecf20Sopenharmony_ci				nr_samples += pos_hists->stats.nr_non_filtered_samples;
4768c2ecf20Sopenharmony_ci				nr_events += pos_hists->stats.total_non_filtered_period;
4778c2ecf20Sopenharmony_ci			} else {
4788c2ecf20Sopenharmony_ci				nr_samples += pos_hists->stats.nr_events[PERF_RECORD_SAMPLE];
4798c2ecf20Sopenharmony_ci				nr_events += pos_hists->stats.total_period;
4808c2ecf20Sopenharmony_ci			}
4818c2ecf20Sopenharmony_ci		}
4828c2ecf20Sopenharmony_ci	}
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_ci	nr_samples = convert_unit(nr_samples, &unit);
4858c2ecf20Sopenharmony_ci	ret = fprintf(fp, "# Samples: %lu%c", nr_samples, unit);
4868c2ecf20Sopenharmony_ci	if (evname != NULL) {
4878c2ecf20Sopenharmony_ci		ret += fprintf(fp, " of event%s '%s'",
4888c2ecf20Sopenharmony_ci			       evsel->core.nr_members > 1 ? "s" : "", evname);
4898c2ecf20Sopenharmony_ci	}
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci	if (rep->time_str)
4928c2ecf20Sopenharmony_ci		ret += fprintf(fp, " (time slices: %s)", rep->time_str);
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci	if (symbol_conf.show_ref_callgraph && evname && strstr(evname, "call-graph=no")) {
4958c2ecf20Sopenharmony_ci		ret += fprintf(fp, ", show reference callgraph");
4968c2ecf20Sopenharmony_ci	}
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci	if (rep->mem_mode) {
4998c2ecf20Sopenharmony_ci		ret += fprintf(fp, "\n# Total weight : %" PRIu64, nr_events);
5008c2ecf20Sopenharmony_ci		ret += fprintf(fp, "\n# Sort order   : %s", sort_order ? : default_mem_sort_order);
5018c2ecf20Sopenharmony_ci	} else
5028c2ecf20Sopenharmony_ci		ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events);
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci	if (socked_id > -1)
5058c2ecf20Sopenharmony_ci		ret += fprintf(fp, "\n# Processor Socket: %d", socked_id);
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci	return ret + fprintf(fp, "\n#\n");
5088c2ecf20Sopenharmony_ci}
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_cistatic int perf_evlist__tui_block_hists_browse(struct evlist *evlist,
5118c2ecf20Sopenharmony_ci					       struct report *rep)
5128c2ecf20Sopenharmony_ci{
5138c2ecf20Sopenharmony_ci	struct evsel *pos;
5148c2ecf20Sopenharmony_ci	int i = 0, ret;
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci	evlist__for_each_entry(evlist, pos) {
5178c2ecf20Sopenharmony_ci		ret = report__browse_block_hists(&rep->block_reports[i++].hist,
5188c2ecf20Sopenharmony_ci						 rep->min_percent, pos,
5198c2ecf20Sopenharmony_ci						 &rep->session->header.env,
5208c2ecf20Sopenharmony_ci						 &rep->annotation_opts);
5218c2ecf20Sopenharmony_ci		if (ret != 0)
5228c2ecf20Sopenharmony_ci			return ret;
5238c2ecf20Sopenharmony_ci	}
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_ci	return 0;
5268c2ecf20Sopenharmony_ci}
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_cistatic int perf_evlist__tty_browse_hists(struct evlist *evlist,
5298c2ecf20Sopenharmony_ci					 struct report *rep,
5308c2ecf20Sopenharmony_ci					 const char *help)
5318c2ecf20Sopenharmony_ci{
5328c2ecf20Sopenharmony_ci	struct evsel *pos;
5338c2ecf20Sopenharmony_ci	int i = 0;
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci	if (!quiet) {
5368c2ecf20Sopenharmony_ci		fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n",
5378c2ecf20Sopenharmony_ci			evlist->stats.total_lost_samples);
5388c2ecf20Sopenharmony_ci	}
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci	evlist__for_each_entry(evlist, pos) {
5418c2ecf20Sopenharmony_ci		struct hists *hists = evsel__hists(pos);
5428c2ecf20Sopenharmony_ci		const char *evname = evsel__name(pos);
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ci		if (symbol_conf.event_group && !evsel__is_group_leader(pos))
5458c2ecf20Sopenharmony_ci			continue;
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci		hists__fprintf_nr_sample_events(hists, rep, evname, stdout);
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_ci		if (rep->total_cycles_mode) {
5508c2ecf20Sopenharmony_ci			report__browse_block_hists(&rep->block_reports[i++].hist,
5518c2ecf20Sopenharmony_ci						   rep->min_percent, pos,
5528c2ecf20Sopenharmony_ci						   NULL, NULL);
5538c2ecf20Sopenharmony_ci			continue;
5548c2ecf20Sopenharmony_ci		}
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci		hists__fprintf(hists, !quiet, 0, 0, rep->min_percent, stdout,
5578c2ecf20Sopenharmony_ci			       !(symbol_conf.use_callchain ||
5588c2ecf20Sopenharmony_ci			         symbol_conf.show_branchflag_count));
5598c2ecf20Sopenharmony_ci		fprintf(stdout, "\n\n");
5608c2ecf20Sopenharmony_ci	}
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_ci	if (!quiet)
5638c2ecf20Sopenharmony_ci		fprintf(stdout, "#\n# (%s)\n#\n", help);
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ci	if (rep->show_threads) {
5668c2ecf20Sopenharmony_ci		bool style = !strcmp(rep->pretty_printing_style, "raw");
5678c2ecf20Sopenharmony_ci		perf_read_values_display(stdout, &rep->show_threads_values,
5688c2ecf20Sopenharmony_ci					 style);
5698c2ecf20Sopenharmony_ci		perf_read_values_destroy(&rep->show_threads_values);
5708c2ecf20Sopenharmony_ci	}
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci	if (sort__mode == SORT_MODE__BRANCH)
5738c2ecf20Sopenharmony_ci		branch_type_stat_display(stdout, &rep->brtype_stat);
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci	return 0;
5768c2ecf20Sopenharmony_ci}
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_cistatic void report__warn_kptr_restrict(const struct report *rep)
5798c2ecf20Sopenharmony_ci{
5808c2ecf20Sopenharmony_ci	struct map *kernel_map = machine__kernel_map(&rep->session->machines.host);
5818c2ecf20Sopenharmony_ci	struct kmap *kernel_kmap = kernel_map ? map__kmap(kernel_map) : NULL;
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci	if (perf_evlist__exclude_kernel(rep->session->evlist))
5848c2ecf20Sopenharmony_ci		return;
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_ci	if (kernel_map == NULL ||
5878c2ecf20Sopenharmony_ci	    (kernel_map->dso->hit &&
5888c2ecf20Sopenharmony_ci	     (kernel_kmap->ref_reloc_sym == NULL ||
5898c2ecf20Sopenharmony_ci	      kernel_kmap->ref_reloc_sym->addr == 0))) {
5908c2ecf20Sopenharmony_ci		const char *desc =
5918c2ecf20Sopenharmony_ci		    "As no suitable kallsyms nor vmlinux was found, kernel samples\n"
5928c2ecf20Sopenharmony_ci		    "can't be resolved.";
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ci		if (kernel_map && map__has_symbols(kernel_map)) {
5958c2ecf20Sopenharmony_ci			desc = "If some relocation was applied (e.g. "
5968c2ecf20Sopenharmony_ci			       "kexec) symbols may be misresolved.";
5978c2ecf20Sopenharmony_ci		}
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci		ui__warning(
6008c2ecf20Sopenharmony_ci"Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n"
6018c2ecf20Sopenharmony_ci"Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n"
6028c2ecf20Sopenharmony_ci"Samples in kernel modules can't be resolved as well.\n\n",
6038c2ecf20Sopenharmony_ci		desc);
6048c2ecf20Sopenharmony_ci	}
6058c2ecf20Sopenharmony_ci}
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_cistatic int report__gtk_browse_hists(struct report *rep, const char *help)
6088c2ecf20Sopenharmony_ci{
6098c2ecf20Sopenharmony_ci	int (*hist_browser)(struct evlist *evlist, const char *help,
6108c2ecf20Sopenharmony_ci			    struct hist_browser_timer *timer, float min_pcnt);
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ci	hist_browser = dlsym(perf_gtk_handle, "perf_evlist__gtk_browse_hists");
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci	if (hist_browser == NULL) {
6158c2ecf20Sopenharmony_ci		ui__error("GTK browser not found!\n");
6168c2ecf20Sopenharmony_ci		return -1;
6178c2ecf20Sopenharmony_ci	}
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ci	return hist_browser(rep->session->evlist, help, NULL, rep->min_percent);
6208c2ecf20Sopenharmony_ci}
6218c2ecf20Sopenharmony_ci
6228c2ecf20Sopenharmony_cistatic int report__browse_hists(struct report *rep)
6238c2ecf20Sopenharmony_ci{
6248c2ecf20Sopenharmony_ci	int ret;
6258c2ecf20Sopenharmony_ci	struct perf_session *session = rep->session;
6268c2ecf20Sopenharmony_ci	struct evlist *evlist = session->evlist;
6278c2ecf20Sopenharmony_ci	char *help = NULL, *path = NULL;
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci	path = system_path(TIPDIR);
6308c2ecf20Sopenharmony_ci	if (perf_tip(&help, path) || help == NULL) {
6318c2ecf20Sopenharmony_ci		/* fallback for people who don't install perf ;-) */
6328c2ecf20Sopenharmony_ci		free(path);
6338c2ecf20Sopenharmony_ci		path = system_path(DOCDIR);
6348c2ecf20Sopenharmony_ci		if (perf_tip(&help, path) || help == NULL)
6358c2ecf20Sopenharmony_ci			help = strdup("Cannot load tips.txt file, please install perf!");
6368c2ecf20Sopenharmony_ci	}
6378c2ecf20Sopenharmony_ci	free(path);
6388c2ecf20Sopenharmony_ci
6398c2ecf20Sopenharmony_ci	switch (use_browser) {
6408c2ecf20Sopenharmony_ci	case 1:
6418c2ecf20Sopenharmony_ci		if (rep->total_cycles_mode) {
6428c2ecf20Sopenharmony_ci			ret = perf_evlist__tui_block_hists_browse(evlist, rep);
6438c2ecf20Sopenharmony_ci			break;
6448c2ecf20Sopenharmony_ci		}
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_ci		ret = perf_evlist__tui_browse_hists(evlist, help, NULL,
6478c2ecf20Sopenharmony_ci						    rep->min_percent,
6488c2ecf20Sopenharmony_ci						    &session->header.env,
6498c2ecf20Sopenharmony_ci						    true, &rep->annotation_opts);
6508c2ecf20Sopenharmony_ci		/*
6518c2ecf20Sopenharmony_ci		 * Usually "ret" is the last pressed key, and we only
6528c2ecf20Sopenharmony_ci		 * care if the key notifies us to switch data file.
6538c2ecf20Sopenharmony_ci		 */
6548c2ecf20Sopenharmony_ci		if (ret != K_SWITCH_INPUT_DATA && ret != K_RELOAD)
6558c2ecf20Sopenharmony_ci			ret = 0;
6568c2ecf20Sopenharmony_ci		break;
6578c2ecf20Sopenharmony_ci	case 2:
6588c2ecf20Sopenharmony_ci		ret = report__gtk_browse_hists(rep, help);
6598c2ecf20Sopenharmony_ci		break;
6608c2ecf20Sopenharmony_ci	default:
6618c2ecf20Sopenharmony_ci		ret = perf_evlist__tty_browse_hists(evlist, rep, help);
6628c2ecf20Sopenharmony_ci		break;
6638c2ecf20Sopenharmony_ci	}
6648c2ecf20Sopenharmony_ci	free(help);
6658c2ecf20Sopenharmony_ci	return ret;
6668c2ecf20Sopenharmony_ci}
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_cistatic int report__collapse_hists(struct report *rep)
6698c2ecf20Sopenharmony_ci{
6708c2ecf20Sopenharmony_ci	struct ui_progress prog;
6718c2ecf20Sopenharmony_ci	struct evsel *pos;
6728c2ecf20Sopenharmony_ci	int ret = 0;
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_ci	ui_progress__init(&prog, rep->nr_entries, "Merging related events...");
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci	evlist__for_each_entry(rep->session->evlist, pos) {
6778c2ecf20Sopenharmony_ci		struct hists *hists = evsel__hists(pos);
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_ci		if (pos->idx == 0)
6808c2ecf20Sopenharmony_ci			hists->symbol_filter_str = rep->symbol_filter_str;
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ci		hists->socket_filter = rep->socket_filter;
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci		ret = hists__collapse_resort(hists, &prog);
6858c2ecf20Sopenharmony_ci		if (ret < 0)
6868c2ecf20Sopenharmony_ci			break;
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_ci		/* Non-group events are considered as leader */
6898c2ecf20Sopenharmony_ci		if (symbol_conf.event_group && !evsel__is_group_leader(pos)) {
6908c2ecf20Sopenharmony_ci			struct hists *leader_hists = evsel__hists(pos->leader);
6918c2ecf20Sopenharmony_ci
6928c2ecf20Sopenharmony_ci			hists__match(leader_hists, hists);
6938c2ecf20Sopenharmony_ci			hists__link(leader_hists, hists);
6948c2ecf20Sopenharmony_ci		}
6958c2ecf20Sopenharmony_ci	}
6968c2ecf20Sopenharmony_ci
6978c2ecf20Sopenharmony_ci	ui_progress__finish();
6988c2ecf20Sopenharmony_ci	return ret;
6998c2ecf20Sopenharmony_ci}
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_cistatic int hists__resort_cb(struct hist_entry *he, void *arg)
7028c2ecf20Sopenharmony_ci{
7038c2ecf20Sopenharmony_ci	struct report *rep = arg;
7048c2ecf20Sopenharmony_ci	struct symbol *sym = he->ms.sym;
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_ci	if (rep->symbol_ipc && sym && !sym->annotate2) {
7078c2ecf20Sopenharmony_ci		struct evsel *evsel = hists_to_evsel(he->hists);
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci		symbol__annotate2(&he->ms, evsel,
7108c2ecf20Sopenharmony_ci				  &annotation__default_options, NULL);
7118c2ecf20Sopenharmony_ci	}
7128c2ecf20Sopenharmony_ci
7138c2ecf20Sopenharmony_ci	return 0;
7148c2ecf20Sopenharmony_ci}
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_cistatic void report__output_resort(struct report *rep)
7178c2ecf20Sopenharmony_ci{
7188c2ecf20Sopenharmony_ci	struct ui_progress prog;
7198c2ecf20Sopenharmony_ci	struct evsel *pos;
7208c2ecf20Sopenharmony_ci
7218c2ecf20Sopenharmony_ci	ui_progress__init(&prog, rep->nr_entries, "Sorting events for output...");
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_ci	evlist__for_each_entry(rep->session->evlist, pos) {
7248c2ecf20Sopenharmony_ci		evsel__output_resort_cb(pos, &prog, hists__resort_cb, rep);
7258c2ecf20Sopenharmony_ci	}
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_ci	ui_progress__finish();
7288c2ecf20Sopenharmony_ci}
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_cistatic void stats_setup(struct report *rep)
7318c2ecf20Sopenharmony_ci{
7328c2ecf20Sopenharmony_ci	memset(&rep->tool, 0, sizeof(rep->tool));
7338c2ecf20Sopenharmony_ci	rep->tool.no_warn = true;
7348c2ecf20Sopenharmony_ci}
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_cistatic int stats_print(struct report *rep)
7378c2ecf20Sopenharmony_ci{
7388c2ecf20Sopenharmony_ci	struct perf_session *session = rep->session;
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci	perf_session__fprintf_nr_events(session, stdout);
7418c2ecf20Sopenharmony_ci	return 0;
7428c2ecf20Sopenharmony_ci}
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_cistatic void tasks_setup(struct report *rep)
7458c2ecf20Sopenharmony_ci{
7468c2ecf20Sopenharmony_ci	memset(&rep->tool, 0, sizeof(rep->tool));
7478c2ecf20Sopenharmony_ci	rep->tool.ordered_events = true;
7488c2ecf20Sopenharmony_ci	if (rep->mmaps_mode) {
7498c2ecf20Sopenharmony_ci		rep->tool.mmap = perf_event__process_mmap;
7508c2ecf20Sopenharmony_ci		rep->tool.mmap2 = perf_event__process_mmap2;
7518c2ecf20Sopenharmony_ci	}
7528c2ecf20Sopenharmony_ci	rep->tool.comm = perf_event__process_comm;
7538c2ecf20Sopenharmony_ci	rep->tool.exit = perf_event__process_exit;
7548c2ecf20Sopenharmony_ci	rep->tool.fork = perf_event__process_fork;
7558c2ecf20Sopenharmony_ci	rep->tool.no_warn = true;
7568c2ecf20Sopenharmony_ci}
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_cistruct task {
7598c2ecf20Sopenharmony_ci	struct thread		*thread;
7608c2ecf20Sopenharmony_ci	struct list_head	 list;
7618c2ecf20Sopenharmony_ci	struct list_head	 children;
7628c2ecf20Sopenharmony_ci};
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_cistatic struct task *tasks_list(struct task *task, struct machine *machine)
7658c2ecf20Sopenharmony_ci{
7668c2ecf20Sopenharmony_ci	struct thread *parent_thread, *thread = task->thread;
7678c2ecf20Sopenharmony_ci	struct task   *parent_task;
7688c2ecf20Sopenharmony_ci
7698c2ecf20Sopenharmony_ci	/* Already listed. */
7708c2ecf20Sopenharmony_ci	if (!list_empty(&task->list))
7718c2ecf20Sopenharmony_ci		return NULL;
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_ci	/* Last one in the chain. */
7748c2ecf20Sopenharmony_ci	if (thread->ppid == -1)
7758c2ecf20Sopenharmony_ci		return task;
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci	parent_thread = machine__find_thread(machine, -1, thread->ppid);
7788c2ecf20Sopenharmony_ci	if (!parent_thread)
7798c2ecf20Sopenharmony_ci		return ERR_PTR(-ENOENT);
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ci	parent_task = thread__priv(parent_thread);
7828c2ecf20Sopenharmony_ci	list_add_tail(&task->list, &parent_task->children);
7838c2ecf20Sopenharmony_ci	return tasks_list(parent_task, machine);
7848c2ecf20Sopenharmony_ci}
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_cistatic size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)
7878c2ecf20Sopenharmony_ci{
7888c2ecf20Sopenharmony_ci	size_t printed = 0;
7898c2ecf20Sopenharmony_ci	struct map *map;
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci	maps__for_each_entry(maps, map) {
7928c2ecf20Sopenharmony_ci		printed += fprintf(fp, "%*s  %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n",
7938c2ecf20Sopenharmony_ci				   indent, "", map->start, map->end,
7948c2ecf20Sopenharmony_ci				   map->prot & PROT_READ ? 'r' : '-',
7958c2ecf20Sopenharmony_ci				   map->prot & PROT_WRITE ? 'w' : '-',
7968c2ecf20Sopenharmony_ci				   map->prot & PROT_EXEC ? 'x' : '-',
7978c2ecf20Sopenharmony_ci				   map->flags & MAP_SHARED ? 's' : 'p',
7988c2ecf20Sopenharmony_ci				   map->pgoff,
7998c2ecf20Sopenharmony_ci				   map->dso->id.ino, map->dso->name);
8008c2ecf20Sopenharmony_ci	}
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ci	return printed;
8038c2ecf20Sopenharmony_ci}
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_cistatic void task__print_level(struct task *task, FILE *fp, int level)
8068c2ecf20Sopenharmony_ci{
8078c2ecf20Sopenharmony_ci	struct thread *thread = task->thread;
8088c2ecf20Sopenharmony_ci	struct task *child;
8098c2ecf20Sopenharmony_ci	int comm_indent = fprintf(fp, "  %8d %8d %8d |%*s",
8108c2ecf20Sopenharmony_ci				  thread->pid_, thread->tid, thread->ppid,
8118c2ecf20Sopenharmony_ci				  level, "");
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci	fprintf(fp, "%s\n", thread__comm_str(thread));
8148c2ecf20Sopenharmony_ci
8158c2ecf20Sopenharmony_ci	maps__fprintf_task(thread->maps, comm_indent, fp);
8168c2ecf20Sopenharmony_ci
8178c2ecf20Sopenharmony_ci	if (!list_empty(&task->children)) {
8188c2ecf20Sopenharmony_ci		list_for_each_entry(child, &task->children, list)
8198c2ecf20Sopenharmony_ci			task__print_level(child, fp, level + 1);
8208c2ecf20Sopenharmony_ci	}
8218c2ecf20Sopenharmony_ci}
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_cistatic int tasks_print(struct report *rep, FILE *fp)
8248c2ecf20Sopenharmony_ci{
8258c2ecf20Sopenharmony_ci	struct perf_session *session = rep->session;
8268c2ecf20Sopenharmony_ci	struct machine      *machine = &session->machines.host;
8278c2ecf20Sopenharmony_ci	struct task *tasks, *task;
8288c2ecf20Sopenharmony_ci	unsigned int nr = 0, itask = 0, i;
8298c2ecf20Sopenharmony_ci	struct rb_node *nd;
8308c2ecf20Sopenharmony_ci	LIST_HEAD(list);
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_ci	/*
8338c2ecf20Sopenharmony_ci	 * No locking needed while accessing machine->threads,
8348c2ecf20Sopenharmony_ci	 * because --tasks is single threaded command.
8358c2ecf20Sopenharmony_ci	 */
8368c2ecf20Sopenharmony_ci
8378c2ecf20Sopenharmony_ci	/* Count all the threads. */
8388c2ecf20Sopenharmony_ci	for (i = 0; i < THREADS__TABLE_SIZE; i++)
8398c2ecf20Sopenharmony_ci		nr += machine->threads[i].nr;
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ci	tasks = malloc(sizeof(*tasks) * nr);
8428c2ecf20Sopenharmony_ci	if (!tasks)
8438c2ecf20Sopenharmony_ci		return -ENOMEM;
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_ci	for (i = 0; i < THREADS__TABLE_SIZE; i++) {
8468c2ecf20Sopenharmony_ci		struct threads *threads = &machine->threads[i];
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_ci		for (nd = rb_first_cached(&threads->entries); nd;
8498c2ecf20Sopenharmony_ci		     nd = rb_next(nd)) {
8508c2ecf20Sopenharmony_ci			task = tasks + itask++;
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_ci			task->thread = rb_entry(nd, struct thread, rb_node);
8538c2ecf20Sopenharmony_ci			INIT_LIST_HEAD(&task->children);
8548c2ecf20Sopenharmony_ci			INIT_LIST_HEAD(&task->list);
8558c2ecf20Sopenharmony_ci			thread__set_priv(task->thread, task);
8568c2ecf20Sopenharmony_ci		}
8578c2ecf20Sopenharmony_ci	}
8588c2ecf20Sopenharmony_ci
8598c2ecf20Sopenharmony_ci	/*
8608c2ecf20Sopenharmony_ci	 * Iterate every task down to the unprocessed parent
8618c2ecf20Sopenharmony_ci	 * and link all in task children list. Task with no
8628c2ecf20Sopenharmony_ci	 * parent is added into 'list'.
8638c2ecf20Sopenharmony_ci	 */
8648c2ecf20Sopenharmony_ci	for (itask = 0; itask < nr; itask++) {
8658c2ecf20Sopenharmony_ci		task = tasks + itask;
8668c2ecf20Sopenharmony_ci
8678c2ecf20Sopenharmony_ci		if (!list_empty(&task->list))
8688c2ecf20Sopenharmony_ci			continue;
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_ci		task = tasks_list(task, machine);
8718c2ecf20Sopenharmony_ci		if (IS_ERR(task)) {
8728c2ecf20Sopenharmony_ci			pr_err("Error: failed to process tasks\n");
8738c2ecf20Sopenharmony_ci			free(tasks);
8748c2ecf20Sopenharmony_ci			return PTR_ERR(task);
8758c2ecf20Sopenharmony_ci		}
8768c2ecf20Sopenharmony_ci
8778c2ecf20Sopenharmony_ci		if (task)
8788c2ecf20Sopenharmony_ci			list_add_tail(&task->list, &list);
8798c2ecf20Sopenharmony_ci	}
8808c2ecf20Sopenharmony_ci
8818c2ecf20Sopenharmony_ci	fprintf(fp, "# %8s %8s %8s  %s\n", "pid", "tid", "ppid", "comm");
8828c2ecf20Sopenharmony_ci
8838c2ecf20Sopenharmony_ci	list_for_each_entry(task, &list, list)
8848c2ecf20Sopenharmony_ci		task__print_level(task, fp, 0);
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_ci	free(tasks);
8878c2ecf20Sopenharmony_ci	return 0;
8888c2ecf20Sopenharmony_ci}
8898c2ecf20Sopenharmony_ci
8908c2ecf20Sopenharmony_cistatic int __cmd_report(struct report *rep)
8918c2ecf20Sopenharmony_ci{
8928c2ecf20Sopenharmony_ci	int ret;
8938c2ecf20Sopenharmony_ci	struct perf_session *session = rep->session;
8948c2ecf20Sopenharmony_ci	struct evsel *pos;
8958c2ecf20Sopenharmony_ci	struct perf_data *data = session->data;
8968c2ecf20Sopenharmony_ci
8978c2ecf20Sopenharmony_ci	signal(SIGINT, sig_handler);
8988c2ecf20Sopenharmony_ci
8998c2ecf20Sopenharmony_ci	if (rep->cpu_list) {
9008c2ecf20Sopenharmony_ci		ret = perf_session__cpu_bitmap(session, rep->cpu_list,
9018c2ecf20Sopenharmony_ci					       rep->cpu_bitmap);
9028c2ecf20Sopenharmony_ci		if (ret) {
9038c2ecf20Sopenharmony_ci			ui__error("failed to set cpu bitmap\n");
9048c2ecf20Sopenharmony_ci			return ret;
9058c2ecf20Sopenharmony_ci		}
9068c2ecf20Sopenharmony_ci		session->itrace_synth_opts->cpu_bitmap = rep->cpu_bitmap;
9078c2ecf20Sopenharmony_ci	}
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_ci	if (rep->show_threads) {
9108c2ecf20Sopenharmony_ci		ret = perf_read_values_init(&rep->show_threads_values);
9118c2ecf20Sopenharmony_ci		if (ret)
9128c2ecf20Sopenharmony_ci			return ret;
9138c2ecf20Sopenharmony_ci	}
9148c2ecf20Sopenharmony_ci
9158c2ecf20Sopenharmony_ci	ret = report__setup_sample_type(rep);
9168c2ecf20Sopenharmony_ci	if (ret) {
9178c2ecf20Sopenharmony_ci		/* report__setup_sample_type() already showed error message */
9188c2ecf20Sopenharmony_ci		return ret;
9198c2ecf20Sopenharmony_ci	}
9208c2ecf20Sopenharmony_ci
9218c2ecf20Sopenharmony_ci	if (rep->stats_mode)
9228c2ecf20Sopenharmony_ci		stats_setup(rep);
9238c2ecf20Sopenharmony_ci
9248c2ecf20Sopenharmony_ci	if (rep->tasks_mode)
9258c2ecf20Sopenharmony_ci		tasks_setup(rep);
9268c2ecf20Sopenharmony_ci
9278c2ecf20Sopenharmony_ci	ret = perf_session__process_events(session);
9288c2ecf20Sopenharmony_ci	if (ret) {
9298c2ecf20Sopenharmony_ci		ui__error("failed to process sample\n");
9308c2ecf20Sopenharmony_ci		return ret;
9318c2ecf20Sopenharmony_ci	}
9328c2ecf20Sopenharmony_ci
9338c2ecf20Sopenharmony_ci	if (rep->stats_mode)
9348c2ecf20Sopenharmony_ci		return stats_print(rep);
9358c2ecf20Sopenharmony_ci
9368c2ecf20Sopenharmony_ci	if (rep->tasks_mode)
9378c2ecf20Sopenharmony_ci		return tasks_print(rep, stdout);
9388c2ecf20Sopenharmony_ci
9398c2ecf20Sopenharmony_ci	report__warn_kptr_restrict(rep);
9408c2ecf20Sopenharmony_ci
9418c2ecf20Sopenharmony_ci	evlist__for_each_entry(session->evlist, pos)
9428c2ecf20Sopenharmony_ci		rep->nr_entries += evsel__hists(pos)->nr_entries;
9438c2ecf20Sopenharmony_ci
9448c2ecf20Sopenharmony_ci	if (use_browser == 0) {
9458c2ecf20Sopenharmony_ci		if (verbose > 3)
9468c2ecf20Sopenharmony_ci			perf_session__fprintf(session, stdout);
9478c2ecf20Sopenharmony_ci
9488c2ecf20Sopenharmony_ci		if (verbose > 2)
9498c2ecf20Sopenharmony_ci			perf_session__fprintf_dsos(session, stdout);
9508c2ecf20Sopenharmony_ci
9518c2ecf20Sopenharmony_ci		if (dump_trace) {
9528c2ecf20Sopenharmony_ci			perf_session__fprintf_nr_events(session, stdout);
9538c2ecf20Sopenharmony_ci			perf_evlist__fprintf_nr_events(session->evlist, stdout);
9548c2ecf20Sopenharmony_ci			return 0;
9558c2ecf20Sopenharmony_ci		}
9568c2ecf20Sopenharmony_ci	}
9578c2ecf20Sopenharmony_ci
9588c2ecf20Sopenharmony_ci	ret = report__collapse_hists(rep);
9598c2ecf20Sopenharmony_ci	if (ret) {
9608c2ecf20Sopenharmony_ci		ui__error("failed to process hist entry\n");
9618c2ecf20Sopenharmony_ci		return ret;
9628c2ecf20Sopenharmony_ci	}
9638c2ecf20Sopenharmony_ci
9648c2ecf20Sopenharmony_ci	if (session_done())
9658c2ecf20Sopenharmony_ci		return 0;
9668c2ecf20Sopenharmony_ci
9678c2ecf20Sopenharmony_ci	/*
9688c2ecf20Sopenharmony_ci	 * recalculate number of entries after collapsing since it
9698c2ecf20Sopenharmony_ci	 * might be changed during the collapse phase.
9708c2ecf20Sopenharmony_ci	 */
9718c2ecf20Sopenharmony_ci	rep->nr_entries = 0;
9728c2ecf20Sopenharmony_ci	evlist__for_each_entry(session->evlist, pos)
9738c2ecf20Sopenharmony_ci		rep->nr_entries += evsel__hists(pos)->nr_entries;
9748c2ecf20Sopenharmony_ci
9758c2ecf20Sopenharmony_ci	if (rep->nr_entries == 0) {
9768c2ecf20Sopenharmony_ci		ui__error("The %s data has no samples!\n", data->path);
9778c2ecf20Sopenharmony_ci		return 0;
9788c2ecf20Sopenharmony_ci	}
9798c2ecf20Sopenharmony_ci
9808c2ecf20Sopenharmony_ci	report__output_resort(rep);
9818c2ecf20Sopenharmony_ci
9828c2ecf20Sopenharmony_ci	if (rep->total_cycles_mode) {
9838c2ecf20Sopenharmony_ci		int block_hpps[6] = {
9848c2ecf20Sopenharmony_ci			PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT,
9858c2ecf20Sopenharmony_ci			PERF_HPP_REPORT__BLOCK_LBR_CYCLES,
9868c2ecf20Sopenharmony_ci			PERF_HPP_REPORT__BLOCK_CYCLES_PCT,
9878c2ecf20Sopenharmony_ci			PERF_HPP_REPORT__BLOCK_AVG_CYCLES,
9888c2ecf20Sopenharmony_ci			PERF_HPP_REPORT__BLOCK_RANGE,
9898c2ecf20Sopenharmony_ci			PERF_HPP_REPORT__BLOCK_DSO,
9908c2ecf20Sopenharmony_ci		};
9918c2ecf20Sopenharmony_ci
9928c2ecf20Sopenharmony_ci		rep->block_reports = block_info__create_report(session->evlist,
9938c2ecf20Sopenharmony_ci							       rep->total_cycles,
9948c2ecf20Sopenharmony_ci							       block_hpps, 6,
9958c2ecf20Sopenharmony_ci							       &rep->nr_block_reports);
9968c2ecf20Sopenharmony_ci		if (!rep->block_reports)
9978c2ecf20Sopenharmony_ci			return -1;
9988c2ecf20Sopenharmony_ci	}
9998c2ecf20Sopenharmony_ci
10008c2ecf20Sopenharmony_ci	return report__browse_hists(rep);
10018c2ecf20Sopenharmony_ci}
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_cistatic int
10048c2ecf20Sopenharmony_cireport_parse_callchain_opt(const struct option *opt, const char *arg, int unset)
10058c2ecf20Sopenharmony_ci{
10068c2ecf20Sopenharmony_ci	struct callchain_param *callchain = opt->value;
10078c2ecf20Sopenharmony_ci
10088c2ecf20Sopenharmony_ci	callchain->enabled = !unset;
10098c2ecf20Sopenharmony_ci	/*
10108c2ecf20Sopenharmony_ci	 * --no-call-graph
10118c2ecf20Sopenharmony_ci	 */
10128c2ecf20Sopenharmony_ci	if (unset) {
10138c2ecf20Sopenharmony_ci		symbol_conf.use_callchain = false;
10148c2ecf20Sopenharmony_ci		callchain->mode = CHAIN_NONE;
10158c2ecf20Sopenharmony_ci		return 0;
10168c2ecf20Sopenharmony_ci	}
10178c2ecf20Sopenharmony_ci
10188c2ecf20Sopenharmony_ci	return parse_callchain_report_opt(arg);
10198c2ecf20Sopenharmony_ci}
10208c2ecf20Sopenharmony_ci
10218c2ecf20Sopenharmony_cistatic int
10228c2ecf20Sopenharmony_ciparse_time_quantum(const struct option *opt, const char *arg,
10238c2ecf20Sopenharmony_ci		   int unset __maybe_unused)
10248c2ecf20Sopenharmony_ci{
10258c2ecf20Sopenharmony_ci	unsigned long *time_q = opt->value;
10268c2ecf20Sopenharmony_ci	char *end;
10278c2ecf20Sopenharmony_ci
10288c2ecf20Sopenharmony_ci	*time_q = strtoul(arg, &end, 0);
10298c2ecf20Sopenharmony_ci	if (end == arg)
10308c2ecf20Sopenharmony_ci		goto parse_err;
10318c2ecf20Sopenharmony_ci	if (*time_q == 0) {
10328c2ecf20Sopenharmony_ci		pr_err("time quantum cannot be 0");
10338c2ecf20Sopenharmony_ci		return -1;
10348c2ecf20Sopenharmony_ci	}
10358c2ecf20Sopenharmony_ci	end = skip_spaces(end);
10368c2ecf20Sopenharmony_ci	if (*end == 0)
10378c2ecf20Sopenharmony_ci		return 0;
10388c2ecf20Sopenharmony_ci	if (!strcmp(end, "s")) {
10398c2ecf20Sopenharmony_ci		*time_q *= NSEC_PER_SEC;
10408c2ecf20Sopenharmony_ci		return 0;
10418c2ecf20Sopenharmony_ci	}
10428c2ecf20Sopenharmony_ci	if (!strcmp(end, "ms")) {
10438c2ecf20Sopenharmony_ci		*time_q *= NSEC_PER_MSEC;
10448c2ecf20Sopenharmony_ci		return 0;
10458c2ecf20Sopenharmony_ci	}
10468c2ecf20Sopenharmony_ci	if (!strcmp(end, "us")) {
10478c2ecf20Sopenharmony_ci		*time_q *= NSEC_PER_USEC;
10488c2ecf20Sopenharmony_ci		return 0;
10498c2ecf20Sopenharmony_ci	}
10508c2ecf20Sopenharmony_ci	if (!strcmp(end, "ns"))
10518c2ecf20Sopenharmony_ci		return 0;
10528c2ecf20Sopenharmony_ciparse_err:
10538c2ecf20Sopenharmony_ci	pr_err("Cannot parse time quantum `%s'\n", arg);
10548c2ecf20Sopenharmony_ci	return -1;
10558c2ecf20Sopenharmony_ci}
10568c2ecf20Sopenharmony_ci
10578c2ecf20Sopenharmony_ciint
10588c2ecf20Sopenharmony_cireport_parse_ignore_callees_opt(const struct option *opt __maybe_unused,
10598c2ecf20Sopenharmony_ci				const char *arg, int unset __maybe_unused)
10608c2ecf20Sopenharmony_ci{
10618c2ecf20Sopenharmony_ci	if (arg) {
10628c2ecf20Sopenharmony_ci		int err = regcomp(&ignore_callees_regex, arg, REG_EXTENDED);
10638c2ecf20Sopenharmony_ci		if (err) {
10648c2ecf20Sopenharmony_ci			char buf[BUFSIZ];
10658c2ecf20Sopenharmony_ci			regerror(err, &ignore_callees_regex, buf, sizeof(buf));
10668c2ecf20Sopenharmony_ci			pr_err("Invalid --ignore-callees regex: %s\n%s", arg, buf);
10678c2ecf20Sopenharmony_ci			return -1;
10688c2ecf20Sopenharmony_ci		}
10698c2ecf20Sopenharmony_ci		have_ignore_callees = 1;
10708c2ecf20Sopenharmony_ci	}
10718c2ecf20Sopenharmony_ci
10728c2ecf20Sopenharmony_ci	return 0;
10738c2ecf20Sopenharmony_ci}
10748c2ecf20Sopenharmony_ci
10758c2ecf20Sopenharmony_cistatic int
10768c2ecf20Sopenharmony_ciparse_branch_mode(const struct option *opt,
10778c2ecf20Sopenharmony_ci		  const char *str __maybe_unused, int unset)
10788c2ecf20Sopenharmony_ci{
10798c2ecf20Sopenharmony_ci	int *branch_mode = opt->value;
10808c2ecf20Sopenharmony_ci
10818c2ecf20Sopenharmony_ci	*branch_mode = !unset;
10828c2ecf20Sopenharmony_ci	return 0;
10838c2ecf20Sopenharmony_ci}
10848c2ecf20Sopenharmony_ci
10858c2ecf20Sopenharmony_cistatic int
10868c2ecf20Sopenharmony_ciparse_percent_limit(const struct option *opt, const char *str,
10878c2ecf20Sopenharmony_ci		    int unset __maybe_unused)
10888c2ecf20Sopenharmony_ci{
10898c2ecf20Sopenharmony_ci	struct report *rep = opt->value;
10908c2ecf20Sopenharmony_ci	double pcnt = strtof(str, NULL);
10918c2ecf20Sopenharmony_ci
10928c2ecf20Sopenharmony_ci	rep->min_percent = pcnt;
10938c2ecf20Sopenharmony_ci	callchain_param.min_percent = pcnt;
10948c2ecf20Sopenharmony_ci	return 0;
10958c2ecf20Sopenharmony_ci}
10968c2ecf20Sopenharmony_ci
10978c2ecf20Sopenharmony_cistatic int process_attr(struct perf_tool *tool __maybe_unused,
10988c2ecf20Sopenharmony_ci			union perf_event *event,
10998c2ecf20Sopenharmony_ci			struct evlist **pevlist)
11008c2ecf20Sopenharmony_ci{
11018c2ecf20Sopenharmony_ci	u64 sample_type;
11028c2ecf20Sopenharmony_ci	int err;
11038c2ecf20Sopenharmony_ci
11048c2ecf20Sopenharmony_ci	err = perf_event__process_attr(tool, event, pevlist);
11058c2ecf20Sopenharmony_ci	if (err)
11068c2ecf20Sopenharmony_ci		return err;
11078c2ecf20Sopenharmony_ci
11088c2ecf20Sopenharmony_ci	/*
11098c2ecf20Sopenharmony_ci	 * Check if we need to enable callchains based
11108c2ecf20Sopenharmony_ci	 * on events sample_type.
11118c2ecf20Sopenharmony_ci	 */
11128c2ecf20Sopenharmony_ci	sample_type = evlist__combined_sample_type(*pevlist);
11138c2ecf20Sopenharmony_ci	callchain_param_setup(sample_type);
11148c2ecf20Sopenharmony_ci	return 0;
11158c2ecf20Sopenharmony_ci}
11168c2ecf20Sopenharmony_ci
11178c2ecf20Sopenharmony_ciint cmd_report(int argc, const char **argv)
11188c2ecf20Sopenharmony_ci{
11198c2ecf20Sopenharmony_ci	struct perf_session *session;
11208c2ecf20Sopenharmony_ci	struct itrace_synth_opts itrace_synth_opts = { .set = 0, };
11218c2ecf20Sopenharmony_ci	struct stat st;
11228c2ecf20Sopenharmony_ci	bool has_br_stack = false;
11238c2ecf20Sopenharmony_ci	int branch_mode = -1;
11248c2ecf20Sopenharmony_ci	int last_key = 0;
11258c2ecf20Sopenharmony_ci	bool branch_call_mode = false;
11268c2ecf20Sopenharmony_ci#define CALLCHAIN_DEFAULT_OPT  "graph,0.5,caller,function,percent"
11278c2ecf20Sopenharmony_ci	static const char report_callchain_help[] = "Display call graph (stack chain/backtrace):\n\n"
11288c2ecf20Sopenharmony_ci						    CALLCHAIN_REPORT_HELP
11298c2ecf20Sopenharmony_ci						    "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT;
11308c2ecf20Sopenharmony_ci	char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT;
11318c2ecf20Sopenharmony_ci	const char * const report_usage[] = {
11328c2ecf20Sopenharmony_ci		"perf report [<options>]",
11338c2ecf20Sopenharmony_ci		NULL
11348c2ecf20Sopenharmony_ci	};
11358c2ecf20Sopenharmony_ci	struct report report = {
11368c2ecf20Sopenharmony_ci		.tool = {
11378c2ecf20Sopenharmony_ci			.sample		 = process_sample_event,
11388c2ecf20Sopenharmony_ci			.mmap		 = perf_event__process_mmap,
11398c2ecf20Sopenharmony_ci			.mmap2		 = perf_event__process_mmap2,
11408c2ecf20Sopenharmony_ci			.comm		 = perf_event__process_comm,
11418c2ecf20Sopenharmony_ci			.namespaces	 = perf_event__process_namespaces,
11428c2ecf20Sopenharmony_ci			.cgroup		 = perf_event__process_cgroup,
11438c2ecf20Sopenharmony_ci			.exit		 = perf_event__process_exit,
11448c2ecf20Sopenharmony_ci			.fork		 = perf_event__process_fork,
11458c2ecf20Sopenharmony_ci			.lost		 = perf_event__process_lost,
11468c2ecf20Sopenharmony_ci			.read		 = process_read_event,
11478c2ecf20Sopenharmony_ci			.attr		 = process_attr,
11488c2ecf20Sopenharmony_ci			.tracing_data	 = perf_event__process_tracing_data,
11498c2ecf20Sopenharmony_ci			.build_id	 = perf_event__process_build_id,
11508c2ecf20Sopenharmony_ci			.id_index	 = perf_event__process_id_index,
11518c2ecf20Sopenharmony_ci			.auxtrace_info	 = perf_event__process_auxtrace_info,
11528c2ecf20Sopenharmony_ci			.auxtrace	 = perf_event__process_auxtrace,
11538c2ecf20Sopenharmony_ci			.event_update	 = perf_event__process_event_update,
11548c2ecf20Sopenharmony_ci			.feature	 = process_feature_event,
11558c2ecf20Sopenharmony_ci			.ordered_events	 = true,
11568c2ecf20Sopenharmony_ci			.ordering_requires_timestamps = true,
11578c2ecf20Sopenharmony_ci		},
11588c2ecf20Sopenharmony_ci		.max_stack		 = PERF_MAX_STACK_DEPTH,
11598c2ecf20Sopenharmony_ci		.pretty_printing_style	 = "normal",
11608c2ecf20Sopenharmony_ci		.socket_filter		 = -1,
11618c2ecf20Sopenharmony_ci		.annotation_opts	 = annotation__default_options,
11628c2ecf20Sopenharmony_ci	};
11638c2ecf20Sopenharmony_ci	char *sort_order_help = sort_help("sort by key(s):");
11648c2ecf20Sopenharmony_ci	char *field_order_help = sort_help("output field(s): overhead period sample ");
11658c2ecf20Sopenharmony_ci	const struct option options[] = {
11668c2ecf20Sopenharmony_ci	OPT_STRING('i', "input", &input_name, "file",
11678c2ecf20Sopenharmony_ci		    "input file name"),
11688c2ecf20Sopenharmony_ci	OPT_INCR('v', "verbose", &verbose,
11698c2ecf20Sopenharmony_ci		    "be more verbose (show symbol address, etc)"),
11708c2ecf20Sopenharmony_ci	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
11718c2ecf20Sopenharmony_ci	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
11728c2ecf20Sopenharmony_ci		    "dump raw trace in ASCII"),
11738c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "stats", &report.stats_mode, "Display event stats"),
11748c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "tasks", &report.tasks_mode, "Display recorded tasks"),
11758c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "mmaps", &report.mmaps_mode, "Display recorded tasks memory maps"),
11768c2ecf20Sopenharmony_ci	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
11778c2ecf20Sopenharmony_ci		   "file", "vmlinux pathname"),
11788c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "ignore-vmlinux", &symbol_conf.ignore_vmlinux,
11798c2ecf20Sopenharmony_ci                    "don't load vmlinux even if found"),
11808c2ecf20Sopenharmony_ci	OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
11818c2ecf20Sopenharmony_ci		   "file", "kallsyms pathname"),
11828c2ecf20Sopenharmony_ci	OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
11838c2ecf20Sopenharmony_ci	OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
11848c2ecf20Sopenharmony_ci		    "load module symbols - WARNING: use only with -k and LIVE kernel"),
11858c2ecf20Sopenharmony_ci	OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
11868c2ecf20Sopenharmony_ci		    "Show a column with the number of samples"),
11878c2ecf20Sopenharmony_ci	OPT_BOOLEAN('T', "threads", &report.show_threads,
11888c2ecf20Sopenharmony_ci		    "Show per-thread event counters"),
11898c2ecf20Sopenharmony_ci	OPT_STRING(0, "pretty", &report.pretty_printing_style, "key",
11908c2ecf20Sopenharmony_ci		   "pretty printing style key: normal raw"),
11918c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "tui", &report.use_tui, "Use the TUI interface"),
11928c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "gtk", &report.use_gtk, "Use the GTK2 interface"),
11938c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "stdio", &report.use_stdio,
11948c2ecf20Sopenharmony_ci		    "Use the stdio interface"),
11958c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "header", &report.header, "Show data header."),
11968c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "header-only", &report.header_only,
11978c2ecf20Sopenharmony_ci		    "Show only data header."),
11988c2ecf20Sopenharmony_ci	OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
11998c2ecf20Sopenharmony_ci		   sort_order_help),
12008c2ecf20Sopenharmony_ci	OPT_STRING('F', "fields", &field_order, "key[,keys...]",
12018c2ecf20Sopenharmony_ci		   field_order_help),
12028c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization,
12038c2ecf20Sopenharmony_ci		    "Show sample percentage for different cpu modes"),
12048c2ecf20Sopenharmony_ci	OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
12058c2ecf20Sopenharmony_ci		    "Show sample percentage for different cpu modes", PARSE_OPT_HIDDEN),
12068c2ecf20Sopenharmony_ci	OPT_STRING('p', "parent", &parent_pattern, "regex",
12078c2ecf20Sopenharmony_ci		   "regex filter to identify parent, see: '--sort parent'"),
12088c2ecf20Sopenharmony_ci	OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
12098c2ecf20Sopenharmony_ci		    "Only display entries with parent-match"),
12108c2ecf20Sopenharmony_ci	OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param,
12118c2ecf20Sopenharmony_ci			     "print_type,threshold[,print_limit],order,sort_key[,branch],value",
12128c2ecf20Sopenharmony_ci			     report_callchain_help, &report_parse_callchain_opt,
12138c2ecf20Sopenharmony_ci			     callchain_default_opt),
12148c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain,
12158c2ecf20Sopenharmony_ci		    "Accumulate callchains of children and show total overhead as well. "
12168c2ecf20Sopenharmony_ci		    "Enabled by default, use --no-children to disable."),
12178c2ecf20Sopenharmony_ci	OPT_INTEGER(0, "max-stack", &report.max_stack,
12188c2ecf20Sopenharmony_ci		    "Set the maximum stack depth when parsing the callchain, "
12198c2ecf20Sopenharmony_ci		    "anything beyond the specified depth will be ignored. "
12208c2ecf20Sopenharmony_ci		    "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
12218c2ecf20Sopenharmony_ci	OPT_BOOLEAN('G', "inverted", &report.inverted_callchain,
12228c2ecf20Sopenharmony_ci		    "alias for inverted call graph"),
12238c2ecf20Sopenharmony_ci	OPT_CALLBACK(0, "ignore-callees", NULL, "regex",
12248c2ecf20Sopenharmony_ci		   "ignore callees of these functions in call graphs",
12258c2ecf20Sopenharmony_ci		   report_parse_ignore_callees_opt),
12268c2ecf20Sopenharmony_ci	OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
12278c2ecf20Sopenharmony_ci		   "only consider symbols in these dsos"),
12288c2ecf20Sopenharmony_ci	OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]",
12298c2ecf20Sopenharmony_ci		   "only consider symbols in these comms"),
12308c2ecf20Sopenharmony_ci	OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]",
12318c2ecf20Sopenharmony_ci		   "only consider symbols in these pids"),
12328c2ecf20Sopenharmony_ci	OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
12338c2ecf20Sopenharmony_ci		   "only consider symbols in these tids"),
12348c2ecf20Sopenharmony_ci	OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
12358c2ecf20Sopenharmony_ci		   "only consider these symbols"),
12368c2ecf20Sopenharmony_ci	OPT_STRING(0, "symbol-filter", &report.symbol_filter_str, "filter",
12378c2ecf20Sopenharmony_ci		   "only show symbols that (partially) match with this filter"),
12388c2ecf20Sopenharmony_ci	OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str,
12398c2ecf20Sopenharmony_ci		   "width[,width...]",
12408c2ecf20Sopenharmony_ci		   "don't try to adjust column width, use these fixed values"),
12418c2ecf20Sopenharmony_ci	OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
12428c2ecf20Sopenharmony_ci		   "separator for columns, no spaces will be added between "
12438c2ecf20Sopenharmony_ci		   "columns '.' is reserved."),
12448c2ecf20Sopenharmony_ci	OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved,
12458c2ecf20Sopenharmony_ci		    "Only display entries resolved to a symbol"),
12468c2ecf20Sopenharmony_ci	OPT_CALLBACK(0, "symfs", NULL, "directory",
12478c2ecf20Sopenharmony_ci		     "Look for files with symbols relative to this directory",
12488c2ecf20Sopenharmony_ci		     symbol__config_symfs),
12498c2ecf20Sopenharmony_ci	OPT_STRING('C', "cpu", &report.cpu_list, "cpu",
12508c2ecf20Sopenharmony_ci		   "list of cpus to profile"),
12518c2ecf20Sopenharmony_ci	OPT_BOOLEAN('I', "show-info", &report.show_full_info,
12528c2ecf20Sopenharmony_ci		    "Display extended information about perf.data file"),
12538c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "source", &report.annotation_opts.annotate_src,
12548c2ecf20Sopenharmony_ci		    "Interleave source code with assembly code (default)"),
12558c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "asm-raw", &report.annotation_opts.show_asm_raw,
12568c2ecf20Sopenharmony_ci		    "Display raw encoding of assembly instructions (default)"),
12578c2ecf20Sopenharmony_ci	OPT_STRING('M', "disassembler-style", &report.annotation_opts.disassembler_style, "disassembler style",
12588c2ecf20Sopenharmony_ci		   "Specify disassembler style (e.g. -M intel for intel syntax)"),
12598c2ecf20Sopenharmony_ci	OPT_STRING(0, "prefix", &report.annotation_opts.prefix, "prefix",
12608c2ecf20Sopenharmony_ci		    "Add prefix to source file path names in programs (with --prefix-strip)"),
12618c2ecf20Sopenharmony_ci	OPT_STRING(0, "prefix-strip", &report.annotation_opts.prefix_strip, "N",
12628c2ecf20Sopenharmony_ci		    "Strip first N entries of source file path name in programs (with --prefix)"),
12638c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
12648c2ecf20Sopenharmony_ci		    "Show a column with the sum of periods"),
12658c2ecf20Sopenharmony_ci	OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &report.group_set,
12668c2ecf20Sopenharmony_ci		    "Show event group information together"),
12678c2ecf20Sopenharmony_ci	OPT_INTEGER(0, "group-sort-idx", &symbol_conf.group_sort_idx,
12688c2ecf20Sopenharmony_ci		    "Sort the output by the event at the index n in group. "
12698c2ecf20Sopenharmony_ci		    "If n is invalid, sort by the first event. "
12708c2ecf20Sopenharmony_ci		    "WARNING: should be used on grouped events."),
12718c2ecf20Sopenharmony_ci	OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "",
12728c2ecf20Sopenharmony_ci		    "use branch records for per branch histogram filling",
12738c2ecf20Sopenharmony_ci		    parse_branch_mode),
12748c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "branch-history", &branch_call_mode,
12758c2ecf20Sopenharmony_ci		    "add last branch records to call history"),
12768c2ecf20Sopenharmony_ci	OPT_STRING(0, "objdump", &report.annotation_opts.objdump_path, "path",
12778c2ecf20Sopenharmony_ci		   "objdump binary to use for disassembly and annotations"),
12788c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
12798c2ecf20Sopenharmony_ci		    "Disable symbol demangling"),
12808c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
12818c2ecf20Sopenharmony_ci		    "Enable kernel symbol demangling"),
12828c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"),
12838c2ecf20Sopenharmony_ci	OPT_INTEGER(0, "samples", &symbol_conf.res_sample,
12848c2ecf20Sopenharmony_ci		    "Number of samples to save per histogram entry for individual browsing"),
12858c2ecf20Sopenharmony_ci	OPT_CALLBACK(0, "percent-limit", &report, "percent",
12868c2ecf20Sopenharmony_ci		     "Don't show entries under that percent", parse_percent_limit),
12878c2ecf20Sopenharmony_ci	OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
12888c2ecf20Sopenharmony_ci		     "how to display percentage of filtered entries", parse_filter_percentage),
12898c2ecf20Sopenharmony_ci	OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
12908c2ecf20Sopenharmony_ci			    "Instruction Tracing options\n" ITRACE_HELP,
12918c2ecf20Sopenharmony_ci			    itrace_parse_synth_opts),
12928c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
12938c2ecf20Sopenharmony_ci			"Show full source file name path for source lines"),
12948c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf.show_ref_callgraph,
12958c2ecf20Sopenharmony_ci		    "Show callgraph from reference event"),
12968c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "stitch-lbr", &report.stitch_lbr,
12978c2ecf20Sopenharmony_ci		    "Enable LBR callgraph stitching approach"),
12988c2ecf20Sopenharmony_ci	OPT_INTEGER(0, "socket-filter", &report.socket_filter,
12998c2ecf20Sopenharmony_ci		    "only show processor socket that match with this filter"),
13008c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace,
13018c2ecf20Sopenharmony_ci		    "Show raw trace event output (do not use print fmt or plugins)"),
13028c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy,
13038c2ecf20Sopenharmony_ci		    "Show entries in a hierarchy"),
13048c2ecf20Sopenharmony_ci	OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
13058c2ecf20Sopenharmony_ci			     "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
13068c2ecf20Sopenharmony_ci			     stdio__config_color, "always"),
13078c2ecf20Sopenharmony_ci	OPT_STRING(0, "time", &report.time_str, "str",
13088c2ecf20Sopenharmony_ci		   "Time span of interest (start,stop)"),
13098c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name,
13108c2ecf20Sopenharmony_ci		    "Show inline function"),
13118c2ecf20Sopenharmony_ci	OPT_CALLBACK(0, "percent-type", &report.annotation_opts, "local-period",
13128c2ecf20Sopenharmony_ci		     "Set percent type local/global-period/hits",
13138c2ecf20Sopenharmony_ci		     annotate_parse_percent_type),
13148c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "ns", &symbol_conf.nanosecs, "Show times in nanosecs"),
13158c2ecf20Sopenharmony_ci	OPT_CALLBACK(0, "time-quantum", &symbol_conf.time_quantum, "time (ms|us|ns|s)",
13168c2ecf20Sopenharmony_ci		     "Set time quantum for time sort key (default 100ms)",
13178c2ecf20Sopenharmony_ci		     parse_time_quantum),
13188c2ecf20Sopenharmony_ci	OPTS_EVSWITCH(&report.evswitch),
13198c2ecf20Sopenharmony_ci	OPT_BOOLEAN(0, "total-cycles", &report.total_cycles_mode,
13208c2ecf20Sopenharmony_ci		    "Sort all blocks by 'Sampled Cycles%'"),
13218c2ecf20Sopenharmony_ci	OPT_END()
13228c2ecf20Sopenharmony_ci	};
13238c2ecf20Sopenharmony_ci	struct perf_data data = {
13248c2ecf20Sopenharmony_ci		.mode  = PERF_DATA_MODE_READ,
13258c2ecf20Sopenharmony_ci	};
13268c2ecf20Sopenharmony_ci	int ret = hists__init();
13278c2ecf20Sopenharmony_ci	char sort_tmp[128];
13288c2ecf20Sopenharmony_ci
13298c2ecf20Sopenharmony_ci	if (ret < 0)
13308c2ecf20Sopenharmony_ci		goto exit;
13318c2ecf20Sopenharmony_ci
13328c2ecf20Sopenharmony_ci	ret = perf_config(report__config, &report);
13338c2ecf20Sopenharmony_ci	if (ret)
13348c2ecf20Sopenharmony_ci		goto exit;
13358c2ecf20Sopenharmony_ci
13368c2ecf20Sopenharmony_ci	argc = parse_options(argc, argv, options, report_usage, 0);
13378c2ecf20Sopenharmony_ci	if (argc) {
13388c2ecf20Sopenharmony_ci		/*
13398c2ecf20Sopenharmony_ci		 * Special case: if there's an argument left then assume that
13408c2ecf20Sopenharmony_ci		 * it's a symbol filter:
13418c2ecf20Sopenharmony_ci		 */
13428c2ecf20Sopenharmony_ci		if (argc > 1)
13438c2ecf20Sopenharmony_ci			usage_with_options(report_usage, options);
13448c2ecf20Sopenharmony_ci
13458c2ecf20Sopenharmony_ci		report.symbol_filter_str = argv[0];
13468c2ecf20Sopenharmony_ci	}
13478c2ecf20Sopenharmony_ci
13488c2ecf20Sopenharmony_ci	if (annotate_check_args(&report.annotation_opts) < 0) {
13498c2ecf20Sopenharmony_ci		ret = -EINVAL;
13508c2ecf20Sopenharmony_ci		goto exit;
13518c2ecf20Sopenharmony_ci	}
13528c2ecf20Sopenharmony_ci
13538c2ecf20Sopenharmony_ci	if (report.mmaps_mode)
13548c2ecf20Sopenharmony_ci		report.tasks_mode = true;
13558c2ecf20Sopenharmony_ci
13568c2ecf20Sopenharmony_ci	if (dump_trace)
13578c2ecf20Sopenharmony_ci		report.tool.ordered_events = false;
13588c2ecf20Sopenharmony_ci
13598c2ecf20Sopenharmony_ci	if (quiet)
13608c2ecf20Sopenharmony_ci		perf_quiet_option();
13618c2ecf20Sopenharmony_ci
13628c2ecf20Sopenharmony_ci	if (symbol_conf.vmlinux_name &&
13638c2ecf20Sopenharmony_ci	    access(symbol_conf.vmlinux_name, R_OK)) {
13648c2ecf20Sopenharmony_ci		pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name);
13658c2ecf20Sopenharmony_ci		ret = -EINVAL;
13668c2ecf20Sopenharmony_ci		goto exit;
13678c2ecf20Sopenharmony_ci	}
13688c2ecf20Sopenharmony_ci	if (symbol_conf.kallsyms_name &&
13698c2ecf20Sopenharmony_ci	    access(symbol_conf.kallsyms_name, R_OK)) {
13708c2ecf20Sopenharmony_ci		pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name);
13718c2ecf20Sopenharmony_ci		ret = -EINVAL;
13728c2ecf20Sopenharmony_ci		goto exit;
13738c2ecf20Sopenharmony_ci	}
13748c2ecf20Sopenharmony_ci
13758c2ecf20Sopenharmony_ci	if (report.inverted_callchain)
13768c2ecf20Sopenharmony_ci		callchain_param.order = ORDER_CALLER;
13778c2ecf20Sopenharmony_ci	if (symbol_conf.cumulate_callchain && !callchain_param.order_set)
13788c2ecf20Sopenharmony_ci		callchain_param.order = ORDER_CALLER;
13798c2ecf20Sopenharmony_ci
13808c2ecf20Sopenharmony_ci	if ((itrace_synth_opts.callchain || itrace_synth_opts.add_callchain) &&
13818c2ecf20Sopenharmony_ci	    (int)itrace_synth_opts.callchain_sz > report.max_stack)
13828c2ecf20Sopenharmony_ci		report.max_stack = itrace_synth_opts.callchain_sz;
13838c2ecf20Sopenharmony_ci
13848c2ecf20Sopenharmony_ci	if (!input_name || !strlen(input_name)) {
13858c2ecf20Sopenharmony_ci		if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))
13868c2ecf20Sopenharmony_ci			input_name = "-";
13878c2ecf20Sopenharmony_ci		else
13888c2ecf20Sopenharmony_ci			input_name = "perf.data";
13898c2ecf20Sopenharmony_ci	}
13908c2ecf20Sopenharmony_ci
13918c2ecf20Sopenharmony_ci	data.path  = input_name;
13928c2ecf20Sopenharmony_ci	data.force = symbol_conf.force;
13938c2ecf20Sopenharmony_ci
13948c2ecf20Sopenharmony_cirepeat:
13958c2ecf20Sopenharmony_ci	session = perf_session__new(&data, false, &report.tool);
13968c2ecf20Sopenharmony_ci	if (IS_ERR(session)) {
13978c2ecf20Sopenharmony_ci		ret = PTR_ERR(session);
13988c2ecf20Sopenharmony_ci		goto exit;
13998c2ecf20Sopenharmony_ci	}
14008c2ecf20Sopenharmony_ci
14018c2ecf20Sopenharmony_ci	ret = evswitch__init(&report.evswitch, session->evlist, stderr);
14028c2ecf20Sopenharmony_ci	if (ret)
14038c2ecf20Sopenharmony_ci		goto exit;
14048c2ecf20Sopenharmony_ci
14058c2ecf20Sopenharmony_ci	if (zstd_init(&(session->zstd_data), 0) < 0)
14068c2ecf20Sopenharmony_ci		pr_warning("Decompression initialization failed. Reported data may be incomplete.\n");
14078c2ecf20Sopenharmony_ci
14088c2ecf20Sopenharmony_ci	if (report.queue_size) {
14098c2ecf20Sopenharmony_ci		ordered_events__set_alloc_size(&session->ordered_events,
14108c2ecf20Sopenharmony_ci					       report.queue_size);
14118c2ecf20Sopenharmony_ci	}
14128c2ecf20Sopenharmony_ci
14138c2ecf20Sopenharmony_ci	session->itrace_synth_opts = &itrace_synth_opts;
14148c2ecf20Sopenharmony_ci
14158c2ecf20Sopenharmony_ci	report.session = session;
14168c2ecf20Sopenharmony_ci
14178c2ecf20Sopenharmony_ci	has_br_stack = perf_header__has_feat(&session->header,
14188c2ecf20Sopenharmony_ci					     HEADER_BRANCH_STACK);
14198c2ecf20Sopenharmony_ci	if (evlist__combined_sample_type(session->evlist) & PERF_SAMPLE_STACK_USER)
14208c2ecf20Sopenharmony_ci		has_br_stack = false;
14218c2ecf20Sopenharmony_ci
14228c2ecf20Sopenharmony_ci	setup_forced_leader(&report, session->evlist);
14238c2ecf20Sopenharmony_ci
14248c2ecf20Sopenharmony_ci	if (symbol_conf.group_sort_idx && !session->evlist->nr_groups) {
14258c2ecf20Sopenharmony_ci		parse_options_usage(NULL, options, "group-sort-idx", 0);
14268c2ecf20Sopenharmony_ci		ret = -EINVAL;
14278c2ecf20Sopenharmony_ci		goto error;
14288c2ecf20Sopenharmony_ci	}
14298c2ecf20Sopenharmony_ci
14308c2ecf20Sopenharmony_ci	if (itrace_synth_opts.last_branch || itrace_synth_opts.add_last_branch)
14318c2ecf20Sopenharmony_ci		has_br_stack = true;
14328c2ecf20Sopenharmony_ci
14338c2ecf20Sopenharmony_ci	if (has_br_stack && branch_call_mode)
14348c2ecf20Sopenharmony_ci		symbol_conf.show_branchflag_count = true;
14358c2ecf20Sopenharmony_ci
14368c2ecf20Sopenharmony_ci	memset(&report.brtype_stat, 0, sizeof(struct branch_type_stat));
14378c2ecf20Sopenharmony_ci
14388c2ecf20Sopenharmony_ci	/*
14398c2ecf20Sopenharmony_ci	 * Branch mode is a tristate:
14408c2ecf20Sopenharmony_ci	 * -1 means default, so decide based on the file having branch data.
14418c2ecf20Sopenharmony_ci	 * 0/1 means the user chose a mode.
14428c2ecf20Sopenharmony_ci	 */
14438c2ecf20Sopenharmony_ci	if (((branch_mode == -1 && has_br_stack) || branch_mode == 1) &&
14448c2ecf20Sopenharmony_ci	    !branch_call_mode) {
14458c2ecf20Sopenharmony_ci		sort__mode = SORT_MODE__BRANCH;
14468c2ecf20Sopenharmony_ci		symbol_conf.cumulate_callchain = false;
14478c2ecf20Sopenharmony_ci	}
14488c2ecf20Sopenharmony_ci	if (branch_call_mode) {
14498c2ecf20Sopenharmony_ci		callchain_param.key = CCKEY_ADDRESS;
14508c2ecf20Sopenharmony_ci		callchain_param.branch_callstack = true;
14518c2ecf20Sopenharmony_ci		symbol_conf.use_callchain = true;
14528c2ecf20Sopenharmony_ci		callchain_register_param(&callchain_param);
14538c2ecf20Sopenharmony_ci		if (sort_order == NULL)
14548c2ecf20Sopenharmony_ci			sort_order = "srcline,symbol,dso";
14558c2ecf20Sopenharmony_ci	}
14568c2ecf20Sopenharmony_ci
14578c2ecf20Sopenharmony_ci	if (report.mem_mode) {
14588c2ecf20Sopenharmony_ci		if (sort__mode == SORT_MODE__BRANCH) {
14598c2ecf20Sopenharmony_ci			pr_err("branch and mem mode incompatible\n");
14608c2ecf20Sopenharmony_ci			goto error;
14618c2ecf20Sopenharmony_ci		}
14628c2ecf20Sopenharmony_ci		sort__mode = SORT_MODE__MEMORY;
14638c2ecf20Sopenharmony_ci		symbol_conf.cumulate_callchain = false;
14648c2ecf20Sopenharmony_ci	}
14658c2ecf20Sopenharmony_ci
14668c2ecf20Sopenharmony_ci	if (symbol_conf.report_hierarchy) {
14678c2ecf20Sopenharmony_ci		/* disable incompatible options */
14688c2ecf20Sopenharmony_ci		symbol_conf.cumulate_callchain = false;
14698c2ecf20Sopenharmony_ci
14708c2ecf20Sopenharmony_ci		if (field_order) {
14718c2ecf20Sopenharmony_ci			pr_err("Error: --hierarchy and --fields options cannot be used together\n");
14728c2ecf20Sopenharmony_ci			parse_options_usage(report_usage, options, "F", 1);
14738c2ecf20Sopenharmony_ci			parse_options_usage(NULL, options, "hierarchy", 0);
14748c2ecf20Sopenharmony_ci			goto error;
14758c2ecf20Sopenharmony_ci		}
14768c2ecf20Sopenharmony_ci
14778c2ecf20Sopenharmony_ci		perf_hpp_list.need_collapse = true;
14788c2ecf20Sopenharmony_ci	}
14798c2ecf20Sopenharmony_ci
14808c2ecf20Sopenharmony_ci	if (report.use_stdio)
14818c2ecf20Sopenharmony_ci		use_browser = 0;
14828c2ecf20Sopenharmony_ci	else if (report.use_tui)
14838c2ecf20Sopenharmony_ci		use_browser = 1;
14848c2ecf20Sopenharmony_ci	else if (report.use_gtk)
14858c2ecf20Sopenharmony_ci		use_browser = 2;
14868c2ecf20Sopenharmony_ci
14878c2ecf20Sopenharmony_ci	/* Force tty output for header output and per-thread stat. */
14888c2ecf20Sopenharmony_ci	if (report.header || report.header_only || report.show_threads)
14898c2ecf20Sopenharmony_ci		use_browser = 0;
14908c2ecf20Sopenharmony_ci	if (report.header || report.header_only)
14918c2ecf20Sopenharmony_ci		report.tool.show_feat_hdr = SHOW_FEAT_HEADER;
14928c2ecf20Sopenharmony_ci	if (report.show_full_info)
14938c2ecf20Sopenharmony_ci		report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO;
14948c2ecf20Sopenharmony_ci	if (report.stats_mode || report.tasks_mode)
14958c2ecf20Sopenharmony_ci		use_browser = 0;
14968c2ecf20Sopenharmony_ci	if (report.stats_mode && report.tasks_mode) {
14978c2ecf20Sopenharmony_ci		pr_err("Error: --tasks and --mmaps can't be used together with --stats\n");
14988c2ecf20Sopenharmony_ci		goto error;
14998c2ecf20Sopenharmony_ci	}
15008c2ecf20Sopenharmony_ci
15018c2ecf20Sopenharmony_ci	if (report.total_cycles_mode) {
15028c2ecf20Sopenharmony_ci		if (sort__mode != SORT_MODE__BRANCH)
15038c2ecf20Sopenharmony_ci			report.total_cycles_mode = false;
15048c2ecf20Sopenharmony_ci		else
15058c2ecf20Sopenharmony_ci			sort_order = NULL;
15068c2ecf20Sopenharmony_ci	}
15078c2ecf20Sopenharmony_ci
15088c2ecf20Sopenharmony_ci	if (strcmp(input_name, "-") != 0)
15098c2ecf20Sopenharmony_ci		setup_browser(true);
15108c2ecf20Sopenharmony_ci	else
15118c2ecf20Sopenharmony_ci		use_browser = 0;
15128c2ecf20Sopenharmony_ci
15138c2ecf20Sopenharmony_ci	if (sort_order && strstr(sort_order, "ipc")) {
15148c2ecf20Sopenharmony_ci		parse_options_usage(report_usage, options, "s", 1);
15158c2ecf20Sopenharmony_ci		goto error;
15168c2ecf20Sopenharmony_ci	}
15178c2ecf20Sopenharmony_ci
15188c2ecf20Sopenharmony_ci	if (sort_order && strstr(sort_order, "symbol")) {
15198c2ecf20Sopenharmony_ci		if (sort__mode == SORT_MODE__BRANCH) {
15208c2ecf20Sopenharmony_ci			snprintf(sort_tmp, sizeof(sort_tmp), "%s,%s",
15218c2ecf20Sopenharmony_ci				 sort_order, "ipc_lbr");
15228c2ecf20Sopenharmony_ci			report.symbol_ipc = true;
15238c2ecf20Sopenharmony_ci		} else {
15248c2ecf20Sopenharmony_ci			snprintf(sort_tmp, sizeof(sort_tmp), "%s,%s",
15258c2ecf20Sopenharmony_ci				 sort_order, "ipc_null");
15268c2ecf20Sopenharmony_ci		}
15278c2ecf20Sopenharmony_ci
15288c2ecf20Sopenharmony_ci		sort_order = sort_tmp;
15298c2ecf20Sopenharmony_ci	}
15308c2ecf20Sopenharmony_ci
15318c2ecf20Sopenharmony_ci	if ((last_key != K_SWITCH_INPUT_DATA && last_key != K_RELOAD) &&
15328c2ecf20Sopenharmony_ci	    (setup_sorting(session->evlist) < 0)) {
15338c2ecf20Sopenharmony_ci		if (sort_order)
15348c2ecf20Sopenharmony_ci			parse_options_usage(report_usage, options, "s", 1);
15358c2ecf20Sopenharmony_ci		if (field_order)
15368c2ecf20Sopenharmony_ci			parse_options_usage(sort_order ? NULL : report_usage,
15378c2ecf20Sopenharmony_ci					    options, "F", 1);
15388c2ecf20Sopenharmony_ci		goto error;
15398c2ecf20Sopenharmony_ci	}
15408c2ecf20Sopenharmony_ci
15418c2ecf20Sopenharmony_ci	if ((report.header || report.header_only) && !quiet) {
15428c2ecf20Sopenharmony_ci		perf_session__fprintf_info(session, stdout,
15438c2ecf20Sopenharmony_ci					   report.show_full_info);
15448c2ecf20Sopenharmony_ci		if (report.header_only) {
15458c2ecf20Sopenharmony_ci			ret = 0;
15468c2ecf20Sopenharmony_ci			goto error;
15478c2ecf20Sopenharmony_ci		}
15488c2ecf20Sopenharmony_ci	} else if (use_browser == 0 && !quiet &&
15498c2ecf20Sopenharmony_ci		   !report.stats_mode && !report.tasks_mode) {
15508c2ecf20Sopenharmony_ci		fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
15518c2ecf20Sopenharmony_ci		      stdout);
15528c2ecf20Sopenharmony_ci	}
15538c2ecf20Sopenharmony_ci
15548c2ecf20Sopenharmony_ci	/*
15558c2ecf20Sopenharmony_ci	 * Only in the TUI browser we are doing integrated annotation,
15568c2ecf20Sopenharmony_ci	 * so don't allocate extra space that won't be used in the stdio
15578c2ecf20Sopenharmony_ci	 * implementation.
15588c2ecf20Sopenharmony_ci	 */
15598c2ecf20Sopenharmony_ci	if (ui__has_annotation() || report.symbol_ipc ||
15608c2ecf20Sopenharmony_ci	    report.total_cycles_mode) {
15618c2ecf20Sopenharmony_ci		ret = symbol__annotation_init();
15628c2ecf20Sopenharmony_ci		if (ret < 0)
15638c2ecf20Sopenharmony_ci			goto error;
15648c2ecf20Sopenharmony_ci		/*
15658c2ecf20Sopenharmony_ci 		 * For searching by name on the "Browse map details".
15668c2ecf20Sopenharmony_ci 		 * providing it only in verbose mode not to bloat too
15678c2ecf20Sopenharmony_ci 		 * much struct symbol.
15688c2ecf20Sopenharmony_ci 		 */
15698c2ecf20Sopenharmony_ci		if (verbose > 0) {
15708c2ecf20Sopenharmony_ci			/*
15718c2ecf20Sopenharmony_ci			 * XXX: Need to provide a less kludgy way to ask for
15728c2ecf20Sopenharmony_ci			 * more space per symbol, the u32 is for the index on
15738c2ecf20Sopenharmony_ci			 * the ui browser.
15748c2ecf20Sopenharmony_ci			 * See symbol__browser_index.
15758c2ecf20Sopenharmony_ci			 */
15768c2ecf20Sopenharmony_ci			symbol_conf.priv_size += sizeof(u32);
15778c2ecf20Sopenharmony_ci			symbol_conf.sort_by_name = true;
15788c2ecf20Sopenharmony_ci		}
15798c2ecf20Sopenharmony_ci		annotation_config__init(&report.annotation_opts);
15808c2ecf20Sopenharmony_ci	}
15818c2ecf20Sopenharmony_ci
15828c2ecf20Sopenharmony_ci	if (symbol__init(&session->header.env) < 0)
15838c2ecf20Sopenharmony_ci		goto error;
15848c2ecf20Sopenharmony_ci
15858c2ecf20Sopenharmony_ci	if (report.time_str) {
15868c2ecf20Sopenharmony_ci		ret = perf_time__parse_for_ranges(report.time_str, session,
15878c2ecf20Sopenharmony_ci						  &report.ptime_range,
15888c2ecf20Sopenharmony_ci						  &report.range_size,
15898c2ecf20Sopenharmony_ci						  &report.range_num);
15908c2ecf20Sopenharmony_ci		if (ret < 0)
15918c2ecf20Sopenharmony_ci			goto error;
15928c2ecf20Sopenharmony_ci
15938c2ecf20Sopenharmony_ci		itrace_synth_opts__set_time_range(&itrace_synth_opts,
15948c2ecf20Sopenharmony_ci						  report.ptime_range,
15958c2ecf20Sopenharmony_ci						  report.range_num);
15968c2ecf20Sopenharmony_ci	}
15978c2ecf20Sopenharmony_ci
15988c2ecf20Sopenharmony_ci	if (session->tevent.pevent &&
15998c2ecf20Sopenharmony_ci	    tep_set_function_resolver(session->tevent.pevent,
16008c2ecf20Sopenharmony_ci				      machine__resolve_kernel_addr,
16018c2ecf20Sopenharmony_ci				      &session->machines.host) < 0) {
16028c2ecf20Sopenharmony_ci		pr_err("%s: failed to set libtraceevent function resolver\n",
16038c2ecf20Sopenharmony_ci		       __func__);
16048c2ecf20Sopenharmony_ci		return -1;
16058c2ecf20Sopenharmony_ci	}
16068c2ecf20Sopenharmony_ci
16078c2ecf20Sopenharmony_ci	sort__setup_elide(stdout);
16088c2ecf20Sopenharmony_ci
16098c2ecf20Sopenharmony_ci	ret = __cmd_report(&report);
16108c2ecf20Sopenharmony_ci	if (ret == K_SWITCH_INPUT_DATA || ret == K_RELOAD) {
16118c2ecf20Sopenharmony_ci		perf_session__delete(session);
16128c2ecf20Sopenharmony_ci		last_key = K_SWITCH_INPUT_DATA;
16138c2ecf20Sopenharmony_ci		goto repeat;
16148c2ecf20Sopenharmony_ci	} else
16158c2ecf20Sopenharmony_ci		ret = 0;
16168c2ecf20Sopenharmony_ci
16178c2ecf20Sopenharmony_cierror:
16188c2ecf20Sopenharmony_ci	if (report.ptime_range) {
16198c2ecf20Sopenharmony_ci		itrace_synth_opts__clear_time_range(&itrace_synth_opts);
16208c2ecf20Sopenharmony_ci		zfree(&report.ptime_range);
16218c2ecf20Sopenharmony_ci	}
16228c2ecf20Sopenharmony_ci
16238c2ecf20Sopenharmony_ci	if (report.block_reports) {
16248c2ecf20Sopenharmony_ci		block_info__free_report(report.block_reports,
16258c2ecf20Sopenharmony_ci					report.nr_block_reports);
16268c2ecf20Sopenharmony_ci		report.block_reports = NULL;
16278c2ecf20Sopenharmony_ci	}
16288c2ecf20Sopenharmony_ci
16298c2ecf20Sopenharmony_ci	zstd_fini(&(session->zstd_data));
16308c2ecf20Sopenharmony_ci	perf_session__delete(session);
16318c2ecf20Sopenharmony_ciexit:
16328c2ecf20Sopenharmony_ci	free(sort_order_help);
16338c2ecf20Sopenharmony_ci	free(field_order_help);
16348c2ecf20Sopenharmony_ci	return ret;
16358c2ecf20Sopenharmony_ci}
1636