evsel.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. struct perf_counts_values {
  9. union {
  10. struct {
  11. u64 val;
  12. u64 ena;
  13. u64 run;
  14. };
  15. u64 values[3];
  16. };
  17. };
  18. struct perf_counts {
  19. s8 scaled;
  20. struct perf_counts_values aggr;
  21. struct perf_counts_values cpu[];
  22. };
  23. struct perf_evsel;
  24. /*
  25. * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
  26. * more than one entry in the evlist.
  27. */
  28. struct perf_sample_id {
  29. struct hlist_node node;
  30. u64 id;
  31. struct perf_evsel *evsel;
  32. };
  33. struct perf_evsel {
  34. struct list_head node;
  35. struct perf_event_attr attr;
  36. char *filter;
  37. struct xyarray *fd;
  38. struct xyarray *id;
  39. struct perf_counts *counts;
  40. int idx;
  41. void *priv;
  42. };
  43. struct cpu_map;
  44. struct thread_map;
  45. struct perf_evlist;
  46. struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
  47. void perf_evsel__init(struct perf_evsel *evsel,
  48. struct perf_event_attr *attr, int idx);
  49. void perf_evsel__exit(struct perf_evsel *evsel);
  50. void perf_evsel__delete(struct perf_evsel *evsel);
  51. int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  52. int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
  53. int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
  54. void perf_evsel__free_fd(struct perf_evsel *evsel);
  55. void perf_evsel__free_id(struct perf_evsel *evsel);
  56. void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  57. int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
  58. struct cpu_map *cpus, bool group, bool inherit);
  59. int perf_evsel__open_per_thread(struct perf_evsel *evsel,
  60. struct thread_map *threads, bool group, bool inherit);
  61. int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
  62. struct thread_map *threads, bool group, bool inherit);
  63. #define perf_evsel__match(evsel, t, c) \
  64. (evsel->attr.type == PERF_TYPE_##t && \
  65. evsel->attr.config == PERF_COUNT_##c)
  66. int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  67. int cpu, int thread, bool scale);
  68. /**
  69. * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
  70. *
  71. * @evsel - event selector to read value
  72. * @cpu - CPU of interest
  73. * @thread - thread of interest
  74. */
  75. static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  76. int cpu, int thread)
  77. {
  78. return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
  79. }
  80. /**
  81. * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
  82. *
  83. * @evsel - event selector to read value
  84. * @cpu - CPU of interest
  85. * @thread - thread of interest
  86. */
  87. static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
  88. int cpu, int thread)
  89. {
  90. return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
  91. }
  92. int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
  93. bool scale);
  94. /**
  95. * perf_evsel__read - Read the aggregate results on all CPUs
  96. *
  97. * @evsel - event selector to read value
  98. * @ncpus - Number of cpus affected, from zero
  99. * @nthreads - Number of threads affected, from zero
  100. */
  101. static inline int perf_evsel__read(struct perf_evsel *evsel,
  102. int ncpus, int nthreads)
  103. {
  104. return __perf_evsel__read(evsel, ncpus, nthreads, false);
  105. }
  106. /**
  107. * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
  108. *
  109. * @evsel - event selector to read value
  110. * @ncpus - Number of cpus affected, from zero
  111. * @nthreads - Number of threads affected, from zero
  112. */
  113. static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
  114. int ncpus, int nthreads)
  115. {
  116. return __perf_evsel__read(evsel, ncpus, nthreads, true);
  117. }
  118. #endif /* __PERF_EVSEL_H */