diff options
author | Wu Fengguang <fengguang.wu@intel.com> | 2009-03-19 22:08:03 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-04-06 03:30:20 -0400 |
commit | f49012fad4ed2231c7380c0b1901122242b3eab0 (patch) | |
tree | 015db7f6d6adac377c814c8b6f23728e24cfc37e | |
parent | cea92ce5b07078cd62c4712d51390b09a43dba2e (diff) |
perf_counter tools: Move perfstat supporting code into perfcounters.h
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | Documentation/perf_counter/perfcounters.h | 130 | ||||
-rw-r--r-- | Documentation/perf_counter/perfstat.c | 130 |
2 files changed, 130 insertions, 130 deletions
diff --git a/Documentation/perf_counter/perfcounters.h b/Documentation/perf_counter/perfcounters.h index 8c1559b25f10..0f3764aa52ab 100644 --- a/Documentation/perf_counter/perfcounters.h +++ b/Documentation/perf_counter/perfcounters.h | |||
@@ -16,6 +16,14 @@ | |||
16 | 16 | ||
17 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | 17 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
18 | 18 | ||
19 | #define rdclock() \ | ||
20 | ({ \ | ||
21 | struct timespec ts; \ | ||
22 | \ | ||
23 | clock_gettime(CLOCK_MONOTONIC, &ts); \ | ||
24 | ts.tv_sec * 1000000000ULL + ts.tv_nsec; \ | ||
25 | }) | ||
26 | |||
19 | /* | 27 | /* |
20 | * Pick up some kernel type conventions: | 28 | * Pick up some kernel type conventions: |
21 | */ | 29 | */ |
@@ -135,3 +143,125 @@ asmlinkage int sys_perf_counter_open( | |||
135 | return ret; | 143 | return ret; |
136 | } | 144 | } |
137 | 145 | ||
146 | static char *hw_event_names [] = { | ||
147 | "CPU cycles", | ||
148 | "instructions", | ||
149 | "cache references", | ||
150 | "cache misses", | ||
151 | "branches", | ||
152 | "branch misses", | ||
153 | "bus cycles", | ||
154 | }; | ||
155 | |||
156 | static char *sw_event_names [] = { | ||
157 | "cpu clock ticks", | ||
158 | "task clock ticks", | ||
159 | "pagefaults", | ||
160 | "context switches", | ||
161 | "CPU migrations", | ||
162 | }; | ||
163 | |||
164 | struct event_symbol { | ||
165 | int event; | ||
166 | char *symbol; | ||
167 | }; | ||
168 | |||
169 | static struct event_symbol event_symbols [] = { | ||
170 | {PERF_COUNT_CPU_CYCLES, "cpu-cycles", }, | ||
171 | {PERF_COUNT_CPU_CYCLES, "cycles", }, | ||
172 | {PERF_COUNT_INSTRUCTIONS, "instructions", }, | ||
173 | {PERF_COUNT_CACHE_REFERENCES, "cache-references", }, | ||
174 | {PERF_COUNT_CACHE_MISSES, "cache-misses", }, | ||
175 | {PERF_COUNT_BRANCH_INSTRUCTIONS, "branch-instructions", }, | ||
176 | {PERF_COUNT_BRANCH_INSTRUCTIONS, "branches", }, | ||
177 | {PERF_COUNT_BRANCH_MISSES, "branch-misses", }, | ||
178 | {PERF_COUNT_BUS_CYCLES, "bus-cycles", }, | ||
179 | {PERF_COUNT_CPU_CLOCK, "cpu-ticks", }, | ||
180 | {PERF_COUNT_CPU_CLOCK, "ticks", }, | ||
181 | {PERF_COUNT_TASK_CLOCK, "task-ticks", }, | ||
182 | {PERF_COUNT_PAGE_FAULTS, "page-faults", }, | ||
183 | {PERF_COUNT_PAGE_FAULTS, "faults", }, | ||
184 | {PERF_COUNT_CONTEXT_SWITCHES, "context-switches", }, | ||
185 | {PERF_COUNT_CONTEXT_SWITCHES, "cs", }, | ||
186 | {PERF_COUNT_CPU_MIGRATIONS, "cpu-migrations", }, | ||
187 | {PERF_COUNT_CPU_MIGRATIONS, "migrations", }, | ||
188 | }; | ||
189 | |||
190 | static int type_valid(int type) | ||
191 | { | ||
192 | if (type >= PERF_HW_EVENTS_MAX) | ||
193 | return 0; | ||
194 | if (type <= PERF_SW_EVENTS_MIN) | ||
195 | return 0; | ||
196 | |||
197 | return 1; | ||
198 | } | ||
199 | |||
200 | static char *event_name(int ctr) | ||
201 | { | ||
202 | int type = event_id[ctr]; | ||
203 | static char buf[32]; | ||
204 | |||
205 | if (event_raw[ctr]) { | ||
206 | sprintf(buf, "raw 0x%x", type); | ||
207 | return buf; | ||
208 | } | ||
209 | if (!type_valid(type)) | ||
210 | return "unknown"; | ||
211 | |||
212 | if (type >= 0) | ||
213 | return hw_event_names[type]; | ||
214 | |||
215 | return sw_event_names[-type-1]; | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * Each event can have multiple symbolic names. | ||
220 | * Symbolic names are (almost) exactly matched. | ||
221 | */ | ||
222 | static int match_event_symbols(char *str) | ||
223 | { | ||
224 | unsigned int i; | ||
225 | |||
226 | if (isdigit(str[0]) || str[0] == '-') | ||
227 | return atoi(str); | ||
228 | |||
229 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { | ||
230 | if (!strncmp(str, event_symbols[i].symbol, | ||
231 | strlen(event_symbols[i].symbol))) | ||
232 | return event_symbols[i].event; | ||
233 | } | ||
234 | |||
235 | return PERF_HW_EVENTS_MAX; | ||
236 | } | ||
237 | |||
238 | static void parse_events(char *str) | ||
239 | { | ||
240 | int type, raw; | ||
241 | |||
242 | again: | ||
243 | nr_counters++; | ||
244 | if (nr_counters == MAX_COUNTERS) | ||
245 | display_help(); | ||
246 | |||
247 | raw = 0; | ||
248 | if (*str == 'r') { | ||
249 | raw = 1; | ||
250 | ++str; | ||
251 | type = strtol(str, NULL, 16); | ||
252 | } else { | ||
253 | type = match_event_symbols(str); | ||
254 | if (!type_valid(type)) | ||
255 | display_help(); | ||
256 | } | ||
257 | |||
258 | event_id[nr_counters] = type; | ||
259 | event_raw[nr_counters] = raw; | ||
260 | |||
261 | str = strstr(str, ","); | ||
262 | if (str) { | ||
263 | str++; | ||
264 | goto again; | ||
265 | } | ||
266 | } | ||
267 | |||
diff --git a/Documentation/perf_counter/perfstat.c b/Documentation/perf_counter/perfstat.c index a3d4a7a602f6..3364dcb9dd9d 100644 --- a/Documentation/perf_counter/perfstat.c +++ b/Documentation/perf_counter/perfstat.c | |||
@@ -54,50 +54,6 @@ | |||
54 | 54 | ||
55 | #include "perfcounters.h" | 55 | #include "perfcounters.h" |
56 | 56 | ||
57 | static char *hw_event_names [] = { | ||
58 | "CPU cycles", | ||
59 | "instructions", | ||
60 | "cache references", | ||
61 | "cache misses", | ||
62 | "branches", | ||
63 | "branch misses", | ||
64 | "bus cycles", | ||
65 | }; | ||
66 | |||
67 | static char *sw_event_names [] = { | ||
68 | "cpu clock ticks", | ||
69 | "task clock ticks", | ||
70 | "pagefaults", | ||
71 | "context switches", | ||
72 | "CPU migrations", | ||
73 | }; | ||
74 | |||
75 | struct event_symbol { | ||
76 | int event; | ||
77 | char *symbol; | ||
78 | }; | ||
79 | |||
80 | static struct event_symbol event_symbols [] = { | ||
81 | {PERF_COUNT_CPU_CYCLES, "cpu-cycles", }, | ||
82 | {PERF_COUNT_CPU_CYCLES, "cycles", }, | ||
83 | {PERF_COUNT_INSTRUCTIONS, "instructions", }, | ||
84 | {PERF_COUNT_CACHE_REFERENCES, "cache-references", }, | ||
85 | {PERF_COUNT_CACHE_MISSES, "cache-misses", }, | ||
86 | {PERF_COUNT_BRANCH_INSTRUCTIONS, "branch-instructions", }, | ||
87 | {PERF_COUNT_BRANCH_INSTRUCTIONS, "branches", }, | ||
88 | {PERF_COUNT_BRANCH_MISSES, "branch-misses", }, | ||
89 | {PERF_COUNT_BUS_CYCLES, "bus-cycles", }, | ||
90 | {PERF_COUNT_CPU_CLOCK, "cpu-ticks", }, | ||
91 | {PERF_COUNT_CPU_CLOCK, "ticks", }, | ||
92 | {PERF_COUNT_TASK_CLOCK, "task-ticks", }, | ||
93 | {PERF_COUNT_PAGE_FAULTS, "page-faults", }, | ||
94 | {PERF_COUNT_PAGE_FAULTS, "faults", }, | ||
95 | {PERF_COUNT_CONTEXT_SWITCHES, "context-switches", }, | ||
96 | {PERF_COUNT_CONTEXT_SWITCHES, "cs", }, | ||
97 | {PERF_COUNT_CPU_MIGRATIONS, "cpu-migrations", }, | ||
98 | {PERF_COUNT_CPU_MIGRATIONS, "migrations", }, | ||
99 | }; | ||
100 | |||
101 | static int nr_counters = 0; | 57 | static int nr_counters = 0; |
102 | static int nr_cpus = 0; | 58 | static int nr_cpus = 0; |
103 | 59 | ||
@@ -137,84 +93,6 @@ static void display_help(void) | |||
137 | exit(0); | 93 | exit(0); |
138 | } | 94 | } |
139 | 95 | ||
140 | static int type_valid(int type) | ||
141 | { | ||
142 | if (type >= PERF_HW_EVENTS_MAX) | ||
143 | return 0; | ||
144 | if (type <= PERF_SW_EVENTS_MIN) | ||
145 | return 0; | ||
146 | |||
147 | return 1; | ||
148 | } | ||
149 | |||
150 | static char *event_name(int ctr) | ||
151 | { | ||
152 | int type = event_id[ctr]; | ||
153 | static char buf[32]; | ||
154 | |||
155 | if (event_raw[ctr]) { | ||
156 | sprintf(buf, "raw 0x%x", type); | ||
157 | return buf; | ||
158 | } | ||
159 | if (!type_valid(type)) | ||
160 | return "unknown"; | ||
161 | |||
162 | if (type >= 0) | ||
163 | return hw_event_names[type]; | ||
164 | |||
165 | return sw_event_names[-type-1]; | ||
166 | } | ||
167 | |||
168 | /* | ||
169 | * Each event can have multiple symbolic names. | ||
170 | * Symbolic names are (almost) exactly matched. | ||
171 | */ | ||
172 | static int match_event_symbols(char *str) | ||
173 | { | ||
174 | unsigned int i; | ||
175 | |||
176 | if (isdigit(str[0]) || str[0] == '-') | ||
177 | return atoi(str); | ||
178 | |||
179 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { | ||
180 | if (!strncmp(str, event_symbols[i].symbol, | ||
181 | strlen(event_symbols[i].symbol))) | ||
182 | return event_symbols[i].event; | ||
183 | } | ||
184 | |||
185 | return PERF_HW_EVENTS_MAX; | ||
186 | } | ||
187 | |||
188 | static void parse_events(char *str) | ||
189 | { | ||
190 | int type, raw; | ||
191 | |||
192 | again: | ||
193 | nr_counters++; | ||
194 | if (nr_counters == MAX_COUNTERS) | ||
195 | display_help(); | ||
196 | |||
197 | raw = 0; | ||
198 | if (*str == 'r') { | ||
199 | raw = 1; | ||
200 | ++str; | ||
201 | type = strtol(str, NULL, 16); | ||
202 | } else { | ||
203 | type = match_event_symbols(str); | ||
204 | if (!type_valid(type)) | ||
205 | display_help(); | ||
206 | } | ||
207 | |||
208 | event_id[nr_counters] = type; | ||
209 | event_raw[nr_counters] = raw; | ||
210 | |||
211 | str = strstr(str, ","); | ||
212 | if (str) { | ||
213 | str++; | ||
214 | goto again; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | static void process_options(int argc, char *argv[]) | 96 | static void process_options(int argc, char *argv[]) |
219 | { | 97 | { |
220 | for (;;) { | 98 | for (;;) { |
@@ -296,14 +174,6 @@ static void create_counter(int counter) | |||
296 | } | 174 | } |
297 | 175 | ||
298 | 176 | ||
299 | #define rdclock() \ | ||
300 | ({ \ | ||
301 | struct timespec ts; \ | ||
302 | \ | ||
303 | clock_gettime(CLOCK_MONOTONIC, &ts); \ | ||
304 | ts.tv_sec * 1000000000ULL + ts.tv_nsec; \ | ||
305 | }) | ||
306 | |||
307 | int main(int argc, char *argv[]) | 177 | int main(int argc, char *argv[]) |
308 | { | 178 | { |
309 | unsigned long long t0, t1; | 179 | unsigned long long t0, t1; |