aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/traceevent/event-parse.h
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2012-04-05 18:47:53 -0400
committerFrederic Weisbecker <fweisbec@gmail.com>2012-04-25 06:28:28 -0400
commitf7d82350e597d76dc8765a55c7849843395728b0 (patch)
tree6e254dde9c6b30dc9f5dc4fb28d3eeec86382e32 /tools/lib/traceevent/event-parse.h
parent4ace73eef52c651b8f58415fb4476f4791c95e72 (diff)
tools/events: Add files to create libtraceevent.a
Copy over the files from trace-cmd to the Linux tools directory such that applications like perf and latencytrace can use the more advanced parsing code. Because some of the file names of perf conflict with trace-cmd file names, the trace-cmd files have been renamed as follows: parse-events.c ==> event-parse.c parse-events.h ==> event-parse.h utils.h ==> event-utils.h The files have been updated to handle the changes to the header files but other than that, they are identical to what was in the trace-cmd repository. The history of these files, including authorship is available at the git repo: git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git The Makefile was also copied over, but most of it was removed to focus on the parse-events code first. The parts of the Makefile for the plugins have also been removed, but will be added back when the plugin code is copied over as well. But that may be in its own separate directory. Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Arnaldo Carvalho de Melo <acme@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Arun Sharma <asharma@fb.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Diffstat (limited to 'tools/lib/traceevent/event-parse.h')
-rw-r--r--tools/lib/traceevent/event-parse.h806
1 files changed, 806 insertions, 0 deletions
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
new file mode 100644
index 000000000000..c32d7153a8d6
--- /dev/null
+++ b/tools/lib/traceevent/event-parse.h
@@ -0,0 +1,806 @@
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
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 */
21#ifndef _PARSE_EVENTS_H
22#define _PARSE_EVENTS_H
23
24#include <stdarg.h>
25#include <regex.h>
26
27#ifndef __unused
28#define __unused __attribute__ ((unused))
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
42struct record {
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 */
52 void *private;
53#if DEBUG_RECORD
54 struct record *prev;
55 struct record *next;
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
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);
73void trace_seq_destroy(struct trace_seq *s);
74
75extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
76 __attribute__ ((format (printf, 2, 3)));
77extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
78 __attribute__ ((format (printf, 2, 0)));
79
80extern int trace_seq_puts(struct trace_seq *s, const char *str);
81extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
82
83extern void trace_seq_terminate(struct trace_seq *s);
84
85extern int trace_seq_do_printf(struct trace_seq *s);
86
87
88/* ----------------------- pevent ----------------------- */
89
90struct pevent;
91struct event_format;
92
93typedef int (*pevent_event_handler_func)(struct trace_seq *s,
94 struct record *record,
95 struct event_format *event,
96 void *context);
97
98typedef int (*pevent_plugin_load_func)(struct pevent *pevent);
99typedef int (*pevent_plugin_unload_func)(void);
100
101struct plugin_option {
102 struct plugin_option *next;
103 void *handle;
104 char *file;
105 char *name;
106 char *plugin_alias;
107 char *description;
108 char *value;
109 void *private;
110 int set;
111};
112
113/*
114 * Plugin hooks that can be called:
115 *
116 * PEVENT_PLUGIN_LOADER: (required)
117 * The function name to initialized the plugin.
118 *
119 * int PEVENT_PLUGIN_LOADER(struct pevent *pevent)
120 *
121 * PEVENT_PLUGIN_UNLOADER: (optional)
122 * The function called just before unloading
123 *
124 * int PEVENT_PLUGIN_UNLOADER(void)
125 *
126 * PEVENT_PLUGIN_OPTIONS: (optional)
127 * Plugin options that can be set before loading
128 *
129 * struct plugin_option PEVENT_PLUGIN_OPTIONS[] = {
130 * {
131 * .name = "option-name",
132 * .plugin_alias = "overide-file-name", (optional)
133 * .description = "description of option to show users",
134 * },
135 * {
136 * .name = NULL,
137 * },
138 * };
139 *
140 * Array must end with .name = NULL;
141 *
142 *
143 * .plugin_alias is used to give a shorter name to access
144 * the vairable. Useful if a plugin handles more than one event.
145 *
146 * PEVENT_PLUGIN_ALIAS: (optional)
147 * The name to use for finding options (uses filename if not defined)
148 */
149#define PEVENT_PLUGIN_LOADER pevent_plugin_loader
150#define PEVENT_PLUGIN_UNLOADER pevent_plugin_unloader
151#define PEVENT_PLUGIN_OPTIONS pevent_plugin_options
152#define PEVENT_PLUGIN_ALIAS pevent_plugin_alias
153#define _MAKE_STR(x) #x
154#define MAKE_STR(x) _MAKE_STR(x)
155#define PEVENT_PLUGIN_LOADER_NAME MAKE_STR(PEVENT_PLUGIN_LOADER)
156#define PEVENT_PLUGIN_UNLOADER_NAME MAKE_STR(PEVENT_PLUGIN_UNLOADER)
157#define PEVENT_PLUGIN_OPTIONS_NAME MAKE_STR(PEVENT_PLUGIN_OPTIONS)
158#define PEVENT_PLUGIN_ALIAS_NAME MAKE_STR(PEVENT_PLUGIN_ALIAS)
159
160#define NSECS_PER_SEC 1000000000ULL
161#define NSECS_PER_USEC 1000ULL
162
163enum format_flags {
164 FIELD_IS_ARRAY = 1,
165 FIELD_IS_POINTER = 2,
166 FIELD_IS_SIGNED = 4,
167 FIELD_IS_STRING = 8,
168 FIELD_IS_DYNAMIC = 16,
169 FIELD_IS_LONG = 32,
170};
171
172struct format_field {
173 struct format_field *next;
174 struct event_format *event;
175 char *type;
176 char *name;
177 int offset;
178 int size;
179 unsigned int arraylen;
180 unsigned int elementsize;
181 unsigned long flags;
182};
183
184struct format {
185 int nr_common;
186 int nr_fields;
187 struct format_field *common_fields;
188 struct format_field *fields;
189};
190
191struct print_arg_atom {
192 char *atom;
193};
194
195struct print_arg_string {
196 char *string;
197 int offset;
198};
199
200struct print_arg_field {
201 char *name;
202 struct format_field *field;
203};
204
205struct print_flag_sym {
206 struct print_flag_sym *next;
207 char *value;
208 char *str;
209};
210
211struct print_arg_typecast {
212 char *type;
213 struct print_arg *item;
214};
215
216struct print_arg_flags {
217 struct print_arg *field;
218 char *delim;
219 struct print_flag_sym *flags;
220};
221
222struct print_arg_symbol {
223 struct print_arg *field;
224 struct print_flag_sym *symbols;
225};
226
227struct print_arg_dynarray {
228 struct format_field *field;
229 struct print_arg *index;
230};
231
232struct print_arg;
233
234struct print_arg_op {
235 char *op;
236 int prio;
237 struct print_arg *left;
238 struct print_arg *right;
239};
240
241struct pevent_function_handler;
242
243struct print_arg_func {
244 struct pevent_function_handler *func;
245 struct print_arg *args;
246};
247
248enum print_arg_type {
249 PRINT_NULL,
250 PRINT_ATOM,
251 PRINT_FIELD,
252 PRINT_FLAGS,
253 PRINT_SYMBOL,
254 PRINT_TYPE,
255 PRINT_STRING,
256 PRINT_BSTRING,
257 PRINT_DYNAMIC_ARRAY,
258 PRINT_OP,
259 PRINT_FUNC,
260};
261
262struct print_arg {
263 struct print_arg *next;
264 enum print_arg_type type;
265 union {
266 struct print_arg_atom atom;
267 struct print_arg_field field;
268 struct print_arg_typecast typecast;
269 struct print_arg_flags flags;
270 struct print_arg_symbol symbol;
271 struct print_arg_func func;
272 struct print_arg_string string;
273 struct print_arg_op op;
274 struct print_arg_dynarray dynarray;
275 };
276};
277
278struct print_fmt {
279 char *format;
280 struct print_arg *args;
281};
282
283struct event_format {
284 struct pevent *pevent;
285 char *name;
286 int id;
287 int flags;
288 struct format format;
289 struct print_fmt print_fmt;
290 char *system;
291 pevent_event_handler_func handler;
292 void *context;
293};
294
295enum {
296 EVENT_FL_ISFTRACE = 0x01,
297 EVENT_FL_ISPRINT = 0x02,
298 EVENT_FL_ISBPRINT = 0x04,
299 EVENT_FL_ISFUNCENT = 0x10,
300 EVENT_FL_ISFUNCRET = 0x20,
301
302 EVENT_FL_FAILED = 0x80000000
303};
304
305enum event_sort_type {
306 EVENT_SORT_ID,
307 EVENT_SORT_NAME,
308 EVENT_SORT_SYSTEM,
309};
310
311enum event_type {
312 EVENT_ERROR,
313 EVENT_NONE,
314 EVENT_SPACE,
315 EVENT_NEWLINE,
316 EVENT_OP,
317 EVENT_DELIM,
318 EVENT_ITEM,
319 EVENT_DQUOTE,
320 EVENT_SQUOTE,
321};
322
323typedef unsigned long long (*pevent_func_handler)(struct trace_seq *s,
324 unsigned long long *args);
325
326enum pevent_func_arg_type {
327 PEVENT_FUNC_ARG_VOID,
328 PEVENT_FUNC_ARG_INT,
329 PEVENT_FUNC_ARG_LONG,
330 PEVENT_FUNC_ARG_STRING,
331 PEVENT_FUNC_ARG_PTR,
332 PEVENT_FUNC_ARG_MAX_TYPES
333};
334
335struct cmdline;
336struct cmdline_list;
337struct func_map;
338struct func_list;
339struct event_handler;
340
341struct pevent {
342 int ref_count;
343
344 int header_page_ts_offset;
345 int header_page_ts_size;
346 int header_page_size_offset;
347 int header_page_size_size;
348 int header_page_data_offset;
349 int header_page_data_size;
350 int header_page_overwrite;
351
352 int file_bigendian;
353 int host_bigendian;
354
355 int latency_format;
356
357 int old_format;
358
359 int cpus;
360 int long_size;
361
362 struct cmdline *cmdlines;
363 struct cmdline_list *cmdlist;
364 int cmdline_count;
365
366 struct func_map *func_map;
367 struct func_list *funclist;
368 unsigned int func_count;
369
370 struct printk_map *printk_map;
371 struct printk_list *printklist;
372 unsigned int printk_count;
373
374 struct event_format **events;
375 int nr_events;
376 struct event_format **sort_events;
377 enum event_sort_type last_type;
378
379 int type_offset;
380 int type_size;
381
382 int pid_offset;
383 int pid_size;
384
385 int pc_offset;
386 int pc_size;
387
388 int flags_offset;
389 int flags_size;
390
391 int ld_offset;
392 int ld_size;
393
394 int print_raw;
395
396 int test_filters;
397
398 struct format_field *bprint_ip_field;
399 struct format_field *bprint_fmt_field;
400 struct format_field *bprint_buf_field;
401
402 struct event_handler *handlers;
403 struct pevent_function_handler *func_handlers;
404
405 /* cache */
406 struct event_format *last_event;
407};
408
409/* Can be overridden */
410void die(const char *fmt, ...);
411void *malloc_or_die(unsigned int size);
412void warning(const char *fmt, ...);
413void pr_stat(const char *fmt, ...);
414void vpr_stat(const char *fmt, va_list ap);
415
416/* Always available */
417void __die(const char *fmt, ...);
418void __warning(const char *fmt, ...);
419void __pr_stat(const char *fmt, ...);
420
421void __vdie(const char *fmt, ...);
422void __vwarning(const char *fmt, ...);
423void __vpr_stat(const char *fmt, ...);
424
425static inline unsigned short
426__data2host2(struct pevent *pevent, unsigned short data)
427{
428 unsigned short swap;
429
430 if (pevent->host_bigendian == pevent->file_bigendian)
431 return data;
432
433 swap = ((data & 0xffULL) << 8) |
434 ((data & (0xffULL << 8)) >> 8);
435
436 return swap;
437}
438
439static inline unsigned int
440__data2host4(struct pevent *pevent, unsigned int data)
441{
442 unsigned int swap;
443
444 if (pevent->host_bigendian == pevent->file_bigendian)
445 return data;
446
447 swap = ((data & 0xffULL) << 24) |
448 ((data & (0xffULL << 8)) << 8) |
449 ((data & (0xffULL << 16)) >> 8) |
450 ((data & (0xffULL << 24)) >> 24);
451
452 return swap;
453}
454
455static inline unsigned long long
456__data2host8(struct pevent *pevent, unsigned long long data)
457{
458 unsigned long long swap;
459
460 if (pevent->host_bigendian == pevent->file_bigendian)
461 return data;
462
463 swap = ((data & 0xffULL) << 56) |
464 ((data & (0xffULL << 8)) << 40) |
465 ((data & (0xffULL << 16)) << 24) |
466 ((data & (0xffULL << 24)) << 8) |
467 ((data & (0xffULL << 32)) >> 8) |
468 ((data & (0xffULL << 40)) >> 24) |
469 ((data & (0xffULL << 48)) >> 40) |
470 ((data & (0xffULL << 56)) >> 56);
471
472 return swap;
473}
474
475#define data2host2(pevent, ptr) __data2host2(pevent, *(unsigned short *)(ptr))
476#define data2host4(pevent, ptr) __data2host4(pevent, *(unsigned int *)(ptr))
477#define data2host8(pevent, ptr) \
478({ \
479 unsigned long long __val; \
480 \
481 memcpy(&__val, (ptr), sizeof(unsigned long long)); \
482 __data2host8(pevent, __val); \
483})
484
485/* taken from kernel/trace/trace.h */
486enum trace_flag_type {
487 TRACE_FLAG_IRQS_OFF = 0x01,
488 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
489 TRACE_FLAG_NEED_RESCHED = 0x04,
490 TRACE_FLAG_HARDIRQ = 0x08,
491 TRACE_FLAG_SOFTIRQ = 0x10,
492};
493
494int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);
495int pevent_register_function(struct pevent *pevent, char *name,
496 unsigned long long addr, char *mod);
497int pevent_register_print_string(struct pevent *pevent, char *fmt,
498 unsigned long long addr);
499int pevent_pid_is_registered(struct pevent *pevent, int pid);
500
501void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
502 struct record *record);
503
504int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size,
505 int long_size);
506
507int pevent_parse_event(struct pevent *pevent, const char *buf,
508 unsigned long size, const char *sys);
509
510void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
511 const char *name, struct record *record,
512 int *len, int err);
513
514int pevent_get_field_val(struct trace_seq *s, struct event_format *event,
515 const char *name, struct record *record,
516 unsigned long long *val, int err);
517int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
518 const char *name, struct record *record,
519 unsigned long long *val, int err);
520int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
521 const char *name, struct record *record,
522 unsigned long long *val, int err);
523
524int pevent_print_num_field(struct trace_seq *s, const char *fmt,
525 struct event_format *event, const char *name,
526 struct record *record, int err);
527
528int pevent_register_event_handler(struct pevent *pevent, int id, char *sys_name, char *event_name,
529 pevent_event_handler_func func, void *context);
530int pevent_register_print_function(struct pevent *pevent,
531 pevent_func_handler func,
532 enum pevent_func_arg_type ret_type,
533 char *name, ...);
534
535struct format_field *pevent_find_common_field(struct event_format *event, const char *name);
536struct format_field *pevent_find_field(struct event_format *event, const char *name);
537struct format_field *pevent_find_any_field(struct event_format *event, const char *name);
538
539const char *pevent_find_function(struct pevent *pevent, unsigned long long addr);
540unsigned long long
541pevent_find_function_address(struct pevent *pevent, unsigned long long addr);
542unsigned long long pevent_read_number(struct pevent *pevent, const void *ptr, int size);
543int pevent_read_number_field(struct format_field *field, const void *data,
544 unsigned long long *value);
545
546struct event_format *pevent_find_event(struct pevent *pevent, int id);
547
548struct event_format *
549pevent_find_event_by_name(struct pevent *pevent, const char *sys, const char *name);
550
551void pevent_data_lat_fmt(struct pevent *pevent,
552 struct trace_seq *s, struct record *record);
553int pevent_data_type(struct pevent *pevent, struct record *rec);
554struct event_format *pevent_data_event_from_type(struct pevent *pevent, int type);
555int pevent_data_pid(struct pevent *pevent, struct record *rec);
556const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid);
557void pevent_event_info(struct trace_seq *s, struct event_format *event,
558 struct record *record);
559
560struct event_format **pevent_list_events(struct pevent *pevent, enum event_sort_type);
561struct format_field **pevent_event_common_fields(struct event_format *event);
562struct format_field **pevent_event_fields(struct event_format *event);
563
564static inline int pevent_get_cpus(struct pevent *pevent)
565{
566 return pevent->cpus;
567}
568
569static inline void pevent_set_cpus(struct pevent *pevent, int cpus)
570{
571 pevent->cpus = cpus;
572}
573
574static inline int pevent_get_long_size(struct pevent *pevent)
575{
576 return pevent->long_size;
577}
578
579static inline void pevent_set_long_size(struct pevent *pevent, int long_size)
580{
581 pevent->long_size = long_size;
582}
583
584static inline int pevent_is_file_bigendian(struct pevent *pevent)
585{
586 return pevent->file_bigendian;
587}
588
589static inline void pevent_set_file_bigendian(struct pevent *pevent, int endian)
590{
591 pevent->file_bigendian = endian;
592}
593
594static inline int pevent_is_host_bigendian(struct pevent *pevent)
595{
596 return pevent->host_bigendian;
597}
598
599static inline void pevent_set_host_bigendian(struct pevent *pevent, int endian)
600{
601 pevent->host_bigendian = endian;
602}
603
604static inline int pevent_is_latency_format(struct pevent *pevent)
605{
606 return pevent->latency_format;
607}
608
609static inline void pevent_set_latency_format(struct pevent *pevent, int lat)
610{
611 pevent->latency_format = lat;
612}
613
614struct pevent *pevent_alloc(void);
615void pevent_free(struct pevent *pevent);
616void pevent_ref(struct pevent *pevent);
617void pevent_unref(struct pevent *pevent);
618
619/* access to the internal parser */
620void pevent_buffer_init(const char *buf, unsigned long long size);
621enum event_type pevent_read_token(char **tok);
622void pevent_free_token(char *token);
623int pevent_peek_char(void);
624const char *pevent_get_input_buf(void);
625unsigned long long pevent_get_input_buf_ptr(void);
626
627/* for debugging */
628void pevent_print_funcs(struct pevent *pevent);
629void pevent_print_printk(struct pevent *pevent);
630
631/* ----------------------- filtering ----------------------- */
632
633enum filter_boolean_type {
634 FILTER_FALSE,
635 FILTER_TRUE,
636};
637
638enum filter_op_type {
639 FILTER_OP_AND = 1,
640 FILTER_OP_OR,
641 FILTER_OP_NOT,
642};
643
644enum filter_cmp_type {
645 FILTER_CMP_NONE,
646 FILTER_CMP_EQ,
647 FILTER_CMP_NE,
648 FILTER_CMP_GT,
649 FILTER_CMP_LT,
650 FILTER_CMP_GE,
651 FILTER_CMP_LE,
652 FILTER_CMP_MATCH,
653 FILTER_CMP_NOT_MATCH,
654 FILTER_CMP_REGEX,
655 FILTER_CMP_NOT_REGEX,
656};
657
658enum filter_exp_type {
659 FILTER_EXP_NONE,
660 FILTER_EXP_ADD,
661 FILTER_EXP_SUB,
662 FILTER_EXP_MUL,
663 FILTER_EXP_DIV,
664 FILTER_EXP_MOD,
665 FILTER_EXP_RSHIFT,
666 FILTER_EXP_LSHIFT,
667 FILTER_EXP_AND,
668 FILTER_EXP_OR,
669 FILTER_EXP_XOR,
670 FILTER_EXP_NOT,
671};
672
673enum filter_arg_type {
674 FILTER_ARG_NONE,
675 FILTER_ARG_BOOLEAN,
676 FILTER_ARG_VALUE,
677 FILTER_ARG_FIELD,
678 FILTER_ARG_EXP,
679 FILTER_ARG_OP,
680 FILTER_ARG_NUM,
681 FILTER_ARG_STR,
682};
683
684enum filter_value_type {
685 FILTER_NUMBER,
686 FILTER_STRING,
687 FILTER_CHAR
688};
689
690struct fliter_arg;
691
692struct filter_arg_boolean {
693 enum filter_boolean_type value;
694};
695
696struct filter_arg_field {
697 struct format_field *field;
698};
699
700struct filter_arg_value {
701 enum filter_value_type type;
702 union {
703 char *str;
704 unsigned long long val;
705 };
706};
707
708struct filter_arg_op {
709 enum filter_op_type type;
710 struct filter_arg *left;
711 struct filter_arg *right;
712};
713
714struct filter_arg_exp {
715 enum filter_exp_type type;
716 struct filter_arg *left;
717 struct filter_arg *right;
718};
719
720struct filter_arg_num {
721 enum filter_cmp_type type;
722 struct filter_arg *left;
723 struct filter_arg *right;
724};
725
726struct filter_arg_str {
727 enum filter_cmp_type type;
728 struct format_field *field;
729 char *val;
730 char *buffer;
731 regex_t reg;
732};
733
734struct filter_arg {
735 enum filter_arg_type type;
736 union {
737 struct filter_arg_boolean bool;
738 struct filter_arg_field field;
739 struct filter_arg_value value;
740 struct filter_arg_op op;
741 struct filter_arg_exp exp;
742 struct filter_arg_num num;
743 struct filter_arg_str str;
744 };
745};
746
747struct filter_type {
748 int event_id;
749 struct event_format *event;
750 struct filter_arg *filter;
751};
752
753struct event_filter {
754 struct pevent *pevent;
755 int filters;
756 struct filter_type *event_filters;
757};
758
759struct event_filter *pevent_filter_alloc(struct pevent *pevent);
760
761#define FILTER_NONE -2
762#define FILTER_NOEXIST -1
763#define FILTER_MISS 0
764#define FILTER_MATCH 1
765
766enum filter_trivial_type {
767 FILTER_TRIVIAL_FALSE,
768 FILTER_TRIVIAL_TRUE,
769 FILTER_TRIVIAL_BOTH,
770};
771
772int pevent_filter_add_filter_str(struct event_filter *filter,
773 const char *filter_str,
774 char **error_str);
775
776
777int pevent_filter_match(struct event_filter *filter,
778 struct record *record);
779
780int pevent_event_filtered(struct event_filter *filter,
781 int event_id);
782
783void pevent_filter_reset(struct event_filter *filter);
784
785void pevent_filter_clear_trivial(struct event_filter *filter,
786 enum filter_trivial_type type);
787
788void pevent_filter_free(struct event_filter *filter);
789
790char *pevent_filter_make_string(struct event_filter *filter, int event_id);
791
792int pevent_filter_remove_event(struct event_filter *filter,
793 int event_id);
794
795int pevent_filter_event_has_trivial(struct event_filter *filter,
796 int event_id,
797 enum filter_trivial_type type);
798
799int pevent_filter_copy(struct event_filter *dest, struct event_filter *source);
800
801int pevent_update_trivial(struct event_filter *dest, struct event_filter *source,
802 enum filter_trivial_type type);
803
804int pevent_filter_compare(struct event_filter *filter1, struct event_filter *filter2);
805
806#endif /* _PARSE_EVENTS_H */