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