blob: 41d4f9f6a8436764b7b335f32a9747fe2d32f713 [file] [log] [blame]
Steven Rostedt (VMware)4e59ab932020-07-02 14:53:58 -04001/* SPDX-License-Identifier: LGPL-2.1 */
Steven Rostedtf7d82352012-04-06 00:47:53 +02002/*
3 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4 *
Steven Rostedtf7d82352012-04-06 00:47:53 +02005 */
6#ifndef _PARSE_EVENTS_H
7#define _PARSE_EVENTS_H
8
Yoshihiro YUNOMAE1b372ca2013-11-01 17:53:53 -04009#include <stdbool.h>
Steven Rostedtf7d82352012-04-06 00:47:53 +020010#include <stdarg.h>
Arnaldo Carvalho de Melo402bb4e2015-02-03 12:44:09 -030011#include <stdio.h>
Steven Rostedtf7d82352012-04-06 00:47:53 +020012#include <regex.h>
Jiri Olsa91a058a2013-12-03 14:09:18 +010013#include <string.h>
Steven Rostedtf7d82352012-04-06 00:47:53 +020014
Tzvetomir Stoyanov (VMware)266b8512018-08-28 18:50:38 -040015#include "trace-seq.h"
16
Irina Tirdea1d037ca2012-09-11 01:15:03 +030017#ifndef __maybe_unused
18#define __maybe_unused __attribute__((unused))
Steven Rostedtf7d82352012-04-06 00:47:53 +020019#endif
20
Steven Rostedtf7d82352012-04-06 00:47:53 +020021#ifndef DEBUG_RECORD
22#define DEBUG_RECORD 0
23#endif
24
Tzvetomir Stoyanov (VMware)cbc49b22018-08-08 14:02:47 -040025struct tep_record {
Steven Rostedtf7d82352012-04-06 00:47:53 +020026 unsigned long long ts;
27 unsigned long long offset;
28 long long missed_events; /* buffer dropped events before */
29 int record_size; /* size of binary record */
30 int size; /* size of data */
31 void *data;
32 int cpu;
33 int ref_count;
34 int locked; /* Do not free, even if ref_count is zero */
Steven Rostedtff1a70e2012-08-23 11:22:01 -040035 void *priv;
Steven Rostedtf7d82352012-04-06 00:47:53 +020036#if DEBUG_RECORD
Tzvetomir Stoyanov (VMware)cbc49b22018-08-08 14:02:47 -040037 struct tep_record *prev;
38 struct tep_record *next;
Steven Rostedtf7d82352012-04-06 00:47:53 +020039 long alloc_addr;
40#endif
41};
42
Tzvetomir Stoyanov (VMware)4963b0f2018-09-19 14:56:44 -040043/* ----------------------- tep ----------------------- */
Steven Rostedtf7d82352012-04-06 00:47:53 +020044
Tzvetomir Stoyanov (VMware)096177a2018-08-08 14:02:46 -040045struct tep_handle;
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -050046struct tep_event;
Steven Rostedtf7d82352012-04-06 00:47:53 +020047
Tzvetomir Stoyanov (VMware)c32d52b2018-08-08 14:02:48 -040048typedef int (*tep_event_handler_func)(struct trace_seq *s,
49 struct tep_record *record,
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -050050 struct tep_event *event,
Tzvetomir Stoyanov (VMware)c32d52b2018-08-08 14:02:48 -040051 void *context);
Steven Rostedtf7d82352012-04-06 00:47:53 +020052
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -040053typedef int (*tep_plugin_load_func)(struct tep_handle *tep);
54typedef int (*tep_plugin_unload_func)(struct tep_handle *tep);
Steven Rostedtf7d82352012-04-06 00:47:53 +020055
Tzvetomir Stoyanov (VMware)c32d52b2018-08-08 14:02:48 -040056struct tep_plugin_option {
57 struct tep_plugin_option *next;
Steven Rostedtf7d82352012-04-06 00:47:53 +020058 void *handle;
59 char *file;
60 char *name;
61 char *plugin_alias;
62 char *description;
Steven Rostedt5dbcfd92015-03-24 09:57:54 -040063 const char *value;
Steven Rostedtff1a70e2012-08-23 11:22:01 -040064 void *priv;
Steven Rostedtf7d82352012-04-06 00:47:53 +020065 int set;
66};
67
68/*
69 * Plugin hooks that can be called:
70 *
Tzvetomir Stoyanov (VMware)c32d52b2018-08-08 14:02:48 -040071 * TEP_PLUGIN_LOADER: (required)
Steven Rostedtf7d82352012-04-06 00:47:53 +020072 * The function name to initialized the plugin.
73 *
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -040074 * int TEP_PLUGIN_LOADER(struct tep_handle *tep)
Steven Rostedtf7d82352012-04-06 00:47:53 +020075 *
Tzvetomir Stoyanov (VMware)c32d52b2018-08-08 14:02:48 -040076 * TEP_PLUGIN_UNLOADER: (optional)
Steven Rostedtf7d82352012-04-06 00:47:53 +020077 * The function called just before unloading
78 *
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -040079 * int TEP_PLUGIN_UNLOADER(struct tep_handle *tep)
Steven Rostedtf7d82352012-04-06 00:47:53 +020080 *
Tzvetomir Stoyanov (VMware)c32d52b2018-08-08 14:02:48 -040081 * TEP_PLUGIN_OPTIONS: (optional)
Steven Rostedtf7d82352012-04-06 00:47:53 +020082 * Plugin options that can be set before loading
83 *
Tzvetomir Stoyanov (VMware)c32d52b2018-08-08 14:02:48 -040084 * struct tep_plugin_option TEP_PLUGIN_OPTIONS[] = {
Steven Rostedtf7d82352012-04-06 00:47:53 +020085 * {
86 * .name = "option-name",
Masahiro Yamada505d3082017-03-09 16:16:33 -080087 * .plugin_alias = "override-file-name", (optional)
Steven Rostedtf7d82352012-04-06 00:47:53 +020088 * .description = "description of option to show users",
89 * },
90 * {
91 * .name = NULL,
92 * },
93 * };
94 *
95 * Array must end with .name = NULL;
96 *
97 *
98 * .plugin_alias is used to give a shorter name to access
99 * the vairable. Useful if a plugin handles more than one event.
100 *
Steven Rostedt5dbcfd92015-03-24 09:57:54 -0400101 * If .value is not set, then it is considered a boolean and only
102 * .set will be processed. If .value is defined, then it is considered
103 * a string option and .set will be ignored.
104 *
Tzvetomir Stoyanov (VMware)c32d52b2018-08-08 14:02:48 -0400105 * TEP_PLUGIN_ALIAS: (optional)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200106 * The name to use for finding options (uses filename if not defined)
107 */
Tzvetomir Stoyanov (VMware)c32d52b2018-08-08 14:02:48 -0400108#define TEP_PLUGIN_LOADER tep_plugin_loader
109#define TEP_PLUGIN_UNLOADER tep_plugin_unloader
110#define TEP_PLUGIN_OPTIONS tep_plugin_options
111#define TEP_PLUGIN_ALIAS tep_plugin_alias
Steven Rostedtf7d82352012-04-06 00:47:53 +0200112#define _MAKE_STR(x) #x
113#define MAKE_STR(x) _MAKE_STR(x)
Tzvetomir Stoyanov (VMware)c32d52b2018-08-08 14:02:48 -0400114#define TEP_PLUGIN_LOADER_NAME MAKE_STR(TEP_PLUGIN_LOADER)
115#define TEP_PLUGIN_UNLOADER_NAME MAKE_STR(TEP_PLUGIN_UNLOADER)
116#define TEP_PLUGIN_OPTIONS_NAME MAKE_STR(TEP_PLUGIN_OPTIONS)
117#define TEP_PLUGIN_ALIAS_NAME MAKE_STR(TEP_PLUGIN_ALIAS)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200118
Tzvetomir Stoyanov (VMware)bb39ccb2018-09-19 14:56:46 -0400119enum tep_format_flags {
120 TEP_FIELD_IS_ARRAY = 1,
121 TEP_FIELD_IS_POINTER = 2,
122 TEP_FIELD_IS_SIGNED = 4,
123 TEP_FIELD_IS_STRING = 8,
124 TEP_FIELD_IS_DYNAMIC = 16,
125 TEP_FIELD_IS_LONG = 32,
126 TEP_FIELD_IS_FLAG = 64,
127 TEP_FIELD_IS_SYMBOLIC = 128,
Masami Hiramatsucd772902021-11-22 18:30:40 +0900128 TEP_FIELD_IS_RELATIVE = 256,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200129};
130
Tzvetomir Stoyanov (VMware)2c92f982018-09-19 14:56:45 -0400131struct tep_format_field {
132 struct tep_format_field *next;
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500133 struct tep_event *event;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200134 char *type;
135 char *name;
Jiri Olsad3542432015-04-18 17:50:18 +0200136 char *alias;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200137 int offset;
138 int size;
139 unsigned int arraylen;
140 unsigned int elementsize;
141 unsigned long flags;
142};
143
Tzvetomir Stoyanov (VMware)2c92f982018-09-19 14:56:45 -0400144struct tep_format {
Steven Rostedtf7d82352012-04-06 00:47:53 +0200145 int nr_common;
146 int nr_fields;
Tzvetomir Stoyanov (VMware)2c92f982018-09-19 14:56:45 -0400147 struct tep_format_field *common_fields;
148 struct tep_format_field *fields;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200149};
150
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400151struct tep_print_arg_atom {
Steven Rostedtf7d82352012-04-06 00:47:53 +0200152 char *atom;
153};
154
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400155struct tep_print_arg_string {
Steven Rostedtf7d82352012-04-06 00:47:53 +0200156 char *string;
Masami Hiramatsucd772902021-11-22 18:30:40 +0900157 struct tep_format_field *field;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200158};
159
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400160struct tep_print_arg_bitmask {
Steven Rostedt (Red Hat)473a7782014-06-02 23:20:16 -0400161 char *bitmask;
Masami Hiramatsucd772902021-11-22 18:30:40 +0900162 struct tep_format_field *field;
Steven Rostedt (Red Hat)473a7782014-06-02 23:20:16 -0400163};
164
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400165struct tep_print_arg_field {
Steven Rostedtf7d82352012-04-06 00:47:53 +0200166 char *name;
Tzvetomir Stoyanov (VMware)2c92f982018-09-19 14:56:45 -0400167 struct tep_format_field *field;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200168};
169
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400170struct tep_print_flag_sym {
171 struct tep_print_flag_sym *next;
172 char *value;
173 char *str;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200174};
175
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400176struct tep_print_arg_typecast {
Steven Rostedtf7d82352012-04-06 00:47:53 +0200177 char *type;
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400178 struct tep_print_arg *item;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200179};
180
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400181struct tep_print_arg_flags {
182 struct tep_print_arg *field;
183 char *delim;
184 struct tep_print_flag_sym *flags;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200185};
186
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400187struct tep_print_arg_symbol {
188 struct tep_print_arg *field;
189 struct tep_print_flag_sym *symbols;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200190};
191
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400192struct tep_print_arg_hex {
193 struct tep_print_arg *field;
194 struct tep_print_arg *size;
Namhyung Kime080e6f2012-06-27 09:41:41 +0900195};
196
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400197struct tep_print_arg_int_array {
198 struct tep_print_arg *field;
199 struct tep_print_arg *count;
200 struct tep_print_arg *el_size;
Javi Merinob839e1e82015-03-24 11:07:19 +0000201};
202
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400203struct tep_print_arg_dynarray {
Tzvetomir Stoyanov (VMware)2c92f982018-09-19 14:56:45 -0400204 struct tep_format_field *field;
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400205 struct tep_print_arg *index;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200206};
207
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400208struct tep_print_arg;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200209
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400210struct tep_print_arg_op {
Steven Rostedtf7d82352012-04-06 00:47:53 +0200211 char *op;
212 int prio;
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400213 struct tep_print_arg *left;
214 struct tep_print_arg *right;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200215};
216
Tzvetomir Stoyanov (VMware)3cf47782018-08-08 14:02:59 -0400217struct tep_function_handler;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200218
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400219struct tep_print_arg_func {
Tzvetomir Stoyanov (VMware)3cf47782018-08-08 14:02:59 -0400220 struct tep_function_handler *func;
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400221 struct tep_print_arg *args;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200222};
223
Tzvetomir Stoyanov (VMware)1e97216f2018-09-19 14:56:50 -0400224enum tep_print_arg_type {
225 TEP_PRINT_NULL,
226 TEP_PRINT_ATOM,
227 TEP_PRINT_FIELD,
228 TEP_PRINT_FLAGS,
229 TEP_PRINT_SYMBOL,
230 TEP_PRINT_HEX,
231 TEP_PRINT_INT_ARRAY,
232 TEP_PRINT_TYPE,
233 TEP_PRINT_STRING,
234 TEP_PRINT_BSTRING,
235 TEP_PRINT_DYNAMIC_ARRAY,
236 TEP_PRINT_OP,
237 TEP_PRINT_FUNC,
238 TEP_PRINT_BITMASK,
239 TEP_PRINT_DYNAMIC_ARRAY_LEN,
240 TEP_PRINT_HEX_STR,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200241};
242
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400243struct tep_print_arg {
244 struct tep_print_arg *next;
Tzvetomir Stoyanov (VMware)1e97216f2018-09-19 14:56:50 -0400245 enum tep_print_arg_type type;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200246 union {
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400247 struct tep_print_arg_atom atom;
248 struct tep_print_arg_field field;
249 struct tep_print_arg_typecast typecast;
250 struct tep_print_arg_flags flags;
251 struct tep_print_arg_symbol symbol;
252 struct tep_print_arg_hex hex;
253 struct tep_print_arg_int_array int_array;
254 struct tep_print_arg_func func;
255 struct tep_print_arg_string string;
256 struct tep_print_arg_bitmask bitmask;
257 struct tep_print_arg_op op;
258 struct tep_print_arg_dynarray dynarray;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200259 };
260};
261
Tzvetomir Stoyanov (VMware)e7a90882020-07-02 14:53:51 -0400262struct tep_print_parse;
263
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400264struct tep_print_fmt {
Steven Rostedtf7d82352012-04-06 00:47:53 +0200265 char *format;
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400266 struct tep_print_arg *args;
Tzvetomir Stoyanov (VMware)e7a90882020-07-02 14:53:51 -0400267 struct tep_print_parse *print_cache;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200268};
269
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500270struct tep_event {
Tzvetomir Stoyanov69769ce2019-04-01 12:43:18 -0400271 struct tep_handle *tep;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200272 char *name;
273 int id;
274 int flags;
Tzvetomir Stoyanov (VMware)2c92f982018-09-19 14:56:45 -0400275 struct tep_format format;
Tzvetomir Stoyanov (VMware)5647f942018-09-19 14:56:49 -0400276 struct tep_print_fmt print_fmt;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200277 char *system;
Tzvetomir Stoyanov (VMware)c32d52b2018-08-08 14:02:48 -0400278 tep_event_handler_func handler;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200279 void *context;
280};
281
282enum {
Tzvetomir Stoyanov (VMware)c1953bc2018-09-19 14:56:48 -0400283 TEP_EVENT_FL_ISFTRACE = 0x01,
284 TEP_EVENT_FL_ISPRINT = 0x02,
285 TEP_EVENT_FL_ISBPRINT = 0x04,
286 TEP_EVENT_FL_ISFUNCENT = 0x10,
287 TEP_EVENT_FL_ISFUNCRET = 0x20,
288 TEP_EVENT_FL_NOHANDLE = 0x40,
289 TEP_EVENT_FL_PRINTRAW = 0x80,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200290
Tzvetomir Stoyanov (VMware)c1953bc2018-09-19 14:56:48 -0400291 TEP_EVENT_FL_FAILED = 0x80000000
Steven Rostedtf7d82352012-04-06 00:47:53 +0200292};
293
Tzvetomir Stoyanov (VMware)f25d9e02018-09-19 14:56:47 -0400294enum tep_event_sort_type {
295 TEP_EVENT_SORT_ID,
296 TEP_EVENT_SORT_NAME,
297 TEP_EVENT_SORT_SYSTEM,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200298};
299
Tzvetomir Stoyanov (VMware)f25d9e02018-09-19 14:56:47 -0400300enum tep_event_type {
301 TEP_EVENT_ERROR,
302 TEP_EVENT_NONE,
303 TEP_EVENT_SPACE,
304 TEP_EVENT_NEWLINE,
305 TEP_EVENT_OP,
306 TEP_EVENT_DELIM,
307 TEP_EVENT_ITEM,
308 TEP_EVENT_DQUOTE,
309 TEP_EVENT_SQUOTE,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200310};
311
Tzvetomir Stoyanov (VMware)3cf47782018-08-08 14:02:59 -0400312typedef unsigned long long (*tep_func_handler)(struct trace_seq *s,
313 unsigned long long *args);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200314
Tzvetomir Stoyanov (VMware)3cf47782018-08-08 14:02:59 -0400315enum tep_func_arg_type {
316 TEP_FUNC_ARG_VOID,
317 TEP_FUNC_ARG_INT,
318 TEP_FUNC_ARG_LONG,
319 TEP_FUNC_ARG_STRING,
320 TEP_FUNC_ARG_PTR,
321 TEP_FUNC_ARG_MAX_TYPES
Steven Rostedtf7d82352012-04-06 00:47:53 +0200322};
323
Tzvetomir Stoyanov (VMware)6fed9322018-08-08 14:02:57 -0400324enum tep_flag {
325 TEP_NSEC_OUTPUT = 1, /* output in NSECS */
326 TEP_DISABLE_SYS_PLUGINS = 1 << 1,
327 TEP_DISABLE_PLUGINS = 1 << 2,
Steven Rostedt4dc10242012-04-06 00:47:57 +0200328};
329
Tzvetomir Stoyanov (VMware)d97f4ef2018-08-08 14:02:58 -0400330#define TEP_ERRORS \
Namhyung Kim2f197b92012-08-22 16:00:30 +0900331 _PE(MEM_ALLOC_FAILED, "failed to allocate memory"), \
332 _PE(PARSE_EVENT_FAILED, "failed to parse event"), \
333 _PE(READ_ID_FAILED, "failed to read event id"), \
334 _PE(READ_FORMAT_FAILED, "failed to read event format"), \
335 _PE(READ_PRINT_FAILED, "failed to read event print fmt"), \
Namhyung Kim67ed9392012-09-07 11:49:47 +0900336 _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
Namhyung Kim605b8fd2013-12-12 16:36:08 +0900337 _PE(INVALID_ARG_TYPE, "invalid argument type"), \
Namhyung Kim41e12e52013-12-12 16:36:15 +0900338 _PE(INVALID_EXP_TYPE, "invalid expression type"), \
339 _PE(INVALID_OP_TYPE, "invalid operator type"), \
Namhyung Kim605b8fd2013-12-12 16:36:08 +0900340 _PE(INVALID_EVENT_NAME, "invalid event name"), \
Namhyung Kim02d62d62013-12-12 16:36:09 +0900341 _PE(EVENT_NOT_FOUND, "no event found"), \
342 _PE(SYNTAX_ERROR, "syntax error"), \
343 _PE(ILLEGAL_RVALUE, "illegal rvalue"), \
344 _PE(ILLEGAL_LVALUE, "illegal lvalue for string comparison"), \
345 _PE(INVALID_REGEX, "regex did not compute"), \
346 _PE(ILLEGAL_STRING_CMP, "illegal comparison for string"), \
Namhyung Kim7bb73552013-12-12 16:36:11 +0900347 _PE(ILLEGAL_INTEGER_CMP,"illegal comparison for integer"), \
348 _PE(REPARENT_NOT_OP, "cannot reparent other than OP"), \
349 _PE(REPARENT_FAILED, "failed to reparent filter OP"), \
Namhyung Kimc8ea6902013-12-12 16:36:12 +0900350 _PE(BAD_FILTER_ARG, "bad arg in filter tree"), \
Namhyung Kim42d61942013-12-12 16:36:13 +0900351 _PE(UNEXPECTED_TYPE, "unexpected type (not a value)"), \
352 _PE(ILLEGAL_TOKEN, "illegal token"), \
353 _PE(INVALID_PAREN, "open parenthesis cannot come here"), \
354 _PE(UNBALANCED_PAREN, "unbalanced number of parenthesis"), \
Namhyung Kim69c770a2013-12-12 16:36:14 +0900355 _PE(UNKNOWN_TOKEN, "unknown token"), \
Namhyung Kim41e12e52013-12-12 16:36:15 +0900356 _PE(FILTER_NOT_FOUND, "no filter found"), \
357 _PE(NOT_A_NUMBER, "must have number field"), \
358 _PE(NO_FILTER, "no filters exists"), \
359 _PE(FILTER_MISS, "record does not match to filter")
Namhyung Kim2f197b92012-08-22 16:00:30 +0900360
361#undef _PE
Tzvetomir Stoyanov (VMware)d97f4ef2018-08-08 14:02:58 -0400362#define _PE(__code, __str) TEP_ERRNO__ ## __code
363enum tep_errno {
364 TEP_ERRNO__SUCCESS = 0,
365 TEP_ERRNO__FILTER_MATCH = TEP_ERRNO__SUCCESS,
Namhyung Kimbffddff2012-08-22 16:00:29 +0900366
367 /*
368 * Choose an arbitrary negative big number not to clash with standard
369 * errno since SUS requires the errno has distinct positive values.
370 * See 'Issue 6' in the link below.
371 *
Alexander A. Klimov79e3ea52020-08-06 23:17:22 -0700372 * https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
Namhyung Kimbffddff2012-08-22 16:00:29 +0900373 */
Tzvetomir Stoyanov (VMware)d97f4ef2018-08-08 14:02:58 -0400374 __TEP_ERRNO__START = -100000,
Namhyung Kimbffddff2012-08-22 16:00:29 +0900375
Tzvetomir Stoyanov (VMware)d97f4ef2018-08-08 14:02:58 -0400376 TEP_ERRORS,
Namhyung Kimbffddff2012-08-22 16:00:29 +0900377
Tzvetomir Stoyanov (VMware)d97f4ef2018-08-08 14:02:58 -0400378 __TEP_ERRNO__END,
Namhyung Kimbffddff2012-08-22 16:00:29 +0900379};
Namhyung Kim2f197b92012-08-22 16:00:30 +0900380#undef _PE
Namhyung Kimbffddff2012-08-22 16:00:29 +0900381
Tzvetomir Stoyanov (VMware)785be0c2018-09-19 14:56:56 -0400382struct tep_plugin_list;
Jiri Olsac877bbd2013-12-03 14:09:16 +0100383
Steven Rostedt5827f2f2014-06-03 18:41:54 -0400384#define INVALID_PLUGIN_LIST_OPTION ((char **)((unsigned long)-1))
385
Tzvetomir Stoyanov (VMware)4d70cae2020-07-02 14:53:49 -0400386enum tep_plugin_load_priority {
387 TEP_PLUGIN_FIRST,
388 TEP_PLUGIN_LAST,
389};
390
391int tep_add_plugin_path(struct tep_handle *tep, char *path,
392 enum tep_plugin_load_priority prio);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400393struct tep_plugin_list *tep_load_plugins(struct tep_handle *tep);
Tzvetomir Stoyanov (VMware)785be0c2018-09-19 14:56:56 -0400394void tep_unload_plugins(struct tep_plugin_list *plugin_list,
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400395 struct tep_handle *tep);
Tzvetomir Stoyanov (VMware)662081a2020-07-02 14:53:47 -0400396void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
397 void (*load_plugin)(struct tep_handle *tep,
398 const char *path,
399 const char *name,
400 void *data),
401 void *data);
Tzvetomir Stoyanov (VMware)ca2921d2018-08-08 14:03:00 -0400402char **tep_plugin_list_options(void);
403void tep_plugin_free_options_list(char **list);
404int tep_plugin_add_options(const char *name,
405 struct tep_plugin_option *options);
Tzvetomir Stoyanov (VMware)74006282020-07-02 14:53:48 -0400406int tep_plugin_add_option(const char *name, const char *val);
Tzvetomir Stoyanov (VMware)ca2921d2018-08-08 14:03:00 -0400407void tep_plugin_remove_options(struct tep_plugin_option *options);
Tzvetomir Stoyanov (VMware)74006282020-07-02 14:53:48 -0400408void tep_plugin_print_options(struct trace_seq *s);
Tzvetomir Stoyanov (VMware)ca2921d2018-08-08 14:03:00 -0400409void tep_print_plugins(struct trace_seq *s,
410 const char *prefix, const char *suffix,
Tzvetomir Stoyanov (VMware)785be0c2018-09-19 14:56:56 -0400411 const struct tep_plugin_list *list);
Jiri Olsac877bbd2013-12-03 14:09:16 +0100412
Tzvetomir Stoyanovbb3dd7e2018-10-05 12:22:25 -0400413/* tep_handle */
Tzvetomir Stoyanov (VMware)4d5c58b2018-08-08 14:02:49 -0400414typedef char *(tep_func_resolver_t)(void *priv,
415 unsigned long long *addrp, char **modp);
Tzvetomir Stoyanovbb3dd7e2018-10-05 12:22:25 -0400416void tep_set_flag(struct tep_handle *tep, int flag);
Tzvetomir Stoyanov80c55262019-04-01 12:43:12 -0400417void tep_clear_flag(struct tep_handle *tep, enum tep_flag flag);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400418bool tep_test_flag(struct tep_handle *tep, enum tep_flag flags);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200419
Tzvetomir Stoyanov55c34ae2019-04-01 12:43:16 -0400420static inline int tep_is_bigendian(void)
Jiri Olsa91a058a2013-12-03 14:09:18 +0100421{
422 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
423 unsigned int val;
424
425 memcpy(&val, str, 4);
426 return val == 0x01020304;
427}
428
Steven Rostedtf7d82352012-04-06 00:47:53 +0200429/* taken from kernel/trace/trace.h */
430enum trace_flag_type {
431 TRACE_FLAG_IRQS_OFF = 0x01,
432 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
433 TRACE_FLAG_NEED_RESCHED = 0x04,
434 TRACE_FLAG_HARDIRQ = 0x08,
435 TRACE_FLAG_SOFTIRQ = 0x10,
436};
437
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400438int tep_set_function_resolver(struct tep_handle *tep,
Tzvetomir Stoyanov (VMware)ece2a4f2018-08-08 14:02:55 -0400439 tep_func_resolver_t *func, void *priv);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400440void tep_reset_function_resolver(struct tep_handle *tep);
441int tep_register_comm(struct tep_handle *tep, const char *comm, int pid);
442int tep_override_comm(struct tep_handle *tep, const char *comm, int pid);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400443int tep_register_function(struct tep_handle *tep, char *name,
Tzvetomir Stoyanov (VMware)b843e9c2018-08-08 14:03:02 -0400444 unsigned long long addr, char *mod);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400445int tep_register_print_string(struct tep_handle *tep, const char *fmt,
Tzvetomir Stoyanov (VMware)13a41892018-08-08 14:02:54 -0400446 unsigned long long addr);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400447bool tep_is_pid_registered(struct tep_handle *tep, int pid);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200448
Tzvetomir Stoyanov (VMware)d69094f2019-09-19 17:23:39 -0400449struct tep_event *tep_get_event(struct tep_handle *tep, int index);
450
Tzvetomir Stoyanov38847db2019-08-05 16:43:13 -0400451#define TEP_PRINT_INFO "INFO"
452#define TEP_PRINT_INFO_RAW "INFO_RAW"
453#define TEP_PRINT_COMM "COMM"
454#define TEP_PRINT_LATENCY "LATENCY"
455#define TEP_PRINT_NAME "NAME"
456#define TEP_PRINT_PID 1U
457#define TEP_PRINT_TIME 2U
458#define TEP_PRINT_CPU 3U
459
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400460void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
Tzvetomir Stoyanov38847db2019-08-05 16:43:13 -0400461 struct tep_record *record, const char *fmt, ...)
462 __attribute__ ((format (printf, 4, 5)));
Steven Rostedtf7d82352012-04-06 00:47:53 +0200463
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400464int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size,
Tzvetomir Stoyanov (VMware)c60167c2018-08-08 14:02:51 -0400465 int long_size);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200466
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400467enum tep_errno tep_parse_event(struct tep_handle *tep, const char *buf,
Tzvetomir Stoyanov (VMware)d97f4ef2018-08-08 14:02:58 -0400468 unsigned long size, const char *sys);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400469enum tep_errno tep_parse_format(struct tep_handle *tep,
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500470 struct tep_event **eventp,
Tzvetomir Stoyanov (VMware)d97f4ef2018-08-08 14:02:58 -0400471 const char *buf,
472 unsigned long size, const char *sys);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200473
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500474void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event,
Tzvetomir Stoyanov (VMware)8b3e0872018-08-08 14:03:04 -0400475 const char *name, struct tep_record *record,
476 int *len, int err);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200477
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500478int tep_get_field_val(struct trace_seq *s, struct tep_event *event,
Tzvetomir Stoyanov (VMware)8b3e0872018-08-08 14:03:04 -0400479 const char *name, struct tep_record *record,
480 unsigned long long *val, int err);
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500481int tep_get_common_field_val(struct trace_seq *s, struct tep_event *event,
Tzvetomir Stoyanov (VMware)cbc49b22018-08-08 14:02:47 -0400482 const char *name, struct tep_record *record,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200483 unsigned long long *val, int err);
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500484int tep_get_any_field_val(struct trace_seq *s, struct tep_event *event,
Tzvetomir Stoyanov (VMware)8b3e0872018-08-08 14:03:04 -0400485 const char *name, struct tep_record *record,
486 unsigned long long *val, int err);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200487
Tzvetomir Stoyanov (VMware)6a48dc22018-08-08 14:02:52 -0400488int tep_print_num_field(struct trace_seq *s, const char *fmt,
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500489 struct tep_event *event, const char *name,
Tzvetomir Stoyanov (VMware)4963b0f2018-09-19 14:56:44 -0400490 struct tep_record *record, int err);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200491
Tzvetomir Stoyanov (VMware)6a48dc22018-08-08 14:02:52 -0400492int tep_print_func_field(struct trace_seq *s, const char *fmt,
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500493 struct tep_event *event, const char *name,
Tzvetomir Stoyanov (VMware)6a48dc22018-08-08 14:02:52 -0400494 struct tep_record *record, int err);
Steven Rostedt6d862b82013-11-01 17:54:00 -0400495
Tzvetomir Stoyanovf87ce7c2018-11-30 23:08:11 -0500496enum tep_reg_handler {
497 TEP_REGISTER_SUCCESS = 0,
498 TEP_REGISTER_SUCCESS_OVERWRITE,
499};
500
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400501int tep_register_event_handler(struct tep_handle *tep, int id,
Tzvetomir Stoyanov (VMware)b843e9c2018-08-08 14:03:02 -0400502 const char *sys_name, const char *event_name,
503 tep_event_handler_func func, void *context);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400504int tep_unregister_event_handler(struct tep_handle *tep, int id,
Tzvetomir Stoyanov (VMware)b843e9c2018-08-08 14:03:02 -0400505 const char *sys_name, const char *event_name,
506 tep_event_handler_func func, void *context);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400507int tep_register_print_function(struct tep_handle *tep,
Tzvetomir Stoyanov (VMware)b843e9c2018-08-08 14:03:02 -0400508 tep_func_handler func,
509 enum tep_func_arg_type ret_type,
510 char *name, ...);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400511int tep_unregister_print_function(struct tep_handle *tep,
Tzvetomir Stoyanov (VMware)b843e9c2018-08-08 14:03:02 -0400512 tep_func_handler func, char *name);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200513
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500514struct tep_format_field *tep_find_common_field(struct tep_event *event, const char *name);
515struct tep_format_field *tep_find_field(struct tep_event *event, const char *name);
516struct tep_format_field *tep_find_any_field(struct tep_event *event, const char *name);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200517
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400518const char *tep_find_function(struct tep_handle *tep, unsigned long long addr);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200519unsigned long long
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400520tep_find_function_address(struct tep_handle *tep, unsigned long long addr);
521unsigned long long tep_read_number(struct tep_handle *tep, const void *ptr, int size);
Tzvetomir Stoyanov (VMware)2c92f982018-09-19 14:56:45 -0400522int tep_read_number_field(struct tep_format_field *field, const void *data,
Tzvetomir Stoyanov (VMware)59c1bae2018-08-08 14:02:53 -0400523 unsigned long long *value);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200524
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500525struct tep_event *tep_get_first_event(struct tep_handle *tep);
Tzvetomir Stoyanovbb3dd7e2018-10-05 12:22:25 -0400526int tep_get_events_count(struct tep_handle *tep);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400527struct tep_event *tep_find_event(struct tep_handle *tep, int id);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200528
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500529struct tep_event *
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400530tep_find_event_by_name(struct tep_handle *tep, const char *sys, const char *name);
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500531struct tep_event *
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400532tep_find_event_by_record(struct tep_handle *tep, struct tep_record *record);
Steven Rostedta6745332016-02-29 09:01:28 -0500533
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400534int tep_data_type(struct tep_handle *tep, struct tep_record *rec);
535int tep_data_pid(struct tep_handle *tep, struct tep_record *rec);
536int tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec);
537int tep_data_flags(struct tep_handle *tep, struct tep_record *rec);
538const char *tep_data_comm_from_pid(struct tep_handle *tep, int pid);
Tzvetomir Stoyanov2e4318a2018-11-30 23:08:09 -0500539struct tep_cmdline;
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400540struct tep_cmdline *tep_data_pid_from_comm(struct tep_handle *tep, const char *comm,
Tzvetomir Stoyanov2e4318a2018-11-30 23:08:09 -0500541 struct tep_cmdline *next);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400542int tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline);
Steven Rostedt (Red Hat)27719842015-03-24 09:57:52 -0400543
Tzvetomir Stoyanov (VMware)6a48dc22018-08-08 14:02:52 -0400544void tep_print_field(struct trace_seq *s, void *data,
Tzvetomir Stoyanov (VMware)2c92f982018-09-19 14:56:45 -0400545 struct tep_format_field *field);
Tzvetomir Stoyanov (VMware)6a48dc22018-08-08 14:02:52 -0400546void tep_print_fields(struct trace_seq *s, void *data,
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500547 int size __maybe_unused, struct tep_event *event);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400548int tep_strerror(struct tep_handle *tep, enum tep_errno errnum,
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500549 char *buf, size_t buflen);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200550
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400551struct tep_event **tep_list_events(struct tep_handle *tep, enum tep_event_sort_type);
Tzvetomir Stoyanov6699ed72019-04-01 12:43:08 -0400552struct tep_event **tep_list_events_copy(struct tep_handle *tep,
553 enum tep_event_sort_type);
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500554struct tep_format_field **tep_event_common_fields(struct tep_event *event);
555struct tep_format_field **tep_event_fields(struct tep_event *event);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200556
Tzvetomir Stoyanovbb3dd7e2018-10-05 12:22:25 -0400557enum tep_endian {
558 TEP_LITTLE_ENDIAN = 0,
559 TEP_BIG_ENDIAN
560};
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400561int tep_get_cpus(struct tep_handle *tep);
562void tep_set_cpus(struct tep_handle *tep, int cpus);
563int tep_get_long_size(struct tep_handle *tep);
564void tep_set_long_size(struct tep_handle *tep, int long_size);
565int tep_get_page_size(struct tep_handle *tep);
566void tep_set_page_size(struct tep_handle *tep, int _page_size);
567bool tep_is_file_bigendian(struct tep_handle *tep);
568void tep_set_file_bigendian(struct tep_handle *tep, enum tep_endian endian);
569bool tep_is_local_bigendian(struct tep_handle *tep);
570void tep_set_local_bigendian(struct tep_handle *tep, enum tep_endian endian);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400571int tep_get_header_page_size(struct tep_handle *tep);
Tzvetomir Stoyanov80c55262019-04-01 12:43:12 -0400572int tep_get_header_timestamp_size(struct tep_handle *tep);
573bool tep_is_old_format(struct tep_handle *tep);
Tzvetomir Stoyanov80c55262019-04-01 12:43:12 -0400574void tep_set_test_filters(struct tep_handle *tep, int test_filters);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200575
Tzvetomir Stoyanov (VMware)4d5c58b2018-08-08 14:02:49 -0400576struct tep_handle *tep_alloc(void);
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400577void tep_free(struct tep_handle *tep);
578void tep_ref(struct tep_handle *tep);
579void tep_unref(struct tep_handle *tep);
Tzvetomir Stoyanov477be102018-11-30 10:44:04 -0500580int tep_get_ref(struct tep_handle *tep);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200581
Steven Rostedtf7d82352012-04-06 00:47:53 +0200582/* for debugging */
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400583void tep_print_funcs(struct tep_handle *tep);
584void tep_print_printk(struct tep_handle *tep);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200585
586/* ----------------------- filtering ----------------------- */
587
Tzvetomir Stoyanov (VMware)e906bb72018-09-19 14:56:51 -0400588enum tep_filter_boolean_type {
589 TEP_FILTER_FALSE,
590 TEP_FILTER_TRUE,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200591};
592
Tzvetomir Stoyanov (VMware)e906bb72018-09-19 14:56:51 -0400593enum tep_filter_op_type {
594 TEP_FILTER_OP_AND = 1,
595 TEP_FILTER_OP_OR,
596 TEP_FILTER_OP_NOT,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200597};
598
Tzvetomir Stoyanov (VMware)e906bb72018-09-19 14:56:51 -0400599enum tep_filter_cmp_type {
600 TEP_FILTER_CMP_NONE,
601 TEP_FILTER_CMP_EQ,
602 TEP_FILTER_CMP_NE,
603 TEP_FILTER_CMP_GT,
604 TEP_FILTER_CMP_LT,
605 TEP_FILTER_CMP_GE,
606 TEP_FILTER_CMP_LE,
607 TEP_FILTER_CMP_MATCH,
608 TEP_FILTER_CMP_NOT_MATCH,
609 TEP_FILTER_CMP_REGEX,
610 TEP_FILTER_CMP_NOT_REGEX,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200611};
612
Tzvetomir Stoyanov (VMware)4746d222018-09-19 14:56:52 -0400613enum tep_filter_exp_type {
614 TEP_FILTER_EXP_NONE,
615 TEP_FILTER_EXP_ADD,
616 TEP_FILTER_EXP_SUB,
617 TEP_FILTER_EXP_MUL,
618 TEP_FILTER_EXP_DIV,
619 TEP_FILTER_EXP_MOD,
620 TEP_FILTER_EXP_RSHIFT,
621 TEP_FILTER_EXP_LSHIFT,
622 TEP_FILTER_EXP_AND,
623 TEP_FILTER_EXP_OR,
624 TEP_FILTER_EXP_XOR,
625 TEP_FILTER_EXP_NOT,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200626};
627
Tzvetomir Stoyanov (VMware)4746d222018-09-19 14:56:52 -0400628enum tep_filter_arg_type {
629 TEP_FILTER_ARG_NONE,
630 TEP_FILTER_ARG_BOOLEAN,
631 TEP_FILTER_ARG_VALUE,
632 TEP_FILTER_ARG_FIELD,
633 TEP_FILTER_ARG_EXP,
634 TEP_FILTER_ARG_OP,
635 TEP_FILTER_ARG_NUM,
636 TEP_FILTER_ARG_STR,
Steven Rostedtf7d82352012-04-06 00:47:53 +0200637};
638
Tzvetomir Stoyanov (VMware)0515ca52018-09-19 14:56:53 -0400639enum tep_filter_value_type {
640 TEP_FILTER_NUMBER,
641 TEP_FILTER_STRING,
642 TEP_FILTER_CHAR
Steven Rostedtf7d82352012-04-06 00:47:53 +0200643};
644
Tzvetomir Stoyanov (VMware)0515ca52018-09-19 14:56:53 -0400645struct tep_filter_arg;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200646
Tzvetomir Stoyanov (VMware)88e6c212018-09-19 14:56:54 -0400647struct tep_filter_arg_boolean {
Tzvetomir Stoyanov (VMware)e906bb72018-09-19 14:56:51 -0400648 enum tep_filter_boolean_type value;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200649};
650
Tzvetomir Stoyanov (VMware)88e6c212018-09-19 14:56:54 -0400651struct tep_filter_arg_field {
652 struct tep_format_field *field;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200653};
654
Tzvetomir Stoyanov (VMware)88e6c212018-09-19 14:56:54 -0400655struct tep_filter_arg_value {
Tzvetomir Stoyanov (VMware)0515ca52018-09-19 14:56:53 -0400656 enum tep_filter_value_type type;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200657 union {
658 char *str;
659 unsigned long long val;
660 };
661};
662
Tzvetomir Stoyanov (VMware)88e6c212018-09-19 14:56:54 -0400663struct tep_filter_arg_op {
664 enum tep_filter_op_type type;
665 struct tep_filter_arg *left;
666 struct tep_filter_arg *right;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200667};
668
Tzvetomir Stoyanov (VMware)88e6c212018-09-19 14:56:54 -0400669struct tep_filter_arg_exp {
Tzvetomir Stoyanov (VMware)4746d222018-09-19 14:56:52 -0400670 enum tep_filter_exp_type type;
Tzvetomir Stoyanov (VMware)0515ca52018-09-19 14:56:53 -0400671 struct tep_filter_arg *left;
672 struct tep_filter_arg *right;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200673};
674
Tzvetomir Stoyanov (VMware)88e6c212018-09-19 14:56:54 -0400675struct tep_filter_arg_num {
Tzvetomir Stoyanov (VMware)e906bb72018-09-19 14:56:51 -0400676 enum tep_filter_cmp_type type;
Tzvetomir Stoyanov (VMware)88e6c212018-09-19 14:56:54 -0400677 struct tep_filter_arg *left;
678 struct tep_filter_arg *right;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200679};
680
Tzvetomir Stoyanov (VMware)88e6c212018-09-19 14:56:54 -0400681struct tep_filter_arg_str {
Tzvetomir Stoyanov (VMware)e906bb72018-09-19 14:56:51 -0400682 enum tep_filter_cmp_type type;
Tzvetomir Stoyanov (VMware)88e6c212018-09-19 14:56:54 -0400683 struct tep_format_field *field;
684 char *val;
685 char *buffer;
686 regex_t reg;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200687};
688
Tzvetomir Stoyanov (VMware)0515ca52018-09-19 14:56:53 -0400689struct tep_filter_arg {
Tzvetomir Stoyanov (VMware)4746d222018-09-19 14:56:52 -0400690 enum tep_filter_arg_type type;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200691 union {
Tzvetomir Stoyanov (VMware)88e6c212018-09-19 14:56:54 -0400692 struct tep_filter_arg_boolean boolean;
693 struct tep_filter_arg_field field;
694 struct tep_filter_arg_value value;
695 struct tep_filter_arg_op op;
696 struct tep_filter_arg_exp exp;
697 struct tep_filter_arg_num num;
698 struct tep_filter_arg_str str;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200699 };
700};
701
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400702struct tep_filter_type {
Steven Rostedtf7d82352012-04-06 00:47:53 +0200703 int event_id;
Tzvetomir Stoyanov97fbf3f2018-11-30 10:44:07 -0500704 struct tep_event *event;
Tzvetomir Stoyanov (VMware)0515ca52018-09-19 14:56:53 -0400705 struct tep_filter_arg *filter;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200706};
707
Tzvetomir Stoyanov (VMware)64e23792018-08-08 14:03:01 -0400708#define TEP_FILTER_ERROR_BUFSZ 1024
Namhyung Kimbf19b822013-12-12 16:36:17 +0900709
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400710struct tep_event_filter {
Tzvetomir Stoyanov6b1f4c42019-04-01 12:43:19 -0400711 struct tep_handle *tep;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200712 int filters;
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400713 struct tep_filter_type *event_filters;
Tzvetomir Stoyanov (VMware)64e23792018-08-08 14:03:01 -0400714 char error_buffer[TEP_FILTER_ERROR_BUFSZ];
Steven Rostedtf7d82352012-04-06 00:47:53 +0200715};
716
Tzvetomir Stoyanov047ff222019-04-01 12:43:17 -0400717struct tep_event_filter *tep_filter_alloc(struct tep_handle *tep);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200718
Namhyung Kim41e12e52013-12-12 16:36:15 +0900719/* for backward compatibility */
Tzvetomir Stoyanov (VMware)d97f4ef2018-08-08 14:02:58 -0400720#define FILTER_NONE TEP_ERRNO__NO_FILTER
721#define FILTER_NOEXIST TEP_ERRNO__FILTER_NOT_FOUND
722#define FILTER_MISS TEP_ERRNO__FILTER_MISS
723#define FILTER_MATCH TEP_ERRNO__FILTER_MATCH
Steven Rostedtf7d82352012-04-06 00:47:53 +0200724
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400725enum tep_errno tep_filter_add_filter_str(struct tep_event_filter *filter,
Tzvetomir Stoyanov (VMware)64e23792018-08-08 14:03:01 -0400726 const char *filter_str);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200727
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400728enum tep_errno tep_filter_match(struct tep_event_filter *filter,
Tzvetomir Stoyanov (VMware)64e23792018-08-08 14:03:01 -0400729 struct tep_record *record);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200730
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400731int tep_filter_strerror(struct tep_event_filter *filter, enum tep_errno err,
Tzvetomir Stoyanov (VMware)64e23792018-08-08 14:03:01 -0400732 char *buf, size_t buflen);
Namhyung Kimbf19b822013-12-12 16:36:17 +0900733
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400734int tep_event_filtered(struct tep_event_filter *filter,
Tzvetomir Stoyanov (VMware)64e23792018-08-08 14:03:01 -0400735 int event_id);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200736
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400737void tep_filter_reset(struct tep_event_filter *filter);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200738
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400739void tep_filter_free(struct tep_event_filter *filter);
Tzvetomir Stoyanov (VMware)64e23792018-08-08 14:03:01 -0400740
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400741char *tep_filter_make_string(struct tep_event_filter *filter, int event_id);
Tzvetomir Stoyanov (VMware)64e23792018-08-08 14:03:01 -0400742
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400743int tep_filter_remove_event(struct tep_event_filter *filter,
Tzvetomir Stoyanov (VMware)64e23792018-08-08 14:03:01 -0400744 int event_id);
745
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400746int tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *source);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200747
Tzvetomir Stoyanov (VMware)9334c962018-09-19 14:56:55 -0400748int tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200749
750#endif /* _PARSE_EVENTS_H */