John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 1 | #ifndef __PERF_TRACE_EVENTS_H |
| 2 | #define __PERF_TRACE_EVENTS_H |
Steven Rostedt | 52050943 | 2009-08-17 16:18:05 +0200 | [diff] [blame] | 3 | |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 4 | #include <stdbool.h> |
Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 5 | #include "parse-events.h" |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 6 | |
| 7 | struct machine; |
| 8 | struct perf_sample; |
| 9 | union perf_event; |
| 10 | struct thread; |
Steven Rostedt | 52050943 | 2009-08-17 16:18:05 +0200 | [diff] [blame] | 11 | |
| 12 | #define __unused __attribute__((unused)) |
| 13 | |
| 14 | |
| 15 | #ifndef PAGE_MASK |
| 16 | #define PAGE_MASK (page_size - 1) |
| 17 | #endif |
| 18 | |
| 19 | enum { |
| 20 | RINGBUF_TYPE_PADDING = 29, |
| 21 | RINGBUF_TYPE_TIME_EXTEND = 30, |
| 22 | RINGBUF_TYPE_TIME_STAMP = 31, |
| 23 | }; |
| 24 | |
| 25 | #ifndef TS_SHIFT |
| 26 | #define TS_SHIFT 27 |
| 27 | #endif |
| 28 | |
| 29 | #define NSECS_PER_SEC 1000000000ULL |
| 30 | #define NSECS_PER_USEC 1000ULL |
| 31 | |
| 32 | enum format_flags { |
| 33 | FIELD_IS_ARRAY = 1, |
| 34 | FIELD_IS_POINTER = 2, |
Tom Zanussi | 26a5074 | 2009-10-06 01:09:50 -0500 | [diff] [blame] | 35 | FIELD_IS_SIGNED = 4, |
Tom Zanussi | 064739b | 2009-10-06 01:09:52 -0500 | [diff] [blame] | 36 | FIELD_IS_STRING = 8, |
| 37 | FIELD_IS_DYNAMIC = 16, |
Tom Zanussi | eb9a42c | 2009-11-25 01:15:47 -0600 | [diff] [blame] | 38 | FIELD_IS_FLAG = 32, |
| 39 | FIELD_IS_SYMBOLIC = 64, |
Steven Rostedt | 52050943 | 2009-08-17 16:18:05 +0200 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | struct format_field { |
| 43 | struct format_field *next; |
| 44 | char *type; |
| 45 | char *name; |
| 46 | int offset; |
| 47 | int size; |
| 48 | unsigned long flags; |
| 49 | }; |
| 50 | |
| 51 | struct format { |
| 52 | int nr_common; |
| 53 | int nr_fields; |
| 54 | struct format_field *common_fields; |
| 55 | struct format_field *fields; |
| 56 | }; |
| 57 | |
| 58 | struct print_arg_atom { |
| 59 | char *atom; |
| 60 | }; |
| 61 | |
| 62 | struct print_arg_string { |
| 63 | char *string; |
Frederic Weisbecker | 561f732 | 2009-08-31 06:45:21 +0200 | [diff] [blame] | 64 | int offset; |
Steven Rostedt | 52050943 | 2009-08-17 16:18:05 +0200 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | struct print_arg_field { |
| 68 | char *name; |
| 69 | struct format_field *field; |
| 70 | }; |
| 71 | |
| 72 | struct print_flag_sym { |
| 73 | struct print_flag_sym *next; |
| 74 | char *value; |
| 75 | char *str; |
| 76 | }; |
| 77 | |
| 78 | struct print_arg_typecast { |
| 79 | char *type; |
| 80 | struct print_arg *item; |
| 81 | }; |
| 82 | |
| 83 | struct print_arg_flags { |
| 84 | struct print_arg *field; |
| 85 | char *delim; |
| 86 | struct print_flag_sym *flags; |
| 87 | }; |
| 88 | |
| 89 | struct print_arg_symbol { |
| 90 | struct print_arg *field; |
| 91 | struct print_flag_sym *symbols; |
| 92 | }; |
| 93 | |
| 94 | struct print_arg; |
| 95 | |
| 96 | struct print_arg_op { |
| 97 | char *op; |
| 98 | int prio; |
| 99 | struct print_arg *left; |
| 100 | struct print_arg *right; |
| 101 | }; |
| 102 | |
| 103 | struct print_arg_func { |
| 104 | char *name; |
| 105 | struct print_arg *args; |
| 106 | }; |
| 107 | |
| 108 | enum print_arg_type { |
| 109 | PRINT_NULL, |
| 110 | PRINT_ATOM, |
| 111 | PRINT_FIELD, |
| 112 | PRINT_FLAGS, |
| 113 | PRINT_SYMBOL, |
| 114 | PRINT_TYPE, |
| 115 | PRINT_STRING, |
| 116 | PRINT_OP, |
| 117 | }; |
| 118 | |
| 119 | struct print_arg { |
| 120 | struct print_arg *next; |
| 121 | enum print_arg_type type; |
| 122 | union { |
| 123 | struct print_arg_atom atom; |
| 124 | struct print_arg_field field; |
| 125 | struct print_arg_typecast typecast; |
| 126 | struct print_arg_flags flags; |
| 127 | struct print_arg_symbol symbol; |
| 128 | struct print_arg_func func; |
| 129 | struct print_arg_string string; |
| 130 | struct print_arg_op op; |
| 131 | }; |
| 132 | }; |
| 133 | |
| 134 | struct print_fmt { |
| 135 | char *format; |
| 136 | struct print_arg *args; |
| 137 | }; |
| 138 | |
| 139 | struct event { |
| 140 | struct event *next; |
| 141 | char *name; |
| 142 | int id; |
| 143 | int flags; |
| 144 | struct format format; |
| 145 | struct print_fmt print_fmt; |
Tom Zanussi | 2774601 | 2009-10-06 01:09:51 -0500 | [diff] [blame] | 146 | char *system; |
Steven Rostedt | 52050943 | 2009-08-17 16:18:05 +0200 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | enum { |
Steven Rostedt | 07a4bdd | 2009-10-14 15:43:39 -0400 | [diff] [blame] | 150 | EVENT_FL_ISFTRACE = 0x01, |
| 151 | EVENT_FL_ISPRINT = 0x02, |
| 152 | EVENT_FL_ISBPRINT = 0x04, |
| 153 | EVENT_FL_ISFUNC = 0x08, |
| 154 | EVENT_FL_ISFUNCENT = 0x10, |
| 155 | EVENT_FL_ISFUNCRET = 0x20, |
| 156 | |
| 157 | EVENT_FL_FAILED = 0x80000000 |
Steven Rostedt | 52050943 | 2009-08-17 16:18:05 +0200 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | struct record { |
| 161 | unsigned long long ts; |
| 162 | int size; |
| 163 | void *data; |
| 164 | }; |
| 165 | |
| 166 | struct record *trace_peek_data(int cpu); |
| 167 | struct record *trace_read_data(int cpu); |
| 168 | |
| 169 | void parse_set_info(int nr_cpus, int long_sz); |
| 170 | |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 171 | ssize_t trace_report(int fd, bool repipe); |
Steven Rostedt | 52050943 | 2009-08-17 16:18:05 +0200 | [diff] [blame] | 172 | |
| 173 | void *malloc_or_die(unsigned int size); |
| 174 | |
| 175 | void parse_cmdlines(char *file, int size); |
| 176 | void parse_proc_kallsyms(char *file, unsigned int size); |
| 177 | void parse_ftrace_printk(char *file, unsigned int size); |
| 178 | |
| 179 | void print_funcs(void); |
| 180 | void print_printk(void); |
| 181 | |
| 182 | int parse_ftrace_file(char *buf, unsigned long size); |
Tom Zanussi | 2774601 | 2009-10-06 01:09:51 -0500 | [diff] [blame] | 183 | int parse_event_file(char *buf, unsigned long size, char *sys); |
David Ahern | c70c94b | 2011-03-09 22:23:25 -0700 | [diff] [blame] | 184 | void print_trace_event(int cpu, void *data, int size); |
Steven Rostedt | 52050943 | 2009-08-17 16:18:05 +0200 | [diff] [blame] | 185 | |
| 186 | extern int file_bigendian; |
| 187 | extern int host_bigendian; |
| 188 | |
| 189 | int bigendian(void); |
| 190 | |
| 191 | static inline unsigned short __data2host2(unsigned short data) |
| 192 | { |
| 193 | unsigned short swap; |
| 194 | |
| 195 | if (host_bigendian == file_bigendian) |
| 196 | return data; |
| 197 | |
| 198 | swap = ((data & 0xffULL) << 8) | |
| 199 | ((data & (0xffULL << 8)) >> 8); |
| 200 | |
| 201 | return swap; |
| 202 | } |
| 203 | |
| 204 | static inline unsigned int __data2host4(unsigned int data) |
| 205 | { |
| 206 | unsigned int swap; |
| 207 | |
| 208 | if (host_bigendian == file_bigendian) |
| 209 | return data; |
| 210 | |
| 211 | swap = ((data & 0xffULL) << 24) | |
| 212 | ((data & (0xffULL << 8)) << 8) | |
| 213 | ((data & (0xffULL << 16)) >> 8) | |
| 214 | ((data & (0xffULL << 24)) >> 24); |
| 215 | |
| 216 | return swap; |
| 217 | } |
| 218 | |
| 219 | static inline unsigned long long __data2host8(unsigned long long data) |
| 220 | { |
| 221 | unsigned long long swap; |
| 222 | |
| 223 | if (host_bigendian == file_bigendian) |
| 224 | return data; |
| 225 | |
| 226 | swap = ((data & 0xffULL) << 56) | |
| 227 | ((data & (0xffULL << 8)) << 40) | |
| 228 | ((data & (0xffULL << 16)) << 24) | |
| 229 | ((data & (0xffULL << 24)) << 8) | |
| 230 | ((data & (0xffULL << 32)) >> 8) | |
| 231 | ((data & (0xffULL << 40)) >> 24) | |
| 232 | ((data & (0xffULL << 48)) >> 40) | |
| 233 | ((data & (0xffULL << 56)) >> 56); |
| 234 | |
| 235 | return swap; |
| 236 | } |
| 237 | |
| 238 | #define data2host2(ptr) __data2host2(*(unsigned short *)ptr) |
| 239 | #define data2host4(ptr) __data2host4(*(unsigned int *)ptr) |
Frederic Weisbecker | 85cb68b | 2010-05-20 10:34:59 +0200 | [diff] [blame] | 240 | #define data2host8(ptr) ({ \ |
| 241 | unsigned long long __val; \ |
| 242 | \ |
| 243 | memcpy(&__val, (ptr), sizeof(unsigned long long)); \ |
| 244 | __data2host8(__val); \ |
| 245 | }) |
Steven Rostedt | 52050943 | 2009-08-17 16:18:05 +0200 | [diff] [blame] | 246 | |
| 247 | extern int header_page_ts_offset; |
| 248 | extern int header_page_ts_size; |
| 249 | extern int header_page_size_offset; |
| 250 | extern int header_page_size_size; |
| 251 | extern int header_page_data_offset; |
| 252 | extern int header_page_data_size; |
| 253 | |
Ian Munsie | c055564 | 2010-04-13 18:37:33 +1000 | [diff] [blame] | 254 | extern bool latency_format; |
Steven Rostedt | cda4846 | 2009-10-14 15:43:42 -0400 | [diff] [blame] | 255 | |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 256 | int trace_parse_common_type(void *data); |
Tom Zanussi | 16c632d | 2009-11-25 01:15:48 -0600 | [diff] [blame] | 257 | int trace_parse_common_pid(void *data); |
Tom Zanussi | d1b9377 | 2009-11-25 01:15:50 -0600 | [diff] [blame] | 258 | int parse_common_pc(void *data); |
| 259 | int parse_common_flags(void *data); |
| 260 | int parse_common_lock_depth(void *data); |
Ingo Molnar | ec15676 | 2009-09-11 12:12:54 +0200 | [diff] [blame] | 261 | struct event *trace_find_event(int id); |
Tom Zanussi | 16c632d | 2009-11-25 01:15:48 -0600 | [diff] [blame] | 262 | struct event *trace_find_next_event(struct event *event); |
| 263 | unsigned long long read_size(void *ptr, int size); |
Frederic Weisbecker | 4653881 | 2009-09-12 02:43:45 +0200 | [diff] [blame] | 264 | unsigned long long |
| 265 | raw_field_value(struct event *event, const char *name, void *data); |
| 266 | void *raw_field_ptr(struct event *event, const char *name, void *data); |
Tom Zanussi | 16c632d | 2009-11-25 01:15:48 -0600 | [diff] [blame] | 267 | unsigned long long eval_flag(const char *flag); |
Steven Rostedt | 52050943 | 2009-08-17 16:18:05 +0200 | [diff] [blame] | 268 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 269 | int read_tracing_data(int fd, struct list_head *pattrs); |
Jiri Olsa | 29208e5 | 2011-10-20 15:59:43 +0200 | [diff] [blame] | 270 | |
| 271 | struct tracing_data { |
| 272 | /* size is only valid if temp is 'true' */ |
| 273 | ssize_t size; |
| 274 | bool temp; |
| 275 | char temp_file[50]; |
| 276 | }; |
| 277 | |
| 278 | struct tracing_data *tracing_data_get(struct list_head *pattrs, |
| 279 | int fd, bool temp); |
| 280 | void tracing_data_put(struct tracing_data *tdata); |
| 281 | |
Steven Rostedt | 52050943 | 2009-08-17 16:18:05 +0200 | [diff] [blame] | 282 | |
Steven Rostedt | cda4846 | 2009-10-14 15:43:42 -0400 | [diff] [blame] | 283 | /* taken from kernel/trace/trace.h */ |
| 284 | enum trace_flag_type { |
| 285 | TRACE_FLAG_IRQS_OFF = 0x01, |
| 286 | TRACE_FLAG_IRQS_NOSUPPORT = 0x02, |
| 287 | TRACE_FLAG_NEED_RESCHED = 0x04, |
| 288 | TRACE_FLAG_HARDIRQ = 0x08, |
| 289 | TRACE_FLAG_SOFTIRQ = 0x10, |
| 290 | }; |
| 291 | |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 292 | struct scripting_ops { |
| 293 | const char *name; |
Tom Zanussi | 586bc5c | 2009-12-15 02:53:35 -0600 | [diff] [blame] | 294 | int (*start_script) (const char *script, int argc, const char **argv); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 295 | int (*stop_script) (void); |
David Ahern | be6d842 | 2011-03-09 22:23:23 -0700 | [diff] [blame] | 296 | void (*process_event) (union perf_event *event, |
| 297 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 298 | struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 299 | struct machine *machine, |
David Ahern | be6d842 | 2011-03-09 22:23:23 -0700 | [diff] [blame] | 300 | struct thread *thread); |
Tom Zanussi | 956ffd0 | 2009-11-25 01:15:46 -0600 | [diff] [blame] | 301 | int (*generate_script) (const char *outfile); |
| 302 | }; |
| 303 | |
| 304 | int script_spec_register(const char *spec, struct scripting_ops *ops); |
| 305 | |
Tom Zanussi | 16c632d | 2009-11-25 01:15:48 -0600 | [diff] [blame] | 306 | void setup_perl_scripting(void); |
Tom Zanussi | 7e4b21b | 2010-01-27 02:27:57 -0600 | [diff] [blame] | 307 | void setup_python_scripting(void); |
Tom Zanussi | 16c632d | 2009-11-25 01:15:48 -0600 | [diff] [blame] | 308 | |
Tom Zanussi | 7397d80 | 2010-01-27 02:27:54 -0600 | [diff] [blame] | 309 | struct scripting_context { |
| 310 | void *event_data; |
| 311 | }; |
| 312 | |
| 313 | int common_pc(struct scripting_context *context); |
| 314 | int common_flags(struct scripting_context *context); |
| 315 | int common_lock_depth(struct scripting_context *context); |
| 316 | |
John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 317 | #endif /* __PERF_TRACE_EVENTS_H */ |