perf evsel: Allow specifying if the inherit bit should be set
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / tools / perf / util / evsel.h
1 #ifndef __PERF_EVSEL_H
2 #define __PERF_EVSEL_H 1
3
4 #include <linux/list.h>
5 #include <stdbool.h>
6 #include "../../../include/linux/perf_event.h"
7 #include "types.h"
8 #include "xyarray.h"
9
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
21 struct perf_counts {
22 s8 scaled;
23 struct perf_counts_values aggr;
24 struct perf_counts_values cpu[];
25 };
26
27 struct perf_evsel {
28 struct list_head node;
29 struct perf_event_attr attr;
30 char *filter;
31 struct xyarray *fd;
32 struct perf_counts *counts;
33 int idx;
34 void *priv;
35 };
36
37 struct cpu_map;
38 struct thread_map;
39
40 struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
41 void perf_evsel__delete(struct perf_evsel *evsel);
42
43 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
44 int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
45 void perf_evsel__free_fd(struct perf_evsel *evsel);
46 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
47
48 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
49 struct cpu_map *cpus, bool group, bool inherit);
50 int perf_evsel__open_per_thread(struct perf_evsel *evsel,
51 struct thread_map *threads, bool group, bool inherit);
52 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
53 struct thread_map *threads, bool group, bool inherit);
54
55 #define perf_evsel__match(evsel, t, c) \
56 (evsel->attr.type == PERF_TYPE_##t && \
57 evsel->attr.config == PERF_COUNT_##c)
58
59 int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
60 int cpu, int thread, bool scale);
61
62 /**
63 * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
64 *
65 * @evsel - event selector to read value
66 * @cpu - CPU of interest
67 * @thread - thread of interest
68 */
69 static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
70 int cpu, int thread)
71 {
72 return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
73 }
74
75 /**
76 * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
77 *
78 * @evsel - event selector to read value
79 * @cpu - CPU of interest
80 * @thread - thread of interest
81 */
82 static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
83 int cpu, int thread)
84 {
85 return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
86 }
87
88 int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
89 bool scale);
90
91 /**
92 * perf_evsel__read - Read the aggregate results on all CPUs
93 *
94 * @evsel - event selector to read value
95 * @ncpus - Number of cpus affected, from zero
96 * @nthreads - Number of threads affected, from zero
97 */
98 static inline int perf_evsel__read(struct perf_evsel *evsel,
99 int ncpus, int nthreads)
100 {
101 return __perf_evsel__read(evsel, ncpus, nthreads, false);
102 }
103
104 /**
105 * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
106 *
107 * @evsel - event selector to read value
108 * @ncpus - Number of cpus affected, from zero
109 * @nthreads - Number of threads affected, from zero
110 */
111 static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
112 int ncpus, int nthreads)
113 {
114 return __perf_evsel__read(evsel, ncpus, nthreads, true);
115 }
116
117 #endif /* __PERF_EVSEL_H */