Commit 2996f5dd authored by Ingo Molnar's avatar Ingo Molnar

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@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: John Kacur <jkacur@redhat.com>
LKML-Reference: <new-submission>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent c04f5e5d
...@@ -71,6 +71,9 @@ static const unsigned int default_count[] = { ...@@ -71,6 +71,9 @@ static const unsigned int default_count[] = {
10000, 10000,
}; };
static __u64 event_res[MAX_COUNTERS][3];
static __u64 event_scaled[MAX_COUNTERS];
static void create_perfstat_counter(int counter) static void create_perfstat_counter(int counter)
{ {
struct perf_counter_hw_event hw_event; struct perf_counter_hw_event hw_event;
...@@ -123,16 +126,19 @@ static inline int nsec_counter(int counter) ...@@ -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; ssize_t res;
int cpu, nv; int cpu, nv;
int scaled; int scaled;
count = event_res[counter];
count[0] = count[1] = count[2] = 0; count[0] = count[1] = count[2] = 0;
nv = scale ? 3 : 1; nv = scale ? 3 : 1;
for (cpu = 0; cpu < nr_cpus; cpu ++) { for (cpu = 0; cpu < nr_cpus; cpu ++) {
res = read(fd[cpu][counter], single_count, nv * sizeof(__u64)); res = read(fd[cpu][counter], single_count, nv * sizeof(__u64));
...@@ -148,16 +154,35 @@ static void print_counter(int counter) ...@@ -148,16 +154,35 @@ static void print_counter(int counter)
scaled = 0; scaled = 0;
if (scale) { if (scale) {
if (count[2] == 0) { if (count[2] == 0) {
fprintf(stderr, " %14s %-20s\n", event_scaled[counter] = -1;
"<not counted>", event_name(counter)); count[0] = 0;
return; return;
} }
if (count[2] < count[1]) { if (count[2] < count[1]) {
scaled = 1; event_scaled[counter] = 1;
count[0] = (unsigned long long) count[0] = (unsigned long long)
((double)count[0] * count[1] / count[2] + 0.5); ((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)) { if (nsec_counter(counter)) {
double msecs = (double)count[0] / 1000000; double msecs = (double)count[0] / 1000000;
...@@ -213,6 +238,9 @@ static int do_perfstat(int argc, const char **argv) ...@@ -213,6 +238,9 @@ static int do_perfstat(int argc, const char **argv)
argv[0]); argv[0]);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
for (counter = 0; counter < nr_counters; counter++)
read_counter(counter);
for (counter = 0; counter < nr_counters; counter++) for (counter = 0; counter < nr_counters; counter++)
print_counter(counter); print_counter(counter);
......
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