0001
0002 #ifndef __PERF_EVLIST_H
0003 #define __PERF_EVLIST_H 1
0004
0005 #include <linux/compiler.h>
0006 #include <linux/kernel.h>
0007 #include <linux/refcount.h>
0008 #include <linux/list.h>
0009 #include <api/fd/array.h>
0010 #include <internal/evlist.h>
0011 #include <internal/evsel.h>
0012 #include "events_stats.h"
0013 #include "evsel.h"
0014 #include <pthread.h>
0015 #include <signal.h>
0016 #include <unistd.h>
0017
0018 struct pollfd;
0019 struct thread_map;
0020 struct perf_cpu_map;
0021 struct record_opts;
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 enum bkw_mmap_state {
0045 BKW_MMAP_NOTREADY,
0046 BKW_MMAP_RUNNING,
0047 BKW_MMAP_DATA_PENDING,
0048 BKW_MMAP_EMPTY,
0049 };
0050
0051 struct evlist {
0052 struct perf_evlist core;
0053 bool enabled;
0054 int id_pos;
0055 int is_pos;
0056 u64 combined_sample_type;
0057 enum bkw_mmap_state bkw_mmap_state;
0058 struct {
0059 int cork_fd;
0060 pid_t pid;
0061 } workload;
0062 struct mmap *mmap;
0063 struct mmap *overwrite_mmap;
0064 struct evsel *selected;
0065 struct events_stats stats;
0066 struct perf_env *env;
0067 const char *hybrid_pmu_name;
0068 void (*trace_event_sample_raw)(struct evlist *evlist,
0069 union perf_event *event,
0070 struct perf_sample *sample);
0071 u64 first_sample_time;
0072 u64 last_sample_time;
0073 struct {
0074 pthread_t th;
0075 volatile int done;
0076 } thread;
0077 struct {
0078 int fd;
0079 int ack;
0080 int pos;
0081 } ctl_fd;
0082 };
0083
0084 struct evsel_str_handler {
0085 const char *name;
0086 void *handler;
0087 };
0088
0089 struct evlist *evlist__new(void);
0090 struct evlist *evlist__new_default(void);
0091 struct evlist *evlist__new_dummy(void);
0092 void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
0093 struct perf_thread_map *threads);
0094 void evlist__exit(struct evlist *evlist);
0095 void evlist__delete(struct evlist *evlist);
0096
0097 void evlist__add(struct evlist *evlist, struct evsel *entry);
0098 void evlist__remove(struct evlist *evlist, struct evsel *evsel);
0099
0100 int __evlist__add_default(struct evlist *evlist, bool precise);
0101
0102 static inline int evlist__add_default(struct evlist *evlist)
0103 {
0104 return __evlist__add_default(evlist, true);
0105 }
0106
0107 int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs);
0108
0109 int __evlist__add_default_attrs(struct evlist *evlist,
0110 struct perf_event_attr *attrs, size_t nr_attrs);
0111
0112 int arch_evlist__add_default_attrs(struct evlist *evlist,
0113 struct perf_event_attr *attrs,
0114 size_t nr_attrs);
0115
0116 #define evlist__add_default_attrs(evlist, array) \
0117 arch_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
0118
0119 struct evsel *arch_evlist__leader(struct list_head *list);
0120
0121 int evlist__add_dummy(struct evlist *evlist);
0122 struct evsel *evlist__add_aux_dummy(struct evlist *evlist, bool system_wide);
0123 static inline struct evsel *evlist__add_dummy_on_all_cpus(struct evlist *evlist)
0124 {
0125 return evlist__add_aux_dummy(evlist, true);
0126 }
0127
0128 int evlist__add_sb_event(struct evlist *evlist, struct perf_event_attr *attr,
0129 evsel__sb_cb_t cb, void *data);
0130 void evlist__set_cb(struct evlist *evlist, evsel__sb_cb_t cb, void *data);
0131 int evlist__start_sb_thread(struct evlist *evlist, struct target *target);
0132 void evlist__stop_sb_thread(struct evlist *evlist);
0133
0134 int evlist__add_newtp(struct evlist *evlist, const char *sys, const char *name, void *handler);
0135
0136 int __evlist__set_tracepoints_handlers(struct evlist *evlist,
0137 const struct evsel_str_handler *assocs,
0138 size_t nr_assocs);
0139
0140 #define evlist__set_tracepoints_handlers(evlist, array) \
0141 __evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
0142
0143 int evlist__set_tp_filter(struct evlist *evlist, const char *filter);
0144 int evlist__set_tp_filter_pid(struct evlist *evlist, pid_t pid);
0145 int evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
0146
0147 int evlist__append_tp_filter(struct evlist *evlist, const char *filter);
0148
0149 int evlist__append_tp_filter_pid(struct evlist *evlist, pid_t pid);
0150 int evlist__append_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
0151
0152 struct evsel *evlist__find_tracepoint_by_id(struct evlist *evlist, int id);
0153 struct evsel *evlist__find_tracepoint_by_name(struct evlist *evlist, const char *name);
0154
0155 int evlist__add_pollfd(struct evlist *evlist, int fd);
0156 int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
0157
0158 #ifdef HAVE_EVENTFD_SUPPORT
0159 int evlist__add_wakeup_eventfd(struct evlist *evlist, int fd);
0160 #endif
0161
0162 int evlist__poll(struct evlist *evlist, int timeout);
0163
0164 struct evsel *evlist__id2evsel(struct evlist *evlist, u64 id);
0165 struct evsel *evlist__id2evsel_strict(struct evlist *evlist, u64 id);
0166
0167 struct perf_sample_id *evlist__id2sid(struct evlist *evlist, u64 id);
0168
0169 void evlist__toggle_bkw_mmap(struct evlist *evlist, enum bkw_mmap_state state);
0170
0171 void evlist__mmap_consume(struct evlist *evlist, int idx);
0172
0173 int evlist__open(struct evlist *evlist);
0174 void evlist__close(struct evlist *evlist);
0175
0176 struct callchain_param;
0177
0178 void evlist__set_id_pos(struct evlist *evlist);
0179 void evlist__config(struct evlist *evlist, struct record_opts *opts, struct callchain_param *callchain);
0180 int record_opts__config(struct record_opts *opts);
0181
0182 int evlist__prepare_workload(struct evlist *evlist, struct target *target,
0183 const char *argv[], bool pipe_output,
0184 void (*exec_error)(int signo, siginfo_t *info, void *ucontext));
0185 int evlist__start_workload(struct evlist *evlist);
0186
0187 struct option;
0188
0189 int __evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
0190 int evlist__parse_mmap_pages(const struct option *opt, const char *str, int unset);
0191
0192 unsigned long perf_event_mlock_kb_in_pages(void);
0193
0194 int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
0195 unsigned int auxtrace_pages,
0196 bool auxtrace_overwrite, int nr_cblocks,
0197 int affinity, int flush, int comp_level);
0198 int evlist__mmap(struct evlist *evlist, unsigned int pages);
0199 void evlist__munmap(struct evlist *evlist);
0200
0201 size_t evlist__mmap_size(unsigned long pages);
0202
0203 void evlist__disable(struct evlist *evlist);
0204 void evlist__enable(struct evlist *evlist);
0205 void evlist__toggle_enable(struct evlist *evlist);
0206 void evlist__disable_evsel(struct evlist *evlist, char *evsel_name);
0207 void evlist__enable_evsel(struct evlist *evlist, char *evsel_name);
0208
0209 void evlist__set_selected(struct evlist *evlist, struct evsel *evsel);
0210
0211 int evlist__create_maps(struct evlist *evlist, struct target *target);
0212 int evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel);
0213
0214 void evlist__set_leader(struct evlist *evlist);
0215
0216 u64 __evlist__combined_sample_type(struct evlist *evlist);
0217 u64 evlist__combined_sample_type(struct evlist *evlist);
0218 u64 evlist__combined_branch_type(struct evlist *evlist);
0219 bool evlist__sample_id_all(struct evlist *evlist);
0220 u16 evlist__id_hdr_size(struct evlist *evlist);
0221
0222 int evlist__parse_sample(struct evlist *evlist, union perf_event *event, struct perf_sample *sample);
0223 int evlist__parse_sample_timestamp(struct evlist *evlist, union perf_event *event, u64 *timestamp);
0224
0225 bool evlist__valid_sample_type(struct evlist *evlist);
0226 bool evlist__valid_sample_id_all(struct evlist *evlist);
0227 bool evlist__valid_read_format(struct evlist *evlist);
0228
0229 void evlist__splice_list_tail(struct evlist *evlist, struct list_head *list);
0230
0231 static inline bool evlist__empty(struct evlist *evlist)
0232 {
0233 return list_empty(&evlist->core.entries);
0234 }
0235
0236 static inline struct evsel *evlist__first(struct evlist *evlist)
0237 {
0238 struct perf_evsel *evsel = perf_evlist__first(&evlist->core);
0239
0240 return container_of(evsel, struct evsel, core);
0241 }
0242
0243 static inline struct evsel *evlist__last(struct evlist *evlist)
0244 {
0245 struct perf_evsel *evsel = perf_evlist__last(&evlist->core);
0246
0247 return container_of(evsel, struct evsel, core);
0248 }
0249
0250 int evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_t size);
0251 int evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size);
0252
0253 bool evlist__can_select_event(struct evlist *evlist, const char *str);
0254 void evlist__to_front(struct evlist *evlist, struct evsel *move_evsel);
0255
0256
0257
0258
0259
0260
0261 #define __evlist__for_each_entry(list, evsel) \
0262 list_for_each_entry(evsel, list, core.node)
0263
0264
0265
0266
0267
0268
0269 #define evlist__for_each_entry(evlist, evsel) \
0270 __evlist__for_each_entry(&(evlist)->core.entries, evsel)
0271
0272
0273
0274
0275
0276
0277 #define __evlist__for_each_entry_continue(list, evsel) \
0278 list_for_each_entry_continue(evsel, list, core.node)
0279
0280
0281
0282
0283
0284
0285 #define evlist__for_each_entry_continue(evlist, evsel) \
0286 __evlist__for_each_entry_continue(&(evlist)->core.entries, evsel)
0287
0288
0289
0290
0291
0292
0293 #define __evlist__for_each_entry_from(list, evsel) \
0294 list_for_each_entry_from(evsel, list, core.node)
0295
0296
0297
0298
0299
0300
0301 #define evlist__for_each_entry_from(evlist, evsel) \
0302 __evlist__for_each_entry_from(&(evlist)->core.entries, evsel)
0303
0304
0305
0306
0307
0308
0309 #define __evlist__for_each_entry_reverse(list, evsel) \
0310 list_for_each_entry_reverse(evsel, list, core.node)
0311
0312
0313
0314
0315
0316
0317 #define evlist__for_each_entry_reverse(evlist, evsel) \
0318 __evlist__for_each_entry_reverse(&(evlist)->core.entries, evsel)
0319
0320
0321
0322
0323
0324
0325
0326 #define __evlist__for_each_entry_safe(list, tmp, evsel) \
0327 list_for_each_entry_safe(evsel, tmp, list, core.node)
0328
0329
0330
0331
0332
0333
0334
0335 #define evlist__for_each_entry_safe(evlist, tmp, evsel) \
0336 __evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)
0337
0338
0339 struct evlist_cpu_iterator {
0340
0341 struct evlist *container;
0342
0343 struct evsel *evsel;
0344
0345 int cpu_map_idx;
0346
0347
0348
0349
0350
0351 int evlist_cpu_map_idx;
0352
0353 int evlist_cpu_map_nr;
0354
0355 struct perf_cpu cpu;
0356
0357 struct affinity *affinity;
0358 };
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370 #define evlist__for_each_cpu(evlist_cpu_itr, evlist, affinity) \
0371 for ((evlist_cpu_itr) = evlist__cpu_begin(evlist, affinity); \
0372 !evlist_cpu_iterator__end(&evlist_cpu_itr); \
0373 evlist_cpu_iterator__next(&evlist_cpu_itr))
0374
0375
0376 struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affinity *affinity);
0377
0378 void evlist_cpu_iterator__next(struct evlist_cpu_iterator *evlist_cpu_itr);
0379
0380 bool evlist_cpu_iterator__end(const struct evlist_cpu_iterator *evlist_cpu_itr);
0381
0382 struct evsel *evlist__get_tracking_event(struct evlist *evlist);
0383 void evlist__set_tracking_event(struct evlist *evlist, struct evsel *tracking_evsel);
0384
0385 struct evsel *evlist__find_evsel_by_str(struct evlist *evlist, const char *str);
0386
0387 struct evsel *evlist__event2evsel(struct evlist *evlist, union perf_event *event);
0388
0389 bool evlist__exclude_kernel(struct evlist *evlist);
0390
0391 void evlist__force_leader(struct evlist *evlist);
0392
0393 struct evsel *evlist__reset_weak_group(struct evlist *evlist, struct evsel *evsel, bool close);
0394
0395 #define EVLIST_CTL_CMD_ENABLE_TAG "enable"
0396 #define EVLIST_CTL_CMD_DISABLE_TAG "disable"
0397 #define EVLIST_CTL_CMD_ACK_TAG "ack\n"
0398 #define EVLIST_CTL_CMD_SNAPSHOT_TAG "snapshot"
0399 #define EVLIST_CTL_CMD_EVLIST_TAG "evlist"
0400 #define EVLIST_CTL_CMD_STOP_TAG "stop"
0401 #define EVLIST_CTL_CMD_PING_TAG "ping"
0402
0403 #define EVLIST_CTL_CMD_MAX_LEN 64
0404
0405 enum evlist_ctl_cmd {
0406 EVLIST_CTL_CMD_UNSUPPORTED = 0,
0407 EVLIST_CTL_CMD_ENABLE,
0408 EVLIST_CTL_CMD_DISABLE,
0409 EVLIST_CTL_CMD_ACK,
0410 EVLIST_CTL_CMD_SNAPSHOT,
0411 EVLIST_CTL_CMD_EVLIST,
0412 EVLIST_CTL_CMD_STOP,
0413 EVLIST_CTL_CMD_PING,
0414 };
0415
0416 int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close);
0417 void evlist__close_control(int ctl_fd, int ctl_fd_ack, bool *ctl_fd_close);
0418 int evlist__initialize_ctlfd(struct evlist *evlist, int ctl_fd, int ctl_fd_ack);
0419 int evlist__finalize_ctlfd(struct evlist *evlist);
0420 bool evlist__ctlfd_initialized(struct evlist *evlist);
0421 int evlist__ctlfd_update(struct evlist *evlist, struct pollfd *update);
0422 int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd);
0423 int evlist__ctlfd_ack(struct evlist *evlist);
0424
0425 #define EVLIST_ENABLED_MSG "Events enabled\n"
0426 #define EVLIST_DISABLED_MSG "Events disabled\n"
0427
0428 struct evsel *evlist__find_evsel(struct evlist *evlist, int idx);
0429
0430 int evlist__scnprintf_evsels(struct evlist *evlist, size_t size, char *bf);
0431 void evlist__check_mem_load_aux(struct evlist *evlist);
0432 #endif