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 (!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
return0;
}
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);
}
}
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));
/* Same thread? */ if (thread__tid(a) == thread__tid(b)) return0;
/* Compare a and b to root. */ if (thread__tid(a) == 0) return -1;
if (thread__tid(b) == 0) return1;
/* If parents match sort by tid. */ if (thread__ppid(a) == thread__ppid(b)) return thread__tid(a) < thread__tid(b) ? -1 : 1;
/* *Findaandbsuchthatiftheyareachildofeachotheraandb's *tid'smatch,otherwiseaandbhaveacommonparentanddistinct *tid'stosortby.Firstmakethedepthsofthethreadsmatch.
*/
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); return1;
}
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);
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 [<options>]",
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;
/* 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;
}
¤ 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.0.36Bemerkung:
(vorverarbeitet am 2026-10-12)
¤
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.