Massive debugging in lttv filter core:
[lttv.git] / ltt / branches / poly / lttv / lttv / filter.h
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
30 /* A filter expression consists in nested AND, OR and NOT expressions
31 involving boolean relation (>, >=, =, !=, <, <=) between event fields and
32 specific values. It is compiled into an efficient data structure which
33 is used in functions to check if a given event or tracefile satisfies the
34 filter.
35
36 The grammar for filters is:
37
38 filter = expression
39
40 expression = "(" expression ")" | "!" expression |
41 expression "&&" expression | expression "||" expression |
42 simpleExpression
43
44 simpleExpression = fieldPath op value
45
46 fieldPath = fieldComponent [ "." fieldPath ]
47
48 fieldComponent = name [ "[" integer "]" ]
49
50 value = integer | double | string
51
52 */
53
54 /**
55 * @enum LttvStructType
56 * @brief The lttv structures
57 *
58 * the LttvStructType enumerates
59 * the possible structures for the
60 * lttv core filter
61 */
62 enum _LttvStructType {
63 LTTV_FILTER_TRACE,
64 LTTV_FILTER_TRACESET,
65 LTTV_FILTER_TRACEFILE,
66 LTTV_FILTER_EVENT,
67 LTTV_FILTER_STATE
68 } LttvStructType;
69
70 /**
71 * @enum LttvFieldType
72 * @brief Possible fields for the structures
73 *
74 * the LttvFieldType enum consists on
75 * all the hardcoded structures and
76 * their appropriate fields on which
77 * filters can be applied.
78 */
79 enum _LttvFieldType {
80 LTTV_FILTER_TRACE_NAME, /** trace.name (char*) */
81 LTTV_FILTER_TRACEFILE_NAME, /** tracefile.name (char*) */
82 LTTV_FILTER_STATE_PID, /** state.pid (guint) */
83 LTTV_FILTER_STATE_PPID, /** state.ppid (guint) */
84 LTTV_FILTER_STATE_CT, /** state.creation_time (double) */
85 LTTV_FILTER_STATE_IT, /** state.insertion_time (double) */
86 LTTV_FILTER_STATE_P_NAME, /** state.process_name (char*) */
87 LTTV_FILTER_STATE_EX_MODE, /** state.execution_mode (LttvExecutionMode) */
88 LTTV_FILTER_STATE_EX_SUBMODE, /** state.execution_submode (LttvExecutionSubmode) */
89 LTTV_FILTER_STATE_P_STATUS, /** state.process_status (LttvProcessStatus) */
90 LTTV_FILTER_STATE_CPU, /** state.cpu (?last_cpu?) */
91 LTTV_FILTER_EVENT_NAME, /** event.name (char*) */
92 LTTV_FILTER_EVENT_CATEGORY, /** FIXME: not implemented */
93 LTTV_FILTER_EVENT_TIME, /** event.time (double) */
94 LTTV_FILTER_EVENT_TSC, /** event.tsc (double) */
95 LTTV_FILTER_EVENT_FIELD,
96 LTTV_FILTER_UNDEFINED
97 // LTTV_FILTER_CATEGORY,
98 // LTTV_FILTER_TIME,
99 // LTTV_FILTER_TSC,
100 // LTTV_FILTER_PID,
101 // LTTV_FILTER_PPID,
102 // LTTV_FILTER_C_TIME,
103 // LTTV_FILTER_I_TIME,
104 // LTTV_FILTER_P_NAME,
105 // LTTV_FILTER_EX_MODE,
106 // LTTV_FILTER_EX_SUBMODE,
107 // LTTV_FILTER_P_STATUS,
108 // LTTV_FILTER_CPU
109 } LttvFieldType;
110
111 /**
112 * @enum LttvExpressionOp
113 */
114 typedef enum _LttvExpressionOp
115 {
116 LTTV_FIELD_EQ, /** equal */
117 LTTV_FIELD_NE, /** not equal */
118 LTTV_FIELD_LT, /** lower than */
119 LTTV_FIELD_LE, /** lower or equal */
120 LTTV_FIELD_GT, /** greater than */
121 LTTV_FIELD_GE /** greater or equal */
122 } LttvExpressionOp;
123
124 /**
125 * @enum LttvTreeElement
126 * @brief element types for the tree nodes
127 *
128 * LttvTreeElement defines the possible
129 * types of nodes which build the LttvFilterTree.
130 */
131 typedef enum _LttvTreeElement {
132 LTTV_TREE_IDLE, /** this node does nothing */
133 LTTV_TREE_NODE, /** this node contains a logical operator */
134 LTTV_TREE_LEAF /** this node is a leaf and contains a simple expression */
135 } LttvTreeElement;
136
137 /**
138 * @enum LttvSimpleExpression
139 * @brief simple expression structure
140 *
141 * An LttvSimpleExpression is the base
142 * of all filtering operations. It also
143 * populates the leaves of the
144 * LttvFilterTree. Each expression
145 * consists basically in a structure
146 * field, an operator and a specific
147 * value.
148 */
149 typedef struct _LttvSimpleExpression
150 {
151 // char *field_name;
152 gint field;
153 gint offset;
154 // LttvExpressionOp op;
155 gboolean (*op)(gpointer,char*);
156 char *value;
157 } LttvSimpleExpression;
158
159 /**
160 * @enum LttvLogicalOp
161 * @brief logical operators
162 *
163 * Contains the possible values taken
164 * by logical operator used to link
165 * simple expression. Values are
166 * AND, OR, XOR or NOT
167 */
168 typedef enum _LttvLogicalOp {
169 LTTV_LOGICAL_OR = 1, /* 1 */
170 LTTV_LOGICAL_AND = 1<<1, /* 2 */
171 LTTV_LOGICAL_NOT = 1<<2, /* 4 */
172 LTTV_LOGICAL_XOR = 1<<3 /* 8 */
173 } LttvLogicalOp;
174
175 /**
176 * @struct LttvFilterTree
177 * The filtering tree is used to represent the
178 * expression string in its entire hierarchy
179 * composed of simple expressions and logical
180 * operators
181 */
182 typedef struct _LttvFilterTree {
183 int node; /** value of LttvLogicalOp */
184 LttvTreeElement left;
185 LttvTreeElement right;
186 union {
187 struct LttvFilter* t;
188 LttvSimpleExpression* leaf;
189 } l_child;
190 union {
191 struct LttvFilter* t;
192 LttvSimpleExpression* leaf;
193 } r_child;
194 } LttvFilterTree;
195
196 /**
197 * @struct lttv_filter
198 * Contains a binary tree of filtering options along
199 * with the expression itself.
200 */
201 typedef struct _LttvFilter {
202 char *expression;
203 LttvFilterTree *head;
204 } LttvFilter;
205
206 /*
207 * General Data Handling functions
208 */
209
210 LttvSimpleExpression* lttv_simple_expression_new();
211
212 void lttv_filter_tree_add_node(GPtrArray* stack, LttvFilterTree* subtree, LttvLogicalOp op);
213
214 gboolean parse_field_path(GPtrArray* fp, LttvSimpleExpression* se);
215
216 gboolean assign_operator(LttvSimpleExpression* se, LttvExpressionOp op);
217
218
219
220 /*
221 * Logical operators functions
222 */
223
224 gboolean lttv_apply_op_eq_uint64(gpointer v1, char* v2);
225 gboolean lttv_apply_op_eq_uint32(gpointer v1, char* v2);
226 gboolean lttv_apply_op_eq_uint16(gpointer v1, char* v2);
227 gboolean lttv_apply_op_eq_double(gpointer v1, char* v2);
228 gboolean lttv_apply_op_eq_string(gpointer v1, char* v2);
229
230 gboolean lttv_apply_op_ne_uint64(gpointer v1, char* v2);
231 gboolean lttv_apply_op_ne_uint32(gpointer v1, char* v2);
232 gboolean lttv_apply_op_ne_uint16(gpointer v1, char* v2);
233 gboolean lttv_apply_op_ne_double(gpointer v1, char* v2);
234 gboolean lttv_apply_op_ne_string(gpointer v1, char* v2);
235
236 gboolean lttv_apply_op_lt_uint64(gpointer v1, char* v2);
237 gboolean lttv_apply_op_lt_uint32(gpointer v1, char* v2);
238 gboolean lttv_apply_op_lt_uint16(gpointer v1, char* v2);
239 gboolean lttv_apply_op_lt_double(gpointer v1, char* v2);
240
241 gboolean lttv_apply_op_le_uint64(gpointer v1, char* v2);
242 gboolean lttv_apply_op_le_uint32(gpointer v1, char* v2);
243 gboolean lttv_apply_op_le_uint16(gpointer v1, char* v2);
244 gboolean lttv_apply_op_le_double(gpointer v1, char* v2);
245
246 gboolean lttv_apply_op_gt_uint64(gpointer v1, char* v2);
247 gboolean lttv_apply_op_gt_uint32(gpointer v1, char* v2);
248 gboolean lttv_apply_op_gt_uint16(gpointer v1, char* v2);
249 gboolean lttv_apply_op_gt_double(gpointer v1, char* v2);
250
251 gboolean lttv_apply_op_ge_uint64(gpointer v1, char* v2);
252 gboolean lttv_apply_op_ge_uint32(gpointer v1, char* v2);
253 gboolean lttv_apply_op_ge_uint16(gpointer v1, char* v2);
254 gboolean lttv_apply_op_ge_double(gpointer v1, char* v2);
255
256 /*
257 * Cloning
258 */
259
260 LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree* tree);
261
262 LttvFilter* lttv_filter_clone(LttvFilter* filter);
263
264 /*
265 * Constructors/Destructors
266 */
267
268 /* LttvFilter */
269 LttvFilter *lttv_filter_new();
270
271 gboolean lttv_filter_update(LttvFilter* filter);
272
273 void lttv_filter_destroy(LttvFilter* filter);
274
275 void lttv_filter_append_expression(LttvFilter* filter, char *expression);
276
277 void lttv_filter_clear_expression(LttvFilter* filter);
278
279 /* LttvFilterTree */
280 LttvFilterTree* lttv_filter_tree_new();
281
282 void lttv_filter_tree_destroy(LttvFilterTree* tree);
283
284 gboolean lttv_filter_tree_parse(
285 LttvFilterTree* t,
286 LttEvent* event,
287 LttTracefile* tracefile,
288 LttTrace* trace,
289 LttvProcessState* state);
290
291 /*
292 * Hook functions
293 *
294 * These hook functions will be the one called when filtering
295 * an event, a trace, a state, etc.
296 */
297
298 /* Check if the tracefile or event satisfies the filter. The arguments are
299 declared as void * to allow these functions to be used as hooks. */
300
301 gboolean lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile);
302
303 gboolean lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate);
304
305 gboolean lttv_filter_event(LttvFilter *filter, LttEvent *event);
306
307 /*
308 * Debug functions
309 */
310 void lttv_print_tree(LttvFilterTree* t);
311
312 #endif // FILTER_H
313
This page took 0.035462 seconds and 5 git commands to generate.