1 #ifndef __PERF_STATS_H 2 #define __PERF_STATS_H 3 4 #include <linux/types.h> 5 #include <stdio.h> 6 7 struct stats 8 { 9 double n, mean, M2; 10 u64 max, min; 11 }; 12 13 enum perf_stat_evsel_id { 14 PERF_STAT_EVSEL_ID__NONE = 0, 15 PERF_STAT_EVSEL_ID__CYCLES_IN_TX, 16 PERF_STAT_EVSEL_ID__TRANSACTION_START, 17 PERF_STAT_EVSEL_ID__ELISION_START, 18 PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP, 19 PERF_STAT_EVSEL_ID__MAX, 20 }; 21 22 struct perf_stat { 23 struct stats res_stats[3]; 24 enum perf_stat_evsel_id id; 25 }; 26 27 enum aggr_mode { 28 AGGR_NONE, 29 AGGR_GLOBAL, 30 AGGR_SOCKET, 31 AGGR_CORE, 32 }; 33 34 void update_stats(struct stats *stats, u64 val); 35 double avg_stats(struct stats *stats); 36 double stddev_stats(struct stats *stats); 37 double rel_stddev_stats(double stddev, double avg); 38 39 static inline void init_stats(struct stats *stats) 40 { 41 stats->n = 0.0; 42 stats->mean = 0.0; 43 stats->M2 = 0.0; 44 stats->min = (u64) -1; 45 stats->max = 0; 46 } 47 48 struct perf_evsel; 49 bool __perf_evsel_stat__is(struct perf_evsel *evsel, 50 enum perf_stat_evsel_id id); 51 52 #define perf_stat_evsel__is(evsel, id) \ 53 __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id) 54 55 void perf_stat_evsel_id_init(struct perf_evsel *evsel); 56 57 extern struct stats walltime_nsecs_stats; 58 59 void perf_stat__reset_shadow_stats(void); 60 void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, 61 int cpu); 62 void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel, 63 double avg, int cpu, enum aggr_mode aggr); 64 65 struct perf_counts *perf_counts__new(int ncpus); 66 void perf_counts__delete(struct perf_counts *counts); 67 68 void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus); 69 int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus); 70 void perf_evsel__free_counts(struct perf_evsel *evsel); 71 #endif 72