aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/perf_counter/builtin-stat.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-05-29 03:10:54 -0400
committerIngo Molnar <mingo@elte.hu>2009-05-29 03:21:49 -0400
commit2996f5ddb7ba8889caeeac65edafe48845106eaa (patch)
treee5a93215c835bb820720d929513a4cbebfbbeeea /Documentation/perf_counter/builtin-stat.c
parentc04f5e5d7b523f90ee3cdd70a68c4002aaecd3fa (diff)
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: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'Documentation/perf_counter/builtin-stat.c')
-rw-r--r--Documentation/perf_counter/builtin-stat.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/Documentation/perf_counter/builtin-stat.c b/Documentation/perf_counter/builtin-stat.c
index 6a2936150f28..0c92eb725526 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[] = {
71 10000, 71 10000,
72}; 72};
73 73
74static __u64 event_res[MAX_COUNTERS][3];
75static __u64 event_scaled[MAX_COUNTERS];
76
74static void create_perfstat_counter(int counter) 77static void create_perfstat_counter(int counter)
75{ 78{
76 struct perf_counter_hw_event hw_event; 79 struct perf_counter_hw_event hw_event;
@@ -123,16 +126,19 @@ static inline int nsec_counter(int counter)
123} 126}
124 127
125/* 128/*
126 * Print out the results of a single counter: 129 * Read out the results of a single counter:
127 */ 130 */
128static void print_counter(int counter) 131static void read_counter(int counter)
129{ 132{
130 __u64 count[3], single_count[3]; 133 __u64 *count, single_count[3];
131 ssize_t res; 134 ssize_t res;
132 int cpu, nv; 135 int cpu, nv;
133 int scaled; 136 int scaled;
134 137
138 count = event_res[counter];
139
135 count[0] = count[1] = count[2] = 0; 140 count[0] = count[1] = count[2] = 0;
141
136 nv = scale ? 3 : 1; 142 nv = scale ? 3 : 1;
137 for (cpu = 0; cpu < nr_cpus; cpu ++) { 143 for (cpu = 0; cpu < nr_cpus; cpu ++) {
138 res = read(fd[cpu][counter], single_count, nv * sizeof(__u64)); 144 res = read(fd[cpu][counter], single_count, nv * sizeof(__u64));
@@ -148,16 +154,35 @@ static void print_counter(int counter)
148 scaled = 0; 154 scaled = 0;
149 if (scale) { 155 if (scale) {
150 if (count[2] == 0) { 156 if (count[2] == 0) {
151 fprintf(stderr, " %14s %-20s\n", 157 event_scaled[counter] = -1;
152 "<not counted>", event_name(counter)); 158 count[0] = 0;
153 return; 159 return;
154 } 160 }
161
155 if (count[2] < count[1]) { 162 if (count[2] < count[1]) {
156 scaled = 1; 163 event_scaled[counter] = 1;
157 count[0] = (unsigned long long) 164 count[0] = (unsigned long long)
158 ((double)count[0] * count[1] / count[2] + 0.5); 165 ((double)count[0] * count[1] / count[2] + 0.5);
159 } 166 }
160 } 167 }
168}
169
170/*
171 * Print out the results of a single counter:
172 */
173static void print_counter(int counter)
174{
175 __u64 *count;
176 int scaled;
177
178 count = event_res[counter];
179 scaled = event_scaled[counter];
180
181 if (scaled == -1) {
182 fprintf(stderr, " %14s %-20s\n",
183 "<not counted>", event_name(counter));
184 return;
185 }
161 186
162 if (nsec_counter(counter)) { 187 if (nsec_counter(counter)) {
163 double msecs = (double)count[0] / 1000000; 188 double msecs = (double)count[0] / 1000000;
@@ -214,6 +239,9 @@ static int do_perfstat(int argc, const char **argv)
214 fprintf(stderr, "\n"); 239 fprintf(stderr, "\n");
215 240
216 for (counter = 0; counter < nr_counters; counter++) 241 for (counter = 0; counter < nr_counters; counter++)
242 read_counter(counter);
243
244 for (counter = 0; counter < nr_counters; counter++)
217 print_counter(counter); 245 print_counter(counter);
218 246
219 247