4 * Builtin report command: Analyze the perf.data input file,
5 * look up and read DSOs and symbol information and display
6 * a histogram of results, along various sorting keys.
10 #include "util/util.h"
11 #include "util/config.h"
13 #include "util/annotate.h"
14 #include "util/color.h"
15 #include <linux/list.h>
16 #include <linux/rbtree.h>
17 #include "util/symbol.h"
18 #include "util/callchain.h"
19 #include "util/values.h"
22 #include "util/debug.h"
23 #include "util/evlist.h"
24 #include "util/evsel.h"
25 #include "util/header.h"
26 #include "util/session.h"
27 #include "util/tool.h"
29 #include <subcmd/parse-options.h>
30 #include <subcmd/exec-cmd.h>
31 #include "util/parse-events.h"
33 #include "util/thread.h"
34 #include "util/sort.h"
35 #include "util/hist.h"
36 #include "util/data.h"
37 #include "arch/common.h"
38 #include "util/time-utils.h"
39 #include "util/auxtrace.h"
40 #include "util/units.h"
41 #include "util/branch.h"
48 #include <linux/bitmap.h>
49 #include <linux/stringify.h>
50 #include <sys/types.h>
55 struct perf_tool tool
;
56 struct perf_session
*session
;
57 bool use_tui
, use_gtk
, use_stdio
;
60 bool inverted_callchain
;
64 bool nonany_branch_mode
;
66 struct perf_read_values show_threads_values
;
67 const char *pretty_printing_style
;
69 const char *symbol_filter_str
;
71 struct perf_time_interval ptime
;
76 DECLARE_BITMAP(cpu_bitmap
, MAX_NR_CPUS
);
77 struct branch_type_stat brtype_stat
;
80 static int report__config(const char *var
, const char *value
, void *cb
)
82 struct report
*rep
= cb
;
84 if (!strcmp(var
, "report.group")) {
85 symbol_conf
.event_group
= perf_config_bool(var
, value
);
88 if (!strcmp(var
, "report.percent-limit")) {
89 double pcnt
= strtof(value
, NULL
);
91 rep
->min_percent
= pcnt
;
92 callchain_param
.min_percent
= pcnt
;
95 if (!strcmp(var
, "report.children")) {
96 symbol_conf
.cumulate_callchain
= perf_config_bool(var
, value
);
99 if (!strcmp(var
, "report.queue-size"))
100 return perf_config_u64(&rep
->queue_size
, var
, value
);
102 if (!strcmp(var
, "report.sort_order")) {
103 default_sort_order
= strdup(value
);
110 static int hist_iter__report_callback(struct hist_entry_iter
*iter
,
111 struct addr_location
*al
, bool single
,
115 struct report
*rep
= arg
;
116 struct hist_entry
*he
= iter
->he
;
117 struct perf_evsel
*evsel
= iter
->evsel
;
118 struct perf_sample
*sample
= iter
->sample
;
120 struct branch_info
*bi
;
122 if (!ui__has_annotation())
125 hist__account_cycles(sample
->branch_stack
, al
, sample
,
126 rep
->nonany_branch_mode
);
128 if (sort__mode
== SORT_MODE__BRANCH
) {
129 bi
= he
->branch_info
;
130 err
= addr_map_symbol__inc_samples(&bi
->from
, sample
, evsel
->idx
);
134 err
= addr_map_symbol__inc_samples(&bi
->to
, sample
, evsel
->idx
);
136 } else if (rep
->mem_mode
) {
138 err
= addr_map_symbol__inc_samples(&mi
->daddr
, sample
, evsel
->idx
);
142 err
= hist_entry__inc_addr_samples(he
, sample
, evsel
->idx
, al
->addr
);
144 } else if (symbol_conf
.cumulate_callchain
) {
146 err
= hist_entry__inc_addr_samples(he
, sample
, evsel
->idx
,
149 err
= hist_entry__inc_addr_samples(he
, sample
, evsel
->idx
, al
->addr
);
156 static int hist_iter__branch_callback(struct hist_entry_iter
*iter
,
157 struct addr_location
*al __maybe_unused
,
158 bool single __maybe_unused
,
161 struct hist_entry
*he
= iter
->he
;
162 struct report
*rep
= arg
;
163 struct branch_info
*bi
;
165 bi
= he
->branch_info
;
166 branch_type_count(&rep
->brtype_stat
, &bi
->flags
,
167 bi
->from
.addr
, bi
->to
.addr
);
172 static int process_sample_event(struct perf_tool
*tool
,
173 union perf_event
*event
,
174 struct perf_sample
*sample
,
175 struct perf_evsel
*evsel
,
176 struct machine
*machine
)
178 struct report
*rep
= container_of(tool
, struct report
, tool
);
179 struct addr_location al
;
180 struct hist_entry_iter iter
= {
183 .hide_unresolved
= symbol_conf
.hide_unresolved
,
184 .add_entry_cb
= hist_iter__report_callback
,
188 if (perf_time__skip_sample(&rep
->ptime
, sample
->time
))
191 if (machine__resolve(machine
, &al
, sample
) < 0) {
192 pr_debug("problem processing %d event, skipping it.\n",
197 if (symbol_conf
.hide_unresolved
&& al
.sym
== NULL
)
200 if (rep
->cpu_list
&& !test_bit(sample
->cpu
, rep
->cpu_bitmap
))
203 if (sort__mode
== SORT_MODE__BRANCH
) {
205 * A non-synthesized event might not have a branch stack if
206 * branch stacks have been synthesized (using itrace options).
208 if (!sample
->branch_stack
)
211 iter
.add_entry_cb
= hist_iter__branch_callback
;
212 iter
.ops
= &hist_iter_branch
;
213 } else if (rep
->mem_mode
) {
214 iter
.ops
= &hist_iter_mem
;
215 } else if (symbol_conf
.cumulate_callchain
) {
216 iter
.ops
= &hist_iter_cumulative
;
218 iter
.ops
= &hist_iter_normal
;
222 al
.map
->dso
->hit
= 1;
224 ret
= hist_entry_iter__add(&iter
, &al
, rep
->max_stack
, rep
);
226 pr_debug("problem adding hist entry, skipping event\n");
228 addr_location__put(&al
);
232 static int process_read_event(struct perf_tool
*tool
,
233 union perf_event
*event
,
234 struct perf_sample
*sample __maybe_unused
,
235 struct perf_evsel
*evsel
,
236 struct machine
*machine __maybe_unused
)
238 struct report
*rep
= container_of(tool
, struct report
, tool
);
240 if (rep
->show_threads
) {
241 const char *name
= evsel
? perf_evsel__name(evsel
) : "unknown";
242 int err
= perf_read_values_add_value(&rep
->show_threads_values
,
243 event
->read
.pid
, event
->read
.tid
,
255 /* For pipe mode, sample_type is not currently set */
256 static int report__setup_sample_type(struct report
*rep
)
258 struct perf_session
*session
= rep
->session
;
259 u64 sample_type
= perf_evlist__combined_sample_type(session
->evlist
);
260 bool is_pipe
= perf_data_file__is_pipe(session
->file
);
262 if (session
->itrace_synth_opts
->callchain
||
264 perf_header__has_feat(&session
->header
, HEADER_AUXTRACE
) &&
265 !session
->itrace_synth_opts
->set
))
266 sample_type
|= PERF_SAMPLE_CALLCHAIN
;
268 if (session
->itrace_synth_opts
->last_branch
)
269 sample_type
|= PERF_SAMPLE_BRANCH_STACK
;
271 if (!is_pipe
&& !(sample_type
& PERF_SAMPLE_CALLCHAIN
)) {
272 if (perf_hpp_list
.parent
) {
273 ui__error("Selected --sort parent, but no "
274 "callchain data. Did you call "
275 "'perf record' without -g?\n");
278 if (symbol_conf
.use_callchain
&&
279 !symbol_conf
.show_branchflag_count
) {
280 ui__error("Selected -g or --branch-history.\n"
281 "But no callchain or branch data.\n"
282 "Did you call 'perf record' without -g or -b?\n");
285 } else if (!callchain_param
.enabled
&&
286 callchain_param
.mode
!= CHAIN_NONE
&&
287 !symbol_conf
.use_callchain
) {
288 symbol_conf
.use_callchain
= true;
289 if (callchain_register_param(&callchain_param
) < 0) {
290 ui__error("Can't register callchain params.\n");
295 if (symbol_conf
.cumulate_callchain
) {
296 /* Silently ignore if callchain is missing */
297 if (!(sample_type
& PERF_SAMPLE_CALLCHAIN
)) {
298 symbol_conf
.cumulate_callchain
= false;
299 perf_hpp__cancel_cumulate();
303 if (sort__mode
== SORT_MODE__BRANCH
) {
305 !(sample_type
& PERF_SAMPLE_BRANCH_STACK
)) {
306 ui__error("Selected -b but no branch data. "
307 "Did you call perf record without -b?\n");
312 if (symbol_conf
.use_callchain
|| symbol_conf
.cumulate_callchain
) {
313 if ((sample_type
& PERF_SAMPLE_REGS_USER
) &&
314 (sample_type
& PERF_SAMPLE_STACK_USER
))
315 callchain_param
.record_mode
= CALLCHAIN_DWARF
;
316 else if (sample_type
& PERF_SAMPLE_BRANCH_STACK
)
317 callchain_param
.record_mode
= CALLCHAIN_LBR
;
319 callchain_param
.record_mode
= CALLCHAIN_FP
;
322 /* ??? handle more cases than just ANY? */
323 if (!(perf_evlist__combined_branch_type(session
->evlist
) &
324 PERF_SAMPLE_BRANCH_ANY
))
325 rep
->nonany_branch_mode
= true;
330 static void sig_handler(int sig __maybe_unused
)
335 static size_t hists__fprintf_nr_sample_events(struct hists
*hists
, struct report
*rep
,
336 const char *evname
, FILE *fp
)
340 unsigned long nr_samples
= hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
];
341 u64 nr_events
= hists
->stats
.total_period
;
342 struct perf_evsel
*evsel
= hists_to_evsel(hists
);
344 size_t size
= sizeof(buf
);
345 int socked_id
= hists
->socket_filter
;
350 if (symbol_conf
.filter_relative
) {
351 nr_samples
= hists
->stats
.nr_non_filtered_samples
;
352 nr_events
= hists
->stats
.total_non_filtered_period
;
355 if (perf_evsel__is_group_event(evsel
)) {
356 struct perf_evsel
*pos
;
358 perf_evsel__group_desc(evsel
, buf
, size
);
361 for_each_group_member(pos
, evsel
) {
362 const struct hists
*pos_hists
= evsel__hists(pos
);
364 if (symbol_conf
.filter_relative
) {
365 nr_samples
+= pos_hists
->stats
.nr_non_filtered_samples
;
366 nr_events
+= pos_hists
->stats
.total_non_filtered_period
;
368 nr_samples
+= pos_hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
];
369 nr_events
+= pos_hists
->stats
.total_period
;
374 nr_samples
= convert_unit(nr_samples
, &unit
);
375 ret
= fprintf(fp
, "# Samples: %lu%c", nr_samples
, unit
);
377 ret
+= fprintf(fp
, " of event '%s'", evname
);
379 if (symbol_conf
.show_ref_callgraph
&&
380 strstr(evname
, "call-graph=no")) {
381 ret
+= fprintf(fp
, ", show reference callgraph");
385 ret
+= fprintf(fp
, "\n# Total weight : %" PRIu64
, nr_events
);
386 ret
+= fprintf(fp
, "\n# Sort order : %s", sort_order
? : default_mem_sort_order
);
388 ret
+= fprintf(fp
, "\n# Event count (approx.): %" PRIu64
, nr_events
);
391 ret
+= fprintf(fp
, "\n# Processor Socket: %d", socked_id
);
393 return ret
+ fprintf(fp
, "\n#\n");
396 static int perf_evlist__tty_browse_hists(struct perf_evlist
*evlist
,
400 struct perf_evsel
*pos
;
403 fprintf(stdout
, "#\n# Total Lost Samples: %" PRIu64
"\n#\n",
404 evlist
->stats
.total_lost_samples
);
407 evlist__for_each_entry(evlist
, pos
) {
408 struct hists
*hists
= evsel__hists(pos
);
409 const char *evname
= perf_evsel__name(pos
);
411 if (symbol_conf
.event_group
&&
412 !perf_evsel__is_group_leader(pos
))
415 hists__fprintf_nr_sample_events(hists
, rep
, evname
, stdout
);
416 hists__fprintf(hists
, !quiet
, 0, 0, rep
->min_percent
, stdout
,
417 symbol_conf
.use_callchain
||
418 symbol_conf
.show_branchflag_count
);
419 fprintf(stdout
, "\n\n");
423 fprintf(stdout
, "#\n# (%s)\n#\n", help
);
425 if (rep
->show_threads
) {
426 bool style
= !strcmp(rep
->pretty_printing_style
, "raw");
427 perf_read_values_display(stdout
, &rep
->show_threads_values
,
429 perf_read_values_destroy(&rep
->show_threads_values
);
432 if (sort__mode
== SORT_MODE__BRANCH
)
433 branch_type_stat_display(stdout
, &rep
->brtype_stat
);
438 static void report__warn_kptr_restrict(const struct report
*rep
)
440 struct map
*kernel_map
= machine__kernel_map(&rep
->session
->machines
.host
);
441 struct kmap
*kernel_kmap
= kernel_map
? map__kmap(kernel_map
) : NULL
;
443 if (kernel_map
== NULL
||
444 (kernel_map
->dso
->hit
&&
445 (kernel_kmap
->ref_reloc_sym
== NULL
||
446 kernel_kmap
->ref_reloc_sym
->addr
== 0))) {
448 "As no suitable kallsyms nor vmlinux was found, kernel samples\n"
449 "can't be resolved.";
452 const struct dso
*kdso
= kernel_map
->dso
;
453 if (!RB_EMPTY_ROOT(&kdso
->symbols
[MAP__FUNCTION
])) {
454 desc
= "If some relocation was applied (e.g. "
455 "kexec) symbols may be misresolved.";
460 "Kernel address maps (/proc/{kallsyms,modules}) were restricted.\n\n"
461 "Check /proc/sys/kernel/kptr_restrict before running 'perf record'.\n\n%s\n\n"
462 "Samples in kernel modules can't be resolved as well.\n\n",
467 static int report__gtk_browse_hists(struct report
*rep
, const char *help
)
469 int (*hist_browser
)(struct perf_evlist
*evlist
, const char *help
,
470 struct hist_browser_timer
*timer
, float min_pcnt
);
472 hist_browser
= dlsym(perf_gtk_handle
, "perf_evlist__gtk_browse_hists");
474 if (hist_browser
== NULL
) {
475 ui__error("GTK browser not found!\n");
479 return hist_browser(rep
->session
->evlist
, help
, NULL
, rep
->min_percent
);
482 static int report__browse_hists(struct report
*rep
)
485 struct perf_session
*session
= rep
->session
;
486 struct perf_evlist
*evlist
= session
->evlist
;
487 const char *help
= perf_tip(system_path(TIPDIR
));
490 /* fallback for people who don't install perf ;-) */
491 help
= perf_tip(DOCDIR
);
493 help
= "Cannot load tips.txt file, please install perf!";
496 switch (use_browser
) {
498 ret
= perf_evlist__tui_browse_hists(evlist
, help
, NULL
,
500 &session
->header
.env
);
502 * Usually "ret" is the last pressed key, and we only
503 * care if the key notifies us to switch data file.
505 if (ret
!= K_SWITCH_INPUT_DATA
)
509 ret
= report__gtk_browse_hists(rep
, help
);
512 ret
= perf_evlist__tty_browse_hists(evlist
, rep
, help
);
519 static int report__collapse_hists(struct report
*rep
)
521 struct ui_progress prog
;
522 struct perf_evsel
*pos
;
525 ui_progress__init(&prog
, rep
->nr_entries
, "Merging related events...");
527 evlist__for_each_entry(rep
->session
->evlist
, pos
) {
528 struct hists
*hists
= evsel__hists(pos
);
531 hists
->symbol_filter_str
= rep
->symbol_filter_str
;
533 hists
->socket_filter
= rep
->socket_filter
;
535 ret
= hists__collapse_resort(hists
, &prog
);
539 /* Non-group events are considered as leader */
540 if (symbol_conf
.event_group
&&
541 !perf_evsel__is_group_leader(pos
)) {
542 struct hists
*leader_hists
= evsel__hists(pos
->leader
);
544 hists__match(leader_hists
, hists
);
545 hists__link(leader_hists
, hists
);
549 ui_progress__finish();
553 static void report__output_resort(struct report
*rep
)
555 struct ui_progress prog
;
556 struct perf_evsel
*pos
;
558 ui_progress__init(&prog
, rep
->nr_entries
, "Sorting events for output...");
560 evlist__for_each_entry(rep
->session
->evlist
, pos
)
561 perf_evsel__output_resort(pos
, &prog
);
563 ui_progress__finish();
566 static int __cmd_report(struct report
*rep
)
569 struct perf_session
*session
= rep
->session
;
570 struct perf_evsel
*pos
;
571 struct perf_data_file
*file
= session
->file
;
573 signal(SIGINT
, sig_handler
);
576 ret
= perf_session__cpu_bitmap(session
, rep
->cpu_list
,
579 ui__error("failed to set cpu bitmap\n");
582 session
->itrace_synth_opts
->cpu_bitmap
= rep
->cpu_bitmap
;
585 if (rep
->show_threads
) {
586 ret
= perf_read_values_init(&rep
->show_threads_values
);
591 ret
= report__setup_sample_type(rep
);
593 /* report__setup_sample_type() already showed error message */
597 ret
= perf_session__process_events(session
);
599 ui__error("failed to process sample\n");
603 report__warn_kptr_restrict(rep
);
605 evlist__for_each_entry(session
->evlist
, pos
)
606 rep
->nr_entries
+= evsel__hists(pos
)->nr_entries
;
608 if (use_browser
== 0) {
610 perf_session__fprintf(session
, stdout
);
613 perf_session__fprintf_dsos(session
, stdout
);
616 perf_session__fprintf_nr_events(session
, stdout
);
617 perf_evlist__fprintf_nr_events(session
->evlist
, stdout
);
622 ret
= report__collapse_hists(rep
);
624 ui__error("failed to process hist entry\n");
632 * recalculate number of entries after collapsing since it
633 * might be changed during the collapse phase.
636 evlist__for_each_entry(session
->evlist
, pos
)
637 rep
->nr_entries
+= evsel__hists(pos
)->nr_entries
;
639 if (rep
->nr_entries
== 0) {
640 ui__error("The %s file has no samples!\n", file
->path
);
644 report__output_resort(rep
);
646 return report__browse_hists(rep
);
650 report_parse_callchain_opt(const struct option
*opt
, const char *arg
, int unset
)
652 struct callchain_param
*callchain
= opt
->value
;
654 callchain
->enabled
= !unset
;
659 symbol_conf
.use_callchain
= false;
660 callchain
->mode
= CHAIN_NONE
;
664 return parse_callchain_report_opt(arg
);
668 report_parse_ignore_callees_opt(const struct option
*opt __maybe_unused
,
669 const char *arg
, int unset __maybe_unused
)
672 int err
= regcomp(&ignore_callees_regex
, arg
, REG_EXTENDED
);
675 regerror(err
, &ignore_callees_regex
, buf
, sizeof(buf
));
676 pr_err("Invalid --ignore-callees regex: %s\n%s", arg
, buf
);
679 have_ignore_callees
= 1;
686 parse_branch_mode(const struct option
*opt
,
687 const char *str __maybe_unused
, int unset
)
689 int *branch_mode
= opt
->value
;
691 *branch_mode
= !unset
;
696 parse_percent_limit(const struct option
*opt
, const char *str
,
697 int unset __maybe_unused
)
699 struct report
*rep
= opt
->value
;
700 double pcnt
= strtof(str
, NULL
);
702 rep
->min_percent
= pcnt
;
703 callchain_param
.min_percent
= pcnt
;
707 #define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function,percent"
709 const char report_callchain_help
[] = "Display call graph (stack chain/backtrace):\n\n"
710 CALLCHAIN_REPORT_HELP
711 "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT
;
713 int cmd_report(int argc
, const char **argv
)
715 struct perf_session
*session
;
716 struct itrace_synth_opts itrace_synth_opts
= { .set
= 0, };
718 bool has_br_stack
= false;
719 int branch_mode
= -1;
720 bool branch_call_mode
= false;
721 char callchain_default_opt
[] = CALLCHAIN_DEFAULT_OPT
;
722 const char * const report_usage
[] = {
723 "perf report [<options>]",
726 struct report report
= {
728 .sample
= process_sample_event
,
729 .mmap
= perf_event__process_mmap
,
730 .mmap2
= perf_event__process_mmap2
,
731 .comm
= perf_event__process_comm
,
732 .namespaces
= perf_event__process_namespaces
,
733 .exit
= perf_event__process_exit
,
734 .fork
= perf_event__process_fork
,
735 .lost
= perf_event__process_lost
,
736 .read
= process_read_event
,
737 .attr
= perf_event__process_attr
,
738 .tracing_data
= perf_event__process_tracing_data
,
739 .build_id
= perf_event__process_build_id
,
740 .id_index
= perf_event__process_id_index
,
741 .auxtrace_info
= perf_event__process_auxtrace_info
,
742 .auxtrace
= perf_event__process_auxtrace
,
743 .feature
= perf_event__process_feature
,
744 .ordered_events
= true,
745 .ordering_requires_timestamps
= true,
747 .max_stack
= PERF_MAX_STACK_DEPTH
,
748 .pretty_printing_style
= "normal",
751 const struct option options
[] = {
752 OPT_STRING('i', "input", &input_name
, "file",
754 OPT_INCR('v', "verbose", &verbose
,
755 "be more verbose (show symbol address, etc)"),
756 OPT_BOOLEAN('q', "quiet", &quiet
, "Do not show any message"),
757 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace
,
758 "dump raw trace in ASCII"),
759 OPT_STRING('k', "vmlinux", &symbol_conf
.vmlinux_name
,
760 "file", "vmlinux pathname"),
761 OPT_STRING(0, "kallsyms", &symbol_conf
.kallsyms_name
,
762 "file", "kallsyms pathname"),
763 OPT_BOOLEAN('f', "force", &symbol_conf
.force
, "don't complain, do it"),
764 OPT_BOOLEAN('m', "modules", &symbol_conf
.use_modules
,
765 "load module symbols - WARNING: use only with -k and LIVE kernel"),
766 OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf
.show_nr_samples
,
767 "Show a column with the number of samples"),
768 OPT_BOOLEAN('T', "threads", &report
.show_threads
,
769 "Show per-thread event counters"),
770 OPT_STRING(0, "pretty", &report
.pretty_printing_style
, "key",
771 "pretty printing style key: normal raw"),
772 OPT_BOOLEAN(0, "tui", &report
.use_tui
, "Use the TUI interface"),
773 OPT_BOOLEAN(0, "gtk", &report
.use_gtk
, "Use the GTK2 interface"),
774 OPT_BOOLEAN(0, "stdio", &report
.use_stdio
,
775 "Use the stdio interface"),
776 OPT_BOOLEAN(0, "header", &report
.header
, "Show data header."),
777 OPT_BOOLEAN(0, "header-only", &report
.header_only
,
778 "Show only data header."),
779 OPT_STRING('s', "sort", &sort_order
, "key[,key2...]",
780 "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..."
781 " Please refer the man page for the complete list."),
782 OPT_STRING('F', "fields", &field_order
, "key[,keys...]",
783 "output field(s): overhead, period, sample plus all of sort keys"),
784 OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf
.show_cpu_utilization
,
785 "Show sample percentage for different cpu modes"),
786 OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf
.show_cpu_utilization
,
787 "Show sample percentage for different cpu modes", PARSE_OPT_HIDDEN
),
788 OPT_STRING('p', "parent", &parent_pattern
, "regex",
789 "regex filter to identify parent, see: '--sort parent'"),
790 OPT_BOOLEAN('x', "exclude-other", &symbol_conf
.exclude_other
,
791 "Only display entries with parent-match"),
792 OPT_CALLBACK_DEFAULT('g', "call-graph", &callchain_param
,
793 "print_type,threshold[,print_limit],order,sort_key[,branch],value",
794 report_callchain_help
, &report_parse_callchain_opt
,
795 callchain_default_opt
),
796 OPT_BOOLEAN(0, "children", &symbol_conf
.cumulate_callchain
,
797 "Accumulate callchains of children and show total overhead as well"),
798 OPT_INTEGER(0, "max-stack", &report
.max_stack
,
799 "Set the maximum stack depth when parsing the callchain, "
800 "anything beyond the specified depth will be ignored. "
801 "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH
)),
802 OPT_BOOLEAN('G', "inverted", &report
.inverted_callchain
,
803 "alias for inverted call graph"),
804 OPT_CALLBACK(0, "ignore-callees", NULL
, "regex",
805 "ignore callees of these functions in call graphs",
806 report_parse_ignore_callees_opt
),
807 OPT_STRING('d', "dsos", &symbol_conf
.dso_list_str
, "dso[,dso...]",
808 "only consider symbols in these dsos"),
809 OPT_STRING('c', "comms", &symbol_conf
.comm_list_str
, "comm[,comm...]",
810 "only consider symbols in these comms"),
811 OPT_STRING(0, "pid", &symbol_conf
.pid_list_str
, "pid[,pid...]",
812 "only consider symbols in these pids"),
813 OPT_STRING(0, "tid", &symbol_conf
.tid_list_str
, "tid[,tid...]",
814 "only consider symbols in these tids"),
815 OPT_STRING('S', "symbols", &symbol_conf
.sym_list_str
, "symbol[,symbol...]",
816 "only consider these symbols"),
817 OPT_STRING(0, "symbol-filter", &report
.symbol_filter_str
, "filter",
818 "only show symbols that (partially) match with this filter"),
819 OPT_STRING('w', "column-widths", &symbol_conf
.col_width_list_str
,
821 "don't try to adjust column width, use these fixed values"),
822 OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf
.field_sep
, "separator",
823 "separator for columns, no spaces will be added between "
824 "columns '.' is reserved."),
825 OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf
.hide_unresolved
,
826 "Only display entries resolved to a symbol"),
827 OPT_CALLBACK(0, "symfs", NULL
, "directory",
828 "Look for files with symbols relative to this directory",
829 symbol__config_symfs
),
830 OPT_STRING('C', "cpu", &report
.cpu_list
, "cpu",
831 "list of cpus to profile"),
832 OPT_BOOLEAN('I', "show-info", &report
.show_full_info
,
833 "Display extended information about perf.data file"),
834 OPT_BOOLEAN(0, "source", &symbol_conf
.annotate_src
,
835 "Interleave source code with assembly code (default)"),
836 OPT_BOOLEAN(0, "asm-raw", &symbol_conf
.annotate_asm_raw
,
837 "Display raw encoding of assembly instructions (default)"),
838 OPT_STRING('M', "disassembler-style", &disassembler_style
, "disassembler style",
839 "Specify disassembler style (e.g. -M intel for intel syntax)"),
840 OPT_BOOLEAN(0, "show-total-period", &symbol_conf
.show_total_period
,
841 "Show a column with the sum of periods"),
842 OPT_BOOLEAN(0, "group", &symbol_conf
.event_group
,
843 "Show event group information together"),
844 OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode
, "",
845 "use branch records for per branch histogram filling",
847 OPT_BOOLEAN(0, "branch-history", &branch_call_mode
,
848 "add last branch records to call history"),
849 OPT_STRING(0, "objdump", &objdump_path
, "path",
850 "objdump binary to use for disassembly and annotations"),
851 OPT_BOOLEAN(0, "demangle", &symbol_conf
.demangle
,
852 "Disable symbol demangling"),
853 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf
.demangle_kernel
,
854 "Enable kernel symbol demangling"),
855 OPT_BOOLEAN(0, "mem-mode", &report
.mem_mode
, "mem access profile"),
856 OPT_CALLBACK(0, "percent-limit", &report
, "percent",
857 "Don't show entries under that percent", parse_percent_limit
),
858 OPT_CALLBACK(0, "percentage", NULL
, "relative|absolute",
859 "how to display percentage of filtered entries", parse_filter_percentage
),
860 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts
, NULL
, "opts",
861 "Instruction Tracing options",
862 itrace_parse_synth_opts
),
863 OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename
,
864 "Show full source file name path for source lines"),
865 OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf
.show_ref_callgraph
,
866 "Show callgraph from reference event"),
867 OPT_INTEGER(0, "socket-filter", &report
.socket_filter
,
868 "only show processor socket that match with this filter"),
869 OPT_BOOLEAN(0, "raw-trace", &symbol_conf
.raw_trace
,
870 "Show raw trace event output (do not use print fmt or plugins)"),
871 OPT_BOOLEAN(0, "hierarchy", &symbol_conf
.report_hierarchy
,
872 "Show entries in a hierarchy"),
873 OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL
, "mode",
874 "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
875 stdio__config_color
, "always"),
876 OPT_STRING(0, "time", &report
.time_str
, "str",
877 "Time span of interest (start,stop)"),
878 OPT_BOOLEAN(0, "inline", &symbol_conf
.inline_name
,
879 "Show inline function"),
882 struct perf_data_file file
= {
883 .mode
= PERF_DATA_MODE_READ
,
885 int ret
= hists__init();
890 ret
= perf_config(report__config
, &report
);
894 argc
= parse_options(argc
, argv
, options
, report_usage
, 0);
897 * Special case: if there's an argument left then assume that
898 * it's a symbol filter:
901 usage_with_options(report_usage
, options
);
903 report
.symbol_filter_str
= argv
[0];
909 if (symbol_conf
.vmlinux_name
&&
910 access(symbol_conf
.vmlinux_name
, R_OK
)) {
911 pr_err("Invalid file: %s\n", symbol_conf
.vmlinux_name
);
914 if (symbol_conf
.kallsyms_name
&&
915 access(symbol_conf
.kallsyms_name
, R_OK
)) {
916 pr_err("Invalid file: %s\n", symbol_conf
.kallsyms_name
);
920 if (report
.use_stdio
)
922 else if (report
.use_tui
)
924 else if (report
.use_gtk
)
927 if (report
.inverted_callchain
)
928 callchain_param
.order
= ORDER_CALLER
;
929 if (symbol_conf
.cumulate_callchain
&& !callchain_param
.order_set
)
930 callchain_param
.order
= ORDER_CALLER
;
932 if (itrace_synth_opts
.callchain
&&
933 (int)itrace_synth_opts
.callchain_sz
> report
.max_stack
)
934 report
.max_stack
= itrace_synth_opts
.callchain_sz
;
936 if (!input_name
|| !strlen(input_name
)) {
937 if (!fstat(STDIN_FILENO
, &st
) && S_ISFIFO(st
.st_mode
))
940 input_name
= "perf.data";
943 file
.path
= input_name
;
944 file
.force
= symbol_conf
.force
;
947 session
= perf_session__new(&file
, false, &report
.tool
);
951 if (report
.queue_size
) {
952 ordered_events__set_alloc_size(&session
->ordered_events
,
956 session
->itrace_synth_opts
= &itrace_synth_opts
;
958 report
.session
= session
;
960 has_br_stack
= perf_header__has_feat(&session
->header
,
961 HEADER_BRANCH_STACK
);
963 if (itrace_synth_opts
.last_branch
)
966 if (has_br_stack
&& branch_call_mode
)
967 symbol_conf
.show_branchflag_count
= true;
969 memset(&report
.brtype_stat
, 0, sizeof(struct branch_type_stat
));
972 * Branch mode is a tristate:
973 * -1 means default, so decide based on the file having branch data.
974 * 0/1 means the user chose a mode.
976 if (((branch_mode
== -1 && has_br_stack
) || branch_mode
== 1) &&
978 sort__mode
= SORT_MODE__BRANCH
;
979 symbol_conf
.cumulate_callchain
= false;
981 if (branch_call_mode
) {
982 callchain_param
.key
= CCKEY_ADDRESS
;
983 callchain_param
.branch_callstack
= 1;
984 symbol_conf
.use_callchain
= true;
985 callchain_register_param(&callchain_param
);
986 if (sort_order
== NULL
)
987 sort_order
= "srcline,symbol,dso";
990 if (report
.mem_mode
) {
991 if (sort__mode
== SORT_MODE__BRANCH
) {
992 pr_err("branch and mem mode incompatible\n");
995 sort__mode
= SORT_MODE__MEMORY
;
996 symbol_conf
.cumulate_callchain
= false;
999 if (symbol_conf
.report_hierarchy
) {
1000 /* disable incompatible options */
1001 symbol_conf
.cumulate_callchain
= false;
1004 pr_err("Error: --hierarchy and --fields options cannot be used together\n");
1005 parse_options_usage(report_usage
, options
, "F", 1);
1006 parse_options_usage(NULL
, options
, "hierarchy", 0);
1010 perf_hpp_list
.need_collapse
= true;
1013 /* Force tty output for header output and per-thread stat. */
1014 if (report
.header
|| report
.header_only
|| report
.show_threads
)
1016 if (report
.header
|| report
.header_only
)
1017 report
.tool
.show_feat_hdr
= SHOW_FEAT_HEADER
;
1018 if (report
.show_full_info
)
1019 report
.tool
.show_feat_hdr
= SHOW_FEAT_HEADER_FULL_INFO
;
1021 if (strcmp(input_name
, "-") != 0)
1022 setup_browser(true);
1026 if (setup_sorting(session
->evlist
) < 0) {
1028 parse_options_usage(report_usage
, options
, "s", 1);
1030 parse_options_usage(sort_order
? NULL
: report_usage
,
1035 if ((report
.header
|| report
.header_only
) && !quiet
) {
1036 perf_session__fprintf_info(session
, stdout
,
1037 report
.show_full_info
);
1038 if (report
.header_only
) {
1042 } else if (use_browser
== 0 && !quiet
) {
1043 fputs("# To display the perf.data header info, please use --header/--header-only options.\n#\n",
1048 * Only in the TUI browser we are doing integrated annotation,
1049 * so don't allocate extra space that won't be used in the stdio
1052 if (ui__has_annotation()) {
1053 ret
= symbol__annotation_init();
1057 * For searching by name on the "Browse map details".
1058 * providing it only in verbose mode not to bloat too
1059 * much struct symbol.
1063 * XXX: Need to provide a less kludgy way to ask for
1064 * more space per symbol, the u32 is for the index on
1066 * See symbol__browser_index.
1068 symbol_conf
.priv_size
+= sizeof(u32
);
1069 symbol_conf
.sort_by_name
= true;
1073 if (symbol__init(&session
->header
.env
) < 0)
1076 if (perf_time__parse_str(&report
.ptime
, report
.time_str
) != 0) {
1077 pr_err("Invalid time string\n");
1081 sort__setup_elide(stdout
);
1083 ret
= __cmd_report(&report
);
1084 if (ret
== K_SWITCH_INPUT_DATA
) {
1085 perf_session__delete(session
);
1091 perf_session__delete(session
);