]>
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 | ||
23 | struct perf_stat { | |
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, |
f87027b9 JO |
34 | }; |
35 | ||
1ac77e1c JO |
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; | |
57b28915 | 50 | struct xyarray *values; |
1ac77e1c JO |
51 | }; |
52 | ||
421a50f3 JO |
53 | struct perf_stat_config { |
54 | enum aggr_mode aggr_mode; | |
711a572e | 55 | bool scale; |
5821522e | 56 | FILE *output; |
ec0d3d1f | 57 | unsigned int interval; |
421a50f3 JO |
58 | }; |
59 | ||
1ac77e1c | 60 | static inline struct perf_counts_values* |
a6fa0038 | 61 | perf_counts(struct perf_counts *counts, int cpu, int thread) |
1ac77e1c | 62 | { |
57b28915 | 63 | return xyarray__entry(counts->values, cpu, thread); |
1ac77e1c JO |
64 | } |
65 | ||
0007ecea XG |
66 | void update_stats(struct stats *stats, u64 val); |
67 | double avg_stats(struct stats *stats); | |
68 | double stddev_stats(struct stats *stats); | |
69 | double rel_stddev_stats(double stddev, double avg); | |
70 | ||
ffe4f3c0 DA |
71 | static inline void init_stats(struct stats *stats) |
72 | { | |
73 | stats->n = 0.0; | |
74 | stats->mean = 0.0; | |
75 | stats->M2 = 0.0; | |
76 | stats->min = (u64) -1; | |
77 | stats->max = 0; | |
78 | } | |
e2f56da1 JO |
79 | |
80 | struct perf_evsel; | |
24e34f68 JO |
81 | struct perf_evlist; |
82 | ||
e2f56da1 JO |
83 | bool __perf_evsel_stat__is(struct perf_evsel *evsel, |
84 | enum perf_stat_evsel_id id); | |
85 | ||
86 | #define perf_stat_evsel__is(evsel, id) \ | |
87 | __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id) | |
88 | ||
89 | void perf_stat_evsel_id_init(struct perf_evsel *evsel); | |
90 | ||
f87027b9 JO |
91 | extern struct stats walltime_nsecs_stats; |
92 | ||
93 | void perf_stat__reset_shadow_stats(void); | |
94 | void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, | |
95 | int cpu); | |
96 | void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel, | |
97 | double avg, int cpu, enum aggr_mode aggr); | |
98 | ||
a6fa0038 | 99 | struct perf_counts *perf_counts__new(int ncpus, int nthreads); |
9df38e82 JO |
100 | void perf_counts__delete(struct perf_counts *counts); |
101 | ||
a8e02324 | 102 | void perf_evsel__reset_counts(struct perf_evsel *evsel); |
a6fa0038 | 103 | int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads); |
a9a3a4d9 | 104 | void perf_evsel__free_counts(struct perf_evsel *evsel); |
9689edfa JO |
105 | |
106 | void perf_evsel__reset_stat_priv(struct perf_evsel *evsel); | |
107 | int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel); | |
108 | void perf_evsel__free_stat_priv(struct perf_evsel *evsel); | |
a939512d JO |
109 | |
110 | int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel, | |
111 | int ncpus, int nthreads); | |
112 | void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel); | |
24e34f68 | 113 | |
a7d0a102 JO |
114 | int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw); |
115 | ||
24e34f68 JO |
116 | int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw); |
117 | void perf_evlist__free_stats(struct perf_evlist *evlist); | |
118 | void perf_evlist__reset_stats(struct perf_evlist *evlist); | |
0007ecea | 119 | #endif |