evsel.h 6.4 KB

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