1 #ifndef __PERF_EVLIST_H
2 #define __PERF_EVLIST_H 1
4 #include <linux/list.h>
5 #include <api/fd/array.h>
18 #define PERF_EVLIST__HLIST_BITS 8
19 #define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
22 * struct perf_mmap - perf's ring buffer mmap details
24 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
31 char event_copy[PERF_SAMPLE_MAX_SIZE];
35 struct list_head entries;
36 struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
43 u64 combined_sample_type;
49 struct fdarray pollfd;
50 struct perf_mmap *mmap;
51 struct thread_map *threads;
53 struct perf_evsel *selected;
56 struct perf_evsel_str_handler {
61 struct perf_evlist *perf_evlist__new(void);
62 struct perf_evlist *perf_evlist__new_default(void);
63 void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
64 struct thread_map *threads);
65 void perf_evlist__exit(struct perf_evlist *evlist);
66 void perf_evlist__delete(struct perf_evlist *evlist);
68 void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry);
69 int perf_evlist__add_default(struct perf_evlist *evlist);
70 int __perf_evlist__add_default_attrs(struct perf_evlist *evlist,
71 struct perf_event_attr *attrs, size_t nr_attrs);
73 #define perf_evlist__add_default_attrs(evlist, array) \
74 __perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
76 int perf_evlist__add_newtp(struct perf_evlist *evlist,
77 const char *sys, const char *name, void *handler);
79 int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter);
82 perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id);
85 perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,
88 void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
89 int cpu, int thread, u64 id);
91 int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd);
92 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
93 int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask);
95 int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
97 struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
99 struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);
101 union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx);
103 void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx);
105 int perf_evlist__open(struct perf_evlist *evlist);
106 void perf_evlist__close(struct perf_evlist *evlist);
108 void perf_evlist__set_id_pos(struct perf_evlist *evlist);
109 bool perf_can_sample_identifier(void);
110 void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts);
111 int record_opts__config(struct record_opts *opts);
113 int perf_evlist__prepare_workload(struct perf_evlist *evlist,
114 struct target *target,
115 const char *argv[], bool pipe_output,
116 void (*exec_error)(int signo, siginfo_t *info,
118 int perf_evlist__start_workload(struct perf_evlist *evlist);
120 int perf_evlist__parse_mmap_pages(const struct option *opt,
124 int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
126 void perf_evlist__munmap(struct perf_evlist *evlist);
128 void perf_evlist__disable(struct perf_evlist *evlist);
129 void perf_evlist__enable(struct perf_evlist *evlist);
131 int perf_evlist__disable_event(struct perf_evlist *evlist,
132 struct perf_evsel *evsel);
133 int perf_evlist__enable_event(struct perf_evlist *evlist,
134 struct perf_evsel *evsel);
135 int perf_evlist__enable_event_idx(struct perf_evlist *evlist,
136 struct perf_evsel *evsel, int idx);
138 void perf_evlist__set_selected(struct perf_evlist *evlist,
139 struct perf_evsel *evsel);
141 static inline void perf_evlist__set_maps(struct perf_evlist *evlist,
142 struct cpu_map *cpus,
143 struct thread_map *threads)
146 evlist->threads = threads;
149 int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target);
150 int perf_evlist__apply_filters(struct perf_evlist *evlist);
152 void __perf_evlist__set_leader(struct list_head *list);
153 void perf_evlist__set_leader(struct perf_evlist *evlist);
155 u64 perf_evlist__read_format(struct perf_evlist *evlist);
156 u64 __perf_evlist__combined_sample_type(struct perf_evlist *evlist);
157 u64 perf_evlist__combined_sample_type(struct perf_evlist *evlist);
158 bool perf_evlist__sample_id_all(struct perf_evlist *evlist);
159 u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist);
161 int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
162 struct perf_sample *sample);
164 bool perf_evlist__valid_sample_type(struct perf_evlist *evlist);
165 bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist);
166 bool perf_evlist__valid_read_format(struct perf_evlist *evlist);
168 void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
169 struct list_head *list,
172 static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
174 return list_entry(evlist->entries.next, struct perf_evsel, node);
177 static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist)
179 return list_entry(evlist->entries.prev, struct perf_evsel, node);
182 size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp);
184 int perf_evlist__strerror_tp(struct perf_evlist *evlist, int err, char *buf, size_t size);
185 int perf_evlist__strerror_open(struct perf_evlist *evlist, int err, char *buf, size_t size);
187 static inline unsigned int perf_mmap__read_head(struct perf_mmap *mm)
189 struct perf_event_mmap_page *pc = mm->base;
190 int head = ACCESS_ONCE(pc->data_head);
195 static inline void perf_mmap__write_tail(struct perf_mmap *md,
198 struct perf_event_mmap_page *pc = md->base;
201 * ensure all reads are done before we write the tail out.
204 pc->data_tail = tail;
207 bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str);
208 void perf_evlist__to_front(struct perf_evlist *evlist,
209 struct perf_evsel *move_evsel);
212 * __evlist__for_each - iterate thru all the evsels
213 * @list: list_head instance to iterate
214 * @evsel: struct evsel iterator
216 #define __evlist__for_each(list, evsel) \
217 list_for_each_entry(evsel, list, node)
220 * evlist__for_each - iterate thru all the evsels
221 * @evlist: evlist instance to iterate
222 * @evsel: struct evsel iterator
224 #define evlist__for_each(evlist, evsel) \
225 __evlist__for_each(&(evlist)->entries, evsel)
228 * __evlist__for_each_continue - continue iteration thru all the evsels
229 * @list: list_head instance to iterate
230 * @evsel: struct evsel iterator
232 #define __evlist__for_each_continue(list, evsel) \
233 list_for_each_entry_continue(evsel, list, node)
236 * evlist__for_each_continue - continue iteration thru all the evsels
237 * @evlist: evlist instance to iterate
238 * @evsel: struct evsel iterator
240 #define evlist__for_each_continue(evlist, evsel) \
241 __evlist__for_each_continue(&(evlist)->entries, evsel)
244 * __evlist__for_each_reverse - iterate thru all the evsels in reverse order
245 * @list: list_head instance to iterate
246 * @evsel: struct evsel iterator
248 #define __evlist__for_each_reverse(list, evsel) \
249 list_for_each_entry_reverse(evsel, list, node)
252 * evlist__for_each_reverse - iterate thru all the evsels in reverse order
253 * @evlist: evlist instance to iterate
254 * @evsel: struct evsel iterator
256 #define evlist__for_each_reverse(evlist, evsel) \
257 __evlist__for_each_reverse(&(evlist)->entries, evsel)
260 * __evlist__for_each_safe - safely iterate thru all the evsels
261 * @list: list_head instance to iterate
262 * @tmp: struct evsel temp iterator
263 * @evsel: struct evsel iterator
265 #define __evlist__for_each_safe(list, tmp, evsel) \
266 list_for_each_entry_safe(evsel, tmp, list, node)
269 * evlist__for_each_safe - safely iterate thru all the evsels
270 * @evlist: evlist instance to iterate
271 * @evsel: struct evsel iterator
272 * @tmp: struct evsel temp iterator
274 #define evlist__for_each_safe(evlist, tmp, evsel) \
275 __evlist__for_each_safe(&(evlist)->entries, tmp, evsel)
277 void perf_evlist__set_tracking_event(struct perf_evlist *evlist,
278 struct perf_evsel *tracking_evsel);
280 #endif /* __PERF_EVLIST_H */