Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> |
| 3 | * |
| 4 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; |
| 8 | * version 2.1 of the License (not later!) |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
Jon Stanley | 7b9f6b4 | 2012-09-07 16:32:46 -0400 | [diff] [blame] | 16 | * License along with this program; if not, see <http://www.gnu.org/licenses> |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 17 | * |
| 18 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 19 | */ |
| 20 | #ifndef _PARSE_EVENTS_H |
| 21 | #define _PARSE_EVENTS_H |
| 22 | |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 23 | #include <stdbool.h> |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 24 | #include <stdarg.h> |
| 25 | #include <regex.h> |
| 26 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 27 | #ifndef __maybe_unused |
| 28 | #define __maybe_unused __attribute__((unused)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 29 | #endif |
| 30 | |
| 31 | /* ----------------------- trace_seq ----------------------- */ |
| 32 | |
| 33 | |
| 34 | #ifndef TRACE_SEQ_BUF_SIZE |
| 35 | #define TRACE_SEQ_BUF_SIZE 4096 |
| 36 | #endif |
| 37 | |
| 38 | #ifndef DEBUG_RECORD |
| 39 | #define DEBUG_RECORD 0 |
| 40 | #endif |
| 41 | |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 42 | struct pevent_record { |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 43 | unsigned long long ts; |
| 44 | unsigned long long offset; |
| 45 | long long missed_events; /* buffer dropped events before */ |
| 46 | int record_size; /* size of binary record */ |
| 47 | int size; /* size of data */ |
| 48 | void *data; |
| 49 | int cpu; |
| 50 | int ref_count; |
| 51 | int locked; /* Do not free, even if ref_count is zero */ |
Steven Rostedt | ff1a70e | 2012-08-23 11:22:01 -0400 | [diff] [blame] | 52 | void *priv; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 53 | #if DEBUG_RECORD |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 54 | struct pevent_record *prev; |
| 55 | struct pevent_record *next; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 56 | long alloc_addr; |
| 57 | #endif |
| 58 | }; |
| 59 | |
| 60 | /* |
| 61 | * Trace sequences are used to allow a function to call several other functions |
| 62 | * to create a string of data to use (up to a max of PAGE_SIZE). |
| 63 | */ |
| 64 | |
| 65 | struct trace_seq { |
| 66 | char *buffer; |
| 67 | unsigned int buffer_size; |
| 68 | unsigned int len; |
| 69 | unsigned int readpos; |
| 70 | }; |
| 71 | |
| 72 | void trace_seq_init(struct trace_seq *s); |
Namhyung Kim | 6a48aec | 2013-06-04 14:20:19 +0900 | [diff] [blame] | 73 | void trace_seq_reset(struct trace_seq *s); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 74 | void trace_seq_destroy(struct trace_seq *s); |
| 75 | |
| 76 | extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...) |
| 77 | __attribute__ ((format (printf, 2, 3))); |
| 78 | extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args) |
| 79 | __attribute__ ((format (printf, 2, 0))); |
| 80 | |
| 81 | extern int trace_seq_puts(struct trace_seq *s, const char *str); |
| 82 | extern int trace_seq_putc(struct trace_seq *s, unsigned char c); |
| 83 | |
| 84 | extern void trace_seq_terminate(struct trace_seq *s); |
| 85 | |
| 86 | extern int trace_seq_do_printf(struct trace_seq *s); |
| 87 | |
| 88 | |
| 89 | /* ----------------------- pevent ----------------------- */ |
| 90 | |
| 91 | struct pevent; |
| 92 | struct event_format; |
| 93 | |
| 94 | typedef int (*pevent_event_handler_func)(struct trace_seq *s, |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 95 | struct pevent_record *record, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 96 | struct event_format *event, |
| 97 | void *context); |
| 98 | |
| 99 | typedef int (*pevent_plugin_load_func)(struct pevent *pevent); |
| 100 | typedef int (*pevent_plugin_unload_func)(void); |
| 101 | |
| 102 | struct plugin_option { |
| 103 | struct plugin_option *next; |
| 104 | void *handle; |
| 105 | char *file; |
| 106 | char *name; |
| 107 | char *plugin_alias; |
| 108 | char *description; |
| 109 | char *value; |
Steven Rostedt | ff1a70e | 2012-08-23 11:22:01 -0400 | [diff] [blame] | 110 | void *priv; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 111 | int set; |
| 112 | }; |
| 113 | |
| 114 | /* |
| 115 | * Plugin hooks that can be called: |
| 116 | * |
| 117 | * PEVENT_PLUGIN_LOADER: (required) |
| 118 | * The function name to initialized the plugin. |
| 119 | * |
| 120 | * int PEVENT_PLUGIN_LOADER(struct pevent *pevent) |
| 121 | * |
| 122 | * PEVENT_PLUGIN_UNLOADER: (optional) |
| 123 | * The function called just before unloading |
| 124 | * |
| 125 | * int PEVENT_PLUGIN_UNLOADER(void) |
| 126 | * |
| 127 | * PEVENT_PLUGIN_OPTIONS: (optional) |
| 128 | * Plugin options that can be set before loading |
| 129 | * |
| 130 | * struct plugin_option PEVENT_PLUGIN_OPTIONS[] = { |
| 131 | * { |
| 132 | * .name = "option-name", |
| 133 | * .plugin_alias = "overide-file-name", (optional) |
| 134 | * .description = "description of option to show users", |
| 135 | * }, |
| 136 | * { |
| 137 | * .name = NULL, |
| 138 | * }, |
| 139 | * }; |
| 140 | * |
| 141 | * Array must end with .name = NULL; |
| 142 | * |
| 143 | * |
| 144 | * .plugin_alias is used to give a shorter name to access |
| 145 | * the vairable. Useful if a plugin handles more than one event. |
| 146 | * |
| 147 | * PEVENT_PLUGIN_ALIAS: (optional) |
| 148 | * The name to use for finding options (uses filename if not defined) |
| 149 | */ |
| 150 | #define PEVENT_PLUGIN_LOADER pevent_plugin_loader |
| 151 | #define PEVENT_PLUGIN_UNLOADER pevent_plugin_unloader |
| 152 | #define PEVENT_PLUGIN_OPTIONS pevent_plugin_options |
| 153 | #define PEVENT_PLUGIN_ALIAS pevent_plugin_alias |
| 154 | #define _MAKE_STR(x) #x |
| 155 | #define MAKE_STR(x) _MAKE_STR(x) |
| 156 | #define PEVENT_PLUGIN_LOADER_NAME MAKE_STR(PEVENT_PLUGIN_LOADER) |
| 157 | #define PEVENT_PLUGIN_UNLOADER_NAME MAKE_STR(PEVENT_PLUGIN_UNLOADER) |
| 158 | #define PEVENT_PLUGIN_OPTIONS_NAME MAKE_STR(PEVENT_PLUGIN_OPTIONS) |
| 159 | #define PEVENT_PLUGIN_ALIAS_NAME MAKE_STR(PEVENT_PLUGIN_ALIAS) |
| 160 | |
| 161 | #define NSECS_PER_SEC 1000000000ULL |
| 162 | #define NSECS_PER_USEC 1000ULL |
| 163 | |
| 164 | enum format_flags { |
| 165 | FIELD_IS_ARRAY = 1, |
| 166 | FIELD_IS_POINTER = 2, |
| 167 | FIELD_IS_SIGNED = 4, |
| 168 | FIELD_IS_STRING = 8, |
| 169 | FIELD_IS_DYNAMIC = 16, |
| 170 | FIELD_IS_LONG = 32, |
Steven Rostedt | 668fe01 | 2012-04-06 00:47:55 +0200 | [diff] [blame] | 171 | FIELD_IS_FLAG = 64, |
| 172 | FIELD_IS_SYMBOLIC = 128, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | struct format_field { |
| 176 | struct format_field *next; |
| 177 | struct event_format *event; |
| 178 | char *type; |
| 179 | char *name; |
| 180 | int offset; |
| 181 | int size; |
| 182 | unsigned int arraylen; |
| 183 | unsigned int elementsize; |
| 184 | unsigned long flags; |
| 185 | }; |
| 186 | |
| 187 | struct format { |
| 188 | int nr_common; |
| 189 | int nr_fields; |
| 190 | struct format_field *common_fields; |
| 191 | struct format_field *fields; |
| 192 | }; |
| 193 | |
| 194 | struct print_arg_atom { |
| 195 | char *atom; |
| 196 | }; |
| 197 | |
| 198 | struct print_arg_string { |
| 199 | char *string; |
| 200 | int offset; |
| 201 | }; |
| 202 | |
| 203 | struct print_arg_field { |
| 204 | char *name; |
| 205 | struct format_field *field; |
| 206 | }; |
| 207 | |
| 208 | struct print_flag_sym { |
| 209 | struct print_flag_sym *next; |
| 210 | char *value; |
| 211 | char *str; |
| 212 | }; |
| 213 | |
| 214 | struct print_arg_typecast { |
| 215 | char *type; |
| 216 | struct print_arg *item; |
| 217 | }; |
| 218 | |
| 219 | struct print_arg_flags { |
| 220 | struct print_arg *field; |
| 221 | char *delim; |
| 222 | struct print_flag_sym *flags; |
| 223 | }; |
| 224 | |
| 225 | struct print_arg_symbol { |
| 226 | struct print_arg *field; |
| 227 | struct print_flag_sym *symbols; |
| 228 | }; |
| 229 | |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 230 | struct print_arg_hex { |
| 231 | struct print_arg *field; |
| 232 | struct print_arg *size; |
| 233 | }; |
| 234 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 235 | struct print_arg_dynarray { |
| 236 | struct format_field *field; |
| 237 | struct print_arg *index; |
| 238 | }; |
| 239 | |
| 240 | struct print_arg; |
| 241 | |
| 242 | struct print_arg_op { |
| 243 | char *op; |
| 244 | int prio; |
| 245 | struct print_arg *left; |
| 246 | struct print_arg *right; |
| 247 | }; |
| 248 | |
| 249 | struct pevent_function_handler; |
| 250 | |
| 251 | struct print_arg_func { |
| 252 | struct pevent_function_handler *func; |
| 253 | struct print_arg *args; |
| 254 | }; |
| 255 | |
| 256 | enum print_arg_type { |
| 257 | PRINT_NULL, |
| 258 | PRINT_ATOM, |
| 259 | PRINT_FIELD, |
| 260 | PRINT_FLAGS, |
| 261 | PRINT_SYMBOL, |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 262 | PRINT_HEX, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 263 | PRINT_TYPE, |
| 264 | PRINT_STRING, |
| 265 | PRINT_BSTRING, |
| 266 | PRINT_DYNAMIC_ARRAY, |
| 267 | PRINT_OP, |
| 268 | PRINT_FUNC, |
| 269 | }; |
| 270 | |
| 271 | struct print_arg { |
| 272 | struct print_arg *next; |
| 273 | enum print_arg_type type; |
| 274 | union { |
| 275 | struct print_arg_atom atom; |
| 276 | struct print_arg_field field; |
| 277 | struct print_arg_typecast typecast; |
| 278 | struct print_arg_flags flags; |
| 279 | struct print_arg_symbol symbol; |
Namhyung Kim | e080e6f | 2012-06-27 09:41:41 +0900 | [diff] [blame] | 280 | struct print_arg_hex hex; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 281 | struct print_arg_func func; |
| 282 | struct print_arg_string string; |
| 283 | struct print_arg_op op; |
| 284 | struct print_arg_dynarray dynarray; |
| 285 | }; |
| 286 | }; |
| 287 | |
| 288 | struct print_fmt { |
| 289 | char *format; |
| 290 | struct print_arg *args; |
| 291 | }; |
| 292 | |
| 293 | struct event_format { |
| 294 | struct pevent *pevent; |
| 295 | char *name; |
| 296 | int id; |
| 297 | int flags; |
| 298 | struct format format; |
| 299 | struct print_fmt print_fmt; |
| 300 | char *system; |
| 301 | pevent_event_handler_func handler; |
| 302 | void *context; |
| 303 | }; |
| 304 | |
| 305 | enum { |
| 306 | EVENT_FL_ISFTRACE = 0x01, |
| 307 | EVENT_FL_ISPRINT = 0x02, |
| 308 | EVENT_FL_ISBPRINT = 0x04, |
| 309 | EVENT_FL_ISFUNCENT = 0x10, |
| 310 | EVENT_FL_ISFUNCRET = 0x20, |
Steven Rostedt | c6c2b96 | 2013-11-01 17:53:59 -0400 | [diff] [blame^] | 311 | EVENT_FL_NOHANDLE = 0x40, |
| 312 | EVENT_FL_PRINTRAW = 0x80, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 313 | |
| 314 | EVENT_FL_FAILED = 0x80000000 |
| 315 | }; |
| 316 | |
| 317 | enum event_sort_type { |
| 318 | EVENT_SORT_ID, |
| 319 | EVENT_SORT_NAME, |
| 320 | EVENT_SORT_SYSTEM, |
| 321 | }; |
| 322 | |
| 323 | enum event_type { |
| 324 | EVENT_ERROR, |
| 325 | EVENT_NONE, |
| 326 | EVENT_SPACE, |
| 327 | EVENT_NEWLINE, |
| 328 | EVENT_OP, |
| 329 | EVENT_DELIM, |
| 330 | EVENT_ITEM, |
| 331 | EVENT_DQUOTE, |
| 332 | EVENT_SQUOTE, |
| 333 | }; |
| 334 | |
| 335 | typedef unsigned long long (*pevent_func_handler)(struct trace_seq *s, |
| 336 | unsigned long long *args); |
| 337 | |
| 338 | enum pevent_func_arg_type { |
| 339 | PEVENT_FUNC_ARG_VOID, |
| 340 | PEVENT_FUNC_ARG_INT, |
| 341 | PEVENT_FUNC_ARG_LONG, |
| 342 | PEVENT_FUNC_ARG_STRING, |
| 343 | PEVENT_FUNC_ARG_PTR, |
| 344 | PEVENT_FUNC_ARG_MAX_TYPES |
| 345 | }; |
| 346 | |
Steven Rostedt | 4dc1024 | 2012-04-06 00:47:57 +0200 | [diff] [blame] | 347 | enum pevent_flag { |
| 348 | PEVENT_NSEC_OUTPUT = 1, /* output in NSECS */ |
| 349 | }; |
| 350 | |
Namhyung Kim | 2f197b9 | 2012-08-22 16:00:30 +0900 | [diff] [blame] | 351 | #define PEVENT_ERRORS \ |
| 352 | _PE(MEM_ALLOC_FAILED, "failed to allocate memory"), \ |
| 353 | _PE(PARSE_EVENT_FAILED, "failed to parse event"), \ |
| 354 | _PE(READ_ID_FAILED, "failed to read event id"), \ |
| 355 | _PE(READ_FORMAT_FAILED, "failed to read event format"), \ |
| 356 | _PE(READ_PRINT_FAILED, "failed to read event print fmt"), \ |
Namhyung Kim | 67ed939 | 2012-09-07 11:49:47 +0900 | [diff] [blame] | 357 | _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\ |
| 358 | _PE(INVALID_ARG_TYPE, "invalid argument type") |
Namhyung Kim | 2f197b9 | 2012-08-22 16:00:30 +0900 | [diff] [blame] | 359 | |
| 360 | #undef _PE |
| 361 | #define _PE(__code, __str) PEVENT_ERRNO__ ## __code |
Namhyung Kim | bffddff | 2012-08-22 16:00:29 +0900 | [diff] [blame] | 362 | enum pevent_errno { |
| 363 | PEVENT_ERRNO__SUCCESS = 0, |
| 364 | |
| 365 | /* |
| 366 | * Choose an arbitrary negative big number not to clash with standard |
| 367 | * errno since SUS requires the errno has distinct positive values. |
| 368 | * See 'Issue 6' in the link below. |
| 369 | * |
| 370 | * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html |
| 371 | */ |
| 372 | __PEVENT_ERRNO__START = -100000, |
| 373 | |
Namhyung Kim | 2f197b9 | 2012-08-22 16:00:30 +0900 | [diff] [blame] | 374 | PEVENT_ERRORS, |
Namhyung Kim | bffddff | 2012-08-22 16:00:29 +0900 | [diff] [blame] | 375 | |
| 376 | __PEVENT_ERRNO__END, |
| 377 | }; |
Namhyung Kim | 2f197b9 | 2012-08-22 16:00:30 +0900 | [diff] [blame] | 378 | #undef _PE |
Namhyung Kim | bffddff | 2012-08-22 16:00:29 +0900 | [diff] [blame] | 379 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 380 | struct cmdline; |
| 381 | struct cmdline_list; |
| 382 | struct func_map; |
| 383 | struct func_list; |
| 384 | struct event_handler; |
| 385 | |
| 386 | struct pevent { |
| 387 | int ref_count; |
| 388 | |
| 389 | int header_page_ts_offset; |
| 390 | int header_page_ts_size; |
| 391 | int header_page_size_offset; |
| 392 | int header_page_size_size; |
| 393 | int header_page_data_offset; |
| 394 | int header_page_data_size; |
| 395 | int header_page_overwrite; |
| 396 | |
| 397 | int file_bigendian; |
| 398 | int host_bigendian; |
| 399 | |
| 400 | int latency_format; |
| 401 | |
| 402 | int old_format; |
| 403 | |
| 404 | int cpus; |
| 405 | int long_size; |
Namhyung Kim | 012ac69 | 2013-06-04 14:20:20 +0900 | [diff] [blame] | 406 | int page_size; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 407 | |
| 408 | struct cmdline *cmdlines; |
| 409 | struct cmdline_list *cmdlist; |
| 410 | int cmdline_count; |
| 411 | |
| 412 | struct func_map *func_map; |
| 413 | struct func_list *funclist; |
| 414 | unsigned int func_count; |
| 415 | |
| 416 | struct printk_map *printk_map; |
| 417 | struct printk_list *printklist; |
| 418 | unsigned int printk_count; |
| 419 | |
Steven Rostedt | 4dc1024 | 2012-04-06 00:47:57 +0200 | [diff] [blame] | 420 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 421 | struct event_format **events; |
| 422 | int nr_events; |
| 423 | struct event_format **sort_events; |
| 424 | enum event_sort_type last_type; |
| 425 | |
| 426 | int type_offset; |
| 427 | int type_size; |
| 428 | |
| 429 | int pid_offset; |
| 430 | int pid_size; |
| 431 | |
| 432 | int pc_offset; |
| 433 | int pc_size; |
| 434 | |
| 435 | int flags_offset; |
| 436 | int flags_size; |
| 437 | |
| 438 | int ld_offset; |
| 439 | int ld_size; |
| 440 | |
| 441 | int print_raw; |
| 442 | |
| 443 | int test_filters; |
| 444 | |
Steven Rostedt | 4dc1024 | 2012-04-06 00:47:57 +0200 | [diff] [blame] | 445 | int flags; |
| 446 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 447 | struct format_field *bprint_ip_field; |
| 448 | struct format_field *bprint_fmt_field; |
| 449 | struct format_field *bprint_buf_field; |
| 450 | |
| 451 | struct event_handler *handlers; |
| 452 | struct pevent_function_handler *func_handlers; |
| 453 | |
| 454 | /* cache */ |
| 455 | struct event_format *last_event; |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 456 | |
| 457 | char *trace_clock; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 458 | }; |
| 459 | |
Steven Rostedt | 4dc1024 | 2012-04-06 00:47:57 +0200 | [diff] [blame] | 460 | static inline void pevent_set_flag(struct pevent *pevent, int flag) |
| 461 | { |
| 462 | pevent->flags |= flag; |
| 463 | } |
| 464 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 465 | static inline unsigned short |
| 466 | __data2host2(struct pevent *pevent, unsigned short data) |
| 467 | { |
| 468 | unsigned short swap; |
| 469 | |
| 470 | if (pevent->host_bigendian == pevent->file_bigendian) |
| 471 | return data; |
| 472 | |
| 473 | swap = ((data & 0xffULL) << 8) | |
| 474 | ((data & (0xffULL << 8)) >> 8); |
| 475 | |
| 476 | return swap; |
| 477 | } |
| 478 | |
| 479 | static inline unsigned int |
| 480 | __data2host4(struct pevent *pevent, unsigned int data) |
| 481 | { |
| 482 | unsigned int swap; |
| 483 | |
| 484 | if (pevent->host_bigendian == pevent->file_bigendian) |
| 485 | return data; |
| 486 | |
| 487 | swap = ((data & 0xffULL) << 24) | |
| 488 | ((data & (0xffULL << 8)) << 8) | |
| 489 | ((data & (0xffULL << 16)) >> 8) | |
| 490 | ((data & (0xffULL << 24)) >> 24); |
| 491 | |
| 492 | return swap; |
| 493 | } |
| 494 | |
| 495 | static inline unsigned long long |
| 496 | __data2host8(struct pevent *pevent, unsigned long long data) |
| 497 | { |
| 498 | unsigned long long swap; |
| 499 | |
| 500 | if (pevent->host_bigendian == pevent->file_bigendian) |
| 501 | return data; |
| 502 | |
| 503 | swap = ((data & 0xffULL) << 56) | |
| 504 | ((data & (0xffULL << 8)) << 40) | |
| 505 | ((data & (0xffULL << 16)) << 24) | |
| 506 | ((data & (0xffULL << 24)) << 8) | |
| 507 | ((data & (0xffULL << 32)) >> 8) | |
| 508 | ((data & (0xffULL << 40)) >> 24) | |
| 509 | ((data & (0xffULL << 48)) >> 40) | |
| 510 | ((data & (0xffULL << 56)) >> 56); |
| 511 | |
| 512 | return swap; |
| 513 | } |
| 514 | |
| 515 | #define data2host2(pevent, ptr) __data2host2(pevent, *(unsigned short *)(ptr)) |
| 516 | #define data2host4(pevent, ptr) __data2host4(pevent, *(unsigned int *)(ptr)) |
| 517 | #define data2host8(pevent, ptr) \ |
| 518 | ({ \ |
| 519 | unsigned long long __val; \ |
| 520 | \ |
| 521 | memcpy(&__val, (ptr), sizeof(unsigned long long)); \ |
| 522 | __data2host8(pevent, __val); \ |
| 523 | }) |
| 524 | |
| 525 | /* taken from kernel/trace/trace.h */ |
| 526 | enum trace_flag_type { |
| 527 | TRACE_FLAG_IRQS_OFF = 0x01, |
| 528 | TRACE_FLAG_IRQS_NOSUPPORT = 0x02, |
| 529 | TRACE_FLAG_NEED_RESCHED = 0x04, |
| 530 | TRACE_FLAG_HARDIRQ = 0x08, |
| 531 | TRACE_FLAG_SOFTIRQ = 0x10, |
| 532 | }; |
| 533 | |
| 534 | int pevent_register_comm(struct pevent *pevent, const char *comm, int pid); |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 535 | void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 536 | int pevent_register_function(struct pevent *pevent, char *name, |
| 537 | unsigned long long addr, char *mod); |
Steven Rostedt (Red Hat) | 18900af | 2013-11-01 17:53:54 -0400 | [diff] [blame] | 538 | int pevent_register_print_string(struct pevent *pevent, const char *fmt, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 539 | unsigned long long addr); |
| 540 | int pevent_pid_is_registered(struct pevent *pevent, int pid); |
| 541 | |
| 542 | void pevent_print_event(struct pevent *pevent, struct trace_seq *s, |
Yoshihiro YUNOMAE | 1b372ca | 2013-11-01 17:53:53 -0400 | [diff] [blame] | 543 | struct pevent_record *record, bool use_trace_clock); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 544 | |
| 545 | int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size, |
| 546 | int long_size); |
| 547 | |
Namhyung Kim | bffddff | 2012-08-22 16:00:29 +0900 | [diff] [blame] | 548 | enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf, |
| 549 | unsigned long size, const char *sys); |
Arnaldo Carvalho de Melo | 2b29175 | 2012-09-18 11:13:15 -0300 | [diff] [blame] | 550 | enum pevent_errno pevent_parse_format(struct event_format **eventp, const char *buf, |
| 551 | unsigned long size, const char *sys); |
| 552 | void pevent_free_format(struct event_format *event); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 553 | |
| 554 | void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event, |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 555 | const char *name, struct pevent_record *record, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 556 | int *len, int err); |
| 557 | |
| 558 | int pevent_get_field_val(struct trace_seq *s, struct event_format *event, |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 559 | const char *name, struct pevent_record *record, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 560 | unsigned long long *val, int err); |
| 561 | int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event, |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 562 | const char *name, struct pevent_record *record, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 563 | unsigned long long *val, int err); |
| 564 | int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event, |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 565 | const char *name, struct pevent_record *record, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 566 | unsigned long long *val, int err); |
| 567 | |
| 568 | int pevent_print_num_field(struct trace_seq *s, const char *fmt, |
| 569 | struct event_format *event, const char *name, |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 570 | struct pevent_record *record, int err); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 571 | |
Namhyung Kim | 79d5adf | 2013-06-04 14:20:18 +0900 | [diff] [blame] | 572 | int pevent_register_event_handler(struct pevent *pevent, int id, |
| 573 | const char *sys_name, const char *event_name, |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 574 | pevent_event_handler_func func, void *context); |
| 575 | int pevent_register_print_function(struct pevent *pevent, |
| 576 | pevent_func_handler func, |
| 577 | enum pevent_func_arg_type ret_type, |
| 578 | char *name, ...); |
| 579 | |
| 580 | struct format_field *pevent_find_common_field(struct event_format *event, const char *name); |
| 581 | struct format_field *pevent_find_field(struct event_format *event, const char *name); |
| 582 | struct format_field *pevent_find_any_field(struct event_format *event, const char *name); |
| 583 | |
| 584 | const char *pevent_find_function(struct pevent *pevent, unsigned long long addr); |
| 585 | unsigned long long |
| 586 | pevent_find_function_address(struct pevent *pevent, unsigned long long addr); |
| 587 | unsigned long long pevent_read_number(struct pevent *pevent, const void *ptr, int size); |
| 588 | int pevent_read_number_field(struct format_field *field, const void *data, |
| 589 | unsigned long long *value); |
| 590 | |
| 591 | struct event_format *pevent_find_event(struct pevent *pevent, int id); |
| 592 | |
| 593 | struct event_format * |
| 594 | pevent_find_event_by_name(struct pevent *pevent, const char *sys, const char *name); |
| 595 | |
| 596 | void pevent_data_lat_fmt(struct pevent *pevent, |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 597 | struct trace_seq *s, struct pevent_record *record); |
| 598 | int pevent_data_type(struct pevent *pevent, struct pevent_record *rec); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 599 | struct event_format *pevent_data_event_from_type(struct pevent *pevent, int type); |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 600 | int pevent_data_pid(struct pevent *pevent, struct pevent_record *rec); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 601 | const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid); |
| 602 | void pevent_event_info(struct trace_seq *s, struct event_format *event, |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 603 | struct pevent_record *record); |
Namhyung Kim | 2f197b9 | 2012-08-22 16:00:30 +0900 | [diff] [blame] | 604 | int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum, |
| 605 | char *buf, size_t buflen); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 606 | |
| 607 | struct event_format **pevent_list_events(struct pevent *pevent, enum event_sort_type); |
| 608 | struct format_field **pevent_event_common_fields(struct event_format *event); |
| 609 | struct format_field **pevent_event_fields(struct event_format *event); |
| 610 | |
| 611 | static inline int pevent_get_cpus(struct pevent *pevent) |
| 612 | { |
| 613 | return pevent->cpus; |
| 614 | } |
| 615 | |
| 616 | static inline void pevent_set_cpus(struct pevent *pevent, int cpus) |
| 617 | { |
| 618 | pevent->cpus = cpus; |
| 619 | } |
| 620 | |
| 621 | static inline int pevent_get_long_size(struct pevent *pevent) |
| 622 | { |
| 623 | return pevent->long_size; |
| 624 | } |
| 625 | |
| 626 | static inline void pevent_set_long_size(struct pevent *pevent, int long_size) |
| 627 | { |
| 628 | pevent->long_size = long_size; |
| 629 | } |
| 630 | |
Namhyung Kim | 012ac69 | 2013-06-04 14:20:20 +0900 | [diff] [blame] | 631 | static inline int pevent_get_page_size(struct pevent *pevent) |
| 632 | { |
| 633 | return pevent->page_size; |
| 634 | } |
| 635 | |
| 636 | static inline void pevent_set_page_size(struct pevent *pevent, int _page_size) |
| 637 | { |
| 638 | pevent->page_size = _page_size; |
| 639 | } |
| 640 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 641 | static inline int pevent_is_file_bigendian(struct pevent *pevent) |
| 642 | { |
| 643 | return pevent->file_bigendian; |
| 644 | } |
| 645 | |
| 646 | static inline void pevent_set_file_bigendian(struct pevent *pevent, int endian) |
| 647 | { |
| 648 | pevent->file_bigendian = endian; |
| 649 | } |
| 650 | |
| 651 | static inline int pevent_is_host_bigendian(struct pevent *pevent) |
| 652 | { |
| 653 | return pevent->host_bigendian; |
| 654 | } |
| 655 | |
| 656 | static inline void pevent_set_host_bigendian(struct pevent *pevent, int endian) |
| 657 | { |
| 658 | pevent->host_bigendian = endian; |
| 659 | } |
| 660 | |
| 661 | static inline int pevent_is_latency_format(struct pevent *pevent) |
| 662 | { |
| 663 | return pevent->latency_format; |
| 664 | } |
| 665 | |
| 666 | static inline void pevent_set_latency_format(struct pevent *pevent, int lat) |
| 667 | { |
| 668 | pevent->latency_format = lat; |
| 669 | } |
| 670 | |
| 671 | struct pevent *pevent_alloc(void); |
| 672 | void pevent_free(struct pevent *pevent); |
| 673 | void pevent_ref(struct pevent *pevent); |
| 674 | void pevent_unref(struct pevent *pevent); |
| 675 | |
| 676 | /* access to the internal parser */ |
| 677 | void pevent_buffer_init(const char *buf, unsigned long long size); |
| 678 | enum event_type pevent_read_token(char **tok); |
| 679 | void pevent_free_token(char *token); |
| 680 | int pevent_peek_char(void); |
| 681 | const char *pevent_get_input_buf(void); |
| 682 | unsigned long long pevent_get_input_buf_ptr(void); |
| 683 | |
| 684 | /* for debugging */ |
| 685 | void pevent_print_funcs(struct pevent *pevent); |
| 686 | void pevent_print_printk(struct pevent *pevent); |
| 687 | |
| 688 | /* ----------------------- filtering ----------------------- */ |
| 689 | |
| 690 | enum filter_boolean_type { |
| 691 | FILTER_FALSE, |
| 692 | FILTER_TRUE, |
| 693 | }; |
| 694 | |
| 695 | enum filter_op_type { |
| 696 | FILTER_OP_AND = 1, |
| 697 | FILTER_OP_OR, |
| 698 | FILTER_OP_NOT, |
| 699 | }; |
| 700 | |
| 701 | enum filter_cmp_type { |
| 702 | FILTER_CMP_NONE, |
| 703 | FILTER_CMP_EQ, |
| 704 | FILTER_CMP_NE, |
| 705 | FILTER_CMP_GT, |
| 706 | FILTER_CMP_LT, |
| 707 | FILTER_CMP_GE, |
| 708 | FILTER_CMP_LE, |
| 709 | FILTER_CMP_MATCH, |
| 710 | FILTER_CMP_NOT_MATCH, |
| 711 | FILTER_CMP_REGEX, |
| 712 | FILTER_CMP_NOT_REGEX, |
| 713 | }; |
| 714 | |
| 715 | enum filter_exp_type { |
| 716 | FILTER_EXP_NONE, |
| 717 | FILTER_EXP_ADD, |
| 718 | FILTER_EXP_SUB, |
| 719 | FILTER_EXP_MUL, |
| 720 | FILTER_EXP_DIV, |
| 721 | FILTER_EXP_MOD, |
| 722 | FILTER_EXP_RSHIFT, |
| 723 | FILTER_EXP_LSHIFT, |
| 724 | FILTER_EXP_AND, |
| 725 | FILTER_EXP_OR, |
| 726 | FILTER_EXP_XOR, |
| 727 | FILTER_EXP_NOT, |
| 728 | }; |
| 729 | |
| 730 | enum filter_arg_type { |
| 731 | FILTER_ARG_NONE, |
| 732 | FILTER_ARG_BOOLEAN, |
| 733 | FILTER_ARG_VALUE, |
| 734 | FILTER_ARG_FIELD, |
| 735 | FILTER_ARG_EXP, |
| 736 | FILTER_ARG_OP, |
| 737 | FILTER_ARG_NUM, |
| 738 | FILTER_ARG_STR, |
| 739 | }; |
| 740 | |
| 741 | enum filter_value_type { |
| 742 | FILTER_NUMBER, |
| 743 | FILTER_STRING, |
| 744 | FILTER_CHAR |
| 745 | }; |
| 746 | |
| 747 | struct fliter_arg; |
| 748 | |
| 749 | struct filter_arg_boolean { |
| 750 | enum filter_boolean_type value; |
| 751 | }; |
| 752 | |
| 753 | struct filter_arg_field { |
| 754 | struct format_field *field; |
| 755 | }; |
| 756 | |
| 757 | struct filter_arg_value { |
| 758 | enum filter_value_type type; |
| 759 | union { |
| 760 | char *str; |
| 761 | unsigned long long val; |
| 762 | }; |
| 763 | }; |
| 764 | |
| 765 | struct filter_arg_op { |
| 766 | enum filter_op_type type; |
| 767 | struct filter_arg *left; |
| 768 | struct filter_arg *right; |
| 769 | }; |
| 770 | |
| 771 | struct filter_arg_exp { |
| 772 | enum filter_exp_type type; |
| 773 | struct filter_arg *left; |
| 774 | struct filter_arg *right; |
| 775 | }; |
| 776 | |
| 777 | struct filter_arg_num { |
| 778 | enum filter_cmp_type type; |
| 779 | struct filter_arg *left; |
| 780 | struct filter_arg *right; |
| 781 | }; |
| 782 | |
| 783 | struct filter_arg_str { |
| 784 | enum filter_cmp_type type; |
| 785 | struct format_field *field; |
| 786 | char *val; |
| 787 | char *buffer; |
| 788 | regex_t reg; |
| 789 | }; |
| 790 | |
| 791 | struct filter_arg { |
| 792 | enum filter_arg_type type; |
| 793 | union { |
Steven Rostedt | 668fe01 | 2012-04-06 00:47:55 +0200 | [diff] [blame] | 794 | struct filter_arg_boolean boolean; |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 795 | struct filter_arg_field field; |
| 796 | struct filter_arg_value value; |
| 797 | struct filter_arg_op op; |
| 798 | struct filter_arg_exp exp; |
| 799 | struct filter_arg_num num; |
| 800 | struct filter_arg_str str; |
| 801 | }; |
| 802 | }; |
| 803 | |
| 804 | struct filter_type { |
| 805 | int event_id; |
| 806 | struct event_format *event; |
| 807 | struct filter_arg *filter; |
| 808 | }; |
| 809 | |
| 810 | struct event_filter { |
| 811 | struct pevent *pevent; |
| 812 | int filters; |
| 813 | struct filter_type *event_filters; |
| 814 | }; |
| 815 | |
| 816 | struct event_filter *pevent_filter_alloc(struct pevent *pevent); |
| 817 | |
| 818 | #define FILTER_NONE -2 |
| 819 | #define FILTER_NOEXIST -1 |
| 820 | #define FILTER_MISS 0 |
| 821 | #define FILTER_MATCH 1 |
| 822 | |
| 823 | enum filter_trivial_type { |
| 824 | FILTER_TRIVIAL_FALSE, |
| 825 | FILTER_TRIVIAL_TRUE, |
| 826 | FILTER_TRIVIAL_BOTH, |
| 827 | }; |
| 828 | |
| 829 | int pevent_filter_add_filter_str(struct event_filter *filter, |
| 830 | const char *filter_str, |
| 831 | char **error_str); |
| 832 | |
| 833 | |
| 834 | int pevent_filter_match(struct event_filter *filter, |
Steven Rostedt | 1c69818 | 2012-04-06 00:48:06 +0200 | [diff] [blame] | 835 | struct pevent_record *record); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 836 | |
| 837 | int pevent_event_filtered(struct event_filter *filter, |
| 838 | int event_id); |
| 839 | |
| 840 | void pevent_filter_reset(struct event_filter *filter); |
| 841 | |
| 842 | void pevent_filter_clear_trivial(struct event_filter *filter, |
| 843 | enum filter_trivial_type type); |
| 844 | |
| 845 | void pevent_filter_free(struct event_filter *filter); |
| 846 | |
| 847 | char *pevent_filter_make_string(struct event_filter *filter, int event_id); |
| 848 | |
| 849 | int pevent_filter_remove_event(struct event_filter *filter, |
| 850 | int event_id); |
| 851 | |
| 852 | int pevent_filter_event_has_trivial(struct event_filter *filter, |
| 853 | int event_id, |
| 854 | enum filter_trivial_type type); |
| 855 | |
| 856 | int pevent_filter_copy(struct event_filter *dest, struct event_filter *source); |
| 857 | |
| 858 | int pevent_update_trivial(struct event_filter *dest, struct event_filter *source, |
| 859 | enum filter_trivial_type type); |
| 860 | |
| 861 | int pevent_filter_compare(struct event_filter *filter1, struct event_filter *filter2); |
| 862 | |
| 863 | #endif /* _PARSE_EVENTS_H */ |