blob: 1b197280c621fea866e3bfd90f71f3213971ee4a [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"
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +02009
Peter Zijlstra18408dd2009-08-13 11:47:55 +020010/*
11 * PERF_SAMPLE_IP | PERF_SAMPLE_TID | *
12 */
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020013struct ip_event {
14 struct perf_event_header header;
15 u64 ip;
16 u32 pid, tid;
17 unsigned char __more_data[];
18};
19
20struct mmap_event {
21 struct perf_event_header header;
22 u32 pid, tid;
23 u64 start;
24 u64 len;
25 u64 pgoff;
26 char filename[PATH_MAX];
27};
28
29struct comm_event {
30 struct perf_event_header header;
31 u32 pid, tid;
32 char comm[16];
33};
34
35struct fork_event {
36 struct perf_event_header header;
37 u32 pid, ppid;
38 u32 tid, ptid;
Arjan van de Ven393b2ad2009-09-12 07:52:47 +020039 u64 time;
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020040};
41
42struct lost_event {
43 struct perf_event_header header;
44 u64 id;
45 u64 lost;
46};
47
Peter Zijlstra18408dd2009-08-13 11:47:55 +020048/*
49 * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
50 */
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020051struct read_event {
52 struct perf_event_header header;
Ingo Molnardc02bf72009-09-16 13:45:00 +020053 u32 pid, tid;
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +020054 u64 value;
55 u64 time_enabled;
56 u64 time_running;
57 u64 id;
58};
59
Frederic Weisbeckera2854122011-05-21 19:33:04 +020060
61#define PERF_SAMPLE_MASK \
62 (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
63 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \
64 PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \
65 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
66
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +090067struct sample_event {
Arjan van de Venfd39e052009-09-12 07:53:00 +020068 struct perf_event_header header;
69 u64 array[];
70};
71
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -020072struct perf_sample {
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +090073 u64 ip;
74 u32 pid, tid;
75 u64 time;
76 u64 addr;
77 u64 id;
78 u64 stream_id;
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +090079 u64 period;
Arnaldo Carvalho de Meloeed05fe2010-04-05 12:53:45 -030080 u32 cpu;
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +090081 u32 raw_size;
82 void *raw_data;
Arnaldo Carvalho de Meloeed05fe2010-04-05 12:53:45 -030083 struct ip_callchain *callchain;
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +010084 struct branch_stack *branch_stack;
OGAWA Hirofumi180f95e2009-12-06 20:08:24 +090085};
86
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -020087#define BUILD_ID_SIZE 20
88
89struct build_id_event {
90 struct perf_event_header header;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080091 pid_t pid;
Arnaldo Carvalho de Melo8d063672009-11-04 18:50:43 -020092 u8 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))];
93 char filename[];
94};
Arjan van de Venfd39e052009-09-12 07:53:00 +020095
Frederic Weisbecker98402802010-05-02 22:05:29 +020096enum perf_user_event_type { /* above any possible kernel type */
Thomas Gleixner9aefcab2010-12-07 12:48:47 +000097 PERF_RECORD_USER_TYPE_START = 64,
Tom Zanussi2c46dbb2010-04-01 23:59:19 -050098 PERF_RECORD_HEADER_ATTR = 64,
Tom Zanussicd19a032010-04-01 23:59:20 -050099 PERF_RECORD_HEADER_EVENT_TYPE = 65,
Tom Zanussi92155452010-04-01 23:59:21 -0500100 PERF_RECORD_HEADER_TRACING_DATA = 66,
Tom Zanussic7929e42010-04-01 23:59:22 -0500101 PERF_RECORD_HEADER_BUILD_ID = 67,
Frederic Weisbecker98402802010-05-02 22:05:29 +0200102 PERF_RECORD_FINISHED_ROUND = 68,
Tom Zanussi2c46dbb2010-04-01 23:59:19 -0500103 PERF_RECORD_HEADER_MAX
104};
105
106struct attr_event {
107 struct perf_event_header header;
108 struct perf_event_attr attr;
109 u64 id[];
Tom Zanussi8dc58102010-04-01 23:59:15 -0500110};
111
Tom Zanussicd19a032010-04-01 23:59:20 -0500112#define MAX_EVENT_NAME 64
113
114struct perf_trace_event_type {
115 u64 event_id;
116 char name[MAX_EVENT_NAME];
117};
118
119struct event_type_event {
120 struct perf_event_header header;
121 struct perf_trace_event_type event_type;
122};
123
Tom Zanussi92155452010-04-01 23:59:21 -0500124struct tracing_data_event {
125 struct perf_event_header header;
126 u32 size;
127};
128
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200129union perf_event {
Frederic Weisbecker1fe2c102009-08-12 10:19:53 +0200130 struct perf_event_header header;
131 struct ip_event ip;
132 struct mmap_event mmap;
133 struct comm_event comm;
134 struct fork_event fork;
135 struct lost_event lost;
136 struct read_event read;
Arjan van de Venfd39e052009-09-12 07:53:00 +0200137 struct sample_event sample;
Tom Zanussi2c46dbb2010-04-01 23:59:19 -0500138 struct attr_event attr;
Tom Zanussicd19a032010-04-01 23:59:20 -0500139 struct event_type_event event_type;
Tom Zanussi92155452010-04-01 23:59:21 -0500140 struct tracing_data_event tracing_data;
Tom Zanussic7929e42010-04-01 23:59:22 -0500141 struct build_id_event build_id;
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200142};
Frederic Weisbecker66e274f2009-08-12 11:07:25 +0200143
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200144void perf_event__print_totals(void);
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200145
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200146struct perf_tool;
Arnaldo Carvalho de Melo401b8e12011-02-10 12:52:47 -0200147struct thread_map;
Arnaldo Carvalho de Melo4aa65632009-12-13 19:50:29 -0200148
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200149typedef int (*perf_event__handler_t)(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200150 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200151 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200152 struct machine *machine);
Arnaldo Carvalho de Melocf553112010-01-07 19:59:40 -0200153
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200154int perf_event__synthesize_thread_map(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200155 struct thread_map *threads,
Arnaldo Carvalho de Melo7c940c12011-02-11 11:45:54 -0200156 perf_event__handler_t process,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200157 struct machine *machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200158int perf_event__synthesize_threads(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200159 perf_event__handler_t process,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200160 struct machine *machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200161int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200162 perf_event__handler_t process,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200163 struct machine *machine,
164 const char *symbol_name);
165
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200166int perf_event__synthesize_modules(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200167 perf_event__handler_t process,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200168 struct machine *machine);
169
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200170int perf_event__process_comm(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200171 union perf_event *event,
172 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200173 struct machine *machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200174int perf_event__process_lost(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200175 union perf_event *event,
176 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200177 struct machine *machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200178int perf_event__process_mmap(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200179 union perf_event *event,
180 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200181 struct machine *machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200182int perf_event__process_task(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200183 union perf_event *event,
184 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200185 struct machine *machine);
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200186int perf_event__process(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200187 union perf_event *event,
188 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200189 struct machine *machine);
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200190
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200191struct addr_location;
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200192int perf_event__preprocess_sample(const union perf_event *self,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200193 struct machine *machine,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200194 struct addr_location *al,
195 struct perf_sample *sample,
196 symbol_filter_t filter);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200197
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200198const char *perf_event__name(unsigned int id);
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300199
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200200int perf_event__parse_sample(const union perf_event *event, u64 type,
Frederic Weisbeckera2854122011-05-21 19:33:04 +0200201 int sample_size, bool sample_id_all,
David Ahern936be502011-09-06 09:12:26 -0600202 struct perf_sample *sample, bool swapped);
Andrew Vagin74eec262011-11-28 12:03:31 +0300203int perf_event__synthesize_sample(union perf_event *event, u64 type,
204 const struct perf_sample *sample,
205 bool swapped);
Arnaldo Carvalho de Melod0dd74e2011-01-21 13:46:41 -0200206
Arnaldo Carvalho de Melo482ad892011-12-02 11:06:37 -0200207size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
208size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
209size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
210size_t perf_event__fprintf(union perf_event *event, FILE *fp);
211
John Kacur8b40f522009-09-24 18:02:18 +0200212#endif /* __PERF_RECORD_H */