1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define __PERF_EVSEL_H 1
5 #include <linux/list.h>
8 #include <linux/perf_event.h>
9 #include <linux/types.h>
11 #include "symbol_conf.h"
18 * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
19 * more than one entry in the evlist.
21 struct perf_sample_id
{
22 struct hlist_node node
;
24 struct perf_evsel
*evsel
;
29 /* Holds total ID period value for PERF_SAMPLE_READ processing. */
36 * The 'struct perf_evsel_config_term' is used to pass event
37 * specific configuration data to perf_evsel__config routine.
38 * It is allocated within event parsing and attached to
39 * perf_evsel::config_terms list head.
42 PERF_EVSEL__CONFIG_TERM_PERIOD
,
43 PERF_EVSEL__CONFIG_TERM_FREQ
,
44 PERF_EVSEL__CONFIG_TERM_TIME
,
45 PERF_EVSEL__CONFIG_TERM_CALLGRAPH
,
46 PERF_EVSEL__CONFIG_TERM_STACK_USER
,
47 PERF_EVSEL__CONFIG_TERM_INHERIT
,
48 PERF_EVSEL__CONFIG_TERM_MAX_STACK
,
49 PERF_EVSEL__CONFIG_TERM_MAX_EVENTS
,
50 PERF_EVSEL__CONFIG_TERM_OVERWRITE
,
51 PERF_EVSEL__CONFIG_TERM_DRV_CFG
,
52 PERF_EVSEL__CONFIG_TERM_BRANCH
,
53 PERF_EVSEL__CONFIG_TERM_PERCORE
,
56 struct perf_evsel_config_term
{
57 struct list_head list
;
70 unsigned long max_events
;
76 struct perf_stat_evsel
;
78 typedef int (perf_evsel__sb_cb_t
)(union perf_event
*event
, void *data
);
80 enum perf_tool_event
{
82 PERF_TOOL_DURATION_TIME
= 1,
85 /** struct perf_evsel - event selector
87 * @evlist - evlist this evsel is in, if it is in one.
88 * @node - To insert it into evlist->entries or in other list_heads, say in
89 * the event parsing routines.
90 * @name - Can be set to retain the original event name passed by the user,
91 * so that when showing results in tools such as 'perf stat', we
92 * show the name used, not some alias.
93 * @id_pos: the position of the event id (PERF_SAMPLE_ID or
94 * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of
96 * @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or
97 * PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all
98 * is used there is an id sample appended to non-sample events
99 * @priv: And what is in its containing unnamed union are tool specific
102 struct list_head node
;
103 struct perf_evlist
*evlist
;
104 struct perf_event_attr attr
;
107 struct xyarray
*sample_id
;
109 struct perf_counts
*counts
;
110 struct perf_counts
*prev_raw_counts
;
113 unsigned long max_events
;
114 unsigned long nr_events_printed
;
118 struct tep_event
*tp_format
;
120 struct perf_stat_evsel
*stats
;
125 struct cpu_map
*cpus
;
126 struct cpu_map
*own_cpus
;
127 struct thread_map
*threads
;
128 unsigned int sample_size
;
131 enum perf_tool_event tool_event
;
132 bool uniquified_name
;
143 bool ignore_missing_thread
;
145 bool use_uncore_alias
;
146 /* parse modifier helper */
150 unsigned long *per_pkg_mask
;
151 struct perf_evsel
*leader
;
153 bool cmdline_group_boundary
;
154 struct list_head config_terms
;
156 bool auto_merge_stats
;
158 const char * metric_expr
;
159 const char * metric_name
;
160 struct perf_evsel
**metric_events
;
164 const char *pmu_name
;
166 perf_evsel__sb_cb_t
*cb
;
176 struct perf_missing_features
{
190 extern struct perf_missing_features perf_missing_features
;
197 static inline struct cpu_map
*perf_evsel__cpus(struct perf_evsel
*evsel
)
202 static inline int perf_evsel__nr_cpus(struct perf_evsel
*evsel
)
204 return perf_evsel__cpus(evsel
)->nr
;
207 void perf_counts_values__scale(struct perf_counts_values
*count
,
208 bool scale
, s8
*pscaled
);
210 void perf_evsel__compute_deltas(struct perf_evsel
*evsel
, int cpu
, int thread
,
211 struct perf_counts_values
*count
);
213 int perf_evsel__object_config(size_t object_size
,
214 int (*init
)(struct perf_evsel
*evsel
),
215 void (*fini
)(struct perf_evsel
*evsel
));
217 struct perf_evsel
*perf_evsel__new_idx(struct perf_event_attr
*attr
, int idx
);
219 static inline struct perf_evsel
*perf_evsel__new(struct perf_event_attr
*attr
)
221 return perf_evsel__new_idx(attr
, 0);
224 struct perf_evsel
*perf_evsel__newtp_idx(const char *sys
, const char *name
, int idx
);
227 * Returns pointer with encoded error via <linux/err.h> interface.
229 static inline struct perf_evsel
*perf_evsel__newtp(const char *sys
, const char *name
)
231 return perf_evsel__newtp_idx(sys
, name
, 0);
234 struct perf_evsel
*perf_evsel__new_cycles(bool precise
);
236 struct tep_event
*event_format__new(const char *sys
, const char *name
);
238 void perf_evsel__init(struct perf_evsel
*evsel
,
239 struct perf_event_attr
*attr
, int idx
);
240 void perf_evsel__exit(struct perf_evsel
*evsel
);
241 void perf_evsel__delete(struct perf_evsel
*evsel
);
243 struct callchain_param
;
245 void perf_evsel__config(struct perf_evsel
*evsel
,
246 struct record_opts
*opts
,
247 struct callchain_param
*callchain
);
248 void perf_evsel__config_callchain(struct perf_evsel
*evsel
,
249 struct record_opts
*opts
,
250 struct callchain_param
*callchain
);
252 int __perf_evsel__sample_size(u64 sample_type
);
253 void perf_evsel__calc_id_pos(struct perf_evsel
*evsel
);
255 bool perf_evsel__is_cache_op_valid(u8 type
, u8 op
);
257 #define PERF_EVSEL__MAX_ALIASES 8
259 extern const char *perf_evsel__hw_cache
[PERF_COUNT_HW_CACHE_MAX
]
260 [PERF_EVSEL__MAX_ALIASES
];
261 extern const char *perf_evsel__hw_cache_op
[PERF_COUNT_HW_CACHE_OP_MAX
]
262 [PERF_EVSEL__MAX_ALIASES
];
263 extern const char *perf_evsel__hw_cache_result
[PERF_COUNT_HW_CACHE_RESULT_MAX
]
264 [PERF_EVSEL__MAX_ALIASES
];
265 extern const char *perf_evsel__hw_names
[PERF_COUNT_HW_MAX
];
266 extern const char *perf_evsel__sw_names
[PERF_COUNT_SW_MAX
];
267 int __perf_evsel__hw_cache_type_op_res_name(u8 type
, u8 op
, u8 result
,
268 char *bf
, size_t size
);
269 const char *perf_evsel__name(struct perf_evsel
*evsel
);
271 const char *perf_evsel__group_name(struct perf_evsel
*evsel
);
272 int perf_evsel__group_desc(struct perf_evsel
*evsel
, char *buf
, size_t size
);
274 int perf_evsel__alloc_id(struct perf_evsel
*evsel
, int ncpus
, int nthreads
);
275 void perf_evsel__close_fd(struct perf_evsel
*evsel
);
277 void __perf_evsel__set_sample_bit(struct perf_evsel
*evsel
,
278 enum perf_event_sample_format bit
);
279 void __perf_evsel__reset_sample_bit(struct perf_evsel
*evsel
,
280 enum perf_event_sample_format bit
);
282 #define perf_evsel__set_sample_bit(evsel, bit) \
283 __perf_evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
285 #define perf_evsel__reset_sample_bit(evsel, bit) \
286 __perf_evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
288 void perf_evsel__set_sample_id(struct perf_evsel
*evsel
,
289 bool use_sample_identifier
);
291 int perf_evsel__set_filter(struct perf_evsel
*evsel
, const char *filter
);
292 int perf_evsel__append_tp_filter(struct perf_evsel
*evsel
, const char *filter
);
293 int perf_evsel__append_addr_filter(struct perf_evsel
*evsel
,
295 int perf_evsel__apply_filter(struct perf_evsel
*evsel
, const char *filter
);
296 int perf_evsel__enable(struct perf_evsel
*evsel
);
297 int perf_evsel__disable(struct perf_evsel
*evsel
);
299 int perf_evsel__open_per_cpu(struct perf_evsel
*evsel
,
300 struct cpu_map
*cpus
);
301 int perf_evsel__open_per_thread(struct perf_evsel
*evsel
,
302 struct thread_map
*threads
);
303 int perf_evsel__open(struct perf_evsel
*evsel
, struct cpu_map
*cpus
,
304 struct thread_map
*threads
);
305 void perf_evsel__close(struct perf_evsel
*evsel
);
309 void *perf_evsel__rawptr(struct perf_evsel
*evsel
, struct perf_sample
*sample
,
311 u64
perf_evsel__intval(struct perf_evsel
*evsel
, struct perf_sample
*sample
,
314 static inline char *perf_evsel__strval(struct perf_evsel
*evsel
,
315 struct perf_sample
*sample
,
318 return perf_evsel__rawptr(evsel
, sample
, name
);
321 struct tep_format_field
;
323 u64
format_field__intval(struct tep_format_field
*field
, struct perf_sample
*sample
, bool needs_swap
);
325 struct tep_format_field
*perf_evsel__field(struct perf_evsel
*evsel
, const char *name
);
327 #define perf_evsel__match(evsel, t, c) \
328 (evsel->attr.type == PERF_TYPE_##t && \
329 evsel->attr.config == PERF_COUNT_##c)
331 static inline bool perf_evsel__match2(struct perf_evsel
*e1
,
332 struct perf_evsel
*e2
)
334 return (e1
->attr
.type
== e2
->attr
.type
) &&
335 (e1
->attr
.config
== e2
->attr
.config
);
338 #define perf_evsel__cmp(a, b) \
341 (a)->attr.type == (b)->attr.type && \
342 (a)->attr.config == (b)->attr.config)
344 int perf_evsel__read(struct perf_evsel
*evsel
, int cpu
, int thread
,
345 struct perf_counts_values
*count
);
347 int perf_evsel__read_counter(struct perf_evsel
*evsel
, int cpu
, int thread
);
349 int __perf_evsel__read_on_cpu(struct perf_evsel
*evsel
,
350 int cpu
, int thread
, bool scale
);
353 * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
355 * @evsel - event selector to read value
356 * @cpu - CPU of interest
357 * @thread - thread of interest
359 static inline int perf_evsel__read_on_cpu(struct perf_evsel
*evsel
,
362 return __perf_evsel__read_on_cpu(evsel
, cpu
, thread
, false);
366 * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
368 * @evsel - event selector to read value
369 * @cpu - CPU of interest
370 * @thread - thread of interest
372 static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel
*evsel
,
375 return __perf_evsel__read_on_cpu(evsel
, cpu
, thread
, true);
378 int perf_evsel__parse_sample(struct perf_evsel
*evsel
, union perf_event
*event
,
379 struct perf_sample
*sample
);
381 int perf_evsel__parse_sample_timestamp(struct perf_evsel
*evsel
,
382 union perf_event
*event
,
385 static inline struct perf_evsel
*perf_evsel__next(struct perf_evsel
*evsel
)
387 return list_entry(evsel
->node
.next
, struct perf_evsel
, node
);
390 static inline struct perf_evsel
*perf_evsel__prev(struct perf_evsel
*evsel
)
392 return list_entry(evsel
->node
.prev
, struct perf_evsel
, node
);
396 * perf_evsel__is_group_leader - Return whether given evsel is a leader event
398 * @evsel - evsel selector to be tested
400 * Return %true if @evsel is a group leader or a stand-alone event
402 static inline bool perf_evsel__is_group_leader(const struct perf_evsel
*evsel
)
404 return evsel
->leader
== evsel
;
408 * perf_evsel__is_group_event - Return whether given evsel is a group event
410 * @evsel - evsel selector to be tested
412 * Return %true iff event group view is enabled and @evsel is a actual group
413 * leader which has other members in the group
415 static inline bool perf_evsel__is_group_event(struct perf_evsel
*evsel
)
417 if (!symbol_conf
.event_group
)
420 return perf_evsel__is_group_leader(evsel
) && evsel
->nr_members
> 1;
423 bool perf_evsel__is_function_event(struct perf_evsel
*evsel
);
425 static inline bool perf_evsel__is_bpf_output(struct perf_evsel
*evsel
)
427 return perf_evsel__match(evsel
, SOFTWARE
, SW_BPF_OUTPUT
);
430 static inline bool perf_evsel__is_clock(struct perf_evsel
*evsel
)
432 return perf_evsel__match(evsel
, SOFTWARE
, SW_CPU_CLOCK
) ||
433 perf_evsel__match(evsel
, SOFTWARE
, SW_TASK_CLOCK
);
436 struct perf_attr_details
{
444 int perf_evsel__fprintf(struct perf_evsel
*evsel
,
445 struct perf_attr_details
*details
, FILE *fp
);
447 #define EVSEL__PRINT_IP (1<<0)
448 #define EVSEL__PRINT_SYM (1<<1)
449 #define EVSEL__PRINT_DSO (1<<2)
450 #define EVSEL__PRINT_SYMOFFSET (1<<3)
451 #define EVSEL__PRINT_ONELINE (1<<4)
452 #define EVSEL__PRINT_SRCLINE (1<<5)
453 #define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<6)
454 #define EVSEL__PRINT_CALLCHAIN_ARROW (1<<7)
455 #define EVSEL__PRINT_SKIP_IGNORED (1<<8)
457 struct callchain_cursor
;
459 int sample__fprintf_callchain(struct perf_sample
*sample
, int left_alignment
,
460 unsigned int print_opts
,
461 struct callchain_cursor
*cursor
, FILE *fp
);
463 int sample__fprintf_sym(struct perf_sample
*sample
, struct addr_location
*al
,
464 int left_alignment
, unsigned int print_opts
,
465 struct callchain_cursor
*cursor
, FILE *fp
);
467 bool perf_evsel__fallback(struct perf_evsel
*evsel
, int err
,
468 char *msg
, size_t msgsize
);
469 int perf_evsel__open_strerror(struct perf_evsel
*evsel
, struct target
*target
,
470 int err
, char *msg
, size_t size
);
472 static inline int perf_evsel__group_idx(struct perf_evsel
*evsel
)
474 return evsel
->idx
- evsel
->leader
->idx
;
477 /* Iterates group WITHOUT the leader. */
478 #define for_each_group_member(_evsel, _leader) \
479 for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); \
480 (_evsel) && (_evsel)->leader == (_leader); \
481 (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
483 /* Iterates group WITH the leader. */
484 #define for_each_group_evsel(_evsel, _leader) \
485 for ((_evsel) = _leader; \
486 (_evsel) && (_evsel)->leader == (_leader); \
487 (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
489 static inline bool perf_evsel__has_branch_callstack(const struct perf_evsel
*evsel
)
491 return evsel
->attr
.branch_sample_type
& PERF_SAMPLE_BRANCH_CALL_STACK
;
494 static inline bool evsel__has_callchain(const struct perf_evsel
*evsel
)
496 return (evsel
->attr
.sample_type
& PERF_SAMPLE_CALLCHAIN
) != 0;
499 typedef int (*attr__fprintf_f
)(FILE *, const char *, const char *, void *);
501 int perf_event_attr__fprintf(FILE *fp
, struct perf_event_attr
*attr
,
502 attr__fprintf_f attr__fprintf
, void *priv
);
504 struct perf_env
*perf_evsel__env(struct perf_evsel
*evsel
);
506 int perf_evsel__store_ids(struct perf_evsel
*evsel
, struct perf_evlist
*evlist
);
507 #endif /* __PERF_EVSEL_H */