aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorStephane Eranian <eranian@google.com>2012-03-08 17:47:47 -0500
committerIngo Molnar <mingo@elte.hu>2012-03-09 02:26:08 -0500
commit993ac88d5892629fbe1f8a54857f9947f49f0d96 (patch)
tree27f23cc95a72be350781803530e09b1535b719e7 /tools
parent330aa675b4f92a422cb6d3acbbfd16a628017520 (diff)
perf report: Auto-detect branch stack sampling mode
This patch enhances perf report to auto-detect when the perf.data file contains samples with branch stacks. That way it is not necessary to use the -b option. To force branch view mode to off, simply use --no-branch-stack. Signed-off-by: Stephane Eranian <eranian@google.com> Cc: peterz@infradead.org Cc: acme@redhat.com Cc: asharma@fb.com Cc: ravitillo@lbl.gov Cc: vweaver1@eecs.utk.edu Cc: khandual@linux.vnet.ibm.com Cc: dsahern@gmail.com Link: http://lkml.kernel.org/r/1331246868-19905-4-git-send-email-eranian@google.com Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/Documentation/perf-report.txt7
-rw-r--r--tools/perf/builtin-report.c50
-rw-r--r--tools/perf/util/sort.c2
-rw-r--r--tools/perf/util/sort.h2
4 files changed, 41 insertions, 20 deletions
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 19b9092cf8b7..87feeee8b90c 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -157,8 +157,11 @@ OPTIONS
157--branch-stack:: 157--branch-stack::
158 Use the addresses of sampled taken branches instead of the instruction 158 Use the addresses of sampled taken branches instead of the instruction
159 address to build the histograms. To generate meaningful output, the 159 address to build the histograms. To generate meaningful output, the
160 perf.data file must have been obtained using perf record -b xxx where 160 perf.data file must have been obtained using perf record -b or
161 xxx is a branch filter option. 161 perf record --branch-filter xxx where xxx is a branch filter option.
162 perf report is able to auto-detect whether a perf.data file contains
163 branch stacks and it will automatically switch to the branch view mode,
164 unless --no-branch-stack is used.
162 165
163SEE ALSO 166SEE ALSO
164-------- 167--------
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 528789f6c702..66e852376a05 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -170,7 +170,7 @@ static int process_sample_event(struct perf_tool *tool,
170 if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap)) 170 if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
171 return 0; 171 return 0;
172 172
173 if (sort__branch_mode) { 173 if (sort__branch_mode == 1) {
174 if (perf_report__add_branch_hist_entry(tool, &al, sample, 174 if (perf_report__add_branch_hist_entry(tool, &al, sample,
175 evsel, machine)) { 175 evsel, machine)) {
176 pr_debug("problem adding lbr entry, skipping event\n"); 176 pr_debug("problem adding lbr entry, skipping event\n");
@@ -239,7 +239,7 @@ static int perf_report__setup_sample_type(struct perf_report *rep)
239 } 239 }
240 } 240 }
241 241
242 if (sort__branch_mode) { 242 if (sort__branch_mode == 1) {
243 if (!(self->sample_type & PERF_SAMPLE_BRANCH_STACK)) { 243 if (!(self->sample_type & PERF_SAMPLE_BRANCH_STACK)) {
244 fprintf(stderr, "selected -b but no branch data." 244 fprintf(stderr, "selected -b but no branch data."
245 " Did you call perf record without" 245 " Did you call perf record without"
@@ -306,7 +306,7 @@ static int __cmd_report(struct perf_report *rep)
306{ 306{
307 int ret = -EINVAL; 307 int ret = -EINVAL;
308 u64 nr_samples; 308 u64 nr_samples;
309 struct perf_session *session; 309 struct perf_session *session = rep->session;
310 struct perf_evsel *pos; 310 struct perf_evsel *pos;
311 struct map *kernel_map; 311 struct map *kernel_map;
312 struct kmap *kernel_kmap; 312 struct kmap *kernel_kmap;
@@ -314,13 +314,6 @@ static int __cmd_report(struct perf_report *rep)
314 314
315 signal(SIGINT, sig_handler); 315 signal(SIGINT, sig_handler);
316 316
317 session = perf_session__new(rep->input_name, O_RDONLY,
318 rep->force, false, &rep->tool);
319 if (session == NULL)
320 return -ENOMEM;
321
322 rep->session = session;
323
324 if (rep->cpu_list) { 317 if (rep->cpu_list) {
325 ret = perf_session__cpu_bitmap(session, rep->cpu_list, 318 ret = perf_session__cpu_bitmap(session, rep->cpu_list,
326 rep->cpu_bitmap); 319 rep->cpu_bitmap);
@@ -487,9 +480,19 @@ setup:
487 return 0; 480 return 0;
488} 481}
489 482
483static int
484parse_branch_mode(const struct option *opt __used, const char *str __used, int unset)
485{
486 sort__branch_mode = !unset;
487 return 0;
488}
489
490int cmd_report(int argc, const char **argv, const char *prefix __used) 490int cmd_report(int argc, const char **argv, const char *prefix __used)
491{ 491{
492 struct perf_session *session;
492 struct stat st; 493 struct stat st;
494 bool has_br_stack = false;
495 int ret = -1;
493 char callchain_default_opt[] = "fractal,0.5,callee"; 496 char callchain_default_opt[] = "fractal,0.5,callee";
494 const char * const report_usage[] = { 497 const char * const report_usage[] = {
495 "perf report [<options>]", 498 "perf report [<options>]",
@@ -578,8 +581,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
578 "Specify disassembler style (e.g. -M intel for intel syntax)"), 581 "Specify disassembler style (e.g. -M intel for intel syntax)"),
579 OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period, 582 OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
580 "Show a column with the sum of periods"), 583 "Show a column with the sum of periods"),
581 OPT_BOOLEAN('b', "branch-stack", &sort__branch_mode, 584 OPT_CALLBACK_NOOPT('b', "branch-stack", &sort__branch_mode, "",
582 "use branch records for histogram filling"), 585 "use branch records for histogram filling", parse_branch_mode),
583 OPT_END() 586 OPT_END()
584 }; 587 };
585 588
@@ -599,8 +602,20 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
599 else 602 else
600 report.input_name = "perf.data"; 603 report.input_name = "perf.data";
601 } 604 }
605 session = perf_session__new(report.input_name, O_RDONLY,
606 report.force, false, &report.tool);
607 if (session == NULL)
608 return -ENOMEM;
609
610 report.session = session;
611
612 has_br_stack = perf_header__has_feat(&session->header,
613 HEADER_BRANCH_STACK);
602 614
603 if (sort__branch_mode) { 615 if (sort__branch_mode == -1 && has_br_stack)
616 sort__branch_mode = 1;
617
618 if (sort__branch_mode == 1) {
604 if (use_browser) 619 if (use_browser)
605 fprintf(stderr, "Warning: TUI interface not supported" 620 fprintf(stderr, "Warning: TUI interface not supported"
606 " in branch mode\n"); 621 " in branch mode\n");
@@ -657,13 +672,13 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
657 } 672 }
658 673
659 if (symbol__init() < 0) 674 if (symbol__init() < 0)
660 return -1; 675 goto error;
661 676
662 setup_sorting(report_usage, options); 677 setup_sorting(report_usage, options);
663 678
664 if (parent_pattern != default_parent_pattern) { 679 if (parent_pattern != default_parent_pattern) {
665 if (sort_dimension__add("parent") < 0) 680 if (sort_dimension__add("parent") < 0)
666 return -1; 681 goto error;
667 682
668 /* 683 /*
669 * Only show the parent fields if we explicitly 684 * Only show the parent fields if we explicitly
@@ -685,5 +700,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
685 sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list, "comm", stdout); 700 sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list, "comm", stdout);
686 sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list, "symbol", stdout); 701 sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list, "symbol", stdout);
687 702
688 return __cmd_report(&report); 703 ret = __cmd_report(&report);
704error:
705 perf_session__delete(session);
706 return ret;
689} 707}
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 2739ed10d5e6..88dbcf6f9575 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -8,7 +8,7 @@ const char default_sort_order[] = "comm,dso,symbol";
8const char *sort_order = default_sort_order; 8const char *sort_order = default_sort_order;
9int sort__need_collapse = 0; 9int sort__need_collapse = 0;
10int sort__has_parent = 0; 10int sort__has_parent = 0;
11bool sort__branch_mode; 11int sort__branch_mode = -1; /* -1 = means not set */
12 12
13enum sort_type sort__first_dimension; 13enum sort_type sort__first_dimension;
14 14
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 7aa72a00bc8e..8505b9bcfa36 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -31,7 +31,7 @@ extern const char *parent_pattern;
31extern const char default_sort_order[]; 31extern const char default_sort_order[];
32extern int sort__need_collapse; 32extern int sort__need_collapse;
33extern int sort__has_parent; 33extern int sort__has_parent;
34extern bool sort__branch_mode; 34extern int sort__branch_mode;
35extern char *field_sep; 35extern char *field_sep;
36extern struct sort_entry sort_comm; 36extern struct sort_entry sort_comm;
37extern struct sort_entry sort_dso; 37extern struct sort_entry sort_dso;