14 #include <linux/list.h>
16 #include <linux/rbtree.h>
37 #include <linux/bitmap.h>
57 static int perf_report__add_branch_hist_entry(
struct perf_tool *tool,
97 notes = symbol__annotation(bx->
from.sym);
111 notes = symbol__annotation(bx->
to.sym);
123 evsel->
hists.stats.total_period += 1;
133 static int perf_evsel__add_hist_entry(
struct perf_evsel *evsel,
136 struct machine *machine)
166 struct annotation *notes = symbol__annotation(he->
ms.sym);
184 static int process_sample_event(
struct perf_tool *tool,
188 struct machine *machine)
195 fprintf(stderr,
"problem processing %d event, skipping it.\n",
207 if (perf_report__add_branch_hist_entry(tool, &al, sample,
209 pr_debug(
"problem adding lbr entry, skipping event\n");
214 al.
map->dso->hit = 1;
216 if (perf_evsel__add_hist_entry(evsel, &al, sample, machine)) {
217 pr_debug(
"problem incrementing symbol period, skipping event\n");
224 static int process_read_event(
struct perf_tool *tool,
228 struct machine *machine __maybe_unused)
249 static int perf_report__setup_sample_type(
struct perf_report *rep)
256 ui__error(
"Selected --sort parent, but no "
257 "callchain data. Did you call "
258 "'perf record' without -g?\n");
262 ui__error(
"Selected -g but no callchain data. Did "
263 "you call 'perf record' without -g?\n");
271 ui__error(
"Can't register callchain params.\n");
277 if (!self->fd_pipe &&
279 ui__error(
"Selected -b but no branch data. "
280 "Did you call perf record without -b?\n");
295 static size_t hists__fprintf_nr_sample_events(
struct hists *
self,
296 const char *evname, FILE *
fp)
301 u64 nr_events =
self->stats.total_period;
304 ret =
fprintf(fp,
"# Samples: %lu%c", nr_samples, unit);
306 ret +=
fprintf(fp,
" of event '%s'", evname);
308 ret +=
fprintf(fp,
"\n# Event count (approx.): %" PRIu64, nr_events);
309 return ret +
fprintf(fp,
"\n#\n");
322 hists__fprintf_nr_sample_events(hists, evname, stdout);
329 fprintf(stdout,
"#\n# (%s)\n#\n", help);
349 struct kmap *kernel_kmap;
350 const char *help =
"For a higher level overview, try: perf report --sort comm,dso";
367 ret = perf_report__setup_sample_type(rep);
376 kernel_kmap = map__kmap(kernel_map);
377 if (kernel_map ==
NULL ||
378 (kernel_map->
dso->hit &&
382 "As no suitable kallsyms nor vmlinux was found, kernel samples\n"
383 "can't be resolved.";
386 const struct dso *kdso = kernel_map->
dso;
388 desc =
"If some relocation was applied (e.g. "
389 "kexec) symbols may be misresolved.";
394 "Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n"
395 "Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n"
396 "Samples in kernel modules can't be resolved as well.\n\n",
423 if (nr_samples == 0) {
437 perf_evlist__tty_browse_hists(session->
evlist, rep, help);
456 parse_callchain_opt(
const struct option *
opt,
const char *
arg,
int unset)
475 tok = strtok((
char *)arg,
",");
500 tok = strtok(
NULL,
",");
509 tok2 = strtok(
NULL,
",");
513 if (tok2[0] !=
'c') {
515 tok2 = strtok(
NULL,
",");
521 if (!
strcmp(tok2,
"caller"))
523 else if (!
strcmp(tok2,
"callee"))
529 fprintf(stderr,
"Can't register callchain params\n");
536 parse_branch_mode(
const struct option *opt __maybe_unused,
537 const char *
str __maybe_unused,
int unset)
547 bool has_br_stack =
false;
549 char callchain_default_opt[] =
"fractal,0.5,callee";
550 const char *
const report_usage[] = {
551 "perf report [<options>]",
556 .sample = process_sample_event,
562 .read = process_read_event,
567 .ordered_samples =
true,
568 .ordering_requires_timestamps =
true,
570 .pretty_printing_style =
"normal",
572 const struct option options[] = {
576 "be more verbose (show symbol address, etc)"),
578 "dump raw trace in ASCII"),
580 "file",
"vmlinux pathname"),
582 "file",
"kallsyms pathname"),
585 "load module symbols - WARNING: use only with -k and LIVE kernel"),
587 "Show a column with the number of samples"),
589 "Show per-thread event counters"),
591 "pretty printing style key: normal raw"),
595 "Use the stdio interface"),
597 "sort by key(s): pid, comm, dso, symbol, parent, dso_to,"
598 " dso_from, symbol_to, symbol_from, mispredict"),
600 "Show sample percentage for different cpu modes"),
602 "regex filter to identify parent, see: '--sort parent'"),
604 "Only display entries with parent-match"),
605 OPT_CALLBACK_DEFAULT(
'g',
"call-graph", &report,
"output_type,min_percent[,print_limit],call_order",
606 "Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold, optional print limit and callchain order. "
607 "Default: fractal,0.5,callee", &parse_callchain_opt, callchain_default_opt),
609 "alias for inverted call graph"),
611 "only consider symbols in these dsos"),
613 "only consider symbols in these comms"),
615 "only consider these symbols"),
617 "only show symbols that (partially) match with this filter"),
620 "don't try to adjust column width, use these fixed values"),
622 "separator for columns, no spaces will be added between "
623 "columns '.' is reserved."),
625 "Only display entries resolved to a symbol"),
627 "Look for files with symbols relative to this directory"),
629 "list of cpus to profile"),
631 "Display extended information about perf.data file"),
633 "Interleave source code with assembly code (default)"),
635 "Display raw encoding of assembly instructions (default)"),
637 "Specify disassembler style (e.g. -M intel for intel syntax)"),
639 "Show a column with the sum of periods"),
641 "use branch records for histogram filling", parse_branch_mode),
643 "objdump binary to use for disassembly and annotations"),
764 ret = __cmd_report(&report);