| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2003-2004 Michel Dagenais |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation; |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 16 | * MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef FILTER_H |
| 20 | #define FILTER_H |
| 21 | |
| 22 | #include <lttv/traceset.h> |
| 23 | #include <lttv/tracecontext.h> |
| 24 | #include <lttv/state.h> |
| 25 | #include <lttv/module.h> |
| 26 | #include <ltt/ltt.h> |
| 27 | #include <ltt/event.h> |
| 28 | |
| 29 | #define AVERAGE_EXPRESSION_LENGTH 6 |
| 30 | #define MAX_FACTOR 1.5 |
| 31 | |
| 32 | /* A filter expression consists in nested AND, OR and NOT expressions |
| 33 | involving boolean relation (>, >=, =, !=, <, <=) between event fields and |
| 34 | specific values. It is compiled into an efficient data structure which |
| 35 | is used in functions to check if a given event or tracefile satisfies the |
| 36 | filter. |
| 37 | |
| 38 | The grammar for filters is: |
| 39 | |
| 40 | filter = expression |
| 41 | |
| 42 | expression = "(" expression ")" | "!" expression | |
| 43 | expression "&&" expression | expression "||" expression | |
| 44 | simpleExpression |
| 45 | |
| 46 | simpleExpression = fieldPath op value |
| 47 | |
| 48 | fieldPath = fieldComponent [ "." fieldPath ] |
| 49 | |
| 50 | fieldComponent = name [ "[" integer "]" ] |
| 51 | |
| 52 | value = integer | double | string |
| 53 | |
| 54 | */ |
| 55 | |
| 56 | extern GQuark |
| 57 | LTTV_FILTER_TRACE, |
| 58 | LTTV_FILTER_TRACESET, |
| 59 | LTTV_FILTER_TRACEFILE, |
| 60 | LTTV_FILTER_STATE, |
| 61 | LTTV_FILTER_EVENT, |
| 62 | LTTV_FILTER_NAME, |
| 63 | LTTV_FILTER_CATEGORY, |
| 64 | LTTV_FILTER_TIME, |
| 65 | LTTV_FILTER_TSC, |
| 66 | LTTV_FILTER_PID, |
| 67 | LTTV_FILTER_PPID, |
| 68 | LTTV_FILTER_C_TIME, |
| 69 | LTTV_FILTER_I_TIME, |
| 70 | LTTV_FILTER_P_NAME, |
| 71 | LTTV_FILTER_EX_MODE, |
| 72 | LTTV_FILTER_EX_SUBMODE, |
| 73 | LTTV_FILTER_P_STATUS, |
| 74 | LTTV_FILTER_CPU; |
| 75 | |
| 76 | /** |
| 77 | * @enum lttv_expression_op |
| 78 | */ |
| 79 | typedef enum _lttv_expression_op |
| 80 | { |
| 81 | LTTV_FIELD_EQ, /** equal */ |
| 82 | LTTV_FIELD_NE, /** not equal */ |
| 83 | LTTV_FIELD_LT, /** lower than */ |
| 84 | LTTV_FIELD_LE, /** lower or equal */ |
| 85 | LTTV_FIELD_GT, /** greater than */ |
| 86 | LTTV_FIELD_GE /** greater or equal */ |
| 87 | } lttv_expression_op; |
| 88 | |
| 89 | typedef enum _lttv_expression_type |
| 90 | { |
| 91 | LTTV_EXPRESSION, |
| 92 | LTTV_SIMPLE_EXPRESSION |
| 93 | } lttv_expression_type; |
| 94 | |
| 95 | typedef struct _lttv_simple_expression |
| 96 | { |
| 97 | lttv_expression_op op; |
| 98 | char *field_name; |
| 99 | char *value; |
| 100 | } lttv_simple_expression; |
| 101 | |
| 102 | typedef enum _lttv_logical_op { |
| 103 | OR = 1, /* 1 */ |
| 104 | AND = 1<<1, /* 2 */ |
| 105 | NOT = 1<<2, /* 4 */ |
| 106 | XOR = 1<<3 /* 8 */ |
| 107 | } lttv_logical_op; |
| 108 | |
| 109 | /* |
| 110 | * Ah .. that's my tree |
| 111 | */ |
| 112 | typedef struct _lttv_expression |
| 113 | { |
| 114 | // gboolean simple_expression; |
| 115 | int op; |
| 116 | lttv_expression_type type; |
| 117 | union { |
| 118 | struct lttv_expression *e; |
| 119 | // lttv_field_relation *se; /* --> simple expression */ |
| 120 | } e; |
| 121 | } lttv_expression; |
| 122 | |
| 123 | |
| 124 | //typedef union _lttv_expression { |
| 125 | // lttv_simple_expression se; |
| 126 | // |
| 127 | //} lttv_expression; |
| 128 | |
| 129 | typedef struct _lttv_filter_tree { |
| 130 | lttv_expression* node; |
| 131 | struct lttv_filter_tree* r_child; |
| 132 | struct lttv_filter_tree* l_child; |
| 133 | } lttv_filter_tree; |
| 134 | |
| 135 | /** |
| 136 | * @struct lttv_filter |
| 137 | * ( will later contain a binary tree of filtering options ) |
| 138 | */ |
| 139 | typedef struct _lttv_filter_t { |
| 140 | lttv_filter_tree* tree; |
| 141 | } lttv_filter_t; |
| 142 | |
| 143 | /* Parse field path contained in list */ |
| 144 | gboolean parse_field_path(GList* fp); |
| 145 | |
| 146 | |
| 147 | gboolean parse_simple_expression(GString* expression); |
| 148 | |
| 149 | /* Compile the filter expression into an efficient data structure */ |
| 150 | lttv_filter_t *lttv_filter_new(char *expression, LttvTraceState *tfs); |
| 151 | |
| 152 | |
| 153 | /* Check if the tracefile or event satisfies the filter. The arguments are |
| 154 | declared as void * to allow these functions to be used as hooks. */ |
| 155 | |
| 156 | gboolean lttv_filter_tracefile(lttv_filter_t *filter, LttTracefile *tracefile); |
| 157 | |
| 158 | gboolean lttv_filter_tracestate(lttv_filter_t *filter, LttvTraceState *tracestate); |
| 159 | |
| 160 | gboolean lttv_filter_event(lttv_filter_t *filter, LttEvent *event); |
| 161 | |
| 162 | #endif // FILTER_H |
| 163 | |