1 #ifndef __PERF_STATS_H 2 #define __PERF_STATS_H 3 4 #include <linux/types.h> 5 #include <stdio.h> 6 #include "xyarray.h" 7 8 struct stats 9 { 10 double n, mean, M2; 11 u64 max, min; 12 }; 13 14 enum perf_stat_evsel_id { 15 PERF_STAT_EVSEL_ID__NONE = 0, 16 PERF_STAT_EVSEL_ID__CYCLES_IN_TX, 17 PERF_STAT_EVSEL_ID__TRANSACTION_START, 18 PERF_STAT_EVSEL_ID__ELISION_START, 19 PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP, 20 PERF_STAT_EVSEL_ID__MAX, 21 }; 22 23 struct perf_stat { 24 struct stats res_stats[3]; 25 enum perf_stat_evsel_id id; 26 }; 27 28 enum aggr_mode { 29 AGGR_NONE, 30 AGGR_GLOBAL, 31 AGGR_SOCKET, 32 AGGR_CORE, 33 AGGR_THREAD, 34 }; 35 36 struct perf_stat_config { 37 enum aggr_mode aggr_mode; 38 bool scale; 39 FILE *output; 40 unsigned int interval; 41 }; 42 43 void update_stats(struct stats *stats, u64 val); 44 double avg_stats(struct stats *stats); 45 double stddev_stats(struct stats *stats); 46 double rel_stddev_stats(double stddev, double avg); 47 48 static inline void init_stats(struct stats *stats) 49 { 50 stats->n = 0.0; 51 stats->mean = 0.0; 52 stats->M2 = 0.0; 53 stats->min = (u64) -1; 54 stats->max = 0; 55 } 56 57 struct perf_evsel; 58 struct perf_evlist; 59 60 bool __perf_evsel_stat__is(struct perf_evsel *evsel, 61 enum perf_stat_evsel_id id); 62 63 #define perf_stat_evsel__is(evsel, id) \ 64 __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id) 65 66 void perf_stat_evsel_id_init(struct perf_evsel *evsel); 67 68 extern struct stats walltime_nsecs_stats; 69 70 void perf_stat__reset_shadow_stats(void); 71 void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, 72 int cpu); 73 void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel, 74 double avg, int cpu, enum aggr_mode aggr); 75 76 void perf_evsel__reset_stat_priv(struct perf_evsel *evsel); 77 int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel); 78 void perf_evsel__free_stat_priv(struct perf_evsel *evsel); 79 80 int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel, 81 int ncpus, int nthreads); 82 void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel); 83 84 int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw); 85 86 int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw); 87 void perf_evlist__free_stats(struct perf_evlist *evlist); 88 void perf_evlist__reset_stats(struct perf_evlist *evlist); 89 90 int perf_stat_process_counter(struct perf_stat_config *config, 91 struct perf_evsel *counter); 92 #endif 93