evsel.h 4.0 KB

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