evsel.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 {
  35. struct list_head node;
  36. struct perf_event_attr attr;
  37. char *filter;
  38. struct xyarray *fd;
  39. struct xyarray *id;
  40. struct perf_counts *counts;
  41. int idx;
  42. void *priv;
  43. struct cgroup_sel *cgrp;
  44. };
  45. struct cpu_map;
  46. struct thread_map;
  47. struct perf_evlist;
  48. struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
  49. void perf_evsel__init(struct perf_evsel *evsel,
  50. struct perf_event_attr *attr, int idx);
  51. void perf_evsel__exit(struct perf_evsel *evsel);
  52. void perf_evsel__delete(struct perf_evsel *evsel);
  53. int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  54. int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
  55. int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
  56. void perf_evsel__free_fd(struct perf_evsel *evsel);
  57. void perf_evsel__free_id(struct perf_evsel *evsel);
  58. void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
  59. int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
  60. struct cpu_map *cpus, bool group, bool inherit);
  61. int perf_evsel__open_per_thread(struct perf_evsel *evsel,
  62. struct thread_map *threads, bool group, bool inherit);
  63. int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
  64. struct thread_map *threads, bool group, bool inherit);
  65. #define perf_evsel__match(evsel, t, c) \
  66. (evsel->attr.type == PERF_TYPE_##t && \
  67. evsel->attr.config == PERF_COUNT_##c)
  68. int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  69. int cpu, int thread, bool scale);
  70. /**
  71. * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
  72. *
  73. * @evsel - event selector to read value
  74. * @cpu - CPU of interest
  75. * @thread - thread of interest
  76. */
  77. static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
  78. int cpu, int thread)
  79. {
  80. return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
  81. }
  82. /**
  83. * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
  84. *
  85. * @evsel - event selector to read value
  86. * @cpu - CPU of interest
  87. * @thread - thread of interest
  88. */
  89. static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
  90. int cpu, int thread)
  91. {
  92. return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
  93. }
  94. int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
  95. bool scale);
  96. /**
  97. * perf_evsel__read - Read the aggregate results on all CPUs
  98. *
  99. * @evsel - event selector to read value
  100. * @ncpus - Number of cpus affected, from zero
  101. * @nthreads - Number of threads affected, from zero
  102. */
  103. static inline int perf_evsel__read(struct perf_evsel *evsel,
  104. int ncpus, int nthreads)
  105. {
  106. return __perf_evsel__read(evsel, ncpus, nthreads, false);
  107. }
  108. /**
  109. * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
  110. *
  111. * @evsel - event selector to read value
  112. * @ncpus - Number of cpus affected, from zero
  113. * @nthreads - Number of threads affected, from zero
  114. */
  115. static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
  116. int ncpus, int nthreads)
  117. {
  118. return __perf_evsel__read(evsel, ncpus, nthreads, true);
  119. }
  120. #endif /* __PERF_EVSEL_H */