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 /* 12 * PERF_SAMPLE_IP | PERF_SAMPLE_TID | * 13 */ 14 struct ip_event { 15 struct perf_event_header header; 16 u64 ip; 17 u32 pid, tid; 18 unsigned char __more_data[]; 19 }; 20 21 struct mmap_event { 22 struct perf_event_header header; 23 u32 pid, tid; 24 u64 start; 25 u64 len; 26 u64 pgoff; 27 char filename[PATH_MAX]; 28 }; 29 30 struct comm_event { 31 struct perf_event_header header; 32 u32 pid, tid; 33 char comm[16]; 34 }; 35 36 struct fork_event { 37 struct perf_event_header header; 38 u32 pid, ppid; 39 u32 tid, ptid; 40 u64 time; 41 }; 42 43 struct lost_event { 44 struct perf_event_header header; 45 u64 id; 46 u64 lost; 47 }; 48 49 /* 50 * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID 51 */ 52 struct read_event { 53 struct perf_event_header header; 54 u32 pid, tid; 55 u64 value; 56 u64 time_enabled; 57 u64 time_running; 58 u64 id; 59 }; 60 61 62 #define PERF_SAMPLE_MASK \ 63 (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \ 64 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \ 65 PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \ 66 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD) 67 68 struct sample_event { 69 struct perf_event_header header; 70 u64 array[]; 71 }; 72 73 struct regs_dump { 74 u64 *regs; 75 }; 76 77 struct stack_dump { 78 u16 offset; 79 u64 size; 80 char *data; 81 }; 82 83 struct perf_sample { 84 u64 ip; 85 u32 pid, tid; 86 u64 time; 87 u64 addr; 88 u64 id; 89 u64 stream_id; 90 u64 period; 91 u32 cpu; 92 u32 raw_size; 93 void *raw_data; 94 struct ip_callchain *callchain; 95 struct branch_stack *branch_stack; 96 struct regs_dump user_regs; 97 struct stack_dump user_stack; 98 }; 99 100 struct build_id_event { 101 struct perf_event_header header; 102 pid_t pid; 103 u8 build_id[PERF_ALIGN(BUILD_ID_SIZE, sizeof(u64))]; 104 char filename[]; 105 }; 106 107 enum perf_user_event_type { /* above any possible kernel type */ 108 PERF_RECORD_USER_TYPE_START = 64, 109 PERF_RECORD_HEADER_ATTR = 64, 110 PERF_RECORD_HEADER_EVENT_TYPE = 65, 111 PERF_RECORD_HEADER_TRACING_DATA = 66, 112 PERF_RECORD_HEADER_BUILD_ID = 67, 113 PERF_RECORD_FINISHED_ROUND = 68, 114 PERF_RECORD_HEADER_MAX 115 }; 116 117 struct attr_event { 118 struct perf_event_header header; 119 struct perf_event_attr attr; 120 u64 id[]; 121 }; 122 123 #define MAX_EVENT_NAME 64 124 125 struct perf_trace_event_type { 126 u64 event_id; 127 char name[MAX_EVENT_NAME]; 128 }; 129 130 struct event_type_event { 131 struct perf_event_header header; 132 struct perf_trace_event_type event_type; 133 }; 134 135 struct tracing_data_event { 136 struct perf_event_header header; 137 u32 size; 138 }; 139 140 union perf_event { 141 struct perf_event_header header; 142 struct ip_event ip; 143 struct mmap_event mmap; 144 struct comm_event comm; 145 struct fork_event fork; 146 struct lost_event lost; 147 struct read_event read; 148 struct sample_event sample; 149 struct attr_event attr; 150 struct event_type_event event_type; 151 struct tracing_data_event tracing_data; 152 struct build_id_event build_id; 153 }; 154 155 void perf_event__print_totals(void); 156 157 struct perf_tool; 158 struct thread_map; 159 160 typedef int (*perf_event__handler_t)(struct perf_tool *tool, 161 union perf_event *event, 162 struct perf_sample *sample, 163 struct machine *machine); 164 165 int perf_event__synthesize_thread_map(struct perf_tool *tool, 166 struct thread_map *threads, 167 perf_event__handler_t process, 168 struct machine *machine); 169 int perf_event__synthesize_threads(struct perf_tool *tool, 170 perf_event__handler_t process, 171 struct machine *machine); 172 int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, 173 perf_event__handler_t process, 174 struct machine *machine, 175 const char *symbol_name); 176 177 int perf_event__synthesize_modules(struct perf_tool *tool, 178 perf_event__handler_t process, 179 struct machine *machine); 180 181 int perf_event__process_comm(struct perf_tool *tool, 182 union perf_event *event, 183 struct perf_sample *sample, 184 struct machine *machine); 185 int perf_event__process_lost(struct perf_tool *tool, 186 union perf_event *event, 187 struct perf_sample *sample, 188 struct machine *machine); 189 int perf_event__process_mmap(struct perf_tool *tool, 190 union perf_event *event, 191 struct perf_sample *sample, 192 struct machine *machine); 193 int perf_event__process_fork(struct perf_tool *tool, 194 union perf_event *event, 195 struct perf_sample *sample, 196 struct machine *machine); 197 int perf_event__process_exit(struct perf_tool *tool, 198 union perf_event *event, 199 struct perf_sample *sample, 200 struct machine *machine); 201 int perf_event__process(struct perf_tool *tool, 202 union perf_event *event, 203 struct perf_sample *sample, 204 struct machine *machine); 205 206 struct addr_location; 207 int perf_event__preprocess_sample(const union perf_event *self, 208 struct machine *machine, 209 struct addr_location *al, 210 struct perf_sample *sample, 211 symbol_filter_t filter); 212 213 const char *perf_event__name(unsigned int id); 214 215 int perf_event__synthesize_sample(union perf_event *event, u64 type, 216 const struct perf_sample *sample, 217 bool swapped); 218 219 size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp); 220 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp); 221 size_t perf_event__fprintf_task(union perf_event *event, FILE *fp); 222 size_t perf_event__fprintf(union perf_event *event, FILE *fp); 223 224 #endif /* __PERF_RECORD_H */ 225