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 * @fn void lttv_filter_tree_add_node(GPtrArray*,LttvFilterTree*,LttvLogicalOp)
87 * add a node to the current tree
88 * FIXME: Might be used to lower coding in lttv_filter_new switch expression
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
94 lttv_filter_tree_add_node(GPtrArray
* stack
, LttvFilterTree
* subtree
, LttvLogicalOp op
) {
96 LttvFilterTree
* t1
= NULL
;
97 LttvFilterTree
* t2
= NULL
;
99 t1
= (LttvFilterTree
*)g_ptr_array_index(stack
,stack
->len
-1);
100 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= (LttvFilterTree
*)t1
->r_child
.t
;
101 t2
= lttv_filter_tree_new();
103 if(subtree
!= NULL
) {
104 t2
->left
= LTTV_TREE_NODE
;
105 t2
->l_child
.t
= (LttvFilterTree
*)subtree
;
107 t1
->right
= LTTV_TREE_NODE
;
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
;
123 * @fn LttvSimpleExpression* lttv_simple_expression_new()
125 * Constructor for LttvSimpleExpression
126 * @return pointer to new LttvSimpleExpression
128 LttvSimpleExpression
*
129 lttv_simple_expression_new() {
131 LttvSimpleExpression
* se
= g_new(LttvSimpleExpression
,1);
133 se
->field
= LTTV_FILTER_UNDEFINED
;
142 * @fn gboolean lttv_simple_expression_add_field(GPtrArray*,LttvSimpleExpression*)
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
148 * @param se current simple expression
149 * @return success/failure of operation
152 lttv_simple_expression_add_field(GPtrArray
* fp
, LttvSimpleExpression
* se
) {
156 if(fp
->len
< 2) return FALSE
;
157 g_assert(f
=g_ptr_array_remove_index(fp
,0));
160 * Parse through the specified
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
172 if(!g_strcasecmp(f
->str
,"trace") ) {
177 g_string_free(f
,TRUE
);
178 f
=g_ptr_array_remove_index(fp
,0);
179 if(!g_strcasecmp(f
->str
,"name")) {
180 se
->field
= LTTV_FILTER_TRACE_NAME
;
182 } else if(!g_strcasecmp(f
->str
,"traceset") ) {
184 * FIXME: not yet implemented !
186 } else if(!g_strcasecmp(f
->str
,"tracefile") ) {
191 g_string_free(f
,TRUE
);
192 f
=g_ptr_array_remove_index(fp
,0);
193 if(!g_strcasecmp(f
->str
,"name")) {
194 se
->field
= LTTV_FILTER_TRACEFILE_NAME
;
196 } else if(!g_strcasecmp(f
->str
,"state") ) {
201 * state.creation_time
202 * state.insertion_time
204 * state.execution_mode
205 * state.execution_submode
206 * state.process_status
209 g_string_free(f
,TRUE
);
210 f
=g_ptr_array_remove_index(fp
,0);
211 if(!g_strcasecmp(f
->str
,"pid") ) {
212 se
->field
= LTTV_FILTER_STATE_PID
;
214 else if(!g_strcasecmp(f
->str
,"ppid") ) {
215 se
->field
= LTTV_FILTER_STATE_PPID
;
217 else if(!g_strcasecmp(f
->str
,"creation_time") ) {
218 se
->field
= LTTV_FILTER_STATE_CT
;
220 else if(!g_strcasecmp(f
->str
,"insertion_time") ) {
221 se
->field
= LTTV_FILTER_STATE_IT
;
223 else if(!g_strcasecmp(f
->str
,"process_name") ) {
224 se
->field
= LTTV_FILTER_STATE_P_NAME
;
226 else if(!g_strcasecmp(f
->str
,"execution_mode") ) {
227 se
->field
= LTTV_FILTER_STATE_EX_MODE
;
229 else if(!g_strcasecmp(f
->str
,"execution_submode") ) {
230 se
->field
= LTTV_FILTER_STATE_EX_SUBMODE
;
232 else if(!g_strcasecmp(f
->str
,"process_status") ) {
233 se
->field
= LTTV_FILTER_STATE_P_STATUS
;
235 else if(!g_strcasecmp(f
->str
,"cpu") ) {
236 se
->field
= LTTV_FILTER_STATE_CPU
;
238 } else if(!g_strcasecmp(f
->str
,"event") ) {
246 g_string_free(f
,TRUE
);
247 f
=g_ptr_array_remove_index(fp
,0);
248 if(!g_strcasecmp(f
->str
,"name") ) {
249 se
->field
= LTTV_FILTER_EVENT_NAME
;
251 else if(!g_strcasecmp(f
->str
,"category") ) {
253 * FIXME: Category not yet functional in lttv
255 se
->field
= LTTV_FILTER_EVENT_CATEGORY
;
257 else if(!g_strcasecmp(f
->str
,"time") ) {
258 se
->field
= LTTV_FILTER_EVENT_TIME
;
260 else if(!g_strcasecmp(f
->str
,"tsc") ) {
261 se
->field
= LTTV_FILTER_EVENT_TSC
;
263 else { /* core.xml specified options */
264 se
->field
= LTTV_FILTER_EVENT_FIELD
;
267 g_warning("Unrecognized field in filter string");
270 /* free memory for last string */
271 g_string_free(f
,TRUE
);
273 /* array should be empty */
274 g_assert(fp
->len
== 0);
276 g_print("field: %i\n",se
->field
);
277 if(se
->field
== LTTV_FILTER_UNDEFINED
) {
278 g_warning("The specified field was not recognized !");
285 * @fn gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression*,LttvExpressionOp)
287 * Sets the function pointer for the current
289 * @param se current simple expression
290 * @return success/failure of operation
292 gboolean
lttv_simple_expression_assign_operator(LttvSimpleExpression
* se
, LttvExpressionOp op
) {
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);
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
:
309 se
->op
= lttv_apply_op_eq_string
;
312 se
->op
= lttv_apply_op_ne_string
;
315 g_warning("Error encountered in operator assignment = or != expected");
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
:
329 se
->op
= lttv_apply_op_eq_uint64
;
332 se
->op
= lttv_apply_op_ne_uint64
;
335 se
->op
= lttv_apply_op_lt_uint64
;
338 se
->op
= lttv_apply_op_le_uint64
;
341 se
->op
= lttv_apply_op_gt_uint64
;
344 se
->op
= lttv_apply_op_ge_uint64
;
347 g_warning("Error encountered in operator assignment");
354 case LTTV_FILTER_STATE_CT
:
355 case LTTV_FILTER_STATE_IT
:
356 case LTTV_FILTER_EVENT_TIME
:
357 case LTTV_FILTER_EVENT_TSC
:
360 se
->op
= lttv_apply_op_eq_double
;
363 se
->op
= lttv_apply_op_ne_double
;
366 se
->op
= lttv_apply_op_lt_double
;
369 se
->op
= lttv_apply_op_le_double
;
372 se
->op
= lttv_apply_op_gt_double
;
375 se
->op
= lttv_apply_op_ge_double
;
378 g_warning("Error encountered in operator assignment");
383 g_warning("Error encountered in operator assignment ! Bad field type ...");
392 * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*)
394 * Desallocate memory for the current
396 * @param se pointer to the current LttvSimpleExpression
399 lttv_simple_expression_destroy(LttvSimpleExpression
* se
) {
407 * @fn gint lttv_struct_type(gint)
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
415 lttv_struct_type(gint ft
) {
418 case LTTV_FILTER_TRACE_NAME
:
419 return LTTV_FILTER_TRACE
;
421 case LTTV_FILTER_TRACEFILE_NAME
:
422 return LTTV_FILTER_TRACEFILE
;
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
;
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
;
448 * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue)
450 * Applies the 'equal' operator to the
451 * specified structure and value
452 * @param v1 left member of comparison
453 * @param v2 right member of comparison
454 * @return success/failure of operation
456 gboolean
lttv_apply_op_eq_uint64(gpointer v1
, char* v2
) {
458 guint64
* r
= (guint64
*) v1
;
459 guint64 l
= atoi(v2
);
465 * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue)
467 * Applies the 'equal' operator to the
468 * specified structure and value
469 * @param v1 left member of comparison
470 * @param v2 right member of comparison
471 * @return success/failure of operation
473 gboolean
lttv_apply_op_eq_uint32(gpointer v1
, char* v2
) {
474 guint32
* r
= (guint32
*) v1
;
475 guint32 l
= atoi(v2
);
480 * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue)
482 * Applies the 'equal' operator to the
483 * specified structure and value
484 * @param v1 left member of comparison
485 * @param v2 right member of comparison
486 * @return success/failure of operation
488 gboolean
lttv_apply_op_eq_uint16(gpointer v1
, char* v2
) {
489 guint16
* r
= (guint16
*) v1
;
490 guint16 l
= atoi(v2
);
495 * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue)
497 * Applies the 'equal' operator to the
498 * specified structure and value
499 * @param v1 left member of comparison
500 * @param v2 right member of comparison
501 * @return success/failure of operation
503 gboolean
lttv_apply_op_eq_double(gpointer v1
, char* v2
) {
504 double* r
= (double*) v1
;
510 * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue)
512 * Applies the 'equal' operator to the
513 * specified structure and value
514 * @param v1 left member of comparison
515 * @param v2 right member of comparison
516 * @return success/failure of operation
518 gboolean
lttv_apply_op_eq_string(gpointer v1
, char* v2
) {
519 char* r
= (char*) v1
;
520 return (!g_strcasecmp(r
,v2
));
524 * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue)
526 * Applies the 'not equal' operator to the
527 * specified structure and value
528 * @param v1 left member of comparison
529 * @param v2 right member of comparison
530 * @return success/failure of operation
532 gboolean
lttv_apply_op_ne_uint64(gpointer v1
, char* v2
) {
533 guint64
* r
= (guint64
*) v1
;
534 guint64 l
= atoi(v2
);
539 * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue)
541 * Applies the 'not equal' operator to the
542 * specified structure and value
543 * @param v1 left member of comparison
544 * @param v2 right member of comparison
545 * @return success/failure of operation
547 gboolean
lttv_apply_op_ne_uint32(gpointer v1
, char* v2
) {
548 guint32
* r
= (guint32
*) v1
;
549 guint32 l
= atoi(v2
);
554 * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue)
556 * Applies the 'not equal' operator to the
557 * specified structure and value
558 * @param v1 left member of comparison
559 * @param v2 right member of comparison
560 * @return success/failure of operation
562 gboolean
lttv_apply_op_ne_uint16(gpointer v1
, char* v2
) {
563 guint16
* r
= (guint16
*) v1
;
564 guint16 l
= atoi(v2
);
569 * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue)
571 * Applies the 'not equal' operator to the
572 * specified structure and value
573 * @param v1 left member of comparison
574 * @param v2 right member of comparison
575 * @return success/failure of operation
577 gboolean
lttv_apply_op_ne_double(gpointer v1
, char* v2
) {
578 double* r
= (double*) v1
;
584 * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue)
586 * Applies the 'not equal' operator to the
587 * specified structure and value
588 * @param v1 left member of comparison
589 * @param v2 right member of comparison
590 * @return success/failure of operation
592 gboolean
lttv_apply_op_ne_string(gpointer v1
, char* v2
) {
593 char* r
= (char*) v1
;
594 return (g_strcasecmp(r
,v2
));
598 * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue)
600 * Applies the 'lower than' operator to the
601 * specified structure and value
602 * @param v1 left member of comparison
603 * @param v2 right member of comparison
604 * @return success/failure of operation
606 gboolean
lttv_apply_op_lt_uint64(gpointer v1
, char* v2
) {
607 guint64
* r
= (guint64
*) v1
;
608 guint64 l
= atoi(v2
);
613 * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue)
615 * Applies the 'lower than' operator to the
616 * specified structure and value
617 * @param v1 left member of comparison
618 * @param v2 right member of comparison
619 * @return success/failure of operation
621 gboolean
lttv_apply_op_lt_uint32(gpointer v1
, char* v2
) {
622 guint32
* r
= (guint32
*) v1
;
623 guint32 l
= atoi(v2
);
628 * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue)
630 * Applies the 'lower than' operator to the
631 * specified structure and value
632 * @param v1 left member of comparison
633 * @param v2 right member of comparison
634 * @return success/failure of operation
636 gboolean
lttv_apply_op_lt_uint16(gpointer v1
, char* v2
) {
637 guint16
* r
= (guint16
*) v1
;
638 guint16 l
= atoi(v2
);
643 * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue)
645 * Applies the 'lower than' operator to the
646 * specified structure and value
647 * @param v1 left member of comparison
648 * @param v2 right member of comparison
649 * @return success/failure of operation
651 gboolean
lttv_apply_op_lt_double(gpointer v1
, char* v2
) {
652 double* r
= (double*) v1
;
658 * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue)
660 * Applies the 'lower or equal' operator to the
661 * specified structure and value
662 * @param v1 left member of comparison
663 * @param v2 right member of comparison
664 * @return success/failure of operation
666 gboolean
lttv_apply_op_le_uint64(gpointer v1
, char* v2
) {
667 guint64
* r
= (guint64
*) v1
;
668 guint64 l
= atoi(v2
);
673 * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue)
675 * Applies the 'lower or equal' operator to the
676 * specified structure and value
677 * @param v1 left member of comparison
678 * @param v2 right member of comparison
679 * @return success/failure of operation
681 gboolean
lttv_apply_op_le_uint32(gpointer v1
, char* v2
) {
682 guint32
* r
= (guint32
*) v1
;
683 guint32 l
= atoi(v2
);
688 * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue)
690 * Applies the 'lower or equal' operator to the
691 * specified structure and value
692 * @param v1 left member of comparison
693 * @param v2 right member of comparison
694 * @return success/failure of operation
696 gboolean
lttv_apply_op_le_uint16(gpointer v1
, char* v2
) {
697 guint16
* r
= (guint16
*) v1
;
698 guint16 l
= atoi(v2
);
703 * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue)
705 * Applies the 'lower or equal' operator to the
706 * specified structure and value
707 * @param v1 left member of comparison
708 * @param v2 right member of comparison
709 * @return success/failure of operation
711 gboolean
lttv_apply_op_le_double(gpointer v1
, char* v2
) {
712 double* r
= (double*) v1
;
718 * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue)
720 * Applies the 'greater than' operator to the
721 * specified structure and value
722 * @param v1 left member of comparison
723 * @param v2 right member of comparison
724 * @return success/failure of operation
726 gboolean
lttv_apply_op_gt_uint64(gpointer v1
, char* v2
) {
727 guint64
* r
= (guint64
*) v1
;
728 guint64 l
= atoi(v2
);
733 * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue)
735 * Applies the 'greater than' operator to the
736 * specified structure and value
737 * @param v1 left member of comparison
738 * @param v2 right member of comparison
739 * @return success/failure of operation
741 gboolean
lttv_apply_op_gt_uint32(gpointer v1
, char* v2
) {
742 guint32
* r
= (guint32
*) v1
;
743 guint32 l
= atoi(v2
);
748 * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue)
750 * Applies the 'greater than' operator to the
751 * specified structure and value
752 * @param v1 left member of comparison
753 * @param v2 right member of comparison
754 * @return success/failure of operation
756 gboolean
lttv_apply_op_gt_uint16(gpointer v1
, char* v2
) {
757 guint16
* r
= (guint16
*) v1
;
758 guint16 l
= atoi(v2
);
763 * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue)
765 * Applies the 'greater than' operator to the
766 * specified structure and value
767 * @param v1 left member of comparison
768 * @param v2 right member of comparison
769 * @return success/failure of operation
771 gboolean
lttv_apply_op_gt_double(gpointer v1
, char* v2
) {
772 double* r
= (double*) v1
;
778 * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue)
780 * Applies the 'greater or equal' operator to the
781 * specified structure and value
782 * @param v1 left member of comparison
783 * @param v2 right member of comparison
784 * @return success/failure of operation
786 gboolean
lttv_apply_op_ge_uint64(gpointer v1
, char* v2
) {
787 guint64
* r
= (guint64
*) v1
;
788 guint64 l
= atoi(v2
);
793 * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue)
795 * Applies the 'greater or equal' operator to the
796 * specified structure and value
797 * @param v1 left member of comparison
798 * @param v2 right member of comparison
799 * @return success/failure of operation
801 gboolean
lttv_apply_op_ge_uint32(gpointer v1
, char* v2
) {
802 guint32
* r
= (guint32
*) v1
;
803 guint32 l
= atoi(v2
);
808 * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue)
810 * Applies the 'greater or equal' operator to the
811 * specified structure and value
812 * @param v1 left member of comparison
813 * @param v2 right member of comparison
814 * @return success/failure of operation
816 gboolean
lttv_apply_op_ge_uint16(gpointer v1
, char* v2
) {
817 guint16
* r
= (guint16
*) v1
;
818 guint16 l
= atoi(v2
);
823 * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue)
825 * Applies the 'greater or equal' operator to the
826 * specified structure and value
827 * @param v1 left member of comparison
828 * @param v2 right member of comparison
829 * @return success/failure of operation
831 gboolean
lttv_apply_op_ge_double(gpointer v1
, char* v2
) {
832 double* r
= (double*) v1
;
839 * @fn LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree*)
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
846 lttv_filter_tree_clone(LttvFilterTree
* tree
) {
848 LttvFilterTree
* newtree
= lttv_filter_tree_new();
850 newtree
->node
= tree
->node
;
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
);
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
);
879 * @fn LttvFilter* lttv_filter_clone(LttvFilter*)
881 * Makes a copy of the current filter
882 * @param filter pointer to the current filter
883 * @return new copy of the filter
886 lttv_filter_clone(LttvFilter
* filter
) {
889 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
891 // newfilter->expression = g_new(char,1)
892 strcpy(newfilter
->expression
,filter
->expression
);
894 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
902 * @fn LttvFilter* lttv_filter_new()
904 * Creates a new lttv_filter
905 * @param expression filtering options string
906 * @param t pointer to the current LttvTrace
907 * @return the current lttv_filter or NULL if error
912 LttvFilter
* filter
= g_new(LttvFilter
,1);
913 filter
->expression
= NULL
;
919 * @fn gboolean lttv_filter_update(LttvFilter*)
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
927 lttv_filter_update(LttvFilter
* filter
) {
929 g_print("filter::lttv_filter_new()\n"); /* debug */
931 if(filter
->expression
== NULL
) return FALSE
;
935 p_nesting
=0; /* parenthesis nesting value */
939 *tree
= lttv_filter_tree_new(), /* main tree */
940 *subtree
= NULL
, /* buffer for subtrees */
946 * If the tree already exists,
947 * destroy it and build a new one
949 if(filter
->head
!= NULL
) lttv_filter_tree_destroy(filter
->head
);
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
958 * will be the one left at the root of
961 GPtrArray
*tree_stack
= g_ptr_array_new();
962 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
964 /* temporary values */
965 GString
*a_field_component
= g_string_new("");
966 GPtrArray
*a_field_path
= g_ptr_array_new();
968 /* simple expression buffer */
969 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
972 * Parse entire expression and construct
973 * the binary tree. There are two steps
974 * in browsing that string
975 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
976 * 2. finding simple expressions
977 * - field path ( separated by dots )
978 * - op ( >, <, =, >=, <=, !=)
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.
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
1002 g_print("expression: %s\n",filter
->expression
);
1003 g_print("strlen(expression): %i\n",strlen(filter
->expression
));
1004 for(i
=0;i
<strlen(filter
->expression
);i
++) {
1006 g_print("%c ",filter
->expression
[i
]);
1007 switch(filter
->expression
[i
]) {
1013 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1014 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
1015 t2
= lttv_filter_tree_new();
1016 t2
->node
= LTTV_LOGICAL_AND
;
1017 if(subtree
!= NULL
) { /* append subtree to current tree */
1018 t2
->left
= LTTV_TREE_NODE
;
1019 t2
->l_child
.t
= subtree
;
1021 t1
->right
= LTTV_TREE_NODE
;
1023 } else { /* append a simple expression */
1024 a_simple_expression
->value
= g_string_free(a_field_component
,FALSE
);
1025 a_field_component
= g_string_new("");
1026 t2
->left
= LTTV_TREE_LEAF
;
1027 t2
->l_child
.leaf
= a_simple_expression
;
1028 a_simple_expression
= lttv_simple_expression_new();
1029 t1
->right
= LTTV_TREE_NODE
;
1036 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1037 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
1038 t2
= lttv_filter_tree_new();
1039 t2
->node
= LTTV_LOGICAL_OR
;
1040 if(subtree
!= NULL
) { /* append subtree to current tree */
1041 t2
->left
= LTTV_TREE_NODE
;
1042 t2
->l_child
.t
= subtree
;
1044 t1
->right
= LTTV_TREE_NODE
;
1046 } else { /* append a simple expression */
1047 a_simple_expression
->value
= g_string_free(a_field_component
,FALSE
);
1048 a_field_component
= g_string_new("");
1049 t2
->left
= LTTV_TREE_LEAF
;
1050 t2
->l_child
.leaf
= a_simple_expression
;
1051 a_simple_expression
= lttv_simple_expression_new();
1052 t1
->right
= LTTV_TREE_NODE
;
1059 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1060 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
1061 t2
= lttv_filter_tree_new();
1062 t2
->node
= LTTV_LOGICAL_XOR
;
1063 if(subtree
!= NULL
) { /* append subtree to current tree */
1064 t2
->left
= LTTV_TREE_NODE
;
1065 t2
->l_child
.t
= subtree
;
1067 t1
->right
= LTTV_TREE_NODE
;
1069 } else { /* append a simple expression */
1070 a_simple_expression
->value
= g_string_free(a_field_component
,FALSE
);
1071 a_field_component
= g_string_new("");
1072 t2
->left
= LTTV_TREE_LEAF
;
1073 t2
->l_child
.leaf
= a_simple_expression
;
1074 a_simple_expression
= lttv_simple_expression_new();
1075 t1
->right
= LTTV_TREE_NODE
;
1080 case '!': /* not, or not equal (math op) */
1082 if(filter
->expression
[i
+1] == '=') { /* != */
1083 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1084 lttv_simple_expression_add_field(a_field_path
,a_simple_expression
);
1085 a_field_component
= g_string_new("");
1086 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_NE
);
1089 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1090 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
1091 t2
= lttv_filter_tree_new();
1092 t2
->node
= LTTV_LOGICAL_NOT
;
1093 t1
->right
= LTTV_TREE_NODE
;
1098 case '(': /* start of parenthesis */
1102 p_nesting
++; /* incrementing parenthesis nesting value */
1103 t1
= lttv_filter_tree_new();
1104 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
1107 case ')': /* end of parenthesis */
1111 p_nesting
--; /* decrementing parenthesis nesting value */
1112 if(p_nesting
<0 || tree_stack
->len
<2) {
1113 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1114 is not valid due to parenthesis incorrect use",filter
->expression
);
1118 /* there must at least be the root tree left in the array */
1119 g_assert(tree_stack
->len
>0);
1121 if(subtree
!= NULL
) { /* append subtree to current tree */
1122 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1123 while(t1
->right
!= LTTV_TREE_IDLE
&& t1
->right
!= LTTV_TREE_LEAF
) {
1124 g_assert(t1
!=NULL
&& t1
->r_child
.t
!= NULL
);
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);
1131 } else { /* assign subtree as current tree */
1132 a_simple_expression
->value
= g_string_free(a_field_component
,FALSE
);
1133 a_field_component
= g_string_new("");
1134 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1135 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
1136 t1
->right
= LTTV_TREE_LEAF
;
1137 t1
->r_child
.leaf
= a_simple_expression
;
1138 a_simple_expression
= lttv_simple_expression_new();
1139 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1140 g_assert(subtree
!= NULL
);
1141 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1146 * mathematic operators
1148 case '<': /* lower, lower or equal */
1150 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1151 lttv_simple_expression_add_field(a_field_path
,a_simple_expression
);
1152 a_field_component
= g_string_new("");
1153 if(filter
->expression
[i
+1] == '=') { /* <= */
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
);
1159 case '>': /* higher, higher or equal */
1161 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1162 lttv_simple_expression_add_field(a_field_path
,a_simple_expression
);
1163 a_field_component
= g_string_new("");
1164 if(filter
->expression
[i
+1] == '=') { /* >= */
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
);
1170 case '=': /* equal */
1172 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1173 lttv_simple_expression_add_field(a_field_path
,a_simple_expression
);
1174 a_field_component
= g_string_new("");
1175 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1179 * Field concatening caracter
1184 * divide field expression into elements
1185 * in a_field_path array.
1187 /* FIXME: check for double values */
1188 // if(a_simple_expression->op == NULL) {
1189 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1190 a_field_component
= g_string_new("");
1196 default: /* concatening current string */
1197 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1201 g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree
,tree
,t1
,t2
);
1202 g_print("stack size: %i\n",tree_stack
->len
);
1205 * Preliminary check to see
1206 * if tree was constructed correctly
1209 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1210 is not valid due to parenthesis incorrect use",filter
->expression
);
1214 if(tree_stack
->len
!= 1) /* only root tree should remain */
1217 /* processing last element of expression */
1218 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1219 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= t1
->r_child
.t
;
1220 if(subtree
!= NULL
) { /* add the subtree */
1221 g_print("there right!\n");
1222 t1
->right
= LTTV_TREE_NODE
;
1223 t1
->r_child
.t
= subtree
;
1225 } else { /* add a leaf */
1226 a_simple_expression
->value
= g_string_free(a_field_component
,FALSE
);
1227 a_field_component
= NULL
;
1228 t1
->right
= LTTV_TREE_LEAF
;
1229 t1
->r_child
.leaf
= a_simple_expression
;
1230 a_simple_expression
= NULL
;
1234 /* free the pointer array */
1235 g_assert(a_field_path
->len
== 0);
1236 g_ptr_array_free(a_field_path
,TRUE
);
1238 /* free the tree stack -- but keep the root tree */
1239 g_ptr_array_free(tree_stack
,FALSE
);
1241 /* free the field buffer if allocated */
1242 if(a_field_component
!= NULL
) g_string_free(a_field_component
,TRUE
);
1244 /* free the simple expression buffer if allocated */
1245 if(a_simple_expression
!= NULL
) lttv_simple_expression_destroy(a_simple_expression
);
1247 g_assert(tree
!= NULL
); /* tree should exist */
1248 g_assert(subtree
== NULL
); /* remaining subtree should be included in main tree */
1251 g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1252 lttv_print_tree(filter
->head
) ;
1253 g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1261 * @fn void lttv_filter_destroy(LttvFilter*)
1263 * Destroy the current LttvFilter
1264 * @param filter pointer to the current LttvFilter
1267 lttv_filter_destroy(LttvFilter
* filter
) {
1269 g_free(filter
->expression
);
1270 lttv_filter_tree_destroy(filter
->head
);
1276 * LttvFilterTree* lttv_filter_tree_new()
1278 * Assign a new tree for the current expression
1280 * @return pointer of LttvFilterTree
1283 lttv_filter_tree_new() {
1284 LttvFilterTree
* tree
;
1286 tree
= g_new(LttvFilter
,1);
1287 tree
->node
= 0; //g_new(lttv_expression,1);
1288 tree
->left
= LTTV_TREE_IDLE
;
1289 tree
->right
= LTTV_TREE_IDLE
;
1295 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
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
1301 * @return Success/Failure of operation
1303 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, char *expression
) {
1305 if(expression
== NULL
) return FALSE
;
1306 if(filter
== NULL
) {
1307 filter
= lttv_filter_new();
1308 filter
->expression
= expression
;
1309 } else if(filter
->expression
== NULL
) {
1310 filter
->expression
= expression
;
1312 filter
->expression
= g_strconcat(filter
->expression
,"&",expression
);
1315 return lttv_filter_update(filter
);
1320 * @fn void lttv_filter_clear_expression(LttvFilter*)
1322 * Clear the filter expression from the
1323 * current filter and sets its pointer to NULL
1324 * @param filter pointer to the current LttvFilter
1326 void lttv_filter_clear_expression(LttvFilter
* filter
) {
1328 if(filter
->expression
!= NULL
) {
1329 g_free(filter
->expression
);
1330 filter
->expression
= NULL
;
1336 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1338 * Destroys the tree and his sub-trees
1339 * @param tree Tree which must be destroyed
1342 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1344 if(tree
== NULL
) return;
1346 if(tree
->left
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->l_child
.leaf
);
1347 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1349 if(tree
->right
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->r_child
.leaf
);
1350 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1357 * gboolean lttv_filter_tree_parse(LttvFilterTree*,LttEvent,LttTracefile,LttTrace,LttvProcessState)
1359 * Global parsing function for the current
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
1368 lttv_filter_tree_parse(
1371 LttTracefile
* tracefile
,
1373 LttvProcessState
* state
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
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 )
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
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.
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
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
1408 * -Result of left branch will not affect exploration of
1411 g_print("filter::lttv_parse_tree(...)\n");
1413 gboolean lresult
= FALSE
, rresult
= FALSE
;
1418 if(t
->left
== LTTV_TREE_NODE
) lresult
= lttv_filter_tree_parse(t
->l_child
.t
,event
,tracefile
,trace
,state
);
1419 else if(t
->left
== LTTV_TREE_LEAF
) {
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);
1422 g_assert(v
= t
->l_child
.leaf
->value
);
1423 switch(t
->l_child
.leaf
->field
) {
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
);
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
);
1433 case LTTV_FILTER_STATE_PID
:
1434 if(state
== NULL
) lresult
= TRUE
;
1435 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1437 case LTTV_FILTER_STATE_PPID
:
1438 if(state
== NULL
) lresult
= TRUE
;
1439 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1441 case LTTV_FILTER_STATE_CT
:
1442 if(state
== NULL
) lresult
= TRUE
;
1444 double val
= ltt_time_to_double(state
->creation_time
);
1445 lresult
= t
->l_child
.leaf
->op((gpointer
)&val
,v
);
1448 case LTTV_FILTER_STATE_IT
:
1449 if(state
== NULL
) lresult
= TRUE
;
1451 double val
= ltt_time_to_double(state
->insertion_time
);
1452 lresult
= t
->l_child
.leaf
->op((gpointer
)&val
,v
);
1455 case LTTV_FILTER_STATE_P_NAME
:
1457 * FIXME: Yet to be done ( I think ? )
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
);
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
);
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
);
1473 case LTTV_FILTER_STATE_CPU
:
1475 * FIXME: What is the comparison value ?
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
);
1484 case LTTV_FILTER_EVENT_CATEGORY
:
1486 * FIXME: Not yet implemented
1490 case LTTV_FILTER_EVENT_TIME
:
1491 // if(event == NULL) lresult = TRUE;
1493 // double val = ltt_time_to_double(event->event_time);
1494 // lresult = t->l_child.leaf->op((gpointer)&val,v);
1498 case LTTV_FILTER_EVENT_TSC
:
1499 // if(event == NULL) lresult = TRUE;
1501 // double val = ltt_time_to_double(event->event_time);
1502 // lresult = t->l_child.leaf->op((gpointer)&val,v);
1505 * FIXME: Where is event.tsc
1509 case LTTV_FILTER_EVENT_FIELD
:
1511 * TODO: Use the offset to
1512 * find the dynamic field
1513 * in the event struct
1518 * This case should never be
1519 * parsed, if so, the whole
1520 * filtering is cancelled
1522 g_warning("Error while parsing the filter tree");
1528 * Parse linking operator
1529 * make a cutoff if possible
1531 if((t
->node
& LTTV_LOGICAL_OR
) && lresult
== TRUE
) return TRUE
;
1532 if((t
->node
& LTTV_LOGICAL_AND
) && lresult
== FALSE
) return FALSE
;
1535 * Parse right branch
1537 if(t
->right
== LTTV_TREE_NODE
) rresult
= lttv_filter_tree_parse(t
->r_child
.t
,event
,tracefile
,trace
,state
);
1538 else if(t
->right
== LTTV_TREE_LEAF
) {
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);
1541 g_assert(v
= t
->r_child
.leaf
->value
);
1542 switch(t
->r_child
.leaf
->field
) {
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
);
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
);
1552 case LTTV_FILTER_STATE_PID
:
1553 if(state
== NULL
) rresult
= TRUE
;
1554 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1556 case LTTV_FILTER_STATE_PPID
:
1557 if(state
== NULL
) rresult
= TRUE
;
1558 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1560 case LTTV_FILTER_STATE_CT
:
1561 if(state
== NULL
) rresult
= TRUE
;
1563 double val
= ltt_time_to_double(state
->creation_time
);
1564 rresult
= t
->r_child
.leaf
->op((gpointer
)&val
,v
);
1567 case LTTV_FILTER_STATE_IT
:
1568 if(state
== NULL
) rresult
= TRUE
;
1570 double val
= ltt_time_to_double(state
->insertion_time
);
1571 rresult
= t
->r_child
.leaf
->op((gpointer
)&val
,v
);
1574 case LTTV_FILTER_STATE_P_NAME
:
1576 * FIXME: Yet to be done ( I think ? )
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
);
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
);
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
);
1592 case LTTV_FILTER_STATE_CPU
:
1594 * FIXME: What is the comparison value ?
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
);
1603 case LTTV_FILTER_EVENT_CATEGORY
:
1605 * FIXME: Not yet implemented
1609 case LTTV_FILTER_EVENT_TIME
:
1610 // if(event == NULL) rresult = TRUE;
1612 // double val = ltt_time_to_double(event->event_time);
1613 // rresult = t->r_child.leaf->op((gpointer)&val,v);
1617 case LTTV_FILTER_EVENT_TSC
:
1618 // if(event == NULL) rresult = TRUE;
1620 // double val = ltt_time_to_double(event->event_time);
1621 // rresult = t->r_child.leaf->op((gpointer)&val,v);
1624 * FIXME: Where is event.tsc
1628 case LTTV_FILTER_EVENT_FIELD
:
1630 * TODO: Use the offset to
1631 * find the dynamic field
1632 * in the event struct
1637 * This case should never be
1638 * parsed, if so, this subtree
1641 g_warning("Error while parsing the filter tree");
1647 * Apply and return the
1648 * logical link between the
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
);
1658 * This case should never be
1659 * parsed, if so, this subtree
1668 * @fn void lttv_print_tree(LttvFilterTree*)
1671 * @param t the pointer to the current LttvFilterTree
1674 lttv_print_tree(LttvFilterTree
* t
) {
1676 g_print("node:%p lchild:%p rchild:%p\n",t
, //t->l_child.t,t->r_child.t);
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
) {
1682 // g_assert(t->l_child.leaf->value != NULL);
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
);
1686 if(t
->right
== LTTV_TREE_NODE
) lttv_print_tree(t
->r_child
.t
);
1687 else if(t
->right
== LTTV_TREE_LEAF
) {
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
);
1696 * gboolean lttv_filter_tracefile(LttvFilter*, LttTracefile*)
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
1704 lttv_filter_tracefile(LttvFilter
*filter
, LttTracefile
*tracefile
) {
1706 return lttv_filter_tree_parse(filter
->head
,NULL
,tracefile
,NULL
,NULL
);
1711 * @fn gboolean lttv_filter_tracestate(LttvFilter*,LttvTraceState*)
1713 * Parse the current tracestate
1714 * @param filter pointer to the current LttvFilter
1715 * @param tracestate pointer to the current tracestate
1718 lttv_filter_tracestate(LttvFilter
*filter
, LttvTraceState
*tracestate
) {
1723 * @fn gboolean lttv_filter_event(LttvFilter*,LttEvent*)
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
1731 lttv_filter_event(LttvFilter
*filter
, LttEvent
*event
) {
1736 * @fn static void module_init()
1738 * Initializes the filter module and specific values
1740 static void module_init()
1746 * Destroys the filter module and specific values
1748 static void module_destroy()
1754 LTTV_MODULE("filter", "Filters traceset and events", \
1755 "Filters traceset and events specifically to user input", \
1756 module_init
, module_destroy
)