Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1 */
0002 /*
0003  * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
0004  *
0005  */
0006 #ifndef _PARSE_EVENTS_H
0007 #define _PARSE_EVENTS_H
0008 
0009 #include <stdbool.h>
0010 #include <stdarg.h>
0011 #include <stdio.h>
0012 #include <regex.h>
0013 #include <string.h>
0014 
0015 #include "trace-seq.h"
0016 
0017 #ifndef __maybe_unused
0018 #define __maybe_unused __attribute__((unused))
0019 #endif
0020 
0021 #ifndef DEBUG_RECORD
0022 #define DEBUG_RECORD 0
0023 #endif
0024 
0025 struct tep_record {
0026     unsigned long long  ts;
0027     unsigned long long  offset;
0028     long long       missed_events;  /* buffer dropped events before */
0029     int         record_size;    /* size of binary record */
0030     int         size;       /* size of data */
0031     void            *data;
0032     int         cpu;
0033     int         ref_count;
0034     int         locked;     /* Do not free, even if ref_count is zero */
0035     void            *priv;
0036 #if DEBUG_RECORD
0037     struct tep_record   *prev;
0038     struct tep_record   *next;
0039     long            alloc_addr;
0040 #endif
0041 };
0042 
0043 /* ----------------------- tep ----------------------- */
0044 
0045 struct tep_handle;
0046 struct tep_event;
0047 
0048 typedef int (*tep_event_handler_func)(struct trace_seq *s,
0049                       struct tep_record *record,
0050                       struct tep_event *event,
0051                       void *context);
0052 
0053 typedef int (*tep_plugin_load_func)(struct tep_handle *tep);
0054 typedef int (*tep_plugin_unload_func)(struct tep_handle *tep);
0055 
0056 struct tep_plugin_option {
0057     struct tep_plugin_option    *next;
0058     void                *handle;
0059     char                *file;
0060     char                *name;
0061     char                *plugin_alias;
0062     char                *description;
0063     const char          *value;
0064     void                *priv;
0065     int             set;
0066 };
0067 
0068 /*
0069  * Plugin hooks that can be called:
0070  *
0071  * TEP_PLUGIN_LOADER:  (required)
0072  *   The function name to initialized the plugin.
0073  *
0074  *   int TEP_PLUGIN_LOADER(struct tep_handle *tep)
0075  *
0076  * TEP_PLUGIN_UNLOADER:  (optional)
0077  *   The function called just before unloading
0078  *
0079  *   int TEP_PLUGIN_UNLOADER(struct tep_handle *tep)
0080  *
0081  * TEP_PLUGIN_OPTIONS:  (optional)
0082  *   Plugin options that can be set before loading
0083  *
0084  *   struct tep_plugin_option TEP_PLUGIN_OPTIONS[] = {
0085  *  {
0086  *      .name = "option-name",
0087  *      .plugin_alias = "override-file-name", (optional)
0088  *      .description = "description of option to show users",
0089  *  },
0090  *  {
0091  *      .name = NULL,
0092  *  },
0093  *   };
0094  *
0095  *   Array must end with .name = NULL;
0096  *
0097  *
0098  *   .plugin_alias is used to give a shorter name to access
0099  *   the vairable. Useful if a plugin handles more than one event.
0100  *
0101  *   If .value is not set, then it is considered a boolean and only
0102  *   .set will be processed. If .value is defined, then it is considered
0103  *   a string option and .set will be ignored.
0104  *
0105  * TEP_PLUGIN_ALIAS: (optional)
0106  *   The name to use for finding options (uses filename if not defined)
0107  */
0108 #define TEP_PLUGIN_LOADER tep_plugin_loader
0109 #define TEP_PLUGIN_UNLOADER tep_plugin_unloader
0110 #define TEP_PLUGIN_OPTIONS tep_plugin_options
0111 #define TEP_PLUGIN_ALIAS tep_plugin_alias
0112 #define _MAKE_STR(x)    #x
0113 #define MAKE_STR(x) _MAKE_STR(x)
0114 #define TEP_PLUGIN_LOADER_NAME MAKE_STR(TEP_PLUGIN_LOADER)
0115 #define TEP_PLUGIN_UNLOADER_NAME MAKE_STR(TEP_PLUGIN_UNLOADER)
0116 #define TEP_PLUGIN_OPTIONS_NAME MAKE_STR(TEP_PLUGIN_OPTIONS)
0117 #define TEP_PLUGIN_ALIAS_NAME MAKE_STR(TEP_PLUGIN_ALIAS)
0118 
0119 enum tep_format_flags {
0120     TEP_FIELD_IS_ARRAY  = 1,
0121     TEP_FIELD_IS_POINTER    = 2,
0122     TEP_FIELD_IS_SIGNED = 4,
0123     TEP_FIELD_IS_STRING = 8,
0124     TEP_FIELD_IS_DYNAMIC    = 16,
0125     TEP_FIELD_IS_LONG   = 32,
0126     TEP_FIELD_IS_FLAG   = 64,
0127     TEP_FIELD_IS_SYMBOLIC   = 128,
0128     TEP_FIELD_IS_RELATIVE   = 256,
0129 };
0130 
0131 struct tep_format_field {
0132     struct tep_format_field *next;
0133     struct tep_event    *event;
0134     char            *type;
0135     char            *name;
0136     char            *alias;
0137     int         offset;
0138     int         size;
0139     unsigned int        arraylen;
0140     unsigned int        elementsize;
0141     unsigned long       flags;
0142 };
0143 
0144 struct tep_format {
0145     int         nr_common;
0146     int         nr_fields;
0147     struct tep_format_field *common_fields;
0148     struct tep_format_field *fields;
0149 };
0150 
0151 struct tep_print_arg_atom {
0152     char            *atom;
0153 };
0154 
0155 struct tep_print_arg_string {
0156     char            *string;
0157     struct tep_format_field *field;
0158 };
0159 
0160 struct tep_print_arg_bitmask {
0161     char            *bitmask;
0162     struct tep_format_field *field;
0163 };
0164 
0165 struct tep_print_arg_field {
0166     char            *name;
0167     struct tep_format_field *field;
0168 };
0169 
0170 struct tep_print_flag_sym {
0171     struct tep_print_flag_sym   *next;
0172     char                *value;
0173     char                *str;
0174 };
0175 
0176 struct tep_print_arg_typecast {
0177     char            *type;
0178     struct tep_print_arg    *item;
0179 };
0180 
0181 struct tep_print_arg_flags {
0182     struct tep_print_arg        *field;
0183     char                *delim;
0184     struct tep_print_flag_sym   *flags;
0185 };
0186 
0187 struct tep_print_arg_symbol {
0188     struct tep_print_arg        *field;
0189     struct tep_print_flag_sym   *symbols;
0190 };
0191 
0192 struct tep_print_arg_hex {
0193     struct tep_print_arg    *field;
0194     struct tep_print_arg    *size;
0195 };
0196 
0197 struct tep_print_arg_int_array {
0198     struct tep_print_arg    *field;
0199     struct tep_print_arg    *count;
0200     struct tep_print_arg    *el_size;
0201 };
0202 
0203 struct tep_print_arg_dynarray {
0204     struct tep_format_field *field;
0205     struct tep_print_arg    *index;
0206 };
0207 
0208 struct tep_print_arg;
0209 
0210 struct tep_print_arg_op {
0211     char            *op;
0212     int         prio;
0213     struct tep_print_arg    *left;
0214     struct tep_print_arg    *right;
0215 };
0216 
0217 struct tep_function_handler;
0218 
0219 struct tep_print_arg_func {
0220     struct tep_function_handler *func;
0221     struct tep_print_arg        *args;
0222 };
0223 
0224 enum tep_print_arg_type {
0225     TEP_PRINT_NULL,
0226     TEP_PRINT_ATOM,
0227     TEP_PRINT_FIELD,
0228     TEP_PRINT_FLAGS,
0229     TEP_PRINT_SYMBOL,
0230     TEP_PRINT_HEX,
0231     TEP_PRINT_INT_ARRAY,
0232     TEP_PRINT_TYPE,
0233     TEP_PRINT_STRING,
0234     TEP_PRINT_BSTRING,
0235     TEP_PRINT_DYNAMIC_ARRAY,
0236     TEP_PRINT_OP,
0237     TEP_PRINT_FUNC,
0238     TEP_PRINT_BITMASK,
0239     TEP_PRINT_DYNAMIC_ARRAY_LEN,
0240     TEP_PRINT_HEX_STR,
0241 };
0242 
0243 struct tep_print_arg {
0244     struct tep_print_arg        *next;
0245     enum tep_print_arg_type     type;
0246     union {
0247         struct tep_print_arg_atom   atom;
0248         struct tep_print_arg_field  field;
0249         struct tep_print_arg_typecast   typecast;
0250         struct tep_print_arg_flags  flags;
0251         struct tep_print_arg_symbol symbol;
0252         struct tep_print_arg_hex    hex;
0253         struct tep_print_arg_int_array  int_array;
0254         struct tep_print_arg_func   func;
0255         struct tep_print_arg_string string;
0256         struct tep_print_arg_bitmask    bitmask;
0257         struct tep_print_arg_op     op;
0258         struct tep_print_arg_dynarray   dynarray;
0259     };
0260 };
0261 
0262 struct tep_print_parse;
0263 
0264 struct tep_print_fmt {
0265     char            *format;
0266     struct tep_print_arg    *args;
0267     struct tep_print_parse  *print_cache;
0268 };
0269 
0270 struct tep_event {
0271     struct tep_handle   *tep;
0272     char            *name;
0273     int         id;
0274     int         flags;
0275     struct tep_format   format;
0276     struct tep_print_fmt    print_fmt;
0277     char            *system;
0278     tep_event_handler_func  handler;
0279     void            *context;
0280 };
0281 
0282 enum {
0283     TEP_EVENT_FL_ISFTRACE   = 0x01,
0284     TEP_EVENT_FL_ISPRINT    = 0x02,
0285     TEP_EVENT_FL_ISBPRINT   = 0x04,
0286     TEP_EVENT_FL_ISFUNCENT  = 0x10,
0287     TEP_EVENT_FL_ISFUNCRET  = 0x20,
0288     TEP_EVENT_FL_NOHANDLE   = 0x40,
0289     TEP_EVENT_FL_PRINTRAW   = 0x80,
0290 
0291     TEP_EVENT_FL_FAILED = 0x80000000
0292 };
0293 
0294 enum tep_event_sort_type {
0295     TEP_EVENT_SORT_ID,
0296     TEP_EVENT_SORT_NAME,
0297     TEP_EVENT_SORT_SYSTEM,
0298 };
0299 
0300 enum tep_event_type {
0301     TEP_EVENT_ERROR,
0302     TEP_EVENT_NONE,
0303     TEP_EVENT_SPACE,
0304     TEP_EVENT_NEWLINE,
0305     TEP_EVENT_OP,
0306     TEP_EVENT_DELIM,
0307     TEP_EVENT_ITEM,
0308     TEP_EVENT_DQUOTE,
0309     TEP_EVENT_SQUOTE,
0310 };
0311 
0312 typedef unsigned long long (*tep_func_handler)(struct trace_seq *s,
0313                            unsigned long long *args);
0314 
0315 enum tep_func_arg_type {
0316     TEP_FUNC_ARG_VOID,
0317     TEP_FUNC_ARG_INT,
0318     TEP_FUNC_ARG_LONG,
0319     TEP_FUNC_ARG_STRING,
0320     TEP_FUNC_ARG_PTR,
0321     TEP_FUNC_ARG_MAX_TYPES
0322 };
0323 
0324 enum tep_flag {
0325     TEP_NSEC_OUTPUT     = 1,    /* output in NSECS */
0326     TEP_DISABLE_SYS_PLUGINS = 1 << 1,
0327     TEP_DISABLE_PLUGINS = 1 << 2,
0328 };
0329 
0330 #define TEP_ERRORS                                \
0331     _PE(MEM_ALLOC_FAILED,   "failed to allocate memory"),             \
0332     _PE(PARSE_EVENT_FAILED, "failed to parse event"),             \
0333     _PE(READ_ID_FAILED, "failed to read event id"),           \
0334     _PE(READ_FORMAT_FAILED, "failed to read event format"),           \
0335     _PE(READ_PRINT_FAILED,  "failed to read event print fmt"),        \
0336     _PE(OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),\
0337     _PE(INVALID_ARG_TYPE,   "invalid argument type"),             \
0338     _PE(INVALID_EXP_TYPE,   "invalid expression type"),           \
0339     _PE(INVALID_OP_TYPE,    "invalid operator type"),             \
0340     _PE(INVALID_EVENT_NAME, "invalid event name"),                \
0341     _PE(EVENT_NOT_FOUND,    "no event found"),                \
0342     _PE(SYNTAX_ERROR,   "syntax error"),                  \
0343     _PE(ILLEGAL_RVALUE, "illegal rvalue"),                \
0344     _PE(ILLEGAL_LVALUE, "illegal lvalue for string comparison"),      \
0345     _PE(INVALID_REGEX,  "regex did not compute"),             \
0346     _PE(ILLEGAL_STRING_CMP, "illegal comparison for string"),         \
0347     _PE(ILLEGAL_INTEGER_CMP,"illegal comparison for integer"),        \
0348     _PE(REPARENT_NOT_OP,    "cannot reparent other than OP"),         \
0349     _PE(REPARENT_FAILED,    "failed to reparent filter OP"),          \
0350     _PE(BAD_FILTER_ARG, "bad arg in filter tree"),            \
0351     _PE(UNEXPECTED_TYPE,    "unexpected type (not a value)"),         \
0352     _PE(ILLEGAL_TOKEN,  "illegal token"),                 \
0353     _PE(INVALID_PAREN,  "open parenthesis cannot come here"),         \
0354     _PE(UNBALANCED_PAREN,   "unbalanced number of parenthesis"),          \
0355     _PE(UNKNOWN_TOKEN,  "unknown token"),                 \
0356     _PE(FILTER_NOT_FOUND,   "no filter found"),               \
0357     _PE(NOT_A_NUMBER,   "must have number field"),            \
0358     _PE(NO_FILTER,      "no filters exists"),                 \
0359     _PE(FILTER_MISS,    "record does not match to filter")
0360 
0361 #undef _PE
0362 #define _PE(__code, __str) TEP_ERRNO__ ## __code
0363 enum tep_errno {
0364     TEP_ERRNO__SUCCESS          = 0,
0365     TEP_ERRNO__FILTER_MATCH         = TEP_ERRNO__SUCCESS,
0366 
0367     /*
0368      * Choose an arbitrary negative big number not to clash with standard
0369      * errno since SUS requires the errno has distinct positive values.
0370      * See 'Issue 6' in the link below.
0371      *
0372      * https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
0373      */
0374     __TEP_ERRNO__START          = -100000,
0375 
0376     TEP_ERRORS,
0377 
0378     __TEP_ERRNO__END,
0379 };
0380 #undef _PE
0381 
0382 struct tep_plugin_list;
0383 
0384 #define INVALID_PLUGIN_LIST_OPTION  ((char **)((unsigned long)-1))
0385 
0386 enum tep_plugin_load_priority {
0387     TEP_PLUGIN_FIRST,
0388     TEP_PLUGIN_LAST,
0389 };
0390 
0391 int tep_add_plugin_path(struct tep_handle *tep, char *path,
0392             enum tep_plugin_load_priority prio);
0393 struct tep_plugin_list *tep_load_plugins(struct tep_handle *tep);
0394 void tep_unload_plugins(struct tep_plugin_list *plugin_list,
0395             struct tep_handle *tep);
0396 void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
0397                void (*load_plugin)(struct tep_handle *tep,
0398                            const char *path,
0399                            const char *name,
0400                            void *data),
0401                void *data);
0402 char **tep_plugin_list_options(void);
0403 void tep_plugin_free_options_list(char **list);
0404 int tep_plugin_add_options(const char *name,
0405                struct tep_plugin_option *options);
0406 int tep_plugin_add_option(const char *name, const char *val);
0407 void tep_plugin_remove_options(struct tep_plugin_option *options);
0408 void tep_plugin_print_options(struct trace_seq *s);
0409 void tep_print_plugins(struct trace_seq *s,
0410             const char *prefix, const char *suffix,
0411             const struct tep_plugin_list *list);
0412 
0413 /* tep_handle */
0414 typedef char *(tep_func_resolver_t)(void *priv,
0415                     unsigned long long *addrp, char **modp);
0416 void tep_set_flag(struct tep_handle *tep, int flag);
0417 void tep_clear_flag(struct tep_handle *tep, enum tep_flag flag);
0418 bool tep_test_flag(struct tep_handle *tep, enum tep_flag flags);
0419 
0420 static inline int tep_is_bigendian(void)
0421 {
0422     unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
0423     unsigned int val;
0424 
0425     memcpy(&val, str, 4);
0426     return val == 0x01020304;
0427 }
0428 
0429 /* taken from kernel/trace/trace.h */
0430 enum trace_flag_type {
0431     TRACE_FLAG_IRQS_OFF     = 0x01,
0432     TRACE_FLAG_IRQS_NOSUPPORT   = 0x02,
0433     TRACE_FLAG_NEED_RESCHED     = 0x04,
0434     TRACE_FLAG_HARDIRQ      = 0x08,
0435     TRACE_FLAG_SOFTIRQ      = 0x10,
0436 };
0437 
0438 int tep_set_function_resolver(struct tep_handle *tep,
0439                   tep_func_resolver_t *func, void *priv);
0440 void tep_reset_function_resolver(struct tep_handle *tep);
0441 int tep_register_comm(struct tep_handle *tep, const char *comm, int pid);
0442 int tep_override_comm(struct tep_handle *tep, const char *comm, int pid);
0443 int tep_register_function(struct tep_handle *tep, char *name,
0444               unsigned long long addr, char *mod);
0445 int tep_register_print_string(struct tep_handle *tep, const char *fmt,
0446                   unsigned long long addr);
0447 bool tep_is_pid_registered(struct tep_handle *tep, int pid);
0448 
0449 struct tep_event *tep_get_event(struct tep_handle *tep, int index);
0450 
0451 #define TEP_PRINT_INFO      "INFO"
0452 #define TEP_PRINT_INFO_RAW  "INFO_RAW"
0453 #define TEP_PRINT_COMM      "COMM"
0454 #define TEP_PRINT_LATENCY   "LATENCY"
0455 #define TEP_PRINT_NAME      "NAME"
0456 #define TEP_PRINT_PID       1U
0457 #define TEP_PRINT_TIME      2U
0458 #define TEP_PRINT_CPU       3U
0459 
0460 void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
0461              struct tep_record *record, const char *fmt, ...)
0462     __attribute__ ((format (printf, 4, 5)));
0463 
0464 int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size,
0465               int long_size);
0466 
0467 enum tep_errno tep_parse_event(struct tep_handle *tep, const char *buf,
0468                    unsigned long size, const char *sys);
0469 enum tep_errno tep_parse_format(struct tep_handle *tep,
0470                 struct tep_event **eventp,
0471                 const char *buf,
0472                 unsigned long size, const char *sys);
0473 
0474 void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event,
0475             const char *name, struct tep_record *record,
0476             int *len, int err);
0477 
0478 int tep_get_field_val(struct trace_seq *s, struct tep_event *event,
0479               const char *name, struct tep_record *record,
0480               unsigned long long *val, int err);
0481 int tep_get_common_field_val(struct trace_seq *s, struct tep_event *event,
0482                  const char *name, struct tep_record *record,
0483                  unsigned long long *val, int err);
0484 int tep_get_any_field_val(struct trace_seq *s, struct tep_event *event,
0485               const char *name, struct tep_record *record,
0486               unsigned long long *val, int err);
0487 
0488 int tep_print_num_field(struct trace_seq *s, const char *fmt,
0489             struct tep_event *event, const char *name,
0490             struct tep_record *record, int err);
0491 
0492 int tep_print_func_field(struct trace_seq *s, const char *fmt,
0493              struct tep_event *event, const char *name,
0494              struct tep_record *record, int err);
0495 
0496 enum tep_reg_handler {
0497     TEP_REGISTER_SUCCESS = 0,
0498     TEP_REGISTER_SUCCESS_OVERWRITE,
0499 };
0500 
0501 int tep_register_event_handler(struct tep_handle *tep, int id,
0502                    const char *sys_name, const char *event_name,
0503                    tep_event_handler_func func, void *context);
0504 int tep_unregister_event_handler(struct tep_handle *tep, int id,
0505                  const char *sys_name, const char *event_name,
0506                  tep_event_handler_func func, void *context);
0507 int tep_register_print_function(struct tep_handle *tep,
0508                 tep_func_handler func,
0509                 enum tep_func_arg_type ret_type,
0510                 char *name, ...);
0511 int tep_unregister_print_function(struct tep_handle *tep,
0512                   tep_func_handler func, char *name);
0513 
0514 struct tep_format_field *tep_find_common_field(struct tep_event *event, const char *name);
0515 struct tep_format_field *tep_find_field(struct tep_event *event, const char *name);
0516 struct tep_format_field *tep_find_any_field(struct tep_event *event, const char *name);
0517 
0518 const char *tep_find_function(struct tep_handle *tep, unsigned long long addr);
0519 unsigned long long
0520 tep_find_function_address(struct tep_handle *tep, unsigned long long addr);
0521 unsigned long long tep_read_number(struct tep_handle *tep, const void *ptr, int size);
0522 int tep_read_number_field(struct tep_format_field *field, const void *data,
0523               unsigned long long *value);
0524 
0525 struct tep_event *tep_get_first_event(struct tep_handle *tep);
0526 int tep_get_events_count(struct tep_handle *tep);
0527 struct tep_event *tep_find_event(struct tep_handle *tep, int id);
0528 
0529 struct tep_event *
0530 tep_find_event_by_name(struct tep_handle *tep, const char *sys, const char *name);
0531 struct tep_event *
0532 tep_find_event_by_record(struct tep_handle *tep, struct tep_record *record);
0533 
0534 int tep_data_type(struct tep_handle *tep, struct tep_record *rec);
0535 int tep_data_pid(struct tep_handle *tep, struct tep_record *rec);
0536 int tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec);
0537 int tep_data_flags(struct tep_handle *tep, struct tep_record *rec);
0538 const char *tep_data_comm_from_pid(struct tep_handle *tep, int pid);
0539 struct tep_cmdline;
0540 struct tep_cmdline *tep_data_pid_from_comm(struct tep_handle *tep, const char *comm,
0541                        struct tep_cmdline *next);
0542 int tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline);
0543 
0544 void tep_print_field(struct trace_seq *s, void *data,
0545              struct tep_format_field *field);
0546 void tep_print_fields(struct trace_seq *s, void *data,
0547               int size __maybe_unused, struct tep_event *event);
0548 int tep_strerror(struct tep_handle *tep, enum tep_errno errnum,
0549          char *buf, size_t buflen);
0550 
0551 struct tep_event **tep_list_events(struct tep_handle *tep, enum tep_event_sort_type);
0552 struct tep_event **tep_list_events_copy(struct tep_handle *tep,
0553                     enum tep_event_sort_type);
0554 struct tep_format_field **tep_event_common_fields(struct tep_event *event);
0555 struct tep_format_field **tep_event_fields(struct tep_event *event);
0556 
0557 enum tep_endian {
0558         TEP_LITTLE_ENDIAN = 0,
0559         TEP_BIG_ENDIAN
0560 };
0561 int tep_get_cpus(struct tep_handle *tep);
0562 void tep_set_cpus(struct tep_handle *tep, int cpus);
0563 int tep_get_long_size(struct tep_handle *tep);
0564 void tep_set_long_size(struct tep_handle *tep, int long_size);
0565 int tep_get_page_size(struct tep_handle *tep);
0566 void tep_set_page_size(struct tep_handle *tep, int _page_size);
0567 bool tep_is_file_bigendian(struct tep_handle *tep);
0568 void tep_set_file_bigendian(struct tep_handle *tep, enum tep_endian endian);
0569 bool tep_is_local_bigendian(struct tep_handle *tep);
0570 void tep_set_local_bigendian(struct tep_handle *tep, enum tep_endian endian);
0571 int tep_get_header_page_size(struct tep_handle *tep);
0572 int tep_get_header_timestamp_size(struct tep_handle *tep);
0573 bool tep_is_old_format(struct tep_handle *tep);
0574 void tep_set_test_filters(struct tep_handle *tep, int test_filters);
0575 
0576 struct tep_handle *tep_alloc(void);
0577 void tep_free(struct tep_handle *tep);
0578 void tep_ref(struct tep_handle *tep);
0579 void tep_unref(struct tep_handle *tep);
0580 int tep_get_ref(struct tep_handle *tep);
0581 
0582 /* for debugging */
0583 void tep_print_funcs(struct tep_handle *tep);
0584 void tep_print_printk(struct tep_handle *tep);
0585 
0586 /* ----------------------- filtering ----------------------- */
0587 
0588 enum tep_filter_boolean_type {
0589     TEP_FILTER_FALSE,
0590     TEP_FILTER_TRUE,
0591 };
0592 
0593 enum tep_filter_op_type {
0594     TEP_FILTER_OP_AND = 1,
0595     TEP_FILTER_OP_OR,
0596     TEP_FILTER_OP_NOT,
0597 };
0598 
0599 enum tep_filter_cmp_type {
0600     TEP_FILTER_CMP_NONE,
0601     TEP_FILTER_CMP_EQ,
0602     TEP_FILTER_CMP_NE,
0603     TEP_FILTER_CMP_GT,
0604     TEP_FILTER_CMP_LT,
0605     TEP_FILTER_CMP_GE,
0606     TEP_FILTER_CMP_LE,
0607     TEP_FILTER_CMP_MATCH,
0608     TEP_FILTER_CMP_NOT_MATCH,
0609     TEP_FILTER_CMP_REGEX,
0610     TEP_FILTER_CMP_NOT_REGEX,
0611 };
0612 
0613 enum tep_filter_exp_type {
0614     TEP_FILTER_EXP_NONE,
0615     TEP_FILTER_EXP_ADD,
0616     TEP_FILTER_EXP_SUB,
0617     TEP_FILTER_EXP_MUL,
0618     TEP_FILTER_EXP_DIV,
0619     TEP_FILTER_EXP_MOD,
0620     TEP_FILTER_EXP_RSHIFT,
0621     TEP_FILTER_EXP_LSHIFT,
0622     TEP_FILTER_EXP_AND,
0623     TEP_FILTER_EXP_OR,
0624     TEP_FILTER_EXP_XOR,
0625     TEP_FILTER_EXP_NOT,
0626 };
0627 
0628 enum tep_filter_arg_type {
0629     TEP_FILTER_ARG_NONE,
0630     TEP_FILTER_ARG_BOOLEAN,
0631     TEP_FILTER_ARG_VALUE,
0632     TEP_FILTER_ARG_FIELD,
0633     TEP_FILTER_ARG_EXP,
0634     TEP_FILTER_ARG_OP,
0635     TEP_FILTER_ARG_NUM,
0636     TEP_FILTER_ARG_STR,
0637 };
0638 
0639 enum tep_filter_value_type {
0640     TEP_FILTER_NUMBER,
0641     TEP_FILTER_STRING,
0642     TEP_FILTER_CHAR
0643 };
0644 
0645 struct tep_filter_arg;
0646 
0647 struct tep_filter_arg_boolean {
0648     enum tep_filter_boolean_type    value;
0649 };
0650 
0651 struct tep_filter_arg_field {
0652     struct tep_format_field     *field;
0653 };
0654 
0655 struct tep_filter_arg_value {
0656     enum tep_filter_value_type  type;
0657     union {
0658         char            *str;
0659         unsigned long long  val;
0660     };
0661 };
0662 
0663 struct tep_filter_arg_op {
0664     enum tep_filter_op_type     type;
0665     struct tep_filter_arg       *left;
0666     struct tep_filter_arg       *right;
0667 };
0668 
0669 struct tep_filter_arg_exp {
0670     enum tep_filter_exp_type    type;
0671     struct tep_filter_arg       *left;
0672     struct tep_filter_arg       *right;
0673 };
0674 
0675 struct tep_filter_arg_num {
0676     enum tep_filter_cmp_type    type;
0677     struct tep_filter_arg       *left;
0678     struct tep_filter_arg       *right;
0679 };
0680 
0681 struct tep_filter_arg_str {
0682     enum tep_filter_cmp_type    type;
0683     struct tep_format_field     *field;
0684     char                *val;
0685     char                *buffer;
0686     regex_t             reg;
0687 };
0688 
0689 struct tep_filter_arg {
0690     enum tep_filter_arg_type        type;
0691     union {
0692         struct tep_filter_arg_boolean   boolean;
0693         struct tep_filter_arg_field field;
0694         struct tep_filter_arg_value value;
0695         struct tep_filter_arg_op    op;
0696         struct tep_filter_arg_exp   exp;
0697         struct tep_filter_arg_num   num;
0698         struct tep_filter_arg_str   str;
0699     };
0700 };
0701 
0702 struct tep_filter_type {
0703     int         event_id;
0704     struct tep_event    *event;
0705     struct tep_filter_arg   *filter;
0706 };
0707 
0708 #define TEP_FILTER_ERROR_BUFSZ  1024
0709 
0710 struct tep_event_filter {
0711     struct tep_handle   *tep;
0712     int         filters;
0713     struct tep_filter_type  *event_filters;
0714     char            error_buffer[TEP_FILTER_ERROR_BUFSZ];
0715 };
0716 
0717 struct tep_event_filter *tep_filter_alloc(struct tep_handle *tep);
0718 
0719 /* for backward compatibility */
0720 #define FILTER_NONE     TEP_ERRNO__NO_FILTER
0721 #define FILTER_NOEXIST      TEP_ERRNO__FILTER_NOT_FOUND
0722 #define FILTER_MISS     TEP_ERRNO__FILTER_MISS
0723 #define FILTER_MATCH        TEP_ERRNO__FILTER_MATCH
0724 
0725 enum tep_errno tep_filter_add_filter_str(struct tep_event_filter *filter,
0726                      const char *filter_str);
0727 
0728 enum tep_errno tep_filter_match(struct tep_event_filter *filter,
0729                 struct tep_record *record);
0730 
0731 int tep_filter_strerror(struct tep_event_filter *filter, enum tep_errno err,
0732             char *buf, size_t buflen);
0733 
0734 int tep_event_filtered(struct tep_event_filter *filter,
0735                int event_id);
0736 
0737 void tep_filter_reset(struct tep_event_filter *filter);
0738 
0739 void tep_filter_free(struct tep_event_filter *filter);
0740 
0741 char *tep_filter_make_string(struct tep_event_filter *filter, int event_id);
0742 
0743 int tep_filter_remove_event(struct tep_event_filter *filter,
0744                 int event_id);
0745 
0746 int tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *source);
0747 
0748 int tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2);
0749 
0750 #endif /* _PARSE_EVENTS_H */