blob: d970232cb270cf5f3e5590a42798175e9cb2ad9e [file] [log] [blame]
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001#ifndef __PERF_RECORD_H
2#define __PERF_RECORD_H
John Kacur8b40f522009-09-24 18:02:18 +02003
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -02004#include <limits.h>
Arnaldo Carvalho de Melo482ad892011-12-02 11:06:37 -02005#include <stdio.h>
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -02006
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +02007#include "../perf.h"
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -02008#include "map.h"
Jiri Olsa4383db82012-10-27 23:18:29 +02009#include "build-id.h"
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020010
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020011struct 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
Stephane Eranian5c5e8542013-08-21 12:10:25 +020020struct 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 char filename[PATH_MAX];
31};
32
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020033struct comm_event {
34 struct perf_event_header header;
35 u32 pid, tid;
36 char comm[16];
37};
38
39struct fork_event {
40 struct perf_event_header header;
41 u32 pid, ppid;
42 u32 tid, ptid;
Arjan van de Ven393b2ad2009-09-12 07:52:47 +020043 u64 time;
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020044};
45
46struct lost_event {
47 struct perf_event_header header;
48 u64 id;
49 u64 lost;
50};
51
Peter Zijlstra18408dd2009-08-13 11:47:55 +020052/*
53 * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
54 */
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020055struct read_event {
56 struct perf_event_header header;
Ingo Molnardc02bf72009-09-16 13:45:00 +020057 u32 pid, tid;
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020058 u64 value;
59 u64 time_enabled;
60 u64 time_running;
61 u64 id;
62};
63
Jiri Olsadd96c462013-09-01 12:36:15 +020064struct throttle_event {
65 struct perf_event_header header;
66 u64 time;
67 u64 id;
68 u64 stream_id;
69};
Frederic Weisbeckera2854122011-05-21 19:33:04 +020070
71#define PERF_SAMPLE_MASK \
72 (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
73 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \
74 PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \
Adrian Hunter75562572013-08-27 11:23:09 +030075 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD | \
76 PERF_SAMPLE_IDENTIFIER)
Frederic Weisbeckera2854122011-05-21 19:33:04 +020077
Jiri Olsaa65cb4b2013-10-02 15:46:39 +020078/* perf sample has 16 bits size limit */
79#define PERF_SAMPLE_MAX_SIZE (1 << 16)
80
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +090081struct sample_event {
Arjan van de Venfd39e052009-09-12 07:53:00 +020082 struct perf_event_header header;
83 u64 array[];
84};
85
Jiri Olsa0f6a3012012-08-07 15:20:45 +020086struct regs_dump {
Adrian Hunter5b95a4a32013-08-27 11:23:10 +030087 u64 abi;
Jiri Olsa352ea452014-01-07 13:47:25 +010088 u64 mask;
Jiri Olsa0f6a3012012-08-07 15:20:45 +020089 u64 *regs;
90};
91
92struct stack_dump {
93 u16 offset;
94 u64 size;
95 char *data;
96};
97
Jiri Olsa9ede4732012-10-10 17:38:13 +020098struct sample_read_value {
99 u64 value;
100 u64 id;
101};
102
103struct sample_read {
104 u64 time_enabled;
105 u64 time_running;
106 union {
107 struct {
108 u64 nr;
109 struct sample_read_value *values;
110 } group;
111 struct sample_read_value one;
112 };
113};
114
Jiri Olsa0776eb52014-05-05 12:41:45 +0200115struct ip_callchain {
116 u64 nr;
117 u64 ips[0];
118};
119
120struct branch_flags {
121 u64 mispred:1;
122 u64 predicted:1;
123 u64 in_tx:1;
124 u64 abort:1;
125 u64 reserved:60;
126};
127
128struct branch_entry {
129 u64 from;
130 u64 to;
131 struct branch_flags flags;
132};
133
134struct branch_stack {
135 u64 nr;
136 struct branch_entry entries[0];
137};
138
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200139struct perf_sample {
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900140 u64 ip;
141 u32 pid, tid;
142 u64 time;
143 u64 addr;
144 u64 id;
145 u64 stream_id;
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900146 u64 period;
Andi Kleen05484292013-01-24 16:10:29 +0100147 u64 weight;
Andi Kleen475eeab2013-09-20 07:40:43 -0700148 u64 transaction;
Arnaldo Carvalho de Meloeed05fe2010-04-05 12:53:45 -0300149 u32 cpu;
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900150 u32 raw_size;
Stephane Eranian98a3b322013-01-24 16:10:35 +0100151 u64 data_src;
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900152 void *raw_data;
Arnaldo Carvalho de Meloeed05fe2010-04-05 12:53:45 -0300153 struct ip_callchain *callchain;
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100154 struct branch_stack *branch_stack;
Jiri Olsa0f6a3012012-08-07 15:20:45 +0200155 struct regs_dump user_regs;
156 struct stack_dump user_stack;
Jiri Olsa9ede4732012-10-10 17:38:13 +0200157 struct sample_read read;
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +0900158};
159
Stephane Eranian98a3b322013-01-24 16:10:35 +0100160#define PERF_MEM_DATA_SRC_NONE \
161 (PERF_MEM_S(OP, NA) |\
162 PERF_MEM_S(LVL, NA) |\
163 PERF_MEM_S(SNOOP, NA) |\
164 PERF_MEM_S(LOCK, NA) |\
165 PERF_MEM_S(TLB, NA))
166
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200167struct build_id_event {
168 struct perf_event_header header;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800169 pid_t pid;
Irina Tirdea9ac3e482012-09-11 01:15:01 +0300170 u8 build_id[PERF_ALIGN(BUILD_ID_SIZE, sizeof(u64))];
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -0200171 char filename[];
172};
Arjan van de Venfd39e052009-09-12 07:53:00 +0200173
Frederic Weisbecker98402802010-05-02 22:05:29 +0200174enum perf_user_event_type { /* above any possible kernel type */
Thomas Gleixner9aefcab2010-12-07 12:48:47 +0000175 PERF_RECORD_USER_TYPE_START = 64,
Tom Zanussi2c46dbb2010-04-01 23:59:19 -0500176 PERF_RECORD_HEADER_ATTR = 64,
Jiri Olsa60652102013-07-11 17:28:33 +0200177 PERF_RECORD_HEADER_EVENT_TYPE = 65, /* depreceated */
Tom Zanussi92155452010-04-01 23:59:21 -0500178 PERF_RECORD_HEADER_TRACING_DATA = 66,
Tom Zanussic7929e42010-04-01 23:59:22 -0500179 PERF_RECORD_HEADER_BUILD_ID = 67,
Frederic Weisbecker98402802010-05-02 22:05:29 +0200180 PERF_RECORD_FINISHED_ROUND = 68,
Tom Zanussi2c46dbb2010-04-01 23:59:19 -0500181 PERF_RECORD_HEADER_MAX
182};
183
184struct attr_event {
185 struct perf_event_header header;
186 struct perf_event_attr attr;
187 u64 id[];
Tom Zanussi8dc58102010-04-01 23:59:15 -0500188};
189
Tom Zanussicd19a032010-04-01 23:59:20 -0500190#define MAX_EVENT_NAME 64
191
192struct perf_trace_event_type {
193 u64 event_id;
194 char name[MAX_EVENT_NAME];
195};
196
197struct event_type_event {
198 struct perf_event_header header;
199 struct perf_trace_event_type event_type;
200};
201
Tom Zanussi92155452010-04-01 23:59:21 -0500202struct tracing_data_event {
203 struct perf_event_header header;
204 u32 size;
205};
206
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200207union perf_event {
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +0200208 struct perf_event_header header;
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +0200209 struct mmap_event mmap;
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200210 struct mmap2_event mmap2;
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +0200211 struct comm_event comm;
212 struct fork_event fork;
213 struct lost_event lost;
214 struct read_event read;
Jiri Olsadd96c462013-09-01 12:36:15 +0200215 struct throttle_event throttle;
Arjan van de Venfd39e052009-09-12 07:53:00 +0200216 struct sample_event sample;
Tom Zanussi2c46dbb2010-04-01 23:59:19 -0500217 struct attr_event attr;
Tom Zanussicd19a032010-04-01 23:59:20 -0500218 struct event_type_event event_type;
Tom Zanussi92155452010-04-01 23:59:21 -0500219 struct tracing_data_event tracing_data;
Tom Zanussic7929e42010-04-01 23:59:22 -0500220 struct build_id_event build_id;
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200221};
Frederic Weisbecker66e274f2009-08-12 11:07:25 +0200222
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200223void perf_event__print_totals(void);
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200224
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200225struct perf_tool;
Arnaldo Carvalho de Melo401b8e12011-02-10 12:52:47 -0200226struct thread_map;
Arnaldo Carvalho de Melo4aa65632009-12-13 19:50:29 -0200227
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200228typedef int (*perf_event__handler_t)(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200229 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200230 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200231 struct machine *machine);
Arnaldo Carvalho de Melocf553112010-01-07 19:59:40 -0200232
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200233int perf_event__synthesize_thread_map(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200234 struct thread_map *threads,
Arnaldo Carvalho de Melo7c940c12011-02-11 11:45:54 -0200235 perf_event__handler_t process,
Arnaldo Carvalho de Melo62605dc502013-11-11 09:44:09 -0300236 struct machine *machine, bool mmap_data);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200237int perf_event__synthesize_threads(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200238 perf_event__handler_t process,
Arnaldo Carvalho de Melo62605dc502013-11-11 09:44:09 -0300239 struct machine *machine, bool mmap_data);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200240int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200241 perf_event__handler_t process,
Adrian Hunter0ae617b2014-01-29 16:14:40 +0200242 struct machine *machine);
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200243
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200244int perf_event__synthesize_modules(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200245 perf_event__handler_t process,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200246 struct machine *machine);
247
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200248int perf_event__process_comm(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200249 union perf_event *event,
250 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200251 struct machine *machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200252int perf_event__process_lost(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200253 union perf_event *event,
254 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200255 struct machine *machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200256int perf_event__process_mmap(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200257 union perf_event *event,
258 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200259 struct machine *machine);
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200260int perf_event__process_mmap2(struct perf_tool *tool,
261 union perf_event *event,
262 struct perf_sample *sample,
263 struct machine *machine);
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300264int perf_event__process_fork(struct perf_tool *tool,
265 union perf_event *event,
266 struct perf_sample *sample,
267 struct machine *machine);
268int perf_event__process_exit(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200269 union perf_event *event,
270 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200271 struct machine *machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200272int perf_event__process(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200273 union perf_event *event,
274 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200275 struct machine *machine);
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200276
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200277struct addr_location;
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300278
279int perf_event__preprocess_sample(const union perf_event *event,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200280 struct machine *machine,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200281 struct addr_location *al,
Adrian Huntere44baa32013-08-08 14:32:25 +0300282 struct perf_sample *sample);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200283
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200284const char *perf_event__name(unsigned int id);
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300285
Adrian Hunterb1cf6f62013-08-27 11:23:12 +0300286size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
Jiri Olsa352ea452014-01-07 13:47:25 +0100287 u64 read_format);
Andrew Vagin74eec262011-11-28 12:03:31 +0300288int perf_event__synthesize_sample(union perf_event *event, u64 type,
Jiri Olsa352ea452014-01-07 13:47:25 +0100289 u64 read_format,
Andrew Vagin74eec262011-11-28 12:03:31 +0300290 const struct perf_sample *sample,
291 bool swapped);
Arnaldo Carvalho de Melod0dd74e2011-01-21 13:46:41 -0200292
Jiri Olsaa18382b2014-01-07 13:47:20 +0100293int perf_event__synthesize_mmap_events(struct perf_tool *tool,
294 union perf_event *event,
295 pid_t pid, pid_t tgid,
296 perf_event__handler_t process,
297 struct machine *machine,
298 bool mmap_data);
299
Arnaldo Carvalho de Melo482ad892011-12-02 11:06:37 -0200300size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
301size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200302size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
Arnaldo Carvalho de Melo482ad892011-12-02 11:06:37 -0200303size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
304size_t perf_event__fprintf(union perf_event *event, FILE *fp);
305
Adrian Hunter29b596b2014-01-29 16:14:37 +0200306u64 kallsyms__get_function_start(const char *kallsyms_filename,
307 const char *symbol_name);
308
John Kacur8b40f522009-09-24 18:02:18 +0200309#endif /* __PERF_RECORD_H */