]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - tools/perf/util/evlist.h
perf evlist: Fix the class prefix for 'struct evlist' strerror methods
[mirror_ubuntu-hirsute-kernel.git] / tools / perf / util / evlist.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
361c99a6
ACM
2#ifndef __PERF_EVLIST_H
3#define __PERF_EVLIST_H 1
4
5c97cac6 5#include <linux/compiler.h>
877a7a11 6#include <linux/kernel.h>
25a3720c 7#include <linux/refcount.h>
361c99a6 8#include <linux/list.h>
1b85337d 9#include <api/fd/array.h>
ce9036a6 10#include <internal/evlist.h>
515dbe48 11#include <internal/evsel.h>
47729258 12#include "events_stats.h"
0c21f736 13#include "evsel.h"
e0fcfb08 14#include <pthread.h>
9607ad3a 15#include <signal.h>
35b9d88e 16#include <unistd.h>
361c99a6 17
5c581041 18struct pollfd;
f8a95309 19struct thread_map;
f854839b 20struct perf_cpu_map;
b4006796 21struct record_opts;
5c581041 22
e0fcfb08
ACM
23/*
24 * State machine of bkw_mmap_state:
25 *
26 * .________________(forbid)_____________.
27 * | V
28 * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
29 * ^ ^ | ^ |
30 * | |__(forbid)____/ |___(forbid)___/|
31 * | |
32 * \_________________(3)_______________/
33 *
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.
38 *
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
43 */
44enum bkw_mmap_state {
45 BKW_MMAP_NOTREADY,
46 BKW_MMAP_RUNNING,
47 BKW_MMAP_DATA_PENDING,
48 BKW_MMAP_EMPTY,
49};
50
63503dba 51struct evlist {
ce9036a6 52 struct perf_evlist core;
97f63e4a 53 int nr_groups;
2b56bcfb 54 bool enabled;
75562573
AH
55 int id_pos;
56 int is_pos;
57 u64 combined_sample_type;
54cc54de 58 enum bkw_mmap_state bkw_mmap_state;
35b9d88e
ACM
59 struct {
60 int cork_fd;
61 pid_t pid;
62 } workload;
a5830532
JO
63 struct mmap *mmap;
64 struct mmap *overwrite_mmap;
32dcd021 65 struct evsel *selected;
75be989a 66 struct events_stats stats;
2c07144d 67 struct perf_env *env;
63503dba 68 void (*trace_event_sample_raw)(struct evlist *evlist,
93115d32
TR
69 union perf_event *event,
70 struct perf_sample *sample);
6011518d
JY
71 u64 first_sample_time;
72 u64 last_sample_time;
657ee553
SL
73 struct {
74 pthread_t th;
75 volatile int done;
76 } thread;
361c99a6
ACM
77};
78
32dcd021 79struct evsel_str_handler {
ee29be62
ACM
80 const char *name;
81 void *handler;
82};
83
0f98b11c 84struct evlist *evlist__new(void);
63503dba
JO
85struct evlist *perf_evlist__new_default(void);
86struct evlist *perf_evlist__new_dummy(void);
52c86bca
JO
87void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
88 struct perf_thread_map *threads);
470579b0 89void evlist__exit(struct evlist *evlist);
c12995a5 90void evlist__delete(struct evlist *evlist);
361c99a6 91
a1cf3a75 92void evlist__add(struct evlist *evlist, struct evsel *entry);
16251027 93void evlist__remove(struct evlist *evlist, struct evsel *evsel);
db918acb 94
e251abee 95int __evlist__add_default(struct evlist *evlist, bool precise);
db918acb 96
e251abee 97static inline int evlist__add_default(struct evlist *evlist)
db918acb 98{
e251abee 99 return __evlist__add_default(evlist, true);
db918acb
ACM
100}
101
e251abee 102int __evlist__add_default_attrs(struct evlist *evlist,
79695e1b 103 struct perf_event_attr *attrs, size_t nr_attrs);
e60fc847 104
e251abee
ACM
105#define evlist__add_default_attrs(evlist, array) \
106 __evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
361c99a6 107
e251abee 108int evlist__add_dummy(struct evlist *evlist);
5bae0250 109
b38d85ef 110int perf_evlist__add_sb_event(struct evlist *evlist,
657ee553 111 struct perf_event_attr *attr,
65ddce3f 112 evsel__sb_cb_t cb,
657ee553 113 void *data);
65ddce3f 114void evlist__set_cb(struct evlist *evlist, evsel__sb_cb_t cb, void *data);
63503dba 115int perf_evlist__start_sb_thread(struct evlist *evlist,
657ee553 116 struct target *target);
63503dba 117void perf_evlist__stop_sb_thread(struct evlist *evlist);
657ee553 118
e251abee 119int evlist__add_newtp(struct evlist *evlist, const char *sys, const char *name, void *handler);
39876e7d 120
c0e53476
ACM
121int __evlist__set_tracepoints_handlers(struct evlist *evlist,
122 const struct evsel_str_handler *assocs,
123 size_t nr_assocs);
124
125#define evlist__set_tracepoints_handlers(evlist, array) \
126 __evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
127
63503dba 128void __perf_evlist__set_sample_bit(struct evlist *evlist,
22c8a376 129 enum perf_event_sample_format bit);
63503dba 130void __perf_evlist__reset_sample_bit(struct evlist *evlist,
22c8a376
ACM
131 enum perf_event_sample_format bit);
132
133#define perf_evlist__set_sample_bit(evlist, bit) \
134 __perf_evlist__set_sample_bit(evlist, PERF_SAMPLE_##bit)
135
136#define perf_evlist__reset_sample_bit(evlist, bit) \
137 __perf_evlist__reset_sample_bit(evlist, PERF_SAMPLE_##bit)
138
63503dba
JO
139int perf_evlist__set_tp_filter(struct evlist *evlist, const char *filter);
140int perf_evlist__set_tp_filter_pid(struct evlist *evlist, pid_t pid);
141int perf_evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
745cefc5 142
53c92f73
ACM
143int perf_evlist__append_tp_filter(struct evlist *evlist, const char *filter);
144
1827ab5b
ACM
145int perf_evlist__append_tp_filter_pid(struct evlist *evlist, pid_t pid);
146int perf_evlist__append_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
147
32dcd021 148struct evsel *
63503dba 149perf_evlist__find_tracepoint_by_id(struct evlist *evlist, int id);
da378962 150
32dcd021 151struct evsel *
63503dba 152perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
a2f2804a
DA
153 const char *name);
154
f4009e7b
JO
155int evlist__add_pollfd(struct evlist *evlist, int fd);
156int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
1ddec7f0 157
80ab2987 158int evlist__poll(struct evlist *evlist, int timeout);
f66a889d 159
63503dba
JO
160struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id);
161struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
dddcf6ab 162 u64 id);
70db7533 163
63503dba 164struct perf_sample_id *perf_evlist__id2sid(struct evlist *evlist, u64 id);
932a3594 165
63503dba 166void perf_evlist__toggle_bkw_mmap(struct evlist *evlist, enum bkw_mmap_state state);
54cc54de 167
9521b5f2 168void evlist__mmap_consume(struct evlist *evlist, int idx);
8e50d384 169
474ddc4c 170int evlist__open(struct evlist *evlist);
750b4ede 171void evlist__close(struct evlist *evlist);
727ab04e 172
e68ae9cf
ACM
173struct callchain_param;
174
63503dba 175void perf_evlist__set_id_pos(struct evlist *evlist);
63503dba 176void perf_evlist__config(struct evlist *evlist, struct record_opts *opts,
e68ae9cf 177 struct callchain_param *callchain);
b4006796 178int record_opts__config(struct record_opts *opts);
0f82ebc4 179
63503dba 180int perf_evlist__prepare_workload(struct evlist *evlist,
602ad878 181 struct target *target,
55e162ea 182 const char *argv[], bool pipe_output,
735f7e0b
ACM
183 void (*exec_error)(int signo, siginfo_t *info,
184 void *ucontext));
63503dba 185int perf_evlist__start_workload(struct evlist *evlist);
35b9d88e 186
724ce97e
ACM
187struct option;
188
e9db1310 189int __perf_evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
994a1f78
JO
190int perf_evlist__parse_mmap_pages(const struct option *opt,
191 const char *str,
192 int unset);
193
f5e7150c
ACM
194unsigned long perf_event_mlock_kb_in_pages(void);
195
9521b5f2 196int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
7a276ff6 197 unsigned int auxtrace_pages,
470530bb 198 bool auxtrace_overwrite, int nr_cblocks,
51255a8a 199 int affinity, int flush, int comp_level);
9521b5f2 200int evlist__mmap(struct evlist *evlist, unsigned int pages);
db6b7b13 201void evlist__munmap(struct evlist *evlist);
7e2ed097 202
9521b5f2 203size_t evlist__mmap_size(unsigned long pages);
0c582449 204
e74676de 205void evlist__disable(struct evlist *evlist);
1c87f165 206void evlist__enable(struct evlist *evlist);
63503dba 207void perf_evlist__toggle_enable(struct evlist *evlist);
4152ab37 208
63503dba 209int perf_evlist__enable_event_idx(struct evlist *evlist,
32dcd021 210 struct evsel *evsel, int idx);
395c3070 211
63503dba 212void perf_evlist__set_selected(struct evlist *evlist,
32dcd021 213 struct evsel *evsel);
81cce8de 214
63503dba
JO
215int perf_evlist__create_maps(struct evlist *evlist, struct target *target);
216int perf_evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel);
f8a95309 217
63dab225 218void __perf_evlist__set_leader(struct list_head *list);
63503dba 219void perf_evlist__set_leader(struct evlist *evlist);
63dab225 220
63503dba
JO
221u64 __perf_evlist__combined_sample_type(struct evlist *evlist);
222u64 perf_evlist__combined_sample_type(struct evlist *evlist);
223u64 perf_evlist__combined_branch_type(struct evlist *evlist);
224bool perf_evlist__sample_id_all(struct evlist *evlist);
225u16 perf_evlist__id_hdr_size(struct evlist *evlist);
74429964 226
63503dba 227int perf_evlist__parse_sample(struct evlist *evlist, union perf_event *event,
0807d2d8 228 struct perf_sample *sample);
cb0b29e0 229
63503dba 230int perf_evlist__parse_sample_timestamp(struct evlist *evlist,
01468120
JO
231 union perf_event *event,
232 u64 *timestamp);
233
63503dba
JO
234bool perf_evlist__valid_sample_type(struct evlist *evlist);
235bool perf_evlist__valid_sample_id_all(struct evlist *evlist);
236bool perf_evlist__valid_read_format(struct evlist *evlist);
0529bc1f 237
63503dba 238void perf_evlist__splice_list_tail(struct evlist *evlist,
f114d6ef 239 struct list_head *list);
0c21f736 240
63503dba 241static inline bool perf_evlist__empty(struct evlist *evlist)
64831a21 242{
ce9036a6 243 return list_empty(&evlist->core.entries);
64831a21
DCC
244}
245
515dbe48 246static inline struct evsel *evlist__first(struct evlist *evlist)
0c21f736 247{
515dbe48
JO
248 struct perf_evsel *evsel = perf_evlist__first(&evlist->core);
249
250 return container_of(evsel, struct evsel, core);
0c21f736
ACM
251}
252
515dbe48 253static inline struct evsel *evlist__last(struct evlist *evlist)
0c21f736 254{
515dbe48
JO
255 struct perf_evsel *evsel = perf_evlist__last(&evlist->core);
256
257 return container_of(evsel, struct evsel, core);
0c21f736 258}
78f067b3 259
d1f249ec
ACM
260int evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_t size);
261int evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size);
6ef068cb 262
63503dba
JO
263bool perf_evlist__can_select_event(struct evlist *evlist, const char *str);
264void perf_evlist__to_front(struct evlist *evlist,
32dcd021 265 struct evsel *move_evsel);
a025e4f0 266
0050f7aa 267/**
e5cadb93 268 * __evlist__for_each_entry - iterate thru all the evsels
0050f7aa
ACM
269 * @list: list_head instance to iterate
270 * @evsel: struct evsel iterator
271 */
e5cadb93 272#define __evlist__for_each_entry(list, evsel) \
b27c4ece 273 list_for_each_entry(evsel, list, core.node)
0050f7aa
ACM
274
275/**
e5cadb93 276 * evlist__for_each_entry - iterate thru all the evsels
0050f7aa
ACM
277 * @evlist: evlist instance to iterate
278 * @evsel: struct evsel iterator
279 */
e5cadb93 280#define evlist__for_each_entry(evlist, evsel) \
ce9036a6 281 __evlist__for_each_entry(&(evlist)->core.entries, evsel)
0050f7aa
ACM
282
283/**
e5cadb93 284 * __evlist__for_each_entry_continue - continue iteration thru all the evsels
0050f7aa
ACM
285 * @list: list_head instance to iterate
286 * @evsel: struct evsel iterator
287 */
e5cadb93 288#define __evlist__for_each_entry_continue(list, evsel) \
b27c4ece 289 list_for_each_entry_continue(evsel, list, core.node)
0050f7aa
ACM
290
291/**
e5cadb93 292 * evlist__for_each_entry_continue - continue iteration thru all the evsels
0050f7aa
ACM
293 * @evlist: evlist instance to iterate
294 * @evsel: struct evsel iterator
295 */
e5cadb93 296#define evlist__for_each_entry_continue(evlist, evsel) \
ce9036a6 297 __evlist__for_each_entry_continue(&(evlist)->core.entries, evsel)
0050f7aa
ACM
298
299/**
e5cadb93 300 * __evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
0050f7aa
ACM
301 * @list: list_head instance to iterate
302 * @evsel: struct evsel iterator
303 */
e5cadb93 304#define __evlist__for_each_entry_reverse(list, evsel) \
b27c4ece 305 list_for_each_entry_reverse(evsel, list, core.node)
0050f7aa
ACM
306
307/**
e5cadb93 308 * evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
0050f7aa
ACM
309 * @evlist: evlist instance to iterate
310 * @evsel: struct evsel iterator
311 */
e5cadb93 312#define evlist__for_each_entry_reverse(evlist, evsel) \
ce9036a6 313 __evlist__for_each_entry_reverse(&(evlist)->core.entries, evsel)
0050f7aa
ACM
314
315/**
e5cadb93 316 * __evlist__for_each_entry_safe - safely iterate thru all the evsels
0050f7aa
ACM
317 * @list: list_head instance to iterate
318 * @tmp: struct evsel temp iterator
319 * @evsel: struct evsel iterator
320 */
e5cadb93 321#define __evlist__for_each_entry_safe(list, tmp, evsel) \
b27c4ece 322 list_for_each_entry_safe(evsel, tmp, list, core.node)
0050f7aa
ACM
323
324/**
e5cadb93 325 * evlist__for_each_entry_safe - safely iterate thru all the evsels
0050f7aa
ACM
326 * @evlist: evlist instance to iterate
327 * @evsel: struct evsel iterator
328 * @tmp: struct evsel temp iterator
329 */
e5cadb93 330#define evlist__for_each_entry_safe(evlist, tmp, evsel) \
ce9036a6 331 __evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)
c09ec622 332
a8cbe40f
AK
333#define evlist__for_each_cpu(evlist, index, cpu) \
334 evlist__cpu_iter_start(evlist); \
335 perf_cpu_map__for_each_cpu (cpu, index, (evlist)->core.all_cpus)
336
63503dba 337void perf_evlist__set_tracking_event(struct evlist *evlist,
32dcd021 338 struct evsel *tracking_evsel);
45cf6c33 339
a8cbe40f
AK
340void evlist__cpu_iter_start(struct evlist *evlist);
341bool evsel__cpu_iter_skip(struct evsel *ev, int cpu);
342bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu);
343
32dcd021 344struct evsel *
63503dba 345perf_evlist__find_evsel_by_str(struct evlist *evlist, const char *str);
7cb5c5ac 346
63503dba 347struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
7cb5c5ac 348 union perf_event *event);
07d6f446 349
63503dba 350bool perf_evlist__exclude_kernel(struct evlist *evlist);
e2bdbe80 351
63503dba 352void perf_evlist__force_leader(struct evlist *evlist);
e2bdbe80 353
63503dba 354struct evsel *perf_evlist__reset_weak_group(struct evlist *evlist,
4804e011
AK
355 struct evsel *evsel,
356 bool close);
361c99a6 357#endif /* __PERF_EVLIST_H */