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 | |
Jiri Olsa | 581cc8a | 2015-10-16 12:41:03 +0200 | [diff] [blame] | 23 | struct perf_stat_evsel { |
Jiri Olsa | e2f56da | 2015-06-04 15:50:55 +0200 | [diff] [blame] | 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 | 208df99 | 2015-10-16 12:41:04 +0200 | [diff] [blame] | 34 | AGGR_UNSET, |
Jiri Olsa | f87027b | 2015-06-03 16:25:59 +0200 | [diff] [blame] | 35 | }; |
| 36 | |
Jiri Olsa | 421a50f | 2015-07-21 14:31:22 +0200 | [diff] [blame] | 37 | struct perf_stat_config { |
| 38 | enum aggr_mode aggr_mode; |
Jiri Olsa | 711a572 | 2015-07-21 14:31:23 +0200 | [diff] [blame] | 39 | bool scale; |
Jiri Olsa | 5821522 | 2015-07-21 14:31:24 +0200 | [diff] [blame] | 40 | FILE *output; |
Jiri Olsa | ec0d3d1 | 2015-07-21 14:31:25 +0200 | [diff] [blame] | 41 | unsigned int interval; |
Jiri Olsa | 421a50f | 2015-07-21 14:31:22 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 44 | void update_stats(struct stats *stats, u64 val); |
| 45 | double avg_stats(struct stats *stats); |
| 46 | double stddev_stats(struct stats *stats); |
| 47 | double rel_stddev_stats(double stddev, double avg); |
| 48 | |
David Ahern | ffe4f3c | 2013-08-02 14:05:40 -0600 | [diff] [blame] | 49 | static inline void init_stats(struct stats *stats) |
| 50 | { |
| 51 | stats->n = 0.0; |
| 52 | stats->mean = 0.0; |
| 53 | stats->M2 = 0.0; |
| 54 | stats->min = (u64) -1; |
| 55 | stats->max = 0; |
| 56 | } |
Jiri Olsa | e2f56da | 2015-06-04 15:50:55 +0200 | [diff] [blame] | 57 | |
| 58 | struct perf_evsel; |
Jiri Olsa | 24e34f6 | 2015-06-26 11:29:16 +0200 | [diff] [blame] | 59 | struct perf_evlist; |
| 60 | |
Jiri Olsa | e2f56da | 2015-06-04 15:50:55 +0200 | [diff] [blame] | 61 | bool __perf_evsel_stat__is(struct perf_evsel *evsel, |
| 62 | enum perf_stat_evsel_id id); |
| 63 | |
| 64 | #define perf_stat_evsel__is(evsel, id) \ |
| 65 | __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id) |
| 66 | |
| 67 | void perf_stat_evsel_id_init(struct perf_evsel *evsel); |
| 68 | |
Jiri Olsa | f87027b | 2015-06-03 16:25:59 +0200 | [diff] [blame] | 69 | extern struct stats walltime_nsecs_stats; |
| 70 | |
Andi Kleen | 140aead | 2016-01-30 09:06:49 -0800 | [diff] [blame] | 71 | typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit, |
| 72 | const char *fmt, double val); |
| 73 | typedef void (*new_line_t )(void *ctx); |
| 74 | |
Andi Kleen | fb4605b | 2016-03-01 10:57:52 -0800 | [diff] [blame] | 75 | void perf_stat__init_shadow_stats(void); |
Jiri Olsa | f87027b | 2015-06-03 16:25:59 +0200 | [diff] [blame] | 76 | void perf_stat__reset_shadow_stats(void); |
| 77 | void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, |
| 78 | int cpu); |
Andi Kleen | 140aead | 2016-01-30 09:06:49 -0800 | [diff] [blame] | 79 | struct perf_stat_output_ctx { |
| 80 | void *ctx; |
| 81 | print_metric_t print_metric; |
| 82 | new_line_t new_line; |
| 83 | }; |
| 84 | |
| 85 | void perf_stat__print_shadow_stats(struct perf_evsel *evsel, |
| 86 | double avg, int cpu, |
| 87 | struct perf_stat_output_ctx *out); |
Jiri Olsa | f87027b | 2015-06-03 16:25:59 +0200 | [diff] [blame] | 88 | |
Jiri Olsa | 24e34f6 | 2015-06-26 11:29:16 +0200 | [diff] [blame] | 89 | int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw); |
| 90 | void perf_evlist__free_stats(struct perf_evlist *evlist); |
| 91 | void perf_evlist__reset_stats(struct perf_evlist *evlist); |
Jiri Olsa | f80010e | 2015-07-21 14:31:27 +0200 | [diff] [blame] | 92 | |
| 93 | int perf_stat_process_counter(struct perf_stat_config *config, |
| 94 | struct perf_evsel *counter); |
Jiri Olsa | 0ea0e35 | 2015-10-25 15:51:32 +0100 | [diff] [blame] | 95 | struct perf_tool; |
| 96 | union perf_event; |
| 97 | struct perf_session; |
| 98 | int perf_event__process_stat_event(struct perf_tool *tool, |
| 99 | union perf_event *event, |
| 100 | struct perf_session *session); |
Jiri Olsa | e08a456 | 2015-10-25 15:51:35 +0100 | [diff] [blame] | 101 | |
| 102 | size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp); |
| 103 | size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp); |
| 104 | size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp); |
Xiao Guangrong | 0007ece | 2012-09-17 16:31:14 +0800 | [diff] [blame] | 105 | #endif |