ceph: use i_size_{read,write} to get/set i_size
[linux/fpc-iii.git] / tools / perf / util / evlist.h
bloba459fe71b452e0b721d798cc73cc6287ae87dc1c
1 #ifndef __PERF_EVLIST_H
2 #define __PERF_EVLIST_H 1
4 #include <linux/atomic.h>
5 #include <linux/list.h>
6 #include <api/fd/array.h>
7 #include <stdio.h>
8 #include "../perf.h"
9 #include "event.h"
10 #include "evsel.h"
11 #include "util.h"
12 #include "auxtrace.h"
13 #include <unistd.h>
15 struct pollfd;
16 struct thread_map;
17 struct cpu_map;
18 struct record_opts;
20 #define PERF_EVLIST__HLIST_BITS 8
21 #define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
23 /**
24 * struct perf_mmap - perf's ring buffer mmap details
26 * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
28 struct perf_mmap {
29 void *base;
30 int mask;
31 atomic_t refcnt;
32 u64 prev;
33 struct auxtrace_mmap auxtrace_mmap;
34 char event_copy[PERF_SAMPLE_MAX_SIZE] __attribute__((aligned(8)));
37 struct perf_evlist {
38 struct list_head entries;
39 struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
40 int nr_entries;
41 int nr_groups;
42 int nr_mmaps;
43 bool overwrite;
44 bool enabled;
45 bool has_user_cpus;
46 size_t mmap_len;
47 int id_pos;
48 int is_pos;
49 u64 combined_sample_type;
50 struct {
51 int cork_fd;
52 pid_t pid;
53 } workload;
54 struct fdarray pollfd;
55 struct perf_mmap *mmap;
56 struct thread_map *threads;
57 struct cpu_map *cpus;
58 struct perf_evsel *selected;
59 struct events_stats stats;
60 struct perf_env *env;
63 struct perf_evsel_str_handler {
64 const char *name;
65 void *handler;
68 struct perf_evlist *perf_evlist__new(void);
69 struct perf_evlist *perf_evlist__new_default(void);
70 void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
71 struct thread_map *threads);
72 void perf_evlist__exit(struct perf_evlist *evlist);
73 void perf_evlist__delete(struct perf_evlist *evlist);
75 void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry);
76 void perf_evlist__remove(struct perf_evlist *evlist, struct perf_evsel *evsel);
77 int perf_evlist__add_default(struct perf_evlist *evlist);
78 int __perf_evlist__add_default_attrs(struct perf_evlist *evlist,
79 struct perf_event_attr *attrs, size_t nr_attrs);
81 #define perf_evlist__add_default_attrs(evlist, array) \
82 __perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
84 int perf_evlist__add_newtp(struct perf_evlist *evlist,
85 const char *sys, const char *name, void *handler);
87 int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter);
88 int perf_evlist__set_filter_pid(struct perf_evlist *evlist, pid_t pid);
89 int perf_evlist__set_filter_pids(struct perf_evlist *evlist, size_t npids, pid_t *pids);
91 struct perf_evsel *
92 perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id);
94 struct perf_evsel *
95 perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,
96 const char *name);
98 void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
99 int cpu, int thread, u64 id);
101 int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd);
102 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
103 int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask);
105 int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
107 struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
108 struct perf_evsel *perf_evlist__id2evsel_strict(struct perf_evlist *evlist,
109 u64 id);
111 struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);
113 union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx);
115 void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx);
117 int perf_evlist__open(struct perf_evlist *evlist);
118 void perf_evlist__close(struct perf_evlist *evlist);
120 void perf_evlist__set_id_pos(struct perf_evlist *evlist);
121 bool perf_can_sample_identifier(void);
122 bool perf_can_record_switch_events(void);
123 bool perf_can_record_cpu_wide(void);
124 void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts);
125 int record_opts__config(struct record_opts *opts);
127 int perf_evlist__prepare_workload(struct perf_evlist *evlist,
128 struct target *target,
129 const char *argv[], bool pipe_output,
130 void (*exec_error)(int signo, siginfo_t *info,
131 void *ucontext));
132 int perf_evlist__start_workload(struct perf_evlist *evlist);
134 struct option;
136 int __perf_evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
137 int perf_evlist__parse_mmap_pages(const struct option *opt,
138 const char *str,
139 int unset);
141 int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
142 bool overwrite, unsigned int auxtrace_pages,
143 bool auxtrace_overwrite);
144 int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
145 bool overwrite);
146 void perf_evlist__munmap(struct perf_evlist *evlist);
148 void perf_evlist__disable(struct perf_evlist *evlist);
149 void perf_evlist__enable(struct perf_evlist *evlist);
150 void perf_evlist__toggle_enable(struct perf_evlist *evlist);
152 int perf_evlist__disable_event(struct perf_evlist *evlist,
153 struct perf_evsel *evsel);
154 int perf_evlist__enable_event(struct perf_evlist *evlist,
155 struct perf_evsel *evsel);
156 int perf_evlist__enable_event_idx(struct perf_evlist *evlist,
157 struct perf_evsel *evsel, int idx);
159 void perf_evlist__set_selected(struct perf_evlist *evlist,
160 struct perf_evsel *evsel);
162 void perf_evlist__set_maps(struct perf_evlist *evlist, struct cpu_map *cpus,
163 struct thread_map *threads);
164 int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target);
165 int perf_evlist__apply_filters(struct perf_evlist *evlist, struct perf_evsel **err_evsel);
167 void __perf_evlist__set_leader(struct list_head *list);
168 void perf_evlist__set_leader(struct perf_evlist *evlist);
170 u64 perf_evlist__read_format(struct perf_evlist *evlist);
171 u64 __perf_evlist__combined_sample_type(struct perf_evlist *evlist);
172 u64 perf_evlist__combined_sample_type(struct perf_evlist *evlist);
173 u64 perf_evlist__combined_branch_type(struct perf_evlist *evlist);
174 bool perf_evlist__sample_id_all(struct perf_evlist *evlist);
175 u16 perf_evlist__id_hdr_size(struct perf_evlist *evlist);
177 int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
178 struct perf_sample *sample);
180 bool perf_evlist__valid_sample_type(struct perf_evlist *evlist);
181 bool perf_evlist__valid_sample_id_all(struct perf_evlist *evlist);
182 bool perf_evlist__valid_read_format(struct perf_evlist *evlist);
184 void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
185 struct list_head *list);
187 static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
189 return list_entry(evlist->entries.next, struct perf_evsel, node);
192 static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist)
194 return list_entry(evlist->entries.prev, struct perf_evsel, node);
197 size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp);
199 int perf_evlist__strerror_open(struct perf_evlist *evlist, int err, char *buf, size_t size);
200 int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size);
202 static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
204 struct perf_event_mmap_page *pc = mm->base;
205 u64 head = ACCESS_ONCE(pc->data_head);
206 rmb();
207 return head;
210 static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
212 struct perf_event_mmap_page *pc = md->base;
215 * ensure all reads are done before we write the tail out.
217 mb();
218 pc->data_tail = tail;
221 bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str);
222 void perf_evlist__to_front(struct perf_evlist *evlist,
223 struct perf_evsel *move_evsel);
226 * __evlist__for_each - iterate thru all the evsels
227 * @list: list_head instance to iterate
228 * @evsel: struct evsel iterator
230 #define __evlist__for_each(list, evsel) \
231 list_for_each_entry(evsel, list, node)
234 * evlist__for_each - iterate thru all the evsels
235 * @evlist: evlist instance to iterate
236 * @evsel: struct evsel iterator
238 #define evlist__for_each(evlist, evsel) \
239 __evlist__for_each(&(evlist)->entries, evsel)
242 * __evlist__for_each_continue - continue iteration thru all the evsels
243 * @list: list_head instance to iterate
244 * @evsel: struct evsel iterator
246 #define __evlist__for_each_continue(list, evsel) \
247 list_for_each_entry_continue(evsel, list, node)
250 * evlist__for_each_continue - continue iteration thru all the evsels
251 * @evlist: evlist instance to iterate
252 * @evsel: struct evsel iterator
254 #define evlist__for_each_continue(evlist, evsel) \
255 __evlist__for_each_continue(&(evlist)->entries, evsel)
258 * __evlist__for_each_reverse - iterate thru all the evsels in reverse order
259 * @list: list_head instance to iterate
260 * @evsel: struct evsel iterator
262 #define __evlist__for_each_reverse(list, evsel) \
263 list_for_each_entry_reverse(evsel, list, node)
266 * evlist__for_each_reverse - iterate thru all the evsels in reverse order
267 * @evlist: evlist instance to iterate
268 * @evsel: struct evsel iterator
270 #define evlist__for_each_reverse(evlist, evsel) \
271 __evlist__for_each_reverse(&(evlist)->entries, evsel)
274 * __evlist__for_each_safe - safely iterate thru all the evsels
275 * @list: list_head instance to iterate
276 * @tmp: struct evsel temp iterator
277 * @evsel: struct evsel iterator
279 #define __evlist__for_each_safe(list, tmp, evsel) \
280 list_for_each_entry_safe(evsel, tmp, list, node)
283 * evlist__for_each_safe - safely iterate thru all the evsels
284 * @evlist: evlist instance to iterate
285 * @evsel: struct evsel iterator
286 * @tmp: struct evsel temp iterator
288 #define evlist__for_each_safe(evlist, tmp, evsel) \
289 __evlist__for_each_safe(&(evlist)->entries, tmp, evsel)
291 void perf_evlist__set_tracking_event(struct perf_evlist *evlist,
292 struct perf_evsel *tracking_evsel);
294 void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr);
295 #endif /* __PERF_EVLIST_H */