evsel.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #ifndef __PERF_EVSEL_H
  2. #define __PERF_EVSEL_H 1
  3. #include <linux/list.h>
  4. #include <stdbool.h>
  5. #include <stddef.h>
  6. #include <linux/perf_event.h>
  7. #include "types.h"
  8. #include "xyarray.h"
  9. #include "cgroup.h"
  10. #include "hist.h"
  11. struct perf_counts_values {
  12. union {
  13. struct {
  14. u64 val;
  15. u64 ena;
  16. u64 run;
  17. };
  18. u64 values[3];
  19. };
  20. };
  21. struct perf_counts {
  22. s8 scaled;
  23. struct perf_counts_values aggr;
  24. struct perf_counts_values cpu[];
  25. };
  26. struct perf_evsel;
  27. /*
  28. * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
  29. * more than one entry in the evlist.
  30. */
  31. struct perf_sample_id {
  32. struct hlist_node node;
  33. u64 id;
  34. struct perf_evsel *evsel;
  35. };
  36. /** struct perf_evsel - event selector
  37. *
  38. * @name - Can be set to retain the original event name passed by the user,
  39. * so that when showing results in tools such as 'perf stat', we
  40. * show the name used, not some alias.
  41. */
  42. struct perf_evsel {
  43. struct list_head node;
  44. struct perf_event_attr attr;
  45. char *filter;
  46. struct xyarray *fd;
  47. struct xyarray *sample_id;
  48. u64 *id;
  49. struct perf_counts *counts;
  50. struct perf_counts *prev_raw_counts;
  51. int idx;
  52. u32 ids;
  53. struct hists hists;
  54. char *name;
  55. struct event_format *tp_format;
  56. union {
  57. void *priv;
  58. off_t id_offset;
  59. };
  60. struct cgroup_sel *cgrp;
  61. struct {
  62. void *func;
  63. void *data;
  64. } handler;
  65. struct cpu_map *cpus;
  66. unsigned int sample_size;
  67. bool supported;
  68. bool needs_swap;
  69. /* parse modifier helper */
  70. int exclude_GH;
  71. int nr_members;
  72. struct perf_evsel *leader;
  73. char *group_name;
  74. };
  75. #define hists_to_evsel(h) container_of(h, struct perf_evsel, hists)
  76. struct cpu_map;
  77. struct thread_map;
  78. struct perf_evlist;
  79. struct perf_record_opts;
  80. struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
  81. struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name, int idx);
  82. struct event_format *event_format__new(const char *sys, const char *name);
  83. void perf_evsel__init(struct perf_evsel *evsel,
  84. struct perf_event_attr *attr, int idx);
  85. void perf_evsel__exit(struct perf_evsel *evsel);
  86. void perf_evsel__delete(struct perf_evsel *evsel);
  87. void perf_evsel__config(struct perf_evsel *evsel,
  88. struct perf_record_opts *opts);
  89. bool perf_evsel__is_cache_op_valid(u8 type, u8 op);
  90. #define PERF_EVSEL__MAX_ALIASES 8
  91. extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
  92. [PERF_EVSEL__MAX_ALIASES];
  93. extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
  94. [PERF_EVSEL__MAX_ALIASES];
  95. extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
  96. [PERF_EVSEL__MAX_ALIASES];
  97. extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX];
  98. extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX];
  99. int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
  100. char *bf, size_t size);
  101. const char *perf_evsel__name(struct perf_evsel *evsel);
  102. const char *perf_evsel__group_name(struct perf_evsel *evsel);
  103. int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size);
  104. int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  105. int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
  106. int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
  107. void perf_evsel__free_fd(struct perf_evsel *evsel);
  108. void perf_evsel__free_id(struct perf_evsel *evsel);
  109. void perf_evsel__free_counts(struct perf_evsel *evsel);
  110. void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  111. void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
  112. enum perf_event_sample_format bit);
  113. void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel,
  114. enum perf_event_sample_format bit);
  115. #define perf_evsel__set_sample_bit(evsel, bit) \
  116. __perf_evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
  117. #define perf_evsel__reset_sample_bit(evsel, bit) \
  118. __perf_evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
  119. void perf_evsel__set_sample_id(struct perf_evsel *evsel);
  120. int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
  121. const char *filter);
  122. int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
  123. struct cpu_map *cpus);
  124. int perf_evsel__open_per_thread(struct perf_evsel *evsel,
  125. struct thread_map *threads);
  126. int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
  127. struct thread_map *threads);
  128. void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
  129. struct perf_sample;
  130. void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
  131. const char *name);
  132. u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
  133. const char *name);
  134. static inline char *perf_evsel__strval(struct perf_evsel *evsel,
  135. struct perf_sample *sample,
  136. const char *name)
  137. {
  138. return perf_evsel__rawptr(evsel, sample, name);
  139. }
  140. struct format_field;
  141. struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
  142. #define perf_evsel__match(evsel, t, c) \
  143. (evsel->attr.type == PERF_TYPE_##t && \
  144. evsel->attr.config == PERF_COUNT_##c)
  145. static inline bool perf_evsel__match2(struct perf_evsel *e1,
  146. struct perf_evsel *e2)
  147. {
  148. return (e1->attr.type == e2->attr.type) &&
  149. (e1->attr.config == e2->attr.config);
  150. }
  151. int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  152. int cpu, int thread, bool scale);
  153. /**
  154. * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
  155. *
  156. * @evsel - event selector to read value
  157. * @cpu - CPU of interest
  158. * @thread - thread of interest
  159. */
  160. static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  161. int cpu, int thread)
  162. {
  163. return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
  164. }
  165. /**
  166. * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
  167. *
  168. * @evsel - event selector to read value
  169. * @cpu - CPU of interest
  170. * @thread - thread of interest
  171. */
  172. static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
  173. int cpu, int thread)
  174. {
  175. return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
  176. }
  177. int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
  178. bool scale);
  179. /**
  180. * perf_evsel__read - Read the aggregate results on all CPUs
  181. *
  182. * @evsel - event selector to read value
  183. * @ncpus - Number of cpus affected, from zero
  184. * @nthreads - Number of threads affected, from zero
  185. */
  186. static inline int perf_evsel__read(struct perf_evsel *evsel,
  187. int ncpus, int nthreads)
  188. {
  189. return __perf_evsel__read(evsel, ncpus, nthreads, false);
  190. }
  191. /**
  192. * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
  193. *
  194. * @evsel - event selector to read value
  195. * @ncpus - Number of cpus affected, from zero
  196. * @nthreads - Number of threads affected, from zero
  197. */
  198. static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
  199. int ncpus, int nthreads)
  200. {
  201. return __perf_evsel__read(evsel, ncpus, nthreads, true);
  202. }
  203. void hists__init(struct hists *hists);
  204. int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
  205. struct perf_sample *sample);
  206. static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
  207. {
  208. return list_entry(evsel->node.next, struct perf_evsel, node);
  209. }
  210. static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
  211. {
  212. return evsel->leader == evsel;
  213. }
  214. struct perf_attr_details {
  215. bool freq;
  216. bool verbose;
  217. bool event_group;
  218. };
  219. int perf_evsel__fprintf(struct perf_evsel *evsel,
  220. struct perf_attr_details *details, FILE *fp);
  221. bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
  222. char *msg, size_t msgsize);
  223. int perf_evsel__open_strerror(struct perf_evsel *evsel,
  224. struct perf_target *target,
  225. int err, char *msg, size_t size);
  226. static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
  227. {
  228. return evsel->idx - evsel->leader->idx;
  229. }
  230. #define for_each_group_member(_evsel, _leader) \
  231. for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); \
  232. (_evsel) && (_evsel)->leader == (_leader); \
  233. (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
  234. #endif /* __PERF_EVSEL_H */