9ba2eb3bdcfd75c234fe367bff5cd97b450e9929
[firefly-linux-kernel-4.4.55.git] / tools / perf / util / event.h
1 #ifndef __PERF_RECORD_H
2 #define __PERF_RECORD_H
3
4 #include <limits.h>
5 #include <stdio.h>
6
7 #include "../perf.h"
8 #include "map.h"
9 #include "build-id.h"
10
11 struct mmap_event {
12         struct perf_event_header header;
13         u32 pid, tid;
14         u64 start;
15         u64 len;
16         u64 pgoff;
17         char filename[PATH_MAX];
18 };
19
20 struct mmap2_event {
21         struct perf_event_header header;
22         u32 pid, tid;
23         u64 start;
24         u64 len;
25         u64 pgoff;
26         u32 maj;
27         u32 min;
28         u64 ino;
29         u64 ino_generation;
30         u32 prot;
31         u32 flags;
32         char filename[PATH_MAX];
33 };
34
35 struct comm_event {
36         struct perf_event_header header;
37         u32 pid, tid;
38         char comm[16];
39 };
40
41 struct fork_event {
42         struct perf_event_header header;
43         u32 pid, ppid;
44         u32 tid, ptid;
45         u64 time;
46 };
47
48 struct lost_event {
49         struct perf_event_header header;
50         u64 id;
51         u64 lost;
52 };
53
54 /*
55  * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
56  */
57 struct read_event {
58         struct perf_event_header header;
59         u32 pid, tid;
60         u64 value;
61         u64 time_enabled;
62         u64 time_running;
63         u64 id;
64 };
65
66 struct throttle_event {
67         struct perf_event_header header;
68         u64 time;
69         u64 id;
70         u64 stream_id;
71 };
72
73 #define PERF_SAMPLE_MASK                                \
74         (PERF_SAMPLE_IP | PERF_SAMPLE_TID |             \
75          PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR |          \
76         PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID |        \
77          PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD |         \
78          PERF_SAMPLE_IDENTIFIER)
79
80 /* perf sample has 16 bits size limit */
81 #define PERF_SAMPLE_MAX_SIZE (1 << 16)
82
83 struct sample_event {
84         struct perf_event_header        header;
85         u64 array[];
86 };
87
88 struct regs_dump {
89         u64 abi;
90         u64 mask;
91         u64 *regs;
92 };
93
94 struct stack_dump {
95         u16 offset;
96         u64 size;
97         char *data;
98 };
99
100 struct sample_read_value {
101         u64 value;
102         u64 id;
103 };
104
105 struct sample_read {
106         u64 time_enabled;
107         u64 time_running;
108         union {
109                 struct {
110                         u64 nr;
111                         struct sample_read_value *values;
112                 } group;
113                 struct sample_read_value one;
114         };
115 };
116
117 struct ip_callchain {
118         u64 nr;
119         u64 ips[0];
120 };
121
122 struct branch_flags {
123         u64 mispred:1;
124         u64 predicted:1;
125         u64 in_tx:1;
126         u64 abort:1;
127         u64 reserved:60;
128 };
129
130 struct branch_entry {
131         u64                     from;
132         u64                     to;
133         struct branch_flags     flags;
134 };
135
136 struct branch_stack {
137         u64                     nr;
138         struct branch_entry     entries[0];
139 };
140
141 struct perf_sample {
142         u64 ip;
143         u32 pid, tid;
144         u64 time;
145         u64 addr;
146         u64 id;
147         u64 stream_id;
148         u64 period;
149         u64 weight;
150         u64 transaction;
151         u32 cpu;
152         u32 raw_size;
153         u64 data_src;
154         void *raw_data;
155         struct ip_callchain *callchain;
156         struct branch_stack *branch_stack;
157         struct regs_dump  user_regs;
158         struct stack_dump user_stack;
159         struct sample_read read;
160 };
161
162 #define PERF_MEM_DATA_SRC_NONE \
163         (PERF_MEM_S(OP, NA) |\
164          PERF_MEM_S(LVL, NA) |\
165          PERF_MEM_S(SNOOP, NA) |\
166          PERF_MEM_S(LOCK, NA) |\
167          PERF_MEM_S(TLB, NA))
168
169 struct build_id_event {
170         struct perf_event_header header;
171         pid_t                    pid;
172         u8                       build_id[PERF_ALIGN(BUILD_ID_SIZE, sizeof(u64))];
173         char                     filename[];
174 };
175
176 enum perf_user_event_type { /* above any possible kernel type */
177         PERF_RECORD_USER_TYPE_START             = 64,
178         PERF_RECORD_HEADER_ATTR                 = 64,
179         PERF_RECORD_HEADER_EVENT_TYPE           = 65, /* depreceated */
180         PERF_RECORD_HEADER_TRACING_DATA         = 66,
181         PERF_RECORD_HEADER_BUILD_ID             = 67,
182         PERF_RECORD_FINISHED_ROUND              = 68,
183         PERF_RECORD_HEADER_MAX
184 };
185
186 struct attr_event {
187         struct perf_event_header header;
188         struct perf_event_attr attr;
189         u64 id[];
190 };
191
192 #define MAX_EVENT_NAME 64
193
194 struct perf_trace_event_type {
195         u64     event_id;
196         char    name[MAX_EVENT_NAME];
197 };
198
199 struct event_type_event {
200         struct perf_event_header header;
201         struct perf_trace_event_type event_type;
202 };
203
204 struct tracing_data_event {
205         struct perf_event_header header;
206         u32 size;
207 };
208
209 union perf_event {
210         struct perf_event_header        header;
211         struct mmap_event               mmap;
212         struct mmap2_event              mmap2;
213         struct comm_event               comm;
214         struct fork_event               fork;
215         struct lost_event               lost;
216         struct read_event               read;
217         struct throttle_event           throttle;
218         struct sample_event             sample;
219         struct attr_event               attr;
220         struct event_type_event         event_type;
221         struct tracing_data_event       tracing_data;
222         struct build_id_event           build_id;
223 };
224
225 void perf_event__print_totals(void);
226
227 struct perf_tool;
228 struct thread_map;
229
230 typedef int (*perf_event__handler_t)(struct perf_tool *tool,
231                                      union perf_event *event,
232                                      struct perf_sample *sample,
233                                      struct machine *machine);
234
235 int perf_event__synthesize_thread_map(struct perf_tool *tool,
236                                       struct thread_map *threads,
237                                       perf_event__handler_t process,
238                                       struct machine *machine, bool mmap_data);
239 int perf_event__synthesize_threads(struct perf_tool *tool,
240                                    perf_event__handler_t process,
241                                    struct machine *machine, bool mmap_data);
242 int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
243                                        perf_event__handler_t process,
244                                        struct machine *machine);
245
246 int perf_event__synthesize_modules(struct perf_tool *tool,
247                                    perf_event__handler_t process,
248                                    struct machine *machine);
249
250 int perf_event__process_comm(struct perf_tool *tool,
251                              union perf_event *event,
252                              struct perf_sample *sample,
253                              struct machine *machine);
254 int perf_event__process_lost(struct perf_tool *tool,
255                              union perf_event *event,
256                              struct perf_sample *sample,
257                              struct machine *machine);
258 int perf_event__process_mmap(struct perf_tool *tool,
259                              union perf_event *event,
260                              struct perf_sample *sample,
261                              struct machine *machine);
262 int perf_event__process_mmap2(struct perf_tool *tool,
263                              union perf_event *event,
264                              struct perf_sample *sample,
265                              struct machine *machine);
266 int perf_event__process_fork(struct perf_tool *tool,
267                              union perf_event *event,
268                              struct perf_sample *sample,
269                              struct machine *machine);
270 int perf_event__process_exit(struct perf_tool *tool,
271                              union perf_event *event,
272                              struct perf_sample *sample,
273                              struct machine *machine);
274 int perf_event__process(struct perf_tool *tool,
275                         union perf_event *event,
276                         struct perf_sample *sample,
277                         struct machine *machine);
278
279 struct addr_location;
280
281 int perf_event__preprocess_sample(const union perf_event *event,
282                                   struct machine *machine,
283                                   struct addr_location *al,
284                                   struct perf_sample *sample);
285
286 const char *perf_event__name(unsigned int id);
287
288 size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
289                                      u64 read_format);
290 int perf_event__synthesize_sample(union perf_event *event, u64 type,
291                                   u64 read_format,
292                                   const struct perf_sample *sample,
293                                   bool swapped);
294
295 int perf_event__synthesize_mmap_events(struct perf_tool *tool,
296                                        union perf_event *event,
297                                        pid_t pid, pid_t tgid,
298                                        perf_event__handler_t process,
299                                        struct machine *machine,
300                                        bool mmap_data);
301
302 size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
303 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
304 size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
305 size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
306 size_t perf_event__fprintf(union perf_event *event, FILE *fp);
307
308 u64 kallsyms__get_function_start(const char *kallsyms_filename,
309                                  const char *symbol_name);
310
311 #endif /* __PERF_RECORD_H */