xref: /OK3568_Linux_fs/kernel/tools/lib/traceevent/event-parse.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: LGPL-2.1 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #ifndef _PARSE_EVENTS_H
7*4882a593Smuzhiyun #define _PARSE_EVENTS_H
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <stdbool.h>
10*4882a593Smuzhiyun #include <stdarg.h>
11*4882a593Smuzhiyun #include <stdio.h>
12*4882a593Smuzhiyun #include <regex.h>
13*4882a593Smuzhiyun #include <string.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include "trace-seq.h"
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #ifndef __maybe_unused
18*4882a593Smuzhiyun #define __maybe_unused __attribute__((unused))
19*4882a593Smuzhiyun #endif
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #ifndef DEBUG_RECORD
22*4882a593Smuzhiyun #define DEBUG_RECORD 0
23*4882a593Smuzhiyun #endif
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun struct tep_record {
26*4882a593Smuzhiyun 	unsigned long long	ts;
27*4882a593Smuzhiyun 	unsigned long long	offset;
28*4882a593Smuzhiyun 	long long		missed_events;	/* buffer dropped events before */
29*4882a593Smuzhiyun 	int			record_size;	/* size of binary record */
30*4882a593Smuzhiyun 	int			size;		/* size of data */
31*4882a593Smuzhiyun 	void			*data;
32*4882a593Smuzhiyun 	int			cpu;
33*4882a593Smuzhiyun 	int			ref_count;
34*4882a593Smuzhiyun 	int			locked;		/* Do not free, even if ref_count is zero */
35*4882a593Smuzhiyun 	void			*priv;
36*4882a593Smuzhiyun #if DEBUG_RECORD
37*4882a593Smuzhiyun 	struct tep_record	*prev;
38*4882a593Smuzhiyun 	struct tep_record	*next;
39*4882a593Smuzhiyun 	long			alloc_addr;
40*4882a593Smuzhiyun #endif
41*4882a593Smuzhiyun };
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /* ----------------------- tep ----------------------- */
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun struct tep_handle;
46*4882a593Smuzhiyun struct tep_event;
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun typedef int (*tep_event_handler_func)(struct trace_seq *s,
49*4882a593Smuzhiyun 				      struct tep_record *record,
50*4882a593Smuzhiyun 				      struct tep_event *event,
51*4882a593Smuzhiyun 				      void *context);
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun typedef int (*tep_plugin_load_func)(struct tep_handle *tep);
54*4882a593Smuzhiyun typedef int (*tep_plugin_unload_func)(struct tep_handle *tep);
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun struct tep_plugin_option {
57*4882a593Smuzhiyun 	struct tep_plugin_option	*next;
58*4882a593Smuzhiyun 	void				*handle;
59*4882a593Smuzhiyun 	char				*file;
60*4882a593Smuzhiyun 	char				*name;
61*4882a593Smuzhiyun 	char				*plugin_alias;
62*4882a593Smuzhiyun 	char				*description;
63*4882a593Smuzhiyun 	const char			*value;
64*4882a593Smuzhiyun 	void				*priv;
65*4882a593Smuzhiyun 	int				set;
66*4882a593Smuzhiyun };
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun /*
69*4882a593Smuzhiyun  * Plugin hooks that can be called:
70*4882a593Smuzhiyun  *
71*4882a593Smuzhiyun  * TEP_PLUGIN_LOADER:  (required)
72*4882a593Smuzhiyun  *   The function name to initialized the plugin.
73*4882a593Smuzhiyun  *
74*4882a593Smuzhiyun  *   int TEP_PLUGIN_LOADER(struct tep_handle *tep)
75*4882a593Smuzhiyun  *
76*4882a593Smuzhiyun  * TEP_PLUGIN_UNLOADER:  (optional)
77*4882a593Smuzhiyun  *   The function called just before unloading
78*4882a593Smuzhiyun  *
79*4882a593Smuzhiyun  *   int TEP_PLUGIN_UNLOADER(struct tep_handle *tep)
80*4882a593Smuzhiyun  *
81*4882a593Smuzhiyun  * TEP_PLUGIN_OPTIONS:  (optional)
82*4882a593Smuzhiyun  *   Plugin options that can be set before loading
83*4882a593Smuzhiyun  *
84*4882a593Smuzhiyun  *   struct tep_plugin_option TEP_PLUGIN_OPTIONS[] = {
85*4882a593Smuzhiyun  *	{
86*4882a593Smuzhiyun  *		.name = "option-name",
87*4882a593Smuzhiyun  *		.plugin_alias = "override-file-name", (optional)
88*4882a593Smuzhiyun  *		.description = "description of option to show users",
89*4882a593Smuzhiyun  *	},
90*4882a593Smuzhiyun  *	{
91*4882a593Smuzhiyun  *		.name = NULL,
92*4882a593Smuzhiyun  *	},
93*4882a593Smuzhiyun  *   };
94*4882a593Smuzhiyun  *
95*4882a593Smuzhiyun  *   Array must end with .name = NULL;
96*4882a593Smuzhiyun  *
97*4882a593Smuzhiyun  *
98*4882a593Smuzhiyun  *   .plugin_alias is used to give a shorter name to access
99*4882a593Smuzhiyun  *   the vairable. Useful if a plugin handles more than one event.
100*4882a593Smuzhiyun  *
101*4882a593Smuzhiyun  *   If .value is not set, then it is considered a boolean and only
102*4882a593Smuzhiyun  *   .set will be processed. If .value is defined, then it is considered
103*4882a593Smuzhiyun  *   a string option and .set will be ignored.
104*4882a593Smuzhiyun  *
105*4882a593Smuzhiyun  * TEP_PLUGIN_ALIAS: (optional)
106*4882a593Smuzhiyun  *   The name to use for finding options (uses filename if not defined)
107*4882a593Smuzhiyun  */
108*4882a593Smuzhiyun #define TEP_PLUGIN_LOADER tep_plugin_loader
109*4882a593Smuzhiyun #define TEP_PLUGIN_UNLOADER tep_plugin_unloader
110*4882a593Smuzhiyun #define TEP_PLUGIN_OPTIONS tep_plugin_options
111*4882a593Smuzhiyun #define TEP_PLUGIN_ALIAS tep_plugin_alias
112*4882a593Smuzhiyun #define _MAKE_STR(x)	#x
113*4882a593Smuzhiyun #define MAKE_STR(x)	_MAKE_STR(x)
114*4882a593Smuzhiyun #define TEP_PLUGIN_LOADER_NAME MAKE_STR(TEP_PLUGIN_LOADER)
115*4882a593Smuzhiyun #define TEP_PLUGIN_UNLOADER_NAME MAKE_STR(TEP_PLUGIN_UNLOADER)
116*4882a593Smuzhiyun #define TEP_PLUGIN_OPTIONS_NAME MAKE_STR(TEP_PLUGIN_OPTIONS)
117*4882a593Smuzhiyun #define TEP_PLUGIN_ALIAS_NAME MAKE_STR(TEP_PLUGIN_ALIAS)
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun enum tep_format_flags {
120*4882a593Smuzhiyun 	TEP_FIELD_IS_ARRAY	= 1,
121*4882a593Smuzhiyun 	TEP_FIELD_IS_POINTER	= 2,
122*4882a593Smuzhiyun 	TEP_FIELD_IS_SIGNED	= 4,
123*4882a593Smuzhiyun 	TEP_FIELD_IS_STRING	= 8,
124*4882a593Smuzhiyun 	TEP_FIELD_IS_DYNAMIC	= 16,
125*4882a593Smuzhiyun 	TEP_FIELD_IS_LONG	= 32,
126*4882a593Smuzhiyun 	TEP_FIELD_IS_FLAG	= 64,
127*4882a593Smuzhiyun 	TEP_FIELD_IS_SYMBOLIC	= 128,
128*4882a593Smuzhiyun };
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun struct tep_format_field {
131*4882a593Smuzhiyun 	struct tep_format_field	*next;
132*4882a593Smuzhiyun 	struct tep_event	*event;
133*4882a593Smuzhiyun 	char			*type;
134*4882a593Smuzhiyun 	char			*name;
135*4882a593Smuzhiyun 	char			*alias;
136*4882a593Smuzhiyun 	int			offset;
137*4882a593Smuzhiyun 	int			size;
138*4882a593Smuzhiyun 	unsigned int		arraylen;
139*4882a593Smuzhiyun 	unsigned int		elementsize;
140*4882a593Smuzhiyun 	unsigned long		flags;
141*4882a593Smuzhiyun };
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun struct tep_format {
144*4882a593Smuzhiyun 	int			nr_common;
145*4882a593Smuzhiyun 	int			nr_fields;
146*4882a593Smuzhiyun 	struct tep_format_field	*common_fields;
147*4882a593Smuzhiyun 	struct tep_format_field	*fields;
148*4882a593Smuzhiyun };
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun struct tep_print_arg_atom {
151*4882a593Smuzhiyun 	char			*atom;
152*4882a593Smuzhiyun };
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun struct tep_print_arg_string {
155*4882a593Smuzhiyun 	char			*string;
156*4882a593Smuzhiyun 	int			offset;
157*4882a593Smuzhiyun };
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun struct tep_print_arg_bitmask {
160*4882a593Smuzhiyun 	char			*bitmask;
161*4882a593Smuzhiyun 	int			offset;
162*4882a593Smuzhiyun };
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun struct tep_print_arg_field {
165*4882a593Smuzhiyun 	char			*name;
166*4882a593Smuzhiyun 	struct tep_format_field	*field;
167*4882a593Smuzhiyun };
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun struct tep_print_flag_sym {
170*4882a593Smuzhiyun 	struct tep_print_flag_sym	*next;
171*4882a593Smuzhiyun 	char				*value;
172*4882a593Smuzhiyun 	char				*str;
173*4882a593Smuzhiyun };
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun struct tep_print_arg_typecast {
176*4882a593Smuzhiyun 	char 			*type;
177*4882a593Smuzhiyun 	struct tep_print_arg	*item;
178*4882a593Smuzhiyun };
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun struct tep_print_arg_flags {
181*4882a593Smuzhiyun 	struct tep_print_arg		*field;
182*4882a593Smuzhiyun 	char				*delim;
183*4882a593Smuzhiyun 	struct tep_print_flag_sym	*flags;
184*4882a593Smuzhiyun };
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun struct tep_print_arg_symbol {
187*4882a593Smuzhiyun 	struct tep_print_arg		*field;
188*4882a593Smuzhiyun 	struct tep_print_flag_sym	*symbols;
189*4882a593Smuzhiyun };
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun struct tep_print_arg_hex {
192*4882a593Smuzhiyun 	struct tep_print_arg	*field;
193*4882a593Smuzhiyun 	struct tep_print_arg	*size;
194*4882a593Smuzhiyun };
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun struct tep_print_arg_int_array {
197*4882a593Smuzhiyun 	struct tep_print_arg	*field;
198*4882a593Smuzhiyun 	struct tep_print_arg	*count;
199*4882a593Smuzhiyun 	struct tep_print_arg	*el_size;
200*4882a593Smuzhiyun };
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun struct tep_print_arg_dynarray {
203*4882a593Smuzhiyun 	struct tep_format_field	*field;
204*4882a593Smuzhiyun 	struct tep_print_arg	*index;
205*4882a593Smuzhiyun };
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun struct tep_print_arg;
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun struct tep_print_arg_op {
210*4882a593Smuzhiyun 	char			*op;
211*4882a593Smuzhiyun 	int			prio;
212*4882a593Smuzhiyun 	struct tep_print_arg	*left;
213*4882a593Smuzhiyun 	struct tep_print_arg	*right;
214*4882a593Smuzhiyun };
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun struct tep_function_handler;
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun struct tep_print_arg_func {
219*4882a593Smuzhiyun 	struct tep_function_handler	*func;
220*4882a593Smuzhiyun 	struct tep_print_arg		*args;
221*4882a593Smuzhiyun };
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun enum tep_print_arg_type {
224*4882a593Smuzhiyun 	TEP_PRINT_NULL,
225*4882a593Smuzhiyun 	TEP_PRINT_ATOM,
226*4882a593Smuzhiyun 	TEP_PRINT_FIELD,
227*4882a593Smuzhiyun 	TEP_PRINT_FLAGS,
228*4882a593Smuzhiyun 	TEP_PRINT_SYMBOL,
229*4882a593Smuzhiyun 	TEP_PRINT_HEX,
230*4882a593Smuzhiyun 	TEP_PRINT_INT_ARRAY,
231*4882a593Smuzhiyun 	TEP_PRINT_TYPE,
232*4882a593Smuzhiyun 	TEP_PRINT_STRING,
233*4882a593Smuzhiyun 	TEP_PRINT_BSTRING,
234*4882a593Smuzhiyun 	TEP_PRINT_DYNAMIC_ARRAY,
235*4882a593Smuzhiyun 	TEP_PRINT_OP,
236*4882a593Smuzhiyun 	TEP_PRINT_FUNC,
237*4882a593Smuzhiyun 	TEP_PRINT_BITMASK,
238*4882a593Smuzhiyun 	TEP_PRINT_DYNAMIC_ARRAY_LEN,
239*4882a593Smuzhiyun 	TEP_PRINT_HEX_STR,
240*4882a593Smuzhiyun };
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun struct tep_print_arg {
243*4882a593Smuzhiyun 	struct tep_print_arg		*next;
244*4882a593Smuzhiyun 	enum tep_print_arg_type		type;
245*4882a593Smuzhiyun 	union {
246*4882a593Smuzhiyun 		struct tep_print_arg_atom	atom;
247*4882a593Smuzhiyun 		struct tep_print_arg_field	field;
248*4882a593Smuzhiyun 		struct tep_print_arg_typecast	typecast;
249*4882a593Smuzhiyun 		struct tep_print_arg_flags	flags;
250*4882a593Smuzhiyun 		struct tep_print_arg_symbol	symbol;
251*4882a593Smuzhiyun 		struct tep_print_arg_hex	hex;
252*4882a593Smuzhiyun 		struct tep_print_arg_int_array	int_array;
253*4882a593Smuzhiyun 		struct tep_print_arg_func	func;
254*4882a593Smuzhiyun 		struct tep_print_arg_string	string;
255*4882a593Smuzhiyun 		struct tep_print_arg_bitmask	bitmask;
256*4882a593Smuzhiyun 		struct tep_print_arg_op		op;
257*4882a593Smuzhiyun 		struct tep_print_arg_dynarray	dynarray;
258*4882a593Smuzhiyun 	};
259*4882a593Smuzhiyun };
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun struct tep_print_parse;
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun struct tep_print_fmt {
264*4882a593Smuzhiyun 	char			*format;
265*4882a593Smuzhiyun 	struct tep_print_arg	*args;
266*4882a593Smuzhiyun 	struct tep_print_parse	*print_cache;
267*4882a593Smuzhiyun };
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun struct tep_event {
270*4882a593Smuzhiyun 	struct tep_handle	*tep;
271*4882a593Smuzhiyun 	char			*name;
272*4882a593Smuzhiyun 	int			id;
273*4882a593Smuzhiyun 	int			flags;
274*4882a593Smuzhiyun 	struct tep_format	format;
275*4882a593Smuzhiyun 	struct tep_print_fmt	print_fmt;
276*4882a593Smuzhiyun 	char			*system;
277*4882a593Smuzhiyun 	tep_event_handler_func	handler;
278*4882a593Smuzhiyun 	void			*context;
279*4882a593Smuzhiyun };
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun enum {
282*4882a593Smuzhiyun 	TEP_EVENT_FL_ISFTRACE	= 0x01,
283*4882a593Smuzhiyun 	TEP_EVENT_FL_ISPRINT	= 0x02,
284*4882a593Smuzhiyun 	TEP_EVENT_FL_ISBPRINT	= 0x04,
285*4882a593Smuzhiyun 	TEP_EVENT_FL_ISFUNCENT	= 0x10,
286*4882a593Smuzhiyun 	TEP_EVENT_FL_ISFUNCRET	= 0x20,
287*4882a593Smuzhiyun 	TEP_EVENT_FL_NOHANDLE	= 0x40,
288*4882a593Smuzhiyun 	TEP_EVENT_FL_PRINTRAW	= 0x80,
289*4882a593Smuzhiyun 
290*4882a593Smuzhiyun 	TEP_EVENT_FL_FAILED	= 0x80000000
291*4882a593Smuzhiyun };
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun enum tep_event_sort_type {
294*4882a593Smuzhiyun 	TEP_EVENT_SORT_ID,
295*4882a593Smuzhiyun 	TEP_EVENT_SORT_NAME,
296*4882a593Smuzhiyun 	TEP_EVENT_SORT_SYSTEM,
297*4882a593Smuzhiyun };
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun enum tep_event_type {
300*4882a593Smuzhiyun 	TEP_EVENT_ERROR,
301*4882a593Smuzhiyun 	TEP_EVENT_NONE,
302*4882a593Smuzhiyun 	TEP_EVENT_SPACE,
303*4882a593Smuzhiyun 	TEP_EVENT_NEWLINE,
304*4882a593Smuzhiyun 	TEP_EVENT_OP,
305*4882a593Smuzhiyun 	TEP_EVENT_DELIM,
306*4882a593Smuzhiyun 	TEP_EVENT_ITEM,
307*4882a593Smuzhiyun 	TEP_EVENT_DQUOTE,
308*4882a593Smuzhiyun 	TEP_EVENT_SQUOTE,
309*4882a593Smuzhiyun };
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun typedef unsigned long long (*tep_func_handler)(struct trace_seq *s,
312*4882a593Smuzhiyun 					       unsigned long long *args);
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun enum tep_func_arg_type {
315*4882a593Smuzhiyun 	TEP_FUNC_ARG_VOID,
316*4882a593Smuzhiyun 	TEP_FUNC_ARG_INT,
317*4882a593Smuzhiyun 	TEP_FUNC_ARG_LONG,
318*4882a593Smuzhiyun 	TEP_FUNC_ARG_STRING,
319*4882a593Smuzhiyun 	TEP_FUNC_ARG_PTR,
320*4882a593Smuzhiyun 	TEP_FUNC_ARG_MAX_TYPES
321*4882a593Smuzhiyun };
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun enum tep_flag {
324*4882a593Smuzhiyun 	TEP_NSEC_OUTPUT		= 1,	/* output in NSECS */
325*4882a593Smuzhiyun 	TEP_DISABLE_SYS_PLUGINS	= 1 << 1,
326*4882a593Smuzhiyun 	TEP_DISABLE_PLUGINS	= 1 << 2,
327*4882a593Smuzhiyun };
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun #define TEP_ERRORS 							      \
330*4882a593Smuzhiyun 	_PE(MEM_ALLOC_FAILED,	"failed to allocate memory"),		      \
331*4882a593Smuzhiyun 	_PE(PARSE_EVENT_FAILED,	"failed to parse event"),		      \
332*4882a593Smuzhiyun 	_PE(READ_ID_FAILED,	"failed to read event id"),		      \
333*4882a593Smuzhiyun 	_PE(READ_FORMAT_FAILED,	"failed to read event format"),		      \
334*4882a593Smuzhiyun 	_PE(READ_PRINT_FAILED,	"failed to read event print fmt"), 	      \
335*4882a593Smuzhiyun 	_PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
336*4882a593Smuzhiyun 	_PE(INVALID_ARG_TYPE,	"invalid argument type"),		      \
337*4882a593Smuzhiyun 	_PE(INVALID_EXP_TYPE,	"invalid expression type"),		      \
338*4882a593Smuzhiyun 	_PE(INVALID_OP_TYPE,	"invalid operator type"),		      \
339*4882a593Smuzhiyun 	_PE(INVALID_EVENT_NAME,	"invalid event name"),			      \
340*4882a593Smuzhiyun 	_PE(EVENT_NOT_FOUND,	"no event found"),			      \
341*4882a593Smuzhiyun 	_PE(SYNTAX_ERROR,	"syntax error"),			      \
342*4882a593Smuzhiyun 	_PE(ILLEGAL_RVALUE,	"illegal rvalue"),			      \
343*4882a593Smuzhiyun 	_PE(ILLEGAL_LVALUE,	"illegal lvalue for string comparison"),      \
344*4882a593Smuzhiyun 	_PE(INVALID_REGEX,	"regex did not compute"),		      \
345*4882a593Smuzhiyun 	_PE(ILLEGAL_STRING_CMP,	"illegal comparison for string"), 	      \
346*4882a593Smuzhiyun 	_PE(ILLEGAL_INTEGER_CMP,"illegal comparison for integer"), 	      \
347*4882a593Smuzhiyun 	_PE(REPARENT_NOT_OP,	"cannot reparent other than OP"),	      \
348*4882a593Smuzhiyun 	_PE(REPARENT_FAILED,	"failed to reparent filter OP"),	      \
349*4882a593Smuzhiyun 	_PE(BAD_FILTER_ARG,	"bad arg in filter tree"),		      \
350*4882a593Smuzhiyun 	_PE(UNEXPECTED_TYPE,	"unexpected type (not a value)"),	      \
351*4882a593Smuzhiyun 	_PE(ILLEGAL_TOKEN,	"illegal token"),			      \
352*4882a593Smuzhiyun 	_PE(INVALID_PAREN,	"open parenthesis cannot come here"), 	      \
353*4882a593Smuzhiyun 	_PE(UNBALANCED_PAREN,	"unbalanced number of parenthesis"),	      \
354*4882a593Smuzhiyun 	_PE(UNKNOWN_TOKEN,	"unknown token"),			      \
355*4882a593Smuzhiyun 	_PE(FILTER_NOT_FOUND,	"no filter found"),			      \
356*4882a593Smuzhiyun 	_PE(NOT_A_NUMBER,	"must have number field"),		      \
357*4882a593Smuzhiyun 	_PE(NO_FILTER,		"no filters exists"),			      \
358*4882a593Smuzhiyun 	_PE(FILTER_MISS,	"record does not match to filter")
359*4882a593Smuzhiyun 
360*4882a593Smuzhiyun #undef _PE
361*4882a593Smuzhiyun #define _PE(__code, __str) TEP_ERRNO__ ## __code
362*4882a593Smuzhiyun enum tep_errno {
363*4882a593Smuzhiyun 	TEP_ERRNO__SUCCESS			= 0,
364*4882a593Smuzhiyun 	TEP_ERRNO__FILTER_MATCH			= TEP_ERRNO__SUCCESS,
365*4882a593Smuzhiyun 
366*4882a593Smuzhiyun 	/*
367*4882a593Smuzhiyun 	 * Choose an arbitrary negative big number not to clash with standard
368*4882a593Smuzhiyun 	 * errno since SUS requires the errno has distinct positive values.
369*4882a593Smuzhiyun 	 * See 'Issue 6' in the link below.
370*4882a593Smuzhiyun 	 *
371*4882a593Smuzhiyun 	 * https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
372*4882a593Smuzhiyun 	 */
373*4882a593Smuzhiyun 	__TEP_ERRNO__START			= -100000,
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun 	TEP_ERRORS,
376*4882a593Smuzhiyun 
377*4882a593Smuzhiyun 	__TEP_ERRNO__END,
378*4882a593Smuzhiyun };
379*4882a593Smuzhiyun #undef _PE
380*4882a593Smuzhiyun 
381*4882a593Smuzhiyun struct tep_plugin_list;
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun #define INVALID_PLUGIN_LIST_OPTION	((char **)((unsigned long)-1))
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun enum tep_plugin_load_priority {
386*4882a593Smuzhiyun 	TEP_PLUGIN_FIRST,
387*4882a593Smuzhiyun 	TEP_PLUGIN_LAST,
388*4882a593Smuzhiyun };
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun int tep_add_plugin_path(struct tep_handle *tep, char *path,
391*4882a593Smuzhiyun 			enum tep_plugin_load_priority prio);
392*4882a593Smuzhiyun struct tep_plugin_list *tep_load_plugins(struct tep_handle *tep);
393*4882a593Smuzhiyun void tep_unload_plugins(struct tep_plugin_list *plugin_list,
394*4882a593Smuzhiyun 			struct tep_handle *tep);
395*4882a593Smuzhiyun void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
396*4882a593Smuzhiyun 			   void (*load_plugin)(struct tep_handle *tep,
397*4882a593Smuzhiyun 					       const char *path,
398*4882a593Smuzhiyun 					       const char *name,
399*4882a593Smuzhiyun 					       void *data),
400*4882a593Smuzhiyun 			   void *data);
401*4882a593Smuzhiyun char **tep_plugin_list_options(void);
402*4882a593Smuzhiyun void tep_plugin_free_options_list(char **list);
403*4882a593Smuzhiyun int tep_plugin_add_options(const char *name,
404*4882a593Smuzhiyun 			   struct tep_plugin_option *options);
405*4882a593Smuzhiyun int tep_plugin_add_option(const char *name, const char *val);
406*4882a593Smuzhiyun void tep_plugin_remove_options(struct tep_plugin_option *options);
407*4882a593Smuzhiyun void tep_plugin_print_options(struct trace_seq *s);
408*4882a593Smuzhiyun void tep_print_plugins(struct trace_seq *s,
409*4882a593Smuzhiyun 			const char *prefix, const char *suffix,
410*4882a593Smuzhiyun 			const struct tep_plugin_list *list);
411*4882a593Smuzhiyun 
412*4882a593Smuzhiyun /* tep_handle */
413*4882a593Smuzhiyun typedef char *(tep_func_resolver_t)(void *priv,
414*4882a593Smuzhiyun 				    unsigned long long *addrp, char **modp);
415*4882a593Smuzhiyun void tep_set_flag(struct tep_handle *tep, int flag);
416*4882a593Smuzhiyun void tep_clear_flag(struct tep_handle *tep, enum tep_flag flag);
417*4882a593Smuzhiyun bool tep_test_flag(struct tep_handle *tep, enum tep_flag flags);
418*4882a593Smuzhiyun 
tep_is_bigendian(void)419*4882a593Smuzhiyun static inline int tep_is_bigendian(void)
420*4882a593Smuzhiyun {
421*4882a593Smuzhiyun 	unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
422*4882a593Smuzhiyun 	unsigned int val;
423*4882a593Smuzhiyun 
424*4882a593Smuzhiyun 	memcpy(&val, str, 4);
425*4882a593Smuzhiyun 	return val == 0x01020304;
426*4882a593Smuzhiyun }
427*4882a593Smuzhiyun 
428*4882a593Smuzhiyun /* taken from kernel/trace/trace.h */
429*4882a593Smuzhiyun enum trace_flag_type {
430*4882a593Smuzhiyun 	TRACE_FLAG_IRQS_OFF		= 0x01,
431*4882a593Smuzhiyun 	TRACE_FLAG_IRQS_NOSUPPORT	= 0x02,
432*4882a593Smuzhiyun 	TRACE_FLAG_NEED_RESCHED		= 0x04,
433*4882a593Smuzhiyun 	TRACE_FLAG_HARDIRQ		= 0x08,
434*4882a593Smuzhiyun 	TRACE_FLAG_SOFTIRQ		= 0x10,
435*4882a593Smuzhiyun };
436*4882a593Smuzhiyun 
437*4882a593Smuzhiyun int tep_set_function_resolver(struct tep_handle *tep,
438*4882a593Smuzhiyun 			      tep_func_resolver_t *func, void *priv);
439*4882a593Smuzhiyun void tep_reset_function_resolver(struct tep_handle *tep);
440*4882a593Smuzhiyun int tep_register_comm(struct tep_handle *tep, const char *comm, int pid);
441*4882a593Smuzhiyun int tep_override_comm(struct tep_handle *tep, const char *comm, int pid);
442*4882a593Smuzhiyun int tep_register_function(struct tep_handle *tep, char *name,
443*4882a593Smuzhiyun 			  unsigned long long addr, char *mod);
444*4882a593Smuzhiyun int tep_register_print_string(struct tep_handle *tep, const char *fmt,
445*4882a593Smuzhiyun 			      unsigned long long addr);
446*4882a593Smuzhiyun bool tep_is_pid_registered(struct tep_handle *tep, int pid);
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun struct tep_event *tep_get_event(struct tep_handle *tep, int index);
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun #define TEP_PRINT_INFO		"INFO"
451*4882a593Smuzhiyun #define TEP_PRINT_INFO_RAW	"INFO_RAW"
452*4882a593Smuzhiyun #define TEP_PRINT_COMM		"COMM"
453*4882a593Smuzhiyun #define TEP_PRINT_LATENCY	"LATENCY"
454*4882a593Smuzhiyun #define TEP_PRINT_NAME		"NAME"
455*4882a593Smuzhiyun #define TEP_PRINT_PID		1U
456*4882a593Smuzhiyun #define TEP_PRINT_TIME		2U
457*4882a593Smuzhiyun #define TEP_PRINT_CPU		3U
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
460*4882a593Smuzhiyun 		     struct tep_record *record, const char *fmt, ...)
461*4882a593Smuzhiyun 	__attribute__ ((format (printf, 4, 5)));
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size,
464*4882a593Smuzhiyun 			  int long_size);
465*4882a593Smuzhiyun 
466*4882a593Smuzhiyun enum tep_errno tep_parse_event(struct tep_handle *tep, const char *buf,
467*4882a593Smuzhiyun 			       unsigned long size, const char *sys);
468*4882a593Smuzhiyun enum tep_errno tep_parse_format(struct tep_handle *tep,
469*4882a593Smuzhiyun 				struct tep_event **eventp,
470*4882a593Smuzhiyun 				const char *buf,
471*4882a593Smuzhiyun 				unsigned long size, const char *sys);
472*4882a593Smuzhiyun 
473*4882a593Smuzhiyun void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event,
474*4882a593Smuzhiyun 			const char *name, struct tep_record *record,
475*4882a593Smuzhiyun 			int *len, int err);
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun int tep_get_field_val(struct trace_seq *s, struct tep_event *event,
478*4882a593Smuzhiyun 		      const char *name, struct tep_record *record,
479*4882a593Smuzhiyun 		      unsigned long long *val, int err);
480*4882a593Smuzhiyun int tep_get_common_field_val(struct trace_seq *s, struct tep_event *event,
481*4882a593Smuzhiyun 			     const char *name, struct tep_record *record,
482*4882a593Smuzhiyun 			     unsigned long long *val, int err);
483*4882a593Smuzhiyun int tep_get_any_field_val(struct trace_seq *s, struct tep_event *event,
484*4882a593Smuzhiyun 			  const char *name, struct tep_record *record,
485*4882a593Smuzhiyun 			  unsigned long long *val, int err);
486*4882a593Smuzhiyun 
487*4882a593Smuzhiyun int tep_print_num_field(struct trace_seq *s, const char *fmt,
488*4882a593Smuzhiyun 			struct tep_event *event, const char *name,
489*4882a593Smuzhiyun 			struct tep_record *record, int err);
490*4882a593Smuzhiyun 
491*4882a593Smuzhiyun int tep_print_func_field(struct trace_seq *s, const char *fmt,
492*4882a593Smuzhiyun 			 struct tep_event *event, const char *name,
493*4882a593Smuzhiyun 			 struct tep_record *record, int err);
494*4882a593Smuzhiyun 
495*4882a593Smuzhiyun enum tep_reg_handler {
496*4882a593Smuzhiyun 	TEP_REGISTER_SUCCESS = 0,
497*4882a593Smuzhiyun 	TEP_REGISTER_SUCCESS_OVERWRITE,
498*4882a593Smuzhiyun };
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun int tep_register_event_handler(struct tep_handle *tep, int id,
501*4882a593Smuzhiyun 			       const char *sys_name, const char *event_name,
502*4882a593Smuzhiyun 			       tep_event_handler_func func, void *context);
503*4882a593Smuzhiyun int tep_unregister_event_handler(struct tep_handle *tep, int id,
504*4882a593Smuzhiyun 				 const char *sys_name, const char *event_name,
505*4882a593Smuzhiyun 				 tep_event_handler_func func, void *context);
506*4882a593Smuzhiyun int tep_register_print_function(struct tep_handle *tep,
507*4882a593Smuzhiyun 				tep_func_handler func,
508*4882a593Smuzhiyun 				enum tep_func_arg_type ret_type,
509*4882a593Smuzhiyun 				char *name, ...);
510*4882a593Smuzhiyun int tep_unregister_print_function(struct tep_handle *tep,
511*4882a593Smuzhiyun 				  tep_func_handler func, char *name);
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun struct tep_format_field *tep_find_common_field(struct tep_event *event, const char *name);
514*4882a593Smuzhiyun struct tep_format_field *tep_find_field(struct tep_event *event, const char *name);
515*4882a593Smuzhiyun struct tep_format_field *tep_find_any_field(struct tep_event *event, const char *name);
516*4882a593Smuzhiyun 
517*4882a593Smuzhiyun const char *tep_find_function(struct tep_handle *tep, unsigned long long addr);
518*4882a593Smuzhiyun unsigned long long
519*4882a593Smuzhiyun tep_find_function_address(struct tep_handle *tep, unsigned long long addr);
520*4882a593Smuzhiyun unsigned long long tep_read_number(struct tep_handle *tep, const void *ptr, int size);
521*4882a593Smuzhiyun int tep_read_number_field(struct tep_format_field *field, const void *data,
522*4882a593Smuzhiyun 			  unsigned long long *value);
523*4882a593Smuzhiyun 
524*4882a593Smuzhiyun struct tep_event *tep_get_first_event(struct tep_handle *tep);
525*4882a593Smuzhiyun int tep_get_events_count(struct tep_handle *tep);
526*4882a593Smuzhiyun struct tep_event *tep_find_event(struct tep_handle *tep, int id);
527*4882a593Smuzhiyun 
528*4882a593Smuzhiyun struct tep_event *
529*4882a593Smuzhiyun tep_find_event_by_name(struct tep_handle *tep, const char *sys, const char *name);
530*4882a593Smuzhiyun struct tep_event *
531*4882a593Smuzhiyun tep_find_event_by_record(struct tep_handle *tep, struct tep_record *record);
532*4882a593Smuzhiyun 
533*4882a593Smuzhiyun int tep_data_type(struct tep_handle *tep, struct tep_record *rec);
534*4882a593Smuzhiyun int tep_data_pid(struct tep_handle *tep, struct tep_record *rec);
535*4882a593Smuzhiyun int tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec);
536*4882a593Smuzhiyun int tep_data_flags(struct tep_handle *tep, struct tep_record *rec);
537*4882a593Smuzhiyun const char *tep_data_comm_from_pid(struct tep_handle *tep, int pid);
538*4882a593Smuzhiyun struct tep_cmdline;
539*4882a593Smuzhiyun struct tep_cmdline *tep_data_pid_from_comm(struct tep_handle *tep, const char *comm,
540*4882a593Smuzhiyun 					   struct tep_cmdline *next);
541*4882a593Smuzhiyun int tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline);
542*4882a593Smuzhiyun 
543*4882a593Smuzhiyun void tep_print_field(struct trace_seq *s, void *data,
544*4882a593Smuzhiyun 		     struct tep_format_field *field);
545*4882a593Smuzhiyun void tep_print_fields(struct trace_seq *s, void *data,
546*4882a593Smuzhiyun 		      int size __maybe_unused, struct tep_event *event);
547*4882a593Smuzhiyun int tep_strerror(struct tep_handle *tep, enum tep_errno errnum,
548*4882a593Smuzhiyun 		 char *buf, size_t buflen);
549*4882a593Smuzhiyun 
550*4882a593Smuzhiyun struct tep_event **tep_list_events(struct tep_handle *tep, enum tep_event_sort_type);
551*4882a593Smuzhiyun struct tep_event **tep_list_events_copy(struct tep_handle *tep,
552*4882a593Smuzhiyun 					enum tep_event_sort_type);
553*4882a593Smuzhiyun struct tep_format_field **tep_event_common_fields(struct tep_event *event);
554*4882a593Smuzhiyun struct tep_format_field **tep_event_fields(struct tep_event *event);
555*4882a593Smuzhiyun 
556*4882a593Smuzhiyun enum tep_endian {
557*4882a593Smuzhiyun         TEP_LITTLE_ENDIAN = 0,
558*4882a593Smuzhiyun         TEP_BIG_ENDIAN
559*4882a593Smuzhiyun };
560*4882a593Smuzhiyun int tep_get_cpus(struct tep_handle *tep);
561*4882a593Smuzhiyun void tep_set_cpus(struct tep_handle *tep, int cpus);
562*4882a593Smuzhiyun int tep_get_long_size(struct tep_handle *tep);
563*4882a593Smuzhiyun void tep_set_long_size(struct tep_handle *tep, int long_size);
564*4882a593Smuzhiyun int tep_get_page_size(struct tep_handle *tep);
565*4882a593Smuzhiyun void tep_set_page_size(struct tep_handle *tep, int _page_size);
566*4882a593Smuzhiyun bool tep_is_file_bigendian(struct tep_handle *tep);
567*4882a593Smuzhiyun void tep_set_file_bigendian(struct tep_handle *tep, enum tep_endian endian);
568*4882a593Smuzhiyun bool tep_is_local_bigendian(struct tep_handle *tep);
569*4882a593Smuzhiyun void tep_set_local_bigendian(struct tep_handle *tep, enum tep_endian endian);
570*4882a593Smuzhiyun int tep_get_header_page_size(struct tep_handle *tep);
571*4882a593Smuzhiyun int tep_get_header_timestamp_size(struct tep_handle *tep);
572*4882a593Smuzhiyun bool tep_is_old_format(struct tep_handle *tep);
573*4882a593Smuzhiyun void tep_set_test_filters(struct tep_handle *tep, int test_filters);
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun struct tep_handle *tep_alloc(void);
576*4882a593Smuzhiyun void tep_free(struct tep_handle *tep);
577*4882a593Smuzhiyun void tep_ref(struct tep_handle *tep);
578*4882a593Smuzhiyun void tep_unref(struct tep_handle *tep);
579*4882a593Smuzhiyun int tep_get_ref(struct tep_handle *tep);
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun /* for debugging */
582*4882a593Smuzhiyun void tep_print_funcs(struct tep_handle *tep);
583*4882a593Smuzhiyun void tep_print_printk(struct tep_handle *tep);
584*4882a593Smuzhiyun 
585*4882a593Smuzhiyun /* ----------------------- filtering ----------------------- */
586*4882a593Smuzhiyun 
587*4882a593Smuzhiyun enum tep_filter_boolean_type {
588*4882a593Smuzhiyun 	TEP_FILTER_FALSE,
589*4882a593Smuzhiyun 	TEP_FILTER_TRUE,
590*4882a593Smuzhiyun };
591*4882a593Smuzhiyun 
592*4882a593Smuzhiyun enum tep_filter_op_type {
593*4882a593Smuzhiyun 	TEP_FILTER_OP_AND = 1,
594*4882a593Smuzhiyun 	TEP_FILTER_OP_OR,
595*4882a593Smuzhiyun 	TEP_FILTER_OP_NOT,
596*4882a593Smuzhiyun };
597*4882a593Smuzhiyun 
598*4882a593Smuzhiyun enum tep_filter_cmp_type {
599*4882a593Smuzhiyun 	TEP_FILTER_CMP_NONE,
600*4882a593Smuzhiyun 	TEP_FILTER_CMP_EQ,
601*4882a593Smuzhiyun 	TEP_FILTER_CMP_NE,
602*4882a593Smuzhiyun 	TEP_FILTER_CMP_GT,
603*4882a593Smuzhiyun 	TEP_FILTER_CMP_LT,
604*4882a593Smuzhiyun 	TEP_FILTER_CMP_GE,
605*4882a593Smuzhiyun 	TEP_FILTER_CMP_LE,
606*4882a593Smuzhiyun 	TEP_FILTER_CMP_MATCH,
607*4882a593Smuzhiyun 	TEP_FILTER_CMP_NOT_MATCH,
608*4882a593Smuzhiyun 	TEP_FILTER_CMP_REGEX,
609*4882a593Smuzhiyun 	TEP_FILTER_CMP_NOT_REGEX,
610*4882a593Smuzhiyun };
611*4882a593Smuzhiyun 
612*4882a593Smuzhiyun enum tep_filter_exp_type {
613*4882a593Smuzhiyun 	TEP_FILTER_EXP_NONE,
614*4882a593Smuzhiyun 	TEP_FILTER_EXP_ADD,
615*4882a593Smuzhiyun 	TEP_FILTER_EXP_SUB,
616*4882a593Smuzhiyun 	TEP_FILTER_EXP_MUL,
617*4882a593Smuzhiyun 	TEP_FILTER_EXP_DIV,
618*4882a593Smuzhiyun 	TEP_FILTER_EXP_MOD,
619*4882a593Smuzhiyun 	TEP_FILTER_EXP_RSHIFT,
620*4882a593Smuzhiyun 	TEP_FILTER_EXP_LSHIFT,
621*4882a593Smuzhiyun 	TEP_FILTER_EXP_AND,
622*4882a593Smuzhiyun 	TEP_FILTER_EXP_OR,
623*4882a593Smuzhiyun 	TEP_FILTER_EXP_XOR,
624*4882a593Smuzhiyun 	TEP_FILTER_EXP_NOT,
625*4882a593Smuzhiyun };
626*4882a593Smuzhiyun 
627*4882a593Smuzhiyun enum tep_filter_arg_type {
628*4882a593Smuzhiyun 	TEP_FILTER_ARG_NONE,
629*4882a593Smuzhiyun 	TEP_FILTER_ARG_BOOLEAN,
630*4882a593Smuzhiyun 	TEP_FILTER_ARG_VALUE,
631*4882a593Smuzhiyun 	TEP_FILTER_ARG_FIELD,
632*4882a593Smuzhiyun 	TEP_FILTER_ARG_EXP,
633*4882a593Smuzhiyun 	TEP_FILTER_ARG_OP,
634*4882a593Smuzhiyun 	TEP_FILTER_ARG_NUM,
635*4882a593Smuzhiyun 	TEP_FILTER_ARG_STR,
636*4882a593Smuzhiyun };
637*4882a593Smuzhiyun 
638*4882a593Smuzhiyun enum tep_filter_value_type {
639*4882a593Smuzhiyun 	TEP_FILTER_NUMBER,
640*4882a593Smuzhiyun 	TEP_FILTER_STRING,
641*4882a593Smuzhiyun 	TEP_FILTER_CHAR
642*4882a593Smuzhiyun };
643*4882a593Smuzhiyun 
644*4882a593Smuzhiyun struct tep_filter_arg;
645*4882a593Smuzhiyun 
646*4882a593Smuzhiyun struct tep_filter_arg_boolean {
647*4882a593Smuzhiyun 	enum tep_filter_boolean_type	value;
648*4882a593Smuzhiyun };
649*4882a593Smuzhiyun 
650*4882a593Smuzhiyun struct tep_filter_arg_field {
651*4882a593Smuzhiyun 	struct tep_format_field		*field;
652*4882a593Smuzhiyun };
653*4882a593Smuzhiyun 
654*4882a593Smuzhiyun struct tep_filter_arg_value {
655*4882a593Smuzhiyun 	enum tep_filter_value_type	type;
656*4882a593Smuzhiyun 	union {
657*4882a593Smuzhiyun 		char			*str;
658*4882a593Smuzhiyun 		unsigned long long	val;
659*4882a593Smuzhiyun 	};
660*4882a593Smuzhiyun };
661*4882a593Smuzhiyun 
662*4882a593Smuzhiyun struct tep_filter_arg_op {
663*4882a593Smuzhiyun 	enum tep_filter_op_type		type;
664*4882a593Smuzhiyun 	struct tep_filter_arg		*left;
665*4882a593Smuzhiyun 	struct tep_filter_arg		*right;
666*4882a593Smuzhiyun };
667*4882a593Smuzhiyun 
668*4882a593Smuzhiyun struct tep_filter_arg_exp {
669*4882a593Smuzhiyun 	enum tep_filter_exp_type	type;
670*4882a593Smuzhiyun 	struct tep_filter_arg		*left;
671*4882a593Smuzhiyun 	struct tep_filter_arg		*right;
672*4882a593Smuzhiyun };
673*4882a593Smuzhiyun 
674*4882a593Smuzhiyun struct tep_filter_arg_num {
675*4882a593Smuzhiyun 	enum tep_filter_cmp_type	type;
676*4882a593Smuzhiyun 	struct tep_filter_arg		*left;
677*4882a593Smuzhiyun 	struct tep_filter_arg		*right;
678*4882a593Smuzhiyun };
679*4882a593Smuzhiyun 
680*4882a593Smuzhiyun struct tep_filter_arg_str {
681*4882a593Smuzhiyun 	enum tep_filter_cmp_type	type;
682*4882a593Smuzhiyun 	struct tep_format_field		*field;
683*4882a593Smuzhiyun 	char				*val;
684*4882a593Smuzhiyun 	char				*buffer;
685*4882a593Smuzhiyun 	regex_t				reg;
686*4882a593Smuzhiyun };
687*4882a593Smuzhiyun 
688*4882a593Smuzhiyun struct tep_filter_arg {
689*4882a593Smuzhiyun 	enum tep_filter_arg_type		type;
690*4882a593Smuzhiyun 	union {
691*4882a593Smuzhiyun 		struct tep_filter_arg_boolean	boolean;
692*4882a593Smuzhiyun 		struct tep_filter_arg_field	field;
693*4882a593Smuzhiyun 		struct tep_filter_arg_value	value;
694*4882a593Smuzhiyun 		struct tep_filter_arg_op	op;
695*4882a593Smuzhiyun 		struct tep_filter_arg_exp	exp;
696*4882a593Smuzhiyun 		struct tep_filter_arg_num	num;
697*4882a593Smuzhiyun 		struct tep_filter_arg_str	str;
698*4882a593Smuzhiyun 	};
699*4882a593Smuzhiyun };
700*4882a593Smuzhiyun 
701*4882a593Smuzhiyun struct tep_filter_type {
702*4882a593Smuzhiyun 	int			event_id;
703*4882a593Smuzhiyun 	struct tep_event	*event;
704*4882a593Smuzhiyun 	struct tep_filter_arg	*filter;
705*4882a593Smuzhiyun };
706*4882a593Smuzhiyun 
707*4882a593Smuzhiyun #define TEP_FILTER_ERROR_BUFSZ  1024
708*4882a593Smuzhiyun 
709*4882a593Smuzhiyun struct tep_event_filter {
710*4882a593Smuzhiyun 	struct tep_handle	*tep;
711*4882a593Smuzhiyun 	int			filters;
712*4882a593Smuzhiyun 	struct tep_filter_type	*event_filters;
713*4882a593Smuzhiyun 	char			error_buffer[TEP_FILTER_ERROR_BUFSZ];
714*4882a593Smuzhiyun };
715*4882a593Smuzhiyun 
716*4882a593Smuzhiyun struct tep_event_filter *tep_filter_alloc(struct tep_handle *tep);
717*4882a593Smuzhiyun 
718*4882a593Smuzhiyun /* for backward compatibility */
719*4882a593Smuzhiyun #define FILTER_NONE		TEP_ERRNO__NO_FILTER
720*4882a593Smuzhiyun #define FILTER_NOEXIST		TEP_ERRNO__FILTER_NOT_FOUND
721*4882a593Smuzhiyun #define FILTER_MISS		TEP_ERRNO__FILTER_MISS
722*4882a593Smuzhiyun #define FILTER_MATCH		TEP_ERRNO__FILTER_MATCH
723*4882a593Smuzhiyun 
724*4882a593Smuzhiyun enum tep_errno tep_filter_add_filter_str(struct tep_event_filter *filter,
725*4882a593Smuzhiyun 					 const char *filter_str);
726*4882a593Smuzhiyun 
727*4882a593Smuzhiyun enum tep_errno tep_filter_match(struct tep_event_filter *filter,
728*4882a593Smuzhiyun 				struct tep_record *record);
729*4882a593Smuzhiyun 
730*4882a593Smuzhiyun int tep_filter_strerror(struct tep_event_filter *filter, enum tep_errno err,
731*4882a593Smuzhiyun 			char *buf, size_t buflen);
732*4882a593Smuzhiyun 
733*4882a593Smuzhiyun int tep_event_filtered(struct tep_event_filter *filter,
734*4882a593Smuzhiyun 		       int event_id);
735*4882a593Smuzhiyun 
736*4882a593Smuzhiyun void tep_filter_reset(struct tep_event_filter *filter);
737*4882a593Smuzhiyun 
738*4882a593Smuzhiyun void tep_filter_free(struct tep_event_filter *filter);
739*4882a593Smuzhiyun 
740*4882a593Smuzhiyun char *tep_filter_make_string(struct tep_event_filter *filter, int event_id);
741*4882a593Smuzhiyun 
742*4882a593Smuzhiyun int tep_filter_remove_event(struct tep_event_filter *filter,
743*4882a593Smuzhiyun 			    int event_id);
744*4882a593Smuzhiyun 
745*4882a593Smuzhiyun int tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *source);
746*4882a593Smuzhiyun 
747*4882a593Smuzhiyun int tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2);
748*4882a593Smuzhiyun 
749*4882a593Smuzhiyun #endif /* _PARSE_EVENTS_H */
750