tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.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 <stddef.h>
7 #include <linux/perf_event.h>
8 #include "types.h"
9 #include "xyarray.h"
10 #include "cgroup.h"
11 #include "hist.h"
12 #include "symbol.h"
13  
14 struct perf_counts_values {
15         union {
16                 struct {
17                         u64 val;
18                         u64 ena;
19                         u64 run;
20                 };
21                 u64 values[3];
22         };
23 };
24
25 struct perf_counts {
26         s8                        scaled;
27         struct perf_counts_values aggr;
28         struct perf_counts_values cpu[];
29 };
30
31 struct perf_evsel;
32
33 /*
34  * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
35  * more than one entry in the evlist.
36  */
37 struct perf_sample_id {
38         struct hlist_node       node;
39         u64                     id;
40         struct perf_evsel       *evsel;
41 };
42
43 /** struct perf_evsel - event selector
44  *
45  * @name - Can be set to retain the original event name passed by the user,
46  *         so that when showing results in tools such as 'perf stat', we
47  *         show the name used, not some alias.
48  */
49 struct perf_evsel {
50         struct list_head        node;
51         struct perf_event_attr  attr;
52         char                    *filter;
53         struct xyarray          *fd;
54         struct xyarray          *sample_id;
55         u64                     *id;
56         struct perf_counts      *counts;
57         struct perf_counts      *prev_raw_counts;
58         int                     idx;
59         u32                     ids;
60         struct hists            hists;
61         char                    *name;
62         struct event_format     *tp_format;
63         union {
64                 void            *priv;
65                 off_t           id_offset;
66         };
67         struct cgroup_sel       *cgrp;
68         struct {
69                 void            *func;
70                 void            *data;
71         } handler;
72         struct cpu_map          *cpus;
73         unsigned int            sample_size;
74         bool                    supported;
75         bool                    needs_swap;
76         /* parse modifier helper */
77         int                     exclude_GH;
78         int                     nr_members;
79         struct perf_evsel       *leader;
80         char                    *group_name;
81 };
82
83 #define hists_to_evsel(h) container_of(h, struct perf_evsel, hists)
84
85 struct cpu_map;
86 struct thread_map;
87 struct perf_evlist;
88 struct perf_record_opts;
89
90 struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
91 struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name, int idx);
92
93 struct event_format *event_format__new(const char *sys, const char *name);
94
95 void perf_evsel__init(struct perf_evsel *evsel,
96                       struct perf_event_attr *attr, int idx);
97 void perf_evsel__exit(struct perf_evsel *evsel);
98 void perf_evsel__delete(struct perf_evsel *evsel);
99
100 void perf_evsel__config(struct perf_evsel *evsel,
101                         struct perf_record_opts *opts);
102
103 bool perf_evsel__is_cache_op_valid(u8 type, u8 op);
104
105 #define PERF_EVSEL__MAX_ALIASES 8
106
107 extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
108                                        [PERF_EVSEL__MAX_ALIASES];
109 extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
110                                           [PERF_EVSEL__MAX_ALIASES];
111 extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
112                                               [PERF_EVSEL__MAX_ALIASES];
113 extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX];
114 extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX];
115 int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
116                                             char *bf, size_t size);
117 const char *perf_evsel__name(struct perf_evsel *evsel);
118 const char *perf_evsel__group_name(struct perf_evsel *evsel);
119 int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size);
120
121 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
122 int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
123 int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
124 void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus);
125 void perf_evsel__free_fd(struct perf_evsel *evsel);
126 void perf_evsel__free_id(struct perf_evsel *evsel);
127 void perf_evsel__free_counts(struct perf_evsel *evsel);
128 void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
129
130 void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
131                                   enum perf_event_sample_format bit);
132 void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel,
133                                     enum perf_event_sample_format bit);
134
135 #define perf_evsel__set_sample_bit(evsel, bit) \
136         __perf_evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
137
138 #define perf_evsel__reset_sample_bit(evsel, bit) \
139         __perf_evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
140
141 void perf_evsel__set_sample_id(struct perf_evsel *evsel);
142
143 int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
144                            const char *filter);
145
146 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
147                              struct cpu_map *cpus);
148 int perf_evsel__open_per_thread(struct perf_evsel *evsel,
149                                 struct thread_map *threads);
150 int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
151                      struct thread_map *threads);
152 void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
153
154 struct perf_sample;
155
156 void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
157                          const char *name);
158 u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
159                        const char *name);
160
161 static inline char *perf_evsel__strval(struct perf_evsel *evsel,
162                                        struct perf_sample *sample,
163                                        const char *name)
164 {
165         return perf_evsel__rawptr(evsel, sample, name);
166 }
167
168 struct format_field;
169
170 struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
171
172 #define perf_evsel__match(evsel, t, c)          \
173         (evsel->attr.type == PERF_TYPE_##t &&   \
174          evsel->attr.config == PERF_COUNT_##c)
175
176 static inline bool perf_evsel__match2(struct perf_evsel *e1,
177                                       struct perf_evsel *e2)
178 {
179         return (e1->attr.type == e2->attr.type) &&
180                (e1->attr.config == e2->attr.config);
181 }
182
183 int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
184                               int cpu, int thread, bool scale);
185
186 /**
187  * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
188  *
189  * @evsel - event selector to read value
190  * @cpu - CPU of interest
191  * @thread - thread of interest
192  */
193 static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
194                                           int cpu, int thread)
195 {
196         return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
197 }
198
199 /**
200  * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
201  *
202  * @evsel - event selector to read value
203  * @cpu - CPU of interest
204  * @thread - thread of interest
205  */
206 static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
207                                                  int cpu, int thread)
208 {
209         return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
210 }
211
212 int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
213                        bool scale);
214
215 /**
216  * perf_evsel__read - Read the aggregate results on all CPUs
217  *
218  * @evsel - event selector to read value
219  * @ncpus - Number of cpus affected, from zero
220  * @nthreads - Number of threads affected, from zero
221  */
222 static inline int perf_evsel__read(struct perf_evsel *evsel,
223                                     int ncpus, int nthreads)
224 {
225         return __perf_evsel__read(evsel, ncpus, nthreads, false);
226 }
227
228 /**
229  * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
230  *
231  * @evsel - event selector to read value
232  * @ncpus - Number of cpus affected, from zero
233  * @nthreads - Number of threads affected, from zero
234  */
235 static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
236                                           int ncpus, int nthreads)
237 {
238         return __perf_evsel__read(evsel, ncpus, nthreads, true);
239 }
240
241 void hists__init(struct hists *hists);
242
243 int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
244                              struct perf_sample *sample);
245
246 static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
247 {
248         return list_entry(evsel->node.next, struct perf_evsel, node);
249 }
250
251 /**
252  * perf_evsel__is_group_leader - Return whether given evsel is a leader event
253  *
254  * @evsel - evsel selector to be tested
255  *
256  * Return %true if @evsel is a group leader or a stand-alone event
257  */
258 static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
259 {
260         return evsel->leader == evsel;
261 }
262
263 /**
264  * perf_evsel__is_group_event - Return whether given evsel is a group event
265  *
266  * @evsel - evsel selector to be tested
267  *
268  * Return %true iff event group view is enabled and @evsel is a actual group
269  * leader which has other members in the group
270  */
271 static inline bool perf_evsel__is_group_event(struct perf_evsel *evsel)
272 {
273         if (!symbol_conf.event_group)
274                 return false;
275
276         return perf_evsel__is_group_leader(evsel) && evsel->nr_members > 1;
277 }
278
279 struct perf_attr_details {
280         bool freq;
281         bool verbose;
282         bool event_group;
283 };
284
285 int perf_evsel__fprintf(struct perf_evsel *evsel,
286                         struct perf_attr_details *details, FILE *fp);
287
288 bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
289                           char *msg, size_t msgsize);
290 int perf_evsel__open_strerror(struct perf_evsel *evsel,
291                               struct perf_target *target,
292                               int err, char *msg, size_t size);
293
294 static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
295 {
296         return evsel->idx - evsel->leader->idx;
297 }
298
299 #define for_each_group_member(_evsel, _leader)                                  \
300 for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node);      \
301      (_evsel) && (_evsel)->leader == (_leader);                                 \
302      (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
303
304 #endif /* __PERF_EVSEL_H */