evsel.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. int idx;
  51. u32 ids;
  52. struct hists hists;
  53. char *name;
  54. struct event_format *tp_format;
  55. union {
  56. void *priv;
  57. off_t id_offset;
  58. };
  59. struct cgroup_sel *cgrp;
  60. struct {
  61. void *func;
  62. void *data;
  63. } handler;
  64. struct cpu_map *cpus;
  65. unsigned int sample_size;
  66. bool supported;
  67. bool needs_swap;
  68. /* parse modifier helper */
  69. int exclude_GH;
  70. struct perf_evsel *leader;
  71. char *group_name;
  72. };
  73. struct cpu_map;
  74. struct thread_map;
  75. struct perf_evlist;
  76. struct perf_record_opts;
  77. struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
  78. struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name, int idx);
  79. struct event_format *event_format__new(const char *sys, const char *name);
  80. void perf_evsel__init(struct perf_evsel *evsel,
  81. struct perf_event_attr *attr, int idx);
  82. void perf_evsel__exit(struct perf_evsel *evsel);
  83. void perf_evsel__delete(struct perf_evsel *evsel);
  84. void perf_evsel__config(struct perf_evsel *evsel,
  85. struct perf_record_opts *opts);
  86. bool perf_evsel__is_cache_op_valid(u8 type, u8 op);
  87. #define PERF_EVSEL__MAX_ALIASES 8
  88. extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
  89. [PERF_EVSEL__MAX_ALIASES];
  90. extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
  91. [PERF_EVSEL__MAX_ALIASES];
  92. extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
  93. [PERF_EVSEL__MAX_ALIASES];
  94. extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX];
  95. extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX];
  96. int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
  97. char *bf, size_t size);
  98. const char *perf_evsel__name(struct perf_evsel *evsel);
  99. int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  100. int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
  101. int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
  102. void perf_evsel__free_fd(struct perf_evsel *evsel);
  103. void perf_evsel__free_id(struct perf_evsel *evsel);
  104. void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  105. void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
  106. enum perf_event_sample_format bit);
  107. void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel,
  108. enum perf_event_sample_format bit);
  109. #define perf_evsel__set_sample_bit(evsel, bit) \
  110. __perf_evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
  111. #define perf_evsel__reset_sample_bit(evsel, bit) \
  112. __perf_evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
  113. void perf_evsel__set_sample_id(struct perf_evsel *evsel);
  114. int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
  115. const char *filter);
  116. int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
  117. struct cpu_map *cpus);
  118. int perf_evsel__open_per_thread(struct perf_evsel *evsel,
  119. struct thread_map *threads);
  120. int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
  121. struct thread_map *threads);
  122. void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
  123. struct perf_sample;
  124. void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
  125. const char *name);
  126. u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
  127. const char *name);
  128. static inline char *perf_evsel__strval(struct perf_evsel *evsel,
  129. struct perf_sample *sample,
  130. const char *name)
  131. {
  132. return perf_evsel__rawptr(evsel, sample, name);
  133. }
  134. struct format_field;
  135. struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
  136. #define perf_evsel__match(evsel, t, c) \
  137. (evsel->attr.type == PERF_TYPE_##t && \
  138. evsel->attr.config == PERF_COUNT_##c)
  139. static inline bool perf_evsel__match2(struct perf_evsel *e1,
  140. struct perf_evsel *e2)
  141. {
  142. return (e1->attr.type == e2->attr.type) &&
  143. (e1->attr.config == e2->attr.config);
  144. }
  145. int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  146. int cpu, int thread, bool scale);
  147. /**
  148. * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
  149. *
  150. * @evsel - event selector to read value
  151. * @cpu - CPU of interest
  152. * @thread - thread of interest
  153. */
  154. static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  155. int cpu, int thread)
  156. {
  157. return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
  158. }
  159. /**
  160. * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
  161. *
  162. * @evsel - event selector to read value
  163. * @cpu - CPU of interest
  164. * @thread - thread of interest
  165. */
  166. static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
  167. int cpu, int thread)
  168. {
  169. return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
  170. }
  171. int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
  172. bool scale);
  173. /**
  174. * perf_evsel__read - Read the aggregate results on all CPUs
  175. *
  176. * @evsel - event selector to read value
  177. * @ncpus - Number of cpus affected, from zero
  178. * @nthreads - Number of threads affected, from zero
  179. */
  180. static inline int perf_evsel__read(struct perf_evsel *evsel,
  181. int ncpus, int nthreads)
  182. {
  183. return __perf_evsel__read(evsel, ncpus, nthreads, false);
  184. }
  185. /**
  186. * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
  187. *
  188. * @evsel - event selector to read value
  189. * @ncpus - Number of cpus affected, from zero
  190. * @nthreads - Number of threads affected, from zero
  191. */
  192. static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
  193. int ncpus, int nthreads)
  194. {
  195. return __perf_evsel__read(evsel, ncpus, nthreads, true);
  196. }
  197. void hists__init(struct hists *hists);
  198. int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
  199. struct perf_sample *sample);
  200. static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
  201. {
  202. return list_entry(evsel->node.next, struct perf_evsel, node);
  203. }
  204. static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
  205. {
  206. return evsel->leader == evsel;
  207. }
  208. struct perf_attr_details {
  209. bool freq;
  210. bool verbose;
  211. };
  212. int perf_evsel__fprintf(struct perf_evsel *evsel,
  213. struct perf_attr_details *details, FILE *fp);
  214. #endif /* __PERF_EVSEL_H */