perf evlist: Move evlist methods to evlist.c
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / tools / perf / util / evsel.h
1 #ifndef __PERF_EVSEL_H
2 #define __PERF_EVSEL_H 1
3
4 #include <linux/list.h>
5 #include <stdbool.h>
6 #include "../../../include/linux/perf_event.h"
7 #include "types.h"
8 #include "xyarray.h"
9
10 struct perf_counts_values {
11 union {
12 struct {
13 u64 val;
14 u64 ena;
15 u64 run;
16 };
17 u64 values[3];
18 };
19 };
20
21 struct perf_counts {
22 s8 scaled;
23 struct perf_counts_values aggr;
24 struct perf_counts_values cpu[];
25 };
26
27 struct perf_evsel;
28
29 /*
30 * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
31 * more than one entry in the evlist.
32 */
33 struct perf_sample_id {
34 struct hlist_node node;
35 u64 id;
36 struct perf_evsel *evsel;
37 };
38
39 struct perf_evsel {
40 struct list_head node;
41 struct perf_event_attr attr;
42 char *filter;
43 struct xyarray *fd;
44 struct xyarray *id;
45 struct perf_counts *counts;
46 int idx;
47 void *priv;
48 };
49
50 struct cpu_map;
51 struct thread_map;
52 struct perf_evlist;
53
54 struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
55 void perf_evsel__init(struct perf_evsel *evsel,
56 struct perf_event_attr *attr, int idx);
57 void perf_evsel__exit(struct perf_evsel *evsel);
58 void perf_evsel__delete(struct perf_evsel *evsel);
59
60 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
61 int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
62 int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
63 void perf_evsel__free_fd(struct perf_evsel *evsel);
64 void perf_evsel__free_id(struct perf_evsel *evsel);
65 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
66
67 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
68 struct cpu_map *cpus, bool group, bool inherit);
69 int perf_evsel__open_per_thread(struct perf_evsel *evsel,
70 struct thread_map *threads, bool group, bool inherit);
71 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
72 struct thread_map *threads, bool group, bool inherit);
73
74 #define perf_evsel__match(evsel, t, c) \
75 (evsel->attr.type == PERF_TYPE_##t && \
76 evsel->attr.config == PERF_COUNT_##c)
77
78 int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
79 int cpu, int thread, bool scale);
80
81 /**
82 * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
83 *
84 * @evsel - event selector to read value
85 * @cpu - CPU of interest
86 * @thread - thread of interest
87 */
88 static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
89 int cpu, int thread)
90 {
91 return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
92 }
93
94 /**
95 * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
96 *
97 * @evsel - event selector to read value
98 * @cpu - CPU of interest
99 * @thread - thread of interest
100 */
101 static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
102 int cpu, int thread)
103 {
104 return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
105 }
106
107 int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
108 bool scale);
109
110 /**
111 * perf_evsel__read - Read the aggregate results on all CPUs
112 *
113 * @evsel - event selector to read value
114 * @ncpus - Number of cpus affected, from zero
115 * @nthreads - Number of threads affected, from zero
116 */
117 static inline int perf_evsel__read(struct perf_evsel *evsel,
118 int ncpus, int nthreads)
119 {
120 return __perf_evsel__read(evsel, ncpus, nthreads, false);
121 }
122
123 /**
124 * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
125 *
126 * @evsel - event selector to read value
127 * @ncpus - Number of cpus affected, from zero
128 * @nthreads - Number of threads affected, from zero
129 */
130 static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
131 int ncpus, int nthreads)
132 {
133 return __perf_evsel__read(evsel, ncpus, nthreads, true);
134 }
135
136 #endif /* __PERF_EVSEL_H */