blob: dc8539ee948504ca6c6f5d13cb19d881544671de [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,
Steven Rostedtc6c2b962013-11-01 17:53:59 -0400311 EVENT_FL_NOHANDLE = 0x40,
312 EVENT_FL_PRINTRAW = 0x80,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200313
314 EVENT_FL_FAILED = 0x80000000
315};
316
317enum event_sort_type {
318 EVENT_SORT_ID,
319 EVENT_SORT_NAME,
320 EVENT_SORT_SYSTEM,
321};
322
323enum 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
335typedef unsigned long long (*pevent_func_handler)(struct trace_seq *s,
336 unsigned long long *args);
337
338enum 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 Rostedt4dc10242012-04-06 00:47:57 +0200347enum pevent_flag {
348 PEVENT_NSEC_OUTPUT = 1, /* output in NSECS */
349};
350
Namhyung Kim2f197b92012-08-22 16:00:30 +0900351#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 Kim67ed9392012-09-07 11:49:47 +0900357 _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
358 _PE(INVALID_ARG_TYPE, "invalid argument type")
Namhyung Kim2f197b92012-08-22 16:00:30 +0900359
360#undef _PE
361#define _PE(__code, __str) PEVENT_ERRNO__ ## __code
Namhyung Kimbffddff2012-08-22 16:00:29 +0900362enum 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 Kim2f197b92012-08-22 16:00:30 +0900374 PEVENT_ERRORS,
Namhyung Kimbffddff2012-08-22 16:00:29 +0900375
376 __PEVENT_ERRNO__END,
377};
Namhyung Kim2f197b92012-08-22 16:00:30 +0900378#undef _PE
Namhyung Kimbffddff2012-08-22 16:00:29 +0900379
Steven Rostedtf7d82352012-04-06 00:47:53 +0200380struct cmdline;
381struct cmdline_list;
382struct func_map;
383struct func_list;
384struct event_handler;
385
386struct 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 Kim012ac692013-06-04 14:20:20 +0900406 int page_size;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200407
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 Rostedt4dc10242012-04-06 00:47:57 +0200420
Steven Rostedtf7d82352012-04-06 00:47:53 +0200421 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 Rostedt4dc10242012-04-06 00:47:57 +0200445 int flags;
446
Steven Rostedtf7d82352012-04-06 00:47:53 +0200447 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 YUNOMAE1b372ca2013-11-01 17:53:53 -0400456
457 char *trace_clock;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200458};
459
Steven Rostedt4dc10242012-04-06 00:47:57 +0200460static inline void pevent_set_flag(struct pevent *pevent, int flag)
461{
462 pevent->flags |= flag;
463}
464
Steven Rostedtf7d82352012-04-06 00:47:53 +0200465static 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
479static 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
495static 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 */
526enum 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
534int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);
Yoshihiro YUNOMAE1b372ca2013-11-01 17:53:53 -0400535void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200536int pevent_register_function(struct pevent *pevent, char *name,
537 unsigned long long addr, char *mod);
Steven Rostedt (Red Hat)18900af2013-11-01 17:53:54 -0400538int pevent_register_print_string(struct pevent *pevent, const char *fmt,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200539 unsigned long long addr);
540int pevent_pid_is_registered(struct pevent *pevent, int pid);
541
542void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
Yoshihiro YUNOMAE1b372ca2013-11-01 17:53:53 -0400543 struct pevent_record *record, bool use_trace_clock);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200544
545int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size,
546 int long_size);
547
Namhyung Kimbffddff2012-08-22 16:00:29 +0900548enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
549 unsigned long size, const char *sys);
Arnaldo Carvalho de Melo2b291752012-09-18 11:13:15 -0300550enum pevent_errno pevent_parse_format(struct event_format **eventp, const char *buf,
551 unsigned long size, const char *sys);
552void pevent_free_format(struct event_format *event);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200553
554void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
Steven Rostedt1c698182012-04-06 00:48:06 +0200555 const char *name, struct pevent_record *record,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200556 int *len, int err);
557
558int pevent_get_field_val(struct trace_seq *s, struct event_format *event,
Steven Rostedt1c698182012-04-06 00:48:06 +0200559 const char *name, struct pevent_record *record,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200560 unsigned long long *val, int err);
561int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
Steven Rostedt1c698182012-04-06 00:48:06 +0200562 const char *name, struct pevent_record *record,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200563 unsigned long long *val, int err);
564int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
Steven Rostedt1c698182012-04-06 00:48:06 +0200565 const char *name, struct pevent_record *record,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200566 unsigned long long *val, int err);
567
568int pevent_print_num_field(struct trace_seq *s, const char *fmt,
569 struct event_format *event, const char *name,
Steven Rostedt1c698182012-04-06 00:48:06 +0200570 struct pevent_record *record, int err);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200571
Namhyung Kim79d5adf2013-06-04 14:20:18 +0900572int pevent_register_event_handler(struct pevent *pevent, int id,
573 const char *sys_name, const char *event_name,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200574 pevent_event_handler_func func, void *context);
575int pevent_register_print_function(struct pevent *pevent,
576 pevent_func_handler func,
577 enum pevent_func_arg_type ret_type,
578 char *name, ...);
579
580struct format_field *pevent_find_common_field(struct event_format *event, const char *name);
581struct format_field *pevent_find_field(struct event_format *event, const char *name);
582struct format_field *pevent_find_any_field(struct event_format *event, const char *name);
583
584const char *pevent_find_function(struct pevent *pevent, unsigned long long addr);
585unsigned long long
586pevent_find_function_address(struct pevent *pevent, unsigned long long addr);
587unsigned long long pevent_read_number(struct pevent *pevent, const void *ptr, int size);
588int pevent_read_number_field(struct format_field *field, const void *data,
589 unsigned long long *value);
590
591struct event_format *pevent_find_event(struct pevent *pevent, int id);
592
593struct event_format *
594pevent_find_event_by_name(struct pevent *pevent, const char *sys, const char *name);
595
596void pevent_data_lat_fmt(struct pevent *pevent,
Steven Rostedt1c698182012-04-06 00:48:06 +0200597 struct trace_seq *s, struct pevent_record *record);
598int pevent_data_type(struct pevent *pevent, struct pevent_record *rec);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200599struct event_format *pevent_data_event_from_type(struct pevent *pevent, int type);
Steven Rostedt1c698182012-04-06 00:48:06 +0200600int pevent_data_pid(struct pevent *pevent, struct pevent_record *rec);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200601const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid);
602void pevent_event_info(struct trace_seq *s, struct event_format *event,
Steven Rostedt1c698182012-04-06 00:48:06 +0200603 struct pevent_record *record);
Namhyung Kim2f197b92012-08-22 16:00:30 +0900604int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum,
605 char *buf, size_t buflen);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200606
607struct event_format **pevent_list_events(struct pevent *pevent, enum event_sort_type);
608struct format_field **pevent_event_common_fields(struct event_format *event);
609struct format_field **pevent_event_fields(struct event_format *event);
610
611static inline int pevent_get_cpus(struct pevent *pevent)
612{
613 return pevent->cpus;
614}
615
616static inline void pevent_set_cpus(struct pevent *pevent, int cpus)
617{
618 pevent->cpus = cpus;
619}
620
621static inline int pevent_get_long_size(struct pevent *pevent)
622{
623 return pevent->long_size;
624}
625
626static inline void pevent_set_long_size(struct pevent *pevent, int long_size)
627{
628 pevent->long_size = long_size;
629}
630
Namhyung Kim012ac692013-06-04 14:20:20 +0900631static inline int pevent_get_page_size(struct pevent *pevent)
632{
633 return pevent->page_size;
634}
635
636static inline void pevent_set_page_size(struct pevent *pevent, int _page_size)
637{
638 pevent->page_size = _page_size;
639}
640
Steven Rostedtf7d82352012-04-06 00:47:53 +0200641static inline int pevent_is_file_bigendian(struct pevent *pevent)
642{
643 return pevent->file_bigendian;
644}
645
646static inline void pevent_set_file_bigendian(struct pevent *pevent, int endian)
647{
648 pevent->file_bigendian = endian;
649}
650
651static inline int pevent_is_host_bigendian(struct pevent *pevent)
652{
653 return pevent->host_bigendian;
654}
655
656static inline void pevent_set_host_bigendian(struct pevent *pevent, int endian)
657{
658 pevent->host_bigendian = endian;
659}
660
661static inline int pevent_is_latency_format(struct pevent *pevent)
662{
663 return pevent->latency_format;
664}
665
666static inline void pevent_set_latency_format(struct pevent *pevent, int lat)
667{
668 pevent->latency_format = lat;
669}
670
671struct pevent *pevent_alloc(void);
672void pevent_free(struct pevent *pevent);
673void pevent_ref(struct pevent *pevent);
674void pevent_unref(struct pevent *pevent);
675
676/* access to the internal parser */
677void pevent_buffer_init(const char *buf, unsigned long long size);
678enum event_type pevent_read_token(char **tok);
679void pevent_free_token(char *token);
680int pevent_peek_char(void);
681const char *pevent_get_input_buf(void);
682unsigned long long pevent_get_input_buf_ptr(void);
683
684/* for debugging */
685void pevent_print_funcs(struct pevent *pevent);
686void pevent_print_printk(struct pevent *pevent);
687
688/* ----------------------- filtering ----------------------- */
689
690enum filter_boolean_type {
691 FILTER_FALSE,
692 FILTER_TRUE,
693};
694
695enum filter_op_type {
696 FILTER_OP_AND = 1,
697 FILTER_OP_OR,
698 FILTER_OP_NOT,
699};
700
701enum 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
715enum 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
730enum 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
741enum filter_value_type {
742 FILTER_NUMBER,
743 FILTER_STRING,
744 FILTER_CHAR
745};
746
747struct fliter_arg;
748
749struct filter_arg_boolean {
750 enum filter_boolean_type value;
751};
752
753struct filter_arg_field {
754 struct format_field *field;
755};
756
757struct filter_arg_value {
758 enum filter_value_type type;
759 union {
760 char *str;
761 unsigned long long val;
762 };
763};
764
765struct filter_arg_op {
766 enum filter_op_type type;
767 struct filter_arg *left;
768 struct filter_arg *right;
769};
770
771struct filter_arg_exp {
772 enum filter_exp_type type;
773 struct filter_arg *left;
774 struct filter_arg *right;
775};
776
777struct filter_arg_num {
778 enum filter_cmp_type type;
779 struct filter_arg *left;
780 struct filter_arg *right;
781};
782
783struct 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
791struct filter_arg {
792 enum filter_arg_type type;
793 union {
Steven Rostedt668fe012012-04-06 00:47:55 +0200794 struct filter_arg_boolean boolean;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200795 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
804struct filter_type {
805 int event_id;
806 struct event_format *event;
807 struct filter_arg *filter;
808};
809
810struct event_filter {
811 struct pevent *pevent;
812 int filters;
813 struct filter_type *event_filters;
814};
815
816struct 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
823enum filter_trivial_type {
824 FILTER_TRIVIAL_FALSE,
825 FILTER_TRIVIAL_TRUE,
826 FILTER_TRIVIAL_BOTH,
827};
828
829int pevent_filter_add_filter_str(struct event_filter *filter,
830 const char *filter_str,
831 char **error_str);
832
833
834int pevent_filter_match(struct event_filter *filter,
Steven Rostedt1c698182012-04-06 00:48:06 +0200835 struct pevent_record *record);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200836
837int pevent_event_filtered(struct event_filter *filter,
838 int event_id);
839
840void pevent_filter_reset(struct event_filter *filter);
841
842void pevent_filter_clear_trivial(struct event_filter *filter,
843 enum filter_trivial_type type);
844
845void pevent_filter_free(struct event_filter *filter);
846
847char *pevent_filter_make_string(struct event_filter *filter, int event_id);
848
849int pevent_filter_remove_event(struct event_filter *filter,
850 int event_id);
851
852int pevent_filter_event_has_trivial(struct event_filter *filter,
853 int event_id,
854 enum filter_trivial_type type);
855
856int pevent_filter_copy(struct event_filter *dest, struct event_filter *source);
857
858int pevent_update_trivial(struct event_filter *dest, struct event_filter *source,
859 enum filter_trivial_type type);
860
861int pevent_filter_compare(struct event_filter *filter1, struct event_filter *filter2);
862
863#endif /* _PARSE_EVENTS_H */