// SPDX-License-Identifier: GPL-2.0 /* * builtin-report.c * * Builtin report command: Analyze the perf.data input file, * look up and read DSOs and symbol information and display * a histogram of results, along various sorting keys.
*/ #include"builtin.h"
/* * (feat_id = HEADER_LAST_FEATURE) is the end marker which * means all features are received, now we can force the * group if needed.
*/
setup_forced_leader(rep, session->evlist); return 0;
}
if (rep->stitch_lbr)
thread__set_lbr_stitch_enable(al.thread, true);
if (symbol_conf.hide_unresolved && al.sym == NULL) goto out_put;
if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap)) goto out_put;
if (sort__mode == SORT_MODE__BRANCH) { /* * A non-synthesized event might not have a branch stack if * branch stacks have been synthesized (using itrace options).
*/ if (!sample->branch_stack) goto out_put;
if (session->itrace_synth_opts->last_branch ||
session->itrace_synth_opts->add_last_branch)
sample_type |= PERF_SAMPLE_BRANCH_STACK;
if (!is_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) { if (perf_hpp_list.parent) {
ui__error("Selected --sort parent, but no " "callchain data. Did you call " "'perf record' without -g?\n"); return -EINVAL;
} if (symbol_conf.use_callchain &&
!symbol_conf.show_branchflag_count) {
ui__error("Selected -g or --branch-history.\n" "But no callchain or branch data.\n" "Did you call 'perf record' without -g or -b?\n"); return -1;
}
} elseif (!callchain_param.enabled &&
callchain_param.mode != CHAIN_NONE &&
!symbol_conf.use_callchain) {
symbol_conf.use_callchain = true; if (callchain_register_param(&callchain_param) < 0) {
ui__error("Can't register callchain params.\n"); return -EINVAL;
}
}
if (symbol_conf.cumulate_callchain) { /* Silently ignore if callchain is missing */ if (!(sample_type & PERF_SAMPLE_CALLCHAIN)) {
symbol_conf.cumulate_callchain = false;
perf_hpp__cancel_cumulate(session->evlist);
}
}
if (sort__mode == SORT_MODE__BRANCH) { if (!is_pipe &&
!(sample_type & PERF_SAMPLE_BRANCH_STACK)) {
ui__error("Selected -b but no branch data. " "Did you call perf record without -b?\n"); return -1;
}
}
if (sort__mode == SORT_MODE__MEMORY) { /* * FIXUP: prior to kernel 5.18, Arm SPE missed to set * PERF_SAMPLE_DATA_SRC bit in sample type. For backward * compatibility, set the bit if it's an old perf data file.
*/
evlist__for_each_entry(session->evlist, evsel) { if (strstr(evsel__name(evsel), "arm_spe") &&
!(sample_type & PERF_SAMPLE_DATA_SRC)) {
evsel->core.attr.sample_type |= PERF_SAMPLE_DATA_SRC;
sample_type |= PERF_SAMPLE_DATA_SRC;
}
}
if (!is_pipe && !(sample_type & PERF_SAMPLE_DATA_SRC)) {
ui__error("Selected --mem-mode but no mem data. " "Did you call perf record without -d?\n"); return -1;
}
}
if (rep->stitch_lbr && (callchain_param.record_mode != CALLCHAIN_LBR)) {
ui__warning("Can't find LBR callchain. Switch off --stitch-lbr.\n" "Please apply --call-graph lbr when recording.\n");
rep->stitch_lbr = false;
}
/* ??? handle more cases than just ANY? */ if (!(evlist__combined_branch_type(session->evlist) & PERF_SAMPLE_BRANCH_ANY))
rep->nonany_branch_mode = true;
#if !defined(HAVE_LIBUNWIND_SUPPORT) && !defined(HAVE_LIBDW_SUPPORT) if (dwarf_callchain_users) {
ui__warning("Please install libunwind or libdw " "development packages during the perf build.\n");
} #endif
return 0;
}
staticvoid sig_handler(int sig __maybe_unused)
{
session_done = 1;
}
if (evlist__exclude_kernel(rep->session->evlist)) return;
if (kernel_map == NULL ||
(dso__hit(map__dso(kernel_map)) &&
(kernel_kmap->ref_reloc_sym == NULL ||
kernel_kmap->ref_reloc_sym->addr == 0))) { constchar *desc = "As no suitable kallsyms nor vmlinux was found, kernel samples\n" "can't be resolved.";
if (kernel_map && map__has_symbols(kernel_map)) {
desc = "If some relocation was applied (e.g. " "kexec) symbols may be misresolved.";
}
ui__warning( "Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n" "Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n" "Samples in kernel modules can't be resolved as well.\n\n",
desc);
}
}
path = system_path(TIPDIR); if (perf_tip(&help, path) || help == NULL) { /* fallback for people who don't install perf ;-) */
free(path);
path = system_path(DOCDIR); if (perf_tip(&help, path) || help == NULL)
help = strdup("Cannot load tips.txt file, please install perf!");
}
free(path);
switch (use_browser) { case 1: if (rep->total_cycles_mode) {
ret = evlist__tui_block_hists_browse(evlist, rep); break;
}
ret = evlist__tui_browse_hists(evlist, help, NULL, rep->min_percent,
perf_session__env(session), true); /* * Usually "ret" is the last pressed key, and we only * care if the key notifies us to switch data file.
*/ if (ret != K_SWITCH_INPUT_DATA && ret != K_RELOAD)
ret = 0; break; case 2:
ret = report__gtk_browse_hists(rep, help); break; default:
ret = evlist__tty_browse_hists(evlist, rep, help); break;
}
free(help); return ret;
}
/* * The pipe data needs to setup hierarchy hpp formats now, because it * cannot know about evsels in the data before reading the data. The * normal file data saves the event (attribute) info in the header * section, but pipe does not have the luxury.
*/ if (perf_data__is_pipe(session->data)) { if (perf_hpp__setup_hists_formats(&perf_hpp_list, evlist) < 0) {
ui__error("Failed to setup hierarchy output formats\n"); return -1;
}
}
ui_progress__init(&prog, rep->nr_entries, "Merging related events...");
if (pos->core.idx == 0)
hists->symbol_filter_str = rep->symbol_filter_str;
hists->socket_filter = rep->socket_filter;
ret = hists__collapse_resort(hists, &prog); if (ret < 0) break;
/* Non-group events are considered as leader */ if (symbol_conf.event_group && !evsel__is_group_leader(pos)) { struct hists *leader_hists = evsel__hists(evsel__leader(pos));
/* * Sort two thread list nodes such that they form a tree. The first node is the * root of the tree, its children are ordered numerically after it. If a child * has children itself then they appear immediately after their parent. For * example, the 4 threads in the order they'd appear in the list: * - init with a TID 1 and a parent of 0 * - systemd with a TID 3000 and a parent of init/1 * - systemd child thread with TID 4000, the parent is 3000 * - NetworkManager is a child of init with a TID of 3500.
*/ staticint task_list_cmp(void *priv, conststruct list_head *la, conststruct list_head *lb)
{ struct machine *machine = priv; struct thread_list *task_a = list_entry(la, struct thread_list, list); struct thread_list *task_b = list_entry(lb, struct thread_list, list); struct thread *a = task_a->thread; struct thread *b = task_b->thread; int level_a, level_b, res;
/* Same thread? */ if (thread__tid(a) == thread__tid(b)) return 0;
/* Compare a and b to root. */ if (thread__tid(a) == 0) return -1;
if (thread__tid(b) == 0) return 1;
/* If parents match sort by tid. */ if (thread__ppid(a) == thread__ppid(b)) return thread__tid(a) < thread__tid(b) ? -1 : 1;
/* * Find a and b such that if they are a child of each other a and b's * tid's match, otherwise a and b have a common parent and distinct * tid's to sort by. First make the depths of the threads match.
*/
level_a = thread_level(machine, a);
level_b = thread_level(machine, b);
a = thread__get(a);
b = thread__get(b); for (int i = level_a; i > level_b; i--) { struct thread *parent = machine__find_thread(machine, -1, thread__ppid(a));
thread__put(a); if (!parent) {
pr_err("Missing parent thread of %d\n", thread__tid(a));
thread__put(b); return -1;
}
a = parent;
} for (int i = level_b; i > level_a; i--) { struct thread *parent = machine__find_thread(machine, -1, thread__ppid(b));
thread__put(b); if (!parent) {
pr_err("Missing parent thread of %d\n", thread__tid(b));
thread__put(a); return 1;
}
b = parent;
} /* Search up to a common parent. */ while (thread__ppid(a) != thread__ppid(b)) { struct thread *parent;
parent = machine__find_thread(machine, -1, thread__ppid(a));
thread__put(a); if (!parent)
pr_err("Missing parent thread of %d\n", thread__tid(a));
a = parent;
parent = machine__find_thread(machine, -1, thread__ppid(b));
thread__put(b); if (!parent)
pr_err("Missing parent thread of %d\n", thread__tid(b));
b = parent; if (!a || !b) { /* Handle missing parent (unexpected) with some sanity. */
thread__put(a);
thread__put(b); return !a && !b ? 0 : (!a ? -1 : 1);
}
} if (thread__tid(a) == thread__tid(b)) { /* a is a child of b or vice-versa, deeper levels appear later. */
res = level_a < level_b ? -1 : (level_a > level_b ? 1 : 0);
} else { /* Sort by tid now the parent is the same. */
res = thread__tid(a) < thread__tid(b) ? -1 : 1;
}
thread__put(a);
thread__put(b); return res;
}
if (rep->cpu_list) {
ret = perf_session__cpu_bitmap(session, rep->cpu_list,
rep->cpu_bitmap); if (ret) {
ui__error("failed to set cpu bitmap\n"); return ret;
}
session->itrace_synth_opts->cpu_bitmap = rep->cpu_bitmap;
}
if (rep->show_threads) {
ret = perf_read_values_init(&rep->show_threads_values); if (ret) return ret;
}
ret = report__setup_sample_type(rep); if (ret) { /* report__setup_sample_type() already showed error message */ return ret;
}
if (rep->stats_mode)
stats_setup(rep);
if (rep->tasks_mode)
tasks_setup(rep);
ret = perf_session__process_events(session); if (ret) {
ui__error("failed to process sample\n"); return ret;
}
/* Don't show Latency column for non-parallel profiles by default. */ if (!symbol_conf.prefer_latency && rep->total_samples &&
rep->singlethreaded_samples * 100 / rep->total_samples >= 99)
perf_hpp__cancel_latency(session->evlist);
evlist__check_mem_load_aux(session->evlist);
if (rep->stats_mode) return stats_print(rep);
if (rep->tasks_mode) return tasks_print(rep, stdout);
if (use_browser == 0) { if (verbose > 3)
perf_session__fprintf(session, stdout);
if (verbose > 2)
perf_session__fprintf_dsos(session, stdout);
if (dump_trace) {
stats_print(rep); return 0;
}
}
ret = report__collapse_hists(rep); if (ret) {
ui__error("failed to process hist entry\n"); return ret;
}
if (session_done()) return 0;
/* * recalculate number of entries after collapsing since it * might be changed during the collapse phase.
*/
rep->nr_entries = 0;
evlist__for_each_entry(session->evlist, pos)
rep->nr_entries += evsel__hists(pos)->nr_entries;
if (rep->nr_entries == 0) {
ui__error("The %s data has no samples!\n", data->path); return 0;
}
report__output_resort(rep);
if (rep->total_cycles_mode) { int nr_hpps = 4; int block_hpps[PERF_HPP_REPORT__BLOCK_MAX_INDEX] = {
PERF_HPP_REPORT__BLOCK_TOTAL_CYCLES_PCT,
PERF_HPP_REPORT__BLOCK_LBR_CYCLES,
PERF_HPP_REPORT__BLOCK_CYCLES_PCT,
PERF_HPP_REPORT__BLOCK_AVG_CYCLES,
};
if (session->evlist->nr_br_cntr > 0)
block_hpps[nr_hpps++] = PERF_HPP_REPORT__BLOCK_BRANCH_COUNTER;
err = perf_event__process_attr(tool, event, pevlist); if (err) return err;
/* * Check if we need to enable callchains based * on events sample_type.
*/
sample_type = evlist__combined_sample_type(*pevlist);
session = (*pevlist)->session;
env = perf_session__env(session);
callchain_param_setup(sample_type, perf_env__arch(env)); return 0;
}
int cmd_report(int argc, constchar **argv)
{ struct perf_session *session; struct itrace_synth_opts itrace_synth_opts = { .set = 0, }; struct stat st; bool has_br_stack = false; int branch_mode = -1; int last_key = 0; bool branch_call_mode = false; #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent" staticconstchar report_callchain_help[] = "Display call graph (stack chain/backtrace):\n\n"
CALLCHAIN_REPORT_HELP "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT; char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT; constchar * const report_usage[] = { "perf report []",
NULL
}; struct report report = {
.max_stack = PERF_MAX_STACK_DEPTH,
.pretty_printing_style = "normal",
.socket_filter = -1,
.skip_empty = true,
}; char *sort_order_help = sort_help("sort by key(s):", SORT_MODE__NORMAL); char *field_order_help = sort_help("output field(s):", SORT_MODE__NORMAL); constchar *disassembler_style = NULL, *objdump_path = NULL, *addr2line_path = NULL; conststruct option options[] = {
OPT_STRING('i', "input", &input_name, "file", "input file name"),
OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"),
OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any warnings or messages"),
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"),
OPT_BOOLEAN(0, "stats", &report.stats_mode, "Display event stats"),
OPT_BOOLEAN(0, "tasks", &report.tasks_mode, "Display recorded tasks"),
OPT_BOOLEAN(0, "mmaps", &report.mmaps_mode, "Display recorded tasks memory maps"),
OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, "file", "vmlinux pathname"),
OPT_BOOLEAN(0, "ignore-vmlinux", &symbol_conf.ignore_vmlinux, "don't load vmlinux even if found"),
OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file", "kallsyms pathname"),
OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, "load module symbols - WARNING: use only with -k and LIVE kernel"),
OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples, "Show a column with the number of samples"),
OPT_BOOLEAN('T', "threads", &report.show_threads, "Show per-thread event counters"),
OPT_STRING(0, "pretty", &report.pretty_printing_style, "key", "pretty printing style key: normal raw"), #ifdef HAVE_SLANG_SUPPORT
OPT_BOOLEAN(0, "tui", &report.use_tui, "Use the TUI interface"), #endif #ifdef HAVE_GTK2_SUPPORT
OPT_BOOLEAN(0, "gtk", &report.use_gtk, "Use the GTK2 interface"), #endif
OPT_BOOLEAN(0, "stdio", &report.use_stdio, "Use the stdio interface"),
OPT_BOOLEAN(0, "header", &report.header, "Show data header."),
OPT_BOOLEAN(0, "header-only", &report.header_only, "Show only data header."),
OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
sort_order_help),
OPT_STRING('F', "fields", &field_order, "key[,keys...]",
field_order_help),
OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization, "Show sample percentage for different cpu modes"),
OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization, "Show sample percentage for different cpu modes", PARSE_OPT_HIDDEN),
OPT_STRING('p', "parent", &parent_pattern, "regex", "regex filter to identify parent, see: '--sort parent'"),
OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other, "Only display entries with parent-match"),
OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param, "print_type,threshold[,print_limit],order,sort_key[,branch],value",
report_callchain_help, &report_parse_callchain_opt,
callchain_default_opt),
OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain, "Accumulate callchains of children and show total overhead as well. " "Enabled by default, use --no-children to disable."),
OPT_INTEGER(0, "max-stack", &report.max_stack, "Set the maximum stack depth when parsing the callchain, " "anything beyond the specified depth will be ignored. " "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
OPT_BOOLEAN('G', "inverted", &report.inverted_callchain, "alias for inverted call graph"),
OPT_CALLBACK(0, "ignore-callees", NULL, "regex", "ignore callees of these functions in call graphs",
report_parse_ignore_callees_opt),
OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", "only consider symbols in these dsos"),
OPT_STRING('c', "comms", &symbol_conf.comm_list_str, "comm[,comm...]", "only consider symbols in these comms"),
OPT_STRING(0, "pid", &symbol_conf.pid_list_str, "pid[,pid...]", "only consider symbols in these pids"),
OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]", "only consider symbols in these tids"),
OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]", "only consider these symbols"),
OPT_STRING(0, "symbol-filter", &report.symbol_filter_str, "filter", "only show symbols that (partially) match with this filter"),
OPT_STRING('w', "column-widths", &symbol_conf.col_width_list_str, "width[,width...]", "don't try to adjust column width, use these fixed values"),
OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator", "separator for columns, no spaces will be added between " "columns '.' is reserved."),
OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved, "Only display entries resolved to a symbol"),
OPT_CALLBACK(0, "symfs", NULL, "directory", "Look for files with symbols relative to this directory",
symbol__config_symfs),
OPT_STRING('C', "cpu", &report.cpu_list, "cpu", "list of cpus to profile"),
OPT_STRING(0, "parallelism", &symbol_conf.parallelism_list_str, "parallelism", "only consider these parallelism levels (cpu set format)"),
OPT_BOOLEAN('I', "show-info", &report.show_full_info, "Display extended information about perf.data file"),
OPT_BOOLEAN(0, "source", &annotate_opts.annotate_src, "Interleave source code with assembly code (default)"),
OPT_BOOLEAN(0, "asm-raw", &annotate_opts.show_asm_raw, "Display raw encoding of assembly instructions (default)"),
OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style", "Specify disassembler style (e.g. -M intel for intel syntax)"),
OPT_STRING(0, "prefix", &annotate_opts.prefix, "prefix", "Add prefix to source file path names in programs (with --prefix-strip)"),
OPT_STRING(0, "prefix-strip", &annotate_opts.prefix_strip, "N", "Strip first N entries of source file path name in programs (with --prefix)"),
OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period, "Show a column with the sum of periods"),
OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &report.group_set, "Show event group information together"),
OPT_INTEGER(0, "group-sort-idx", &symbol_conf.group_sort_idx, "Sort the output by the event at the index n in group. " "If n is invalid, sort by the first event. " "WARNING: should be used on grouped events."),
OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "", "use branch records for per branch histogram filling",
parse_branch_mode),
OPT_BOOLEAN(0, "branch-history", &branch_call_mode, "add last branch records to call history"),
OPT_STRING(0, "objdump", &objdump_path, "path", "objdump binary to use for disassembly and annotations"),
OPT_STRING(0, "addr2line", &addr2line_path, "path", "addr2line binary to use for line numbers"),
OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle, "Symbol demangling. Enabled by default, use --no-demangle to disable."),
OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, "Enable kernel symbol demangling"),
OPT_BOOLEAN(0, "mem-mode", &report.mem_mode, "mem access profile"),
OPT_INTEGER(0, "samples", &symbol_conf.res_sample, "Number of samples to save per histogram entry for individual browsing"),
OPT_CALLBACK(0, "percent-limit", &report, "percent", "Don't show entries under that percent", parse_percent_limit),
OPT_CALLBACK(0, "percentage", NULL, "relative|absolute", "how to display percentage of filtered entries", parse_filter_percentage),
OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts", "Instruction Tracing options\n" ITRACE_HELP,
itrace_parse_synth_opts),
OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename, "Show full source file name path for source lines"),
OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf.show_ref_callgraph, "Show callgraph from reference event"),
OPT_BOOLEAN(0, "stitch-lbr", &report.stitch_lbr, "Enable LBR callgraph stitching approach"),
OPT_INTEGER(0, "socket-filter", &report.socket_filter, "only show processor socket that match with this filter"),
OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace, "Show raw trace event output (do not use print fmt or plugins)"),
OPT_BOOLEAN('H', "hierarchy", &symbol_conf.report_hierarchy, "Show entries in a hierarchy"),
OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode", "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
stdio__config_color, "always"),
OPT_STRING(0, "time", &report.time_str, "str", "Time span of interest (start,stop)"),
OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name, "Show inline function"),
OPT_CALLBACK(0, "percent-type", &annotate_opts, "local-period", "Set percent type local/global-period/hits",
annotate_parse_percent_type),
OPT_BOOLEAN(0, "ns", &symbol_conf.nanosecs, "Show times in nanosecs"),
OPT_CALLBACK(0, "time-quantum", &symbol_conf.time_quantum, "time (ms|us|ns|s)", "Set time quantum for time sort key (default 100ms)",
parse_time_quantum),
OPTS_EVSWITCH(&report.evswitch),
OPT_BOOLEAN(0, "total-cycles", &report.total_cycles_mode, "Sort all blocks by 'Sampled Cycles%'"),
OPT_BOOLEAN(0, "disable-order", &report.disable_order, "Disable raw trace ordering"),
OPT_BOOLEAN(0, "skip-empty", &report.skip_empty, "Do not display empty (or dummy) events in the output"),
OPT_BOOLEAN(0, "latency", &symbol_conf.prefer_latency, "Show latency-centric profile rather than the default\n" "\t\t\t CPU-consumption-centric profile\n" "\t\t\t (requires perf record --latency flag)."),
OPT_END()
}; struct perf_data data = {
.mode = PERF_DATA_MODE_READ,
}; int ret = hists__init(); char sort_tmp[128]; bool ordered_events = true;
if (ret < 0) gotoexit;
/* * tasks_mode require access to exited threads to list those that are in * the data file. Off-cpu events are synthesized after other events and * reference exited threads.
*/
symbol_conf.keep_exited_threads = true;
annotation_options__init();
ret = perf_config(report__config, &report); if (ret) gotoexit;
argc = parse_options(argc, argv, options, report_usage, 0); if (argc) { /* * Special case: if there's an argument left then assume that * it's a symbol filter:
*/ if (argc > 1)
usage_with_options(report_usage, options);
report.symbol_filter_str = argv[0];
}
if (disassembler_style) {
annotate_opts.disassembler_style = strdup(disassembler_style); if (!annotate_opts.disassembler_style) return -ENOMEM;
} if (objdump_path) {
annotate_opts.objdump_path = strdup(objdump_path); if (!annotate_opts.objdump_path) return -ENOMEM;
} if (addr2line_path) {
symbol_conf.addr2line_path = strdup(addr2line_path); if (!symbol_conf.addr2line_path) return -ENOMEM;
}
if (annotate_check_args() < 0) {
ret = -EINVAL; gotoexit;
}
if (report.mmaps_mode)
report.tasks_mode = true;
if (dump_trace && report.disable_order)
ordered_events = false;
if (quiet)
perf_quiet_option();
ret = symbol__validate_sym_arguments(); if (ret) gotoexit;
if (report.inverted_callchain)
callchain_param.order = ORDER_CALLER; if (symbol_conf.cumulate_callchain && !callchain_param.order_set)
callchain_param.order = ORDER_CALLER;
/* * Branch mode is a tristate: * -1 means default, so decide based on the file having branch data. * 0/1 means the user chose a mode.
*/ if (((branch_mode == -1 && has_br_stack) || branch_mode == 1) &&
!branch_call_mode) {
sort__mode = SORT_MODE__BRANCH;
symbol_conf.cumulate_callchain = false;
} if (branch_call_mode) {
callchain_param.key = CCKEY_ADDRESS;
callchain_param.branch_callstack = true;
symbol_conf.use_callchain = true;
callchain_register_param(&callchain_param); if (sort_order == NULL)
sort_order = CALLCHAIN_BRANCH_SORT_ORDER;
}
if (report.mem_mode) { if (sort__mode == SORT_MODE__BRANCH) {
pr_err("branch and mem mode incompatible\n"); goto error;
}
sort__mode = SORT_MODE__MEMORY;
symbol_conf.cumulate_callchain = false;
}
if (symbol_conf.report_hierarchy) { /* * The hist entries in hierarchy are added during the collpase * phase. Let's enable it even if no sort keys require it.
*/
perf_hpp_list.need_collapse = true;
}
/* Force tty output for header output and per-thread stat. */ if (report.header || report.header_only || report.show_threads)
use_browser = 0; if (report.header || report.header_only)
report.tool.show_feat_hdr = SHOW_FEAT_HEADER; if (report.show_full_info)
report.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO; if (report.stats_mode || report.tasks_mode)
use_browser = 0; if (report.stats_mode && report.tasks_mode) {
pr_err("Error: --tasks and --mmaps can't be used together with --stats\n"); goto error;
}
if (report.total_cycles_mode) { if (sort__mode != SORT_MODE__BRANCH)
report.total_cycles_mode = false; else
sort_order = NULL;
}
symbol_conf.enable_latency = true; if (report.disable_order || !perf_session__has_switch_events(session)) { if (symbol_conf.parallelism_list_str ||
symbol_conf.prefer_latency ||
(sort_order && (strstr(sort_order, "latency") ||
strstr(sort_order, "parallelism"))) ||
(field_order && (strstr(field_order, "latency") ||
strstr(field_order, "parallelism")))) { if (report.disable_order)
ui__error("Use of latency profile or parallelism is incompatible with --disable-order.\n"); else
ui__error("Use of latency profile or parallelism requires --latency flag during record.\n"); return -1;
} /* * If user did not ask for anything related to * latency/parallelism explicitly, just don't show it.
*/
symbol_conf.enable_latency = false;
}
if (last_key != K_SWITCH_INPUT_DATA) { if (sort_order && strstr(sort_order, "ipc")) {
parse_options_usage(report_usage, options, "s", 1); goto error;
}
if ((report.header || report.header_only) && !quiet) {
perf_session__fprintf_info(session, stdout,
report.show_full_info); if (report.header_only) { if (data.is_pipe) { /* * we need to process first few records * which contains PERF_RECORD_HEADER_FEATURE.
*/
perf_session__process_events(session);
}
ret = 0; goto error;
}
} elseif (use_browser == 0 && !quiet &&
!report.stats_mode && !report.tasks_mode) {
fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
stdout);
}
/* * Only in the TUI browser we are doing integrated annotation, * so don't allocate extra space that won't be used in the stdio * implementation.
*/ if (ui__has_annotation() || report.symbol_ipc || report.data_type ||
report.total_cycles_mode) {
ret = symbol__annotation_init(); if (ret < 0) goto error; /* * For searching by name on the "Browse map details". * providing it only in verbose mode not to bloat too * much struct symbol.
*/ if (verbose > 0) { /* * XXX: Need to provide a less kludgy way to ask for * more space per symbol, the u32 is for the index on * the ui browser. * See symbol__browser_index.
*/
symbol_conf.priv_size += sizeof(u32);
}
annotation_config__init();
}
if (symbol__init(perf_session__env(session)) < 0) goto error;
if (report.time_str) {
ret = perf_time__parse_for_ranges(report.time_str, session,
&report.ptime_range,
&report.range_size,
&report.range_num); if (ret < 0) goto error;
#ifdef HAVE_LIBTRACEEVENT if (session->tevent.pevent &&
tep_set_function_resolver(session->tevent.pevent,
machine__resolve_kernel_addr,
&session->machines.host) < 0) {
pr_err("%s: failed to set libtraceevent function resolver\n",
__func__); return -1;
} #endif
sort__setup_elide(stdout);
ret = __cmd_report(&report); if (ret == K_SWITCH_INPUT_DATA || ret == K_RELOAD) {
perf_session__delete(session);
last_key = K_SWITCH_INPUT_DATA; /* * To support switching between data with and without callchains. * report__setup_sample_type() will update it properly.
*/
symbol_conf.use_callchain = false; goto repeat;
} else
ret = 0;
if (!use_browser && (verbose > 2 || debug_kmaps))
perf_session__dump_kmaps(session);
error: if (report.ptime_range) {
itrace_synth_opts__clear_time_range(&itrace_synth_opts);
zfree(&report.ptime_range);
}
if (report.block_reports) {
block_info__free_report(report.block_reports,
report.nr_block_reports);
report.block_reports = NULL;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.