evsel.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #ifndef __PERF_EVSEL_H
  2. #define __PERF_EVSEL_H 1
  3. #include <linux/list.h>
  4. #include <stdbool.h>
  5. #include "../../../include/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. int ids;
  51. struct hists hists;
  52. char *name;
  53. union {
  54. void *priv;
  55. off_t id_offset;
  56. };
  57. struct cgroup_sel *cgrp;
  58. struct {
  59. void *func;
  60. void *data;
  61. } handler;
  62. bool supported;
  63. };
  64. struct cpu_map;
  65. struct thread_map;
  66. struct perf_evlist;
  67. struct perf_record_opts;
  68. struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
  69. void perf_evsel__init(struct perf_evsel *evsel,
  70. struct perf_event_attr *attr, int idx);
  71. void perf_evsel__exit(struct perf_evsel *evsel);
  72. void perf_evsel__delete(struct perf_evsel *evsel);
  73. void perf_evsel__config(struct perf_evsel *evsel,
  74. struct perf_record_opts *opts,
  75. struct perf_evsel *first);
  76. bool perf_evsel__is_cache_op_valid(u8 type, u8 op);
  77. #define PERF_EVSEL__MAX_ALIASES 8
  78. extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
  79. [PERF_EVSEL__MAX_ALIASES];
  80. extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
  81. [PERF_EVSEL__MAX_ALIASES];
  82. const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
  83. [PERF_EVSEL__MAX_ALIASES];
  84. int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
  85. char *bf, size_t size);
  86. const char *perf_evsel__name(struct perf_evsel *evsel);
  87. int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  88. int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
  89. int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
  90. void perf_evsel__free_fd(struct perf_evsel *evsel);
  91. void perf_evsel__free_id(struct perf_evsel *evsel);
  92. void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  93. int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
  94. struct cpu_map *cpus, bool group,
  95. struct xyarray *group_fds);
  96. int perf_evsel__open_per_thread(struct perf_evsel *evsel,
  97. struct thread_map *threads, bool group,
  98. struct xyarray *group_fds);
  99. int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
  100. struct thread_map *threads, bool group,
  101. struct xyarray *group_fds);
  102. void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
  103. #define perf_evsel__match(evsel, t, c) \
  104. (evsel->attr.type == PERF_TYPE_##t && \
  105. evsel->attr.config == PERF_COUNT_##c)
  106. int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  107. int cpu, int thread, bool scale);
  108. /**
  109. * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
  110. *
  111. * @evsel - event selector to read value
  112. * @cpu - CPU of interest
  113. * @thread - thread of interest
  114. */
  115. static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  116. int cpu, int thread)
  117. {
  118. return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
  119. }
  120. /**
  121. * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
  122. *
  123. * @evsel - event selector to read value
  124. * @cpu - CPU of interest
  125. * @thread - thread of interest
  126. */
  127. static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
  128. int cpu, int thread)
  129. {
  130. return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
  131. }
  132. int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
  133. bool scale);
  134. /**
  135. * perf_evsel__read - Read the aggregate results on all CPUs
  136. *
  137. * @evsel - event selector to read value
  138. * @ncpus - Number of cpus affected, from zero
  139. * @nthreads - Number of threads affected, from zero
  140. */
  141. static inline int perf_evsel__read(struct perf_evsel *evsel,
  142. int ncpus, int nthreads)
  143. {
  144. return __perf_evsel__read(evsel, ncpus, nthreads, false);
  145. }
  146. /**
  147. * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
  148. *
  149. * @evsel - event selector to read value
  150. * @ncpus - Number of cpus affected, from zero
  151. * @nthreads - Number of threads affected, from zero
  152. */
  153. static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
  154. int ncpus, int nthreads)
  155. {
  156. return __perf_evsel__read(evsel, ncpus, nthreads, true);
  157. }
  158. int __perf_evsel__sample_size(u64 sample_type);
  159. static inline int perf_evsel__sample_size(struct perf_evsel *evsel)
  160. {
  161. return __perf_evsel__sample_size(evsel->attr.sample_type);
  162. }
  163. void hists__init(struct hists *hists);
  164. #endif /* __PERF_EVSEL_H */