Commit 8d51735f authored by Jin Yao's avatar Jin Yao Committed by Arnaldo Carvalho de Melo

perf report: Refactor the branch info printing code

The branch info such as predicted/cycles/... are printed at the
callchain entries.

For example: perf report --branch-history --no-children --stdio

    --1.07%--main div.c:39 (predicted:52.4% cycles:1 iterations:17)
              main div.c:44 (predicted:52.4% cycles:1)
              main div.c:42 (cycles:2)
              compute_flag div.c:28 (cycles:2)
              compute_flag div.c:27 (cycles:1)
              rand rand.c:28 (cycles:1)
              rand rand.c:28 (cycles:1)
              __random random.c:298 (cycles:1)
              __random random.c:297 (cycles:1)
              __random random.c:295 (cycles:1)
              __random random.c:295 (cycles:1)
              __random random.c:295 (cycles:1)

But the current code is difficult to maintain and extend. This patch
refactors the code for easy maintenance.

Change log:

v6: 1. Put the multiline condition code into {} brackets in
       counts_str_build()

    2. Keep the original display order, that is:
       predicted, abort, cycles, iterations

v5: It's a new patch in v5 patch series.
Signed-off-by: default avatarYao Jin <yao.jin@linux.intel.com>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1500379995-6449-5-git-send-email-yao.jin@linux.intel.com
[ Don't use 'index' as a name for a variable, it shadows a globa decl in older distros ]
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 60f83fa6
...@@ -1214,83 +1214,65 @@ int callchain_branch_counts(struct callchain_root *root, ...@@ -1214,83 +1214,65 @@ int callchain_branch_counts(struct callchain_root *root,
cycles_count); cycles_count);
} }
static int count_pri64_printf(int idx, const char *str, u64 value, char *bf, int bfsize)
{
int printed;
printed = scnprintf(bf, bfsize, "%s%s:%" PRId64 "", (idx) ? " " : " (", str, value);
return printed;
}
static int count_float_printf(int idx, const char *str, float value, char *bf, int bfsize)
{
int printed;
printed = scnprintf(bf, bfsize, "%s%s:%.1f%%", (idx) ? " " : " (", str, value);
return printed;
}
static int counts_str_build(char *bf, int bfsize, static int counts_str_build(char *bf, int bfsize,
u64 branch_count, u64 predicted_count, u64 branch_count, u64 predicted_count,
u64 abort_count, u64 cycles_count, u64 abort_count, u64 cycles_count,
u64 iter_count, u64 samples_count) u64 iter_count, u64 samples_count)
{ {
double predicted_percent = 0.0;
const char *null_str = "";
char iter_str[32];
char cycle_str[32];
char *istr, *cstr;
u64 cycles; u64 cycles;
int printed = 0, i = 0;
if (branch_count == 0) if (branch_count == 0)
return scnprintf(bf, bfsize, " (calltrace)"); return scnprintf(bf, bfsize, " (calltrace)");
cycles = cycles_count / branch_count; if (predicted_count < branch_count) {
printed += count_float_printf(i++, "predicted",
if (iter_count && samples_count) { predicted_count * 100.0 / branch_count,
if (cycles > 0) bf + printed, bfsize - printed);
scnprintf(iter_str, sizeof(iter_str), }
" iterations:%" PRId64 "",
iter_count / samples_count);
else
scnprintf(iter_str, sizeof(iter_str),
"iterations:%" PRId64 "",
iter_count / samples_count);
istr = iter_str;
} else
istr = (char *)null_str;
if (cycles > 0) {
scnprintf(cycle_str, sizeof(cycle_str),
"cycles:%" PRId64 "", cycles);
cstr = cycle_str;
} else
cstr = (char *)null_str;
predicted_percent = predicted_count * 100.0 / branch_count;
if ((predicted_count == branch_count) && (abort_count == 0)) { if (abort_count) {
if ((cycles > 0) || (istr != (char *)null_str)) printed += count_float_printf(i++, "abort",
return scnprintf(bf, bfsize, " (%s%s)", cstr, istr); abort_count * 100.0 / branch_count,
else bf + printed, bfsize - printed);
return scnprintf(bf, bfsize, "%s", (char *)null_str);
} }
if ((predicted_count < branch_count) && (abort_count == 0)) { cycles = cycles_count / branch_count;
if ((cycles > 0) || (istr != (char *)null_str)) if (cycles) {
return scnprintf(bf, bfsize, printed += count_pri64_printf(i++, "cycles",
" (predicted:%.1f%% %s%s)", cycles,
predicted_percent, cstr, istr); bf + printed, bfsize - printed);
else {
return scnprintf(bf, bfsize,
" (predicted:%.1f%%)",
predicted_percent);
}
} }
if ((predicted_count == branch_count) && (abort_count > 0)) { if (iter_count && samples_count) {
if ((cycles > 0) || (istr != (char *)null_str)) printed += count_pri64_printf(i++, "iterations",
return scnprintf(bf, bfsize, iter_count / samples_count,
" (abort:%" PRId64 " %s%s)", bf + printed, bfsize - printed);
abort_count, cstr, istr);
else
return scnprintf(bf, bfsize,
" (abort:%" PRId64 ")",
abort_count);
} }
if ((cycles > 0) || (istr != (char *)null_str)) if (i)
return scnprintf(bf, bfsize, return scnprintf(bf + printed, bfsize - printed, ")");
" (predicted:%.1f%% abort:%" PRId64 " %s%s)",
predicted_percent, abort_count, cstr, istr);
return scnprintf(bf, bfsize, bf[0] = 0;
" (predicted:%.1f%% abort:%" PRId64 ")", return 0;
predicted_percent, abort_count);
} }
static int callchain_counts_printf(FILE *fp, char *bf, int bfsize, static int callchain_counts_printf(FILE *fp, char *bf, int bfsize,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment