2 #define __PERF_EVSEL_H 1
4 #include <linux/list.h>
7 #include <linux/perf_event.h>
14 struct perf_counts_values {
27 struct perf_counts_values aggr;
28 struct perf_counts_values cpu[];
34 * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
35 * more than one entry in the evlist.
37 struct perf_sample_id {
38 struct hlist_node node;
40 struct perf_evsel *evsel;
43 /** struct perf_evsel - event selector
45 * @name - Can be set to retain the original event name passed by the user,
46 * so that when showing results in tools such as 'perf stat', we
47 * show the name used, not some alias.
50 struct list_head node;
51 struct perf_event_attr attr;
54 struct xyarray *sample_id;
56 struct perf_counts *counts;
57 struct perf_counts *prev_raw_counts;
62 struct event_format *tp_format;
67 struct cgroup_sel *cgrp;
73 unsigned int sample_size;
76 /* parse modifier helper */
79 struct perf_evsel *leader;
83 #define hists_to_evsel(h) container_of(h, struct perf_evsel, hists)
88 struct perf_record_opts;
90 struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
91 struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name, int idx);
93 struct event_format *event_format__new(const char *sys, const char *name);
95 void perf_evsel__init(struct perf_evsel *evsel,
96 struct perf_event_attr *attr, int idx);
97 void perf_evsel__exit(struct perf_evsel *evsel);
98 void perf_evsel__delete(struct perf_evsel *evsel);
100 void perf_evsel__config(struct perf_evsel *evsel,
101 struct perf_record_opts *opts);
103 bool perf_evsel__is_cache_op_valid(u8 type, u8 op);
105 #define PERF_EVSEL__MAX_ALIASES 8
107 extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
108 [PERF_EVSEL__MAX_ALIASES];
109 extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
110 [PERF_EVSEL__MAX_ALIASES];
111 extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
112 [PERF_EVSEL__MAX_ALIASES];
113 extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX];
114 extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX];
115 int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
116 char *bf, size_t size);
117 const char *perf_evsel__name(struct perf_evsel *evsel);
118 const char *perf_evsel__group_name(struct perf_evsel *evsel);
119 int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size);
121 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
122 int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
123 int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
124 void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus);
125 void perf_evsel__free_fd(struct perf_evsel *evsel);
126 void perf_evsel__free_id(struct perf_evsel *evsel);
127 void perf_evsel__free_counts(struct perf_evsel *evsel);
128 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
130 void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
131 enum perf_event_sample_format bit);
132 void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel,
133 enum perf_event_sample_format bit);
135 #define perf_evsel__set_sample_bit(evsel, bit) \
136 __perf_evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
138 #define perf_evsel__reset_sample_bit(evsel, bit) \
139 __perf_evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
141 void perf_evsel__set_sample_id(struct perf_evsel *evsel);
143 int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
146 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
147 struct cpu_map *cpus);
148 int perf_evsel__open_per_thread(struct perf_evsel *evsel,
149 struct thread_map *threads);
150 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
151 struct thread_map *threads);
152 void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
156 void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
158 u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
161 static inline char *perf_evsel__strval(struct perf_evsel *evsel,
162 struct perf_sample *sample,
165 return perf_evsel__rawptr(evsel, sample, name);
170 struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
172 #define perf_evsel__match(evsel, t, c) \
173 (evsel->attr.type == PERF_TYPE_##t && \
174 evsel->attr.config == PERF_COUNT_##c)
176 static inline bool perf_evsel__match2(struct perf_evsel *e1,
177 struct perf_evsel *e2)
179 return (e1->attr.type == e2->attr.type) &&
180 (e1->attr.config == e2->attr.config);
183 int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
184 int cpu, int thread, bool scale);
187 * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
189 * @evsel - event selector to read value
190 * @cpu - CPU of interest
191 * @thread - thread of interest
193 static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
196 return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
200 * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
202 * @evsel - event selector to read value
203 * @cpu - CPU of interest
204 * @thread - thread of interest
206 static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
209 return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
212 int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
216 * perf_evsel__read - Read the aggregate results on all CPUs
218 * @evsel - event selector to read value
219 * @ncpus - Number of cpus affected, from zero
220 * @nthreads - Number of threads affected, from zero
222 static inline int perf_evsel__read(struct perf_evsel *evsel,
223 int ncpus, int nthreads)
225 return __perf_evsel__read(evsel, ncpus, nthreads, false);
229 * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
231 * @evsel - event selector to read value
232 * @ncpus - Number of cpus affected, from zero
233 * @nthreads - Number of threads affected, from zero
235 static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
236 int ncpus, int nthreads)
238 return __perf_evsel__read(evsel, ncpus, nthreads, true);
241 void hists__init(struct hists *hists);
243 int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
244 struct perf_sample *sample);
246 static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
248 return list_entry(evsel->node.next, struct perf_evsel, node);
252 * perf_evsel__is_group_leader - Return whether given evsel is a leader event
254 * @evsel - evsel selector to be tested
256 * Return %true if @evsel is a group leader or a stand-alone event
258 static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
260 return evsel->leader == evsel;
264 * perf_evsel__is_group_event - Return whether given evsel is a group event
266 * @evsel - evsel selector to be tested
268 * Return %true iff event group view is enabled and @evsel is a actual group
269 * leader which has other members in the group
271 static inline bool perf_evsel__is_group_event(struct perf_evsel *evsel)
273 if (!symbol_conf.event_group)
276 return perf_evsel__is_group_leader(evsel) && evsel->nr_members > 1;
279 struct perf_attr_details {
285 int perf_evsel__fprintf(struct perf_evsel *evsel,
286 struct perf_attr_details *details, FILE *fp);
288 bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
289 char *msg, size_t msgsize);
290 int perf_evsel__open_strerror(struct perf_evsel *evsel,
291 struct perf_target *target,
292 int err, char *msg, size_t size);
294 static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
296 return evsel->idx - evsel->leader->idx;
299 #define for_each_group_member(_evsel, _leader) \
300 for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); \
301 (_evsel) && (_evsel)->leader == (_leader); \
302 (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
304 #endif /* __PERF_EVSEL_H */