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> |
Jiri Olsa | a8e0232 | 2015-06-26 11:29:10 +0200 | [diff] [blame] | 6 | #include "xyarray.h" |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 7 | |
| 8 | struct stats |
| 9 | { |
| 10 | double n, mean, M2; |
David Ahern | ffe4f3c | 2013-08-02 14:05:40 -0600 | [diff] [blame] | 11 | u64 max, min; |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 12 | }; |
| 13 | |
Jiri Olsa | e2f56da | 2015-06-04 15:50:55 +0200 | [diff] [blame] | 14 | enum perf_stat_evsel_id { |
| 15 | PERF_STAT_EVSEL_ID__NONE = 0, |
Jiri Olsa | 4c358d5 | 2015-06-03 16:25:52 +0200 | [diff] [blame] | 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, |
Jiri Olsa | e2f56da | 2015-06-04 15:50:55 +0200 | [diff] [blame] | 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 | |
Jiri Olsa | f87027b | 2015-06-03 16:25:59 +0200 | [diff] [blame] | 28 | enum aggr_mode { |
| 29 | AGGR_NONE, |
| 30 | AGGR_GLOBAL, |
| 31 | AGGR_SOCKET, |
| 32 | AGGR_CORE, |
Jiri Olsa | 32b8af8 | 2015-06-26 11:29:27 +0200 | [diff] [blame] | 33 | AGGR_THREAD, |
Jiri Olsa | f87027b | 2015-06-03 16:25:59 +0200 | [diff] [blame] | 34 | }; |
| 35 | |
Jiri Olsa | 1ac77e1 | 2015-06-26 11:29:09 +0200 | [diff] [blame] | 36 | struct perf_counts_values { |
| 37 | union { |
| 38 | struct { |
| 39 | u64 val; |
| 40 | u64 ena; |
| 41 | u64 run; |
| 42 | }; |
| 43 | u64 values[3]; |
| 44 | }; |
| 45 | }; |
| 46 | |
| 47 | struct perf_counts { |
| 48 | s8 scaled; |
| 49 | struct perf_counts_values aggr; |
Jiri Olsa | 57b2891 | 2015-06-26 11:29:12 +0200 | [diff] [blame] | 50 | struct xyarray *values; |
Jiri Olsa | 1ac77e1 | 2015-06-26 11:29:09 +0200 | [diff] [blame] | 51 | }; |
| 52 | |
Jiri Olsa | 421a50f | 2015-07-21 14:31:22 +0200 | [diff] [blame] | 53 | struct perf_stat_config { |
| 54 | enum aggr_mode aggr_mode; |
Jiri Olsa | 711a572 | 2015-07-21 14:31:23 +0200 | [diff] [blame^] | 55 | bool scale; |
Jiri Olsa | 421a50f | 2015-07-21 14:31:22 +0200 | [diff] [blame] | 56 | }; |
| 57 | |
Jiri Olsa | 1ac77e1 | 2015-06-26 11:29:09 +0200 | [diff] [blame] | 58 | static inline struct perf_counts_values* |
Jiri Olsa | a6fa003 | 2015-06-26 11:29:11 +0200 | [diff] [blame] | 59 | perf_counts(struct perf_counts *counts, int cpu, int thread) |
Jiri Olsa | 1ac77e1 | 2015-06-26 11:29:09 +0200 | [diff] [blame] | 60 | { |
Jiri Olsa | 57b2891 | 2015-06-26 11:29:12 +0200 | [diff] [blame] | 61 | return xyarray__entry(counts->values, cpu, thread); |
Jiri Olsa | 1ac77e1 | 2015-06-26 11:29:09 +0200 | [diff] [blame] | 62 | } |
| 63 | |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 64 | void update_stats(struct stats *stats, u64 val); |
| 65 | double avg_stats(struct stats *stats); |
| 66 | double stddev_stats(struct stats *stats); |
| 67 | double rel_stddev_stats(double stddev, double avg); |
| 68 | |
David Ahern | ffe4f3c | 2013-08-02 14:05:40 -0600 | [diff] [blame] | 69 | static inline void init_stats(struct stats *stats) |
| 70 | { |
| 71 | stats->n = 0.0; |
| 72 | stats->mean = 0.0; |
| 73 | stats->M2 = 0.0; |
| 74 | stats->min = (u64) -1; |
| 75 | stats->max = 0; |
| 76 | } |
Jiri Olsa | e2f56da | 2015-06-04 15:50:55 +0200 | [diff] [blame] | 77 | |
| 78 | struct perf_evsel; |
Jiri Olsa | 24e34f6 | 2015-06-26 11:29:16 +0200 | [diff] [blame] | 79 | struct perf_evlist; |
| 80 | |
Jiri Olsa | e2f56da | 2015-06-04 15:50:55 +0200 | [diff] [blame] | 81 | bool __perf_evsel_stat__is(struct perf_evsel *evsel, |
| 82 | enum perf_stat_evsel_id id); |
| 83 | |
| 84 | #define perf_stat_evsel__is(evsel, id) \ |
| 85 | __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id) |
| 86 | |
| 87 | void perf_stat_evsel_id_init(struct perf_evsel *evsel); |
| 88 | |
Jiri Olsa | f87027b | 2015-06-03 16:25:59 +0200 | [diff] [blame] | 89 | extern struct stats walltime_nsecs_stats; |
| 90 | |
| 91 | void perf_stat__reset_shadow_stats(void); |
| 92 | void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, |
| 93 | int cpu); |
| 94 | void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel, |
| 95 | double avg, int cpu, enum aggr_mode aggr); |
| 96 | |
Jiri Olsa | a6fa003 | 2015-06-26 11:29:11 +0200 | [diff] [blame] | 97 | struct perf_counts *perf_counts__new(int ncpus, int nthreads); |
Jiri Olsa | 9df38e8 | 2015-06-14 10:19:27 +0200 | [diff] [blame] | 98 | void perf_counts__delete(struct perf_counts *counts); |
| 99 | |
Jiri Olsa | a8e0232 | 2015-06-26 11:29:10 +0200 | [diff] [blame] | 100 | void perf_evsel__reset_counts(struct perf_evsel *evsel); |
Jiri Olsa | a6fa003 | 2015-06-26 11:29:11 +0200 | [diff] [blame] | 101 | int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads); |
Jiri Olsa | a9a3a4d | 2015-06-14 10:19:26 +0200 | [diff] [blame] | 102 | void perf_evsel__free_counts(struct perf_evsel *evsel); |
Jiri Olsa | 9689edf | 2015-06-26 11:29:14 +0200 | [diff] [blame] | 103 | |
| 104 | void perf_evsel__reset_stat_priv(struct perf_evsel *evsel); |
| 105 | int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel); |
| 106 | void perf_evsel__free_stat_priv(struct perf_evsel *evsel); |
Jiri Olsa | a939512 | 2015-06-26 11:29:15 +0200 | [diff] [blame] | 107 | |
| 108 | int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel, |
| 109 | int ncpus, int nthreads); |
| 110 | void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel); |
Jiri Olsa | 24e34f6 | 2015-06-26 11:29:16 +0200 | [diff] [blame] | 111 | |
Jiri Olsa | a7d0a10 | 2015-06-26 11:29:17 +0200 | [diff] [blame] | 112 | int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw); |
| 113 | |
Jiri Olsa | 24e34f6 | 2015-06-26 11:29:16 +0200 | [diff] [blame] | 114 | int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw); |
| 115 | void perf_evlist__free_stats(struct perf_evlist *evlist); |
| 116 | void perf_evlist__reset_stats(struct perf_evlist *evlist); |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 117 | #endif |