1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_EVLIST_H
3 #define __PERF_EVLIST_H 1
5 #include <linux/compiler.h>
6 #include <linux/kernel.h>
7 #include <linux/refcount.h>
8 #include <linux/list.h>
9 #include <api/fd/array.h>
10 #include <internal/evlist.h>
11 #include <internal/evsel.h>
12 #include "events_stats.h"
24 * State machine of bkw_mmap_state:
26 * .________________(forbid)_____________.
28 * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
30 * | |__(forbid)____/ |___(forbid)___/|
32 * \_________________(3)_______________/
34 * NOTREADY : Backward ring buffers are not ready
35 * RUNNING : Backward ring buffers are recording
36 * DATA_PENDING : We are required to collect data from backward ring buffers
37 * EMPTY : We have collected data from backward ring buffers.
39 * (0): Setup backward ring buffer
40 * (1): Pause ring buffers for reading
41 * (2): Read from ring buffers
42 * (3): Resume ring buffers for recording
47 BKW_MMAP_DATA_PENDING
,
52 struct perf_evlist core
;
57 u64 combined_sample_type
;
58 enum bkw_mmap_state bkw_mmap_state
;
64 struct mmap
*overwrite_mmap
;
65 struct evsel
*selected
;
66 struct events_stats stats
;
68 void (*trace_event_sample_raw
)(struct evlist
*evlist
,
69 union perf_event
*event
,
70 struct perf_sample
*sample
);
71 u64 first_sample_time
;
79 struct evsel_str_handler
{
84 struct evlist
*evlist__new(void);
85 struct evlist
*perf_evlist__new_default(void);
86 struct evlist
*perf_evlist__new_dummy(void);
87 void evlist__init(struct evlist
*evlist
, struct perf_cpu_map
*cpus
,
88 struct perf_thread_map
*threads
);
89 void evlist__exit(struct evlist
*evlist
);
90 void evlist__delete(struct evlist
*evlist
);
92 void evlist__add(struct evlist
*evlist
, struct evsel
*entry
);
93 void evlist__remove(struct evlist
*evlist
, struct evsel
*evsel
);
95 int __perf_evlist__add_default(struct evlist
*evlist
, bool precise
);
97 static inline int perf_evlist__add_default(struct evlist
*evlist
)
99 return __perf_evlist__add_default(evlist
, true);
102 int __perf_evlist__add_default_attrs(struct evlist
*evlist
,
103 struct perf_event_attr
*attrs
, size_t nr_attrs
);
105 #define perf_evlist__add_default_attrs(evlist, array) \
106 __perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
108 int perf_evlist__add_dummy(struct evlist
*evlist
);
110 int perf_evlist__add_sb_event(struct evlist
*evlist
,
111 struct perf_event_attr
*attr
,
114 void evlist__set_cb(struct evlist
*evlist
, evsel__sb_cb_t cb
, void *data
);
115 int perf_evlist__start_sb_thread(struct evlist
*evlist
,
116 struct target
*target
);
117 void perf_evlist__stop_sb_thread(struct evlist
*evlist
);
119 int perf_evlist__add_newtp(struct evlist
*evlist
,
120 const char *sys
, const char *name
, void *handler
);
122 int __evlist__set_tracepoints_handlers(struct evlist
*evlist
,
123 const struct evsel_str_handler
*assocs
,
126 #define evlist__set_tracepoints_handlers(evlist, array) \
127 __evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
129 void __perf_evlist__set_sample_bit(struct evlist
*evlist
,
130 enum perf_event_sample_format bit
);
131 void __perf_evlist__reset_sample_bit(struct evlist
*evlist
,
132 enum perf_event_sample_format bit
);
134 #define perf_evlist__set_sample_bit(evlist, bit) \
135 __perf_evlist__set_sample_bit(evlist, PERF_SAMPLE_##bit)
137 #define perf_evlist__reset_sample_bit(evlist, bit) \
138 __perf_evlist__reset_sample_bit(evlist, PERF_SAMPLE_##bit)
140 int perf_evlist__set_tp_filter(struct evlist
*evlist
, const char *filter
);
141 int perf_evlist__set_tp_filter_pid(struct evlist
*evlist
, pid_t pid
);
142 int perf_evlist__set_tp_filter_pids(struct evlist
*evlist
, size_t npids
, pid_t
*pids
);
144 int perf_evlist__append_tp_filter(struct evlist
*evlist
, const char *filter
);
146 int perf_evlist__append_tp_filter_pid(struct evlist
*evlist
, pid_t pid
);
147 int perf_evlist__append_tp_filter_pids(struct evlist
*evlist
, size_t npids
, pid_t
*pids
);
150 perf_evlist__find_tracepoint_by_id(struct evlist
*evlist
, int id
);
153 perf_evlist__find_tracepoint_by_name(struct evlist
*evlist
,
156 int evlist__add_pollfd(struct evlist
*evlist
, int fd
);
157 int evlist__filter_pollfd(struct evlist
*evlist
, short revents_and_mask
);
159 int evlist__poll(struct evlist
*evlist
, int timeout
);
161 struct evsel
*perf_evlist__id2evsel(struct evlist
*evlist
, u64 id
);
162 struct evsel
*perf_evlist__id2evsel_strict(struct evlist
*evlist
,
165 struct perf_sample_id
*perf_evlist__id2sid(struct evlist
*evlist
, u64 id
);
167 void perf_evlist__toggle_bkw_mmap(struct evlist
*evlist
, enum bkw_mmap_state state
);
169 void evlist__mmap_consume(struct evlist
*evlist
, int idx
);
171 int evlist__open(struct evlist
*evlist
);
172 void evlist__close(struct evlist
*evlist
);
174 struct callchain_param
;
176 void perf_evlist__set_id_pos(struct evlist
*evlist
);
177 void perf_evlist__config(struct evlist
*evlist
, struct record_opts
*opts
,
178 struct callchain_param
*callchain
);
179 int record_opts__config(struct record_opts
*opts
);
181 int perf_evlist__prepare_workload(struct evlist
*evlist
,
182 struct target
*target
,
183 const char *argv
[], bool pipe_output
,
184 void (*exec_error
)(int signo
, siginfo_t
*info
,
186 int perf_evlist__start_workload(struct evlist
*evlist
);
190 int __perf_evlist__parse_mmap_pages(unsigned int *mmap_pages
, const char *str
);
191 int perf_evlist__parse_mmap_pages(const struct option
*opt
,
195 unsigned long perf_event_mlock_kb_in_pages(void);
197 int evlist__mmap_ex(struct evlist
*evlist
, unsigned int pages
,
198 unsigned int auxtrace_pages
,
199 bool auxtrace_overwrite
, int nr_cblocks
,
200 int affinity
, int flush
, int comp_level
);
201 int evlist__mmap(struct evlist
*evlist
, unsigned int pages
);
202 void evlist__munmap(struct evlist
*evlist
);
204 size_t evlist__mmap_size(unsigned long pages
);
206 void evlist__disable(struct evlist
*evlist
);
207 void evlist__enable(struct evlist
*evlist
);
208 void perf_evlist__toggle_enable(struct evlist
*evlist
);
210 int perf_evlist__enable_event_idx(struct evlist
*evlist
,
211 struct evsel
*evsel
, int idx
);
213 void perf_evlist__set_selected(struct evlist
*evlist
,
214 struct evsel
*evsel
);
216 int perf_evlist__create_maps(struct evlist
*evlist
, struct target
*target
);
217 int perf_evlist__apply_filters(struct evlist
*evlist
, struct evsel
**err_evsel
);
219 void __perf_evlist__set_leader(struct list_head
*list
);
220 void perf_evlist__set_leader(struct evlist
*evlist
);
222 u64
__perf_evlist__combined_sample_type(struct evlist
*evlist
);
223 u64
perf_evlist__combined_sample_type(struct evlist
*evlist
);
224 u64
perf_evlist__combined_branch_type(struct evlist
*evlist
);
225 bool perf_evlist__sample_id_all(struct evlist
*evlist
);
226 u16
perf_evlist__id_hdr_size(struct evlist
*evlist
);
228 int perf_evlist__parse_sample(struct evlist
*evlist
, union perf_event
*event
,
229 struct perf_sample
*sample
);
231 int perf_evlist__parse_sample_timestamp(struct evlist
*evlist
,
232 union perf_event
*event
,
235 bool perf_evlist__valid_sample_type(struct evlist
*evlist
);
236 bool perf_evlist__valid_sample_id_all(struct evlist
*evlist
);
237 bool perf_evlist__valid_read_format(struct evlist
*evlist
);
239 void perf_evlist__splice_list_tail(struct evlist
*evlist
,
240 struct list_head
*list
);
242 static inline bool perf_evlist__empty(struct evlist
*evlist
)
244 return list_empty(&evlist
->core
.entries
);
247 static inline struct evsel
*evlist__first(struct evlist
*evlist
)
249 struct perf_evsel
*evsel
= perf_evlist__first(&evlist
->core
);
251 return container_of(evsel
, struct evsel
, core
);
254 static inline struct evsel
*evlist__last(struct evlist
*evlist
)
256 struct perf_evsel
*evsel
= perf_evlist__last(&evlist
->core
);
258 return container_of(evsel
, struct evsel
, core
);
261 int perf_evlist__strerror_open(struct evlist
*evlist
, int err
, char *buf
, size_t size
);
262 int perf_evlist__strerror_mmap(struct evlist
*evlist
, int err
, char *buf
, size_t size
);
264 bool perf_evlist__can_select_event(struct evlist
*evlist
, const char *str
);
265 void perf_evlist__to_front(struct evlist
*evlist
,
266 struct evsel
*move_evsel
);
269 * __evlist__for_each_entry - iterate thru all the evsels
270 * @list: list_head instance to iterate
271 * @evsel: struct evsel iterator
273 #define __evlist__for_each_entry(list, evsel) \
274 list_for_each_entry(evsel, list, core.node)
277 * evlist__for_each_entry - iterate thru all the evsels
278 * @evlist: evlist instance to iterate
279 * @evsel: struct evsel iterator
281 #define evlist__for_each_entry(evlist, evsel) \
282 __evlist__for_each_entry(&(evlist)->core.entries, evsel)
285 * __evlist__for_each_entry_continue - continue iteration thru all the evsels
286 * @list: list_head instance to iterate
287 * @evsel: struct evsel iterator
289 #define __evlist__for_each_entry_continue(list, evsel) \
290 list_for_each_entry_continue(evsel, list, core.node)
293 * evlist__for_each_entry_continue - continue iteration thru all the evsels
294 * @evlist: evlist instance to iterate
295 * @evsel: struct evsel iterator
297 #define evlist__for_each_entry_continue(evlist, evsel) \
298 __evlist__for_each_entry_continue(&(evlist)->core.entries, evsel)
301 * __evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
302 * @list: list_head instance to iterate
303 * @evsel: struct evsel iterator
305 #define __evlist__for_each_entry_reverse(list, evsel) \
306 list_for_each_entry_reverse(evsel, list, core.node)
309 * evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
310 * @evlist: evlist instance to iterate
311 * @evsel: struct evsel iterator
313 #define evlist__for_each_entry_reverse(evlist, evsel) \
314 __evlist__for_each_entry_reverse(&(evlist)->core.entries, evsel)
317 * __evlist__for_each_entry_safe - safely iterate thru all the evsels
318 * @list: list_head instance to iterate
319 * @tmp: struct evsel temp iterator
320 * @evsel: struct evsel iterator
322 #define __evlist__for_each_entry_safe(list, tmp, evsel) \
323 list_for_each_entry_safe(evsel, tmp, list, core.node)
326 * evlist__for_each_entry_safe - safely iterate thru all the evsels
327 * @evlist: evlist instance to iterate
328 * @evsel: struct evsel iterator
329 * @tmp: struct evsel temp iterator
331 #define evlist__for_each_entry_safe(evlist, tmp, evsel) \
332 __evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)
334 #define evlist__for_each_cpu(evlist, index, cpu) \
335 evlist__cpu_iter_start(evlist); \
336 perf_cpu_map__for_each_cpu (cpu, index, (evlist)->core.all_cpus)
338 void perf_evlist__set_tracking_event(struct evlist
*evlist
,
339 struct evsel
*tracking_evsel
);
341 void evlist__cpu_iter_start(struct evlist
*evlist
);
342 bool evsel__cpu_iter_skip(struct evsel
*ev
, int cpu
);
343 bool evsel__cpu_iter_skip_no_inc(struct evsel
*ev
, int cpu
);
346 perf_evlist__find_evsel_by_str(struct evlist
*evlist
, const char *str
);
348 struct evsel
*perf_evlist__event2evsel(struct evlist
*evlist
,
349 union perf_event
*event
);
351 bool perf_evlist__exclude_kernel(struct evlist
*evlist
);
353 void perf_evlist__force_leader(struct evlist
*evlist
);
355 struct evsel
*perf_evlist__reset_weak_group(struct evlist
*evlist
,
358 #endif /* __PERF_EVLIST_H */