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