[<prev] [next>] [day] [month] [year] [list]
Message-ID: <tip-2996f5ddb7ba8889caeeac65edafe48845106eaa@git.kernel.org>
Date: Fri, 29 May 2009 09:00:57 GMT
From: tip-bot for Ingo Molnar <mingo@...e.hu>
To: linux-tip-commits@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, acme@...hat.com, paulus@...ba.org,
hpa@...or.com, mingo@...hat.com, jkacur@...hat.com,
a.p.zijlstra@...llo.nl, efault@....de, mtosatti@...hat.com,
tglx@...utronix.de, cjashfor@...ux.vnet.ibm.com, mingo@...e.hu
Subject: [tip:perfcounters/core] perf_counter tools: Split display into reading and printing
Commit-ID: 2996f5ddb7ba8889caeeac65edafe48845106eaa
Gitweb: http://git.kernel.org/tip/2996f5ddb7ba8889caeeac65edafe48845106eaa
Author: Ingo Molnar <mingo@...e.hu>
AuthorDate: Fri, 29 May 2009 09:10:54 +0200
Committer: Ingo Molnar <mingo@...e.hu>
CommitDate: Fri, 29 May 2009 09:21:49 +0200
perf_counter tools: Split display into reading and printing
We introduce the extra pass to allow the print-out to possibly
rely on already read counters.
[ Impact: cleanup ]
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Mike Galbraith <efault@....de>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Corey Ashford <cjashfor@...ux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@...hat.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: John Kacur <jkacur@...hat.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@...e.hu>
---
Documentation/perf_counter/builtin-stat.c | 40 ++++++++++++++++++++++++----
1 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/Documentation/perf_counter/builtin-stat.c b/Documentation/perf_counter/builtin-stat.c
index 6a29361..0c92eb7 100644
--- a/Documentation/perf_counter/builtin-stat.c
+++ b/Documentation/perf_counter/builtin-stat.c
@@ -71,6 +71,9 @@ static const unsigned int default_count[] = {
10000,
};
+static __u64 event_res[MAX_COUNTERS][3];
+static __u64 event_scaled[MAX_COUNTERS];
+
static void create_perfstat_counter(int counter)
{
struct perf_counter_hw_event hw_event;
@@ -123,16 +126,19 @@ static inline int nsec_counter(int counter)
}
/*
- * Print out the results of a single counter:
+ * Read out the results of a single counter:
*/
-static void print_counter(int counter)
+static void read_counter(int counter)
{
- __u64 count[3], single_count[3];
+ __u64 *count, single_count[3];
ssize_t res;
int cpu, nv;
int scaled;
+ count = event_res[counter];
+
count[0] = count[1] = count[2] = 0;
+
nv = scale ? 3 : 1;
for (cpu = 0; cpu < nr_cpus; cpu ++) {
res = read(fd[cpu][counter], single_count, nv * sizeof(__u64));
@@ -148,16 +154,35 @@ static void print_counter(int counter)
scaled = 0;
if (scale) {
if (count[2] == 0) {
- fprintf(stderr, " %14s %-20s\n",
- "<not counted>", event_name(counter));
+ event_scaled[counter] = -1;
+ count[0] = 0;
return;
}
+
if (count[2] < count[1]) {
- scaled = 1;
+ event_scaled[counter] = 1;
count[0] = (unsigned long long)
((double)count[0] * count[1] / count[2] + 0.5);
}
}
+}
+
+/*
+ * Print out the results of a single counter:
+ */
+static void print_counter(int counter)
+{
+ __u64 *count;
+ int scaled;
+
+ count = event_res[counter];
+ scaled = event_scaled[counter];
+
+ if (scaled == -1) {
+ fprintf(stderr, " %14s %-20s\n",
+ "<not counted>", event_name(counter));
+ return;
+ }
if (nsec_counter(counter)) {
double msecs = (double)count[0] / 1000000;
@@ -214,6 +239,9 @@ static int do_perfstat(int argc, const char **argv)
fprintf(stderr, "\n");
for (counter = 0; counter < nr_counters; counter++)
+ read_counter(counter);
+
+ for (counter = 0; counter < nr_counters; counter++)
print_counter(counter);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists