18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: LGPL-2.1 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#ifndef _PARSE_EVENTS_H
78c2ecf20Sopenharmony_ci#define _PARSE_EVENTS_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <stdbool.h>
108c2ecf20Sopenharmony_ci#include <stdarg.h>
118c2ecf20Sopenharmony_ci#include <stdio.h>
128c2ecf20Sopenharmony_ci#include <regex.h>
138c2ecf20Sopenharmony_ci#include <string.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include "trace-seq.h"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#ifndef __maybe_unused
188c2ecf20Sopenharmony_ci#define __maybe_unused __attribute__((unused))
198c2ecf20Sopenharmony_ci#endif
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#ifndef DEBUG_RECORD
228c2ecf20Sopenharmony_ci#define DEBUG_RECORD 0
238c2ecf20Sopenharmony_ci#endif
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistruct tep_record {
268c2ecf20Sopenharmony_ci	unsigned long long	ts;
278c2ecf20Sopenharmony_ci	unsigned long long	offset;
288c2ecf20Sopenharmony_ci	long long		missed_events;	/* buffer dropped events before */
298c2ecf20Sopenharmony_ci	int			record_size;	/* size of binary record */
308c2ecf20Sopenharmony_ci	int			size;		/* size of data */
318c2ecf20Sopenharmony_ci	void			*data;
328c2ecf20Sopenharmony_ci	int			cpu;
338c2ecf20Sopenharmony_ci	int			ref_count;
348c2ecf20Sopenharmony_ci	int			locked;		/* Do not free, even if ref_count is zero */
358c2ecf20Sopenharmony_ci	void			*priv;
368c2ecf20Sopenharmony_ci#if DEBUG_RECORD
378c2ecf20Sopenharmony_ci	struct tep_record	*prev;
388c2ecf20Sopenharmony_ci	struct tep_record	*next;
398c2ecf20Sopenharmony_ci	long			alloc_addr;
408c2ecf20Sopenharmony_ci#endif
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/* ----------------------- tep ----------------------- */
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistruct tep_handle;
468c2ecf20Sopenharmony_cistruct tep_event;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_citypedef int (*tep_event_handler_func)(struct trace_seq *s,
498c2ecf20Sopenharmony_ci				      struct tep_record *record,
508c2ecf20Sopenharmony_ci				      struct tep_event *event,
518c2ecf20Sopenharmony_ci				      void *context);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_citypedef int (*tep_plugin_load_func)(struct tep_handle *tep);
548c2ecf20Sopenharmony_citypedef int (*tep_plugin_unload_func)(struct tep_handle *tep);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistruct tep_plugin_option {
578c2ecf20Sopenharmony_ci	struct tep_plugin_option	*next;
588c2ecf20Sopenharmony_ci	void				*handle;
598c2ecf20Sopenharmony_ci	char				*file;
608c2ecf20Sopenharmony_ci	char				*name;
618c2ecf20Sopenharmony_ci	char				*plugin_alias;
628c2ecf20Sopenharmony_ci	char				*description;
638c2ecf20Sopenharmony_ci	const char			*value;
648c2ecf20Sopenharmony_ci	void				*priv;
658c2ecf20Sopenharmony_ci	int				set;
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/*
698c2ecf20Sopenharmony_ci * Plugin hooks that can be called:
708c2ecf20Sopenharmony_ci *
718c2ecf20Sopenharmony_ci * TEP_PLUGIN_LOADER:  (required)
728c2ecf20Sopenharmony_ci *   The function name to initialized the plugin.
738c2ecf20Sopenharmony_ci *
748c2ecf20Sopenharmony_ci *   int TEP_PLUGIN_LOADER(struct tep_handle *tep)
758c2ecf20Sopenharmony_ci *
768c2ecf20Sopenharmony_ci * TEP_PLUGIN_UNLOADER:  (optional)
778c2ecf20Sopenharmony_ci *   The function called just before unloading
788c2ecf20Sopenharmony_ci *
798c2ecf20Sopenharmony_ci *   int TEP_PLUGIN_UNLOADER(struct tep_handle *tep)
808c2ecf20Sopenharmony_ci *
818c2ecf20Sopenharmony_ci * TEP_PLUGIN_OPTIONS:  (optional)
828c2ecf20Sopenharmony_ci *   Plugin options that can be set before loading
838c2ecf20Sopenharmony_ci *
848c2ecf20Sopenharmony_ci *   struct tep_plugin_option TEP_PLUGIN_OPTIONS[] = {
858c2ecf20Sopenharmony_ci *	{
868c2ecf20Sopenharmony_ci *		.name = "option-name",
878c2ecf20Sopenharmony_ci *		.plugin_alias = "override-file-name", (optional)
888c2ecf20Sopenharmony_ci *		.description = "description of option to show users",
898c2ecf20Sopenharmony_ci *	},
908c2ecf20Sopenharmony_ci *	{
918c2ecf20Sopenharmony_ci *		.name = NULL,
928c2ecf20Sopenharmony_ci *	},
938c2ecf20Sopenharmony_ci *   };
948c2ecf20Sopenharmony_ci *
958c2ecf20Sopenharmony_ci *   Array must end with .name = NULL;
968c2ecf20Sopenharmony_ci *
978c2ecf20Sopenharmony_ci *
988c2ecf20Sopenharmony_ci *   .plugin_alias is used to give a shorter name to access
998c2ecf20Sopenharmony_ci *   the vairable. Useful if a plugin handles more than one event.
1008c2ecf20Sopenharmony_ci *
1018c2ecf20Sopenharmony_ci *   If .value is not set, then it is considered a boolean and only
1028c2ecf20Sopenharmony_ci *   .set will be processed. If .value is defined, then it is considered
1038c2ecf20Sopenharmony_ci *   a string option and .set will be ignored.
1048c2ecf20Sopenharmony_ci *
1058c2ecf20Sopenharmony_ci * TEP_PLUGIN_ALIAS: (optional)
1068c2ecf20Sopenharmony_ci *   The name to use for finding options (uses filename if not defined)
1078c2ecf20Sopenharmony_ci */
1088c2ecf20Sopenharmony_ci#define TEP_PLUGIN_LOADER tep_plugin_loader
1098c2ecf20Sopenharmony_ci#define TEP_PLUGIN_UNLOADER tep_plugin_unloader
1108c2ecf20Sopenharmony_ci#define TEP_PLUGIN_OPTIONS tep_plugin_options
1118c2ecf20Sopenharmony_ci#define TEP_PLUGIN_ALIAS tep_plugin_alias
1128c2ecf20Sopenharmony_ci#define _MAKE_STR(x)	#x
1138c2ecf20Sopenharmony_ci#define MAKE_STR(x)	_MAKE_STR(x)
1148c2ecf20Sopenharmony_ci#define TEP_PLUGIN_LOADER_NAME MAKE_STR(TEP_PLUGIN_LOADER)
1158c2ecf20Sopenharmony_ci#define TEP_PLUGIN_UNLOADER_NAME MAKE_STR(TEP_PLUGIN_UNLOADER)
1168c2ecf20Sopenharmony_ci#define TEP_PLUGIN_OPTIONS_NAME MAKE_STR(TEP_PLUGIN_OPTIONS)
1178c2ecf20Sopenharmony_ci#define TEP_PLUGIN_ALIAS_NAME MAKE_STR(TEP_PLUGIN_ALIAS)
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cienum tep_format_flags {
1208c2ecf20Sopenharmony_ci	TEP_FIELD_IS_ARRAY	= 1,
1218c2ecf20Sopenharmony_ci	TEP_FIELD_IS_POINTER	= 2,
1228c2ecf20Sopenharmony_ci	TEP_FIELD_IS_SIGNED	= 4,
1238c2ecf20Sopenharmony_ci	TEP_FIELD_IS_STRING	= 8,
1248c2ecf20Sopenharmony_ci	TEP_FIELD_IS_DYNAMIC	= 16,
1258c2ecf20Sopenharmony_ci	TEP_FIELD_IS_LONG	= 32,
1268c2ecf20Sopenharmony_ci	TEP_FIELD_IS_FLAG	= 64,
1278c2ecf20Sopenharmony_ci	TEP_FIELD_IS_SYMBOLIC	= 128,
1288c2ecf20Sopenharmony_ci};
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_cistruct tep_format_field {
1318c2ecf20Sopenharmony_ci	struct tep_format_field	*next;
1328c2ecf20Sopenharmony_ci	struct tep_event	*event;
1338c2ecf20Sopenharmony_ci	char			*type;
1348c2ecf20Sopenharmony_ci	char			*name;
1358c2ecf20Sopenharmony_ci	char			*alias;
1368c2ecf20Sopenharmony_ci	int			offset;
1378c2ecf20Sopenharmony_ci	int			size;
1388c2ecf20Sopenharmony_ci	unsigned int		arraylen;
1398c2ecf20Sopenharmony_ci	unsigned int		elementsize;
1408c2ecf20Sopenharmony_ci	unsigned long		flags;
1418c2ecf20Sopenharmony_ci};
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_cistruct tep_format {
1448c2ecf20Sopenharmony_ci	int			nr_common;
1458c2ecf20Sopenharmony_ci	int			nr_fields;
1468c2ecf20Sopenharmony_ci	struct tep_format_field	*common_fields;
1478c2ecf20Sopenharmony_ci	struct tep_format_field	*fields;
1488c2ecf20Sopenharmony_ci};
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistruct tep_print_arg_atom {
1518c2ecf20Sopenharmony_ci	char			*atom;
1528c2ecf20Sopenharmony_ci};
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistruct tep_print_arg_string {
1558c2ecf20Sopenharmony_ci	char			*string;
1568c2ecf20Sopenharmony_ci	int			offset;
1578c2ecf20Sopenharmony_ci};
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_cistruct tep_print_arg_bitmask {
1608c2ecf20Sopenharmony_ci	char			*bitmask;
1618c2ecf20Sopenharmony_ci	int			offset;
1628c2ecf20Sopenharmony_ci};
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cistruct tep_print_arg_field {
1658c2ecf20Sopenharmony_ci	char			*name;
1668c2ecf20Sopenharmony_ci	struct tep_format_field	*field;
1678c2ecf20Sopenharmony_ci};
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_cistruct tep_print_flag_sym {
1708c2ecf20Sopenharmony_ci	struct tep_print_flag_sym	*next;
1718c2ecf20Sopenharmony_ci	char				*value;
1728c2ecf20Sopenharmony_ci	char				*str;
1738c2ecf20Sopenharmony_ci};
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistruct tep_print_arg_typecast {
1768c2ecf20Sopenharmony_ci	char 			*type;
1778c2ecf20Sopenharmony_ci	struct tep_print_arg	*item;
1788c2ecf20Sopenharmony_ci};
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistruct tep_print_arg_flags {
1818c2ecf20Sopenharmony_ci	struct tep_print_arg		*field;
1828c2ecf20Sopenharmony_ci	char				*delim;
1838c2ecf20Sopenharmony_ci	struct tep_print_flag_sym	*flags;
1848c2ecf20Sopenharmony_ci};
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_cistruct tep_print_arg_symbol {
1878c2ecf20Sopenharmony_ci	struct tep_print_arg		*field;
1888c2ecf20Sopenharmony_ci	struct tep_print_flag_sym	*symbols;
1898c2ecf20Sopenharmony_ci};
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_cistruct tep_print_arg_hex {
1928c2ecf20Sopenharmony_ci	struct tep_print_arg	*field;
1938c2ecf20Sopenharmony_ci	struct tep_print_arg	*size;
1948c2ecf20Sopenharmony_ci};
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistruct tep_print_arg_int_array {
1978c2ecf20Sopenharmony_ci	struct tep_print_arg	*field;
1988c2ecf20Sopenharmony_ci	struct tep_print_arg	*count;
1998c2ecf20Sopenharmony_ci	struct tep_print_arg	*el_size;
2008c2ecf20Sopenharmony_ci};
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_cistruct tep_print_arg_dynarray {
2038c2ecf20Sopenharmony_ci	struct tep_format_field	*field;
2048c2ecf20Sopenharmony_ci	struct tep_print_arg	*index;
2058c2ecf20Sopenharmony_ci};
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cistruct tep_print_arg;
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistruct tep_print_arg_op {
2108c2ecf20Sopenharmony_ci	char			*op;
2118c2ecf20Sopenharmony_ci	int			prio;
2128c2ecf20Sopenharmony_ci	struct tep_print_arg	*left;
2138c2ecf20Sopenharmony_ci	struct tep_print_arg	*right;
2148c2ecf20Sopenharmony_ci};
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_cistruct tep_function_handler;
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_cistruct tep_print_arg_func {
2198c2ecf20Sopenharmony_ci	struct tep_function_handler	*func;
2208c2ecf20Sopenharmony_ci	struct tep_print_arg		*args;
2218c2ecf20Sopenharmony_ci};
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_cienum tep_print_arg_type {
2248c2ecf20Sopenharmony_ci	TEP_PRINT_NULL,
2258c2ecf20Sopenharmony_ci	TEP_PRINT_ATOM,
2268c2ecf20Sopenharmony_ci	TEP_PRINT_FIELD,
2278c2ecf20Sopenharmony_ci	TEP_PRINT_FLAGS,
2288c2ecf20Sopenharmony_ci	TEP_PRINT_SYMBOL,
2298c2ecf20Sopenharmony_ci	TEP_PRINT_HEX,
2308c2ecf20Sopenharmony_ci	TEP_PRINT_INT_ARRAY,
2318c2ecf20Sopenharmony_ci	TEP_PRINT_TYPE,
2328c2ecf20Sopenharmony_ci	TEP_PRINT_STRING,
2338c2ecf20Sopenharmony_ci	TEP_PRINT_BSTRING,
2348c2ecf20Sopenharmony_ci	TEP_PRINT_DYNAMIC_ARRAY,
2358c2ecf20Sopenharmony_ci	TEP_PRINT_OP,
2368c2ecf20Sopenharmony_ci	TEP_PRINT_FUNC,
2378c2ecf20Sopenharmony_ci	TEP_PRINT_BITMASK,
2388c2ecf20Sopenharmony_ci	TEP_PRINT_DYNAMIC_ARRAY_LEN,
2398c2ecf20Sopenharmony_ci	TEP_PRINT_HEX_STR,
2408c2ecf20Sopenharmony_ci};
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_cistruct tep_print_arg {
2438c2ecf20Sopenharmony_ci	struct tep_print_arg		*next;
2448c2ecf20Sopenharmony_ci	enum tep_print_arg_type		type;
2458c2ecf20Sopenharmony_ci	union {
2468c2ecf20Sopenharmony_ci		struct tep_print_arg_atom	atom;
2478c2ecf20Sopenharmony_ci		struct tep_print_arg_field	field;
2488c2ecf20Sopenharmony_ci		struct tep_print_arg_typecast	typecast;
2498c2ecf20Sopenharmony_ci		struct tep_print_arg_flags	flags;
2508c2ecf20Sopenharmony_ci		struct tep_print_arg_symbol	symbol;
2518c2ecf20Sopenharmony_ci		struct tep_print_arg_hex	hex;
2528c2ecf20Sopenharmony_ci		struct tep_print_arg_int_array	int_array;
2538c2ecf20Sopenharmony_ci		struct tep_print_arg_func	func;
2548c2ecf20Sopenharmony_ci		struct tep_print_arg_string	string;
2558c2ecf20Sopenharmony_ci		struct tep_print_arg_bitmask	bitmask;
2568c2ecf20Sopenharmony_ci		struct tep_print_arg_op		op;
2578c2ecf20Sopenharmony_ci		struct tep_print_arg_dynarray	dynarray;
2588c2ecf20Sopenharmony_ci	};
2598c2ecf20Sopenharmony_ci};
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_cistruct tep_print_parse;
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_cistruct tep_print_fmt {
2648c2ecf20Sopenharmony_ci	char			*format;
2658c2ecf20Sopenharmony_ci	struct tep_print_arg	*args;
2668c2ecf20Sopenharmony_ci	struct tep_print_parse	*print_cache;
2678c2ecf20Sopenharmony_ci};
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_cistruct tep_event {
2708c2ecf20Sopenharmony_ci	struct tep_handle	*tep;
2718c2ecf20Sopenharmony_ci	char			*name;
2728c2ecf20Sopenharmony_ci	int			id;
2738c2ecf20Sopenharmony_ci	int			flags;
2748c2ecf20Sopenharmony_ci	struct tep_format	format;
2758c2ecf20Sopenharmony_ci	struct tep_print_fmt	print_fmt;
2768c2ecf20Sopenharmony_ci	char			*system;
2778c2ecf20Sopenharmony_ci	tep_event_handler_func	handler;
2788c2ecf20Sopenharmony_ci	void			*context;
2798c2ecf20Sopenharmony_ci};
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_cienum {
2828c2ecf20Sopenharmony_ci	TEP_EVENT_FL_ISFTRACE	= 0x01,
2838c2ecf20Sopenharmony_ci	TEP_EVENT_FL_ISPRINT	= 0x02,
2848c2ecf20Sopenharmony_ci	TEP_EVENT_FL_ISBPRINT	= 0x04,
2858c2ecf20Sopenharmony_ci	TEP_EVENT_FL_ISFUNCENT	= 0x10,
2868c2ecf20Sopenharmony_ci	TEP_EVENT_FL_ISFUNCRET	= 0x20,
2878c2ecf20Sopenharmony_ci	TEP_EVENT_FL_NOHANDLE	= 0x40,
2888c2ecf20Sopenharmony_ci	TEP_EVENT_FL_PRINTRAW	= 0x80,
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	TEP_EVENT_FL_FAILED	= 0x80000000
2918c2ecf20Sopenharmony_ci};
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_cienum tep_event_sort_type {
2948c2ecf20Sopenharmony_ci	TEP_EVENT_SORT_ID,
2958c2ecf20Sopenharmony_ci	TEP_EVENT_SORT_NAME,
2968c2ecf20Sopenharmony_ci	TEP_EVENT_SORT_SYSTEM,
2978c2ecf20Sopenharmony_ci};
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_cienum tep_event_type {
3008c2ecf20Sopenharmony_ci	TEP_EVENT_ERROR,
3018c2ecf20Sopenharmony_ci	TEP_EVENT_NONE,
3028c2ecf20Sopenharmony_ci	TEP_EVENT_SPACE,
3038c2ecf20Sopenharmony_ci	TEP_EVENT_NEWLINE,
3048c2ecf20Sopenharmony_ci	TEP_EVENT_OP,
3058c2ecf20Sopenharmony_ci	TEP_EVENT_DELIM,
3068c2ecf20Sopenharmony_ci	TEP_EVENT_ITEM,
3078c2ecf20Sopenharmony_ci	TEP_EVENT_DQUOTE,
3088c2ecf20Sopenharmony_ci	TEP_EVENT_SQUOTE,
3098c2ecf20Sopenharmony_ci};
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_citypedef unsigned long long (*tep_func_handler)(struct trace_seq *s,
3128c2ecf20Sopenharmony_ci					       unsigned long long *args);
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_cienum tep_func_arg_type {
3158c2ecf20Sopenharmony_ci	TEP_FUNC_ARG_VOID,
3168c2ecf20Sopenharmony_ci	TEP_FUNC_ARG_INT,
3178c2ecf20Sopenharmony_ci	TEP_FUNC_ARG_LONG,
3188c2ecf20Sopenharmony_ci	TEP_FUNC_ARG_STRING,
3198c2ecf20Sopenharmony_ci	TEP_FUNC_ARG_PTR,
3208c2ecf20Sopenharmony_ci	TEP_FUNC_ARG_MAX_TYPES
3218c2ecf20Sopenharmony_ci};
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_cienum tep_flag {
3248c2ecf20Sopenharmony_ci	TEP_NSEC_OUTPUT		= 1,	/* output in NSECS */
3258c2ecf20Sopenharmony_ci	TEP_DISABLE_SYS_PLUGINS	= 1 << 1,
3268c2ecf20Sopenharmony_ci	TEP_DISABLE_PLUGINS	= 1 << 2,
3278c2ecf20Sopenharmony_ci};
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci#define TEP_ERRORS 							      \
3308c2ecf20Sopenharmony_ci	_PE(MEM_ALLOC_FAILED,	"failed to allocate memory"),		      \
3318c2ecf20Sopenharmony_ci	_PE(PARSE_EVENT_FAILED,	"failed to parse event"),		      \
3328c2ecf20Sopenharmony_ci	_PE(READ_ID_FAILED,	"failed to read event id"),		      \
3338c2ecf20Sopenharmony_ci	_PE(READ_FORMAT_FAILED,	"failed to read event format"),		      \
3348c2ecf20Sopenharmony_ci	_PE(READ_PRINT_FAILED,	"failed to read event print fmt"), 	      \
3358c2ecf20Sopenharmony_ci	_PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
3368c2ecf20Sopenharmony_ci	_PE(INVALID_ARG_TYPE,	"invalid argument type"),		      \
3378c2ecf20Sopenharmony_ci	_PE(INVALID_EXP_TYPE,	"invalid expression type"),		      \
3388c2ecf20Sopenharmony_ci	_PE(INVALID_OP_TYPE,	"invalid operator type"),		      \
3398c2ecf20Sopenharmony_ci	_PE(INVALID_EVENT_NAME,	"invalid event name"),			      \
3408c2ecf20Sopenharmony_ci	_PE(EVENT_NOT_FOUND,	"no event found"),			      \
3418c2ecf20Sopenharmony_ci	_PE(SYNTAX_ERROR,	"syntax error"),			      \
3428c2ecf20Sopenharmony_ci	_PE(ILLEGAL_RVALUE,	"illegal rvalue"),			      \
3438c2ecf20Sopenharmony_ci	_PE(ILLEGAL_LVALUE,	"illegal lvalue for string comparison"),      \
3448c2ecf20Sopenharmony_ci	_PE(INVALID_REGEX,	"regex did not compute"),		      \
3458c2ecf20Sopenharmony_ci	_PE(ILLEGAL_STRING_CMP,	"illegal comparison for string"), 	      \
3468c2ecf20Sopenharmony_ci	_PE(ILLEGAL_INTEGER_CMP,"illegal comparison for integer"), 	      \
3478c2ecf20Sopenharmony_ci	_PE(REPARENT_NOT_OP,	"cannot reparent other than OP"),	      \
3488c2ecf20Sopenharmony_ci	_PE(REPARENT_FAILED,	"failed to reparent filter OP"),	      \
3498c2ecf20Sopenharmony_ci	_PE(BAD_FILTER_ARG,	"bad arg in filter tree"),		      \
3508c2ecf20Sopenharmony_ci	_PE(UNEXPECTED_TYPE,	"unexpected type (not a value)"),	      \
3518c2ecf20Sopenharmony_ci	_PE(ILLEGAL_TOKEN,	"illegal token"),			      \
3528c2ecf20Sopenharmony_ci	_PE(INVALID_PAREN,	"open parenthesis cannot come here"), 	      \
3538c2ecf20Sopenharmony_ci	_PE(UNBALANCED_PAREN,	"unbalanced number of parenthesis"),	      \
3548c2ecf20Sopenharmony_ci	_PE(UNKNOWN_TOKEN,	"unknown token"),			      \
3558c2ecf20Sopenharmony_ci	_PE(FILTER_NOT_FOUND,	"no filter found"),			      \
3568c2ecf20Sopenharmony_ci	_PE(NOT_A_NUMBER,	"must have number field"),		      \
3578c2ecf20Sopenharmony_ci	_PE(NO_FILTER,		"no filters exists"),			      \
3588c2ecf20Sopenharmony_ci	_PE(FILTER_MISS,	"record does not match to filter")
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci#undef _PE
3618c2ecf20Sopenharmony_ci#define _PE(__code, __str) TEP_ERRNO__ ## __code
3628c2ecf20Sopenharmony_cienum tep_errno {
3638c2ecf20Sopenharmony_ci	TEP_ERRNO__SUCCESS			= 0,
3648c2ecf20Sopenharmony_ci	TEP_ERRNO__FILTER_MATCH			= TEP_ERRNO__SUCCESS,
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci	/*
3678c2ecf20Sopenharmony_ci	 * Choose an arbitrary negative big number not to clash with standard
3688c2ecf20Sopenharmony_ci	 * errno since SUS requires the errno has distinct positive values.
3698c2ecf20Sopenharmony_ci	 * See 'Issue 6' in the link below.
3708c2ecf20Sopenharmony_ci	 *
3718c2ecf20Sopenharmony_ci	 * https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
3728c2ecf20Sopenharmony_ci	 */
3738c2ecf20Sopenharmony_ci	__TEP_ERRNO__START			= -100000,
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	TEP_ERRORS,
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	__TEP_ERRNO__END,
3788c2ecf20Sopenharmony_ci};
3798c2ecf20Sopenharmony_ci#undef _PE
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_cistruct tep_plugin_list;
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci#define INVALID_PLUGIN_LIST_OPTION	((char **)((unsigned long)-1))
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_cienum tep_plugin_load_priority {
3868c2ecf20Sopenharmony_ci	TEP_PLUGIN_FIRST,
3878c2ecf20Sopenharmony_ci	TEP_PLUGIN_LAST,
3888c2ecf20Sopenharmony_ci};
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ciint tep_add_plugin_path(struct tep_handle *tep, char *path,
3918c2ecf20Sopenharmony_ci			enum tep_plugin_load_priority prio);
3928c2ecf20Sopenharmony_cistruct tep_plugin_list *tep_load_plugins(struct tep_handle *tep);
3938c2ecf20Sopenharmony_civoid tep_unload_plugins(struct tep_plugin_list *plugin_list,
3948c2ecf20Sopenharmony_ci			struct tep_handle *tep);
3958c2ecf20Sopenharmony_civoid tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
3968c2ecf20Sopenharmony_ci			   void (*load_plugin)(struct tep_handle *tep,
3978c2ecf20Sopenharmony_ci					       const char *path,
3988c2ecf20Sopenharmony_ci					       const char *name,
3998c2ecf20Sopenharmony_ci					       void *data),
4008c2ecf20Sopenharmony_ci			   void *data);
4018c2ecf20Sopenharmony_cichar **tep_plugin_list_options(void);
4028c2ecf20Sopenharmony_civoid tep_plugin_free_options_list(char **list);
4038c2ecf20Sopenharmony_ciint tep_plugin_add_options(const char *name,
4048c2ecf20Sopenharmony_ci			   struct tep_plugin_option *options);
4058c2ecf20Sopenharmony_ciint tep_plugin_add_option(const char *name, const char *val);
4068c2ecf20Sopenharmony_civoid tep_plugin_remove_options(struct tep_plugin_option *options);
4078c2ecf20Sopenharmony_civoid tep_plugin_print_options(struct trace_seq *s);
4088c2ecf20Sopenharmony_civoid tep_print_plugins(struct trace_seq *s,
4098c2ecf20Sopenharmony_ci			const char *prefix, const char *suffix,
4108c2ecf20Sopenharmony_ci			const struct tep_plugin_list *list);
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci/* tep_handle */
4138c2ecf20Sopenharmony_citypedef char *(tep_func_resolver_t)(void *priv,
4148c2ecf20Sopenharmony_ci				    unsigned long long *addrp, char **modp);
4158c2ecf20Sopenharmony_civoid tep_set_flag(struct tep_handle *tep, int flag);
4168c2ecf20Sopenharmony_civoid tep_clear_flag(struct tep_handle *tep, enum tep_flag flag);
4178c2ecf20Sopenharmony_cibool tep_test_flag(struct tep_handle *tep, enum tep_flag flags);
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_cistatic inline int tep_is_bigendian(void)
4208c2ecf20Sopenharmony_ci{
4218c2ecf20Sopenharmony_ci	unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
4228c2ecf20Sopenharmony_ci	unsigned int val;
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	memcpy(&val, str, 4);
4258c2ecf20Sopenharmony_ci	return val == 0x01020304;
4268c2ecf20Sopenharmony_ci}
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci/* taken from kernel/trace/trace.h */
4298c2ecf20Sopenharmony_cienum trace_flag_type {
4308c2ecf20Sopenharmony_ci	TRACE_FLAG_IRQS_OFF		= 0x01,
4318c2ecf20Sopenharmony_ci	TRACE_FLAG_IRQS_NOSUPPORT	= 0x02,
4328c2ecf20Sopenharmony_ci	TRACE_FLAG_NEED_RESCHED		= 0x04,
4338c2ecf20Sopenharmony_ci	TRACE_FLAG_HARDIRQ		= 0x08,
4348c2ecf20Sopenharmony_ci	TRACE_FLAG_SOFTIRQ		= 0x10,
4358c2ecf20Sopenharmony_ci};
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ciint tep_set_function_resolver(struct tep_handle *tep,
4388c2ecf20Sopenharmony_ci			      tep_func_resolver_t *func, void *priv);
4398c2ecf20Sopenharmony_civoid tep_reset_function_resolver(struct tep_handle *tep);
4408c2ecf20Sopenharmony_ciint tep_register_comm(struct tep_handle *tep, const char *comm, int pid);
4418c2ecf20Sopenharmony_ciint tep_override_comm(struct tep_handle *tep, const char *comm, int pid);
4428c2ecf20Sopenharmony_ciint tep_register_function(struct tep_handle *tep, char *name,
4438c2ecf20Sopenharmony_ci			  unsigned long long addr, char *mod);
4448c2ecf20Sopenharmony_ciint tep_register_print_string(struct tep_handle *tep, const char *fmt,
4458c2ecf20Sopenharmony_ci			      unsigned long long addr);
4468c2ecf20Sopenharmony_cibool tep_is_pid_registered(struct tep_handle *tep, int pid);
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_cistruct tep_event *tep_get_event(struct tep_handle *tep, int index);
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci#define TEP_PRINT_INFO		"INFO"
4518c2ecf20Sopenharmony_ci#define TEP_PRINT_INFO_RAW	"INFO_RAW"
4528c2ecf20Sopenharmony_ci#define TEP_PRINT_COMM		"COMM"
4538c2ecf20Sopenharmony_ci#define TEP_PRINT_LATENCY	"LATENCY"
4548c2ecf20Sopenharmony_ci#define TEP_PRINT_NAME		"NAME"
4558c2ecf20Sopenharmony_ci#define TEP_PRINT_PID		1U
4568c2ecf20Sopenharmony_ci#define TEP_PRINT_TIME		2U
4578c2ecf20Sopenharmony_ci#define TEP_PRINT_CPU		3U
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_civoid tep_print_event(struct tep_handle *tep, struct trace_seq *s,
4608c2ecf20Sopenharmony_ci		     struct tep_record *record, const char *fmt, ...)
4618c2ecf20Sopenharmony_ci	__attribute__ ((format (printf, 4, 5)));
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ciint tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size,
4648c2ecf20Sopenharmony_ci			  int long_size);
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_cienum tep_errno tep_parse_event(struct tep_handle *tep, const char *buf,
4678c2ecf20Sopenharmony_ci			       unsigned long size, const char *sys);
4688c2ecf20Sopenharmony_cienum tep_errno tep_parse_format(struct tep_handle *tep,
4698c2ecf20Sopenharmony_ci				struct tep_event **eventp,
4708c2ecf20Sopenharmony_ci				const char *buf,
4718c2ecf20Sopenharmony_ci				unsigned long size, const char *sys);
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_civoid *tep_get_field_raw(struct trace_seq *s, struct tep_event *event,
4748c2ecf20Sopenharmony_ci			const char *name, struct tep_record *record,
4758c2ecf20Sopenharmony_ci			int *len, int err);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ciint tep_get_field_val(struct trace_seq *s, struct tep_event *event,
4788c2ecf20Sopenharmony_ci		      const char *name, struct tep_record *record,
4798c2ecf20Sopenharmony_ci		      unsigned long long *val, int err);
4808c2ecf20Sopenharmony_ciint tep_get_common_field_val(struct trace_seq *s, struct tep_event *event,
4818c2ecf20Sopenharmony_ci			     const char *name, struct tep_record *record,
4828c2ecf20Sopenharmony_ci			     unsigned long long *val, int err);
4838c2ecf20Sopenharmony_ciint tep_get_any_field_val(struct trace_seq *s, struct tep_event *event,
4848c2ecf20Sopenharmony_ci			  const char *name, struct tep_record *record,
4858c2ecf20Sopenharmony_ci			  unsigned long long *val, int err);
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ciint tep_print_num_field(struct trace_seq *s, const char *fmt,
4888c2ecf20Sopenharmony_ci			struct tep_event *event, const char *name,
4898c2ecf20Sopenharmony_ci			struct tep_record *record, int err);
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ciint tep_print_func_field(struct trace_seq *s, const char *fmt,
4928c2ecf20Sopenharmony_ci			 struct tep_event *event, const char *name,
4938c2ecf20Sopenharmony_ci			 struct tep_record *record, int err);
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_cienum tep_reg_handler {
4968c2ecf20Sopenharmony_ci	TEP_REGISTER_SUCCESS = 0,
4978c2ecf20Sopenharmony_ci	TEP_REGISTER_SUCCESS_OVERWRITE,
4988c2ecf20Sopenharmony_ci};
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ciint tep_register_event_handler(struct tep_handle *tep, int id,
5018c2ecf20Sopenharmony_ci			       const char *sys_name, const char *event_name,
5028c2ecf20Sopenharmony_ci			       tep_event_handler_func func, void *context);
5038c2ecf20Sopenharmony_ciint tep_unregister_event_handler(struct tep_handle *tep, int id,
5048c2ecf20Sopenharmony_ci				 const char *sys_name, const char *event_name,
5058c2ecf20Sopenharmony_ci				 tep_event_handler_func func, void *context);
5068c2ecf20Sopenharmony_ciint tep_register_print_function(struct tep_handle *tep,
5078c2ecf20Sopenharmony_ci				tep_func_handler func,
5088c2ecf20Sopenharmony_ci				enum tep_func_arg_type ret_type,
5098c2ecf20Sopenharmony_ci				char *name, ...);
5108c2ecf20Sopenharmony_ciint tep_unregister_print_function(struct tep_handle *tep,
5118c2ecf20Sopenharmony_ci				  tep_func_handler func, char *name);
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_cistruct tep_format_field *tep_find_common_field(struct tep_event *event, const char *name);
5148c2ecf20Sopenharmony_cistruct tep_format_field *tep_find_field(struct tep_event *event, const char *name);
5158c2ecf20Sopenharmony_cistruct tep_format_field *tep_find_any_field(struct tep_event *event, const char *name);
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ciconst char *tep_find_function(struct tep_handle *tep, unsigned long long addr);
5188c2ecf20Sopenharmony_ciunsigned long long
5198c2ecf20Sopenharmony_citep_find_function_address(struct tep_handle *tep, unsigned long long addr);
5208c2ecf20Sopenharmony_ciunsigned long long tep_read_number(struct tep_handle *tep, const void *ptr, int size);
5218c2ecf20Sopenharmony_ciint tep_read_number_field(struct tep_format_field *field, const void *data,
5228c2ecf20Sopenharmony_ci			  unsigned long long *value);
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_cistruct tep_event *tep_get_first_event(struct tep_handle *tep);
5258c2ecf20Sopenharmony_ciint tep_get_events_count(struct tep_handle *tep);
5268c2ecf20Sopenharmony_cistruct tep_event *tep_find_event(struct tep_handle *tep, int id);
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_cistruct tep_event *
5298c2ecf20Sopenharmony_citep_find_event_by_name(struct tep_handle *tep, const char *sys, const char *name);
5308c2ecf20Sopenharmony_cistruct tep_event *
5318c2ecf20Sopenharmony_citep_find_event_by_record(struct tep_handle *tep, struct tep_record *record);
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_ciint tep_data_type(struct tep_handle *tep, struct tep_record *rec);
5348c2ecf20Sopenharmony_ciint tep_data_pid(struct tep_handle *tep, struct tep_record *rec);
5358c2ecf20Sopenharmony_ciint tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec);
5368c2ecf20Sopenharmony_ciint tep_data_flags(struct tep_handle *tep, struct tep_record *rec);
5378c2ecf20Sopenharmony_ciconst char *tep_data_comm_from_pid(struct tep_handle *tep, int pid);
5388c2ecf20Sopenharmony_cistruct tep_cmdline;
5398c2ecf20Sopenharmony_cistruct tep_cmdline *tep_data_pid_from_comm(struct tep_handle *tep, const char *comm,
5408c2ecf20Sopenharmony_ci					   struct tep_cmdline *next);
5418c2ecf20Sopenharmony_ciint tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline);
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_civoid tep_print_field(struct trace_seq *s, void *data,
5448c2ecf20Sopenharmony_ci		     struct tep_format_field *field);
5458c2ecf20Sopenharmony_civoid tep_print_fields(struct trace_seq *s, void *data,
5468c2ecf20Sopenharmony_ci		      int size __maybe_unused, struct tep_event *event);
5478c2ecf20Sopenharmony_ciint tep_strerror(struct tep_handle *tep, enum tep_errno errnum,
5488c2ecf20Sopenharmony_ci		 char *buf, size_t buflen);
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_cistruct tep_event **tep_list_events(struct tep_handle *tep, enum tep_event_sort_type);
5518c2ecf20Sopenharmony_cistruct tep_event **tep_list_events_copy(struct tep_handle *tep,
5528c2ecf20Sopenharmony_ci					enum tep_event_sort_type);
5538c2ecf20Sopenharmony_cistruct tep_format_field **tep_event_common_fields(struct tep_event *event);
5548c2ecf20Sopenharmony_cistruct tep_format_field **tep_event_fields(struct tep_event *event);
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_cienum tep_endian {
5578c2ecf20Sopenharmony_ci        TEP_LITTLE_ENDIAN = 0,
5588c2ecf20Sopenharmony_ci        TEP_BIG_ENDIAN
5598c2ecf20Sopenharmony_ci};
5608c2ecf20Sopenharmony_ciint tep_get_cpus(struct tep_handle *tep);
5618c2ecf20Sopenharmony_civoid tep_set_cpus(struct tep_handle *tep, int cpus);
5628c2ecf20Sopenharmony_ciint tep_get_long_size(struct tep_handle *tep);
5638c2ecf20Sopenharmony_civoid tep_set_long_size(struct tep_handle *tep, int long_size);
5648c2ecf20Sopenharmony_ciint tep_get_page_size(struct tep_handle *tep);
5658c2ecf20Sopenharmony_civoid tep_set_page_size(struct tep_handle *tep, int _page_size);
5668c2ecf20Sopenharmony_cibool tep_is_file_bigendian(struct tep_handle *tep);
5678c2ecf20Sopenharmony_civoid tep_set_file_bigendian(struct tep_handle *tep, enum tep_endian endian);
5688c2ecf20Sopenharmony_cibool tep_is_local_bigendian(struct tep_handle *tep);
5698c2ecf20Sopenharmony_civoid tep_set_local_bigendian(struct tep_handle *tep, enum tep_endian endian);
5708c2ecf20Sopenharmony_ciint tep_get_header_page_size(struct tep_handle *tep);
5718c2ecf20Sopenharmony_ciint tep_get_header_timestamp_size(struct tep_handle *tep);
5728c2ecf20Sopenharmony_cibool tep_is_old_format(struct tep_handle *tep);
5738c2ecf20Sopenharmony_civoid tep_set_test_filters(struct tep_handle *tep, int test_filters);
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_cistruct tep_handle *tep_alloc(void);
5768c2ecf20Sopenharmony_civoid tep_free(struct tep_handle *tep);
5778c2ecf20Sopenharmony_civoid tep_ref(struct tep_handle *tep);
5788c2ecf20Sopenharmony_civoid tep_unref(struct tep_handle *tep);
5798c2ecf20Sopenharmony_ciint tep_get_ref(struct tep_handle *tep);
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_ci/* for debugging */
5828c2ecf20Sopenharmony_civoid tep_print_funcs(struct tep_handle *tep);
5838c2ecf20Sopenharmony_civoid tep_print_printk(struct tep_handle *tep);
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_ci/* ----------------------- filtering ----------------------- */
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_cienum tep_filter_boolean_type {
5888c2ecf20Sopenharmony_ci	TEP_FILTER_FALSE,
5898c2ecf20Sopenharmony_ci	TEP_FILTER_TRUE,
5908c2ecf20Sopenharmony_ci};
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_cienum tep_filter_op_type {
5938c2ecf20Sopenharmony_ci	TEP_FILTER_OP_AND = 1,
5948c2ecf20Sopenharmony_ci	TEP_FILTER_OP_OR,
5958c2ecf20Sopenharmony_ci	TEP_FILTER_OP_NOT,
5968c2ecf20Sopenharmony_ci};
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_cienum tep_filter_cmp_type {
5998c2ecf20Sopenharmony_ci	TEP_FILTER_CMP_NONE,
6008c2ecf20Sopenharmony_ci	TEP_FILTER_CMP_EQ,
6018c2ecf20Sopenharmony_ci	TEP_FILTER_CMP_NE,
6028c2ecf20Sopenharmony_ci	TEP_FILTER_CMP_GT,
6038c2ecf20Sopenharmony_ci	TEP_FILTER_CMP_LT,
6048c2ecf20Sopenharmony_ci	TEP_FILTER_CMP_GE,
6058c2ecf20Sopenharmony_ci	TEP_FILTER_CMP_LE,
6068c2ecf20Sopenharmony_ci	TEP_FILTER_CMP_MATCH,
6078c2ecf20Sopenharmony_ci	TEP_FILTER_CMP_NOT_MATCH,
6088c2ecf20Sopenharmony_ci	TEP_FILTER_CMP_REGEX,
6098c2ecf20Sopenharmony_ci	TEP_FILTER_CMP_NOT_REGEX,
6108c2ecf20Sopenharmony_ci};
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_cienum tep_filter_exp_type {
6138c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_NONE,
6148c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_ADD,
6158c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_SUB,
6168c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_MUL,
6178c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_DIV,
6188c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_MOD,
6198c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_RSHIFT,
6208c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_LSHIFT,
6218c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_AND,
6228c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_OR,
6238c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_XOR,
6248c2ecf20Sopenharmony_ci	TEP_FILTER_EXP_NOT,
6258c2ecf20Sopenharmony_ci};
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_cienum tep_filter_arg_type {
6288c2ecf20Sopenharmony_ci	TEP_FILTER_ARG_NONE,
6298c2ecf20Sopenharmony_ci	TEP_FILTER_ARG_BOOLEAN,
6308c2ecf20Sopenharmony_ci	TEP_FILTER_ARG_VALUE,
6318c2ecf20Sopenharmony_ci	TEP_FILTER_ARG_FIELD,
6328c2ecf20Sopenharmony_ci	TEP_FILTER_ARG_EXP,
6338c2ecf20Sopenharmony_ci	TEP_FILTER_ARG_OP,
6348c2ecf20Sopenharmony_ci	TEP_FILTER_ARG_NUM,
6358c2ecf20Sopenharmony_ci	TEP_FILTER_ARG_STR,
6368c2ecf20Sopenharmony_ci};
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_cienum tep_filter_value_type {
6398c2ecf20Sopenharmony_ci	TEP_FILTER_NUMBER,
6408c2ecf20Sopenharmony_ci	TEP_FILTER_STRING,
6418c2ecf20Sopenharmony_ci	TEP_FILTER_CHAR
6428c2ecf20Sopenharmony_ci};
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_cistruct tep_filter_arg;
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_cistruct tep_filter_arg_boolean {
6478c2ecf20Sopenharmony_ci	enum tep_filter_boolean_type	value;
6488c2ecf20Sopenharmony_ci};
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_cistruct tep_filter_arg_field {
6518c2ecf20Sopenharmony_ci	struct tep_format_field		*field;
6528c2ecf20Sopenharmony_ci};
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_cistruct tep_filter_arg_value {
6558c2ecf20Sopenharmony_ci	enum tep_filter_value_type	type;
6568c2ecf20Sopenharmony_ci	union {
6578c2ecf20Sopenharmony_ci		char			*str;
6588c2ecf20Sopenharmony_ci		unsigned long long	val;
6598c2ecf20Sopenharmony_ci	};
6608c2ecf20Sopenharmony_ci};
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_cistruct tep_filter_arg_op {
6638c2ecf20Sopenharmony_ci	enum tep_filter_op_type		type;
6648c2ecf20Sopenharmony_ci	struct tep_filter_arg		*left;
6658c2ecf20Sopenharmony_ci	struct tep_filter_arg		*right;
6668c2ecf20Sopenharmony_ci};
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_cistruct tep_filter_arg_exp {
6698c2ecf20Sopenharmony_ci	enum tep_filter_exp_type	type;
6708c2ecf20Sopenharmony_ci	struct tep_filter_arg		*left;
6718c2ecf20Sopenharmony_ci	struct tep_filter_arg		*right;
6728c2ecf20Sopenharmony_ci};
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_cistruct tep_filter_arg_num {
6758c2ecf20Sopenharmony_ci	enum tep_filter_cmp_type	type;
6768c2ecf20Sopenharmony_ci	struct tep_filter_arg		*left;
6778c2ecf20Sopenharmony_ci	struct tep_filter_arg		*right;
6788c2ecf20Sopenharmony_ci};
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_cistruct tep_filter_arg_str {
6818c2ecf20Sopenharmony_ci	enum tep_filter_cmp_type	type;
6828c2ecf20Sopenharmony_ci	struct tep_format_field		*field;
6838c2ecf20Sopenharmony_ci	char				*val;
6848c2ecf20Sopenharmony_ci	char				*buffer;
6858c2ecf20Sopenharmony_ci	regex_t				reg;
6868c2ecf20Sopenharmony_ci};
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_cistruct tep_filter_arg {
6898c2ecf20Sopenharmony_ci	enum tep_filter_arg_type		type;
6908c2ecf20Sopenharmony_ci	union {
6918c2ecf20Sopenharmony_ci		struct tep_filter_arg_boolean	boolean;
6928c2ecf20Sopenharmony_ci		struct tep_filter_arg_field	field;
6938c2ecf20Sopenharmony_ci		struct tep_filter_arg_value	value;
6948c2ecf20Sopenharmony_ci		struct tep_filter_arg_op	op;
6958c2ecf20Sopenharmony_ci		struct tep_filter_arg_exp	exp;
6968c2ecf20Sopenharmony_ci		struct tep_filter_arg_num	num;
6978c2ecf20Sopenharmony_ci		struct tep_filter_arg_str	str;
6988c2ecf20Sopenharmony_ci	};
6998c2ecf20Sopenharmony_ci};
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_cistruct tep_filter_type {
7028c2ecf20Sopenharmony_ci	int			event_id;
7038c2ecf20Sopenharmony_ci	struct tep_event	*event;
7048c2ecf20Sopenharmony_ci	struct tep_filter_arg	*filter;
7058c2ecf20Sopenharmony_ci};
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_ci#define TEP_FILTER_ERROR_BUFSZ  1024
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_cistruct tep_event_filter {
7108c2ecf20Sopenharmony_ci	struct tep_handle	*tep;
7118c2ecf20Sopenharmony_ci	int			filters;
7128c2ecf20Sopenharmony_ci	struct tep_filter_type	*event_filters;
7138c2ecf20Sopenharmony_ci	char			error_buffer[TEP_FILTER_ERROR_BUFSZ];
7148c2ecf20Sopenharmony_ci};
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_cistruct tep_event_filter *tep_filter_alloc(struct tep_handle *tep);
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_ci/* for backward compatibility */
7198c2ecf20Sopenharmony_ci#define FILTER_NONE		TEP_ERRNO__NO_FILTER
7208c2ecf20Sopenharmony_ci#define FILTER_NOEXIST		TEP_ERRNO__FILTER_NOT_FOUND
7218c2ecf20Sopenharmony_ci#define FILTER_MISS		TEP_ERRNO__FILTER_MISS
7228c2ecf20Sopenharmony_ci#define FILTER_MATCH		TEP_ERRNO__FILTER_MATCH
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_cienum tep_errno tep_filter_add_filter_str(struct tep_event_filter *filter,
7258c2ecf20Sopenharmony_ci					 const char *filter_str);
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_cienum tep_errno tep_filter_match(struct tep_event_filter *filter,
7288c2ecf20Sopenharmony_ci				struct tep_record *record);
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ciint tep_filter_strerror(struct tep_event_filter *filter, enum tep_errno err,
7318c2ecf20Sopenharmony_ci			char *buf, size_t buflen);
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_ciint tep_event_filtered(struct tep_event_filter *filter,
7348c2ecf20Sopenharmony_ci		       int event_id);
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_civoid tep_filter_reset(struct tep_event_filter *filter);
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_civoid tep_filter_free(struct tep_event_filter *filter);
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_cichar *tep_filter_make_string(struct tep_event_filter *filter, int event_id);
7418c2ecf20Sopenharmony_ci
7428c2ecf20Sopenharmony_ciint tep_filter_remove_event(struct tep_event_filter *filter,
7438c2ecf20Sopenharmony_ci			    int event_id);
7448c2ecf20Sopenharmony_ci
7458c2ecf20Sopenharmony_ciint tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *source);
7468c2ecf20Sopenharmony_ci
7478c2ecf20Sopenharmony_ciint tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2);
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci#endif /* _PARSE_EVENTS_H */
750