]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - tools/perf/util/evlist.h
perf record: Add 'snapshot' control command
[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;
8ab705b5
AB
77 struct {
78 int fd; /* control file descriptor */
79 int ack; /* ack file descriptor for control commands */
80 int pos; /* index at evlist core object to check signals */
81 } ctl_fd;
361c99a6
ACM
82};
83
32dcd021 84struct evsel_str_handler {
ee29be62
ACM
85 const char *name;
86 void *handler;
87};
88
0f98b11c 89struct evlist *evlist__new(void);
63503dba
JO
90struct evlist *perf_evlist__new_default(void);
91struct evlist *perf_evlist__new_dummy(void);
52c86bca
JO
92void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
93 struct perf_thread_map *threads);
470579b0 94void evlist__exit(struct evlist *evlist);
c12995a5 95void evlist__delete(struct evlist *evlist);
361c99a6 96
a1cf3a75 97void evlist__add(struct evlist *evlist, struct evsel *entry);
16251027 98void evlist__remove(struct evlist *evlist, struct evsel *evsel);
db918acb 99
e251abee 100int __evlist__add_default(struct evlist *evlist, bool precise);
db918acb 101
e251abee 102static inline int evlist__add_default(struct evlist *evlist)
db918acb 103{
e251abee 104 return __evlist__add_default(evlist, true);
db918acb
ACM
105}
106
e251abee 107int __evlist__add_default_attrs(struct evlist *evlist,
79695e1b 108 struct perf_event_attr *attrs, size_t nr_attrs);
e60fc847 109
e251abee
ACM
110#define evlist__add_default_attrs(evlist, array) \
111 __evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
361c99a6 112
e251abee 113int evlist__add_dummy(struct evlist *evlist);
5bae0250 114
b38d85ef 115int perf_evlist__add_sb_event(struct evlist *evlist,
657ee553 116 struct perf_event_attr *attr,
65ddce3f 117 evsel__sb_cb_t cb,
657ee553 118 void *data);
65ddce3f 119void evlist__set_cb(struct evlist *evlist, evsel__sb_cb_t cb, void *data);
63503dba 120int perf_evlist__start_sb_thread(struct evlist *evlist,
657ee553 121 struct target *target);
63503dba 122void perf_evlist__stop_sb_thread(struct evlist *evlist);
657ee553 123
e251abee 124int evlist__add_newtp(struct evlist *evlist, const char *sys, const char *name, void *handler);
39876e7d 125
c0e53476
ACM
126int __evlist__set_tracepoints_handlers(struct evlist *evlist,
127 const struct evsel_str_handler *assocs,
128 size_t nr_assocs);
129
130#define evlist__set_tracepoints_handlers(evlist, array) \
131 __evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
132
63503dba 133void __perf_evlist__set_sample_bit(struct evlist *evlist,
22c8a376 134 enum perf_event_sample_format bit);
63503dba 135void __perf_evlist__reset_sample_bit(struct evlist *evlist,
22c8a376
ACM
136 enum perf_event_sample_format bit);
137
138#define perf_evlist__set_sample_bit(evlist, bit) \
139 __perf_evlist__set_sample_bit(evlist, PERF_SAMPLE_##bit)
140
141#define perf_evlist__reset_sample_bit(evlist, bit) \
142 __perf_evlist__reset_sample_bit(evlist, PERF_SAMPLE_##bit)
143
63503dba
JO
144int perf_evlist__set_tp_filter(struct evlist *evlist, const char *filter);
145int perf_evlist__set_tp_filter_pid(struct evlist *evlist, pid_t pid);
146int perf_evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
745cefc5 147
53c92f73
ACM
148int perf_evlist__append_tp_filter(struct evlist *evlist, const char *filter);
149
1827ab5b
ACM
150int perf_evlist__append_tp_filter_pid(struct evlist *evlist, pid_t pid);
151int perf_evlist__append_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
152
32dcd021 153struct evsel *
63503dba 154perf_evlist__find_tracepoint_by_id(struct evlist *evlist, int id);
da378962 155
32dcd021 156struct evsel *
63503dba 157perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
a2f2804a
DA
158 const char *name);
159
f4009e7b
JO
160int evlist__add_pollfd(struct evlist *evlist, int fd);
161int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
1ddec7f0 162
80ab2987 163int evlist__poll(struct evlist *evlist, int timeout);
f66a889d 164
63503dba
JO
165struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id);
166struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
dddcf6ab 167 u64 id);
70db7533 168
63503dba 169struct perf_sample_id *perf_evlist__id2sid(struct evlist *evlist, u64 id);
932a3594 170
63503dba 171void perf_evlist__toggle_bkw_mmap(struct evlist *evlist, enum bkw_mmap_state state);
54cc54de 172
9521b5f2 173void evlist__mmap_consume(struct evlist *evlist, int idx);
8e50d384 174
474ddc4c 175int evlist__open(struct evlist *evlist);
750b4ede 176void evlist__close(struct evlist *evlist);
727ab04e 177
e68ae9cf
ACM
178struct callchain_param;
179
63503dba 180void perf_evlist__set_id_pos(struct evlist *evlist);
63503dba 181void perf_evlist__config(struct evlist *evlist, struct record_opts *opts,
e68ae9cf 182 struct callchain_param *callchain);
b4006796 183int record_opts__config(struct record_opts *opts);
0f82ebc4 184
63503dba 185int perf_evlist__prepare_workload(struct evlist *evlist,
602ad878 186 struct target *target,
55e162ea 187 const char *argv[], bool pipe_output,
735f7e0b
ACM
188 void (*exec_error)(int signo, siginfo_t *info,
189 void *ucontext));
63503dba 190int perf_evlist__start_workload(struct evlist *evlist);
35b9d88e 191
724ce97e
ACM
192struct option;
193
e9db1310 194int __perf_evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
994a1f78
JO
195int perf_evlist__parse_mmap_pages(const struct option *opt,
196 const char *str,
197 int unset);
198
f5e7150c
ACM
199unsigned long perf_event_mlock_kb_in_pages(void);
200
9521b5f2 201int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
7a276ff6 202 unsigned int auxtrace_pages,
470530bb 203 bool auxtrace_overwrite, int nr_cblocks,
51255a8a 204 int affinity, int flush, int comp_level);
9521b5f2 205int evlist__mmap(struct evlist *evlist, unsigned int pages);
db6b7b13 206void evlist__munmap(struct evlist *evlist);
7e2ed097 207
9521b5f2 208size_t evlist__mmap_size(unsigned long pages);
0c582449 209
e74676de 210void evlist__disable(struct evlist *evlist);
1c87f165 211void evlist__enable(struct evlist *evlist);
63503dba 212void perf_evlist__toggle_enable(struct evlist *evlist);
4152ab37 213
63503dba 214int perf_evlist__enable_event_idx(struct evlist *evlist,
32dcd021 215 struct evsel *evsel, int idx);
395c3070 216
63503dba 217void perf_evlist__set_selected(struct evlist *evlist,
32dcd021 218 struct evsel *evsel);
81cce8de 219
63503dba
JO
220int perf_evlist__create_maps(struct evlist *evlist, struct target *target);
221int perf_evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel);
f8a95309 222
63dab225 223void __perf_evlist__set_leader(struct list_head *list);
63503dba 224void perf_evlist__set_leader(struct evlist *evlist);
63dab225 225
b3c2cc2b
ACM
226u64 __evlist__combined_sample_type(struct evlist *evlist);
227u64 evlist__combined_sample_type(struct evlist *evlist);
92c7d7cd 228u64 evlist__combined_branch_type(struct evlist *evlist);
8cedf3a5 229bool evlist__sample_id_all(struct evlist *evlist);
63503dba 230u16 perf_evlist__id_hdr_size(struct evlist *evlist);
74429964 231
63503dba 232int perf_evlist__parse_sample(struct evlist *evlist, union perf_event *event,
0807d2d8 233 struct perf_sample *sample);
cb0b29e0 234
63503dba 235int perf_evlist__parse_sample_timestamp(struct evlist *evlist,
01468120
JO
236 union perf_event *event,
237 u64 *timestamp);
238
b3c2cc2b 239bool evlist__valid_sample_type(struct evlist *evlist);
8cedf3a5 240bool evlist__valid_sample_id_all(struct evlist *evlist);
63503dba 241bool perf_evlist__valid_read_format(struct evlist *evlist);
0529bc1f 242
63503dba 243void perf_evlist__splice_list_tail(struct evlist *evlist,
f114d6ef 244 struct list_head *list);
0c21f736 245
63503dba 246static inline bool perf_evlist__empty(struct evlist *evlist)
64831a21 247{
ce9036a6 248 return list_empty(&evlist->core.entries);
64831a21
DCC
249}
250
515dbe48 251static inline struct evsel *evlist__first(struct evlist *evlist)
0c21f736 252{
515dbe48
JO
253 struct perf_evsel *evsel = perf_evlist__first(&evlist->core);
254
255 return container_of(evsel, struct evsel, core);
0c21f736
ACM
256}
257
515dbe48 258static inline struct evsel *evlist__last(struct evlist *evlist)
0c21f736 259{
515dbe48
JO
260 struct perf_evsel *evsel = perf_evlist__last(&evlist->core);
261
262 return container_of(evsel, struct evsel, core);
0c21f736 263}
78f067b3 264
d1f249ec
ACM
265int evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_t size);
266int evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size);
6ef068cb 267
63503dba
JO
268bool perf_evlist__can_select_event(struct evlist *evlist, const char *str);
269void perf_evlist__to_front(struct evlist *evlist,
32dcd021 270 struct evsel *move_evsel);
a025e4f0 271
0050f7aa 272/**
e5cadb93 273 * __evlist__for_each_entry - iterate thru all the evsels
0050f7aa
ACM
274 * @list: list_head instance to iterate
275 * @evsel: struct evsel iterator
276 */
e5cadb93 277#define __evlist__for_each_entry(list, evsel) \
b27c4ece 278 list_for_each_entry(evsel, list, core.node)
0050f7aa
ACM
279
280/**
e5cadb93 281 * evlist__for_each_entry - iterate thru all the evsels
0050f7aa
ACM
282 * @evlist: evlist instance to iterate
283 * @evsel: struct evsel iterator
284 */
e5cadb93 285#define evlist__for_each_entry(evlist, evsel) \
ce9036a6 286 __evlist__for_each_entry(&(evlist)->core.entries, evsel)
0050f7aa
ACM
287
288/**
e5cadb93 289 * __evlist__for_each_entry_continue - continue iteration thru all the evsels
0050f7aa
ACM
290 * @list: list_head instance to iterate
291 * @evsel: struct evsel iterator
292 */
e5cadb93 293#define __evlist__for_each_entry_continue(list, evsel) \
b27c4ece 294 list_for_each_entry_continue(evsel, list, core.node)
0050f7aa
ACM
295
296/**
e5cadb93 297 * evlist__for_each_entry_continue - continue iteration thru all the evsels
0050f7aa
ACM
298 * @evlist: evlist instance to iterate
299 * @evsel: struct evsel iterator
300 */
e5cadb93 301#define evlist__for_each_entry_continue(evlist, evsel) \
ce9036a6 302 __evlist__for_each_entry_continue(&(evlist)->core.entries, evsel)
0050f7aa
ACM
303
304/**
e5cadb93 305 * __evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
0050f7aa
ACM
306 * @list: list_head instance to iterate
307 * @evsel: struct evsel iterator
308 */
e5cadb93 309#define __evlist__for_each_entry_reverse(list, evsel) \
b27c4ece 310 list_for_each_entry_reverse(evsel, list, core.node)
0050f7aa
ACM
311
312/**
e5cadb93 313 * evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
0050f7aa
ACM
314 * @evlist: evlist instance to iterate
315 * @evsel: struct evsel iterator
316 */
e5cadb93 317#define evlist__for_each_entry_reverse(evlist, evsel) \
ce9036a6 318 __evlist__for_each_entry_reverse(&(evlist)->core.entries, evsel)
0050f7aa
ACM
319
320/**
e5cadb93 321 * __evlist__for_each_entry_safe - safely iterate thru all the evsels
0050f7aa
ACM
322 * @list: list_head instance to iterate
323 * @tmp: struct evsel temp iterator
324 * @evsel: struct evsel iterator
325 */
e5cadb93 326#define __evlist__for_each_entry_safe(list, tmp, evsel) \
b27c4ece 327 list_for_each_entry_safe(evsel, tmp, list, core.node)
0050f7aa
ACM
328
329/**
e5cadb93 330 * evlist__for_each_entry_safe - safely iterate thru all the evsels
0050f7aa
ACM
331 * @evlist: evlist instance to iterate
332 * @evsel: struct evsel iterator
333 * @tmp: struct evsel temp iterator
334 */
e5cadb93 335#define evlist__for_each_entry_safe(evlist, tmp, evsel) \
ce9036a6 336 __evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)
c09ec622 337
a8cbe40f
AK
338#define evlist__for_each_cpu(evlist, index, cpu) \
339 evlist__cpu_iter_start(evlist); \
340 perf_cpu_map__for_each_cpu (cpu, index, (evlist)->core.all_cpus)
341
442ad225 342struct evsel *perf_evlist__get_tracking_event(struct evlist *evlist);
63503dba 343void perf_evlist__set_tracking_event(struct evlist *evlist,
32dcd021 344 struct evsel *tracking_evsel);
45cf6c33 345
a8cbe40f
AK
346void evlist__cpu_iter_start(struct evlist *evlist);
347bool evsel__cpu_iter_skip(struct evsel *ev, int cpu);
348bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu);
349
32dcd021 350struct evsel *
63503dba 351perf_evlist__find_evsel_by_str(struct evlist *evlist, const char *str);
7cb5c5ac 352
63503dba 353struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
7cb5c5ac 354 union perf_event *event);
07d6f446 355
63503dba 356bool perf_evlist__exclude_kernel(struct evlist *evlist);
e2bdbe80 357
63503dba 358void perf_evlist__force_leader(struct evlist *evlist);
e2bdbe80 359
63503dba 360struct evsel *perf_evlist__reset_weak_group(struct evlist *evlist,
4804e011
AK
361 struct evsel *evsel,
362 bool close);
ec886bf5
AB
363#define EVLIST_CTL_CMD_ENABLE_TAG "enable"
364#define EVLIST_CTL_CMD_DISABLE_TAG "disable"
365#define EVLIST_CTL_CMD_ACK_TAG "ack\n"
d20aff15 366#define EVLIST_CTL_CMD_SNAPSHOT_TAG "snapshot"
ec886bf5
AB
367
368#define EVLIST_CTL_CMD_MAX_LEN 64
369
370enum evlist_ctl_cmd {
371 EVLIST_CTL_CMD_UNSUPPORTED = 0,
372 EVLIST_CTL_CMD_ENABLE,
373 EVLIST_CTL_CMD_DISABLE,
d20aff15
AH
374 EVLIST_CTL_CMD_ACK,
375 EVLIST_CTL_CMD_SNAPSHOT,
ec886bf5
AB
376};
377
a8fcbd26 378int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close);
ec886bf5
AB
379int evlist__initialize_ctlfd(struct evlist *evlist, int ctl_fd, int ctl_fd_ack);
380int evlist__finalize_ctlfd(struct evlist *evlist);
381bool evlist__ctlfd_initialized(struct evlist *evlist);
382int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd);
d20aff15 383int evlist__ctlfd_ack(struct evlist *evlist);
ec886bf5 384
2162b9c6
AB
385#define EVLIST_ENABLED_MSG "Events enabled\n"
386#define EVLIST_DISABLED_MSG "Events disabled\n"
387
361c99a6 388#endif /* __PERF_EVLIST_H */