]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - tools/perf/util/evsel.h
perf tools: Force period term to overload global settings
[mirror_ubuntu-artful-kernel.git] / tools / perf / util / evsel.h
CommitLineData
69aad6f1
ACM
1#ifndef __PERF_EVSEL_H
2#define __PERF_EVSEL_H 1
3
4#include <linux/list.h>
c52b12ed 5#include <stdbool.h>
07ac002f 6#include <stddef.h>
d2709c7c 7#include <linux/perf_event.h>
d944c4ee 8#include <linux/types.h>
69aad6f1 9#include "xyarray.h"
759ff497 10#include "symbol.h"
a22e99cd 11#include "cpumap.h"
1ac77e1c 12#include "stat.h"
69aad6f1 13
70db7533
ACM
14struct 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 */
20struct perf_sample_id {
21 struct hlist_node node;
22 u64 id;
23 struct perf_evsel *evsel;
3c659eed
AH
24 int idx;
25 int cpu;
26 pid_t tid;
e4caec0d
JO
27
28 /* Holds total ID period value for PERF_SAMPLE_READ processing. */
29 u64 period;
70db7533
ACM
30};
31
f14d5707
ACM
32struct cgroup_sel;
33
930a2e29
JO
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*/
40enum {
ee4c7588 41 PERF_EVSEL__CONFIG_TERM_PERIOD,
930a2e29
JO
42 PERF_EVSEL__CONFIG_TERM_MAX,
43};
44
45struct perf_evsel_config_term {
46 struct list_head list;
47 int type;
48 union {
49 u64 period;
50 } val;
51};
52
f0c55bcf
SE
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.
75562573
AH
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
0db15b1e 64 * @priv: And what is in its containing unnamed union are tool specific
f0c55bcf 65 */
69aad6f1
ACM
66struct perf_evsel {
67 struct list_head node;
68 struct perf_event_attr attr;
69 char *filter;
70 struct xyarray *fd;
a91e5431
ACM
71 struct xyarray *sample_id;
72 u64 *id;
c52b12ed 73 struct perf_counts *counts;
c7a79c47 74 struct perf_counts *prev_raw_counts;
69aad6f1 75 int idx;
f4d83436 76 u32 ids;
f0c55bcf 77 char *name;
410136f5
SE
78 double scale;
79 const char *unit;
fcf65bf1 80 struct event_format *tp_format;
a91e5431
ACM
81 union {
82 void *priv;
83 off_t id_offset;
0db15b1e 84 u64 db_id;
a91e5431 85 };
023695d9 86 struct cgroup_sel *cgrp;
744a9719 87 void *handler;
7ae92e74 88 struct cpu_map *cpus;
578e91ec 89 struct thread_map *threads;
bde09467 90 unsigned int sample_size;
75562573
AH
91 int id_pos;
92 int is_pos;
86066064 93 bool snapshot;
2cee77c4 94 bool supported;
0807d2d8 95 bool needs_swap;
6ff1ce76 96 bool no_aux_samples;
2afd2bcf 97 bool immediate;
bf8e8f4b 98 bool system_wide;
60b0896c 99 bool tracking;
044330c1 100 bool per_pkg;
f5b1135b
JO
101 /* parse modifier helper */
102 int exclude_GH;
97f63e4a 103 int nr_members;
3c176311 104 int sample_read;
86066064 105 unsigned long *per_pkg_mask;
6a4bb04c
JO
106 struct perf_evsel *leader;
107 char *group_name;
15bfd2cc 108 bool cmdline_group_boundary;
930a2e29 109 struct list_head config_terms;
69aad6f1
ACM
110};
111
88080ce7
BP
112union u64_swap {
113 u64 val64;
114 u32 val32[2];
115};
116
86bd5e86 117struct cpu_map;
80b2210c 118struct target;
86bd5e86 119struct thread_map;
70082dd9 120struct perf_evlist;
b4006796 121struct record_opts;
86bd5e86 122
a22e99cd
JO
123static inline struct cpu_map *perf_evsel__cpus(struct perf_evsel *evsel)
124{
125 return evsel->cpus;
126}
127
128static inline int perf_evsel__nr_cpus(struct perf_evsel *evsel)
129{
130 return perf_evsel__cpus(evsel)->nr;
131}
132
13112bbf
JO
133void perf_counts_values__scale(struct perf_counts_values *count,
134 bool scale, s8 *pscaled);
135
a6fa0038 136void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu, int thread,
857a94a2
JO
137 struct perf_counts_values *count);
138
ce8ccff5
ACM
139int perf_evsel__object_config(size_t object_size,
140 int (*init)(struct perf_evsel *evsel),
141 void (*fini)(struct perf_evsel *evsel));
142
ef503831
ACM
143struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx);
144
145static inline struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
146{
147 return perf_evsel__new_idx(attr, 0);
148}
149
150struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx);
151
152static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name)
153{
154 return perf_evsel__newtp_idx(sys, name, 0);
155}
201b7334
ACM
156
157struct event_format *event_format__new(const char *sys, const char *name);
158
ef1d1af2
ACM
159void perf_evsel__init(struct perf_evsel *evsel,
160 struct perf_event_attr *attr, int idx);
161void perf_evsel__exit(struct perf_evsel *evsel);
69aad6f1
ACM
162void perf_evsel__delete(struct perf_evsel *evsel);
163
0f82ebc4 164void perf_evsel__config(struct perf_evsel *evsel,
b4006796 165 struct record_opts *opts);
0f82ebc4 166
75562573
AH
167int __perf_evsel__sample_size(u64 sample_type);
168void perf_evsel__calc_id_pos(struct perf_evsel *evsel);
169
0b668bc9
ACM
170bool perf_evsel__is_cache_op_valid(u8 type, u8 op);
171
172#define PERF_EVSEL__MAX_ALIASES 8
173
174extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
175 [PERF_EVSEL__MAX_ALIASES];
176extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
177 [PERF_EVSEL__MAX_ALIASES];
8ad7013b
ACM
178extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
179 [PERF_EVSEL__MAX_ALIASES];
180extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX];
181extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX];
0b668bc9
ACM
182int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
183 char *bf, size_t size);
7289f83c 184const char *perf_evsel__name(struct perf_evsel *evsel);
410136f5 185
717e263f
NK
186const char *perf_evsel__group_name(struct perf_evsel *evsel);
187int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size);
c410431c 188
70db7533 189int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
c52b12ed 190void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
69aad6f1 191
7be5ebe8
ACM
192void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
193 enum perf_event_sample_format bit);
194void __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
75562573
AH
203void perf_evsel__set_sample_id(struct perf_evsel *evsel,
204 bool use_sample_identifier);
7a5a5ca5 205
12467ae4 206int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter);
64ec84f5
ACM
207int perf_evsel__append_filter(struct perf_evsel *evsel,
208 const char *op, const char *filter);
f47805a2
ACM
209int perf_evsel__apply_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
210 const char *filter);
e2407bef 211int perf_evsel__enable(struct perf_evsel *evsel, int ncpus, int nthreads);
745cefc5 212
f08199d3 213int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
6a4bb04c 214 struct cpu_map *cpus);
f08199d3 215int perf_evsel__open_per_thread(struct perf_evsel *evsel,
6a4bb04c 216 struct thread_map *threads);
f08199d3 217int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
6a4bb04c 218 struct thread_map *threads);
727ab04e 219void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
48290609 220
5555ded4
ACM
221struct perf_sample;
222
5d2074ea 223void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
5555ded4
ACM
224 const char *name);
225u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
226 const char *name);
227
5d2074ea
ACM
228static 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
efd2b924
ACM
235struct format_field;
236
237struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
238
daec78a0
ACM
239#define perf_evsel__match(evsel, t, c) \
240 (evsel->attr.type == PERF_TYPE_##t && \
241 evsel->attr.config == PERF_COUNT_##c)
242
863e451f
JO
243static 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
4cabc3d1
AK
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
f99f4719
JO
256int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
257 struct perf_counts_values *count);
258
c52b12ed
ACM
259int __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 */
269static 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 */
282static 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
a3f698fe 288int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
0807d2d8 289 struct perf_sample *sample);
0c21f736
ACM
290
291static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
292{
293 return list_entry(evsel->node.next, struct perf_evsel, node);
294}
07ac002f 295
d87fcb4a
ACM
296static 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
759ff497
NK
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 */
823254ed 308static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
07ac002f 309{
823254ed 310 return evsel->leader == evsel;
07ac002f 311}
0698aedd 312
759ff497
NK
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 */
321static 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
6bedfab6
JO
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 */
337static 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
0698aedd
ACM
347struct perf_attr_details {
348 bool freq;
349 bool verbose;
e35ef355 350 bool event_group;
9e3b6ec1 351 bool force;
0698aedd
ACM
352};
353
354int perf_evsel__fprintf(struct perf_evsel *evsel,
355 struct perf_attr_details *details, FILE *fp);
c0a54341
ACM
356
357bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
358 char *msg, size_t msgsize);
602ad878 359int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
56e52e85 360 int err, char *msg, size_t size);
97f63e4a
NK
361
362static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
363{
364 return evsel->idx - evsel->leader->idx;
365}
717e263f
NK
366
367#define for_each_group_member(_evsel, _leader) \
368for ((_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
384b6055
KL
372static inline bool has_branch_callstack(struct perf_evsel *evsel)
373{
374 return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
375}
2c5e8c52
PZ
376
377typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *);
378
379int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
380 attr__fprintf_f attr__fprintf, void *priv);
381
69aad6f1 382#endif /* __PERF_EVSEL_H */