1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2005 Michel Dagenais
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;
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.
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,
24 simple expr [ op expr ]
26 read_simple_expression
27 read_field_path [ rel value ]
30 read_field_component [. field path]
39 path(component...) -> field
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.
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 * * clear the field_path array after use
60 #include <lttv/filter.h>
66 LTTV_FILTER_TRACEFILE,
79 LTTV_FILTER_EX_SUBMODE,
85 * Constructor for LttvSimpleExpression
86 * @return pointer to new LttvSimpleExpression
89 lttv_simple_expression_new() {
91 LttvSimpleExpression
* se
= g_new(LttvSimpleExpression
,1);
93 se
->field
= LTTV_FILTER_UNDEFINED
;
100 * add a node to the current tree
101 * @param stack the tree stack
102 * @param subtree the subtree if available (pointer or NULL)
103 * @param op the logical operator that will form the node
106 lttv_filter_tree_add_node(GPtrArray
* stack
, LttvFilterTree
* subtree
, LttvLogicalOp op
) {
108 LttvFilterTree
* t1
= NULL
;
109 LttvFilterTree
* t2
= NULL
;
111 t1
= (LttvFilterTree
*)g_ptr_array_index(stack
,stack
->len
-1);
112 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
113 t2
= lttv_filter_tree_new();
115 if(subtree
!= NULL
) {
116 t2
->left
= LTTV_TREE_NODE
;
117 t2
->l_child
.t
= subtree
;
119 t1
->right
= LTTV_TREE_NODE
;
122 // a_simple_expression->value = a_field_component->str;
123 // a_field_component = g_string_new("");
124 t2
->left
= LTTV_TREE_LEAF
;
125 // t2->l_child.leaf = a_simple_expression;
126 // a_simple_expression = g_new(lttv_simple_expression,1);
127 t1
->right
= LTTV_TREE_NODE
;
134 * Parse through filtering field hierarchy as specified
135 * by user. This function compares each value to
136 * predetermined quarks
137 * @param fp The field path list
138 * @return success/failure of operation
141 parse_field_path(GPtrArray
* fp
, LttvSimpleExpression
* se
) {
144 if(fp
->len
< 2) return FALSE
;
145 g_assert(f
=g_ptr_array_index(fp
,0)); //list_first(fp)->data;
148 * Parse through the specified
151 * Take note however that the
152 * 'event' subfields might change
153 * depending on values specified
154 * in core.xml file. Hence, if
155 * none of the subfields in the
156 * array match the hardcoded
157 * subfields, it will be considered
160 if(g_strcasecmp(f
->str
,"trace") ) {
165 f
=g_ptr_array_index(fp
,1);
166 if(g_strcasecmp(f
->str
,"name")) {
167 se
->field
= LTTV_FILTER_TRACE_NAME
;
170 } else if(g_strcasecmp(f
->str
,"traceset") ) {
172 * FIXME: not yet implemented !
174 } else if(g_strcasecmp(f
->str
,"tracefile") ) {
179 f
=g_ptr_array_index(fp
,1);
180 if(g_strcasecmp(f
->str
,"name")) {
181 se
->field
= LTTV_FILTER_TRACEFILE_NAME
;
184 } else if(g_strcasecmp(f
->str
,"state") ) {
189 * state.creation_time
190 * state.insertion_time
192 * state.execution_mode
193 * state.execution_submode
194 * state.process_status
197 f
=g_ptr_array_index(fp
,1);
198 if(g_strcasecmp(f
->str
,"pid") ) {
199 se
->field
= LTTV_FILTER_STATE_PID
;
201 else if(g_strcasecmp(f
->str
,"ppid") ) {
202 se
->field
= LTTV_FILTER_STATE_PPID
;
204 else if(g_strcasecmp(f
->str
,"creation_time") ) {
205 se
->field
= LTTV_FILTER_STATE_CT
;
207 else if(g_strcasecmp(f
->str
,"insertion_time") ) {
208 se
->field
= LTTV_FILTER_STATE_IT
;
210 else if(g_strcasecmp(f
->str
,"process_name") ) {
211 se
->field
= LTTV_FILTER_STATE_P_NAME
;
213 else if(g_strcasecmp(f
->str
,"execution_mode") ) {
214 se
->field
= LTTV_FILTER_STATE_EX_MODE
;
216 else if(g_strcasecmp(f
->str
,"execution_submode") ) {
217 se
->field
= LTTV_FILTER_STATE_EX_SUBMODE
;
219 else if(g_strcasecmp(f
->str
,"process_status") ) {
220 se
->field
= LTTV_FILTER_STATE_P_STATUS
;
222 else if(g_strcasecmp(f
->str
,"cpu") ) {
223 se
->field
= LTTV_FILTER_STATE_CPU
;
226 } else if(g_strcasecmp(f
->str
,"event") ) {
234 f
=g_ptr_array_index(fp
,1);
235 if(g_strcasecmp(f
->str
,"name") ) {
236 se
->field
= LTTV_FILTER_EVENT_NAME
;
238 else if(g_strcasecmp(f
->str
,"category") ) {
240 * FIXME: Category not yet functional in lttv
242 se
->field
= LTTV_FILTER_EVENT_CATEGORY
;
244 else if(g_strcasecmp(f
->str
,"time") ) {
245 se
->field
= LTTV_FILTER_EVENT_TIME
;
246 // offset = &((LttEvent*)NULL)->event_time);
248 else if(g_strcasecmp(f
->str
,"tsc") ) {
249 se
->field
= LTTV_FILTER_EVENT_TSC
;
250 // offset = &((LttEvent*)NULL)->event_cycle_count);
252 else { /* core.xml specified options */
253 se
->field
= LTTV_FILTER_EVENT_FIELD
;
254 //se->offset = (...);
257 g_warning("Unrecognized field in filter string");
265 * Add an filtering option to the current tree
266 * @param expression Current expression to parse
267 * @return success/failure of operation
270 parse_simple_expression(GString
* expression
) {
280 * Applies the 'equal' operator to the
281 * specified structure and value
282 * @param v1 left member of comparison
283 * @param v2 right member of comparison
284 * @return success/failure of operation
286 gboolean
lttv_apply_op_eq_uint64(guint64 v1
, guint64 v2
) {}
289 * Applies the 'equal' operator to the
290 * specified structure and value
291 * @param v1 left member of comparison
292 * @param v2 right member of comparison
293 * @return success/failure of operation
295 gboolean
lttv_apply_op_eq_uint32(guint32 v1
, guint32 v2
) {}
298 * Applies the 'equal' operator to the
299 * specified structure and value
300 * @param v1 left member of comparison
301 * @param v2 right member of comparison
302 * @return success/failure of operation
304 gboolean
lttv_apply_op_eq_uint16(guint16 v1
, guint16 v2
) {}
307 * Applies the 'equal' operator to the
308 * specified structure and value
309 * @param v1 left member of comparison
310 * @param v2 right member of comparison
311 * @return success/failure of operation
313 gboolean
lttv_apply_op_eq_double(double v1
, double v2
) {}
316 * Applies the 'equal' operator to the
317 * specified structure and value
318 * @param v1 left member of comparison
319 * @param v2 right member of comparison
320 * @return success/failure of operation
322 gboolean
lttv_apply_op_eq_string(char* v1
, char* v2
) {}
325 * Applies the 'not equal' operator to the
326 * specified structure and value
327 * @param v1 left member of comparison
328 * @param v2 right member of comparison
329 * @return success/failure of operation
331 gboolean
lttv_apply_op_ne_uint64(guint64 v1
, guint64 v2
) {}
334 * Applies the 'not equal' operator to the
335 * specified structure and value
336 * @param v1 left member of comparison
337 * @param v2 right member of comparison
338 * @return success/failure of operation
340 gboolean
lttv_apply_op_ne_uint32(guint32 v1
, guint32 v2
) {}
343 * Applies the 'not equal' operator to the
344 * specified structure and value
345 * @param v1 left member of comparison
346 * @param v2 right member of comparison
347 * @return success/failure of operation
349 gboolean
lttv_apply_op_ne_uint16(guint16 v1
, guint16 v2
) {}
352 * Applies the 'not equal' operator to the
353 * specified structure and value
354 * @param v1 left member of comparison
355 * @param v2 right member of comparison
356 * @return success/failure of operation
358 gboolean
lttv_apply_op_ne_double(double v1
, double v2
) {}
361 * Applies the 'not equal' operator to the
362 * specified structure and value
363 * @param v1 left member of comparison
364 * @param v2 right member of comparison
365 * @return success/failure of operation
367 gboolean
lttv_apply_op_ne_string(char* v1
, char* v2
) {}
370 * Applies the 'lower than' operator to the
371 * specified structure and value
372 * @param v1 left member of comparison
373 * @param v2 right member of comparison
374 * @return success/failure of operation
376 gboolean
lttv_apply_op_lt_uint64(guint64 v1
, guint64 v2
) {}
379 * Applies the 'lower than' operator to the
380 * specified structure and value
381 * @param v1 left member of comparison
382 * @param v2 right member of comparison
383 * @return success/failure of operation
385 gboolean
lttv_apply_op_lt_uint32(guint32 v1
, guint32 v2
) {}
388 * Applies the 'lower than' operator to the
389 * specified structure and value
390 * @param v1 left member of comparison
391 * @param v2 right member of comparison
392 * @return success/failure of operation
394 gboolean
lttv_apply_op_lt_uint16(guint16 v1
, guint16 v2
) {}
397 * Applies the 'lower than' operator to the
398 * specified structure and value
399 * @param v1 left member of comparison
400 * @param v2 right member of comparison
401 * @return success/failure of operation
403 gboolean
lttv_apply_op_lt_double(double v1
, double v2
) {}
406 * Applies the 'lower than' operator to the
407 * specified structure and value
408 * @param v1 left member of comparison
409 * @param v2 right member of comparison
410 * @return success/failure of operation
412 gboolean
lttv_apply_op_le_uint64(guint64 v1
, guint64 v2
) {}
415 * Applies the 'lower or equal' operator to the
416 * specified structure and value
417 * @param v1 left member of comparison
418 * @param v2 right member of comparison
419 * @return success/failure of operation
421 gboolean
lttv_apply_op_le_uint32(guint32 v1
, guint32 v2
) {}
424 * Applies the 'lower or equal' operator to the
425 * specified structure and value
426 * @param v1 left member of comparison
427 * @param v2 right member of comparison
428 * @return success/failure of operation
430 gboolean
lttv_apply_op_le_uint16(guint16 v1
, guint16 v2
) {}
433 * Applies the 'lower or equal' operator to the
434 * specified structure and value
435 * @param v1 left member of comparison
436 * @param v2 right member of comparison
437 * @return success/failure of operation
439 gboolean
lttv_apply_op_le_double(double v1
, double v2
) {}
442 * Applies the 'lower or equal' operator to the
443 * specified structure and value
444 * @param v1 left member of comparison
445 * @param v2 right member of comparison
446 * @return success/failure of operation
448 gboolean
lttv_apply_op_gt_uint64(guint64 v1
, guint64 v2
) {}
451 * Applies the 'greater than' operator to the
452 * specified structure and value
453 * @param v1 left member of comparison
454 * @param v2 right member of comparison
455 * @return success/failure of operation
457 gboolean
lttv_apply_op_gt_uint32(guint32 v1
, guint32 v2
) {}
460 * Applies the 'greater than' operator to the
461 * specified structure and value
462 * @param v1 left member of comparison
463 * @param v2 right member of comparison
464 * @return success/failure of operation
466 gboolean
lttv_apply_op_gt_uint16(guint16 v1
, guint16 v2
) {}
469 * Applies the 'greater than' operator to the
470 * specified structure and value
471 * @param v1 left member of comparison
472 * @param v2 right member of comparison
473 * @return success/failure of operation
475 gboolean
lttv_apply_op_gt_double(double v1
, double v2
) {}
478 * Applies the 'greater than' operator to the
479 * specified structure and value
480 * @param v1 left member of comparison
481 * @param v2 right member of comparison
482 * @return success/failure of operation
484 gboolean
lttv_apply_op_ge_uint64(guint64 v1
, guint64 v2
) {}
487 * Applies the 'greater or equal' operator to the
488 * specified structure and value
489 * @param v1 left member of comparison
490 * @param v2 right member of comparison
491 * @return success/failure of operation
493 gboolean
lttv_apply_op_ge_uint32(guint32 v1
, guint32 v2
) {}
496 * Applies the 'greater or equal' operator to the
497 * specified structure and value
498 * @param v1 left member of comparison
499 * @param v2 right member of comparison
500 * @return success/failure of operation
502 gboolean
lttv_apply_op_ge_uint16(guint16 v1
, guint16 v2
) {}
505 * Applies the 'greater or equal' operator to the
506 * specified structure and value
507 * @param v1 left member of comparison
508 * @param v2 right member of comparison
509 * @return success/failure of operation
511 gboolean
lttv_apply_op_ge_double(double v1
, double v2
) {}
515 * Makes a copy of the current filter tree
516 * @param tree pointer to the current tree
517 * @return new copy of the filter tree
520 lttv_filter_tree_clone(LttvFilterTree
* tree
) {
527 * Makes a copy of the current filter
528 * @param filter pointer to the current filter
529 * @return new copy of the filter
532 lttv_filter_clone(LttvFilter
* filter
) {
535 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
537 // newfilter->expression = g_new(char,1)
538 strcpy(newfilter
->expression
,filter
->expression
);
540 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
548 * Creates a new lttv_filter
549 * @param expression filtering options string
550 * @param t pointer to the current LttvTrace
551 * @return the current lttv_filter or NULL if error
554 lttv_filter_new(char *expression
, LttvTraceState
*tcs
) {
556 g_print("filter::lttv_filter_new()\n"); /* debug */
560 p_nesting
=0, /* parenthesis nesting value */
561 b
=0; /* current breakpoint in expression string */
565 *tree
= lttv_filter_tree_new(), /* main tree */
566 *subtree
= NULL
, /* buffer for subtrees */
572 * each element of the list
573 * is a sub tree created
574 * by the use of parenthesis in the
575 * global expression. The final tree
576 * will be the one left at the root of
579 GPtrArray
*tree_stack
= g_ptr_array_new();
580 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
582 /* temporary values */
583 GString
*a_field_component
= g_string_new("");
584 GPtrArray
*a_field_path
= NULL
;
586 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
589 * Parse entire expression and construct
590 * the binary tree. There are two steps
591 * in browsing that string
592 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
593 * 2. finding simple expressions
594 * - field path ( separated by dots )
595 * - op ( >, <, =, >=, <=, !=)
596 * - value ( integer, string ... )
597 * To spare computing time, the whole
598 * string is parsed in this loop for a
599 * O(n) complexity order.
601 * When encountering logical op &,|,^
602 * 1. parse the last value if any
603 * 2. create a new tree
604 * 3. add the expression (simple exp, or exp (subtree)) to the tree
605 * 4. concatenate this tree with the current tree on top of the stack
606 * When encountering math ops >,>=,<,<=,=,!=
607 * 1. add to op to the simple expression
608 * 2. concatenate last field component to field path
609 * When encountering concatening ops .
610 * 1. concatenate last field component to field path
611 * When encountering opening parenthesis (,{,[
612 * 1. create a new subtree on top of tree stack
613 * When encountering closing parenthesis ),},]
614 * 1. add the expression on right child of the current tree
615 * 2. the subtree is completed, allocate a new subtree
616 * 3. pop the tree value from the tree stack
619 a_field_path
= g_ptr_array_new();
620 g_ptr_array_set_size(a_field_path
,2); /* by default, recording 2 field expressions */
623 for(i
=0;i
<strlen(expression
);i
++) {
624 // g_print("%s\n",a_field_component->str);
625 g_print("%c ",expression
[i
]);
626 // g_print("switch:%c -->subtree:%p\n",expression[i],subtree);
627 switch(expression
[i
]) {
632 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
633 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
634 t2
= lttv_filter_tree_new();
635 t2
->node
= LTTV_LOGICAL_AND
;
636 if(subtree
!= NULL
) {
637 t2
->left
= LTTV_TREE_NODE
;
638 t2
->l_child
.t
= subtree
;
640 t1
->right
= LTTV_TREE_NODE
;
643 a_simple_expression
->value
= a_field_component
->str
;
644 a_field_component
= g_string_new("");
645 t2
->left
= LTTV_TREE_LEAF
;
646 t2
->l_child
.leaf
= a_simple_expression
;
647 a_simple_expression
= lttv_simple_expression_new();
648 t1
->right
= LTTV_TREE_NODE
;
654 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
655 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
656 t2
= lttv_filter_tree_new();
657 t2
->node
= LTTV_LOGICAL_OR
;
658 if(subtree
!= NULL
) {
659 t2
->left
= LTTV_TREE_NODE
;
660 t2
->l_child
.t
= subtree
;
662 t1
->right
= LTTV_TREE_NODE
;
665 a_simple_expression
->value
= a_field_component
->str
;
666 a_field_component
= g_string_new("");
667 t2
->left
= LTTV_TREE_LEAF
;
668 t2
->l_child
.leaf
= a_simple_expression
;
669 a_simple_expression
= lttv_simple_expression_new();
670 t1
->right
= LTTV_TREE_NODE
;
675 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
676 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
677 t2
= lttv_filter_tree_new();
678 t2
->node
= LTTV_LOGICAL_XOR
;
679 if(subtree
!= NULL
) {
680 t2
->left
= LTTV_TREE_NODE
;
681 t2
->l_child
.t
= subtree
;
683 t1
->right
= LTTV_TREE_NODE
;
686 a_simple_expression
->value
= a_field_component
->str
;
687 a_field_component
= g_string_new("");
688 t2
->left
= LTTV_TREE_LEAF
;
689 t2
->l_child
.leaf
= a_simple_expression
;
690 a_simple_expression
= lttv_simple_expression_new();
691 t1
->right
= LTTV_TREE_NODE
;
695 case '!': /* not, or not equal (math op) */
696 if(expression
[i
+1] == '=') { /* != */
697 a_simple_expression
->op
= LTTV_FIELD_NE
;
699 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
700 parse_field_path(a_field_path
,a_simple_expression
);
701 a_field_component
= g_string_new("");
703 // g_print("%s\n",a_field_component);
704 // a_field_component = g_string_new("");
705 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
706 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
707 t2
= lttv_filter_tree_new();
708 t2
->node
= LTTV_LOGICAL_NOT
;
709 t1
->right
= LTTV_TREE_NODE
;
713 case '(': /* start of parenthesis */
716 p_nesting
++; /* incrementing parenthesis nesting value */
717 t1
= lttv_filter_tree_new();
718 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
720 case ')': /* end of parenthesis */
723 p_nesting
--; /* decrementing parenthesis nesting value */
724 if(p_nesting
<0 || tree_stack
->len
<2) {
725 g_warning("Wrong filtering options, the string\n\"%s\"\n\
726 is not valid due to parenthesis incorrect use",expression
);
730 g_assert(tree_stack
->len
>0);
731 if(subtree
!= NULL
) {
732 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
733 while(t1
->right
!= LTTV_TREE_IDLE
&& t1
->right
!= LTTV_TREE_LEAF
) {
734 g_assert(t1
!=NULL
&& t1
->r_child
.t
!= NULL
);
737 t1
->right
= LTTV_TREE_NODE
;
738 t1
->r_child
.t
= subtree
;
739 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
740 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
742 a_simple_expression
->value
= a_field_component
->str
;
743 a_field_component
= g_string_new("");
744 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
745 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
746 t1
->right
= LTTV_TREE_LEAF
;
747 t1
->r_child
.leaf
= a_simple_expression
;
748 a_simple_expression
= lttv_simple_expression_new();
749 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
750 g_assert(subtree
!= NULL
);
751 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
756 * mathematic operators
758 case '<': /* lower, lower or equal */
759 if(expression
[i
+1] == '=') { /* <= */
761 a_simple_expression
->op
= LTTV_FIELD_LE
;
762 } else a_simple_expression
->op
= LTTV_FIELD_LT
;
763 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
764 parse_field_path(a_field_path
,a_simple_expression
);
765 a_field_component
= g_string_new("");
767 case '>': /* higher, higher or equal */
768 if(expression
[i
+1] == '=') { /* >= */
770 a_simple_expression
->op
= LTTV_FIELD_GE
;
771 } else a_simple_expression
->op
= LTTV_FIELD_GT
;
772 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
773 parse_field_path(a_field_path
,a_simple_expression
);
774 a_field_component
= g_string_new("");
776 case '=': /* equal */
777 a_simple_expression
->op
= LTTV_FIELD_EQ
;
778 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
779 parse_field_path(a_field_path
,a_simple_expression
);
780 a_field_component
= g_string_new("");
783 * Field concatening caracter
786 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
787 a_field_component
= g_string_new("");
789 default: /* concatening current string */
790 g_string_append_c(a_field_component
,expression
[i
]);
794 g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree
,tree
,t1
,t2
);
795 g_print("stack size: %i\n",tree_stack
->len
);
798 * Preliminary check to see
799 * if tree was constructed correctly
802 g_warning("Wrong filtering options, the string\n\"%s\"\n\
803 is not valid due to parenthesis incorrect use",expression
);
807 if(tree_stack
->len
!= 1) /* only root tree should remain */
810 /* processing last element of expression */
811 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
812 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
813 if(subtree
!= NULL
) { /* add the subtree */
814 t1
->right
= LTTV_TREE_NODE
;
815 t1
->r_child
.t
= subtree
;
817 } else { /* add a leaf */
818 a_simple_expression
->value
= a_field_component
->str
;
819 a_field_component
= g_string_new("");
820 t1
->right
= LTTV_TREE_LEAF
;
821 t1
->r_child
.leaf
= a_simple_expression
;
823 * FIXME: is it really necessary to reallocate
824 * LttvSimpleExpression at this point ??
826 a_simple_expression
= lttv_simple_expression_new();
829 g_assert(tree
!= NULL
);
830 g_assert(subtree
== NULL
);
832 lttv_filter_tracefile(tree
,NULL
);
839 lttv_filter_destroy(LttvFilter
* filter
) {
844 * Assign a new tree for the current expression
846 * @return pointer of LttvFilterTree
848 LttvFilterTree
* lttv_filter_tree_new() {
849 LttvFilterTree
* tree
;
851 tree
= g_new(LttvFilter
,1);
852 tree
->node
= 0; //g_new(lttv_expression,1);
853 // tree->node->type = LTTV_UNDEFINED_EXPRESSION;
854 tree
->left
= LTTV_TREE_IDLE
;
855 tree
->right
= LTTV_TREE_IDLE
;
861 * Destroys the tree and his sub-trees
862 * @param tree Tree which must be destroyed
864 void lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
866 if(tree
== NULL
) return;
868 if(tree
->left
== LTTV_TREE_LEAF
) g_free(tree
->l_child
.leaf
);
869 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
871 if(tree
->right
== LTTV_TREE_LEAF
) g_free(tree
->r_child
.leaf
);
872 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
880 * Apply the filter to a specific trace
881 * @param filter the current filter applied
882 * @param tracefile the trace to apply the filter to
883 * @return success/failure of operation
886 lttv_filter_tracefile(LttvFilter
*filter
, LttTracefile
*tracefile
) {
888 LttvFilterTree
* t
= filter
->head
;
891 * Each tree is parsed in inorder.
892 * This way, it's possible to apply the left filter of the
893 * tree, then decide whether or not the right branch should
894 * be parsed depending on the linking logical operator
896 * As for the filtering structure, since we are trying
897 * to remove elements from the trace, it might be better
898 * managing an array of all items to be removed ..
901 g_print("node:%p lchild:%p rchild:%p\n",t
,t
->l_child
.t
,t
->r_child
.t
);
902 g_print("node type%i\n",t
->node
);
903 if(t
->left
== LTTV_TREE_NODE
) lttv_filter_tracefile(t
->l_child
.t
,NULL
);
904 else if(t
->left
== LTTV_TREE_LEAF
) {
905 g_assert(t
->l_child
.leaf
->value
!= NULL
);
906 g_print("%p: left is qqch %i %s\n",t
,t
->l_child
.leaf
->op
,t
->l_child
.leaf
->value
);
908 if(t
->right
== LTTV_TREE_NODE
) lttv_filter_tracefile(t
->r_child
.t
,NULL
);
909 else if(t
->right
== LTTV_TREE_LEAF
) {
910 g_assert(t
->r_child
.leaf
->value
!= NULL
);
911 g_print("%p: right is qqch %i %s\n",t
,t
->r_child
.leaf
->op
,t
->r_child
.leaf
->value
);
916 char *f_name, *e_name;
926 GString *fe_name = g_string_new("");
928 nb = ltt_trace_eventtype_number(tcs->parent.t);
929 g_print("NB:%i\n",nb);
930 for(i = 0 ; i < nb ; i++) {
931 et = ltt_trace_eventtype_get(tcs->parent.t, i);
932 e_name = ltt_eventtype_name(et);
933 f_name = ltt_facility_name(ltt_eventtype_facility(et));
934 g_string_printf(fe_name, "%s.%s", f_name, e_name);
935 g_print("facility:%s and event:%s\n",f_name,e_name);
941 lttv_filter_tracestate(LttvFilter
*filter
, LttvTraceState
*tracestate
) {
946 * Apply the filter to a specific event
947 * @param filter the current filter applied
948 * @param event the event to apply the filter to
949 * @return success/failure of operation
952 lttv_filter_event(LttvFilter
*filter
, LttEvent
*event
) {
957 * Initializes the filter module and specific values
959 static void module_init()
963 * Quarks initialization
964 * for hardcoded filtering options
966 * TODO: traceset has no yet been defined
970 // LTTV_FILTER_EVENT = g_quark_from_string("event");
971 // LTTV_FILTER_TRACE = g_quark_from_string("trace");
972 // LTTV_FILTER_TRACESET = g_quark_from_string("traceset");
973 // LTTV_FILTER_STATE = g_quark_from_string("state");
974 // LTTV_FILTER_TRACEFILE = g_quark_from_string("tracefile");
976 /* event.name, tracefile.name, trace.name */
977 // LTTV_FILTER_NAME = g_quark_from_string("name");
979 /* event sub fields */
980 // LTTV_FILTER_CATEGORY = g_quark_from_string("category");
981 // LTTV_FILTER_TIME = g_quark_from_string("time");
982 // LTTV_FILTER_TSC = g_quark_from_string("tsc");
984 /* state sub fields */
985 // LTTV_FILTER_PID = g_quark_from_string("pid");
986 // LTTV_FILTER_PPID = g_quark_from_string("ppid");
987 // LTTV_FILTER_C_TIME = g_quark_from_string("creation_time");
988 // LTTV_FILTER_I_TIME = g_quark_from_string("insertion_time");
989 // LTTV_FILTER_P_NAME = g_quark_from_string("process_name");
990 // LTTV_FILTER_EX_MODE = g_quark_from_string("execution_mode");
991 // LTTV_FILTER_EX_SUBMODE = g_quark_from_string("execution_submode");
992 // LTTV_FILTER_P_STATUS = g_quark_from_string("process_status");
993 // LTTV_FILTER_CPU = g_quark_from_string("cpu");
998 * Destroys the filter module and specific values
1000 static void module_destroy()
1005 LTTV_MODULE("filter", "Filters traceset and events", \
1006 "Filters traceset and events specifically to user input", \
1007 module_init
, module_destroy
)