diff options
-rw-r--r-- | tools/perf/builtin-stat.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 095a90e012a1..01cc07efb728 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -96,6 +96,10 @@ static u64 walltime_nsecs_noise; | |||
96 | static u64 runtime_cycles_avg; | 96 | static u64 runtime_cycles_avg; |
97 | static u64 runtime_cycles_noise; | 97 | static u64 runtime_cycles_noise; |
98 | 98 | ||
99 | #define MATCH_EVENT(t, c, counter) \ | ||
100 | (attrs[counter].type == PERF_TYPE_##t && \ | ||
101 | attrs[counter].config == PERF_COUNT_##c) | ||
102 | |||
99 | #define ERR_PERF_OPEN \ | 103 | #define ERR_PERF_OPEN \ |
100 | "Error: counter %d, sys_perf_counter_open() syscall returned with %d (%s)\n" | 104 | "Error: counter %d, sys_perf_counter_open() syscall returned with %d (%s)\n" |
101 | 105 | ||
@@ -133,13 +137,8 @@ static void create_perf_stat_counter(int counter, int pid) | |||
133 | */ | 137 | */ |
134 | static inline int nsec_counter(int counter) | 138 | static inline int nsec_counter(int counter) |
135 | { | 139 | { |
136 | if (attrs[counter].type != PERF_TYPE_SOFTWARE) | 140 | if (MATCH_EVENT(SOFTWARE, SW_CPU_CLOCK, counter) || |
137 | return 0; | 141 | MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) |
138 | |||
139 | if (attrs[counter].config == PERF_COUNT_SW_CPU_CLOCK) | ||
140 | return 1; | ||
141 | |||
142 | if (attrs[counter].config == PERF_COUNT_SW_TASK_CLOCK) | ||
143 | return 1; | 142 | return 1; |
144 | 143 | ||
145 | return 0; | 144 | return 0; |
@@ -194,11 +193,9 @@ static void read_counter(int counter) | |||
194 | /* | 193 | /* |
195 | * Save the full runtime - to allow normalization during printout: | 194 | * Save the full runtime - to allow normalization during printout: |
196 | */ | 195 | */ |
197 | if (attrs[counter].type == PERF_TYPE_SOFTWARE && | 196 | if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) |
198 | attrs[counter].config == PERF_COUNT_SW_TASK_CLOCK) | ||
199 | runtime_nsecs[run_idx] = count[0]; | 197 | runtime_nsecs[run_idx] = count[0]; |
200 | if (attrs[counter].type == PERF_TYPE_HARDWARE && | 198 | if (MATCH_EVENT(HARDWARE, HW_CPU_CYCLES, counter)) |
201 | attrs[counter].config == PERF_COUNT_HW_CPU_CYCLES) | ||
202 | runtime_cycles[run_idx] = count[0]; | 199 | runtime_cycles[run_idx] = count[0]; |
203 | } | 200 | } |
204 | 201 | ||
@@ -292,9 +289,7 @@ static void nsec_printout(int counter, u64 *count, u64 *noise) | |||
292 | 289 | ||
293 | fprintf(stderr, " %14.6f %-24s", msecs, event_name(counter)); | 290 | fprintf(stderr, " %14.6f %-24s", msecs, event_name(counter)); |
294 | 291 | ||
295 | if (attrs[counter].type == PERF_TYPE_SOFTWARE && | 292 | if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) { |
296 | attrs[counter].config == PERF_COUNT_SW_TASK_CLOCK) { | ||
297 | |||
298 | if (walltime_nsecs_avg) | 293 | if (walltime_nsecs_avg) |
299 | fprintf(stderr, " # %10.3f CPUs ", | 294 | fprintf(stderr, " # %10.3f CPUs ", |
300 | (double)count[0] / (double)walltime_nsecs_avg); | 295 | (double)count[0] / (double)walltime_nsecs_avg); |
@@ -307,9 +302,7 @@ static void abs_printout(int counter, u64 *count, u64 *noise) | |||
307 | fprintf(stderr, " %14Ld %-24s", count[0], event_name(counter)); | 302 | fprintf(stderr, " %14Ld %-24s", count[0], event_name(counter)); |
308 | 303 | ||
309 | if (runtime_cycles_avg && | 304 | if (runtime_cycles_avg && |
310 | attrs[counter].type == PERF_TYPE_HARDWARE && | 305 | MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) { |
311 | attrs[counter].config == PERF_COUNT_HW_INSTRUCTIONS) { | ||
312 | |||
313 | fprintf(stderr, " # %10.3f IPC ", | 306 | fprintf(stderr, " # %10.3f IPC ", |
314 | (double)count[0] / (double)runtime_cycles_avg); | 307 | (double)count[0] / (double)runtime_cycles_avg); |
315 | } else { | 308 | } else { |