aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-stat.c37
-rw-r--r--tools/perf/util/evsel.h4
2 files changed, 20 insertions, 21 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 511ebaff9a66..3e5f356a5241 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -170,10 +170,6 @@ struct stats runtime_cycles_stats[MAX_NR_CPUS];
170struct stats runtime_branches_stats[MAX_NR_CPUS]; 170struct stats runtime_branches_stats[MAX_NR_CPUS];
171struct stats walltime_nsecs_stats; 171struct stats walltime_nsecs_stats;
172 172
173#define MATCH_EVENT(t, c, evsel) \
174 (evsel->attr.type == PERF_TYPE_##t && \
175 evsel->attr.config == PERF_COUNT_##c)
176
177#define ERR_PERF_OPEN \ 173#define ERR_PERF_OPEN \
178"counter %d, sys_perf_event_open() syscall returned with %d (%s). /bin/dmesg may provide additional information." 174"counter %d, sys_perf_event_open() syscall returned with %d (%s). /bin/dmesg may provide additional information."
179 175
@@ -229,10 +225,10 @@ static int create_perf_stat_counter(struct perf_evsel *evsel, bool *perm_err)
229/* 225/*
230 * Does the counter have nsecs as a unit? 226 * Does the counter have nsecs as a unit?
231 */ 227 */
232static inline int nsec_counter(struct perf_evsel *counter) 228static inline int nsec_counter(struct perf_evsel *evsel)
233{ 229{
234 if (MATCH_EVENT(SOFTWARE, SW_CPU_CLOCK, counter) || 230 if (perf_evsel__match(evsel, SOFTWARE, SW_CPU_CLOCK) ||
235 MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) 231 perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK))
236 return 1; 232 return 1;
237 233
238 return 0; 234 return 0;
@@ -300,11 +296,11 @@ static void read_counter_aggr(struct perf_evsel *counter)
300 /* 296 /*
301 * Save the full runtime - to allow normalization during printout: 297 * Save the full runtime - to allow normalization during printout:
302 */ 298 */
303 if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) 299 if (perf_evsel__match(counter, SOFTWARE, SW_TASK_CLOCK))
304 update_stats(&runtime_nsecs_stats[0], count[0]); 300 update_stats(&runtime_nsecs_stats[0], count[0]);
305 if (MATCH_EVENT(HARDWARE, HW_CPU_CYCLES, counter)) 301 if (perf_evsel__match(counter, HARDWARE, HW_CPU_CYCLES))
306 update_stats(&runtime_cycles_stats[0], count[0]); 302 update_stats(&runtime_cycles_stats[0], count[0]);
307 if (MATCH_EVENT(HARDWARE, HW_BRANCH_INSTRUCTIONS, counter)) 303 if (perf_evsel__match(counter, HARDWARE, HW_BRANCH_INSTRUCTIONS))
308 update_stats(&runtime_branches_stats[0], count[0]); 304 update_stats(&runtime_branches_stats[0], count[0]);
309} 305}
310 306
@@ -347,11 +343,11 @@ static void read_counter(struct perf_evsel *counter)
347 cpu_counts[cpu].ena = count[1]; 343 cpu_counts[cpu].ena = count[1];
348 cpu_counts[cpu].run = count[2]; 344 cpu_counts[cpu].run = count[2];
349 345
350 if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) 346 if (perf_evsel__match(counter, SOFTWARE, SW_TASK_CLOCK))
351 update_stats(&runtime_nsecs_stats[cpu], count[0]); 347 update_stats(&runtime_nsecs_stats[cpu], count[0]);
352 if (MATCH_EVENT(HARDWARE, HW_CPU_CYCLES, counter)) 348 if (perf_evsel__match(counter, HARDWARE, HW_CPU_CYCLES))
353 update_stats(&runtime_cycles_stats[cpu], count[0]); 349 update_stats(&runtime_cycles_stats[cpu], count[0]);
354 if (MATCH_EVENT(HARDWARE, HW_BRANCH_INSTRUCTIONS, counter)) 350 if (perf_evsel__match(counter, HARDWARE, HW_BRANCH_INSTRUCTIONS))
355 update_stats(&runtime_branches_stats[cpu], count[0]); 351 update_stats(&runtime_branches_stats[cpu], count[0]);
356 } 352 }
357} 353}
@@ -474,7 +470,7 @@ static void print_noise(struct perf_evsel *evsel, double avg)
474 100 * stddev_stats(&ps->res_stats[0]) / avg); 470 100 * stddev_stats(&ps->res_stats[0]) / avg);
475} 471}
476 472
477static void nsec_printout(int cpu, struct perf_evsel *counter, double avg) 473static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg)
478{ 474{
479 double msecs = avg / 1e6; 475 double msecs = avg / 1e6;
480 char cpustr[16] = { '\0', }; 476 char cpustr[16] = { '\0', };
@@ -485,18 +481,17 @@ static void nsec_printout(int cpu, struct perf_evsel *counter, double avg)
485 csv_output ? 0 : -4, 481 csv_output ? 0 : -4,
486 cpumap[cpu], csv_sep); 482 cpumap[cpu], csv_sep);
487 483
488 fprintf(stderr, fmt, cpustr, msecs, csv_sep, event_name(counter)); 484 fprintf(stderr, fmt, cpustr, msecs, csv_sep, event_name(evsel));
489 485
490 if (csv_output) 486 if (csv_output)
491 return; 487 return;
492 488
493 if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) { 489 if (perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK))
494 fprintf(stderr, " # %10.3f CPUs ", 490 fprintf(stderr, " # %10.3f CPUs ",
495 avg / avg_stats(&walltime_nsecs_stats)); 491 avg / avg_stats(&walltime_nsecs_stats));
496 }
497} 492}
498 493
499static void abs_printout(int cpu, struct perf_evsel *counter, double avg) 494static void abs_printout(int cpu, struct perf_evsel *evsel, double avg)
500{ 495{
501 double total, ratio = 0.0; 496 double total, ratio = 0.0;
502 char cpustr[16] = { '\0', }; 497 char cpustr[16] = { '\0', };
@@ -516,19 +511,19 @@ static void abs_printout(int cpu, struct perf_evsel *counter, double avg)
516 else 511 else
517 cpu = 0; 512 cpu = 0;
518 513
519 fprintf(stderr, fmt, cpustr, avg, csv_sep, event_name(counter)); 514 fprintf(stderr, fmt, cpustr, avg, csv_sep, event_name(evsel));
520 515
521 if (csv_output) 516 if (csv_output)
522 return; 517 return;
523 518
524 if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) { 519 if (perf_evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS)) {
525 total = avg_stats(&runtime_cycles_stats[cpu]); 520 total = avg_stats(&runtime_cycles_stats[cpu]);
526 521
527 if (total) 522 if (total)
528 ratio = avg / total; 523 ratio = avg / total;
529 524
530 fprintf(stderr, " # %10.3f IPC ", ratio); 525 fprintf(stderr, " # %10.3f IPC ", ratio);
531 } else if (MATCH_EVENT(HARDWARE, HW_BRANCH_MISSES, counter) && 526 } else if (perf_evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES) &&
532 runtime_branches_stats[cpu].n != 0) { 527 runtime_branches_stats[cpu].n != 0) {
533 total = avg_stats(&runtime_branches_stats[cpu]); 528 total = avg_stats(&runtime_branches_stats[cpu]);
534 529
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 3eb3989a2110..8a5cfb656674 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -21,4 +21,8 @@ void perf_evsel__delete(struct perf_evsel *evsel);
21int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads); 21int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
22void perf_evsel__free_fd(struct perf_evsel *evsel); 22void perf_evsel__free_fd(struct perf_evsel *evsel);
23 23
24#define perf_evsel__match(evsel, t, c) \
25 (evsel->attr.type == PERF_TYPE_##t && \
26 evsel->attr.config == PERF_COUNT_##c)
27
24#endif /* __PERF_EVSEL_H */ 28#endif /* __PERF_EVSEL_H */