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; |
56e29124 |
105 | t2->l_child.t = (LttvFilterTree*)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; |
9ab5ebd7 |
136 | // se->value = NULL; |
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); |
56e29124 |
453 | g_free(se); |
454 | |
455 | } |
456 | |
457 | /** |
458 | * @fn gint lttv_struct_type(gint) |
459 | * |
80f9611a |
460 | * Finds the structure type depending |
461 | * on the fields in parameters |
462 | * @params ft Field of the current structure |
463 | * @return LttvStructType enum or -1 for error |
84a333d6 |
464 | */ |
80f9611a |
465 | gint |
466 | lttv_struct_type(gint ft) { |
5f185a2b |
467 | |
80f9611a |
468 | switch(ft) { |
469 | case LTTV_FILTER_TRACE_NAME: |
470 | return LTTV_FILTER_TRACE; |
471 | break; |
472 | case LTTV_FILTER_TRACEFILE_NAME: |
473 | return LTTV_FILTER_TRACEFILE; |
474 | break; |
475 | case LTTV_FILTER_STATE_PID: |
476 | case LTTV_FILTER_STATE_PPID: |
477 | case LTTV_FILTER_STATE_CT: |
478 | case LTTV_FILTER_STATE_IT: |
479 | case LTTV_FILTER_STATE_P_NAME: |
480 | case LTTV_FILTER_STATE_EX_MODE: |
481 | case LTTV_FILTER_STATE_EX_SUBMODE: |
482 | case LTTV_FILTER_STATE_P_STATUS: |
483 | case LTTV_FILTER_STATE_CPU: |
484 | return LTTV_FILTER_STATE; |
485 | break; |
486 | case LTTV_FILTER_EVENT_NAME: |
487 | case LTTV_FILTER_EVENT_CATEGORY: |
488 | case LTTV_FILTER_EVENT_TIME: |
489 | case LTTV_FILTER_EVENT_TSC: |
490 | case LTTV_FILTER_EVENT_FIELD: |
491 | return LTTV_FILTER_EVENT; |
492 | break; |
493 | default: |
494 | return -1; |
495 | } |
84a333d6 |
496 | } |
497 | |
150f0d33 |
498 | /** |
56e29124 |
499 | * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue) |
500 | * |
150f0d33 |
501 | * Applies the 'equal' operator to the |
47aa6e58 |
502 | * specified structure and value |
503 | * @param v1 left member of comparison |
504 | * @param v2 right member of comparison |
150f0d33 |
505 | * @return success/failure of operation |
506 | */ |
9ab5ebd7 |
507 | gboolean lttv_apply_op_eq_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
508 | |
509 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
510 | return (*r == v2.v_uint64); |
83aa92fc |
511 | |
512 | } |
150f0d33 |
513 | |
5b729fcf |
514 | /** |
56e29124 |
515 | * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue) |
516 | * |
5b729fcf |
517 | * Applies the 'equal' operator to the |
47aa6e58 |
518 | * specified structure and value |
519 | * @param v1 left member of comparison |
520 | * @param v2 right member of comparison |
5b729fcf |
521 | * @return success/failure of operation |
522 | */ |
9ab5ebd7 |
523 | gboolean lttv_apply_op_eq_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
524 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
525 | return (*r == v2.v_uint32); |
83aa92fc |
526 | } |
5b729fcf |
527 | |
528 | /** |
56e29124 |
529 | * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue) |
530 | * |
5b729fcf |
531 | * Applies the 'equal' operator to the |
47aa6e58 |
532 | * specified structure and value |
533 | * @param v1 left member of comparison |
534 | * @param v2 right member of comparison |
5b729fcf |
535 | * @return success/failure of operation |
536 | */ |
9ab5ebd7 |
537 | gboolean lttv_apply_op_eq_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
538 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
539 | return (*r == v2.v_uint16); |
83aa92fc |
540 | } |
5b729fcf |
541 | |
542 | /** |
56e29124 |
543 | * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue) |
544 | * |
5b729fcf |
545 | * Applies the 'equal' operator to the |
47aa6e58 |
546 | * specified structure and value |
547 | * @param v1 left member of comparison |
548 | * @param v2 right member of comparison |
5b729fcf |
549 | * @return success/failure of operation |
550 | */ |
9ab5ebd7 |
551 | gboolean lttv_apply_op_eq_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
552 | double* r = (double*) v1; |
9ab5ebd7 |
553 | return (*r == v2.v_double); |
83aa92fc |
554 | } |
5b729fcf |
555 | |
556 | /** |
56e29124 |
557 | * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue) |
558 | * |
5b729fcf |
559 | * Applies the 'equal' operator to the |
47aa6e58 |
560 | * specified structure and value |
561 | * @param v1 left member of comparison |
562 | * @param v2 right member of comparison |
5b729fcf |
563 | * @return success/failure of operation |
564 | */ |
9ab5ebd7 |
565 | gboolean lttv_apply_op_eq_string(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
566 | char* r = (char*) v1; |
9ab5ebd7 |
567 | return (!g_strcasecmp(r,v2.v_string)); |
83aa92fc |
568 | } |
150f0d33 |
569 | |
570 | /** |
56e29124 |
571 | * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue) |
572 | * |
150f0d33 |
573 | * Applies the 'not equal' operator to the |
47aa6e58 |
574 | * specified structure and value |
575 | * @param v1 left member of comparison |
576 | * @param v2 right member of comparison |
150f0d33 |
577 | * @return success/failure of operation |
578 | */ |
9ab5ebd7 |
579 | gboolean lttv_apply_op_ne_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
580 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
581 | return (*r != v2.v_uint64); |
83aa92fc |
582 | } |
150f0d33 |
583 | |
5b729fcf |
584 | /** |
56e29124 |
585 | * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue) |
586 | * |
5b729fcf |
587 | * Applies the 'not equal' operator to the |
47aa6e58 |
588 | * specified structure and value |
589 | * @param v1 left member of comparison |
590 | * @param v2 right member of comparison |
5b729fcf |
591 | * @return success/failure of operation |
592 | */ |
9ab5ebd7 |
593 | gboolean lttv_apply_op_ne_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
594 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
595 | return (*r != v2.v_uint32); |
83aa92fc |
596 | } |
5b729fcf |
597 | |
598 | /** |
56e29124 |
599 | * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue) |
600 | * |
5b729fcf |
601 | * Applies the 'not equal' operator to the |
47aa6e58 |
602 | * specified structure and value |
603 | * @param v1 left member of comparison |
604 | * @param v2 right member of comparison |
5b729fcf |
605 | * @return success/failure of operation |
606 | */ |
9ab5ebd7 |
607 | gboolean lttv_apply_op_ne_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
608 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
609 | return (*r != v2.v_uint16); |
83aa92fc |
610 | } |
5b729fcf |
611 | |
612 | /** |
56e29124 |
613 | * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue) |
614 | * |
5b729fcf |
615 | * Applies the 'not equal' operator to the |
47aa6e58 |
616 | * specified structure and value |
617 | * @param v1 left member of comparison |
618 | * @param v2 right member of comparison |
5b729fcf |
619 | * @return success/failure of operation |
620 | */ |
9ab5ebd7 |
621 | gboolean lttv_apply_op_ne_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
622 | double* r = (double*) v1; |
9ab5ebd7 |
623 | return (*r != v2.v_double); |
83aa92fc |
624 | } |
5b729fcf |
625 | |
626 | /** |
56e29124 |
627 | * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue) |
628 | * |
5b729fcf |
629 | * Applies the 'not equal' operator to the |
47aa6e58 |
630 | * specified structure and value |
631 | * @param v1 left member of comparison |
632 | * @param v2 right member of comparison |
5b729fcf |
633 | * @return success/failure of operation |
634 | */ |
9ab5ebd7 |
635 | gboolean lttv_apply_op_ne_string(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
636 | char* r = (char*) v1; |
9ab5ebd7 |
637 | return (g_strcasecmp(r,v2.v_string)); |
83aa92fc |
638 | } |
150f0d33 |
639 | |
640 | /** |
56e29124 |
641 | * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue) |
642 | * |
150f0d33 |
643 | * Applies the 'lower than' operator to the |
47aa6e58 |
644 | * specified structure and value |
645 | * @param v1 left member of comparison |
646 | * @param v2 right member of comparison |
150f0d33 |
647 | * @return success/failure of operation |
648 | */ |
9ab5ebd7 |
649 | gboolean lttv_apply_op_lt_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
650 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
651 | return (*r < v2.v_uint64); |
83aa92fc |
652 | } |
150f0d33 |
653 | |
5b729fcf |
654 | /** |
56e29124 |
655 | * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue) |
656 | * |
5b729fcf |
657 | * Applies the 'lower than' operator to the |
47aa6e58 |
658 | * specified structure and value |
659 | * @param v1 left member of comparison |
660 | * @param v2 right member of comparison |
5b729fcf |
661 | * @return success/failure of operation |
662 | */ |
9ab5ebd7 |
663 | gboolean lttv_apply_op_lt_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
664 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
665 | return (*r < v2.v_uint32); |
83aa92fc |
666 | } |
5b729fcf |
667 | |
668 | /** |
56e29124 |
669 | * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue) |
670 | * |
5b729fcf |
671 | * Applies the 'lower than' operator to the |
47aa6e58 |
672 | * specified structure and value |
673 | * @param v1 left member of comparison |
674 | * @param v2 right member of comparison |
5b729fcf |
675 | * @return success/failure of operation |
676 | */ |
9ab5ebd7 |
677 | gboolean lttv_apply_op_lt_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
678 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
679 | return (*r < v2.v_uint16); |
83aa92fc |
680 | } |
5b729fcf |
681 | |
682 | /** |
56e29124 |
683 | * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue) |
684 | * |
5b729fcf |
685 | * Applies the 'lower than' operator to the |
47aa6e58 |
686 | * specified structure and value |
687 | * @param v1 left member of comparison |
688 | * @param v2 right member of comparison |
5b729fcf |
689 | * @return success/failure of operation |
690 | */ |
9ab5ebd7 |
691 | gboolean lttv_apply_op_lt_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
692 | double* r = (double*) v1; |
9ab5ebd7 |
693 | return (*r < v2.v_double); |
83aa92fc |
694 | } |
5b729fcf |
695 | |
696 | /** |
56e29124 |
697 | * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue) |
698 | * |
699 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
700 | * specified structure and value |
701 | * @param v1 left member of comparison |
702 | * @param v2 right member of comparison |
5b729fcf |
703 | * @return success/failure of operation |
704 | */ |
9ab5ebd7 |
705 | gboolean lttv_apply_op_le_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
706 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
707 | return (*r <= v2.v_uint64); |
83aa92fc |
708 | } |
150f0d33 |
709 | |
710 | /** |
56e29124 |
711 | * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue) |
712 | * |
150f0d33 |
713 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
714 | * specified structure and value |
715 | * @param v1 left member of comparison |
716 | * @param v2 right member of comparison |
150f0d33 |
717 | * @return success/failure of operation |
718 | */ |
9ab5ebd7 |
719 | gboolean lttv_apply_op_le_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
720 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
721 | return (*r <= v2.v_uint32); |
83aa92fc |
722 | } |
150f0d33 |
723 | |
5b729fcf |
724 | /** |
56e29124 |
725 | * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue) |
726 | * |
5b729fcf |
727 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
728 | * specified structure and value |
729 | * @param v1 left member of comparison |
730 | * @param v2 right member of comparison |
5b729fcf |
731 | * @return success/failure of operation |
732 | */ |
9ab5ebd7 |
733 | gboolean lttv_apply_op_le_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
734 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
735 | return (*r <= v2.v_uint16); |
83aa92fc |
736 | } |
5b729fcf |
737 | |
738 | /** |
56e29124 |
739 | * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue) |
740 | * |
5b729fcf |
741 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
742 | * specified structure and value |
743 | * @param v1 left member of comparison |
744 | * @param v2 right member of comparison |
5b729fcf |
745 | * @return success/failure of operation |
746 | */ |
9ab5ebd7 |
747 | gboolean lttv_apply_op_le_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
748 | double* r = (double*) v1; |
9ab5ebd7 |
749 | return (*r <= v2.v_double); |
83aa92fc |
750 | } |
5b729fcf |
751 | |
752 | /** |
56e29124 |
753 | * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue) |
754 | * |
83aa92fc |
755 | * Applies the 'greater than' operator to the |
47aa6e58 |
756 | * specified structure and value |
757 | * @param v1 left member of comparison |
758 | * @param v2 right member of comparison |
5b729fcf |
759 | * @return success/failure of operation |
760 | */ |
9ab5ebd7 |
761 | gboolean lttv_apply_op_gt_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
762 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
763 | return (*r > v2.v_uint64); |
83aa92fc |
764 | } |
150f0d33 |
765 | |
766 | /** |
56e29124 |
767 | * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue) |
768 | * |
150f0d33 |
769 | * Applies the 'greater than' operator to the |
47aa6e58 |
770 | * specified structure and value |
771 | * @param v1 left member of comparison |
772 | * @param v2 right member of comparison |
150f0d33 |
773 | * @return success/failure of operation |
774 | */ |
9ab5ebd7 |
775 | gboolean lttv_apply_op_gt_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
776 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
777 | return (*r > v2.v_uint32); |
83aa92fc |
778 | } |
150f0d33 |
779 | |
5b729fcf |
780 | /** |
56e29124 |
781 | * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue) |
782 | * |
5b729fcf |
783 | * Applies the 'greater than' operator to the |
47aa6e58 |
784 | * specified structure and value |
785 | * @param v1 left member of comparison |
786 | * @param v2 right member of comparison |
5b729fcf |
787 | * @return success/failure of operation |
788 | */ |
9ab5ebd7 |
789 | gboolean lttv_apply_op_gt_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
790 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
791 | return (*r > v2.v_uint16); |
83aa92fc |
792 | } |
5b729fcf |
793 | |
794 | /** |
56e29124 |
795 | * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue) |
796 | * |
5b729fcf |
797 | * Applies the 'greater than' operator to the |
47aa6e58 |
798 | * specified structure and value |
799 | * @param v1 left member of comparison |
800 | * @param v2 right member of comparison |
5b729fcf |
801 | * @return success/failure of operation |
802 | */ |
9ab5ebd7 |
803 | gboolean lttv_apply_op_gt_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
804 | double* r = (double*) v1; |
9ab5ebd7 |
805 | return (*r > v2.v_double); |
83aa92fc |
806 | } |
5b729fcf |
807 | |
808 | /** |
56e29124 |
809 | * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue) |
810 | * |
83aa92fc |
811 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
812 | * specified structure and value |
813 | * @param v1 left member of comparison |
814 | * @param v2 right member of comparison |
5b729fcf |
815 | * @return success/failure of operation |
816 | */ |
9ab5ebd7 |
817 | gboolean lttv_apply_op_ge_uint64(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
818 | guint64* r = (guint64*) v1; |
9ab5ebd7 |
819 | return (*r >= v2.v_uint64); |
83aa92fc |
820 | } |
150f0d33 |
821 | |
822 | /** |
56e29124 |
823 | * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue) |
824 | * |
150f0d33 |
825 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
826 | * specified structure and value |
827 | * @param v1 left member of comparison |
828 | * @param v2 right member of comparison |
150f0d33 |
829 | * @return success/failure of operation |
830 | */ |
9ab5ebd7 |
831 | gboolean lttv_apply_op_ge_uint32(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
832 | guint32* r = (guint32*) v1; |
9ab5ebd7 |
833 | return (*r >= v2.v_uint32); |
83aa92fc |
834 | } |
150f0d33 |
835 | |
5b729fcf |
836 | /** |
56e29124 |
837 | * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue) |
838 | * |
5b729fcf |
839 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
840 | * specified structure and value |
841 | * @param v1 left member of comparison |
842 | * @param v2 right member of comparison |
5b729fcf |
843 | * @return success/failure of operation |
844 | */ |
9ab5ebd7 |
845 | gboolean lttv_apply_op_ge_uint16(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
846 | guint16* r = (guint16*) v1; |
9ab5ebd7 |
847 | return (*r >= v2.v_uint16); |
83aa92fc |
848 | } |
150f0d33 |
849 | |
5b729fcf |
850 | /** |
56e29124 |
851 | * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue) |
852 | * |
5b729fcf |
853 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
854 | * specified structure and value |
855 | * @param v1 left member of comparison |
856 | * @param v2 right member of comparison |
5b729fcf |
857 | * @return success/failure of operation |
858 | */ |
9ab5ebd7 |
859 | gboolean lttv_apply_op_ge_double(gpointer v1, LttvFieldValue v2) { |
83aa92fc |
860 | double* r = (double*) v1; |
9ab5ebd7 |
861 | return (*r >= v2.v_double); |
83aa92fc |
862 | } |
150f0d33 |
863 | |
864 | |
865 | /** |
56e29124 |
866 | * @fn LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree*) |
867 | * |
868 | * Makes a copy of the current filter tree |
869 | * @param tree pointer to the current tree |
870 | * @return new copy of the filter tree |
150f0d33 |
871 | */ |
872 | LttvFilterTree* |
873 | lttv_filter_tree_clone(LttvFilterTree* tree) { |
874 | |
8c89f5a8 |
875 | LttvFilterTree* newtree = lttv_filter_tree_new(); |
150f0d33 |
876 | |
8c89f5a8 |
877 | newtree->node = tree->node; |
878 | |
879 | newtree->left = tree->left; |
880 | if(newtree->left == LTTV_TREE_NODE) { |
881 | newtree->l_child.t = lttv_filter_tree_clone(tree->l_child.t); |
882 | } else if(newtree->left == LTTV_TREE_LEAF) { |
883 | newtree->l_child.leaf = lttv_simple_expression_new(); |
884 | newtree->l_child.leaf->field = tree->l_child.leaf->field; |
885 | newtree->l_child.leaf->offset = tree->l_child.leaf->offset; |
886 | newtree->l_child.leaf->op = tree->l_child.leaf->op; |
9ab5ebd7 |
887 | /* FIXME: special case for string copy ! */ |
888 | newtree->l_child.leaf->value = tree->l_child.leaf->value; |
8c89f5a8 |
889 | } |
890 | |
891 | newtree->right = tree->right; |
892 | if(newtree->right == LTTV_TREE_NODE) { |
893 | newtree->r_child.t = lttv_filter_tree_clone(tree->r_child.t); |
894 | } else if(newtree->right == LTTV_TREE_LEAF) { |
895 | newtree->r_child.leaf = lttv_simple_expression_new(); |
896 | newtree->r_child.leaf->field = tree->r_child.leaf->field; |
897 | newtree->r_child.leaf->offset = tree->r_child.leaf->offset; |
898 | newtree->r_child.leaf->op = tree->r_child.leaf->op; |
9ab5ebd7 |
899 | newtree->r_child.leaf->value = tree->r_child.leaf->value; |
8c89f5a8 |
900 | } |
901 | |
902 | return newtree; |
903 | |
150f0d33 |
904 | } |
905 | |
906 | /** |
56e29124 |
907 | * @fn LttvFilter* lttv_filter_clone(LttvFilter*) |
908 | * |
909 | * Makes a copy of the current filter |
910 | * @param filter pointer to the current filter |
911 | * @return new copy of the filter |
150f0d33 |
912 | */ |
913 | LttvFilter* |
914 | lttv_filter_clone(LttvFilter* filter) { |
915 | |
916 | |
917 | LttvFilter* newfilter = g_new(LttvFilter,1); |
918 | |
919 | // newfilter->expression = g_new(char,1) |
920 | strcpy(newfilter->expression,filter->expression); |
921 | |
922 | newfilter->head = lttv_filter_tree_clone(filter->head); |
923 | |
924 | return newfilter; |
925 | |
926 | } |
927 | |
928 | |
84a333d6 |
929 | /** |
56e29124 |
930 | * @fn LttvFilter* lttv_filter_new() |
931 | * |
84a333d6 |
932 | * Creates a new lttv_filter |
31452f49 |
933 | * @param expression filtering options string |
934 | * @param t pointer to the current LttvTrace |
84a333d6 |
935 | * @return the current lttv_filter or NULL if error |
31452f49 |
936 | */ |
2ea36caf |
937 | LttvFilter* |
5f185a2b |
938 | lttv_filter_new() { |
a4c292d4 |
939 | |
5f185a2b |
940 | LttvFilter* filter = g_new(LttvFilter,1); |
941 | filter->expression = NULL; |
942 | filter->head = NULL; |
943 | |
944 | } |
a4c292d4 |
945 | |
8c89f5a8 |
946 | /** |
56e29124 |
947 | * @fn gboolean lttv_filter_update(LttvFilter*) |
948 | * |
8c89f5a8 |
949 | * Updates the current LttvFilter by building |
950 | * its tree based upon the expression string |
951 | * @param filter pointer to the current LttvFilter |
952 | * @return Failure/Success of operation |
953 | */ |
5f185a2b |
954 | gboolean |
955 | lttv_filter_update(LttvFilter* filter) { |
956 | |
957 | g_print("filter::lttv_filter_new()\n"); /* debug */ |
958 | |
959 | if(filter->expression == NULL) return FALSE; |
960 | |
a4c292d4 |
961 | unsigned |
962 | i, |
56e29124 |
963 | p_nesting=0; /* parenthesis nesting value */ |
1601b365 |
964 | |
965 | /* trees */ |
5b729fcf |
966 | LttvFilterTree |
1601b365 |
967 | *tree = lttv_filter_tree_new(), /* main tree */ |
968 | *subtree = NULL, /* buffer for subtrees */ |
969 | *t1, /* buffer #1 */ |
970 | *t2; /* buffer #2 */ |
971 | |
5f185a2b |
972 | /* |
973 | * the filter |
974 | * If the tree already exists, |
975 | * destroy it and build a new one |
976 | */ |
977 | if(filter->head != NULL) lttv_filter_tree_destroy(filter->head); |
978 | filter->head = tree; |
979 | |
1601b365 |
980 | /* |
981 | * Tree Stack |
f4e9dd16 |
982 | * each element of the list |
983 | * is a sub tree created |
984 | * by the use of parenthesis in the |
985 | * global expression. The final tree |
1601b365 |
986 | * will be the one left at the root of |
f4e9dd16 |
987 | * the list |
988 | */ |
18d1226f |
989 | GPtrArray *tree_stack = g_ptr_array_new(); |
990 | g_ptr_array_add( tree_stack,(gpointer) tree ); |
f4e9dd16 |
991 | |
a4c292d4 |
992 | /* temporary values */ |
0769c82f |
993 | GString *a_field_component = g_string_new(""); |
56e29124 |
994 | GPtrArray *a_field_path = g_ptr_array_new(); |
995 | |
996 | /* simple expression buffer */ |
389ba50e |
997 | LttvSimpleExpression* a_simple_expression = lttv_simple_expression_new(); |
0769c82f |
998 | |
a4c292d4 |
999 | /* |
1000 | * Parse entire expression and construct |
1001 | * the binary tree. There are two steps |
1002 | * in browsing that string |
f4e9dd16 |
1003 | * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} " |
a4c292d4 |
1004 | * 2. finding simple expressions |
0769c82f |
1005 | * - field path ( separated by dots ) |
a4c292d4 |
1006 | * - op ( >, <, =, >=, <=, !=) |
0769c82f |
1007 | * - value ( integer, string ... ) |
1008 | * To spare computing time, the whole |
1009 | * string is parsed in this loop for a |
1010 | * O(n) complexity order. |
1601b365 |
1011 | * |
18d1226f |
1012 | * When encountering logical op &,|,^ |
1013 | * 1. parse the last value if any |
1014 | * 2. create a new tree |
1015 | * 3. add the expression (simple exp, or exp (subtree)) to the tree |
1016 | * 4. concatenate this tree with the current tree on top of the stack |
1017 | * When encountering math ops >,>=,<,<=,=,!= |
1018 | * 1. add to op to the simple expression |
1019 | * 2. concatenate last field component to field path |
1020 | * When encountering concatening ops . |
1021 | * 1. concatenate last field component to field path |
1022 | * When encountering opening parenthesis (,{,[ |
1023 | * 1. create a new subtree on top of tree stack |
1024 | * When encountering closing parenthesis ),},] |
1025 | * 1. add the expression on right child of the current tree |
1026 | * 2. the subtree is completed, allocate a new subtree |
1027 | * 3. pop the tree value from the tree stack |
1028 | */ |
1029 | |
73050a5f |
1030 | g_print("expression: %s\n",filter->expression); |
1031 | g_print("strlen(expression): %i\n",strlen(filter->expression)); |
5f185a2b |
1032 | for(i=0;i<strlen(filter->expression);i++) { |
1033 | // debug |
1034 | g_print("%c ",filter->expression[i]); |
1035 | switch(filter->expression[i]) { |
a4c292d4 |
1036 | /* |
1037 | * logical operators |
1038 | */ |
1039 | case '&': /* and */ |
aa4600f3 |
1040 | |
5b729fcf |
1041 | t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1042 | while(t1->right != LTTV_TREE_IDLE) { |
1043 | g_assert(t1->right == LTTV_TREE_NODE); |
1044 | t1 = t1->r_child.t; |
1045 | } |
18d1226f |
1046 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1047 | t2->node = LTTV_LOGICAL_AND; |
bb87caa7 |
1048 | if(subtree != NULL) { /* append subtree to current tree */ |
18d1226f |
1049 | t2->left = LTTV_TREE_NODE; |
1050 | t2->l_child.t = subtree; |
f4e9dd16 |
1051 | subtree = NULL; |
18d1226f |
1052 | t1->right = LTTV_TREE_NODE; |
410c83da |
1053 | t1->r_child.t = t2; |
bb87caa7 |
1054 | } else { /* append a simple expression */ |
9ab5ebd7 |
1055 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1056 | // a_simple_expression->value = g_string_free(a_field_component,FALSE); |
18d1226f |
1057 | a_field_component = g_string_new(""); |
1058 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
1059 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
1060 | a_simple_expression = lttv_simple_expression_new(); |
18d1226f |
1061 | t1->right = LTTV_TREE_NODE; |
9ab5ebd7 |
1062 | t1->r_child.t = t2; |
1063 | g_print("t1:%p t1->child:%p\n",t1,t1->r_child.t); |
f4e9dd16 |
1064 | } |
f4e9dd16 |
1065 | break; |
aa4600f3 |
1066 | |
a4c292d4 |
1067 | case '|': /* or */ |
aa4600f3 |
1068 | |
2ea36caf |
1069 | t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1070 | while(t1->right != LTTV_TREE_IDLE) { |
1071 | g_assert(t1->right == LTTV_TREE_NODE); |
1072 | t1 = t1->r_child.t; |
1073 | } |
1601b365 |
1074 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1075 | t2->node = LTTV_LOGICAL_OR; |
bb87caa7 |
1076 | if(subtree != NULL) { /* append subtree to current tree */ |
1601b365 |
1077 | t2->left = LTTV_TREE_NODE; |
1078 | t2->l_child.t = subtree; |
1079 | subtree = NULL; |
1080 | t1->right = LTTV_TREE_NODE; |
1081 | t1->r_child.t = t2; |
bb87caa7 |
1082 | } else { /* append a simple expression */ |
9ab5ebd7 |
1083 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1084 | //a_simple_expression->value = g_string_free(a_field_component,FALSE); |
1601b365 |
1085 | a_field_component = g_string_new(""); |
1086 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
1087 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
1088 | a_simple_expression = lttv_simple_expression_new(); |
1601b365 |
1089 | t1->right = LTTV_TREE_NODE; |
1090 | t1->r_child.t = t2; |
1091 | } |
f4e9dd16 |
1092 | break; |
aa4600f3 |
1093 | |
a4c292d4 |
1094 | case '^': /* xor */ |
aa4600f3 |
1095 | |
2ea36caf |
1096 | t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1097 | while(t1->right != LTTV_TREE_IDLE) { |
1098 | g_assert(t1->right == LTTV_TREE_NODE); |
1099 | t1 = t1->r_child.t; |
1100 | } |
1601b365 |
1101 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1102 | t2->node = LTTV_LOGICAL_XOR; |
bb87caa7 |
1103 | if(subtree != NULL) { /* append subtree to current tree */ |
1601b365 |
1104 | t2->left = LTTV_TREE_NODE; |
1105 | t2->l_child.t = subtree; |
1106 | subtree = NULL; |
1107 | t1->right = LTTV_TREE_NODE; |
1108 | t1->r_child.t = t2; |
bb87caa7 |
1109 | } else { /* append a simple expression */ |
9ab5ebd7 |
1110 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1111 | //a_simple_expression->value = g_string_free(a_field_component,FALSE); |
1601b365 |
1112 | a_field_component = g_string_new(""); |
1113 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
1114 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
1115 | a_simple_expression = lttv_simple_expression_new(); |
1601b365 |
1116 | t1->right = LTTV_TREE_NODE; |
1117 | t1->r_child.t = t2; |
1118 | } |
a4c292d4 |
1119 | break; |
aa4600f3 |
1120 | |
a4c292d4 |
1121 | case '!': /* not, or not equal (math op) */ |
aa4600f3 |
1122 | |
5f185a2b |
1123 | if(filter->expression[i+1] == '=') { /* != */ |
0cdc2470 |
1124 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1125 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
0cdc2470 |
1126 | a_field_component = g_string_new(""); |
56e29124 |
1127 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_NE); |
aa4600f3 |
1128 | i++; |
a4c292d4 |
1129 | } else { /* ! */ |
2ea36caf |
1130 | t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1131 | while(t1->right != LTTV_TREE_IDLE) { |
1132 | g_assert(t1->right == LTTV_TREE_NODE); |
1133 | t1 = t1->r_child.t; |
1134 | } |
1601b365 |
1135 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1136 | t2->node = LTTV_LOGICAL_NOT; |
1601b365 |
1137 | t1->right = LTTV_TREE_NODE; |
1138 | t1->r_child.t = t2; |
a4c292d4 |
1139 | } |
1140 | break; |
aa4600f3 |
1141 | |
a4c292d4 |
1142 | case '(': /* start of parenthesis */ |
91ad3f0a |
1143 | case '[': |
1144 | case '{': |
aa4600f3 |
1145 | |
91ad3f0a |
1146 | p_nesting++; /* incrementing parenthesis nesting value */ |
1601b365 |
1147 | t1 = lttv_filter_tree_new(); |
1148 | g_ptr_array_add( tree_stack,(gpointer) t1 ); |
a4c292d4 |
1149 | break; |
aa4600f3 |
1150 | |
a4c292d4 |
1151 | case ')': /* end of parenthesis */ |
91ad3f0a |
1152 | case ']': |
1153 | case '}': |
aa4600f3 |
1154 | |
91ad3f0a |
1155 | p_nesting--; /* decrementing parenthesis nesting value */ |
18d1226f |
1156 | if(p_nesting<0 || tree_stack->len<2) { |
f4e9dd16 |
1157 | g_warning("Wrong filtering options, the string\n\"%s\"\n\ |
5f185a2b |
1158 | is not valid due to parenthesis incorrect use",filter->expression); |
1159 | return FALSE; |
f4e9dd16 |
1160 | } |
56e29124 |
1161 | |
1162 | /* there must at least be the root tree left in the array */ |
18d1226f |
1163 | g_assert(tree_stack->len>0); |
56e29124 |
1164 | |
bb87caa7 |
1165 | if(subtree != NULL) { /* append subtree to current tree */ |
18d1226f |
1166 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1167 | while(t1->right != LTTV_TREE_IDLE) { |
1168 | g_assert(t1->right == LTTV_TREE_NODE); |
1169 | t1 = t1->r_child.t; |
18d1226f |
1170 | } |
1171 | t1->right = LTTV_TREE_NODE; |
1172 | t1->r_child.t = subtree; |
1173 | subtree = g_ptr_array_index(tree_stack,tree_stack->len-1); |
1174 | g_ptr_array_remove_index(tree_stack,tree_stack->len-1); |
bb87caa7 |
1175 | } else { /* assign subtree as current tree */ |
9ab5ebd7 |
1176 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1177 | //a_simple_expression->value = g_string_free(a_field_component,FALSE); |
18d1226f |
1178 | a_field_component = g_string_new(""); |
1179 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1180 | g_print("here\n"); |
1181 | while(t1->right != LTTV_TREE_IDLE) { |
1182 | g_print("while right:%i %p->child:%p\n",t1->right,t1,t1->r_child.t); |
1183 | g_assert(t1->right == LTTV_TREE_NODE); |
1184 | g_assert(t1->r_child.t != NULL); |
1185 | t1 = t1->r_child.t; |
1186 | } |
1187 | g_print("here2\n"); |
18d1226f |
1188 | t1->right = LTTV_TREE_LEAF; |
0cdc2470 |
1189 | t1->r_child.leaf = a_simple_expression; |
389ba50e |
1190 | a_simple_expression = lttv_simple_expression_new(); |
9ab5ebd7 |
1191 | subtree = g_ptr_array_remove_index(tree_stack,tree_stack->len-1); |
18d1226f |
1192 | } |
a4c292d4 |
1193 | break; |
1194 | |
1195 | /* |
1196 | * mathematic operators |
1197 | */ |
1198 | case '<': /* lower, lower or equal */ |
aa4600f3 |
1199 | |
1200 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1201 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
aa4600f3 |
1202 | a_field_component = g_string_new(""); |
5f185a2b |
1203 | if(filter->expression[i+1] == '=') { /* <= */ |
a4c292d4 |
1204 | i++; |
56e29124 |
1205 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LE); |
1206 | } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LT); |
aa4600f3 |
1207 | break; |
1208 | |
1209 | case '>': /* higher, higher or equal */ |
1210 | |
1211 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1212 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
f4e9dd16 |
1213 | a_field_component = g_string_new(""); |
5f185a2b |
1214 | if(filter->expression[i+1] == '=') { /* >= */ |
a4c292d4 |
1215 | i++; |
56e29124 |
1216 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GE); |
1217 | } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GT); |
aa4600f3 |
1218 | break; |
1219 | |
a4c292d4 |
1220 | case '=': /* equal */ |
aa4600f3 |
1221 | |
f4e9dd16 |
1222 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
9ab5ebd7 |
1223 | lttv_simple_expression_assign_field(a_field_path,a_simple_expression); |
f4e9dd16 |
1224 | a_field_component = g_string_new(""); |
56e29124 |
1225 | lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_EQ); |
a4c292d4 |
1226 | break; |
aa4600f3 |
1227 | |
0769c82f |
1228 | /* |
1229 | * Field concatening caracter |
1230 | */ |
1231 | case '.': /* dot */ |
aa4600f3 |
1232 | |
bb87caa7 |
1233 | /* |
1234 | * divide field expression into elements |
1235 | * in a_field_path array. |
1236 | */ |
56e29124 |
1237 | /* FIXME: check for double values */ |
80f9611a |
1238 | // if(a_simple_expression->op == NULL) { |
bb87caa7 |
1239 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
1240 | a_field_component = g_string_new(""); |
80f9611a |
1241 | // } |
0769c82f |
1242 | break; |
56e29124 |
1243 | // case ' ': |
1244 | // case '\n': |
1245 | // ignore |
a4c292d4 |
1246 | default: /* concatening current string */ |
73050a5f |
1247 | g_string_append_c(a_field_component,filter->expression[i]); |
a4c292d4 |
1248 | } |
1249 | } |
1601b365 |
1250 | |
1251 | g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree,tree,t1,t2); |
0cdc2470 |
1252 | g_print("stack size: %i\n",tree_stack->len); |
1253 | |
1254 | /* |
1255 | * Preliminary check to see |
1256 | * if tree was constructed correctly |
1257 | */ |
1258 | if( p_nesting>0 ) { |
1259 | g_warning("Wrong filtering options, the string\n\"%s\"\n\ |
5f185a2b |
1260 | is not valid due to parenthesis incorrect use",filter->expression); |
1261 | return FALSE; |
0cdc2470 |
1262 | } |
1263 | |
1264 | if(tree_stack->len != 1) /* only root tree should remain */ |
5f185a2b |
1265 | return FALSE; |
1601b365 |
1266 | |
410c83da |
1267 | /* processing last element of expression */ |
410c83da |
1268 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
9ab5ebd7 |
1269 | while(t1->right != LTTV_TREE_IDLE) { |
1270 | g_assert(t1->right == LTTV_TREE_NODE); |
1271 | t1 = t1->r_child.t; |
1272 | } |
410c83da |
1273 | if(subtree != NULL) { /* add the subtree */ |
1274 | t1->right = LTTV_TREE_NODE; |
0cdc2470 |
1275 | t1->r_child.t = subtree; |
410c83da |
1276 | subtree = NULL; |
1277 | } else { /* add a leaf */ |
9ab5ebd7 |
1278 | lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE)); |
1279 | //a_simple_expression->value = g_string_free(a_field_component,FALSE); |
56e29124 |
1280 | a_field_component = NULL; |
410c83da |
1281 | t1->right = LTTV_TREE_LEAF; |
0cdc2470 |
1282 | t1->r_child.leaf = a_simple_expression; |
56e29124 |
1283 | a_simple_expression = NULL; |
410c83da |
1284 | } |
1285 | |
56e29124 |
1286 | |
73050a5f |
1287 | /* free the pointer array */ |
1288 | g_assert(a_field_path->len == 0); |
1289 | g_ptr_array_free(a_field_path,TRUE); |
56e29124 |
1290 | |
1291 | /* free the tree stack -- but keep the root tree */ |
1292 | g_ptr_array_free(tree_stack,FALSE); |
1293 | |
1294 | /* free the field buffer if allocated */ |
1295 | if(a_field_component != NULL) g_string_free(a_field_component,TRUE); |
1296 | |
1297 | /* free the simple expression buffer if allocated */ |
1298 | if(a_simple_expression != NULL) lttv_simple_expression_destroy(a_simple_expression); |
73050a5f |
1299 | |
56e29124 |
1300 | g_assert(tree != NULL); /* tree should exist */ |
1301 | g_assert(subtree == NULL); /* remaining subtree should be included in main tree */ |
a4c292d4 |
1302 | |
56e29124 |
1303 | /* debug */ |
1304 | g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n"); |
1305 | lttv_print_tree(filter->head) ; |
1306 | g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n"); |
1307 | |
1308 | /* success */ |
5f185a2b |
1309 | return TRUE; |
80f9611a |
1310 | |
31452f49 |
1311 | } |
1312 | |
8c89f5a8 |
1313 | /** |
56e29124 |
1314 | * @fn void lttv_filter_destroy(LttvFilter*) |
1315 | * |
8c89f5a8 |
1316 | * Destroy the current LttvFilter |
1317 | * @param filter pointer to the current LttvFilter |
1318 | */ |
1da1525d |
1319 | void |
2ea36caf |
1320 | lttv_filter_destroy(LttvFilter* filter) { |
5f185a2b |
1321 | |
1322 | g_free(filter->expression); |
1323 | lttv_filter_tree_destroy(filter->head); |
1324 | g_free(filter); |
1325 | |
1da1525d |
1326 | } |
1327 | |
150f0d33 |
1328 | /** |
56e29124 |
1329 | * LttvFilterTree* lttv_filter_tree_new() |
1330 | * |
150f0d33 |
1331 | * Assign a new tree for the current expression |
1332 | * or sub expression |
1333 | * @return pointer of LttvFilterTree |
1334 | */ |
5f185a2b |
1335 | LttvFilterTree* |
1336 | lttv_filter_tree_new() { |
150f0d33 |
1337 | LttvFilterTree* tree; |
1338 | |
1339 | tree = g_new(LttvFilter,1); |
1340 | tree->node = 0; //g_new(lttv_expression,1); |
150f0d33 |
1341 | tree->left = LTTV_TREE_IDLE; |
1342 | tree->right = LTTV_TREE_IDLE; |
1343 | |
1344 | return tree; |
1345 | } |
1346 | |
80f9611a |
1347 | /** |
56e29124 |
1348 | * @fn void lttv_filter_append_expression(LttvFilter*,char*) |
1349 | * |
80f9611a |
1350 | * Append a new expression to the expression |
1351 | * defined in the current filter |
1352 | * @param filter pointer to the current LttvFilter |
1353 | * @param expression string that must be appended |
56e29124 |
1354 | * @return Success/Failure of operation |
80f9611a |
1355 | */ |
56e29124 |
1356 | gboolean lttv_filter_append_expression(LttvFilter* filter, char *expression) { |
80f9611a |
1357 | |
56e29124 |
1358 | if(expression == NULL) return FALSE; |
80f9611a |
1359 | if(filter == NULL) { |
1360 | filter = lttv_filter_new(); |
1361 | filter->expression = expression; |
1362 | } else if(filter->expression == NULL) { |
1363 | filter->expression = expression; |
1364 | } else { |
1365 | filter->expression = g_strconcat(filter->expression,"&",expression); |
1366 | } |
1367 | |
56e29124 |
1368 | return lttv_filter_update(filter); |
80f9611a |
1369 | |
1370 | } |
1371 | |
1372 | /** |
56e29124 |
1373 | * @fn void lttv_filter_clear_expression(LttvFilter*) |
1374 | * |
80f9611a |
1375 | * Clear the filter expression from the |
1376 | * current filter and sets its pointer to NULL |
1377 | * @param filter pointer to the current LttvFilter |
1378 | */ |
1379 | void lttv_filter_clear_expression(LttvFilter* filter) { |
1380 | |
1381 | if(filter->expression != NULL) { |
1382 | g_free(filter->expression); |
1383 | filter->expression = NULL; |
1384 | } |
1385 | |
1386 | } |
1387 | |
150f0d33 |
1388 | /** |
56e29124 |
1389 | * @fn void lttv_filter_tree_destroy(LttvFilterTree*) |
1390 | * |
150f0d33 |
1391 | * Destroys the tree and his sub-trees |
1392 | * @param tree Tree which must be destroyed |
1393 | */ |
5f185a2b |
1394 | void |
1395 | lttv_filter_tree_destroy(LttvFilterTree* tree) { |
56e29124 |
1396 | |
150f0d33 |
1397 | if(tree == NULL) return; |
1398 | |
56e29124 |
1399 | if(tree->left == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->l_child.leaf); |
150f0d33 |
1400 | else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t); |
1401 | |
56e29124 |
1402 | if(tree->right == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->r_child.leaf); |
150f0d33 |
1403 | else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t); |
1404 | |
1405 | g_free(tree->node); |
1406 | g_free(tree); |
1407 | } |
1408 | |
84a333d6 |
1409 | /** |
56e29124 |
1410 | * gboolean lttv_filter_tree_parse(LttvFilterTree*,LttEvent,LttTracefile,LttTrace,LttvProcessState) |
1411 | * |
80f9611a |
1412 | * Global parsing function for the current |
1413 | * LttvFilterTree |
1414 | * @param tree pointer to the current LttvFilterTree |
1415 | * @param event current LttEvent, NULL if not used |
1416 | * @param tracefile current LttTracefile, NULL if not used |
1417 | * @param trace current LttTrace, NULL if not used |
1418 | * @param state current LttvProcessState, NULL if not used |
84a333d6 |
1419 | */ |
31452f49 |
1420 | gboolean |
80f9611a |
1421 | lttv_filter_tree_parse( |
1422 | LttvFilterTree* t, |
1423 | LttEvent* event, |
1424 | LttTracefile* tracefile, |
1425 | LttTrace* trace, |
1426 | LttvProcessState* state |
1427 | /*,...*/) |
1428 | { |
0769c82f |
1429 | |
80f9611a |
1430 | /* |
1601b365 |
1431 | * Each tree is parsed in inorder. |
1432 | * This way, it's possible to apply the left filter of the |
1433 | * tree, then decide whether or not the right branch should |
1434 | * be parsed depending on the linking logical operator |
1435 | * |
80f9611a |
1436 | * Each node consists in a |
1437 | * 1. logical operator |
1438 | * 2. left child ( node or simple expression ) |
1439 | * 3. right child ( node or simple expression ) |
1440 | * |
1441 | * When the child is a simple expression, we must |
1442 | * before all determine if the expression refers to |
1443 | * a structure which is whithin observation ( not NULL ). |
1444 | * -If so, the expression is evaluated. |
1445 | * -If not, the result is set to TRUE since this particular |
1446 | * operation does not interfere with the lttv structure |
1447 | * |
1448 | * The result of each simple expression will directly |
1449 | * affect the next branch. This way, depending on |
1450 | * the linking logical operator, the parser will decide |
1451 | * to explore or not the next branch. |
1452 | * 1. AND OPERATOR |
1453 | * -If result of left branch is 0 / FALSE |
1454 | * then don't explore right branch and return 0; |
1455 | * -If result of left branch is 1 / TRUE then explore |
1456 | * 2. OR OPERATOR |
1457 | * -If result of left branch is 1 / TRUE |
1458 | * then don't explore right branch and return 1; |
1459 | * -If result of left branch is 0 / FALSE then explore |
1460 | * 3. XOR OPERATOR |
56e29124 |
1461 | * -Result of left branch will not affect exploration of |
80f9611a |
1462 | * right branch |
1601b365 |
1463 | */ |
73050a5f |
1464 | g_print("filter::lttv_parse_tree(...)\n"); |
1465 | |
80f9611a |
1466 | gboolean lresult = FALSE, rresult = FALSE; |
0769c82f |
1467 | |
80f9611a |
1468 | /* |
1469 | * Parse left branch |
1470 | */ |
1471 | if(t->left == LTTV_TREE_NODE) lresult = lttv_filter_tree_parse(t->l_child.t,event,tracefile,trace,state); |
5b729fcf |
1472 | else if(t->left == LTTV_TREE_LEAF) { |
80f9611a |
1473 | //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 |
1474 | LttvFieldValue v; |
1475 | v = t->l_child.leaf->value; |
80f9611a |
1476 | switch(t->l_child.leaf->field) { |
1477 | |
1478 | case LTTV_FILTER_TRACE_NAME: |
1479 | if(trace == NULL) lresult = TRUE; |
1480 | else lresult = t->l_child.leaf->op((gpointer)ltt_trace_name(trace),v); |
1481 | break; |
1482 | case LTTV_FILTER_TRACEFILE_NAME: |
1483 | if(tracefile == NULL) lresult = TRUE; |
1484 | else lresult = t->l_child.leaf->op((gpointer)ltt_tracefile_name(tracefile),v); |
1485 | break; |
1486 | case LTTV_FILTER_STATE_PID: |
1487 | if(state == NULL) lresult = TRUE; |
1488 | else lresult = t->l_child.leaf->op((gpointer)&state->pid,v); |
1489 | break; |
1490 | case LTTV_FILTER_STATE_PPID: |
1491 | if(state == NULL) lresult = TRUE; |
1492 | else lresult = t->l_child.leaf->op((gpointer)&state->ppid,v); |
1493 | break; |
1494 | case LTTV_FILTER_STATE_CT: |
1495 | if(state == NULL) lresult = TRUE; |
1496 | else { |
1497 | double val = ltt_time_to_double(state->creation_time); |
1498 | lresult = t->l_child.leaf->op((gpointer)&val,v); |
1499 | } |
1500 | break; |
1501 | case LTTV_FILTER_STATE_IT: |
1502 | if(state == NULL) lresult = TRUE; |
1503 | else { |
1504 | double val = ltt_time_to_double(state->insertion_time); |
1505 | lresult = t->l_child.leaf->op((gpointer)&val,v); |
1506 | } |
1507 | break; |
1508 | case LTTV_FILTER_STATE_P_NAME: |
1509 | /* |
1510 | * FIXME: Yet to be done ( I think ? ) |
1511 | */ |
1512 | lresult = TRUE; |
1513 | break; |
1514 | case LTTV_FILTER_STATE_EX_MODE: |
1515 | if(state == NULL) lresult = TRUE; |
1516 | else lresult = t->l_child.leaf->op((gpointer)&state->state->t,v); |
1517 | break; |
1518 | case LTTV_FILTER_STATE_EX_SUBMODE: |
1519 | if(state == NULL) lresult = TRUE; |
1520 | else lresult = t->l_child.leaf->op((gpointer)&state->state->n,v); |
1521 | break; |
1522 | case LTTV_FILTER_STATE_P_STATUS: |
1523 | if(state == NULL) lresult = TRUE; |
1524 | else lresult = t->l_child.leaf->op((gpointer)&state->state->s,v); |
1525 | break; |
1526 | case LTTV_FILTER_STATE_CPU: |
1527 | /* |
1528 | * FIXME: What is the comparison value ? |
1529 | */ |
1530 | lresult = TRUE; |
1531 | break; |
1532 | case LTTV_FILTER_EVENT_NAME: |
1533 | if(event == NULL) lresult = TRUE; |
1534 | else lresult = t->l_child.leaf->op((gpointer)ltt_event_eventtype(event),v); |
1535 | break; |
1536 | |
1537 | case LTTV_FILTER_EVENT_CATEGORY: |
1538 | /* |
1539 | * FIXME: Not yet implemented |
1540 | */ |
1541 | lresult = TRUE; |
1542 | break; |
1543 | case LTTV_FILTER_EVENT_TIME: |
1544 | // if(event == NULL) lresult = TRUE; |
1545 | // else { |
1546 | // double val = ltt_time_to_double(event->event_time); |
1547 | // lresult = t->l_child.leaf->op((gpointer)&val,v); |
1548 | // } |
1549 | lresult = TRUE; |
1550 | break; |
1551 | case LTTV_FILTER_EVENT_TSC: |
1552 | // if(event == NULL) lresult = TRUE; |
1553 | // else { |
1554 | // double val = ltt_time_to_double(event->event_time); |
1555 | // lresult = t->l_child.leaf->op((gpointer)&val,v); |
1556 | // } |
1557 | /* |
1558 | * FIXME: Where is event.tsc |
1559 | */ |
1560 | lresult = TRUE; |
1561 | break; |
1562 | case LTTV_FILTER_EVENT_FIELD: |
1563 | /* |
1564 | * TODO: Use the offset to |
1565 | * find the dynamic field |
1566 | * in the event struct |
1567 | */ |
1568 | lresult = TRUE; |
1569 | default: |
1570 | /* |
1571 | * This case should never be |
1572 | * parsed, if so, the whole |
1573 | * filtering is cancelled |
1574 | */ |
1575 | g_warning("Error while parsing the filter tree"); |
1576 | return TRUE; |
1577 | } |
0cdc2470 |
1578 | } |
80f9611a |
1579 | |
1580 | /* |
1581 | * Parse linking operator |
1582 | * make a cutoff if possible |
1583 | */ |
1584 | if((t->node & LTTV_LOGICAL_OR) && lresult == TRUE) return TRUE; |
1585 | if((t->node & LTTV_LOGICAL_AND) && lresult == FALSE) return FALSE; |
1586 | |
1587 | /* |
1588 | * Parse right branch |
1589 | */ |
1590 | if(t->right == LTTV_TREE_NODE) rresult = lttv_filter_tree_parse(t->r_child.t,event,tracefile,trace,state); |
5b729fcf |
1591 | else if(t->right == LTTV_TREE_LEAF) { |
80f9611a |
1592 | //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 |
1593 | LttvFieldValue v; |
1594 | v = t->r_child.leaf->value; |
80f9611a |
1595 | switch(t->r_child.leaf->field) { |
1596 | |
1597 | case LTTV_FILTER_TRACE_NAME: |
1598 | if(trace == NULL) rresult = TRUE; |
1599 | else rresult = t->r_child.leaf->op((gpointer)ltt_trace_name(trace),v); |
1600 | break; |
1601 | case LTTV_FILTER_TRACEFILE_NAME: |
1602 | if(tracefile == NULL) rresult = TRUE; |
1603 | else rresult = t->r_child.leaf->op((gpointer)ltt_tracefile_name(tracefile),v); |
1604 | break; |
1605 | case LTTV_FILTER_STATE_PID: |
1606 | if(state == NULL) rresult = TRUE; |
1607 | else rresult = t->r_child.leaf->op((gpointer)&state->pid,v); |
1608 | break; |
1609 | case LTTV_FILTER_STATE_PPID: |
1610 | if(state == NULL) rresult = TRUE; |
1611 | else rresult = t->r_child.leaf->op((gpointer)&state->ppid,v); |
1612 | break; |
1613 | case LTTV_FILTER_STATE_CT: |
1614 | if(state == NULL) rresult = TRUE; |
1615 | else { |
1616 | double val = ltt_time_to_double(state->creation_time); |
1617 | rresult = t->r_child.leaf->op((gpointer)&val,v); |
1618 | } |
1619 | break; |
1620 | case LTTV_FILTER_STATE_IT: |
1621 | if(state == NULL) rresult = TRUE; |
1622 | else { |
1623 | double val = ltt_time_to_double(state->insertion_time); |
1624 | rresult = t->r_child.leaf->op((gpointer)&val,v); |
1625 | } |
1626 | break; |
1627 | case LTTV_FILTER_STATE_P_NAME: |
1628 | /* |
1629 | * FIXME: Yet to be done ( I think ? ) |
1630 | */ |
1631 | rresult = TRUE; |
1632 | break; |
1633 | case LTTV_FILTER_STATE_EX_MODE: |
1634 | if(state == NULL) rresult = TRUE; |
1635 | else rresult = t->r_child.leaf->op((gpointer)&state->state->t,v); |
1636 | break; |
1637 | case LTTV_FILTER_STATE_EX_SUBMODE: |
1638 | if(state == NULL) rresult = TRUE; |
1639 | else rresult = t->r_child.leaf->op((gpointer)&state->state->n,v); |
1640 | break; |
1641 | case LTTV_FILTER_STATE_P_STATUS: |
1642 | if(state == NULL) rresult = TRUE; |
1643 | else rresult = t->r_child.leaf->op((gpointer)&state->state->s,v); |
1644 | break; |
1645 | case LTTV_FILTER_STATE_CPU: |
1646 | /* |
1647 | * FIXME: What is the comparison value ? |
1648 | */ |
1649 | rresult = TRUE; |
1650 | break; |
1651 | case LTTV_FILTER_EVENT_NAME: |
1652 | if(event == NULL) rresult = TRUE; |
1653 | else rresult = t->r_child.leaf->op((gpointer)ltt_event_eventtype(event),v); |
1654 | break; |
1655 | |
1656 | case LTTV_FILTER_EVENT_CATEGORY: |
1657 | /* |
1658 | * FIXME: Not yet implemented |
1659 | */ |
1660 | rresult = TRUE; |
1661 | break; |
1662 | case LTTV_FILTER_EVENT_TIME: |
1663 | // if(event == NULL) rresult = TRUE; |
1664 | // else { |
1665 | // double val = ltt_time_to_double(event->event_time); |
1666 | // rresult = t->r_child.leaf->op((gpointer)&val,v); |
1667 | // } |
1668 | rresult = TRUE; |
1669 | break; |
1670 | case LTTV_FILTER_EVENT_TSC: |
1671 | // if(event == NULL) rresult = TRUE; |
1672 | // else { |
1673 | // double val = ltt_time_to_double(event->event_time); |
1674 | // rresult = t->r_child.leaf->op((gpointer)&val,v); |
1675 | // } |
1676 | /* |
1677 | * FIXME: Where is event.tsc |
1678 | */ |
1679 | rresult = TRUE; |
1680 | break; |
1681 | case LTTV_FILTER_EVENT_FIELD: |
1682 | /* |
1683 | * TODO: Use the offset to |
1684 | * find the dynamic field |
1685 | * in the event struct |
1686 | */ |
1687 | rresult = TRUE; |
1688 | default: |
1689 | /* |
1690 | * This case should never be |
1691 | * parsed, if so, this subtree |
1692 | * is cancelled ! |
1693 | */ |
1694 | g_warning("Error while parsing the filter tree"); |
1695 | return TRUE; |
1696 | } |
0cdc2470 |
1697 | } |
5f185a2b |
1698 | |
80f9611a |
1699 | /* |
1700 | * Apply and return the |
1701 | * logical link between the |
1702 | * two operation |
1703 | */ |
1704 | switch(t->node) { |
1705 | case LTTV_LOGICAL_OR: return (lresult | rresult); |
1706 | case LTTV_LOGICAL_AND: return (lresult & rresult); |
1707 | case LTTV_LOGICAL_NOT: return (!rresult); |
1708 | case LTTV_LOGICAL_XOR: return (lresult ^ rresult); |
1709 | default: |
1710 | /* |
1711 | * This case should never be |
1712 | * parsed, if so, this subtree |
1713 | * is cancelled ! |
1714 | */ |
1715 | return TRUE; |
1716 | } |
0769c82f |
1717 | |
80f9611a |
1718 | } |
0769c82f |
1719 | |
80f9611a |
1720 | /** |
56e29124 |
1721 | * @fn void lttv_print_tree(LttvFilterTree*) |
1722 | * |
1723 | * Debug |
1724 | * @param t the pointer to the current LttvFilterTree |
80f9611a |
1725 | */ |
1726 | void |
1727 | lttv_print_tree(LttvFilterTree* t) { |
0769c82f |
1728 | |
73050a5f |
1729 | g_print("node:%p lchild:%p rchild:%p\n",t, //t->l_child.t,t->r_child.t); |
80f9611a |
1730 | (t->left==LTTV_TREE_NODE)?t->l_child.t:NULL, |
1731 | (t->right==LTTV_TREE_NODE)?t->r_child.t:NULL); |
1732 | g_print("node type: %i / [left] %i / [right] %i\n",t->node,t->left,t->right); |
1733 | if(t->left == LTTV_TREE_NODE) lttv_print_tree(t->l_child.t); |
1734 | else if(t->left == LTTV_TREE_LEAF) { |
73050a5f |
1735 | // g_assert(t->l_child.leaf->value != NULL); |
9ab5ebd7 |
1736 | g_print("%p: left is %i %p value\n",t,t->l_child.leaf->field,t->l_child.leaf->op); |
0769c82f |
1737 | } |
80f9611a |
1738 | if(t->right == LTTV_TREE_NODE) lttv_print_tree(t->r_child.t); |
1739 | else if(t->right == LTTV_TREE_LEAF) { |
73050a5f |
1740 | // g_assert(t->r_child.leaf->value != NULL); |
9ab5ebd7 |
1741 | g_print("%p: right is %i %p value\n",t,t->r_child.leaf->field,t->r_child.leaf->op); |
80f9611a |
1742 | } |
80f9611a |
1743 | |
1744 | } |
1745 | |
1746 | /** |
56e29124 |
1747 | * gboolean lttv_filter_tracefile(LttvFilter*, LttTracefile*) |
1748 | * |
80f9611a |
1749 | * Apply the filter to a specific trace |
1750 | * @param filter the current filter applied |
1751 | * @param tracefile the trace to apply the filter to |
1752 | * @return success/failure of operation |
0769c82f |
1753 | */ |
80f9611a |
1754 | gboolean |
1755 | lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile) { |
1756 | |
1757 | return lttv_filter_tree_parse(filter->head,NULL,tracefile,NULL,NULL); |
1758 | |
31452f49 |
1759 | } |
1760 | |
56e29124 |
1761 | /** |
1762 | * @fn gboolean lttv_filter_tracestate(LttvFilter*,LttvTraceState*) |
1763 | * |
1764 | * Parse the current tracestate |
1765 | * @param filter pointer to the current LttvFilter |
1766 | * @param tracestate pointer to the current tracestate |
1767 | */ |
1a7fa682 |
1768 | gboolean |
2ea36caf |
1769 | lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate) { |
341aa948 |
1770 | |
1771 | } |
1a7fa682 |
1772 | |
84a333d6 |
1773 | /** |
56e29124 |
1774 | * @fn gboolean lttv_filter_event(LttvFilter*,LttEvent*) |
1775 | * |
84a333d6 |
1776 | * Apply the filter to a specific event |
1777 | * @param filter the current filter applied |
1778 | * @param event the event to apply the filter to |
1779 | * @return success/failure of operation |
1780 | */ |
31452f49 |
1781 | gboolean |
2ea36caf |
1782 | lttv_filter_event(LttvFilter *filter, LttEvent *event) { |
31452f49 |
1783 | |
1784 | } |
1a7fa682 |
1785 | |
91ad3f0a |
1786 | /** |
56e29124 |
1787 | * @fn static void module_init() |
1788 | * |
91ad3f0a |
1789 | * Initializes the filter module and specific values |
1790 | */ |
1a7fa682 |
1791 | static void module_init() |
1792 | { |
91ad3f0a |
1793 | |
1a7fa682 |
1794 | } |
1795 | |
91ad3f0a |
1796 | /** |
1797 | * Destroys the filter module and specific values |
1798 | */ |
1a7fa682 |
1799 | static void module_destroy() |
1800 | { |
56e29124 |
1801 | |
1a7fa682 |
1802 | } |
1803 | |
1804 | |
91ad3f0a |
1805 | LTTV_MODULE("filter", "Filters traceset and events", \ |
1806 | "Filters traceset and events specifically to user input", \ |
1a7fa682 |
1807 | module_init, module_destroy) |
1808 | |
1809 | |
1810 | |