filter core:
[lttv.git] / ltt / branches / poly / lttv / lttv / filter.c
CommitLineData
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
57 */
58
59#include <lttv/filter.h>
60
61/*
1a7fa682 62GQuark
63 LTTV_FILTER_TRACE,
64 LTTV_FILTER_TRACESET,
65 LTTV_FILTER_TRACEFILE,
66 LTTV_FILTER_STATE,
91ad3f0a 67 LTTV_FILTER_EVENT,
68 LTTV_FILTER_NAME,
69 LTTV_FILTER_CATEGORY,
70 LTTV_FILTER_TIME,
71 LTTV_FILTER_TSC,
72 LTTV_FILTER_PID,
73 LTTV_FILTER_PPID,
74 LTTV_FILTER_C_TIME,
75 LTTV_FILTER_I_TIME,
76 LTTV_FILTER_P_NAME,
77 LTTV_FILTER_EX_MODE,
78 LTTV_FILTER_EX_SUBMODE,
79 LTTV_FILTER_P_STATUS,
80 LTTV_FILTER_CPU;
150f0d33 81*/
0cdc2470 82
2ea36caf 83LttvSimpleExpression*
0cdc2470 84lttv_simple_expression_new() {
85
86}
f4e9dd16 87/**
150f0d33 88 * add a node to the current tree
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 93void
5b729fcf 94lttv_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);
0cdc2470 100 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
101 t2 = lttv_filter_tree_new();
102 t2->node = op;
103 if(subtree != NULL) {
104 t2->left = LTTV_TREE_NODE;
105 t2->l_child.t = subtree;
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
0769c82f 121/**
122 * Parse through filtering field hierarchy as specified
123 * by user. This function compares each value to
124 * predetermined quarks
125 * @param fp The field path list
126 * @return success/failure of operation
127 */
128gboolean
f4e9dd16 129parse_field_path(GPtrArray* fp) {
0769c82f 130
f4e9dd16 131 GString* f = NULL;
2b99ec10 132 if(fp->len < 2) return FALSE;
f4e9dd16 133 g_assert(f=g_ptr_array_index(fp,0)); //list_first(fp)->data;
0769c82f 134
91ad3f0a 135 if(g_quark_try_string(f->str) == LTTV_FILTER_EVENT) {
2b99ec10 136 f=g_ptr_array_index(fp,1);
137 if(g_quark_try_string(f->str) == LTTV_FILTER_NAME) {}
138 else if(g_quark_try_string(f->str) == LTTV_FILTER_CATEGORY) {}
139 else if(g_quark_try_string(f->str) == LTTV_FILTER_TIME) {
140 // offset = &((LttEvent*)NULL)->event_time);
141 }
142 else if(g_quark_try_string(f->str) == LTTV_FILTER_TSC) {
143 // offset = &((LttEvent*)NULL)->event_cycle_count);
144 }
145 else { /* core.xml specified options */
146
147 }
91ad3f0a 148 } else if(g_quark_try_string(f->str) == LTTV_FILTER_TRACEFILE) {
2b99ec10 149 f=g_ptr_array_index(fp,1);
150 if(g_quark_try_string(f->str) == LTTV_FILTER_NAME) {}
151 else return FALSE;
91ad3f0a 152 } else if(g_quark_try_string(f->str) == LTTV_FILTER_TRACE) {
2b99ec10 153 f=g_ptr_array_index(fp,1);
154 if(g_quark_try_string(f->str) == LTTV_FILTER_NAME) {}
155 else return FALSE;
91ad3f0a 156
157 } else if(g_quark_try_string(f->str) == LTTV_FILTER_STATE) {
2b99ec10 158 f=g_ptr_array_index(fp,1);
159 if(g_quark_try_string(f->str) == LTTV_FILTER_PID) {}
160 else if(g_quark_try_string(f->str) == LTTV_FILTER_PPID) {}
161 else if(g_quark_try_string(f->str) == LTTV_FILTER_C_TIME) {}
162 else if(g_quark_try_string(f->str) == LTTV_FILTER_I_TIME) {}
163 else if(g_quark_try_string(f->str) == LTTV_FILTER_P_NAME) {}
164 else if(g_quark_try_string(f->str) == LTTV_FILTER_EX_MODE) {}
165 else if(g_quark_try_string(f->str) == LTTV_FILTER_EX_SUBMODE) {}
166 else if(g_quark_try_string(f->str) == LTTV_FILTER_P_STATUS) {}
167 else if(g_quark_try_string(f->str) == LTTV_FILTER_CPU) {}
168 else return FALSE;
91ad3f0a 169
170 } else {
171 g_warning("Unrecognized field in filter string");
172 return FALSE;
0769c82f 173 }
91ad3f0a 174 return TRUE;
0769c82f 175}
176
31452f49 177/**
84a333d6 178 * Add an filtering option to the current tree
179 * @param expression Current expression to parse
180 * @return success/failure of operation
181 */
182gboolean
183parse_simple_expression(GString* expression) {
184
185 unsigned i;
186
a4c292d4 187
0769c82f 188
a4c292d4 189
84a333d6 190}
191
150f0d33 192/**
193 * Applies the 'equal' operator to the
194 * specified structure and value
195 * @return success/failure of operation
196 */
5b729fcf 197gboolean lttv_apply_op_eq_uint64() {}
150f0d33 198
5b729fcf 199/**
200 * Applies the 'equal' operator to the
201 * specified structure and value
202 * @return success/failure of operation
203 */
204gboolean lttv_apply_op_eq_uint32() {}
205
206/**
207 * Applies the 'equal' operator to the
208 * specified structure and value
209 * @return success/failure of operation
210 */
211gboolean lttv_apply_op_eq_uint16() {}
212
213/**
214 * Applies the 'equal' operator to the
215 * specified structure and value
216 * @return success/failure of operation
217 */
218gboolean lttv_apply_op_eq_double() {}
219
220/**
221 * Applies the 'equal' operator to the
222 * specified structure and value
223 * @return success/failure of operation
224 */
225gboolean lttv_apply_op_eq_string() {}
150f0d33 226
227/**
228 * Applies the 'not equal' operator to the
229 * specified structure and value
230 * @return success/failure of operation
231 */
5b729fcf 232gboolean lttv_apply_op_ne_uint64() {}
150f0d33 233
5b729fcf 234/**
235 * Applies the 'not equal' operator to the
236 * specified structure and value
237 * @return success/failure of operation
238 */
239gboolean lttv_apply_op_ne_uint32() {}
240
241/**
242 * Applies the 'not equal' operator to the
243 * specified structure and value
244 * @return success/failure of operation
245 */
246gboolean lttv_apply_op_ne_uint16() {}
247
248/**
249 * Applies the 'not equal' operator to the
250 * specified structure and value
251 * @return success/failure of operation
252 */
253gboolean lttv_apply_op_ne_double() {}
254
255/**
256 * Applies the 'not equal' operator to the
257 * specified structure and value
258 * @return success/failure of operation
259 */
260gboolean lttv_apply_op_ne_string() {}
150f0d33 261
262/**
263 * Applies the 'lower than' operator to the
264 * specified structure and value
265 * @return success/failure of operation
266 */
5b729fcf 267gboolean lttv_apply_op_lt_uint64() {}
150f0d33 268
5b729fcf 269/**
270 * Applies the 'lower than' operator to the
271 * specified structure and value
272 * @return success/failure of operation
273 */
274gboolean lttv_apply_op_lt_uint32() {}
275
276/**
277 * Applies the 'lower than' operator to the
278 * specified structure and value
279 * @return success/failure of operation
280 */
281gboolean lttv_apply_op_lt_uint16() {}
282
283/**
284 * Applies the 'lower than' operator to the
285 * specified structure and value
286 * @return success/failure of operation
287 */
288gboolean lttv_apply_op_lt_double() {}
289
290/**
291 * Applies the 'lower than' operator to the
292 * specified structure and value
293 * @return success/failure of operation
294 */
295gboolean lttv_apply_op_le_uint64() {}
150f0d33 296
297/**
298 * Applies the 'lower or equal' operator to the
299 * specified structure and value
300 * @return success/failure of operation
301 */
5b729fcf 302gboolean lttv_apply_op_le_uint32() {}
150f0d33 303
5b729fcf 304/**
305 * Applies the 'lower or equal' operator to the
306 * specified structure and value
307 * @return success/failure of operation
308 */
309gboolean lttv_apply_op_le_uint16() {}
310
311/**
312 * Applies the 'lower or equal' operator to the
313 * specified structure and value
314 * @return success/failure of operation
315 */
316gboolean lttv_apply_op_le_double() {}
317
318/**
319 * Applies the 'lower or equal' operator to the
320 * specified structure and value
321 * @return success/failure of operation
322 */
323gboolean lttv_apply_op_gt_uint64() {}
150f0d33 324
325/**
326 * Applies the 'greater than' operator to the
327 * specified structure and value
328 * @return success/failure of operation
329 */
5b729fcf 330gboolean lttv_apply_op_gt_uint32() {}
150f0d33 331
5b729fcf 332/**
333 * Applies the 'greater than' operator to the
334 * specified structure and value
335 * @return success/failure of operation
336 */
337gboolean lttv_apply_op_gt_uint16() {}
338
339/**
340 * Applies the 'greater than' operator to the
341 * specified structure and value
342 * @return success/failure of operation
343 */
344gboolean lttv_apply_op_gt_double() {}
345
346/**
347 * Applies the 'greater than' operator to the
348 * specified structure and value
349 * @return success/failure of operation
350 */
351gboolean lttv_apply_op_ge_uint64() {}
150f0d33 352
353/**
354 * Applies the 'greater or equal' operator to the
355 * specified structure and value
356 * @return success/failure of operation
357 */
5b729fcf 358gboolean lttv_apply_op_ge_uint32() {}
150f0d33 359
5b729fcf 360/**
361 * Applies the 'greater or equal' operator to the
362 * specified structure and value
363 * @return success/failure of operation
364 */
365gboolean lttv_apply_op_ge_uint16() {}
150f0d33 366
5b729fcf 367/**
368 * Applies the 'greater or equal' operator to the
369 * specified structure and value
370 * @return success/failure of operation
371 */
372gboolean lttv_apply_op_ge_double() {}
150f0d33 373
374
375/**
376 * Makes a copy of the current filter tree
377 * @param tree pointer to the current tree
378 * @return new copy of the filter tree
379 */
380LttvFilterTree*
381lttv_filter_tree_clone(LttvFilterTree* tree) {
382
383
384
385}
386
387/**
388 * Makes a copy of the current filter
389 * @param filter pointer to the current filter
390 * @return new copy of the filter
391 */
392LttvFilter*
393lttv_filter_clone(LttvFilter* filter) {
394
395
396 LttvFilter* newfilter = g_new(LttvFilter,1);
397
398 // newfilter->expression = g_new(char,1)
399 strcpy(newfilter->expression,filter->expression);
400
401 newfilter->head = lttv_filter_tree_clone(filter->head);
402
403 return newfilter;
404
405}
406
407
84a333d6 408/**
409 * Creates a new lttv_filter
31452f49 410 * @param expression filtering options string
411 * @param t pointer to the current LttvTrace
84a333d6 412 * @return the current lttv_filter or NULL if error
31452f49 413 */
2ea36caf 414LttvFilter*
0769c82f 415lttv_filter_new(char *expression, LttvTraceState *tcs) {
a4c292d4 416
0769c82f 417 g_print("filter::lttv_filter_new()\n"); /* debug */
a4c292d4 418
a4c292d4 419 unsigned
420 i,
91ad3f0a 421 p_nesting=0, /* parenthesis nesting value */
a4c292d4 422 b=0; /* current breakpoint in expression string */
1601b365 423
424 /* trees */
5b729fcf 425 LttvFilterTree
1601b365 426 *tree = lttv_filter_tree_new(), /* main tree */
427 *subtree = NULL, /* buffer for subtrees */
428 *t1, /* buffer #1 */
429 *t2; /* buffer #2 */
430
431 /*
432 * Tree Stack
f4e9dd16 433 * each element of the list
434 * is a sub tree created
435 * by the use of parenthesis in the
436 * global expression. The final tree
1601b365 437 * will be the one left at the root of
f4e9dd16 438 * the list
439 */
18d1226f 440 GPtrArray *tree_stack = g_ptr_array_new();
441 g_ptr_array_add( tree_stack,(gpointer) tree );
f4e9dd16 442
a4c292d4 443 /* temporary values */
0769c82f 444 GString *a_field_component = g_string_new("");
f4e9dd16 445 GPtrArray *a_field_path = NULL;
446
2ea36caf 447 LttvSimpleExpression* a_simple_expression = g_new(LttvSimpleExpression,1);
0769c82f 448
a4c292d4 449 /*
450 * Parse entire expression and construct
451 * the binary tree. There are two steps
452 * in browsing that string
f4e9dd16 453 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
a4c292d4 454 * 2. finding simple expressions
0769c82f 455 * - field path ( separated by dots )
a4c292d4 456 * - op ( >, <, =, >=, <=, !=)
0769c82f 457 * - value ( integer, string ... )
458 * To spare computing time, the whole
459 * string is parsed in this loop for a
460 * O(n) complexity order.
1601b365 461 *
18d1226f 462 * When encountering logical op &,|,^
463 * 1. parse the last value if any
464 * 2. create a new tree
465 * 3. add the expression (simple exp, or exp (subtree)) to the tree
466 * 4. concatenate this tree with the current tree on top of the stack
467 * When encountering math ops >,>=,<,<=,=,!=
468 * 1. add to op to the simple expression
469 * 2. concatenate last field component to field path
470 * When encountering concatening ops .
471 * 1. concatenate last field component to field path
472 * When encountering opening parenthesis (,{,[
473 * 1. create a new subtree on top of tree stack
474 * When encountering closing parenthesis ),},]
475 * 1. add the expression on right child of the current tree
476 * 2. the subtree is completed, allocate a new subtree
477 * 3. pop the tree value from the tree stack
478 */
479
f4e9dd16 480 a_field_path = g_ptr_array_new();
481 g_ptr_array_set_size(a_field_path,2); /* by default, recording 2 field expressions */
482
18d1226f 483
a4c292d4 484 for(i=0;i<strlen(expression);i++) {
18d1226f 485// g_print("%s\n",a_field_component->str);
410c83da 486 g_print("%c ",expression[i]);
1601b365 487// g_print("switch:%c -->subtree:%p\n",expression[i],subtree);
a4c292d4 488 switch(expression[i]) {
489 /*
490 * logical operators
491 */
492 case '&': /* and */
5b729fcf 493 t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 494 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
18d1226f 495 t2 = lttv_filter_tree_new();
0cdc2470 496 t2->node = LTTV_LOGICAL_AND;
1601b365 497 if(subtree != NULL) {
18d1226f 498 t2->left = LTTV_TREE_NODE;
499 t2->l_child.t = subtree;
f4e9dd16 500 subtree = NULL;
18d1226f 501 t1->right = LTTV_TREE_NODE;
410c83da 502 t1->r_child.t = t2;
f4e9dd16 503 } else {
0cdc2470 504 a_simple_expression->value = a_field_component->str;
18d1226f 505 a_field_component = g_string_new("");
506 t2->left = LTTV_TREE_LEAF;
0cdc2470 507 t2->l_child.leaf = a_simple_expression;
2ea36caf 508 a_simple_expression = g_new(LttvSimpleExpression,1);
18d1226f 509 t1->right = LTTV_TREE_NODE;
410c83da 510 t1->r_child.t = t2;
f4e9dd16 511 }
512
513 break;
a4c292d4 514 case '|': /* or */
2ea36caf 515 t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 516 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
1601b365 517 t2 = lttv_filter_tree_new();
0cdc2470 518 t2->node = LTTV_LOGICAL_OR;
1601b365 519 if(subtree != NULL) {
520 t2->left = LTTV_TREE_NODE;
521 t2->l_child.t = subtree;
522 subtree = NULL;
523 t1->right = LTTV_TREE_NODE;
524 t1->r_child.t = t2;
525 } else {
0cdc2470 526 a_simple_expression->value = a_field_component->str;
1601b365 527 a_field_component = g_string_new("");
528 t2->left = LTTV_TREE_LEAF;
0cdc2470 529 t2->l_child.leaf = a_simple_expression;
2ea36caf 530 a_simple_expression = g_new(LttvSimpleExpression,1);
1601b365 531 t1->right = LTTV_TREE_NODE;
532 t1->r_child.t = t2;
533 }
f4e9dd16 534 break;
a4c292d4 535 case '^': /* xor */
2ea36caf 536 t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 537 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
1601b365 538 t2 = lttv_filter_tree_new();
0cdc2470 539 t2->node = LTTV_LOGICAL_XOR;
1601b365 540 if(subtree != NULL) {
541 t2->left = LTTV_TREE_NODE;
542 t2->l_child.t = subtree;
543 subtree = NULL;
544 t1->right = LTTV_TREE_NODE;
545 t1->r_child.t = t2;
546 } else {
0cdc2470 547 a_simple_expression->value = a_field_component->str;
1601b365 548 a_field_component = g_string_new("");
549 t2->left = LTTV_TREE_LEAF;
0cdc2470 550 t2->l_child.leaf = a_simple_expression;
2ea36caf 551 a_simple_expression = g_new(LttvSimpleExpression,1);
1601b365 552 t1->right = LTTV_TREE_NODE;
553 t1->r_child.t = t2;
554 }
a4c292d4 555 break;
556 case '!': /* not, or not equal (math op) */
557 if(expression[i+1] == '=') { /* != */
0cdc2470 558 a_simple_expression->op = LTTV_FIELD_NE;
a4c292d4 559 i++;
0cdc2470 560 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
561 a_field_component = g_string_new("");
a4c292d4 562 } else { /* ! */
1601b365 563 // g_print("%s\n",a_field_component);
564 // a_field_component = g_string_new("");
2ea36caf 565 t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 566 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
1601b365 567 t2 = lttv_filter_tree_new();
0cdc2470 568 t2->node = LTTV_LOGICAL_NOT;
1601b365 569 t1->right = LTTV_TREE_NODE;
570 t1->r_child.t = t2;
a4c292d4 571 }
572 break;
573 case '(': /* start of parenthesis */
91ad3f0a 574 case '[':
575 case '{':
576 p_nesting++; /* incrementing parenthesis nesting value */
1601b365 577 t1 = lttv_filter_tree_new();
578 g_ptr_array_add( tree_stack,(gpointer) t1 );
a4c292d4 579 break;
580 case ')': /* end of parenthesis */
91ad3f0a 581 case ']':
582 case '}':
583 p_nesting--; /* decrementing parenthesis nesting value */
18d1226f 584 if(p_nesting<0 || tree_stack->len<2) {
f4e9dd16 585 g_warning("Wrong filtering options, the string\n\"%s\"\n\
586 is not valid due to parenthesis incorrect use",expression);
587 return NULL;
588 }
18d1226f 589
590 g_assert(tree_stack->len>0);
591 if(subtree != NULL) {
592 t1 = g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 593 while(t1->right != LTTV_TREE_IDLE && t1->right != LTTV_TREE_LEAF) {
18d1226f 594 g_assert(t1!=NULL && t1->r_child.t != NULL);
595 t1 = t1->r_child.t;
596 }
597 t1->right = LTTV_TREE_NODE;
598 t1->r_child.t = subtree;
599 subtree = g_ptr_array_index(tree_stack,tree_stack->len-1);
600 g_ptr_array_remove_index(tree_stack,tree_stack->len-1);
601 } else {
0cdc2470 602 a_simple_expression->value = a_field_component->str;
18d1226f 603 a_field_component = g_string_new("");
604 t1 = g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 605 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
18d1226f 606 t1->right = LTTV_TREE_LEAF;
0cdc2470 607 t1->r_child.leaf = a_simple_expression;
2ea36caf 608 a_simple_expression = g_new(LttvSimpleExpression,1);
18d1226f 609 subtree = g_ptr_array_index(tree_stack,tree_stack->len-1);
1601b365 610 g_assert(subtree != NULL);
18d1226f 611 g_ptr_array_remove_index(tree_stack,tree_stack->len-1);
612 }
a4c292d4 613 break;
614
615 /*
616 * mathematic operators
617 */
618 case '<': /* lower, lower or equal */
619 if(expression[i+1] == '=') { /* <= */
620 i++;
0cdc2470 621 a_simple_expression->op = LTTV_FIELD_LE;
622 } else a_simple_expression->op = LTTV_FIELD_LT;
f4e9dd16 623 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
624 a_field_component = g_string_new("");
a4c292d4 625 break;
626 case '>': /* higher, higher or equal */
627 if(expression[i+1] == '=') { /* >= */
628 i++;
0cdc2470 629 a_simple_expression->op = LTTV_FIELD_GE;
630 } else a_simple_expression->op = LTTV_FIELD_GT;
f4e9dd16 631 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
632 a_field_component = g_string_new("");
a4c292d4 633 break;
634 case '=': /* equal */
0cdc2470 635 a_simple_expression->op = LTTV_FIELD_EQ;
f4e9dd16 636 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
637 a_field_component = g_string_new("");
a4c292d4 638 break;
0769c82f 639 /*
640 * Field concatening caracter
641 */
642 case '.': /* dot */
f4e9dd16 643 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
0769c82f 644 a_field_component = g_string_new("");
645 break;
a4c292d4 646 default: /* concatening current string */
1a7fa682 647 g_string_append_c(a_field_component,expression[i]);
a4c292d4 648 }
649 }
1601b365 650
651 g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree,tree,t1,t2);
0cdc2470 652 g_print("stack size: %i\n",tree_stack->len);
653
654 /*
655 * Preliminary check to see
656 * if tree was constructed correctly
657 */
658 if( p_nesting>0 ) {
659 g_warning("Wrong filtering options, the string\n\"%s\"\n\
660 is not valid due to parenthesis incorrect use",expression);
661 return NULL;
662 }
663
664 if(tree_stack->len != 1) /* only root tree should remain */
665 return NULL;
1601b365 666
410c83da 667 /* processing last element of expression */
410c83da 668 t1 = g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 669 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
410c83da 670 if(subtree != NULL) { /* add the subtree */
671 t1->right = LTTV_TREE_NODE;
0cdc2470 672 t1->r_child.t = subtree;
410c83da 673 subtree = NULL;
674 } else { /* add a leaf */
0cdc2470 675 a_simple_expression->value = a_field_component->str;
410c83da 676 a_field_component = g_string_new("");
677 t1->right = LTTV_TREE_LEAF;
0cdc2470 678 t1->r_child.leaf = a_simple_expression;
2ea36caf 679 /*
680 * FIXME: is it really necessary to reallocate
681 * LttvSimpleExpression at this point ??
682 */
683 a_simple_expression = g_new(LttvSimpleExpression,1);
410c83da 684 }
685
686 g_assert(tree != NULL);
687 g_assert(subtree == NULL);
a4c292d4 688
1601b365 689 lttv_filter_tracefile(tree,NULL);
690
410c83da 691 return tree;
692
31452f49 693}
694
1da1525d 695void
2ea36caf 696lttv_filter_destroy(LttvFilter* filter) {
1da1525d 697
698}
699
150f0d33 700/**
701 * Assign a new tree for the current expression
702 * or sub expression
703 * @return pointer of LttvFilterTree
704 */
705LttvFilterTree* lttv_filter_tree_new() {
706 LttvFilterTree* tree;
707
708 tree = g_new(LttvFilter,1);
709 tree->node = 0; //g_new(lttv_expression,1);
710// tree->node->type = LTTV_UNDEFINED_EXPRESSION;
711 tree->left = LTTV_TREE_IDLE;
712 tree->right = LTTV_TREE_IDLE;
713
714 return tree;
715}
716
717/**
718 * Destroys the tree and his sub-trees
719 * @param tree Tree which must be destroyed
720 */
721void lttv_filter_tree_destroy(LttvFilterTree* tree) {
722
723 if(tree == NULL) return;
724
725 if(tree->left == LTTV_TREE_LEAF) g_free(tree->l_child.leaf);
726 else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t);
727
728 if(tree->right == LTTV_TREE_LEAF) g_free(tree->r_child.leaf);
729 else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t);
730
731 g_free(tree->node);
732 g_free(tree);
733}
734
735
84a333d6 736/**
737 * Apply the filter to a specific trace
738 * @param filter the current filter applied
739 * @param tracefile the trace to apply the filter to
740 * @return success/failure of operation
741 */
31452f49 742gboolean
2ea36caf 743lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile) {
0769c82f 744
5b729fcf 745 LttvFilterTree* t = filter->head;
746
1601b365 747 /*
748 * Each tree is parsed in inorder.
749 * This way, it's possible to apply the left filter of the
750 * tree, then decide whether or not the right branch should
751 * be parsed depending on the linking logical operator
752 *
753 * As for the filtering structure, since we are trying
754 * to remove elements from the trace, it might be better
755 * managing an array of all items to be removed ..
756 */
0769c82f 757
5b729fcf 758 g_print("node:%p lchild:%p rchild:%p\n",t,t->l_child.t,t->r_child.t);
759 g_print("node type%i\n",t->node);
760 if(t->left == LTTV_TREE_NODE) lttv_filter_tracefile(t->l_child.t,NULL);
761 else if(t->left == LTTV_TREE_LEAF) {
762 g_assert(t->l_child.leaf->value != NULL);
763 g_print("%p: left is qqch %i %s\n",t,t->l_child.leaf->op,t->l_child.leaf->value);
0cdc2470 764 }
5b729fcf 765 if(t->right == LTTV_TREE_NODE) lttv_filter_tracefile(t->r_child.t,NULL);
766 else if(t->right == LTTV_TREE_LEAF) {
767 g_assert(t->r_child.leaf->value != NULL);
768 g_print("%p: right is qqch %i %s\n",t,t->r_child.leaf->op,t->r_child.leaf->value);
0cdc2470 769 }
0769c82f 770
771 /* test */
772/* int i, nb;
773 char *f_name, *e_name;
31452f49 774
0769c82f 775 char* field = "cpu";
776
777 LttvTraceHook h;
778
779 LttEventType *et;
780
781 LttType *t;
782
783 GString *fe_name = g_string_new("");
784
785 nb = ltt_trace_eventtype_number(tcs->parent.t);
786 g_print("NB:%i\n",nb);
787 for(i = 0 ; i < nb ; i++) {
788 et = ltt_trace_eventtype_get(tcs->parent.t, i);
789 e_name = ltt_eventtype_name(et);
790 f_name = ltt_facility_name(ltt_eventtype_facility(et));
791 g_string_printf(fe_name, "%s.%s", f_name, e_name);
792 g_print("facility:%s and event:%s\n",f_name,e_name);
793 }
794 */
31452f49 795}
796
1a7fa682 797gboolean
2ea36caf 798lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate) {
341aa948 799
800}
1a7fa682 801
84a333d6 802/**
803 * Apply the filter to a specific event
804 * @param filter the current filter applied
805 * @param event the event to apply the filter to
806 * @return success/failure of operation
807 */
31452f49 808gboolean
2ea36caf 809lttv_filter_event(LttvFilter *filter, LttEvent *event) {
31452f49 810
811}
1a7fa682 812
91ad3f0a 813/**
814 * Initializes the filter module and specific values
815 */
1a7fa682 816static void module_init()
817{
91ad3f0a 818
819 /*
820 * Quarks initialization
821 * for hardcoded filtering options
822 *
823 * TODO: traceset has no yet been defined
824 */
825
826 /* top fields */
5b729fcf 827// LTTV_FILTER_EVENT = g_quark_from_string("event");
828// LTTV_FILTER_TRACE = g_quark_from_string("trace");
829// LTTV_FILTER_TRACESET = g_quark_from_string("traceset");
830// LTTV_FILTER_STATE = g_quark_from_string("state");
831// LTTV_FILTER_TRACEFILE = g_quark_from_string("tracefile");
1a7fa682 832
91ad3f0a 833 /* event.name, tracefile.name, trace.name */
5b729fcf 834// LTTV_FILTER_NAME = g_quark_from_string("name");
91ad3f0a 835
836 /* event sub fields */
5b729fcf 837// LTTV_FILTER_CATEGORY = g_quark_from_string("category");
838// LTTV_FILTER_TIME = g_quark_from_string("time");
839// LTTV_FILTER_TSC = g_quark_from_string("tsc");
91ad3f0a 840
841 /* state sub fields */
5b729fcf 842// LTTV_FILTER_PID = g_quark_from_string("pid");
843// LTTV_FILTER_PPID = g_quark_from_string("ppid");
844// LTTV_FILTER_C_TIME = g_quark_from_string("creation_time");
845// LTTV_FILTER_I_TIME = g_quark_from_string("insertion_time");
846// LTTV_FILTER_P_NAME = g_quark_from_string("process_name");
847// LTTV_FILTER_EX_MODE = g_quark_from_string("execution_mode");
848// LTTV_FILTER_EX_SUBMODE = g_quark_from_string("execution_submode");
849// LTTV_FILTER_P_STATUS = g_quark_from_string("process_status");
850// LTTV_FILTER_CPU = g_quark_from_string("cpu");
91ad3f0a 851
1a7fa682 852}
853
91ad3f0a 854/**
855 * Destroys the filter module and specific values
856 */
1a7fa682 857static void module_destroy()
858{
859}
860
861
91ad3f0a 862LTTV_MODULE("filter", "Filters traceset and events", \
863 "Filters traceset and events specifically to user input", \
1a7fa682 864 module_init, module_destroy)
865
866
867
This page took 0.069268 seconds and 4 git commands to generate.