Skip to content

Commit 2d78b18

Browse files
Jin Yaoacmel
authored andcommitted
perf report: Show branch type statistics for stdio mode
Show the branch type statistics at the end of perf report --stdio. For example: perf report --stdio COND_FWD: 28.5% COND_BWD: 9.4% CROSS_4K: 0.7% CROSS_2M: 14.1% COND: 37.9% UNCOND: 0.2% IND: 6.7% CALL: 26.5% RET: 28.7% SYSRET: 0.0% The branch types are: COND_FWD: conditional forward COND_BWD: conditional backward COND: conditional branch UNCOND: unconditional branch IND: indirect CALL: function call IND_CALL: indirect function call RET: function return SYSCALL: syscall SYSRET: syscall return COND_CALL: conditional function call COND_RET: conditional function return CROSS_4K and CROSS_2M: They are the metrics checking for branches cross 4K or 2MB pages. It's an approximate computing. We don't know if the area is 4K or 2MB, so always compute both. To make the output simple, if a branch crosses 2M area, CROSS_4K will not be incremented. Change log v7: Since the common branch type definitions are changed, some tags/strings are updated accordingly. v6: Remove branch_type_stat_display() since it's moved to branch.c. v5: Remove the unnecessary sort__mode checking in hist_iter__branch_callback(). v4: Comparing to previous version, the major changes are: Add the computing of JCC forward/JCC backward and cross page checking by using the from and to addresses. Signed-off-by: Yao Jin <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Kan Liang <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 992c7e9 commit 2d78b18

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

tools/perf/builtin-report.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "util/time-utils.h"
3939
#include "util/auxtrace.h"
4040
#include "util/units.h"
41+
#include "util/branch.h"
4142

4243
#include <dlfcn.h>
4344
#include <errno.h>
@@ -73,6 +74,7 @@ struct report {
7374
u64 queue_size;
7475
int socket_filter;
7576
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
77+
struct branch_type_stat brtype_stat;
7678
};
7779

7880
static int report__config(const char *var, const char *value, void *cb)
@@ -150,6 +152,22 @@ static int hist_iter__report_callback(struct hist_entry_iter *iter,
150152
return err;
151153
}
152154

155+
static int hist_iter__branch_callback(struct hist_entry_iter *iter,
156+
struct addr_location *al __maybe_unused,
157+
bool single __maybe_unused,
158+
void *arg)
159+
{
160+
struct hist_entry *he = iter->he;
161+
struct report *rep = arg;
162+
struct branch_info *bi;
163+
164+
bi = he->branch_info;
165+
branch_type_count(&rep->brtype_stat, &bi->flags,
166+
bi->from.addr, bi->to.addr);
167+
168+
return 0;
169+
}
170+
153171
static int process_sample_event(struct perf_tool *tool,
154172
union perf_event *event,
155173
struct perf_sample *sample,
@@ -188,6 +206,8 @@ static int process_sample_event(struct perf_tool *tool,
188206
*/
189207
if (!sample->branch_stack)
190208
goto out_put;
209+
210+
iter.add_entry_cb = hist_iter__branch_callback;
191211
iter.ops = &hist_iter_branch;
192212
} else if (rep->mem_mode) {
193213
iter.ops = &hist_iter_mem;
@@ -410,6 +430,9 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
410430
perf_read_values_destroy(&rep->show_threads_values);
411431
}
412432

433+
if (sort__mode == SORT_MODE__BRANCH)
434+
branch_type_stat_display(stdout, &rep->brtype_stat);
435+
413436
return 0;
414437
}
415438

@@ -944,6 +967,8 @@ int cmd_report(int argc, const char **argv)
944967
if (has_br_stack && branch_call_mode)
945968
symbol_conf.show_branchflag_count = true;
946969

970+
memset(&report.brtype_stat, 0, sizeof(struct branch_type_stat));
971+
947972
/*
948973
* Branch mode is a tristate:
949974
* -1 means default, so decide based on the file having branch data.

tools/perf/util/hist.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,12 +749,9 @@ iter_prepare_branch_entry(struct hist_entry_iter *iter, struct addr_location *al
749749
}
750750

751751
static int
752-
iter_add_single_branch_entry(struct hist_entry_iter *iter,
752+
iter_add_single_branch_entry(struct hist_entry_iter *iter __maybe_unused,
753753
struct addr_location *al __maybe_unused)
754754
{
755-
/* to avoid calling callback function */
756-
iter->he = NULL;
757-
758755
return 0;
759756
}
760757

0 commit comments

Comments
 (0)