]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
0007ecea XG |
2 | #ifndef __PERF_STATS_H |
3 | #define __PERF_STATS_H | |
4 | ||
d944c4ee | 5 | #include <linux/types.h> |
f87027b9 | 6 | #include <stdio.h> |
a8e02324 | 7 | #include "xyarray.h" |
0007ecea XG |
8 | |
9 | struct stats | |
10 | { | |
11 | double n, mean, M2; | |
ffe4f3c0 | 12 | u64 max, min; |
0007ecea XG |
13 | }; |
14 | ||
e2f56da1 JO |
15 | enum perf_stat_evsel_id { |
16 | PERF_STAT_EVSEL_ID__NONE = 0, | |
4c358d5c JO |
17 | PERF_STAT_EVSEL_ID__CYCLES_IN_TX, |
18 | PERF_STAT_EVSEL_ID__TRANSACTION_START, | |
19 | PERF_STAT_EVSEL_ID__ELISION_START, | |
20 | PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP, | |
239bd47f AK |
21 | PERF_STAT_EVSEL_ID__TOPDOWN_TOTAL_SLOTS, |
22 | PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_ISSUED, | |
23 | PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_RETIRED, | |
24 | PERF_STAT_EVSEL_ID__TOPDOWN_FETCH_BUBBLES, | |
25 | PERF_STAT_EVSEL_ID__TOPDOWN_RECOVERY_BUBBLES, | |
daefd0bc KL |
26 | PERF_STAT_EVSEL_ID__SMI_NUM, |
27 | PERF_STAT_EVSEL_ID__APERF, | |
e2f56da1 JO |
28 | PERF_STAT_EVSEL_ID__MAX, |
29 | }; | |
30 | ||
581cc8a2 | 31 | struct perf_stat_evsel { |
f7794d52 JO |
32 | struct stats res_stats[3]; |
33 | enum perf_stat_evsel_id id; | |
34 | u64 *group_data; | |
e2f56da1 JO |
35 | }; |
36 | ||
f87027b9 JO |
37 | enum aggr_mode { |
38 | AGGR_NONE, | |
39 | AGGR_GLOBAL, | |
40 | AGGR_SOCKET, | |
41 | AGGR_CORE, | |
32b8af82 | 42 | AGGR_THREAD, |
208df99e | 43 | AGGR_UNSET, |
f87027b9 JO |
44 | }; |
45 | ||
421a50f3 JO |
46 | struct perf_stat_config { |
47 | enum aggr_mode aggr_mode; | |
711a572e | 48 | bool scale; |
5821522e | 49 | FILE *output; |
ec0d3d1f | 50 | unsigned int interval; |
421a50f3 JO |
51 | }; |
52 | ||
0007ecea XG |
53 | void update_stats(struct stats *stats, u64 val); |
54 | double avg_stats(struct stats *stats); | |
55 | double stddev_stats(struct stats *stats); | |
56 | double rel_stddev_stats(double stddev, double avg); | |
57 | ||
ffe4f3c0 DA |
58 | static inline void init_stats(struct stats *stats) |
59 | { | |
60 | stats->n = 0.0; | |
61 | stats->mean = 0.0; | |
62 | stats->M2 = 0.0; | |
63 | stats->min = (u64) -1; | |
64 | stats->max = 0; | |
65 | } | |
e2f56da1 JO |
66 | |
67 | struct perf_evsel; | |
24e34f68 JO |
68 | struct perf_evlist; |
69 | ||
e2f56da1 JO |
70 | bool __perf_evsel_stat__is(struct perf_evsel *evsel, |
71 | enum perf_stat_evsel_id id); | |
72 | ||
73 | #define perf_stat_evsel__is(evsel, id) \ | |
74 | __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id) | |
75 | ||
76 | void perf_stat_evsel_id_init(struct perf_evsel *evsel); | |
77 | ||
f87027b9 JO |
78 | extern struct stats walltime_nsecs_stats; |
79 | ||
140aeadc AK |
80 | typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit, |
81 | const char *fmt, double val); | |
82 | typedef void (*new_line_t )(void *ctx); | |
83 | ||
fb4605ba | 84 | void perf_stat__init_shadow_stats(void); |
f87027b9 JO |
85 | void perf_stat__reset_shadow_stats(void); |
86 | void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, | |
87 | int cpu); | |
140aeadc AK |
88 | struct perf_stat_output_ctx { |
89 | void *ctx; | |
90 | print_metric_t print_metric; | |
91 | new_line_t new_line; | |
37932c18 | 92 | bool force_header; |
140aeadc AK |
93 | }; |
94 | ||
95 | void perf_stat__print_shadow_stats(struct perf_evsel *evsel, | |
96 | double avg, int cpu, | |
97 | struct perf_stat_output_ctx *out); | |
37932c18 | 98 | void perf_stat__collect_metric_expr(struct perf_evlist *); |
f87027b9 | 99 | |
24e34f68 JO |
100 | int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw); |
101 | void perf_evlist__free_stats(struct perf_evlist *evlist); | |
102 | void perf_evlist__reset_stats(struct perf_evlist *evlist); | |
f80010eb JO |
103 | |
104 | int perf_stat_process_counter(struct perf_stat_config *config, | |
105 | struct perf_evsel *counter); | |
0ea0e355 JO |
106 | struct perf_tool; |
107 | union perf_event; | |
108 | struct perf_session; | |
109 | int perf_event__process_stat_event(struct perf_tool *tool, | |
110 | union perf_event *event, | |
111 | struct perf_session *session); | |
e08a4564 JO |
112 | |
113 | size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp); | |
114 | size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp); | |
115 | size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp); | |
0007ecea | 116 | #endif |