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
;
101 * add a node to the current tree
102 * FIXME: Might be used to lower coding in lttv_filter_new switch expression
103 * @param stack the tree stack
104 * @param subtree the subtree if available (pointer or NULL)
105 * @param op the logical operator that will form the node
108 lttv_filter_tree_add_node(GPtrArray
* stack
, LttvFilterTree
* subtree
, LttvLogicalOp op
) {
110 LttvFilterTree
* t1
= NULL
;
111 LttvFilterTree
* t2
= NULL
;
113 t1
= (LttvFilterTree
*)g_ptr_array_index(stack
,stack
->len
-1);
114 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
115 t2
= lttv_filter_tree_new();
117 if(subtree
!= NULL
) {
118 t2
->left
= LTTV_TREE_NODE
;
119 t2
->l_child
.t
= subtree
;
121 t1
->right
= LTTV_TREE_NODE
;
124 // a_simple_expression->value = a_field_component->str;
125 // a_field_component = g_string_new("");
126 t2
->left
= LTTV_TREE_LEAF
;
127 // t2->l_child.leaf = a_simple_expression;
128 // a_simple_expression = g_new(lttv_simple_expression,1);
129 t1
->right
= LTTV_TREE_NODE
;
136 * Parse through filtering field hierarchy as specified
137 * by user. This function compares each value to
138 * predetermined quarks
139 * @param fp The field path list
140 * @param se current simple expression
141 * @return success/failure of operation
144 parse_field_path(GPtrArray
* fp
, LttvSimpleExpression
* se
) {
147 if(fp
->len
< 2) return FALSE
;
148 g_assert(f
=g_ptr_array_index(fp
,0)); //list_first(fp)->data;
151 * Parse through the specified
154 * Take note however that the
155 * 'event' subfields might change
156 * depending on values specified
157 * in core.xml file. Hence, if
158 * none of the subfields in the
159 * array match the hardcoded
160 * subfields, it will be considered
163 if(g_strcasecmp(f
->str
,"trace") ) {
168 f
=g_ptr_array_index(fp
,1);
169 if(g_strcasecmp(f
->str
,"name")) {
170 se
->field
= LTTV_FILTER_TRACE_NAME
;
173 } else if(g_strcasecmp(f
->str
,"traceset") ) {
175 * FIXME: not yet implemented !
177 } else if(g_strcasecmp(f
->str
,"tracefile") ) {
182 f
=g_ptr_array_index(fp
,1);
183 if(g_strcasecmp(f
->str
,"name")) {
184 se
->field
= LTTV_FILTER_TRACEFILE_NAME
;
187 } else if(g_strcasecmp(f
->str
,"state") ) {
192 * state.creation_time
193 * state.insertion_time
195 * state.execution_mode
196 * state.execution_submode
197 * state.process_status
200 f
=g_ptr_array_index(fp
,1);
201 if(g_strcasecmp(f
->str
,"pid") ) {
202 se
->field
= LTTV_FILTER_STATE_PID
;
204 else if(g_strcasecmp(f
->str
,"ppid") ) {
205 se
->field
= LTTV_FILTER_STATE_PPID
;
207 else if(g_strcasecmp(f
->str
,"creation_time") ) {
208 se
->field
= LTTV_FILTER_STATE_CT
;
210 else if(g_strcasecmp(f
->str
,"insertion_time") ) {
211 se
->field
= LTTV_FILTER_STATE_IT
;
213 else if(g_strcasecmp(f
->str
,"process_name") ) {
214 se
->field
= LTTV_FILTER_STATE_P_NAME
;
216 else if(g_strcasecmp(f
->str
,"execution_mode") ) {
217 se
->field
= LTTV_FILTER_STATE_EX_MODE
;
219 else if(g_strcasecmp(f
->str
,"execution_submode") ) {
220 se
->field
= LTTV_FILTER_STATE_EX_SUBMODE
;
222 else if(g_strcasecmp(f
->str
,"process_status") ) {
223 se
->field
= LTTV_FILTER_STATE_P_STATUS
;
225 else if(g_strcasecmp(f
->str
,"cpu") ) {
226 se
->field
= LTTV_FILTER_STATE_CPU
;
229 } else if(g_strcasecmp(f
->str
,"event") ) {
237 f
=g_ptr_array_index(fp
,1);
238 if(g_strcasecmp(f
->str
,"name") ) {
239 se
->field
= LTTV_FILTER_EVENT_NAME
;
241 else if(g_strcasecmp(f
->str
,"category") ) {
243 * FIXME: Category not yet functional in lttv
245 se
->field
= LTTV_FILTER_EVENT_CATEGORY
;
247 else if(g_strcasecmp(f
->str
,"time") ) {
248 se
->field
= LTTV_FILTER_EVENT_TIME
;
249 // offset = &((LttEvent*)NULL)->event_time);
251 else if(g_strcasecmp(f
->str
,"tsc") ) {
252 se
->field
= LTTV_FILTER_EVENT_TSC
;
253 // offset = &((LttEvent*)NULL)->event_cycle_count);
255 else { /* core.xml specified options */
256 se
->field
= LTTV_FILTER_EVENT_FIELD
;
257 //se->offset = (...);
260 g_warning("Unrecognized field in filter string");
264 /* free the pointer array */
265 g_ptr_array_free(fp
,FALSE
);
271 * Sets the function pointer for the current
273 * @param se current simple expression
274 * @return success/failure of operation
276 gboolean
assign_operator(LttvSimpleExpression
* se
, LttvExpressionOp op
) {
280 case LTTV_FILTER_TRACE_NAME
:
281 case LTTV_FILTER_TRACEFILE_NAME
:
282 case LTTV_FILTER_STATE_P_NAME
:
283 case LTTV_FILTER_EVENT_NAME
:
286 se
->op
= lttv_apply_op_eq_string
;
289 se
->op
= lttv_apply_op_eq_string
;
292 g_warning("Error encountered in operator assignment");
296 case LTTV_FILTER_STATE_PID
:
297 case LTTV_FILTER_STATE_PPID
:
298 case LTTV_FILTER_STATE_EX_MODE
:
299 case LTTV_FILTER_STATE_EX_SUBMODE
:
300 case LTTV_FILTER_STATE_P_STATUS
:
303 se
->op
= lttv_apply_op_eq_uint64
;
306 se
->op
= lttv_apply_op_ne_uint64
;
309 se
->op
= lttv_apply_op_lt_uint64
;
312 se
->op
= lttv_apply_op_le_uint64
;
315 se
->op
= lttv_apply_op_gt_uint64
;
318 se
->op
= lttv_apply_op_ge_uint64
;
321 g_warning("Error encountered in operator assignment");
325 case LTTV_FILTER_STATE_CT
:
326 case LTTV_FILTER_STATE_IT
:
327 case LTTV_FILTER_EVENT_TIME
:
328 case LTTV_FILTER_EVENT_TSC
:
331 se
->op
= lttv_apply_op_eq_double
;
334 se
->op
= lttv_apply_op_ne_double
;
337 se
->op
= lttv_apply_op_lt_double
;
340 se
->op
= lttv_apply_op_le_double
;
343 se
->op
= lttv_apply_op_gt_double
;
346 se
->op
= lttv_apply_op_ge_double
;
349 g_warning("Error encountered in operator assignment");
354 g_warning("Error encountered in operator assignment");
361 * Add an filtering option to the current tree
362 * @param expression Current expression to parse
363 * @return success/failure of operation
366 parse_simple_expression(GString
* expression
) {
376 * Append a new expression to the expression
377 * defined in the current filter
378 * @param filter pointer to the current LttvFilter
379 * @param expression string that must be appended
381 void lttv_filter_append_expression(LttvFilter
* filter
, char *expression
) {
383 if(expression
== NULL
) return;
385 filter
= lttv_filter_new();
386 filter
->expression
= expression
;
387 } else if(filter
->expression
== NULL
) {
388 filter
->expression
= expression
;
390 filter
->expression
= g_strconcat(filter
->expression
,"&",expression
);
393 lttv_filter_update(filter
);
398 * Clear the filter expression from the
399 * current filter and sets its pointer to NULL
400 * @param filter pointer to the current LttvFilter
402 void lttv_filter_clear_expression(LttvFilter
* filter
) {
404 if(filter
->expression
!= NULL
) {
405 g_free(filter
->expression
);
406 filter
->expression
= NULL
;
412 * Applies the 'equal' operator to the
413 * specified structure and value
414 * @param v1 left member of comparison
415 * @param v2 right member of comparison
416 * @return success/failure of operation
418 gboolean
lttv_apply_op_eq_uint64(gpointer v1
, char* v2
) {
420 guint64
* r
= (guint64
*) v1
;
421 guint64 l
= atoi(v2
);
427 * Applies the 'equal' operator to the
428 * specified structure and value
429 * @param v1 left member of comparison
430 * @param v2 right member of comparison
431 * @return success/failure of operation
433 gboolean
lttv_apply_op_eq_uint32(gpointer v1
, char* v2
) {
434 guint32
* r
= (guint32
*) v1
;
435 guint32 l
= atoi(v2
);
440 * Applies the 'equal' operator to the
441 * specified structure and value
442 * @param v1 left member of comparison
443 * @param v2 right member of comparison
444 * @return success/failure of operation
446 gboolean
lttv_apply_op_eq_uint16(gpointer v1
, char* v2
) {
447 guint16
* r
= (guint16
*) v1
;
448 guint16 l
= atoi(v2
);
453 * Applies the 'equal' operator to the
454 * specified structure and value
455 * @param v1 left member of comparison
456 * @param v2 right member of comparison
457 * @return success/failure of operation
459 gboolean
lttv_apply_op_eq_double(gpointer v1
, char* v2
) {
460 double* r
= (double*) v1
;
466 * Applies the 'equal' operator to the
467 * specified structure and value
468 * @param v1 left member of comparison
469 * @param v2 right member of comparison
470 * @return success/failure of operation
472 gboolean
lttv_apply_op_eq_string(gpointer v1
, char* v2
) {
473 char* r
= (char*) v1
;
474 return (g_strcasecmp(r
,v2
));
478 * Applies the 'not equal' 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_ne_uint64(gpointer v1
, char* v2
) {
485 guint64
* r
= (guint64
*) v1
;
486 guint64 l
= atoi(v2
);
491 * Applies the 'not equal' operator to the
492 * specified structure and value
493 * @param v1 left member of comparison
494 * @param v2 right member of comparison
495 * @return success/failure of operation
497 gboolean
lttv_apply_op_ne_uint32(gpointer v1
, char* v2
) {
498 guint32
* r
= (guint32
*) v1
;
499 guint32 l
= atoi(v2
);
504 * Applies the 'not equal' operator to the
505 * specified structure and value
506 * @param v1 left member of comparison
507 * @param v2 right member of comparison
508 * @return success/failure of operation
510 gboolean
lttv_apply_op_ne_uint16(gpointer v1
, char* v2
) {
511 guint16
* r
= (guint16
*) v1
;
512 guint16 l
= atoi(v2
);
517 * Applies the 'not equal' operator to the
518 * specified structure and value
519 * @param v1 left member of comparison
520 * @param v2 right member of comparison
521 * @return success/failure of operation
523 gboolean
lttv_apply_op_ne_double(gpointer v1
, char* v2
) {
524 double* r
= (double*) v1
;
530 * Applies the 'not equal' operator to the
531 * specified structure and value
532 * @param v1 left member of comparison
533 * @param v2 right member of comparison
534 * @return success/failure of operation
536 gboolean
lttv_apply_op_ne_string(gpointer v1
, char* v2
) {
537 char* r
= (char*) v1
;
538 return (!g_strcasecmp(r
,v2
));
542 * Applies the 'lower than' operator to the
543 * specified structure and value
544 * @param v1 left member of comparison
545 * @param v2 right member of comparison
546 * @return success/failure of operation
548 gboolean
lttv_apply_op_lt_uint64(gpointer v1
, char* v2
) {
549 guint64
* r
= (guint64
*) v1
;
550 guint64 l
= atoi(v2
);
555 * Applies the 'lower than' operator to the
556 * specified structure and value
557 * @param v1 left member of comparison
558 * @param v2 right member of comparison
559 * @return success/failure of operation
561 gboolean
lttv_apply_op_lt_uint32(gpointer v1
, char* v2
) {
562 guint32
* r
= (guint32
*) v1
;
563 guint32 l
= atoi(v2
);
568 * Applies the 'lower than' operator to the
569 * specified structure and value
570 * @param v1 left member of comparison
571 * @param v2 right member of comparison
572 * @return success/failure of operation
574 gboolean
lttv_apply_op_lt_uint16(gpointer v1
, char* v2
) {
575 guint16
* r
= (guint16
*) v1
;
576 guint16 l
= atoi(v2
);
581 * Applies the 'lower than' operator to the
582 * specified structure and value
583 * @param v1 left member of comparison
584 * @param v2 right member of comparison
585 * @return success/failure of operation
587 gboolean
lttv_apply_op_lt_double(gpointer v1
, char* v2
) {
588 double* r
= (double*) v1
;
594 * Applies the 'lower than' operator to the
595 * specified structure and value
596 * @param v1 left member of comparison
597 * @param v2 right member of comparison
598 * @return success/failure of operation
600 gboolean
lttv_apply_op_le_uint64(gpointer v1
, char* v2
) {
601 guint64
* r
= (guint64
*) v1
;
602 guint64 l
= atoi(v2
);
607 * Applies the 'lower or equal' operator to the
608 * specified structure and value
609 * @param v1 left member of comparison
610 * @param v2 right member of comparison
611 * @return success/failure of operation
613 gboolean
lttv_apply_op_le_uint32(gpointer v1
, char* v2
) {
614 guint32
* r
= (guint32
*) v1
;
615 guint32 l
= atoi(v2
);
620 * Applies the 'lower or equal' operator to the
621 * specified structure and value
622 * @param v1 left member of comparison
623 * @param v2 right member of comparison
624 * @return success/failure of operation
626 gboolean
lttv_apply_op_le_uint16(gpointer v1
, char* v2
) {
627 guint16
* r
= (guint16
*) v1
;
628 guint16 l
= atoi(v2
);
633 * Applies the 'lower or equal' operator to the
634 * specified structure and value
635 * @param v1 left member of comparison
636 * @param v2 right member of comparison
637 * @return success/failure of operation
639 gboolean
lttv_apply_op_le_double(gpointer v1
, char* v2
) {
640 double* r
= (double*) v1
;
646 * Applies the 'greater than' operator to the
647 * specified structure and value
648 * @param v1 left member of comparison
649 * @param v2 right member of comparison
650 * @return success/failure of operation
652 gboolean
lttv_apply_op_gt_uint64(gpointer v1
, char* v2
) {
653 guint64
* r
= (guint64
*) v1
;
654 guint64 l
= atoi(v2
);
659 * Applies the 'greater than' operator to the
660 * specified structure and value
661 * @param v1 left member of comparison
662 * @param v2 right member of comparison
663 * @return success/failure of operation
665 gboolean
lttv_apply_op_gt_uint32(gpointer v1
, char* v2
) {
666 guint32
* r
= (guint32
*) v1
;
667 guint32 l
= atoi(v2
);
672 * Applies the 'greater than' operator to the
673 * specified structure and value
674 * @param v1 left member of comparison
675 * @param v2 right member of comparison
676 * @return success/failure of operation
678 gboolean
lttv_apply_op_gt_uint16(gpointer v1
, char* v2
) {
679 guint16
* r
= (guint16
*) v1
;
680 guint16 l
= atoi(v2
);
685 * Applies the 'greater than' operator to the
686 * specified structure and value
687 * @param v1 left member of comparison
688 * @param v2 right member of comparison
689 * @return success/failure of operation
691 gboolean
lttv_apply_op_gt_double(gpointer v1
, char* v2
) {
692 double* r
= (double*) v1
;
698 * Applies the 'greater or equal' operator to the
699 * specified structure and value
700 * @param v1 left member of comparison
701 * @param v2 right member of comparison
702 * @return success/failure of operation
704 gboolean
lttv_apply_op_ge_uint64(gpointer v1
, char* v2
) {
705 guint64
* r
= (guint64
*) v1
;
706 guint64 l
= atoi(v2
);
711 * Applies the 'greater or equal' operator to the
712 * specified structure and value
713 * @param v1 left member of comparison
714 * @param v2 right member of comparison
715 * @return success/failure of operation
717 gboolean
lttv_apply_op_ge_uint32(gpointer v1
, char* v2
) {
718 guint32
* r
= (guint32
*) v1
;
719 guint32 l
= atoi(v2
);
724 * Applies the 'greater or equal' operator to the
725 * specified structure and value
726 * @param v1 left member of comparison
727 * @param v2 right member of comparison
728 * @return success/failure of operation
730 gboolean
lttv_apply_op_ge_uint16(gpointer v1
, char* v2
) {
731 guint16
* r
= (guint16
*) v1
;
732 guint16 l
= atoi(v2
);
737 * Applies the 'greater or equal' operator to the
738 * specified structure and value
739 * @param v1 left member of comparison
740 * @param v2 right member of comparison
741 * @return success/failure of operation
743 gboolean
lttv_apply_op_ge_double(gpointer v1
, char* v2
) {
744 double* r
= (double*) v1
;
751 * Makes a copy of the current filter tree
752 * @param tree pointer to the current tree
753 * @return new copy of the filter tree
756 lttv_filter_tree_clone(LttvFilterTree
* tree
) {
758 LttvFilterTree
* newtree
= lttv_filter_tree_new();
760 newtree
->node
= tree
->node
;
762 newtree
->left
= tree
->left
;
763 if(newtree
->left
== LTTV_TREE_NODE
) {
764 newtree
->l_child
.t
= lttv_filter_tree_clone(tree
->l_child
.t
);
765 } else if(newtree
->left
== LTTV_TREE_LEAF
) {
766 newtree
->l_child
.leaf
= lttv_simple_expression_new();
767 newtree
->l_child
.leaf
->field
= tree
->l_child
.leaf
->field
;
768 newtree
->l_child
.leaf
->offset
= tree
->l_child
.leaf
->offset
;
769 newtree
->l_child
.leaf
->op
= tree
->l_child
.leaf
->op
;
770 newtree
->l_child
.leaf
->value
= g_strconcat(tree
->l_child
.leaf
->value
);
773 newtree
->right
= tree
->right
;
774 if(newtree
->right
== LTTV_TREE_NODE
) {
775 newtree
->r_child
.t
= lttv_filter_tree_clone(tree
->r_child
.t
);
776 } else if(newtree
->right
== LTTV_TREE_LEAF
) {
777 newtree
->r_child
.leaf
= lttv_simple_expression_new();
778 newtree
->r_child
.leaf
->field
= tree
->r_child
.leaf
->field
;
779 newtree
->r_child
.leaf
->offset
= tree
->r_child
.leaf
->offset
;
780 newtree
->r_child
.leaf
->op
= tree
->r_child
.leaf
->op
;
781 newtree
->r_child
.leaf
->value
= g_strconcat(tree
->r_child
.leaf
->value
);
789 * Makes a copy of the current filter
790 * @param filter pointer to the current filter
791 * @return new copy of the filter
794 lttv_filter_clone(LttvFilter
* filter
) {
797 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
799 // newfilter->expression = g_new(char,1)
800 strcpy(newfilter
->expression
,filter
->expression
);
802 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
810 * Creates a new lttv_filter
811 * @param expression filtering options string
812 * @param t pointer to the current LttvTrace
813 * @return the current lttv_filter or NULL if error
818 LttvFilter
* filter
= g_new(LttvFilter
,1);
819 filter
->expression
= NULL
;
825 * Updates the current LttvFilter by building
826 * its tree based upon the expression string
827 * @param filter pointer to the current LttvFilter
828 * @return Failure/Success of operation
831 lttv_filter_update(LttvFilter
* filter
) {
833 g_print("filter::lttv_filter_new()\n"); /* debug */
835 if(filter
->expression
== NULL
) return FALSE
;
839 p_nesting
=0, /* parenthesis nesting value */
840 b
=0; /* current breakpoint in expression string */
844 *tree
= lttv_filter_tree_new(), /* main tree */
845 *subtree
= NULL
, /* buffer for subtrees */
851 * If the tree already exists,
852 * destroy it and build a new one
854 if(filter
->head
!= NULL
) lttv_filter_tree_destroy(filter
->head
);
859 * each element of the list
860 * is a sub tree created
861 * by the use of parenthesis in the
862 * global expression. The final tree
863 * will be the one left at the root of
866 GPtrArray
*tree_stack
= g_ptr_array_new();
867 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
869 /* temporary values */
870 GString
*a_field_component
= g_string_new("");
871 GPtrArray
*a_field_path
= NULL
;
873 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
876 * Parse entire expression and construct
877 * the binary tree. There are two steps
878 * in browsing that string
879 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
880 * 2. finding simple expressions
881 * - field path ( separated by dots )
882 * - op ( >, <, =, >=, <=, !=)
883 * - value ( integer, string ... )
884 * To spare computing time, the whole
885 * string is parsed in this loop for a
886 * O(n) complexity order.
888 * When encountering logical op &,|,^
889 * 1. parse the last value if any
890 * 2. create a new tree
891 * 3. add the expression (simple exp, or exp (subtree)) to the tree
892 * 4. concatenate this tree with the current tree on top of the stack
893 * When encountering math ops >,>=,<,<=,=,!=
894 * 1. add to op to the simple expression
895 * 2. concatenate last field component to field path
896 * When encountering concatening ops .
897 * 1. concatenate last field component to field path
898 * When encountering opening parenthesis (,{,[
899 * 1. create a new subtree on top of tree stack
900 * When encountering closing parenthesis ),},]
901 * 1. add the expression on right child of the current tree
902 * 2. the subtree is completed, allocate a new subtree
903 * 3. pop the tree value from the tree stack
906 a_field_path
= g_ptr_array_new();
907 g_ptr_array_set_size(a_field_path
,2); /* by default, recording 2 field expressions */
910 for(i
=0;i
<strlen(filter
->expression
);i
++) {
912 g_print("%c ",filter
->expression
[i
]);
913 switch(filter
->expression
[i
]) {
918 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
919 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
920 t2
= lttv_filter_tree_new();
921 t2
->node
= LTTV_LOGICAL_AND
;
922 if(subtree
!= NULL
) { /* append subtree to current tree */
923 t2
->left
= LTTV_TREE_NODE
;
924 t2
->l_child
.t
= subtree
;
926 t1
->right
= LTTV_TREE_NODE
;
928 } else { /* append a simple expression */
929 a_simple_expression
->value
= a_field_component
->str
;
930 a_field_component
= g_string_new("");
931 t2
->left
= LTTV_TREE_LEAF
;
932 t2
->l_child
.leaf
= a_simple_expression
;
933 a_simple_expression
= lttv_simple_expression_new();
934 t1
->right
= LTTV_TREE_NODE
;
940 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
941 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
942 t2
= lttv_filter_tree_new();
943 t2
->node
= LTTV_LOGICAL_OR
;
944 if(subtree
!= NULL
) { /* append subtree to current tree */
945 t2
->left
= LTTV_TREE_NODE
;
946 t2
->l_child
.t
= subtree
;
948 t1
->right
= LTTV_TREE_NODE
;
950 } else { /* append a simple expression */
951 a_simple_expression
->value
= a_field_component
->str
;
952 a_field_component
= g_string_new("");
953 t2
->left
= LTTV_TREE_LEAF
;
954 t2
->l_child
.leaf
= a_simple_expression
;
955 a_simple_expression
= lttv_simple_expression_new();
956 t1
->right
= LTTV_TREE_NODE
;
961 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
962 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
963 t2
= lttv_filter_tree_new();
964 t2
->node
= LTTV_LOGICAL_XOR
;
965 if(subtree
!= NULL
) { /* append subtree to current tree */
966 t2
->left
= LTTV_TREE_NODE
;
967 t2
->l_child
.t
= subtree
;
969 t1
->right
= LTTV_TREE_NODE
;
971 } else { /* append a simple expression */
972 a_simple_expression
->value
= a_field_component
->str
;
973 a_field_component
= g_string_new("");
974 t2
->left
= LTTV_TREE_LEAF
;
975 t2
->l_child
.leaf
= a_simple_expression
;
976 a_simple_expression
= lttv_simple_expression_new();
977 t1
->right
= LTTV_TREE_NODE
;
981 case '!': /* not, or not equal (math op) */
982 if(filter
->expression
[i
+1] == '=') { /* != */
983 assign_operator(a_simple_expression
,LTTV_FIELD_NE
);
985 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
986 parse_field_path(a_field_path
,a_simple_expression
);
987 a_field_component
= g_string_new("");
989 // g_print("%s\n",a_field_component);
990 // a_field_component = g_string_new("");
991 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
992 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
993 t2
= lttv_filter_tree_new();
994 t2
->node
= LTTV_LOGICAL_NOT
;
995 t1
->right
= LTTV_TREE_NODE
;
999 case '(': /* start of parenthesis */
1002 p_nesting
++; /* incrementing parenthesis nesting value */
1003 t1
= lttv_filter_tree_new();
1004 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
1006 case ')': /* end of parenthesis */
1009 p_nesting
--; /* decrementing parenthesis nesting value */
1010 if(p_nesting
<0 || tree_stack
->len
<2) {
1011 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1012 is not valid due to parenthesis incorrect use",filter
->expression
);
1016 g_assert(tree_stack
->len
>0);
1017 if(subtree
!= NULL
) { /* append subtree to current tree */
1018 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1019 while(t1
->right
!= LTTV_TREE_IDLE
&& t1
->right
!= LTTV_TREE_LEAF
) {
1020 g_assert(t1
!=NULL
&& t1
->r_child
.t
!= NULL
);
1023 t1
->right
= LTTV_TREE_NODE
;
1024 t1
->r_child
.t
= subtree
;
1025 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1026 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1027 } else { /* assign subtree as current tree */
1028 a_simple_expression
->value
= a_field_component
->str
;
1029 a_field_component
= g_string_new("");
1030 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1031 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
1032 t1
->right
= LTTV_TREE_LEAF
;
1033 t1
->r_child
.leaf
= a_simple_expression
;
1034 a_simple_expression
= lttv_simple_expression_new();
1035 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1036 g_assert(subtree
!= NULL
);
1037 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1042 * mathematic operators
1044 case '<': /* lower, lower or equal */
1045 if(filter
->expression
[i
+1] == '=') { /* <= */
1047 assign_operator(a_simple_expression
,LTTV_FIELD_LE
);
1048 } else assign_operator(a_simple_expression
,LTTV_FIELD_LT
);
1049 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1050 parse_field_path(a_field_path
,a_simple_expression
);
1051 a_field_component
= g_string_new("");
1053 case '>': /* higher, higher or equal */
1054 if(filter
->expression
[i
+1] == '=') { /* >= */
1056 assign_operator(a_simple_expression
,LTTV_FIELD_GE
);
1057 } else assign_operator(a_simple_expression
,LTTV_FIELD_GT
);
1058 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1059 parse_field_path(a_field_path
,a_simple_expression
);
1060 a_field_component
= g_string_new("");
1062 case '=': /* equal */
1063 assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1064 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1065 parse_field_path(a_field_path
,a_simple_expression
);
1066 a_field_component
= g_string_new("");
1069 * Field concatening caracter
1073 * divide field expression into elements
1074 * in a_field_path array.
1076 if(a_simple_expression
->op
!= NULL
) {
1077 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1078 a_field_component
= g_string_new("");
1081 default: /* concatening current string */
1082 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1086 g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree
,tree
,t1
,t2
);
1087 g_print("stack size: %i\n",tree_stack
->len
);
1090 * Preliminary check to see
1091 * if tree was constructed correctly
1094 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1095 is not valid due to parenthesis incorrect use",filter
->expression
);
1099 if(tree_stack
->len
!= 1) /* only root tree should remain */
1102 /* processing last element of expression */
1103 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1104 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
1105 if(subtree
!= NULL
) { /* add the subtree */
1106 t1
->right
= LTTV_TREE_NODE
;
1107 t1
->r_child
.t
= subtree
;
1109 } else { /* add a leaf */
1110 a_simple_expression
->value
= a_field_component
->str
;
1111 a_field_component
= g_string_new("");
1112 t1
->right
= LTTV_TREE_LEAF
;
1113 t1
->r_child
.leaf
= a_simple_expression
;
1115 * FIXME: is it really necessary to reallocate
1116 * LttvSimpleExpression at this point ??
1118 a_simple_expression
= lttv_simple_expression_new();
1121 g_assert(tree
!= NULL
);
1122 g_assert(subtree
== NULL
);
1130 * Destroy the current LttvFilter
1131 * @param filter pointer to the current LttvFilter
1134 lttv_filter_destroy(LttvFilter
* filter
) {
1136 g_free(filter
->expression
);
1137 lttv_filter_tree_destroy(filter
->head
);
1143 * Assign a new tree for the current expression
1145 * @return pointer of LttvFilterTree
1148 lttv_filter_tree_new() {
1149 LttvFilterTree
* tree
;
1151 tree
= g_new(LttvFilter
,1);
1152 tree
->node
= 0; //g_new(lttv_expression,1);
1153 tree
->left
= LTTV_TREE_IDLE
;
1154 tree
->right
= LTTV_TREE_IDLE
;
1160 * Destroys the tree and his sub-trees
1161 * @param tree Tree which must be destroyed
1164 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1166 if(tree
== NULL
) return;
1168 if(tree
->left
== LTTV_TREE_LEAF
) g_free(tree
->l_child
.leaf
);
1169 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1171 if(tree
->right
== LTTV_TREE_LEAF
) g_free(tree
->r_child
.leaf
);
1172 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1180 * Apply the filter to a specific trace
1181 * @param filter the current filter applied
1182 * @param tracefile the trace to apply the filter to
1183 * @return success/failure of operation
1186 lttv_filter_tracefile(LttvFilter
*filter
, LttTracefile
*tracefile
) {
1188 LttvFilterTree
* t
= filter
->head
;
1191 * Each tree is parsed in inorder.
1192 * This way, it's possible to apply the left filter of the
1193 * tree, then decide whether or not the right branch should
1194 * be parsed depending on the linking logical operator
1196 * As for the filtering structure, since we are trying
1197 * to remove elements from the trace, it might be better
1198 * managing an array of all items to be removed ..
1201 /////////////////////////////////////////////////////////////////////////////
1203 /////////////////////////////////////////////////////////////////////////////
1204 g_print("node:%p lchild:%p rchild:%p\n",t
,t
->l_child
.t
,t
->r_child
.t
);
1205 g_print("node type%i\n",t
->node
);
1206 if(t
->left
== LTTV_TREE_NODE
) lttv_filter_tracefile(t
->l_child
.t
,NULL
);
1207 else if(t
->left
== LTTV_TREE_LEAF
) {
1208 g_assert(t
->l_child
.leaf
->value
!= NULL
);
1209 g_print("%p: left is qqch %i %s\n",t
,t
->l_child
.leaf
->op
,t
->l_child
.leaf
->value
);
1211 if(t
->right
== LTTV_TREE_NODE
) lttv_filter_tracefile(t
->r_child
.t
,NULL
);
1212 else if(t
->right
== LTTV_TREE_LEAF
) {
1213 g_assert(t
->r_child
.leaf
->value
!= NULL
);
1214 g_print("%p: right is qqch %i %s\n",t
,t
->r_child
.leaf
->op
,t
->r_child
.leaf
->value
);
1216 /////////////////////////////////////////////////////////////////////////////
1223 char *f_name, *e_name;
1225 char* field = "cpu";
1233 GString *fe_name = g_string_new("");
1235 nb = ltt_trace_eventtype_number(tcs->parent.t);
1236 g_print("NB:%i\n",nb);
1237 for(i = 0 ; i < nb ; i++) {
1238 et = ltt_trace_eventtype_get(tcs->parent.t, i);
1239 e_name = ltt_eventtype_name(et);
1240 f_name = ltt_facility_name(ltt_eventtype_facility(et));
1241 g_string_printf(fe_name, "%s.%s", f_name, e_name);
1242 g_print("facility:%s and event:%s\n",f_name,e_name);
1248 lttv_filter_tracestate(LttvFilter
*filter
, LttvTraceState
*tracestate
) {
1253 * Apply the filter to a specific event
1254 * @param filter the current filter applied
1255 * @param event the event to apply the filter to
1256 * @return success/failure of operation
1259 lttv_filter_event(LttvFilter
*filter
, LttEvent
*event
) {
1264 * Initializes the filter module and specific values
1266 static void module_init()
1270 * Quarks initialization
1271 * for hardcoded filtering options
1273 * TODO: traceset has no yet been defined
1277 // LTTV_FILTER_EVENT = g_quark_from_string("event");
1278 // LTTV_FILTER_TRACE = g_quark_from_string("trace");
1279 // LTTV_FILTER_TRACESET = g_quark_from_string("traceset");
1280 // LTTV_FILTER_STATE = g_quark_from_string("state");
1281 // LTTV_FILTER_TRACEFILE = g_quark_from_string("tracefile");
1283 /* event.name, tracefile.name, trace.name */
1284 // LTTV_FILTER_NAME = g_quark_from_string("name");
1286 /* event sub fields */
1287 // LTTV_FILTER_CATEGORY = g_quark_from_string("category");
1288 // LTTV_FILTER_TIME = g_quark_from_string("time");
1289 // LTTV_FILTER_TSC = g_quark_from_string("tsc");
1291 /* state sub fields */
1292 // LTTV_FILTER_PID = g_quark_from_string("pid");
1293 // LTTV_FILTER_PPID = g_quark_from_string("ppid");
1294 // LTTV_FILTER_C_TIME = g_quark_from_string("creation_time");
1295 // LTTV_FILTER_I_TIME = g_quark_from_string("insertion_time");
1296 // LTTV_FILTER_P_NAME = g_quark_from_string("process_name");
1297 // LTTV_FILTER_EX_MODE = g_quark_from_string("execution_mode");
1298 // LTTV_FILTER_EX_SUBMODE = g_quark_from_string("execution_submode");
1299 // LTTV_FILTER_P_STATUS = g_quark_from_string("process_status");
1300 // LTTV_FILTER_CPU = g_quark_from_string("cpu");
1305 * Destroys the filter module and specific values
1307 static void module_destroy()
1312 LTTV_MODULE("filter", "Filters traceset and events", \
1313 "Filters traceset and events specifically to user input", \
1314 module_init
, module_destroy
)