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, | |
33 | }; | |
34 | ||
1ac77e1c JO |
35 | struct perf_counts_values { |
36 | union { | |
37 | struct { | |
38 | u64 val; | |
39 | u64 ena; | |
40 | u64 run; | |
41 | }; | |
42 | u64 values[3]; | |
43 | }; | |
44 | }; | |
45 | ||
46 | struct perf_counts { | |
47 | s8 scaled; | |
48 | struct perf_counts_values aggr; | |
57b28915 | 49 | struct xyarray *values; |
1ac77e1c JO |
50 | }; |
51 | ||
52 | static inline struct perf_counts_values* | |
a6fa0038 | 53 | perf_counts(struct perf_counts *counts, int cpu, int thread) |
1ac77e1c | 54 | { |
57b28915 | 55 | return xyarray__entry(counts->values, cpu, thread); |
1ac77e1c JO |
56 | } |
57 | ||
0007ecea XG |
58 | void update_stats(struct stats *stats, u64 val); |
59 | double avg_stats(struct stats *stats); | |
60 | double stddev_stats(struct stats *stats); | |
61 | double rel_stddev_stats(double stddev, double avg); | |
62 | ||
ffe4f3c0 DA |
63 | static inline void init_stats(struct stats *stats) |
64 | { | |
65 | stats->n = 0.0; | |
66 | stats->mean = 0.0; | |
67 | stats->M2 = 0.0; | |
68 | stats->min = (u64) -1; | |
69 | stats->max = 0; | |
70 | } | |
e2f56da1 JO |
71 | |
72 | struct perf_evsel; | |
73 | bool __perf_evsel_stat__is(struct perf_evsel *evsel, | |
74 | enum perf_stat_evsel_id id); | |
75 | ||
76 | #define perf_stat_evsel__is(evsel, id) \ | |
77 | __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id) | |
78 | ||
79 | void perf_stat_evsel_id_init(struct perf_evsel *evsel); | |
80 | ||
f87027b9 JO |
81 | extern struct stats walltime_nsecs_stats; |
82 | ||
83 | void perf_stat__reset_shadow_stats(void); | |
84 | void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, | |
85 | int cpu); | |
86 | void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel, | |
87 | double avg, int cpu, enum aggr_mode aggr); | |
88 | ||
a6fa0038 | 89 | struct perf_counts *perf_counts__new(int ncpus, int nthreads); |
9df38e82 JO |
90 | void perf_counts__delete(struct perf_counts *counts); |
91 | ||
a8e02324 | 92 | void perf_evsel__reset_counts(struct perf_evsel *evsel); |
a6fa0038 | 93 | int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads); |
a9a3a4d9 | 94 | void perf_evsel__free_counts(struct perf_evsel *evsel); |
0007ecea | 95 | #endif |