* [PATCH] perf stat: Add branch performance metric
@ 2009-10-18 11:29 Anton Blanchard
2009-10-19 7:55 ` [tip:perf/core] " tip-bot for Anton Blanchard
0 siblings, 1 reply; 2+ messages in thread
From: Anton Blanchard @ 2009-10-18 11:29 UTC (permalink / raw)
To: mingo, paulus, a.p.zijlstra; +Cc: linux-kernel
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: Anton Blanchard <anton@samba.org>
---
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 3db31e7..6a2e37e 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -125,6 +125,7 @@ struct stats event_res_stats[MAX_COUNTERS][3];
struct stats runtime_nsecs_stats;
struct stats walltime_nsecs_stats;
struct stats runtime_cycles_stats;
+struct stats runtime_branches_stats;
#define MATCH_EVENT(t, c, counter) \
(attrs[counter].type == PERF_TYPE_##t && \
@@ -235,6 +237,8 @@ static void read_counter(int counter)
update_stats(&runtime_nsecs_stats, count[0]);
if (MATCH_EVENT(HARDWARE, HW_CPU_CYCLES, counter))
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)
@@ -352,6 +356,14 @@ static void abs_printout(int counter, double avg)
ratio = avg / total;
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 {
total = avg_stats(&runtime_nsecs_stats);
^ permalink raw reply related [flat|nested] 2+ messages in thread* [tip:perf/core] perf stat: Add branch performance metric
2009-10-18 11:29 [PATCH] perf stat: Add branch performance metric Anton Blanchard
@ 2009-10-19 7:55 ` tip-bot for Anton Blanchard
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Anton Blanchard @ 2009-10-19 7:55 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, anton, hpa, mingo, tglx, mingo
Commit-ID: 11018201b831e19304c0d639f105ad6c27e120b1
Gitweb: http://git.kernel.org/tip/11018201b831e19304c0d639f105ad6c27e120b1
Author: Anton Blanchard <anton@samba.org>
AuthorDate: Sun, 18 Oct 2009 22:29:23 +1100
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 19 Oct 2009 09:20:21 +0200
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: Anton Blanchard <anton@samba.org>
Cc: paulus@samba.org
Cc: a.p.zijlstra@chello.nl
LKML-Reference: <20091018112923.GQ4808@kryten>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
tools/perf/builtin-stat.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 3db31e7..c373683 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -125,6 +125,7 @@ struct stats event_res_stats[MAX_COUNTERS][3];
struct stats runtime_nsecs_stats;
struct stats walltime_nsecs_stats;
struct stats runtime_cycles_stats;
+struct stats runtime_branches_stats;
#define MATCH_EVENT(t, c, counter) \
(attrs[counter].type == PERF_TYPE_##t && \
@@ -235,6 +236,8 @@ static void read_counter(int counter)
update_stats(&runtime_nsecs_stats, count[0]);
if (MATCH_EVENT(HARDWARE, HW_CPU_CYCLES, counter))
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)
@@ -352,6 +355,14 @@ static void abs_printout(int counter, double avg)
ratio = avg / total;
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 {
total = avg_stats(&runtime_nsecs_stats);
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-10-19 7:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-18 11:29 [PATCH] perf stat: Add branch performance metric Anton Blanchard
2009-10-19 7:55 ` [tip:perf/core] " tip-bot for Anton Blanchard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox