Commit | Line | Data |
---|---|---|
0007ecea XG |
1 | #ifndef __PERF_STATS_H |
2 | #define __PERF_STATS_H | |
3 | ||
d944c4ee | 4 | #include <linux/types.h> |
f87027b9 | 5 | #include <stdio.h> |
a8e02324 | 6 | #include "xyarray.h" |
0007ecea XG |
7 | |
8 | struct stats | |
9 | { | |
10 | double n, mean, M2; | |
ffe4f3c0 | 11 | u64 max, min; |
0007ecea XG |
12 | }; |
13 | ||
e2f56da1 JO |
14 | enum perf_stat_evsel_id { |
15 | PERF_STAT_EVSEL_ID__NONE = 0, | |
4c358d5c JO |
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, | |
e2f56da1 JO |
20 | PERF_STAT_EVSEL_ID__MAX, |
21 | }; | |
22 | ||
581cc8a2 | 23 | struct perf_stat_evsel { |
e2f56da1 JO |
24 | struct stats res_stats[3]; |
25 | enum perf_stat_evsel_id id; | |
26 | }; | |
27 | ||
f87027b9 JO |
28 | enum aggr_mode { |
29 | AGGR_NONE, | |
30 | AGGR_GLOBAL, | |
31 | AGGR_SOCKET, | |
32 | AGGR_CORE, | |
32b8af82 | 33 | AGGR_THREAD, |
208df99e | 34 | AGGR_UNSET, |
f87027b9 JO |
35 | }; |
36 | ||
421a50f3 JO |
37 | struct perf_stat_config { |
38 | enum aggr_mode aggr_mode; | |
711a572e | 39 | bool scale; |
5821522e | 40 | FILE *output; |
ec0d3d1f | 41 | unsigned int interval; |
421a50f3 JO |
42 | }; |
43 | ||
0007ecea XG |
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 | ||
ffe4f3c0 DA |
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 | } | |
e2f56da1 JO |
57 | |
58 | struct perf_evsel; | |
24e34f68 JO |
59 | struct perf_evlist; |
60 | ||
e2f56da1 JO |
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 | ||
f87027b9 JO |
69 | extern struct stats walltime_nsecs_stats; |
70 | ||
140aeadc AK |
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 | ||
fb4605ba | 75 | void perf_stat__init_shadow_stats(void); |
f87027b9 JO |
76 | void perf_stat__reset_shadow_stats(void); |
77 | void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, | |
78 | int cpu); | |
140aeadc AK |
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); | |
f87027b9 | 88 | |
24e34f68 JO |
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); | |
f80010eb JO |
92 | |
93 | int perf_stat_process_counter(struct perf_stat_config *config, | |
94 | struct perf_evsel *counter); | |
0ea0e355 JO |
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); | |
e08a4564 JO |
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); | |
0007ecea | 105 | #endif |