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