Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 1 | #ifndef __PERF_STATS_H |
| 2 | #define __PERF_STATS_H |
| 3 | |
Borislav Petkov | d944c4e | 2014-04-25 21:31:02 +0200 | [diff] [blame] | 4 | #include <linux/types.h> |
Jiri Olsa | f87027b | 2015-06-03 16:25:59 +0200 | [diff] [blame] | 5 | #include <stdio.h> |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 6 | |
| 7 | struct stats |
| 8 | { |
| 9 | double n, mean, M2; |
David Ahern | ffe4f3c | 2013-08-02 14:05:40 -0600 | [diff] [blame] | 10 | u64 max, min; |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 11 | }; |
| 12 | |
Jiri Olsa | e2f56da | 2015-06-04 15:50:55 +0200 | [diff] [blame] | 13 | enum perf_stat_evsel_id { |
| 14 | PERF_STAT_EVSEL_ID__NONE = 0, |
Jiri Olsa | 4c358d5 | 2015-06-03 16:25:52 +0200 | [diff] [blame] | 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, |
Jiri Olsa | e2f56da | 2015-06-04 15:50:55 +0200 | [diff] [blame] | 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 | |
Jiri Olsa | f87027b | 2015-06-03 16:25:59 +0200 | [diff] [blame] | 27 | enum aggr_mode { |
| 28 | AGGR_NONE, |
| 29 | AGGR_GLOBAL, |
| 30 | AGGR_SOCKET, |
| 31 | AGGR_CORE, |
| 32 | }; |
| 33 | |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 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 | |
David Ahern | ffe4f3c | 2013-08-02 14:05:40 -0600 | [diff] [blame] | 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 | } |
Jiri Olsa | e2f56da | 2015-06-04 15:50:55 +0200 | [diff] [blame] | 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 | |
Jiri Olsa | f87027b | 2015-06-03 16:25:59 +0200 | [diff] [blame] | 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 | |
Jiri Olsa | 9df38e8 | 2015-06-14 10:19:27 +0200 | [diff] [blame^] | 65 | struct perf_counts *perf_counts__new(int ncpus); |
| 66 | void perf_counts__delete(struct perf_counts *counts); |
| 67 | |
Jiri Olsa | a9a3a4d | 2015-06-14 10:19:26 +0200 | [diff] [blame] | 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); |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 71 | #endif |