a7d2175358b8bf416c7048b506f08d89b4e99808
[deliverable/linux.git] / tools / perf / util / evsel.h
1 #ifndef __PERF_EVSEL_H
2 #define __PERF_EVSEL_H 1
3
4 #include <linux/list.h>
5 #include <stdbool.h>
6 #include <stddef.h>
7 #include <linux/perf_event.h>
8 #include <linux/types.h>
9 #include "xyarray.h"
10 #include "symbol.h"
11 #include "cpumap.h"
12 #include "stat.h"
13
14 struct perf_evsel;
15
16 /*
17 * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
18 * more than one entry in the evlist.
19 */
20 struct perf_sample_id {
21 struct hlist_node node;
22 u64 id;
23 struct perf_evsel *evsel;
24 int idx;
25 int cpu;
26 pid_t tid;
27
28 /* Holds total ID period value for PERF_SAMPLE_READ processing. */
29 u64 period;
30 };
31
32 struct cgroup_sel;
33
34 /*
35 * The 'struct perf_evsel_config_term' is used to pass event
36 * specific configuration data to perf_evsel__config routine.
37 * It is allocated within event parsing and attached to
38 * perf_evsel::config_terms list head.
39 */
40 enum {
41 PERF_EVSEL__CONFIG_TERM_PERIOD,
42 PERF_EVSEL__CONFIG_TERM_MAX,
43 };
44
45 struct perf_evsel_config_term {
46 struct list_head list;
47 int type;
48 union {
49 u64 period;
50 } val;
51 };
52
53 /** struct perf_evsel - event selector
54 *
55 * @name - Can be set to retain the original event name passed by the user,
56 * so that when showing results in tools such as 'perf stat', we
57 * show the name used, not some alias.
58 * @id_pos: the position of the event id (PERF_SAMPLE_ID or
59 * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of
60 * struct sample_event
61 * @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or
62 * PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all
63 * is used there is an id sample appended to non-sample events
64 * @priv: And what is in its containing unnamed union are tool specific
65 */
66 struct perf_evsel {
67 struct list_head node;
68 struct perf_event_attr attr;
69 char *filter;
70 struct xyarray *fd;
71 struct xyarray *sample_id;
72 u64 *id;
73 struct perf_counts *counts;
74 struct perf_counts *prev_raw_counts;
75 int idx;
76 u32 ids;
77 char *name;
78 double scale;
79 const char *unit;
80 struct event_format *tp_format;
81 union {
82 void *priv;
83 off_t id_offset;
84 u64 db_id;
85 };
86 struct cgroup_sel *cgrp;
87 void *handler;
88 struct cpu_map *cpus;
89 struct thread_map *threads;
90 unsigned int sample_size;
91 int id_pos;
92 int is_pos;
93 bool snapshot;
94 bool supported;
95 bool needs_swap;
96 bool no_aux_samples;
97 bool immediate;
98 bool system_wide;
99 bool tracking;
100 bool per_pkg;
101 /* parse modifier helper */
102 int exclude_GH;
103 int nr_members;
104 int sample_read;
105 unsigned long *per_pkg_mask;
106 struct perf_evsel *leader;
107 char *group_name;
108 bool cmdline_group_boundary;
109 struct list_head config_terms;
110 };
111
112 union u64_swap {
113 u64 val64;
114 u32 val32[2];
115 };
116
117 struct cpu_map;
118 struct target;
119 struct thread_map;
120 struct perf_evlist;
121 struct record_opts;
122
123 static inline struct cpu_map *perf_evsel__cpus(struct perf_evsel *evsel)
124 {
125 return evsel->cpus;
126 }
127
128 static inline int perf_evsel__nr_cpus(struct perf_evsel *evsel)
129 {
130 return perf_evsel__cpus(evsel)->nr;
131 }
132
133 void perf_counts_values__scale(struct perf_counts_values *count,
134 bool scale, s8 *pscaled);
135
136 void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu, int thread,
137 struct perf_counts_values *count);
138
139 int perf_evsel__object_config(size_t object_size,
140 int (*init)(struct perf_evsel *evsel),
141 void (*fini)(struct perf_evsel *evsel));
142
143 struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx);
144
145 static inline struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
146 {
147 return perf_evsel__new_idx(attr, 0);
148 }
149
150 struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx);
151
152 static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name)
153 {
154 return perf_evsel__newtp_idx(sys, name, 0);
155 }
156
157 struct event_format *event_format__new(const char *sys, const char *name);
158
159 void perf_evsel__init(struct perf_evsel *evsel,
160 struct perf_event_attr *attr, int idx);
161 void perf_evsel__exit(struct perf_evsel *evsel);
162 void perf_evsel__delete(struct perf_evsel *evsel);
163
164 void perf_evsel__config(struct perf_evsel *evsel,
165 struct record_opts *opts);
166
167 int __perf_evsel__sample_size(u64 sample_type);
168 void perf_evsel__calc_id_pos(struct perf_evsel *evsel);
169
170 bool perf_evsel__is_cache_op_valid(u8 type, u8 op);
171
172 #define PERF_EVSEL__MAX_ALIASES 8
173
174 extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
175 [PERF_EVSEL__MAX_ALIASES];
176 extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
177 [PERF_EVSEL__MAX_ALIASES];
178 extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
179 [PERF_EVSEL__MAX_ALIASES];
180 extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX];
181 extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX];
182 int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
183 char *bf, size_t size);
184 const char *perf_evsel__name(struct perf_evsel *evsel);
185
186 const char *perf_evsel__group_name(struct perf_evsel *evsel);
187 int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size);
188
189 int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
190 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
191
192 void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
193 enum perf_event_sample_format bit);
194 void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel,
195 enum perf_event_sample_format bit);
196
197 #define perf_evsel__set_sample_bit(evsel, bit) \
198 __perf_evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
199
200 #define perf_evsel__reset_sample_bit(evsel, bit) \
201 __perf_evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
202
203 void perf_evsel__set_sample_id(struct perf_evsel *evsel,
204 bool use_sample_identifier);
205
206 int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter);
207 int perf_evsel__append_filter(struct perf_evsel *evsel,
208 const char *op, const char *filter);
209 int perf_evsel__apply_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
210 const char *filter);
211 int perf_evsel__enable(struct perf_evsel *evsel, int ncpus, int nthreads);
212
213 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
214 struct cpu_map *cpus);
215 int perf_evsel__open_per_thread(struct perf_evsel *evsel,
216 struct thread_map *threads);
217 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
218 struct thread_map *threads);
219 void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
220
221 struct perf_sample;
222
223 void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
224 const char *name);
225 u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
226 const char *name);
227
228 static inline char *perf_evsel__strval(struct perf_evsel *evsel,
229 struct perf_sample *sample,
230 const char *name)
231 {
232 return perf_evsel__rawptr(evsel, sample, name);
233 }
234
235 struct format_field;
236
237 struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
238
239 #define perf_evsel__match(evsel, t, c) \
240 (evsel->attr.type == PERF_TYPE_##t && \
241 evsel->attr.config == PERF_COUNT_##c)
242
243 static inline bool perf_evsel__match2(struct perf_evsel *e1,
244 struct perf_evsel *e2)
245 {
246 return (e1->attr.type == e2->attr.type) &&
247 (e1->attr.config == e2->attr.config);
248 }
249
250 #define perf_evsel__cmp(a, b) \
251 ((a) && \
252 (b) && \
253 (a)->attr.type == (b)->attr.type && \
254 (a)->attr.config == (b)->attr.config)
255
256 int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
257 struct perf_counts_values *count);
258
259 int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
260 int cpu, int thread, bool scale);
261
262 /**
263 * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
264 *
265 * @evsel - event selector to read value
266 * @cpu - CPU of interest
267 * @thread - thread of interest
268 */
269 static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
270 int cpu, int thread)
271 {
272 return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
273 }
274
275 /**
276 * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
277 *
278 * @evsel - event selector to read value
279 * @cpu - CPU of interest
280 * @thread - thread of interest
281 */
282 static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
283 int cpu, int thread)
284 {
285 return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
286 }
287
288 int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
289 struct perf_sample *sample);
290
291 static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
292 {
293 return list_entry(evsel->node.next, struct perf_evsel, node);
294 }
295
296 static inline struct perf_evsel *perf_evsel__prev(struct perf_evsel *evsel)
297 {
298 return list_entry(evsel->node.prev, struct perf_evsel, node);
299 }
300
301 /**
302 * perf_evsel__is_group_leader - Return whether given evsel is a leader event
303 *
304 * @evsel - evsel selector to be tested
305 *
306 * Return %true if @evsel is a group leader or a stand-alone event
307 */
308 static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
309 {
310 return evsel->leader == evsel;
311 }
312
313 /**
314 * perf_evsel__is_group_event - Return whether given evsel is a group event
315 *
316 * @evsel - evsel selector to be tested
317 *
318 * Return %true iff event group view is enabled and @evsel is a actual group
319 * leader which has other members in the group
320 */
321 static inline bool perf_evsel__is_group_event(struct perf_evsel *evsel)
322 {
323 if (!symbol_conf.event_group)
324 return false;
325
326 return perf_evsel__is_group_leader(evsel) && evsel->nr_members > 1;
327 }
328
329 /**
330 * perf_evsel__is_function_event - Return whether given evsel is a function
331 * trace event
332 *
333 * @evsel - evsel selector to be tested
334 *
335 * Return %true if event is function trace event
336 */
337 static inline bool perf_evsel__is_function_event(struct perf_evsel *evsel)
338 {
339 #define FUNCTION_EVENT "ftrace:function"
340
341 return evsel->name &&
342 !strncmp(FUNCTION_EVENT, evsel->name, sizeof(FUNCTION_EVENT));
343
344 #undef FUNCTION_EVENT
345 }
346
347 struct perf_attr_details {
348 bool freq;
349 bool verbose;
350 bool event_group;
351 bool force;
352 };
353
354 int perf_evsel__fprintf(struct perf_evsel *evsel,
355 struct perf_attr_details *details, FILE *fp);
356
357 bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
358 char *msg, size_t msgsize);
359 int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
360 int err, char *msg, size_t size);
361
362 static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
363 {
364 return evsel->idx - evsel->leader->idx;
365 }
366
367 #define for_each_group_member(_evsel, _leader) \
368 for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); \
369 (_evsel) && (_evsel)->leader == (_leader); \
370 (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
371
372 static inline bool has_branch_callstack(struct perf_evsel *evsel)
373 {
374 return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
375 }
376
377 typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *);
378
379 int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
380 attr__fprintf_f attr__fprintf, void *priv);
381
382 #endif /* __PERF_EVSEL_H */
This page took 0.037754 seconds and 4 git commands to generate.