9c312311 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
0769c82f |
2 | * Copyright (C) 2003-2005 Michel Dagenais |
9c312311 |
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 | |
31452f49 |
19 | /* |
a4c292d4 |
20 | read_token |
48f6f3c2 |
21 | |
a4c292d4 |
22 | read_expression |
23 | ( read expr ) |
24 | simple expr [ op expr ] |
48f6f3c2 |
25 | |
a4c292d4 |
26 | read_simple_expression |
27 | read_field_path [ rel value ] |
48f6f3c2 |
28 | |
a4c292d4 |
29 | read_field_path |
30 | read_field_component [. field path] |
48f6f3c2 |
31 | |
a4c292d4 |
32 | read_field_component |
33 | name [ \[ value \] ] |
48f6f3c2 |
34 | |
a4c292d4 |
35 | data struct: |
36 | and/or(left/right) |
37 | not(child) |
38 | op(left/right) |
39 | path(component...) -> field |
150f0d33 |
40 | |
41 | consist in AND, OR and NOT nested expressions, forming a tree with |
42 | simple relations as leaves. The simple relations test is a field |
43 | in an event is equal, not equal, smaller, smaller or equal, larger, or |
44 | larger or equal to a specified value. |
31452f49 |
45 | */ |
46 | |
150f0d33 |
47 | /* |
48 | * YET TO BE ANSWERED |
49 | * - none yet |
50 | */ |
51 | |
52 | /* |
53 | * TODO |
54 | * - refine switch of expression in multiple uses functions |
55 | * - remove the idle expressions in the tree **** |
56 | * - add the current simple expression to the tree |
389ba50e |
57 | * * clear the field_path array after use |
150f0d33 |
58 | */ |
59 | |
60 | #include <lttv/filter.h> |
61 | |
62 | /* |
1a7fa682 |
63 | GQuark |
64 | LTTV_FILTER_TRACE, |
65 | LTTV_FILTER_TRACESET, |
66 | LTTV_FILTER_TRACEFILE, |
67 | LTTV_FILTER_STATE, |
91ad3f0a |
68 | LTTV_FILTER_EVENT, |
69 | LTTV_FILTER_NAME, |
70 | LTTV_FILTER_CATEGORY, |
71 | LTTV_FILTER_TIME, |
72 | LTTV_FILTER_TSC, |
73 | LTTV_FILTER_PID, |
74 | LTTV_FILTER_PPID, |
75 | LTTV_FILTER_C_TIME, |
76 | LTTV_FILTER_I_TIME, |
77 | LTTV_FILTER_P_NAME, |
78 | LTTV_FILTER_EX_MODE, |
79 | LTTV_FILTER_EX_SUBMODE, |
80 | LTTV_FILTER_P_STATUS, |
81 | LTTV_FILTER_CPU; |
150f0d33 |
82 | */ |
0cdc2470 |
83 | |
f4e9dd16 |
84 | /** |
56e29124 |
85 | * @fn void lttv_filter_tree_add_node(GPtrArray*,LttvFilterTree*,LttvLogicalOp) |
86 | * |
150f0d33 |
87 | * add a node to the current tree |
bb87caa7 |
88 | * FIXME: Might be used to lower coding in lttv_filter_new switch expression |
150f0d33 |
89 | * @param stack the tree stack |
90 | * @param subtree the subtree if available (pointer or NULL) |
91 | * @param op the logical operator that will form the node |
f4e9dd16 |
92 | */ |
0cdc2470 |
93 | void |
5b729fcf |
94 | lttv_filter_tree_add_node(GPtrArray* stack, LttvFilterTree* subtree, LttvLogicalOp op) { |
0cdc2470 |
95 | |
5b729fcf |
96 | LttvFilterTree* t1 = NULL; |
97 | LttvFilterTree* t2 = NULL; |
0cdc2470 |
98 | |
5b729fcf |
99 | t1 = (LttvFilterTree*)g_ptr_array_index(stack,stack->len-1); |
56e29124 |
100 | while(t1->right != LTTV_TREE_IDLE) t1 = (LttvFilterTree*)t1->r_child.t; |
0cdc2470 |
101 | t2 = lttv_filter_tree_new(); |
102 | t2->node = op; |
103 | if(subtree != NULL) { |
104 | t2->left = LTTV_TREE_NODE; |
e00d6a24 |
105 | t2->l_child.t = subtree; |
0cdc2470 |
106 | subtree = NULL; |
107 | t1->right = LTTV_TREE_NODE; |
108 | t1->r_child.t = t2; |
109 | } else { |
110 | // a_simple_expression->value = a_field_component->str; |
111 | // a_field_component = g_string_new(""); |
112 | t2->left = LTTV_TREE_LEAF; |
113 | // t2->l_child.leaf = a_simple_expression; |
114 | // a_simple_expression = g_new(lttv_simple_expression,1); |
115 | t1->right = LTTV_TREE_NODE; |
116 | t1->r_child.t = t2; |
117 | } |
118 | |
119 | } |
120 | |
80f9611a |
121 | |
122 | /** |
56e29124 |
123 | * @fn LttvSimpleExpression* lttv_simple_expression_new() |
124 | * |
80f9611a |
125 | * Constructor for LttvSimpleExpression |
126 | * @return pointer to new LttvSimpleExpression |
127 | */ |
128 | LttvSimpleExpression* |
129 | lttv_simple_expression_new() { |
130 | |
131 | LttvSimpleExpression* se = g_new(LttvSimpleExpression,1); |
132 | |
133 | se->field = LTTV_FILTER_UNDEFINED; |
134 | se->op = NULL; |
135 | se->offset = 0; |
e00d6a24 |
136 | se->value.v_uint64 = 0; |
80f9611a |
137 | |
138 | return se; |
139 | } |
140 | |
0769c82f |
141 | /** |
56e29124 |
142 | * @fn gboolean lttv_simple_expression_add_field(GPtrArray*,LttvSimpleExpression*) |
143 | * |
0769c82f |
144 | * Parse through filtering field hierarchy as specified |
145 | * by user. This function compares each value to |
146 | * predetermined quarks |
147 | * @param fp The field path list |
bb87caa7 |
148 | * @param se current simple expression |
0769c82f |
149 | * @return success/failure of operation |
150 | */ |
151 | gboolean |
9ab5ebd7 |
152 | lttv_simple_expression_assign_field(GPtrArray* fp, LttvSimpleExpression* se) { |
0769c82f |
153 | |
f4e9dd16 |
154 | GString* f = NULL; |
73050a5f |
155 | |
2b99ec10 |
156 | if(fp->len < 2) return FALSE; |
56e29124 |
157 | g_assert(f=g_ptr_array_remove_index(fp,0)); |
73050a5f |
158 | |
47aa6e58 |
159 | /* |
160 | * Parse through the specified |
161 | * hardcoded fields. |
162 | * |
163 | * Take note however that the |
164 | * 'event' subfields might change |
165 | * depending on values specified |
166 | * in core.xml file. Hence, if |
167 | * none of the subfields in the |
168 | * array match the hardcoded |
169 | * subfields, it will be considered |
170 | * as a dynamic field |
171 | */ |
80f9611a |
172 | if(!g_strcasecmp(f->str,"trace") ) { |
47aa6e58 |
173 | /* |
174 | * Possible values: |
175 | * trace.name |
176 | */ |
73050a5f |
177 | g_string_free(f,TRUE); |
178 | f=g_ptr_array_remove_index(fp,0); |
80f9611a |
179 | if(!g_strcasecmp(f->str,"name")) { |
389ba50e |
180 | se->field = LTTV_FILTER_TRACE_NAME; |
181 | } |
80f9611a |
182 | } else if(!g_strcasecmp(f->str,"traceset") ) { |
47aa6e58 |
183 | /* |
184 | * FIXME: not yet implemented ! |
185 | */ |
80f9611a |
186 | } else if(!g_strcasecmp(f->str,"tracefile") ) { |
47aa6e58 |
187 | /* |
188 | * Possible values: |
189 | * tracefile.name |
190 | */ |
73050a5f |
191 | g_string_free(f,TRUE); |
192 | f=g_ptr_array_remove_index(fp,0); |
80f9611a |
193 | if(!g_strcasecmp(f->str,"name")) { |
389ba50e |
194 | se->field = LTTV_FILTER_TRACEFILE_NAME; |
195 | } |
80f9611a |
196 | } else if(!g_strcasecmp(f->str,"state") ) { |
47aa6e58 |
197 | /* |
198 | * Possible values: |
199 | * state.pid |
200 | * state.ppid |
201 | * state.creation_time |
202 | * state.insertion_time |
203 | * state.process_name |
204 | * state.execution_mode |
205 | * state.execution_submode |
206 | * state.process_status |
207 | * state.cpu |
208 | */ |
73050a5f |
209 | g_string_free(f,TRUE); |
210 | f=g_ptr_array_remove_index(fp,0); |
80f9611a |
211 | if(!g_strcasecmp(f->str,"pid") ) { |
389ba50e |
212 | se->field = LTTV_FILTER_STATE_PID; |
213 | } |
80f9611a |
214 | else if(!g_strcasecmp(f->str,"ppid") ) { |
389ba50e |
215 | se->field = LTTV_FILTER_STATE_PPID; |
216 | } |
80f9611a |
217 | else if(!g_strcasecmp(f->str,"creation_time") ) { |
389ba50e |
218 | se->field = LTTV_FILTER_STATE_CT; |
219 | } |
80f9611a |
220 | else if(!g_strcasecmp(f->str,"insertion_time") ) { |
389ba50e |
221 | se->field = LTTV_FILTER_STATE_IT; |
222 | } |
80f9611a |
223 | else if(!g_strcasecmp(f->str,"process_name") ) { |
389ba50e |
224 | se->field = LTTV_FILTER_STATE_P_NAME; |
225 | } |
80f9611a |
226 | else if(!g_strcasecmp(f->str,"execution_mode") ) { |
389ba50e |
227 | se->field = LTTV_FILTER_STATE_EX_MODE; |
228 | } |
80f9611a |
229 | else if(!g_strcasecmp(f->str,"execution_submode") ) { |
389ba50e |
230 | se->field = LTTV_FILTER_STATE_EX_SUBMODE; |
231 | } |
80f9611a |
232 | else if(!g_strcasecmp(f->str,"process_status") ) { |
389ba50e |
233 | se->field = LTTV_FILTER_STATE_P_STATUS; |
234 | } |
80f9611a |
235 | else if(!g_strcasecmp(f->str,"cpu") ) { |
389ba50e |
236 | se->field = LTTV_FILTER_STATE_CPU; |
237 | } |
80f9611a |
238 | } else if(!g_strcasecmp(f->str,"event") ) { |
389ba50e |
239 | /* |
240 | * Possible values: |
241 | * event.name |
242 | * event.category |
243 | * event.time |
244 | * event.tsc |
245 | */ |
73050a5f |
246 | g_string_free(f,TRUE); |
247 | f=g_ptr_array_remove_index(fp,0); |
80f9611a |
248 | if(!g_strcasecmp(f->str,"name") ) { |
389ba50e |
249 | se->field = LTTV_FILTER_EVENT_NAME; |
250 | } |
80f9611a |
251 | else if(!g_strcasecmp(f->str,"category") ) { |
389ba50e |
252 | /* |
253 | * FIXME: Category not yet functional in lttv |
254 | */ |
255 | se->field = LTTV_FILTER_EVENT_CATEGORY; |
256 | } |
80f9611a |
257 | else if(!g_strcasecmp(f->str,"time") ) { |
389ba50e |
258 | se->field = LTTV_FILTER_EVENT_TIME; |
2b99ec10 |
259 | } |
80f9611a |
260 | else if(!g_strcasecmp(f->str,"tsc") ) { |
389ba50e |
261 | se->field = LTTV_FILTER_EVENT_TSC; |
2b99ec10 |
262 | } |
263 | else { /* core.xml specified options */ |
389ba50e |
264 | se->field = LTTV_FILTER_EVENT_FIELD; |
2b99ec10 |
265 | } |
91ad3f0a |
266 | } else { |
267 | g_warning("Unrecognized field in filter string"); |
0769c82f |
268 | } |
47aa6e58 |
269 | |
56e29124 |
270 | /* free memory for last string */ |
73050a5f |
271 | g_string_free(f,TRUE); |
56e29124 |
272 | |
273 | /* array should be empty */ |
73050a5f |
274 | g_assert(fp->len == 0); |
56e29124 |
275 | |
276 | g_print("field: %i\n",se->field); |
277 | if(se->field == LTTV_FILTER_UNDEFINED) { |
278 | g_warning("The specified field was not recognized !"); |
279 | return FALSE; |
280 | } |
91ad3f0a |
281 | return TRUE; |
0769c82f |
282 | } |
283 | |
bb87caa7 |
284 | /** |
56e29124 |
285 | * @fn gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression*,LttvExpressionOp) |
286 | * |
bb87caa7 |
287 | * Sets the function pointer for the current |
288 | * Simple Expression |
289 | * @param se current simple expression |
290 | * @return success/failure of operation |
291 | */ |
56e29124 |
292 | gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression* se, LttvExpressionOp op) { |
aa4600f3 |
293 | |
cec3d7b0 |
294 | // g_print("se->field = %i\n",se->field); |
295 | // g_print("se->offset = %i\n",se->offset); |
296 | // g_print("se->op = %p\n",se->op); |
297 | // g_print("se->value = %s\n",se->value); |
73050a5f |
298 | |
bb87caa7 |
299 | switch(se->field) { |
56e29124 |
300 | /* |
301 | * string |
302 | */ |
bb87caa7 |
303 | case LTTV_FILTER_TRACE_NAME: |
304 | case LTTV_FILTER_TRACEFILE_NAME: |
305 | case LTTV_FILTER_STATE_P_NAME: |
306 | case LTTV_FILTER_EVENT_NAME: |
307 | switch(op) { |
308 | case LTTV_FIELD_EQ: |
309 | se->op = lttv_apply_op_eq_string; |
310 | break; |
311 | case LTTV_FIELD_NE: |
56e29124 |
312 | se->op = lttv_apply_op_ne_string; |
bb87caa7 |
313 | break; |
314 | default: |
73050a5f |
315 | g_warning("Error encountered in operator assignment = or != expected"); |
bb87caa7 |
316 | return FALSE; |
317 | } |
318 | break; |
56e29124 |
319 | /* |
320 | * integer |
321 | */ |
bb87caa7 |
322 | case LTTV_FILTER_STATE_PID: |
323 | case LTTV_FILTER_STATE_PPID: |
324 | case LTTV_FILTER_STATE_EX_MODE: |
325 | case LTTV_FILTER_STATE_EX_SUBMODE: |
326 | case LTTV_FILTER_STATE_P_STATUS: |
327 | switch(op) { |
328 | case LTTV_FIELD_EQ: |
329 | se->op = lttv_apply_op_eq_uint64; |
330 | break; |
331 | case LTTV_FIELD_NE: |
332 | se->op = lttv_apply_op_ne_uint64; |
333 | break; |
334 | case LTTV_FIELD_LT: |
335 | se->op = lttv_apply_op_lt_uint64; |
336 | break; |
337 | case LTTV_FIELD_LE: |
338 | se->op = lttv_apply_op_le_uint64; |
339 | break; |
340 | case LTTV_FIELD_GT: |
341 | se->op = lttv_apply_op_gt_uint64; |
342 | break; |
343 | case LTTV_FIELD_GE: |
344 | se->op = lttv_apply_op_ge_uint64; |
345 | break; |
346 | default: |
347 | g_warning("Error encountered in operator assignment"); |
348 | return FALSE; |
349 | } |
350 | break; |
56e29124 |
351 | /* |
352 | * double |
353 | */ |
bb87caa7 |
354 | case LTTV_FILTER_STATE_CT: |
355 | case LTTV_FILTER_STATE_IT: |
356 | case LTTV_FILTER_EVENT_TIME: |
357 | case LTTV_FILTER_EVENT_TSC: |
358 | switch(op) { |
359 | case LTTV_FIELD_EQ: |
360 | se->op = lttv_apply_op_eq_double; |
361 | break; |
362 | case LTTV_FIELD_NE: |
363 | se->op = lttv_apply_op_ne_double; |
364 | break; |
365 | case LTTV_FIELD_LT: |
366 | se->op = lttv_apply_op_lt_double; |
367 | break; |
368 | case LTTV_FIELD_LE: |
369 | se->op = lttv_apply_op_le_double; |
370 | break; |
371 | case LTTV_FIELD_GT: |
372 | se->op = lttv_apply_op_gt_double; |
373 | break; |
374 | case LTTV_FIELD_GE: |
375 | se->op = lttv_apply_op_ge_double; |
376 | break; |
377 | default: |
378 | g_warning("Error encountered in operator assignment"); |
379 | return FALSE; |
380 | } |
381 | break; |
382 | default: |
9ab5ebd7 |
383 | g_warning("Error encountered in operator assignation ! Field type:%i",se->field); |
bb87caa7 |
384 | return FALSE; |
385 | } |
aa4600f3 |
386 | |
387 | return TRUE; |
bb87caa7 |
388 | |
389 | } |
390 | |
9ab5ebd7 |
391 | /** |
392 | * @fn void lttv_simple_expression_assign_value(LttvSimpleExpression*,char*) |
393 | * |
394 | * Assign the value field to the current LttvSimpleExpression |
395 | * @param se pointer to the current LttvSimpleExpression |
396 | * @param value string value for simple expression |
397 | */ |
398 | gboolean lttv_simple_expression_assign_value(LttvSimpleExpression* se, char* value) { |
399 | |
400 | g_print("se->value:%s\n",value); |
401 | |
402 | switch(se->field) { |
403 | /* |
404 | * string |
405 | */ |
406 | case LTTV_FILTER_TRACE_NAME: |
407 | case LTTV_FILTER_TRACEFILE_NAME: |
408 | case LTTV_FILTER_STATE_P_NAME: |
409 | case LTTV_FILTER_EVENT_NAME: |
410 | se->value.v_string = value; |
411 | break; |
412 | /* |
413 | * integer |
414 | */ |
415 | case LTTV_FILTER_STATE_PID: |
416 | case LTTV_FILTER_STATE_PPID: |
417 | case LTTV_FILTER_STATE_EX_MODE: |
418 | case LTTV_FILTER_STATE_EX_SUBMODE: |
419 | case LTTV_FILTER_STATE_P_STATUS: |
420 | se->value.v_uint64 = atoi(value); |
421 | g_free(value); |
422 | break; |
423 | /* |
424 | * double |
425 | */ |
426 | case LTTV_FILTER_STATE_CT: |
427 | case LTTV_FILTER_STATE_IT: |
428 | case LTTV_FILTER_EVENT_TIME: |
429 | case LTTV_FILTER_EVENT_TSC: |
430 | se->value.v_double = atof(value); |
431 | g_free(value); |
432 | break; |
433 | default: |
434 | g_warning("Error encountered in value assignation ! Field type = %i",se->field); |
435 | return FALSE; |
436 | } |
437 | |
438 | return TRUE; |
439 | |
440 | } |
441 | |
31452f49 |
442 | /** |
56e29124 |
443 | * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*) |
444 | * |
9ab5ebd7 |
445 | * Disallocate memory for the current |
56e29124 |
446 | * simple expression |
447 | * @param se pointer to the current LttvSimpleExpression |
448 | */ |
449 | void |
450 | lttv_simple_expression_destroy(LttvSimpleExpression* se) { |
451 | |
9ab5ebd7 |
452 | // g_free(se->value); |
f3020899 |
453 | switch(se->field) { |
454 | case LTTV_FILTER_TRACE_NAME: |
455 | case LTTV_FILTER_TRACEFILE_NAME: |
456 | case LTTV_FILTER_STATE_P_NAME: |
457 | case LTTV_FILTER_EVENT_NAME: |
458 | g_free(se->value.v_string); |
459 | break; |
460 | } |
56e29124 |
461 | g_free(se); |
462 | |
463 | } |
464 | |
465 | /** |
466 | * @fn gint lttv_struct_type(gint) |
467 | * |
80f9611a |
468 | * Finds the structure type depending |
469 | * on the fields in parameters |
470 | * @params ft Field of the current structure |
471 | * @return LttvStructType enum or -1 for error |
84a333d6 |
472 | */ |
80f9611a |
473 | gint |
474 | lttv_struct_type(gint ft) { |
5f185a2b |
475 | |
80f9611a |
476 | switch(ft) { |
477 | case LTTV_FILTER_TRACE_NAME: |
478 | return LTTV_FILTER_TRACE; |
479 | break; |
480 | case LTTV_FILTER_TRACEFILE_NAME: |
481 | return LTTV_FILTER_TRACEFILE; |
482 | break; |
483 | case LTTV_FILTER_STATE_PID: |
484 | case LTTV_FILTER_STATE_PPID: |
485 | case LTTV_FILTER_STATE_CT: |
486 | case LTTV_FILTER_STATE_IT: |
487 | case LTTV_FILTER_STATE_P_NAME: |
488 | case LTTV_FILTER_STATE_EX_MODE: |
489 | case LTTV_FILTER_STATE_EX_SUBMODE: |
490 | case LTTV_FILTER_STATE_P_STATUS: |
491 | case LTTV_FILTER_STATE_CPU: |
492 | return LTTV_FILTER_STATE; |
493 | break; |
494 | case LTTV_FILTER_EVENT_NAME: |
495 | case LTTV_FILTER_EVENT_CATEGORY: |
496 | case LTTV_FILTER_EVENT_TIME: |
497 | case LTTV_FILTER_EVENT_TSC: |
498 | case LTTV_FILTER_EVENT_FIELD: |
499 | return LTTV_FILTER_EVENT; |
500 | break; |
501 | default: |
502 | return -1; |
503 | } |
84a333d6 |
504 | } |
505 | |
150f0d33 |
506 | /** |
56e29124 |
507 | * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue) |
508 | * |
150f0d33 |
509 | * Applies the 'equal' operator to the |
47aa6e58 |
510 | * specified structure and value |
511 | * @param v1 left member of comparison |
512 | * @param v2 right member of comparison |
150f0d33 |
513 | * @return success/failure of operation |
514 | */ |
9ab5ebd7 |
515 | gboolean lttv_apply_op_eq_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
516 | |
517 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
518 | return (*r == v2.v_uint64); |
83aa92fc |
519 | |
520 | } |
150f0d33 |
521 | |
5b729fcf |
522 | /** |
56e29124 |
523 | * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue) |
524 | * |
5b729fcf |
525 | * Applies the 'equal' operator to the |
47aa6e58 |
526 | * specified structure and value |
527 | * @param v1 left member of comparison |
528 | * @param v2 right member of comparison |
5b729fcf |
529 | * @return success/failure of operation |
530 | */ |
9ab5ebd7 |
531 | gboolean lttv_apply_op_eq_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
532 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
533 | return (*r == v2.v_uint32); |
83aa92fc |
534 | } |
5b729fcf |
535 | |
536 | /** |
56e29124 |
537 | * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue) |
538 | * |
5b729fcf |
539 | * Applies the 'equal' operator to the |
47aa6e58 |
540 | * specified structure and value |
541 | * @param v1 left member of comparison |
542 | * @param v2 right member of comparison |
5b729fcf |
543 | * @return success/failure of operation |
544 | */ |
9ab5ebd7 |
545 | gboolean lttv_apply_op_eq_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
546 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
547 | return (*r == v2.v_uint16); |
83aa92fc |
548 | } |
5b729fcf |
549 | |
550 | /** |
56e29124 |
551 | * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue) |
552 | * |
5b729fcf |
553 | * Applies the 'equal' operator to the |
47aa6e58 |
554 | * specified structure and value |
555 | * @param v1 left member of comparison |
556 | * @param v2 right member of comparison |
5b729fcf |
557 | * @return success/failure of operation |
558 | */ |
9ab5ebd7 |
559 | gboolean lttv_apply_op_eq_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
560 | double* r = (double*) v1; |
9ab5ebd7 |
561 | return (*r == v2.v_double); |
83aa92fc |
562 | } |
5b729fcf |
563 | |
564 | /** |
56e29124 |
565 | * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue) |
566 | * |
5b729fcf |
567 | * Applies the 'equal' operator to the |
47aa6e58 |
568 | * specified structure and value |
569 | * @param v1 left member of comparison |
570 | * @param v2 right member of comparison |
5b729fcf |
571 | * @return success/failure of operation |
572 | */ |
9ab5ebd7 |
573 | gboolean lttv_apply_op_eq_string(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
574 | char* r = (char*) v1; |
8ff6243c |
575 | g_print("v1:%s = v2:%s\n",r,v2.v_string); |
9ab5ebd7 |
576 | return (!g_strcasecmp(r,v2.v_string)); |
83aa92fc |
577 | } |
150f0d33 |
578 | |
579 | /** |
56e29124 |
580 | * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue) |
581 | * |
150f0d33 |
582 | * Applies the 'not equal' operator to the |
47aa6e58 |
583 | * specified structure and value |
584 | * @param v1 left member of comparison |
585 | * @param v2 right member of comparison |
150f0d33 |
586 | * @return success/failure of operation |
587 | */ |
9ab5ebd7 |
588 | gboolean lttv_apply_op_ne_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
589 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
590 | return (*r != v2.v_uint64); |
83aa92fc |
591 | } |
150f0d33 |
592 | |
5b729fcf |
593 | /** |
56e29124 |
594 | * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue) |
595 | * |
5b729fcf |
596 | * Applies the 'not equal' operator to the |
47aa6e58 |
597 | * specified structure and value |
598 | * @param v1 left member of comparison |
599 | * @param v2 right member of comparison |
5b729fcf |
600 | * @return success/failure of operation |
601 | */ |
9ab5ebd7 |
602 | gboolean lttv_apply_op_ne_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
603 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
604 | return (*r != v2.v_uint32); |
83aa92fc |
605 | } |
5b729fcf |
606 | |
607 | /** |
56e29124 |
608 | * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue) |
609 | * |
5b729fcf |
610 | * Applies the 'not equal' operator to the |
47aa6e58 |
611 | * specified structure and value |
612 | * @param v1 left member of comparison |
613 | * @param v2 right member of comparison |
5b729fcf |
614 | * @return success/failure of operation |
615 | */ |
9ab5ebd7 |
616 | gboolean lttv_apply_op_ne_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
617 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
618 | return (*r != v2.v_uint16); |
83aa92fc |
619 | } |
5b729fcf |
620 | |
621 | /** |
56e29124 |
622 | * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue) |
623 | * |
5b729fcf |
624 | * Applies the 'not equal' operator to the |
47aa6e58 |
625 | * specified structure and value |
626 | * @param v1 left member of comparison |
627 | * @param v2 right member of comparison |
5b729fcf |
628 | * @return success/failure of operation |
629 | */ |
9ab5ebd7 |
630 | gboolean lttv_apply_op_ne_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
631 | double* r = (double*) v1; |
9ab5ebd7 |
632 | return (*r != v2.v_double); |
83aa92fc |
633 | } |
5b729fcf |
634 | |
635 | /** |
56e29124 |
636 | * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue) |
637 | * |
5b729fcf |
638 | * Applies the 'not equal' operator to the |
47aa6e58 |
639 | * specified structure and value |
640 | * @param v1 left member of comparison |
641 | * @param v2 right member of comparison |
5b729fcf |
642 | * @return success/failure of operation |
643 | */ |
9ab5ebd7 |
644 | gboolean lttv_apply_op_ne_string(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
645 | char* r = (char*) v1; |
9ab5ebd7 |
646 | return (g_strcasecmp(r,v2.v_string)); |
83aa92fc |
647 | } |
150f0d33 |
648 | |
649 | /** |
56e29124 |
650 | * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue) |
651 | * |
150f0d33 |
652 | * Applies the 'lower than' operator to the |
47aa6e58 |
653 | * specified structure and value |
654 | * @param v1 left member of comparison |
655 | * @param v2 right member of comparison |
150f0d33 |
656 | * @return success/failure of operation |
657 | */ |
9ab5ebd7 |
658 | gboolean lttv_apply_op_lt_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
659 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
660 | return (*r < v2.v_uint64); |
83aa92fc |
661 | } |
150f0d33 |
662 | |
5b729fcf |
663 | /** |
56e29124 |
664 | * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue) |
665 | * |
5b729fcf |
666 | * Applies the 'lower than' operator to the |
47aa6e58 |
667 | * specified structure and value |
668 | * @param v1 left member of comparison |
669 | * @param v2 right member of comparison |
5b729fcf |
670 | * @return success/failure of operation |
671 | */ |
9ab5ebd7 |
672 | gboolean lttv_apply_op_lt_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
673 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
674 | return (*r < v2.v_uint32); |
83aa92fc |
675 | } |
5b729fcf |
676 | |
677 | /** |
56e29124 |
678 | * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue) |
679 | * |
5b729fcf |
680 | * Applies the 'lower than' operator to the |
47aa6e58 |
681 | * specified structure and value |
682 | * @param v1 left member of comparison |
683 | * @param v2 right member of comparison |
5b729fcf |
684 | * @return success/failure of operation |
685 | */ |
9ab5ebd7 |
686 | gboolean lttv_apply_op_lt_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
687 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
688 | return (*r < v2.v_uint16); |
83aa92fc |
689 | } |
5b729fcf |
690 | |
691 | /** |
56e29124 |
692 | * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue) |
693 | * |
5b729fcf |
694 | * Applies the 'lower than' operator to the |
47aa6e58 |
695 | * specified structure and value |
696 | * @param v1 left member of comparison |
697 | * @param v2 right member of comparison |
5b729fcf |
698 | * @return success/failure of operation |
699 | */ |
9ab5ebd7 |
700 | gboolean lttv_apply_op_lt_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
701 | double* r = (double*) v1; |
9ab5ebd7 |
702 | return (*r < v2.v_double); |
83aa92fc |
703 | } |
5b729fcf |
704 | |
705 | /** |
56e29124 |
706 | * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue) |
707 | * |
708 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
709 | * specified structure and value |
710 | * @param v1 left member of comparison |
711 | * @param v2 right member of comparison |
5b729fcf |
712 | * @return success/failure of operation |
713 | */ |
9ab5ebd7 |
714 | gboolean lttv_apply_op_le_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
715 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
716 | return (*r <= v2.v_uint64); |
83aa92fc |
717 | } |
150f0d33 |
718 | |
719 | /** |
56e29124 |
720 | * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue) |
721 | * |
150f0d33 |
722 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
723 | * specified structure and value |
724 | * @param v1 left member of comparison |
725 | * @param v2 right member of comparison |
150f0d33 |
726 | * @return success/failure of operation |
727 | */ |
9ab5ebd7 |
728 | gboolean lttv_apply_op_le_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
729 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
730 | return (*r <= v2.v_uint32); |
83aa92fc |
731 | } |
150f0d33 |
732 | |
5b729fcf |
733 | /** |
56e29124 |
734 | * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue) |
735 | * |
5b729fcf |
736 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
737 | * specified structure and value |
738 | * @param v1 left member of comparison |
739 | * @param v2 right member of comparison |
5b729fcf |
740 | * @return success/failure of operation |
741 | */ |
9ab5ebd7 |
742 | gboolean lttv_apply_op_le_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
743 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
744 | return (*r <= v2.v_uint16); |
83aa92fc |
745 | } |
5b729fcf |
746 | |
747 | /** |
56e29124 |
748 | * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue) |
749 | * |
5b729fcf |
750 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
751 | * specified structure and value |
752 | * @param v1 left member of comparison |
753 | * @param v2 right member of comparison |
5b729fcf |
754 | * @return success/failure of operation |
755 | */ |
9ab5ebd7 |
756 | gboolean lttv_apply_op_le_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
757 | double* r = (double*) v1; |
9ab5ebd7 |
758 | return (*r <= v2.v_double); |
83aa92fc |
759 | } |
5b729fcf |
760 | |
761 | /** |
56e29124 |
762 | * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue) |
763 | * |
83aa92fc |
764 | * Applies the 'greater than' operator to the |
47aa6e58 |
765 | * specified structure and value |
766 | * @param v1 left member of comparison |
767 | * @param v2 right member of comparison |
5b729fcf |
768 | * @return success/failure of operation |
769 | */ |
9ab5ebd7 |
770 | gboolean lttv_apply_op_gt_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
771 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
772 | return (*r > v2.v_uint64); |
83aa92fc |
773 | } |
150f0d33 |
774 | |
775 | /** |
56e29124 |
776 | * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue) |
777 | * |
150f0d33 |
778 | * Applies the 'greater than' operator to the |
47aa6e58 |
779 | * specified structure and value |
780 | * @param v1 left member of comparison |
781 | * @param v2 right member of comparison |
150f0d33 |
782 | * @return success/failure of operation |
783 | */ |
9ab5ebd7 |
784 | gboolean lttv_apply_op_gt_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
785 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
786 | return (*r > v2.v_uint32); |
83aa92fc |
787 | } |
150f0d33 |
788 | |
5b729fcf |
789 | /** |
56e29124 |
790 | * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue) |
791 | * |
5b729fcf |
792 | * Applies the 'greater than' operator to the |
47aa6e58 |
793 | * specified structure and value |
794 | * @param v1 left member of comparison |
795 | * @param v2 right member of comparison |
5b729fcf |
796 | * @return success/failure of operation |
797 | */ |
9ab5ebd7 |
798 | gboolean lttv_apply_op_gt_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
799 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
800 | return (*r > v2.v_uint16); |
83aa92fc |
801 | } |
5b729fcf |
802 | |
803 | /** |
56e29124 |
804 | * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue) |
805 | * |
5b729fcf |
806 | * Applies the 'greater than' operator to the |
47aa6e58 |
807 | * specified structure and value |
808 | * @param v1 left member of comparison |
809 | * @param v2 right member of comparison |
5b729fcf |
810 | * @return success/failure of operation |
811 | */ |
9ab5ebd7 |
812 | gboolean lttv_apply_op_gt_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
813 | double* r = (double*) v1; |
9ab5ebd7 |
814 | return (*r > v2.v_double); |
83aa92fc |
815 | } |
5b729fcf |
816 | |
817 | /** |
56e29124 |
818 | * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue) |
819 | * |
83aa92fc |
820 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
821 | * specified structure and value |
822 | * @param v1 left member of comparison |
823 | * @param v2 right member of comparison |
5b729fcf |
824 | * @return success/failure of operation |
825 | */ |
9ab5ebd7 |
826 | gboolean lttv_apply_op_ge_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
827 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
828 | return (*r >= v2.v_uint64); |
83aa92fc |
829 | } |
150f0d33 |
830 | |
831 | /** |
56e29124 |
832 | * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue) |
833 | * |
150f0d33 |
834 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
835 | * specified structure and value |
836 | * @param v1 left member of comparison |
837 | * @param v2 right member of comparison |
150f0d33 |
838 | * @return success/failure of operation |
839 | */ |
9ab5ebd7 |
840 | gboolean lttv_apply_op_ge_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
841 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
842 | return (*r >= v2.v_uint32); |
83aa92fc |
843 | } |
150f0d33 |
844 | |
5b729fcf |
845 | /** |
56e29124 |
846 | * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue) |
847 | * |
5b729fcf |
848 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
849 | * specified structure and value |
850 | * @param v1 left member of comparison |
851 | * @param v2 right member of comparison |
5b729fcf |
852 | * @return success/failure of operation |
853 | */ |
9ab5ebd7 |
854 | gboolean lttv_apply_op_ge_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
855 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
856 | return (*r >= v2.v_uint16); |
83aa92fc |
857 | } |
150f0d33 |
858 | |
5b729fcf |
859 | /** |
56e29124 |
860 | * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue) |
861 | * |
5b729fcf |
862 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
863 | * specified structure and value |
864 | * @param v1 left member of comparison |
865 | * @param v2 right member of comparison |
5b729fcf |
866 | * @return success/failure of operation |
867 | */ |
9ab5ebd7 |
868 | gboolean lttv_apply_op_ge_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
869 | double* r = (double*) v1; |
9ab5ebd7 |
870 | return (*r >= v2.v_double); |
83aa92fc |
871 | } |
150f0d33 |
872 | |
873 | |
874 | /** |
56e29124 |
875 | * @fn LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree*) |
876 | * |
877 | * Makes a copy of the current filter tree |
878 | * @param tree pointer to the current tree |
879 | * @return new copy of the filter tree |
150f0d33 |
880 | */ |
881 | LttvFilterTree* |
882 | lttv_filter_tree_clone(LttvFilterTree* tree) { |
883 | |
8c89f5a8 |
884 | LttvFilterTree* newtree = lttv_filter_tree_new(); |
150f0d33 |
885 | |
8c89f5a8 |
886 | newtree->node = tree->node; |
887 | |
888 | newtree->left = tree->left; |
889 | if(newtree->left == LTTV_TREE_NODE) { |
890 | newtree->l_child.t = lttv_filter_tree_clone(tree->l_child.t); |
891 | } else if(newtree->left == LTTV_TREE_LEAF) { |
892 | newtree->l_child.leaf = lttv_simple_expression_new(); |
893 | newtree->l_child.leaf->field = tree->l_child.leaf->field; |
894 | newtree->l_child.leaf->offset = tree->l_child.leaf->offset; |
895 | newtree->l_child.leaf->op = tree->l_child.leaf->op; |
9ab5ebd7 |
896 | /* FIXME: special case for string copy ! */ |
897 | newtree->l_child.leaf->value = tree->l_child.leaf->value; |
8c89f5a8 |
898 | } |
899 | |
900 | newtree->right = tree->right; |
901 | if(newtree->right == LTTV_TREE_NODE) { |
902 | newtree->r_child.t = lttv_filter_tree_clone(tree->r_child.t); |
903 | } else if(newtree->right == LTTV_TREE_LEAF) { |
904 | newtree->r_child.leaf = lttv_simple_expression_new(); |
905 | newtree->r_child.leaf->field = tree->r_child.leaf->field; |
906 | newtree->r_child.leaf->offset = tree->r_child.leaf->offset; |
907 | newtree->r_child.leaf->op = tree->r_child.leaf->op; |
9ab5ebd7 |
908 | newtree->r_child.leaf->value = tree->r_child.leaf->value; |
8c89f5a8 |
909 | } |
910 | |
911 | return newtree; |
912 | |
150f0d33 |
913 | } |
914 | |
915 | /** |
56e29124 |
916 | * @fn LttvFilter* lttv_filter_clone(LttvFilter*) |
917 | * |
918 | * Makes a copy of the current filter |
919 | * @param filter pointer to the current filter |
920 | * @return new copy of the filter |
150f0d33 |
921 | */ |
922 | LttvFilter* |
923 | lttv_filter_clone(LttvFilter* filter) { |
924 | |
925 | |
926 | LttvFilter* newfilter = g_new(LttvFilter,1); |
927 | |
928 | // newfilter->expression = g_new(char,1) |
929 | strcpy(newfilter->expression,filter->expression); |
930 | |
931 | newfilter->head = lttv_filter_tree_clone(filter->head); |
932 | |
933 | return newfilter; |
934 | |
935 | } |
936 | |
937 | |
84a333d6 |
938 | /** |
56e29124 |
939 | * @fn LttvFilter* lttv_filter_new() |
940 | * |
84a333d6 |
941 | * Creates a new lttv_filter |
31452f49 |
942 | * @param expression filtering options string |
943 | * @param t pointer to the current LttvTrace |
84a333d6 |
944 | * @return the current lttv_filter or NULL if error |
31452f49 |
945 | */ |
2ea36caf |
946 | LttvFilter* |
5f185a2b |
947 | lttv_filter_new() { |
a4c292d4 |
948 | |
5f185a2b |
949 | LttvFilter* filter = g_new(LttvFilter,1); |
950 | filter->expression = NULL; |
951 | filter->head = NULL; |
952 | |
953 | } |
a4c292d4 |
954 | |
8c89f5a8 |
955 | /** |
56e29124 |
956 | * @fn gboolean lttv_filter_update(LttvFilter*) |
957 | * |
8c89f5a8 |
958 | * Updates the current LttvFilter by building |
959 | * its tree based upon the expression string |
960 | * @param filter pointer to the current LttvFilter |
961 | * @return Failure/Success of operation |
962 | */ |
5f185a2b |
963 | gboolean |
964 | lttv_filter_update(LttvFilter* filter) { |
965 | |
966 | g_print("filter::lttv_filter_new()\n"); /* debug */ |
967 | |
968 | if(filter->expression == NULL) return FALSE; |
969 | |
f3020899 |
970 | int |
a4c292d4 |
971 | i, |
56e29124 |
972 | p_nesting=0; /* parenthesis nesting value */ |
1601b365 |
973 | |
974 | /* trees */ |
5b729fcf |
975 | LttvFilterTree |
1601b365 |
976 | *tree = lttv_filter_tree_new(), /* main tree */ |
977 | *subtree = NULL, /* buffer for subtrees */ |
978 | *t1, /* buffer #1 */ |
979 | *t2; /* buffer #2 */ |
980 | |
5f185a2b |
981 | /* |
982 | * the filter |
983 | * If the tree already exists, |
984 | * destroy it and build a new one |
985 | */ |
986 | if(filter->head != NULL) lttv_filter_tree_destroy(filter->head); |
f3020899 |
987 | filter->head = NULL; /* will be assigned at the end */ |
5f185a2b |
988 | |
1601b365 |
989 | /* |
990 | * Tree Stack |
f4e9dd16 |
991 | * each element of the list |
992 | * is a sub tree created |
993 | * by the use of parenthesis in the |
994 | * global expression. The final tree |
1601b365 |
995 | * will be the one left at the root of |
f4e9dd16 |
996 | * the list |
997 | */ |
18d1226f |
998 | GPtrArray *tree_stack = g_ptr_array_new(); |
999 | g_ptr_array_add( tree_stack,(gpointer) tree ); |
f4e9dd16 |
1000 | |
a4c292d4 |
1001 | /* temporary values */ |
0769c82f |
1002 | GString *a_field_component = g_string_new(""); |
56e29124 |
1003 | GPtrArray *a_field_path = g_ptr_array_new(); |
1004 | |
1005 | /* simple expression buffer */ |
389ba50e |
1006 | LttvSimpleExpression* a_simple_expression = lttv_simple_expression_new(); |
0769c82f |
1007 | |
a4c292d4 |
1008 | /* |
1009 | * Parse entire expression and construct |
1010 | * the binary tree. There are two steps |
1011 | * in browsing that string |
f4e9dd16 |
1012 | * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} " |
a4c292d4 |
1013 | * 2. finding simple expressions |
0769c82f |
1014 | * - field path ( separated by dots ) |
a4c292d4 |
1015 | * - op ( >, <, =, >=, <=, !=) |
0769c82f |
1016 | * - value ( integer, string ... ) |
1017 | * To spare computing time, the whole |
1018 | * string is parsed in this loop for a |
1019 | * O(n) complexity order. |
1601b365 |
1020 | * |
18d1226f |
1021 | * When encountering logical op &,|,^ |
1022 | * 1. parse the last value if any |
1023 | * 2. create a new tree |
1024 | * 3. add the expression (simple exp, or exp (subtree)) to the tree |
1025 | * 4. concatenate this tree with the current tree on top of the stack |
1026 | * When encountering math ops >,>=,<,<=,=,!= |
1027 | * 1. add to op to the simple expression |
1028 | * 2. concatenate last field component to field path |
1029 | * When encountering concatening ops . |
1030 | * 1. concatenate last field component to field path |
1031 | * When encountering opening parenthesis (,{,[ |
1032 | * 1. create a new subtree on top of tree stack |
1033 | * When encountering closing parenthesis ),},] |
1034 | * 1. add the expression on right child of the current tree |
1035 | * 2. the subtree is completed, allocate a new subtree |
1036 | * 3. pop the tree value from the tree stack |
1037 | */ |
1038 | |
73050a5f |
1039 | g_print("expression: %s\n",filter->expression); |
1040 | g_print("strlen(expression): %i\n",strlen(filter->expression)); |
5f185a2b |
1041 | for(i=0;i<strlen(filter->expression);i++) { |
1042 | // debug |
1043 | g_print("%c ",filter->expression[i]); |
1044 | switch(filter->expression[i]) { |
a4c292d4 |
1045 | /* |
1046 | * logical operators |
1047 | */ |
1048 | case '&': /* and */ |
aa4600f3 |
1049 | |
5b729fcf |
1050 | t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1051 | while(t1->right != LTTV_TREE_IDLE) { |
1052 | g_assert(t1->right == LTTV_TREE_NODE); |
1053 | t1 = t1->r_child.t; |
1054 | } |
18d1226f |
1055 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1056 | t2->node = LTTV_LOGICAL_AND; |
bb87caa7 |
1057 | if(subtree != NULL) { /* append subtree to current tree */ |
18d1226f |
1058 | t2->left = LTTV_TREE_NODE; |
1059 | t2->l_child.t = subtree; |
f4e9dd16 |
1060 | subtree = NULL; |
18d1226f |
1061 | t1->right = LTTV_TREE_NODE; |
410c83da |
1062 | t1->r_child.t = t2; |
bb87caa7 |
1063 | } else { /* append a simple expression */ |
9ab5ebd7 |
1064 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1065 | // a_simple_expression->value = g_string_free(a_field_component,FALSE); |
18d1226f |
1066 | a_field_component = g_string_new(""); |
1067 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
1068 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
1069 | a_simple_expression = lttv_simple_expression_new(); |
18d1226f |
1070 | t1->right = LTTV_TREE_NODE; |
9ab5ebd7 |
1071 | t1->r_child.t = t2; |
1072 | g_print("t1:%p t1->child:%p\n",t1,t1->r_child.t); |
f4e9dd16 |
1073 | } |
f4e9dd16 |
1074 | break; |
aa4600f3 |
1075 | |
a4c292d4 |
1076 | case '|': /* or */ |
aa4600f3 |
1077 | |
e00d6a24 |
1078 | t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1079 | while(t1->right != LTTV_TREE_IDLE) { |
1080 | g_assert(t1->right == LTTV_TREE_NODE); |
1081 | t1 = t1->r_child.t; |
1082 | } |
1601b365 |
1083 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1084 | t2->node = LTTV_LOGICAL_OR; |
bb87caa7 |
1085 | if(subtree != NULL) { /* append subtree to current tree */ |
1601b365 |
1086 | t2->left = LTTV_TREE_NODE; |
1087 | t2->l_child.t = subtree; |
1088 | subtree = NULL; |
1089 | t1->right = LTTV_TREE_NODE; |
1090 | t1->r_child.t = t2; |
bb87caa7 |
1091 | } else { /* append a simple expression */ |
9ab5ebd7 |
1092 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1093 | //a_simple_expression->value = g_string_free(a_field_component,FALSE); |
1601b365 |
1094 | a_field_component = g_string_new(""); |
1095 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
1096 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
1097 | a_simple_expression = lttv_simple_expression_new(); |
1601b365 |
1098 | t1->right = LTTV_TREE_NODE; |
1099 | t1->r_child.t = t2; |
1100 | } |
f4e9dd16 |
1101 | break; |
aa4600f3 |
1102 | |
a4c292d4 |
1103 | case '^': /* xor */ |
aa4600f3 |
1104 | |
e00d6a24 |
1105 | t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1106 | while(t1->right != LTTV_TREE_IDLE) { |
1107 | g_assert(t1->right == LTTV_TREE_NODE); |
1108 | t1 = t1->r_child.t; |
1109 | } |
1601b365 |
1110 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1111 | t2->node = LTTV_LOGICAL_XOR; |
bb87caa7 |
1112 | if(subtree != NULL) { /* append subtree to current tree */ |
1601b365 |
1113 | t2->left = LTTV_TREE_NODE; |
1114 | t2->l_child.t = subtree; |
1115 | subtree = NULL; |
1116 | t1->right = LTTV_TREE_NODE; |
1117 | t1->r_child.t = t2; |
bb87caa7 |
1118 | } else { /* append a simple expression */ |
9ab5ebd7 |
1119 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1120 | //a_simple_expression->value = g_string_free(a_field_component,FALSE); |
1601b365 |
1121 | a_field_component = g_string_new(""); |
1122 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
1123 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
1124 | a_simple_expression = lttv_simple_expression_new(); |
1601b365 |
1125 | t1->right = LTTV_TREE_NODE; |
1126 | t1->r_child.t = t2; |
1127 | } |
a4c292d4 |
1128 | break; |
aa4600f3 |
1129 | |
a4c292d4 |
1130 | case '!': /* not, or not equal (math op) */ |
aa4600f3 |
1131 | |
5f185a2b |
1132 | if(filter->expression[i+1] == '=') { /* != */ |
0cdc2470 |
1133 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1134 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
0cdc2470 |
1135 | a_field_component = g_string_new(""); |
56e29124 |
1136 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_NE); |
aa4600f3 |
1137 | i++; |
a4c292d4 |
1138 | } else { /* ! */ |
e00d6a24 |
1139 | t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1140 | while(t1->right != LTTV_TREE_IDLE) { |
1141 | g_assert(t1->right == LTTV_TREE_NODE); |
1142 | t1 = t1->r_child.t; |
1143 | } |
1601b365 |
1144 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1145 | t2->node = LTTV_LOGICAL_NOT; |
1601b365 |
1146 | t1->right = LTTV_TREE_NODE; |
1147 | t1->r_child.t = t2; |
a4c292d4 |
1148 | } |
1149 | break; |
aa4600f3 |
1150 | |
a4c292d4 |
1151 | case '(': /* start of parenthesis */ |
91ad3f0a |
1152 | case '[': |
1153 | case '{': |
aa4600f3 |
1154 | |
91ad3f0a |
1155 | p_nesting++; /* incrementing parenthesis nesting value */ |
1601b365 |
1156 | t1 = lttv_filter_tree_new(); |
1157 | g_ptr_array_add( tree_stack,(gpointer) t1 ); |
a4c292d4 |
1158 | break; |
aa4600f3 |
1159 | |
a4c292d4 |
1160 | case ')': /* end of parenthesis */ |
91ad3f0a |
1161 | case ']': |
1162 | case '}': |
aa4600f3 |
1163 | |
91ad3f0a |
1164 | p_nesting--; /* decrementing parenthesis nesting value */ |
18d1226f |
1165 | if(p_nesting<0 || tree_stack->len<2) { |
f4e9dd16 |
1166 | g_warning("Wrong filtering options, the string\n\"%s\"\n\ |
5f185a2b |
1167 | is not valid due to parenthesis incorrect use",filter->expression); |
1168 | return FALSE; |
f4e9dd16 |
1169 | } |
56e29124 |
1170 | |
1171 | /* there must at least be the root tree left in the array */ |
18d1226f |
1172 | g_assert(tree_stack->len>0); |
56e29124 |
1173 | |
bb87caa7 |
1174 | if(subtree != NULL) { /* append subtree to current tree */ |
18d1226f |
1175 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1176 | while(t1->right != LTTV_TREE_IDLE) { |
1177 | g_assert(t1->right == LTTV_TREE_NODE); |
1178 | t1 = t1->r_child.t; |
18d1226f |
1179 | } |
1180 | t1->right = LTTV_TREE_NODE; |
1181 | t1->r_child.t = subtree; |
1182 | subtree = g_ptr_array_index(tree_stack,tree_stack->len-1); |
1183 | g_ptr_array_remove_index(tree_stack,tree_stack->len-1); |
bb87caa7 |
1184 | } else { /* assign subtree as current tree */ |
9ab5ebd7 |
1185 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1186 | //a_simple_expression->value = g_string_free(a_field_component,FALSE); |
18d1226f |
1187 | a_field_component = g_string_new(""); |
1188 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1189 | g_print("here\n"); |
1190 | while(t1->right != LTTV_TREE_IDLE) { |
1191 | g_print("while right:%i %p->child:%p\n",t1->right,t1,t1->r_child.t); |
1192 | g_assert(t1->right == LTTV_TREE_NODE); |
1193 | g_assert(t1->r_child.t != NULL); |
1194 | t1 = t1->r_child.t; |
1195 | } |
1196 | g_print("here2\n"); |
18d1226f |
1197 | t1->right = LTTV_TREE_LEAF; |
0cdc2470 |
1198 | t1->r_child.leaf = a_simple_expression; |
389ba50e |
1199 | a_simple_expression = lttv_simple_expression_new(); |
9ab5ebd7 |
1200 | subtree = g_ptr_array_remove_index(tree_stack,tree_stack->len-1); |
18d1226f |
1201 | } |
a4c292d4 |
1202 | break; |
1203 | |
1204 | /* |
1205 | * mathematic operators |
1206 | */ |
1207 | case '<': /* lower, lower or equal */ |
aa4600f3 |
1208 | |
1209 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1210 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
aa4600f3 |
1211 | a_field_component = g_string_new(""); |
5f185a2b |
1212 | if(filter->expression[i+1] == '=') { /* <= */ |
a4c292d4 |
1213 | i++; |
56e29124 |
1214 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LE); |
1215 | } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LT); |
aa4600f3 |
1216 | break; |
1217 | |
1218 | case '>': /* higher, higher or equal */ |
1219 | |
1220 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1221 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
f4e9dd16 |
1222 | a_field_component = g_string_new(""); |
5f185a2b |
1223 | if(filter->expression[i+1] == '=') { /* >= */ |
a4c292d4 |
1224 | i++; |
56e29124 |
1225 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GE); |
1226 | } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GT); |
aa4600f3 |
1227 | break; |
1228 | |
a4c292d4 |
1229 | case '=': /* equal */ |
aa4600f3 |
1230 | |
f4e9dd16 |
1231 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1232 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
f4e9dd16 |
1233 | a_field_component = g_string_new(""); |
56e29124 |
1234 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_EQ); |
a4c292d4 |
1235 | break; |
aa4600f3 |
1236 | |
0769c82f |
1237 | /* |
1238 | * Field concatening caracter |
1239 | */ |
1240 | case '.': /* dot */ |
aa4600f3 |
1241 | |
bb87caa7 |
1242 | /* |
1243 | * divide field expression into elements |
1244 | * in a_field_path array. |
1245 | */ |
56e29124 |
1246 | /* FIXME: check for double values */ |
8ff6243c |
1247 | if(a_simple_expression->field == LTTV_FILTER_UNDEFINED) { |
bb87caa7 |
1248 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
1249 | a_field_component = g_string_new(""); |
8ff6243c |
1250 | } |
1251 | break; |
1252 | case ' ': |
1253 | case '\n': |
0769c82f |
1254 | break; |
a4c292d4 |
1255 | default: /* concatening current string */ |
73050a5f |
1256 | g_string_append_c(a_field_component,filter->expression[i]); |
a4c292d4 |
1257 | } |
1258 | } |
1601b365 |
1259 | |
1260 | g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree,tree,t1,t2); |
0cdc2470 |
1261 | g_print("stack size: %i\n",tree_stack->len); |
1262 | |
1263 | /* |
1264 | * Preliminary check to see |
1265 | * if tree was constructed correctly |
1266 | */ |
1267 | if( p_nesting>0 ) { |
1268 | g_warning("Wrong filtering options, the string\n\"%s\"\n\ |
5f185a2b |
1269 | is not valid due to parenthesis incorrect use",filter->expression); |
1270 | return FALSE; |
0cdc2470 |
1271 | } |
1272 | |
1273 | if(tree_stack->len != 1) /* only root tree should remain */ |
5f185a2b |
1274 | return FALSE; |
1601b365 |
1275 | |
410c83da |
1276 | /* processing last element of expression */ |
410c83da |
1277 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1278 | while(t1->right != LTTV_TREE_IDLE) { |
1279 | g_assert(t1->right == LTTV_TREE_NODE); |
1280 | t1 = t1->r_child.t; |
1281 | } |
410c83da |
1282 | if(subtree != NULL) { /* add the subtree */ |
1283 | t1->right = LTTV_TREE_NODE; |
0cdc2470 |
1284 | t1->r_child.t = subtree; |
410c83da |
1285 | subtree = NULL; |
1286 | } else { /* add a leaf */ |
9ab5ebd7 |
1287 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1288 | //a_simple_expression->value = g_string_free(a_field_component,FALSE); |
56e29124 |
1289 | a_field_component = NULL; |
410c83da |
1290 | t1->right = LTTV_TREE_LEAF; |
0cdc2470 |
1291 | t1->r_child.leaf = a_simple_expression; |
56e29124 |
1292 | a_simple_expression = NULL; |
410c83da |
1293 | } |
1294 | |
56e29124 |
1295 | |
73050a5f |
1296 | /* free the pointer array */ |
1297 | g_assert(a_field_path->len == 0); |
1298 | g_ptr_array_free(a_field_path,TRUE); |
56e29124 |
1299 | |
1300 | /* free the tree stack -- but keep the root tree */ |
f3020899 |
1301 | // g_ptr_array_free(tree_stack,FALSE); |
1302 | filter->head = g_ptr_array_remove_index(tree_stack,0); |
1303 | g_ptr_array_free(tree_stack,TRUE); |
1304 | |
56e29124 |
1305 | /* free the field buffer if allocated */ |
1306 | if(a_field_component != NULL) g_string_free(a_field_component,TRUE); |
1307 | |
1308 | /* free the simple expression buffer if allocated */ |
1309 | if(a_simple_expression != NULL) lttv_simple_expression_destroy(a_simple_expression); |
73050a5f |
1310 | |
f3020899 |
1311 | g_assert(filter->head != NULL); /* tree should exist */ |
56e29124 |
1312 | g_assert(subtree == NULL); /* remaining subtree should be included in main tree */ |
a4c292d4 |
1313 | |
56e29124 |
1314 | /* debug */ |
1315 | g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n"); |
1316 | lttv_print_tree(filter->head) ; |
1317 | g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n"); |
1318 | |
1319 | /* success */ |
5f185a2b |
1320 | return TRUE; |
80f9611a |
1321 | |
31452f49 |
1322 | } |
1323 | |
8c89f5a8 |
1324 | /** |
56e29124 |
1325 | * @fn void lttv_filter_destroy(LttvFilter*) |
1326 | * |
8c89f5a8 |
1327 | * Destroy the current LttvFilter |
1328 | * @param filter pointer to the current LttvFilter |
1329 | */ |
1da1525d |
1330 | void |
2ea36caf |
1331 | lttv_filter_destroy(LttvFilter* filter) { |
5f185a2b |
1332 | |
1333 | g_free(filter->expression); |
1334 | lttv_filter_tree_destroy(filter->head); |
1335 | g_free(filter); |
1336 | |
1da1525d |
1337 | } |
1338 | |
150f0d33 |
1339 | /** |
8ff6243c |
1340 | * @fn LttvFilterTree* lttv_filter_tree_new() |
56e29124 |
1341 | * |
150f0d33 |
1342 | * Assign a new tree for the current expression |
1343 | * or sub expression |
1344 | * @return pointer of LttvFilterTree |
1345 | */ |
5f185a2b |
1346 | LttvFilterTree* |
1347 | lttv_filter_tree_new() { |
150f0d33 |
1348 | LttvFilterTree* tree; |
1349 | |
e00d6a24 |
1350 | tree = g_new(LttvFilterTree,1); |
150f0d33 |
1351 | tree->node = 0; //g_new(lttv_expression,1); |
150f0d33 |
1352 | tree->left = LTTV_TREE_IDLE; |
1353 | tree->right = LTTV_TREE_IDLE; |
f3020899 |
1354 | tree->r_child.t = NULL; |
1355 | tree->l_child.t = NULL; |
1356 | |
150f0d33 |
1357 | return tree; |
1358 | } |
1359 | |
80f9611a |
1360 | /** |
56e29124 |
1361 | * @fn void lttv_filter_append_expression(LttvFilter*,char*) |
1362 | * |
80f9611a |
1363 | * Append a new expression to the expression |
1364 | * defined in the current filter |
1365 | * @param filter pointer to the current LttvFilter |
1366 | * @param expression string that must be appended |
56e29124 |
1367 | * @return Success/Failure of operation |
80f9611a |
1368 | */ |
56e29124 |
1369 | gboolean lttv_filter_append_expression(LttvFilter* filter, char *expression) { |
80f9611a |
1370 | |
56e29124 |
1371 | if(expression == NULL) return FALSE; |
80f9611a |
1372 | if(filter == NULL) { |
1373 | filter = lttv_filter_new(); |
1374 | filter->expression = expression; |
1375 | } else if(filter->expression == NULL) { |
1376 | filter->expression = expression; |
1377 | } else { |
1378 | filter->expression = g_strconcat(filter->expression,"&",expression); |
1379 | } |
1380 | |
56e29124 |
1381 | return lttv_filter_update(filter); |
80f9611a |
1382 | |
1383 | } |
1384 | |
1385 | /** |
56e29124 |
1386 | * @fn void lttv_filter_clear_expression(LttvFilter*) |
1387 | * |
80f9611a |
1388 | * Clear the filter expression from the |
1389 | * current filter and sets its pointer to NULL |
1390 | * @param filter pointer to the current LttvFilter |
1391 | */ |
1392 | void lttv_filter_clear_expression(LttvFilter* filter) { |
1393 | |
1394 | if(filter->expression != NULL) { |
1395 | g_free(filter->expression); |
1396 | filter->expression = NULL; |
1397 | } |
1398 | |
1399 | } |
1400 | |
150f0d33 |
1401 | /** |
56e29124 |
1402 | * @fn void lttv_filter_tree_destroy(LttvFilterTree*) |
1403 | * |
150f0d33 |
1404 | * Destroys the tree and his sub-trees |
1405 | * @param tree Tree which must be destroyed |
1406 | */ |
5f185a2b |
1407 | void |
1408 | lttv_filter_tree_destroy(LttvFilterTree* tree) { |
56e29124 |
1409 | |
150f0d33 |
1410 | if(tree == NULL) return; |
1411 | |
56e29124 |
1412 | if(tree->left == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->l_child.leaf); |
150f0d33 |
1413 | else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t); |
1414 | |
56e29124 |
1415 | if(tree->right == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->r_child.leaf); |
150f0d33 |
1416 | else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t); |
1417 | |
e00d6a24 |
1418 | // g_free(tree->node); |
150f0d33 |
1419 | g_free(tree); |
1420 | } |
1421 | |
84a333d6 |
1422 | /** |
8ff6243c |
1423 | * @fn gboolean lttv_filter_tree_parse(LttvFilterTree*,LttEvent,LttTracefile,LttTrace,LttvProcessState) |
56e29124 |
1424 | * |
80f9611a |
1425 | * Global parsing function for the current |
1426 | * LttvFilterTree |
1427 | * @param tree pointer to the current LttvFilterTree |
1428 | * @param event current LttEvent, NULL if not used |
1429 | * @param tracefile current LttTracefile, NULL if not used |
1430 | * @param trace current LttTrace, NULL if not used |
1431 | * @param state current LttvProcessState, NULL if not used |
84a333d6 |
1432 | */ |
31452f49 |
1433 | gboolean |
80f9611a |
1434 | lttv_filter_tree_parse( |
1435 | LttvFilterTree* t, |
1436 | LttEvent* event, |
1437 | LttTracefile* tracefile, |
1438 | LttTrace* trace, |
1439 | LttvProcessState* state |
1440 | /*,...*/) |
1441 | { |
0769c82f |
1442 | |
80f9611a |
1443 | /* |
1601b365 |
1444 | * Each tree is parsed in inorder. |
1445 | * This way, it's possible to apply the left filter of the |
1446 | * tree, then decide whether or not the right branch should |
1447 | * be parsed depending on the linking logical operator |
1448 | * |
80f9611a |
1449 | * Each node consists in a |
1450 | * 1. logical operator |
1451 | * 2. left child ( node or simple expression ) |
1452 | * 3. right child ( node or simple expression ) |
1453 | * |
1454 | * When the child is a simple expression, we must |
1455 | * before all determine if the expression refers to |
1456 | * a structure which is whithin observation ( not NULL ). |
1457 | * -If so, the expression is evaluated. |
1458 | * -If not, the result is set to TRUE since this particular |
1459 | * operation does not interfere with the lttv structure |
1460 | * |
1461 | * The result of each simple expression will directly |
1462 | * affect the next branch. This way, depending on |
1463 | * the linking logical operator, the parser will decide |
1464 | * to explore or not the next branch. |
1465 | * 1. AND OPERATOR |
1466 | * -If result of left branch is 0 / FALSE |
1467 | * then don't explore right branch and return 0; |
1468 | * -If result of left branch is 1 / TRUE then explore |
1469 | * 2. OR OPERATOR |
1470 | * -If result of left branch is 1 / TRUE |
1471 | * then don't explore right branch and return 1; |
1472 | * -If result of left branch is 0 / FALSE then explore |
1473 | * 3. XOR OPERATOR |
56e29124 |
1474 | * -Result of left branch will not affect exploration of |
80f9611a |
1475 | * right branch |
1601b365 |
1476 | */ |
73050a5f |
1477 | g_print("filter::lttv_parse_tree(...)\n"); |
1478 | |
80f9611a |
1479 | gboolean lresult = FALSE, rresult = FALSE; |
0769c82f |
1480 | |
80f9611a |
1481 | /* |
1482 | * Parse left branch |
1483 | */ |
1484 | if(t->left == LTTV_TREE_NODE) lresult = lttv_filter_tree_parse(t->l_child.t,event,tracefile,trace,state); |
5b729fcf |
1485 | else if(t->left == LTTV_TREE_LEAF) { |
80f9611a |
1486 | //g_print("%p: left is %i %p %s\n",t,t->l_child.leaf->field,t->l_child.leaf->op,t->l_child.leaf->value); |
9ab5ebd7 |
1487 | LttvFieldValue v; |
1488 | v = t->l_child.leaf->value; |
80f9611a |
1489 | switch(t->l_child.leaf->field) { |
1490 | |
1491 | case LTTV_FILTER_TRACE_NAME: |
1492 | if(trace == NULL) lresult = TRUE; |
1493 | else lresult = t->l_child.leaf->op((gpointer)ltt_trace_name(trace),v); |
1494 | break; |
1495 | case LTTV_FILTER_TRACEFILE_NAME: |
1496 | if(tracefile == NULL) lresult = TRUE; |
1497 | else lresult = t->l_child.leaf->op((gpointer)ltt_tracefile_name(tracefile),v); |
1498 | break; |
1499 | case LTTV_FILTER_STATE_PID: |
1500 | if(state == NULL) lresult = TRUE; |
1501 | else lresult = t->l_child.leaf->op((gpointer)&state->pid,v); |
1502 | break; |
1503 | case LTTV_FILTER_STATE_PPID: |
1504 | if(state == NULL) lresult = TRUE; |
1505 | else lresult = t->l_child.leaf->op((gpointer)&state->ppid,v); |
1506 | break; |
1507 | case LTTV_FILTER_STATE_CT: |
1508 | if(state == NULL) lresult = TRUE; |
1509 | else { |
1510 | double val = ltt_time_to_double(state->creation_time); |
1511 | lresult = t->l_child.leaf->op((gpointer)&val,v); |
1512 | } |
1513 | break; |
1514 | case LTTV_FILTER_STATE_IT: |
1515 | if(state == NULL) lresult = TRUE; |
1516 | else { |
1517 | double val = ltt_time_to_double(state->insertion_time); |
1518 | lresult = t->l_child.leaf->op((gpointer)&val,v); |
1519 | } |
1520 | break; |
1521 | case LTTV_FILTER_STATE_P_NAME: |
1522 | /* |
1523 | * FIXME: Yet to be done ( I think ? ) |
1524 | */ |
1525 | lresult = TRUE; |
1526 | break; |
1527 | case LTTV_FILTER_STATE_EX_MODE: |
1528 | if(state == NULL) lresult = TRUE; |
1529 | else lresult = t->l_child.leaf->op((gpointer)&state->state->t,v); |
1530 | break; |
1531 | case LTTV_FILTER_STATE_EX_SUBMODE: |
1532 | if(state == NULL) lresult = TRUE; |
1533 | else lresult = t->l_child.leaf->op((gpointer)&state->state->n,v); |
1534 | break; |
1535 | case LTTV_FILTER_STATE_P_STATUS: |
1536 | if(state == NULL) lresult = TRUE; |
1537 | else lresult = t->l_child.leaf->op((gpointer)&state->state->s,v); |
1538 | break; |
1539 | case LTTV_FILTER_STATE_CPU: |
1540 | /* |
1541 | * FIXME: What is the comparison value ? |
1542 | */ |
1543 | lresult = TRUE; |
1544 | break; |
1545 | case LTTV_FILTER_EVENT_NAME: |
1546 | if(event == NULL) lresult = TRUE; |
1547 | else lresult = t->l_child.leaf->op((gpointer)ltt_event_eventtype(event),v); |
1548 | break; |
1549 | |
1550 | case LTTV_FILTER_EVENT_CATEGORY: |
1551 | /* |
1552 | * FIXME: Not yet implemented |
1553 | */ |
1554 | lresult = TRUE; |
1555 | break; |
1556 | case LTTV_FILTER_EVENT_TIME: |
1557 | // if(event == NULL) lresult = TRUE; |
1558 | // else { |
1559 | // double val = ltt_time_to_double(event->event_time); |
1560 | // lresult = t->l_child.leaf->op((gpointer)&val,v); |
1561 | // } |
1562 | lresult = TRUE; |
1563 | break; |
1564 | case LTTV_FILTER_EVENT_TSC: |
1565 | // if(event == NULL) lresult = TRUE; |
1566 | // else { |
1567 | // double val = ltt_time_to_double(event->event_time); |
1568 | // lresult = t->l_child.leaf->op((gpointer)&val,v); |
1569 | // } |
1570 | /* |
1571 | * FIXME: Where is event.tsc |
1572 | */ |
1573 | lresult = TRUE; |
1574 | break; |
1575 | case LTTV_FILTER_EVENT_FIELD: |
1576 | /* |
1577 | * TODO: Use the offset to |
1578 | * find the dynamic field |
1579 | * in the event struct |
1580 | */ |
1581 | lresult = TRUE; |
1582 | default: |
1583 | /* |
1584 | * This case should never be |
1585 | * parsed, if so, the whole |
1586 | * filtering is cancelled |
1587 | */ |
1588 | g_warning("Error while parsing the filter tree"); |
1589 | return TRUE; |
1590 | } |
0cdc2470 |
1591 | } |
80f9611a |
1592 | |
1593 | /* |
1594 | * Parse linking operator |
1595 | * make a cutoff if possible |
1596 | */ |
1597 | if((t->node & LTTV_LOGICAL_OR) && lresult == TRUE) return TRUE; |
1598 | if((t->node & LTTV_LOGICAL_AND) && lresult == FALSE) return FALSE; |
1599 | |
1600 | /* |
1601 | * Parse right branch |
1602 | */ |
1603 | if(t->right == LTTV_TREE_NODE) rresult = lttv_filter_tree_parse(t->r_child.t,event,tracefile,trace,state); |
5b729fcf |
1604 | else if(t->right == LTTV_TREE_LEAF) { |
80f9611a |
1605 | //g_print("%p: right is %i %p %s\n",t,t->r_child.leaf->field,t->r_child.leaf->op,t->r_child.leaf->value); |
9ab5ebd7 |
1606 | LttvFieldValue v; |
1607 | v = t->r_child.leaf->value; |
80f9611a |
1608 | switch(t->r_child.leaf->field) { |
1609 | |
1610 | case LTTV_FILTER_TRACE_NAME: |
1611 | if(trace == NULL) rresult = TRUE; |
1612 | else rresult = t->r_child.leaf->op((gpointer)ltt_trace_name(trace),v); |
1613 | break; |
1614 | case LTTV_FILTER_TRACEFILE_NAME: |
1615 | if(tracefile == NULL) rresult = TRUE; |
1616 | else rresult = t->r_child.leaf->op((gpointer)ltt_tracefile_name(tracefile),v); |
1617 | break; |
1618 | case LTTV_FILTER_STATE_PID: |
1619 | if(state == NULL) rresult = TRUE; |
1620 | else rresult = t->r_child.leaf->op((gpointer)&state->pid,v); |
1621 | break; |
1622 | case LTTV_FILTER_STATE_PPID: |
1623 | if(state == NULL) rresult = TRUE; |
1624 | else rresult = t->r_child.leaf->op((gpointer)&state->ppid,v); |
1625 | break; |
1626 | case LTTV_FILTER_STATE_CT: |
1627 | if(state == NULL) rresult = TRUE; |
1628 | else { |
1629 | double val = ltt_time_to_double(state->creation_time); |
1630 | rresult = t->r_child.leaf->op((gpointer)&val,v); |
1631 | } |
1632 | break; |
1633 | case LTTV_FILTER_STATE_IT: |
1634 | if(state == NULL) rresult = TRUE; |
1635 | else { |
1636 | double val = ltt_time_to_double(state->insertion_time); |
1637 | rresult = t->r_child.leaf->op((gpointer)&val,v); |
1638 | } |
1639 | break; |
1640 | case LTTV_FILTER_STATE_P_NAME: |
1641 | /* |
1642 | * FIXME: Yet to be done ( I think ? ) |
1643 | */ |
1644 | rresult = TRUE; |
1645 | break; |
1646 | case LTTV_FILTER_STATE_EX_MODE: |
1647 | if(state == NULL) rresult = TRUE; |
1648 | else rresult = t->r_child.leaf->op((gpointer)&state->state->t,v); |
1649 | break; |
1650 | case LTTV_FILTER_STATE_EX_SUBMODE: |
1651 | if(state == NULL) rresult = TRUE; |
1652 | else rresult = t->r_child.leaf->op((gpointer)&state->state->n,v); |
1653 | break; |
1654 | case LTTV_FILTER_STATE_P_STATUS: |
1655 | if(state == NULL) rresult = TRUE; |
1656 | else rresult = t->r_child.leaf->op((gpointer)&state->state->s,v); |
1657 | break; |
1658 | case LTTV_FILTER_STATE_CPU: |
1659 | /* |
1660 | * FIXME: What is the comparison value ? |
1661 | */ |
1662 | rresult = TRUE; |
1663 | break; |
1664 | case LTTV_FILTER_EVENT_NAME: |
1665 | if(event == NULL) rresult = TRUE; |
1666 | else rresult = t->r_child.leaf->op((gpointer)ltt_event_eventtype(event),v); |
1667 | break; |
1668 | |
1669 | case LTTV_FILTER_EVENT_CATEGORY: |
1670 | /* |
1671 | * FIXME: Not yet implemented |
1672 | */ |
1673 | rresult = TRUE; |
1674 | break; |
1675 | case LTTV_FILTER_EVENT_TIME: |
1676 | // if(event == NULL) rresult = TRUE; |
1677 | // else { |
1678 | // double val = ltt_time_to_double(event->event_time); |
1679 | // rresult = t->r_child.leaf->op((gpointer)&val,v); |
1680 | // } |
1681 | rresult = TRUE; |
1682 | break; |
1683 | case LTTV_FILTER_EVENT_TSC: |
1684 | // if(event == NULL) rresult = TRUE; |
1685 | // else { |
1686 | // double val = ltt_time_to_double(event->event_time); |
1687 | // rresult = t->r_child.leaf->op((gpointer)&val,v); |
1688 | // } |
1689 | /* |
1690 | * FIXME: Where is event.tsc |
1691 | */ |
1692 | rresult = TRUE; |
1693 | break; |
1694 | case LTTV_FILTER_EVENT_FIELD: |
1695 | /* |
1696 | * TODO: Use the offset to |
1697 | * find the dynamic field |
1698 | * in the event struct |
1699 | */ |
1700 | rresult = TRUE; |
1701 | default: |
1702 | /* |
1703 | * This case should never be |
1704 | * parsed, if so, this subtree |
1705 | * is cancelled ! |
1706 | */ |
1707 | g_warning("Error while parsing the filter tree"); |
1708 | return TRUE; |
1709 | } |
0cdc2470 |
1710 | } |
5f185a2b |
1711 | |
80f9611a |
1712 | /* |
1713 | * Apply and return the |
1714 | * logical link between the |
1715 | * two operation |
1716 | */ |
1717 | switch(t->node) { |
1718 | case LTTV_LOGICAL_OR: return (lresult | rresult); |
1719 | case LTTV_LOGICAL_AND: return (lresult & rresult); |
1720 | case LTTV_LOGICAL_NOT: return (!rresult); |
1721 | case LTTV_LOGICAL_XOR: return (lresult ^ rresult); |
8ff6243c |
1722 | case 0: return (rresult); |
80f9611a |
1723 | default: |
1724 | /* |
1725 | * This case should never be |
1726 | * parsed, if so, this subtree |
1727 | * is cancelled ! |
1728 | */ |
1729 | return TRUE; |
1730 | } |
0769c82f |
1731 | |
80f9611a |
1732 | } |
0769c82f |
1733 | |
80f9611a |
1734 | /** |
56e29124 |
1735 | * @fn void lttv_print_tree(LttvFilterTree*) |
1736 | * |
1737 | * Debug |
1738 | * @param t the pointer to the current LttvFilterTree |
80f9611a |
1739 | */ |
1740 | void |
1741 | lttv_print_tree(LttvFilterTree* t) { |
0769c82f |
1742 | |
73050a5f |
1743 | g_print("node:%p lchild:%p rchild:%p\n",t, //t->l_child.t,t->r_child.t); |
80f9611a |
1744 | (t->left==LTTV_TREE_NODE)?t->l_child.t:NULL, |
1745 | (t->right==LTTV_TREE_NODE)?t->r_child.t:NULL); |
1746 | g_print("node type: %i / [left] %i / [right] %i\n",t->node,t->left,t->right); |
1747 | if(t->left == LTTV_TREE_NODE) lttv_print_tree(t->l_child.t); |
1748 | else if(t->left == LTTV_TREE_LEAF) { |
73050a5f |
1749 | // g_assert(t->l_child.leaf->value != NULL); |
9ab5ebd7 |
1750 | g_print("%p: left is %i %p value\n",t,t->l_child.leaf->field,t->l_child.leaf->op); |
0769c82f |
1751 | } |
80f9611a |
1752 | if(t->right == LTTV_TREE_NODE) lttv_print_tree(t->r_child.t); |
1753 | else if(t->right == LTTV_TREE_LEAF) { |
73050a5f |
1754 | // g_assert(t->r_child.leaf->value != NULL); |
9ab5ebd7 |
1755 | g_print("%p: right is %i %p value\n",t,t->r_child.leaf->field,t->r_child.leaf->op); |
80f9611a |
1756 | } |
80f9611a |
1757 | |
1758 | } |
1759 | |
1760 | /** |
8ff6243c |
1761 | * @fn gboolean lttv_filter_tracefile(LttvFilter*, LttTracefile*) |
56e29124 |
1762 | * |
80f9611a |
1763 | * Apply the filter to a specific trace |
1764 | * @param filter the current filter applied |
1765 | * @param tracefile the trace to apply the filter to |
1766 | * @return success/failure of operation |
0769c82f |
1767 | */ |
80f9611a |
1768 | gboolean |
1769 | lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile) { |
1770 | |
1771 | return lttv_filter_tree_parse(filter->head,NULL,tracefile,NULL,NULL); |
1772 | |
31452f49 |
1773 | } |
1774 | |
56e29124 |
1775 | /** |
1776 | * @fn gboolean lttv_filter_tracestate(LttvFilter*,LttvTraceState*) |
1777 | * |
1778 | * Parse the current tracestate |
1779 | * @param filter pointer to the current LttvFilter |
1780 | * @param tracestate pointer to the current tracestate |
1781 | */ |
1a7fa682 |
1782 | gboolean |
2ea36caf |
1783 | lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate) { |
341aa948 |
1784 | |
1785 | } |
1a7fa682 |
1786 | |
84a333d6 |
1787 | /** |
56e29124 |
1788 | * @fn gboolean lttv_filter_event(LttvFilter*,LttEvent*) |
1789 | * |
84a333d6 |
1790 | * Apply the filter to a specific event |
1791 | * @param filter the current filter applied |
1792 | * @param event the event to apply the filter to |
1793 | * @return success/failure of operation |
1794 | */ |
31452f49 |
1795 | gboolean |
2ea36caf |
1796 | lttv_filter_event(LttvFilter *filter, LttEvent *event) { |
31452f49 |
1797 | |
1798 | } |
1a7fa682 |
1799 | |
91ad3f0a |
1800 | /** |
56e29124 |
1801 | * @fn static void module_init() |
1802 | * |
91ad3f0a |
1803 | * Initializes the filter module and specific values |
1804 | */ |
1a7fa682 |
1805 | static void module_init() |
1806 | { |
91ad3f0a |
1807 | |
1a7fa682 |
1808 | } |
1809 | |
91ad3f0a |
1810 | /** |
8ff6243c |
1811 | * @fn Destroys the filter module and specific values |
91ad3f0a |
1812 | */ |
1a7fa682 |
1813 | static void module_destroy() |
1814 | { |
56e29124 |
1815 | |
1a7fa682 |
1816 | } |
1817 | |
1818 | |
91ad3f0a |
1819 | LTTV_MODULE("filter", "Filters traceset and events", \ |
1820 | "Filters traceset and events specifically to user input", \ |
1a7fa682 |
1821 | module_init, module_destroy) |
1822 | |
1823 | |
1824 | |