blob: 9ab6367f2fe92299461555d3f78b87872f8bf894 [file] [log] [blame]
Steven Rostedtf7d82352012-04-06 00:47:53 +02001/*
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 Stanley7b9f6b42012-09-07 16:32:46 -040016 * License along with this program; if not, see <http://www.gnu.org/licenses>
Steven Rostedtf7d82352012-04-06 00:47:53 +020017 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */
20#ifndef _PARSE_EVENTS_H
21#define _PARSE_EVENTS_H
22
Yoshihiro YUNOMAE1b372ca2013-11-01 17:53:53 -040023#include <stdbool.h>
Steven Rostedtf7d82352012-04-06 00:47:53 +020024#include <stdarg.h>
25#include <regex.h>
26
Irina Tirdea1d037ca2012-09-11 01:15:03 +030027#ifndef __maybe_unused
28#define __maybe_unused __attribute__((unused))
Steven Rostedtf7d82352012-04-06 00:47:53 +020029#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 Rostedt1c698182012-04-06 00:48:06 +020042struct pevent_record {
Steven Rostedtf7d82352012-04-06 00:47:53 +020043 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 Rostedtff1a70e2012-08-23 11:22:01 -040052 void *priv;
Steven Rostedtf7d82352012-04-06 00:47:53 +020053#if DEBUG_RECORD
Steven Rostedt1c698182012-04-06 00:48:06 +020054 struct pevent_record *prev;
55 struct pevent_record *next;
Steven Rostedtf7d82352012-04-06 00:47:53 +020056 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
65struct trace_seq {
66 char *buffer;
67 unsigned int buffer_size;
68 unsigned int len;
69 unsigned int readpos;
70};
71
72void trace_seq_init(struct trace_seq *s);
Namhyung Kim6a48aec2013-06-04 14:20:19 +090073void trace_seq_reset(struct trace_seq *s);
Steven Rostedtf7d82352012-04-06 00:47:53 +020074void trace_seq_destroy(struct trace_seq *s);
75
76extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
77 __attribute__ ((format (printf, 2, 3)));
78extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
79 __attribute__ ((format (printf, 2, 0)));
80
81extern int trace_seq_puts(struct trace_seq *s, const char *str);
82extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
83
84extern void trace_seq_terminate(struct trace_seq *s);
85
86extern int trace_seq_do_printf(struct trace_seq *s);
87
88
89/* ----------------------- pevent ----------------------- */
90
91struct pevent;
92struct event_format;
93
94typedef int (*pevent_event_handler_func)(struct trace_seq *s,
Steven Rostedt1c698182012-04-06 00:48:06 +020095 struct pevent_record *record,
Steven Rostedtf7d82352012-04-06 00:47:53 +020096 struct event_format *event,
97 void *context);
98
99typedef int (*pevent_plugin_load_func)(struct pevent *pevent);
100typedef int (*pevent_plugin_unload_func)(void);
101
102struct 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 Rostedtff1a70e2012-08-23 11:22:01 -0400110 void *priv;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200111 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
164enum 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 Rostedt668fe012012-04-06 00:47:55 +0200171 FIELD_IS_FLAG = 64,
172 FIELD_IS_SYMBOLIC = 128,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200173};
174
175struct 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
187struct format {
188 int nr_common;
189 int nr_fields;
190 struct format_field *common_fields;
191 struct format_field *fields;
192};
193
194struct print_arg_atom {
195 char *atom;
196};
197
198struct print_arg_string {
199 char *string;
200 int offset;
201};
202
203struct print_arg_field {
204 char *name;
205 struct format_field *field;
206};
207
208struct print_flag_sym {
209 struct print_flag_sym *next;
210 char *value;
211 char *str;
212};
213
214struct print_arg_typecast {
215 char *type;
216 struct print_arg *item;
217};
218
219struct print_arg_flags {
220 struct print_arg *field;
221 char *delim;
222 struct print_flag_sym *flags;
223};
224
225struct print_arg_symbol {
226 struct print_arg *field;
227 struct print_flag_sym *symbols;
228};
229
Namhyung Kime080e6f2012-06-27 09:41:41 +0900230struct print_arg_hex {
231 struct print_arg *field;
232 struct print_arg *size;
233};
234
Steven Rostedtf7d82352012-04-06 00:47:53 +0200235struct print_arg_dynarray {
236 struct format_field *field;
237 struct print_arg *index;
238};
239
240struct print_arg;
241
242struct print_arg_op {
243 char *op;
244 int prio;
245 struct print_arg *left;
246 struct print_arg *right;
247};
248
249struct pevent_function_handler;
250
251struct print_arg_func {
252 struct pevent_function_handler *func;
253 struct print_arg *args;
254};
255
256enum print_arg_type {
257 PRINT_NULL,
258 PRINT_ATOM,
259 PRINT_FIELD,
260 PRINT_FLAGS,
261 PRINT_SYMBOL,
Namhyung Kime080e6f2012-06-27 09:41:41 +0900262 PRINT_HEX,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200263 PRINT_TYPE,
264 PRINT_STRING,
265 PRINT_BSTRING,
266 PRINT_DYNAMIC_ARRAY,
267 PRINT_OP,
268 PRINT_FUNC,
269};
270
271struct 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 Kime080e6f2012-06-27 09:41:41 +0900280 struct print_arg_hex hex;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200281 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
288struct print_fmt {
289 char *format;
290 struct print_arg *args;
291};
292
293struct 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
305enum {
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,
311
312 EVENT_FL_FAILED = 0x80000000
313};
314
315enum event_sort_type {
316 EVENT_SORT_ID,
317 EVENT_SORT_NAME,
318 EVENT_SORT_SYSTEM,
319};
320
321enum event_type {
322 EVENT_ERROR,
323 EVENT_NONE,
324 EVENT_SPACE,
325 EVENT_NEWLINE,
326 EVENT_OP,
327 EVENT_DELIM,
328 EVENT_ITEM,
329 EVENT_DQUOTE,
330 EVENT_SQUOTE,
331};
332
333typedef unsigned long long (*pevent_func_handler)(struct trace_seq *s,
334 unsigned long long *args);
335
336enum pevent_func_arg_type {
337 PEVENT_FUNC_ARG_VOID,
338 PEVENT_FUNC_ARG_INT,
339 PEVENT_FUNC_ARG_LONG,
340 PEVENT_FUNC_ARG_STRING,
341 PEVENT_FUNC_ARG_PTR,
342 PEVENT_FUNC_ARG_MAX_TYPES
343};
344
Steven Rostedt4dc10242012-04-06 00:47:57 +0200345enum pevent_flag {
346 PEVENT_NSEC_OUTPUT = 1, /* output in NSECS */
347};
348
Namhyung Kim2f197b92012-08-22 16:00:30 +0900349#define PEVENT_ERRORS \
350 _PE(MEM_ALLOC_FAILED, "failed to allocate memory"), \
351 _PE(PARSE_EVENT_FAILED, "failed to parse event"), \
352 _PE(READ_ID_FAILED, "failed to read event id"), \
353 _PE(READ_FORMAT_FAILED, "failed to read event format"), \
354 _PE(READ_PRINT_FAILED, "failed to read event print fmt"), \
Namhyung Kim67ed9392012-09-07 11:49:47 +0900355 _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
356 _PE(INVALID_ARG_TYPE, "invalid argument type")
Namhyung Kim2f197b92012-08-22 16:00:30 +0900357
358#undef _PE
359#define _PE(__code, __str) PEVENT_ERRNO__ ## __code
Namhyung Kimbffddff2012-08-22 16:00:29 +0900360enum pevent_errno {
361 PEVENT_ERRNO__SUCCESS = 0,
362
363 /*
364 * Choose an arbitrary negative big number not to clash with standard
365 * errno since SUS requires the errno has distinct positive values.
366 * See 'Issue 6' in the link below.
367 *
368 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
369 */
370 __PEVENT_ERRNO__START = -100000,
371
Namhyung Kim2f197b92012-08-22 16:00:30 +0900372 PEVENT_ERRORS,
Namhyung Kimbffddff2012-08-22 16:00:29 +0900373
374 __PEVENT_ERRNO__END,
375};
Namhyung Kim2f197b92012-08-22 16:00:30 +0900376#undef _PE
Namhyung Kimbffddff2012-08-22 16:00:29 +0900377
Steven Rostedtf7d82352012-04-06 00:47:53 +0200378struct cmdline;
379struct cmdline_list;
380struct func_map;
381struct func_list;
382struct event_handler;
383
384struct pevent {
385 int ref_count;
386
387 int header_page_ts_offset;
388 int header_page_ts_size;
389 int header_page_size_offset;
390 int header_page_size_size;
391 int header_page_data_offset;
392 int header_page_data_size;
393 int header_page_overwrite;
394
395 int file_bigendian;
396 int host_bigendian;
397
398 int latency_format;
399
400 int old_format;
401
402 int cpus;
403 int long_size;
Namhyung Kim012ac692013-06-04 14:20:20 +0900404 int page_size;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200405
406 struct cmdline *cmdlines;
407 struct cmdline_list *cmdlist;
408 int cmdline_count;
409
410 struct func_map *func_map;
411 struct func_list *funclist;
412 unsigned int func_count;
413
414 struct printk_map *printk_map;
415 struct printk_list *printklist;
416 unsigned int printk_count;
417
Steven Rostedt4dc10242012-04-06 00:47:57 +0200418
Steven Rostedtf7d82352012-04-06 00:47:53 +0200419 struct event_format **events;
420 int nr_events;
421 struct event_format **sort_events;
422 enum event_sort_type last_type;
423
424 int type_offset;
425 int type_size;
426
427 int pid_offset;
428 int pid_size;
429
430 int pc_offset;
431 int pc_size;
432
433 int flags_offset;
434 int flags_size;
435
436 int ld_offset;
437 int ld_size;
438
439 int print_raw;
440
441 int test_filters;
442
Steven Rostedt4dc10242012-04-06 00:47:57 +0200443 int flags;
444
Steven Rostedtf7d82352012-04-06 00:47:53 +0200445 struct format_field *bprint_ip_field;
446 struct format_field *bprint_fmt_field;
447 struct format_field *bprint_buf_field;
448
449 struct event_handler *handlers;
450 struct pevent_function_handler *func_handlers;
451
452 /* cache */
453 struct event_format *last_event;
Yoshihiro YUNOMAE1b372ca2013-11-01 17:53:53 -0400454
455 char *trace_clock;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200456};
457
Steven Rostedt4dc10242012-04-06 00:47:57 +0200458static inline void pevent_set_flag(struct pevent *pevent, int flag)
459{
460 pevent->flags |= flag;
461}
462
Steven Rostedtf7d82352012-04-06 00:47:53 +0200463static inline unsigned short
464__data2host2(struct pevent *pevent, unsigned short data)
465{
466 unsigned short swap;
467
468 if (pevent->host_bigendian == pevent->file_bigendian)
469 return data;
470
471 swap = ((data & 0xffULL) << 8) |
472 ((data & (0xffULL << 8)) >> 8);
473
474 return swap;
475}
476
477static inline unsigned int
478__data2host4(struct pevent *pevent, unsigned int data)
479{
480 unsigned int swap;
481
482 if (pevent->host_bigendian == pevent->file_bigendian)
483 return data;
484
485 swap = ((data & 0xffULL) << 24) |
486 ((data & (0xffULL << 8)) << 8) |
487 ((data & (0xffULL << 16)) >> 8) |
488 ((data & (0xffULL << 24)) >> 24);
489
490 return swap;
491}
492
493static inline unsigned long long
494__data2host8(struct pevent *pevent, unsigned long long data)
495{
496 unsigned long long swap;
497
498 if (pevent->host_bigendian == pevent->file_bigendian)
499 return data;
500
501 swap = ((data & 0xffULL) << 56) |
502 ((data & (0xffULL << 8)) << 40) |
503 ((data & (0xffULL << 16)) << 24) |
504 ((data & (0xffULL << 24)) << 8) |
505 ((data & (0xffULL << 32)) >> 8) |
506 ((data & (0xffULL << 40)) >> 24) |
507 ((data & (0xffULL << 48)) >> 40) |
508 ((data & (0xffULL << 56)) >> 56);
509
510 return swap;
511}
512
513#define data2host2(pevent, ptr) __data2host2(pevent, *(unsigned short *)(ptr))
514#define data2host4(pevent, ptr) __data2host4(pevent, *(unsigned int *)(ptr))
515#define data2host8(pevent, ptr) \
516({ \
517 unsigned long long __val; \
518 \
519 memcpy(&__val, (ptr), sizeof(unsigned long long)); \
520 __data2host8(pevent, __val); \
521})
522
523/* taken from kernel/trace/trace.h */
524enum trace_flag_type {
525 TRACE_FLAG_IRQS_OFF = 0x01,
526 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
527 TRACE_FLAG_NEED_RESCHED = 0x04,
528 TRACE_FLAG_HARDIRQ = 0x08,
529 TRACE_FLAG_SOFTIRQ = 0x10,
530};
531
532int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);
Yoshihiro YUNOMAE1b372ca2013-11-01 17:53:53 -0400533void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200534int pevent_register_function(struct pevent *pevent, char *name,
535 unsigned long long addr, char *mod);
Steven Rostedt (Red Hat)18900af2013-11-01 17:53:54 -0400536int pevent_register_print_string(struct pevent *pevent, const char *fmt,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200537 unsigned long long addr);
538int pevent_pid_is_registered(struct pevent *pevent, int pid);
539
540void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
Yoshihiro YUNOMAE1b372ca2013-11-01 17:53:53 -0400541 struct pevent_record *record, bool use_trace_clock);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200542
543int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size,
544 int long_size);
545
Namhyung Kimbffddff2012-08-22 16:00:29 +0900546enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
547 unsigned long size, const char *sys);
Arnaldo Carvalho de Melo2b291752012-09-18 11:13:15 -0300548enum pevent_errno pevent_parse_format(struct event_format **eventp, const char *buf,
549 unsigned long size, const char *sys);
550void pevent_free_format(struct event_format *event);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200551
552void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
Steven Rostedt1c698182012-04-06 00:48:06 +0200553 const char *name, struct pevent_record *record,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200554 int *len, int err);
555
556int pevent_get_field_val(struct trace_seq *s, struct event_format *event,
Steven Rostedt1c698182012-04-06 00:48:06 +0200557 const char *name, struct pevent_record *record,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200558 unsigned long long *val, int err);
559int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
Steven Rostedt1c698182012-04-06 00:48:06 +0200560 const char *name, struct pevent_record *record,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200561 unsigned long long *val, int err);
562int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
Steven Rostedt1c698182012-04-06 00:48:06 +0200563 const char *name, struct pevent_record *record,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200564 unsigned long long *val, int err);
565
566int pevent_print_num_field(struct trace_seq *s, const char *fmt,
567 struct event_format *event, const char *name,
Steven Rostedt1c698182012-04-06 00:48:06 +0200568 struct pevent_record *record, int err);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200569
Namhyung Kim79d5adf2013-06-04 14:20:18 +0900570int pevent_register_event_handler(struct pevent *pevent, int id,
571 const char *sys_name, const char *event_name,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200572 pevent_event_handler_func func, void *context);
573int pevent_register_print_function(struct pevent *pevent,
574 pevent_func_handler func,
575 enum pevent_func_arg_type ret_type,
576 char *name, ...);
577
578struct format_field *pevent_find_common_field(struct event_format *event, const char *name);
579struct format_field *pevent_find_field(struct event_format *event, const char *name);
580struct format_field *pevent_find_any_field(struct event_format *event, const char *name);
581
582const char *pevent_find_function(struct pevent *pevent, unsigned long long addr);
583unsigned long long
584pevent_find_function_address(struct pevent *pevent, unsigned long long addr);
585unsigned long long pevent_read_number(struct pevent *pevent, const void *ptr, int size);
586int pevent_read_number_field(struct format_field *field, const void *data,
587 unsigned long long *value);
588
589struct event_format *pevent_find_event(struct pevent *pevent, int id);
590
591struct event_format *
592pevent_find_event_by_name(struct pevent *pevent, const char *sys, const char *name);
593
594void pevent_data_lat_fmt(struct pevent *pevent,
Steven Rostedt1c698182012-04-06 00:48:06 +0200595 struct trace_seq *s, struct pevent_record *record);
596int pevent_data_type(struct pevent *pevent, struct pevent_record *rec);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200597struct event_format *pevent_data_event_from_type(struct pevent *pevent, int type);
Steven Rostedt1c698182012-04-06 00:48:06 +0200598int pevent_data_pid(struct pevent *pevent, struct pevent_record *rec);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200599const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid);
600void pevent_event_info(struct trace_seq *s, struct event_format *event,
Steven Rostedt1c698182012-04-06 00:48:06 +0200601 struct pevent_record *record);
Namhyung Kim2f197b92012-08-22 16:00:30 +0900602int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum,
603 char *buf, size_t buflen);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200604
605struct event_format **pevent_list_events(struct pevent *pevent, enum event_sort_type);
606struct format_field **pevent_event_common_fields(struct event_format *event);
607struct format_field **pevent_event_fields(struct event_format *event);
608
609static inline int pevent_get_cpus(struct pevent *pevent)
610{
611 return pevent->cpus;
612}
613
614static inline void pevent_set_cpus(struct pevent *pevent, int cpus)
615{
616 pevent->cpus = cpus;
617}
618
619static inline int pevent_get_long_size(struct pevent *pevent)
620{
621 return pevent->long_size;
622}
623
624static inline void pevent_set_long_size(struct pevent *pevent, int long_size)
625{
626 pevent->long_size = long_size;
627}
628
Namhyung Kim012ac692013-06-04 14:20:20 +0900629static inline int pevent_get_page_size(struct pevent *pevent)
630{
631 return pevent->page_size;
632}
633
634static inline void pevent_set_page_size(struct pevent *pevent, int _page_size)
635{
636 pevent->page_size = _page_size;
637}
638
Steven Rostedtf7d82352012-04-06 00:47:53 +0200639static inline int pevent_is_file_bigendian(struct pevent *pevent)
640{
641 return pevent->file_bigendian;
642}
643
644static inline void pevent_set_file_bigendian(struct pevent *pevent, int endian)
645{
646 pevent->file_bigendian = endian;
647}
648
649static inline int pevent_is_host_bigendian(struct pevent *pevent)
650{
651 return pevent->host_bigendian;
652}
653
654static inline void pevent_set_host_bigendian(struct pevent *pevent, int endian)
655{
656 pevent->host_bigendian = endian;
657}
658
659static inline int pevent_is_latency_format(struct pevent *pevent)
660{
661 return pevent->latency_format;
662}
663
664static inline void pevent_set_latency_format(struct pevent *pevent, int lat)
665{
666 pevent->latency_format = lat;
667}
668
669struct pevent *pevent_alloc(void);
670void pevent_free(struct pevent *pevent);
671void pevent_ref(struct pevent *pevent);
672void pevent_unref(struct pevent *pevent);
673
674/* access to the internal parser */
675void pevent_buffer_init(const char *buf, unsigned long long size);
676enum event_type pevent_read_token(char **tok);
677void pevent_free_token(char *token);
678int pevent_peek_char(void);
679const char *pevent_get_input_buf(void);
680unsigned long long pevent_get_input_buf_ptr(void);
681
682/* for debugging */
683void pevent_print_funcs(struct pevent *pevent);
684void pevent_print_printk(struct pevent *pevent);
685
686/* ----------------------- filtering ----------------------- */
687
688enum filter_boolean_type {
689 FILTER_FALSE,
690 FILTER_TRUE,
691};
692
693enum filter_op_type {
694 FILTER_OP_AND = 1,
695 FILTER_OP_OR,
696 FILTER_OP_NOT,
697};
698
699enum filter_cmp_type {
700 FILTER_CMP_NONE,
701 FILTER_CMP_EQ,
702 FILTER_CMP_NE,
703 FILTER_CMP_GT,
704 FILTER_CMP_LT,
705 FILTER_CMP_GE,
706 FILTER_CMP_LE,
707 FILTER_CMP_MATCH,
708 FILTER_CMP_NOT_MATCH,
709 FILTER_CMP_REGEX,
710 FILTER_CMP_NOT_REGEX,
711};
712
713enum filter_exp_type {
714 FILTER_EXP_NONE,
715 FILTER_EXP_ADD,
716 FILTER_EXP_SUB,
717 FILTER_EXP_MUL,
718 FILTER_EXP_DIV,
719 FILTER_EXP_MOD,
720 FILTER_EXP_RSHIFT,
721 FILTER_EXP_LSHIFT,
722 FILTER_EXP_AND,
723 FILTER_EXP_OR,
724 FILTER_EXP_XOR,
725 FILTER_EXP_NOT,
726};
727
728enum filter_arg_type {
729 FILTER_ARG_NONE,
730 FILTER_ARG_BOOLEAN,
731 FILTER_ARG_VALUE,
732 FILTER_ARG_FIELD,
733 FILTER_ARG_EXP,
734 FILTER_ARG_OP,
735 FILTER_ARG_NUM,
736 FILTER_ARG_STR,
737};
738
739enum filter_value_type {
740 FILTER_NUMBER,
741 FILTER_STRING,
742 FILTER_CHAR
743};
744
745struct fliter_arg;
746
747struct filter_arg_boolean {
748 enum filter_boolean_type value;
749};
750
751struct filter_arg_field {
752 struct format_field *field;
753};
754
755struct filter_arg_value {
756 enum filter_value_type type;
757 union {
758 char *str;
759 unsigned long long val;
760 };
761};
762
763struct filter_arg_op {
764 enum filter_op_type type;
765 struct filter_arg *left;
766 struct filter_arg *right;
767};
768
769struct filter_arg_exp {
770 enum filter_exp_type type;
771 struct filter_arg *left;
772 struct filter_arg *right;
773};
774
775struct filter_arg_num {
776 enum filter_cmp_type type;
777 struct filter_arg *left;
778 struct filter_arg *right;
779};
780
781struct filter_arg_str {
782 enum filter_cmp_type type;
783 struct format_field *field;
784 char *val;
785 char *buffer;
786 regex_t reg;
787};
788
789struct filter_arg {
790 enum filter_arg_type type;
791 union {
Steven Rostedt668fe012012-04-06 00:47:55 +0200792 struct filter_arg_boolean boolean;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200793 struct filter_arg_field field;
794 struct filter_arg_value value;
795 struct filter_arg_op op;
796 struct filter_arg_exp exp;
797 struct filter_arg_num num;
798 struct filter_arg_str str;
799 };
800};
801
802struct filter_type {
803 int event_id;
804 struct event_format *event;
805 struct filter_arg *filter;
806};
807
808struct event_filter {
809 struct pevent *pevent;
810 int filters;
811 struct filter_type *event_filters;
812};
813
814struct event_filter *pevent_filter_alloc(struct pevent *pevent);
815
816#define FILTER_NONE -2
817#define FILTER_NOEXIST -1
818#define FILTER_MISS 0
819#define FILTER_MATCH 1
820
821enum filter_trivial_type {
822 FILTER_TRIVIAL_FALSE,
823 FILTER_TRIVIAL_TRUE,
824 FILTER_TRIVIAL_BOTH,
825};
826
827int pevent_filter_add_filter_str(struct event_filter *filter,
828 const char *filter_str,
829 char **error_str);
830
831
832int pevent_filter_match(struct event_filter *filter,
Steven Rostedt1c698182012-04-06 00:48:06 +0200833 struct pevent_record *record);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200834
835int pevent_event_filtered(struct event_filter *filter,
836 int event_id);
837
838void pevent_filter_reset(struct event_filter *filter);
839
840void pevent_filter_clear_trivial(struct event_filter *filter,
841 enum filter_trivial_type type);
842
843void pevent_filter_free(struct event_filter *filter);
844
845char *pevent_filter_make_string(struct event_filter *filter, int event_id);
846
847int pevent_filter_remove_event(struct event_filter *filter,
848 int event_id);
849
850int pevent_filter_event_has_trivial(struct event_filter *filter,
851 int event_id,
852 enum filter_trivial_type type);
853
854int pevent_filter_copy(struct event_filter *dest, struct event_filter *source);
855
856int pevent_update_trivial(struct event_filter *dest, struct event_filter *source,
857 enum filter_trivial_type type);
858
859int pevent_filter_compare(struct event_filter *filter1, struct event_filter *filter2);
860
861#endif /* _PARSE_EVENTS_H */