Commit 11018201 authored by Anton Blanchard's avatar Anton Blanchard Committed by Ingo Molnar

perf stat: Add branch performance metric

When we count both branches and branch-misses it is useful to
print out the percentage of branch-misses:

 # perf stat -e branches -e branch-misses /bin/true

 Performance counter stats for '/bin/true':

         401684  branches                 #      0.000 M/sec
          23301  branch-misses            #      5.801 %
Signed-off-by: default avatarAnton Blanchard <anton@samba.org>
Cc: paulus@samba.org
Cc: a.p.zijlstra@chello.nl
LKML-Reference: <20091018112923.GQ4808@kryten>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent f39cdf25
...@@ -125,6 +125,7 @@ struct stats event_res_stats[MAX_COUNTERS][3]; ...@@ -125,6 +125,7 @@ struct stats event_res_stats[MAX_COUNTERS][3];
struct stats runtime_nsecs_stats; struct stats runtime_nsecs_stats;
struct stats walltime_nsecs_stats; struct stats walltime_nsecs_stats;
struct stats runtime_cycles_stats; struct stats runtime_cycles_stats;
struct stats runtime_branches_stats;
#define MATCH_EVENT(t, c, counter) \ #define MATCH_EVENT(t, c, counter) \
(attrs[counter].type == PERF_TYPE_##t && \ (attrs[counter].type == PERF_TYPE_##t && \
...@@ -235,6 +236,8 @@ static void read_counter(int counter) ...@@ -235,6 +236,8 @@ static void read_counter(int counter)
update_stats(&runtime_nsecs_stats, count[0]); update_stats(&runtime_nsecs_stats, count[0]);
if (MATCH_EVENT(HARDWARE, HW_CPU_CYCLES, counter)) if (MATCH_EVENT(HARDWARE, HW_CPU_CYCLES, counter))
update_stats(&runtime_cycles_stats, count[0]); update_stats(&runtime_cycles_stats, count[0]);
if (MATCH_EVENT(HARDWARE, HW_BRANCH_INSTRUCTIONS, counter))
update_stats(&runtime_branches_stats, count[0]);
} }
static int run_perf_stat(int argc __used, const char **argv) static int run_perf_stat(int argc __used, const char **argv)
...@@ -352,6 +355,14 @@ static void abs_printout(int counter, double avg) ...@@ -352,6 +355,14 @@ static void abs_printout(int counter, double avg)
ratio = avg / total; ratio = avg / total;
fprintf(stderr, " # %10.3f IPC ", ratio); fprintf(stderr, " # %10.3f IPC ", ratio);
} else if (MATCH_EVENT(HARDWARE, HW_BRANCH_MISSES, counter)) {
total = avg_stats(&runtime_branches_stats);
if (total)
ratio = avg * 100 / total;
fprintf(stderr, " # %10.3f %% ", ratio);
} else { } else {
total = avg_stats(&runtime_nsecs_stats); total = avg_stats(&runtime_nsecs_stats);
......
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