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