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
= 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
;
136 se
->value
.v_uint64
= 0;
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_assign_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 assignation ! Field type:%i",se
->field
);
392 * @fn void lttv_simple_expression_assign_value(LttvSimpleExpression*,char*)
394 * Assign the value field to the current LttvSimpleExpression
395 * @param se pointer to the current LttvSimpleExpression
396 * @param value string value for simple expression
398 gboolean
lttv_simple_expression_assign_value(LttvSimpleExpression
* se
, char* value
) {
400 // g_print("se->value:%s\n",value);
406 case LTTV_FILTER_TRACE_NAME
:
407 case LTTV_FILTER_TRACEFILE_NAME
:
408 case LTTV_FILTER_STATE_P_NAME
:
409 case LTTV_FILTER_EVENT_NAME
:
410 se
->value
.v_string
= value
;
415 case LTTV_FILTER_STATE_PID
:
416 case LTTV_FILTER_STATE_PPID
:
417 case LTTV_FILTER_STATE_EX_MODE
:
418 case LTTV_FILTER_STATE_EX_SUBMODE
:
419 case LTTV_FILTER_STATE_P_STATUS
:
420 se
->value
.v_uint64
= atoi(value
);
426 case LTTV_FILTER_STATE_CT
:
427 case LTTV_FILTER_STATE_IT
:
428 case LTTV_FILTER_EVENT_TIME
:
429 case LTTV_FILTER_EVENT_TSC
:
430 se
->value
.v_double
= atof(value
);
434 g_warning("Error encountered in value assignation ! Field type = %i",se
->field
);
443 * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*)
445 * Disallocate memory for the current
447 * @param se pointer to the current LttvSimpleExpression
450 lttv_simple_expression_destroy(LttvSimpleExpression
* se
) {
452 // g_free(se->value);
454 case LTTV_FILTER_TRACE_NAME
:
455 case LTTV_FILTER_TRACEFILE_NAME
:
456 case LTTV_FILTER_STATE_P_NAME
:
457 case LTTV_FILTER_EVENT_NAME
:
458 g_free(se
->value
.v_string
);
466 * @fn gint lttv_struct_type(gint)
468 * Finds the structure type depending
469 * on the fields in parameters
470 * @params ft Field of the current structure
471 * @return LttvStructType enum or -1 for error
474 lttv_struct_type(gint ft
) {
477 case LTTV_FILTER_TRACE_NAME
:
478 return LTTV_FILTER_TRACE
;
480 case LTTV_FILTER_TRACEFILE_NAME
:
481 return LTTV_FILTER_TRACEFILE
;
483 case LTTV_FILTER_STATE_PID
:
484 case LTTV_FILTER_STATE_PPID
:
485 case LTTV_FILTER_STATE_CT
:
486 case LTTV_FILTER_STATE_IT
:
487 case LTTV_FILTER_STATE_P_NAME
:
488 case LTTV_FILTER_STATE_EX_MODE
:
489 case LTTV_FILTER_STATE_EX_SUBMODE
:
490 case LTTV_FILTER_STATE_P_STATUS
:
491 case LTTV_FILTER_STATE_CPU
:
492 return LTTV_FILTER_STATE
;
494 case LTTV_FILTER_EVENT_NAME
:
495 case LTTV_FILTER_EVENT_CATEGORY
:
496 case LTTV_FILTER_EVENT_TIME
:
497 case LTTV_FILTER_EVENT_TSC
:
498 case LTTV_FILTER_EVENT_FIELD
:
499 return LTTV_FILTER_EVENT
;
507 * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue)
509 * Applies the 'equal' operator to the
510 * specified structure and value
511 * @param v1 left member of comparison
512 * @param v2 right member of comparison
513 * @return success/failure of operation
515 gboolean
lttv_apply_op_eq_uint64(gpointer v1
, LttvFieldValue v2
) {
517 guint64
* r
= (guint64
*) v1
;
518 return (*r
== v2
.v_uint64
);
523 * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue)
525 * Applies the 'equal' operator to the
526 * specified structure and value
527 * @param v1 left member of comparison
528 * @param v2 right member of comparison
529 * @return success/failure of operation
531 gboolean
lttv_apply_op_eq_uint32(gpointer v1
, LttvFieldValue v2
) {
532 guint32
* r
= (guint32
*) v1
;
533 return (*r
== v2
.v_uint32
);
537 * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue)
539 * Applies the 'equal' operator to the
540 * specified structure and value
541 * @param v1 left member of comparison
542 * @param v2 right member of comparison
543 * @return success/failure of operation
545 gboolean
lttv_apply_op_eq_uint16(gpointer v1
, LttvFieldValue v2
) {
546 guint16
* r
= (guint16
*) v1
;
547 return (*r
== v2
.v_uint16
);
551 * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue)
553 * Applies the 'equal' operator to the
554 * specified structure and value
555 * @param v1 left member of comparison
556 * @param v2 right member of comparison
557 * @return success/failure of operation
559 gboolean
lttv_apply_op_eq_double(gpointer v1
, LttvFieldValue v2
) {
560 double* r
= (double*) v1
;
561 return (*r
== v2
.v_double
);
565 * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue)
567 * Applies the 'equal' operator to the
568 * specified structure and value
569 * @param v1 left member of comparison
570 * @param v2 right member of comparison
571 * @return success/failure of operation
573 gboolean
lttv_apply_op_eq_string(gpointer v1
, LttvFieldValue v2
) {
574 char* r
= (char*) v1
;
575 g_print("v1:%s = v2:%s\n",r
,v2
.v_string
);
576 return (!g_strcasecmp(r
,v2
.v_string
));
580 * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue)
582 * Applies the 'not equal' operator to the
583 * specified structure and value
584 * @param v1 left member of comparison
585 * @param v2 right member of comparison
586 * @return success/failure of operation
588 gboolean
lttv_apply_op_ne_uint64(gpointer v1
, LttvFieldValue v2
) {
589 guint64
* r
= (guint64
*) v1
;
590 return (*r
!= v2
.v_uint64
);
594 * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue)
596 * Applies the 'not equal' operator to the
597 * specified structure and value
598 * @param v1 left member of comparison
599 * @param v2 right member of comparison
600 * @return success/failure of operation
602 gboolean
lttv_apply_op_ne_uint32(gpointer v1
, LttvFieldValue v2
) {
603 guint32
* r
= (guint32
*) v1
;
604 return (*r
!= v2
.v_uint32
);
608 * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue)
610 * Applies the 'not equal' operator to the
611 * specified structure and value
612 * @param v1 left member of comparison
613 * @param v2 right member of comparison
614 * @return success/failure of operation
616 gboolean
lttv_apply_op_ne_uint16(gpointer v1
, LttvFieldValue v2
) {
617 guint16
* r
= (guint16
*) v1
;
618 return (*r
!= v2
.v_uint16
);
622 * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue)
624 * Applies the 'not equal' operator to the
625 * specified structure and value
626 * @param v1 left member of comparison
627 * @param v2 right member of comparison
628 * @return success/failure of operation
630 gboolean
lttv_apply_op_ne_double(gpointer v1
, LttvFieldValue v2
) {
631 double* r
= (double*) v1
;
632 return (*r
!= v2
.v_double
);
636 * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue)
638 * Applies the 'not equal' operator to the
639 * specified structure and value
640 * @param v1 left member of comparison
641 * @param v2 right member of comparison
642 * @return success/failure of operation
644 gboolean
lttv_apply_op_ne_string(gpointer v1
, LttvFieldValue v2
) {
645 char* r
= (char*) v1
;
646 return (g_strcasecmp(r
,v2
.v_string
));
650 * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue)
652 * Applies the 'lower than' operator to the
653 * specified structure and value
654 * @param v1 left member of comparison
655 * @param v2 right member of comparison
656 * @return success/failure of operation
658 gboolean
lttv_apply_op_lt_uint64(gpointer v1
, LttvFieldValue v2
) {
659 guint64
* r
= (guint64
*) v1
;
660 return (*r
< v2
.v_uint64
);
664 * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue)
666 * Applies the 'lower than' operator to the
667 * specified structure and value
668 * @param v1 left member of comparison
669 * @param v2 right member of comparison
670 * @return success/failure of operation
672 gboolean
lttv_apply_op_lt_uint32(gpointer v1
, LttvFieldValue v2
) {
673 guint32
* r
= (guint32
*) v1
;
674 return (*r
< v2
.v_uint32
);
678 * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue)
680 * Applies the 'lower than' operator to the
681 * specified structure and value
682 * @param v1 left member of comparison
683 * @param v2 right member of comparison
684 * @return success/failure of operation
686 gboolean
lttv_apply_op_lt_uint16(gpointer v1
, LttvFieldValue v2
) {
687 guint16
* r
= (guint16
*) v1
;
688 return (*r
< v2
.v_uint16
);
692 * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue)
694 * Applies the 'lower than' operator to the
695 * specified structure and value
696 * @param v1 left member of comparison
697 * @param v2 right member of comparison
698 * @return success/failure of operation
700 gboolean
lttv_apply_op_lt_double(gpointer v1
, LttvFieldValue v2
) {
701 double* r
= (double*) v1
;
702 return (*r
< v2
.v_double
);
706 * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue)
708 * Applies the 'lower or equal' operator to the
709 * specified structure and value
710 * @param v1 left member of comparison
711 * @param v2 right member of comparison
712 * @return success/failure of operation
714 gboolean
lttv_apply_op_le_uint64(gpointer v1
, LttvFieldValue v2
) {
715 guint64
* r
= (guint64
*) v1
;
716 return (*r
<= v2
.v_uint64
);
720 * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue)
722 * Applies the 'lower or equal' operator to the
723 * specified structure and value
724 * @param v1 left member of comparison
725 * @param v2 right member of comparison
726 * @return success/failure of operation
728 gboolean
lttv_apply_op_le_uint32(gpointer v1
, LttvFieldValue v2
) {
729 guint32
* r
= (guint32
*) v1
;
730 return (*r
<= v2
.v_uint32
);
734 * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue)
736 * Applies the 'lower or equal' operator to the
737 * specified structure and value
738 * @param v1 left member of comparison
739 * @param v2 right member of comparison
740 * @return success/failure of operation
742 gboolean
lttv_apply_op_le_uint16(gpointer v1
, LttvFieldValue v2
) {
743 guint16
* r
= (guint16
*) v1
;
744 return (*r
<= v2
.v_uint16
);
748 * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue)
750 * Applies the 'lower or equal' 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_le_double(gpointer v1
, LttvFieldValue v2
) {
757 double* r
= (double*) v1
;
758 return (*r
<= v2
.v_double
);
762 * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue)
764 * Applies the 'greater than' operator to the
765 * specified structure and value
766 * @param v1 left member of comparison
767 * @param v2 right member of comparison
768 * @return success/failure of operation
770 gboolean
lttv_apply_op_gt_uint64(gpointer v1
, LttvFieldValue v2
) {
771 guint64
* r
= (guint64
*) v1
;
772 return (*r
> v2
.v_uint64
);
776 * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue)
778 * Applies the 'greater than' operator to the
779 * specified structure and value
780 * @param v1 left member of comparison
781 * @param v2 right member of comparison
782 * @return success/failure of operation
784 gboolean
lttv_apply_op_gt_uint32(gpointer v1
, LttvFieldValue v2
) {
785 guint32
* r
= (guint32
*) v1
;
786 return (*r
> v2
.v_uint32
);
790 * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue)
792 * Applies the 'greater than' operator to the
793 * specified structure and value
794 * @param v1 left member of comparison
795 * @param v2 right member of comparison
796 * @return success/failure of operation
798 gboolean
lttv_apply_op_gt_uint16(gpointer v1
, LttvFieldValue v2
) {
799 guint16
* r
= (guint16
*) v1
;
800 return (*r
> v2
.v_uint16
);
804 * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue)
806 * Applies the 'greater than' operator to the
807 * specified structure and value
808 * @param v1 left member of comparison
809 * @param v2 right member of comparison
810 * @return success/failure of operation
812 gboolean
lttv_apply_op_gt_double(gpointer v1
, LttvFieldValue v2
) {
813 double* r
= (double*) v1
;
814 return (*r
> v2
.v_double
);
818 * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue)
820 * Applies the 'greater or equal' operator to the
821 * specified structure and value
822 * @param v1 left member of comparison
823 * @param v2 right member of comparison
824 * @return success/failure of operation
826 gboolean
lttv_apply_op_ge_uint64(gpointer v1
, LttvFieldValue v2
) {
827 guint64
* r
= (guint64
*) v1
;
828 return (*r
>= v2
.v_uint64
);
832 * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue)
834 * Applies the 'greater or equal' operator to the
835 * specified structure and value
836 * @param v1 left member of comparison
837 * @param v2 right member of comparison
838 * @return success/failure of operation
840 gboolean
lttv_apply_op_ge_uint32(gpointer v1
, LttvFieldValue v2
) {
841 guint32
* r
= (guint32
*) v1
;
842 return (*r
>= v2
.v_uint32
);
846 * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue)
848 * Applies the 'greater or equal' operator to the
849 * specified structure and value
850 * @param v1 left member of comparison
851 * @param v2 right member of comparison
852 * @return success/failure of operation
854 gboolean
lttv_apply_op_ge_uint16(gpointer v1
, LttvFieldValue v2
) {
855 guint16
* r
= (guint16
*) v1
;
856 return (*r
>= v2
.v_uint16
);
860 * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue)
862 * Applies the 'greater or equal' operator to the
863 * specified structure and value
864 * @param v1 left member of comparison
865 * @param v2 right member of comparison
866 * @return success/failure of operation
868 gboolean
lttv_apply_op_ge_double(gpointer v1
, LttvFieldValue v2
) {
869 double* r
= (double*) v1
;
870 return (*r
>= v2
.v_double
);
875 * @fn LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree*)
877 * Makes a copy of the current filter tree
878 * @param tree pointer to the current tree
879 * @return new copy of the filter tree
882 lttv_filter_tree_clone(LttvFilterTree
* tree
) {
884 LttvFilterTree
* newtree
= lttv_filter_tree_new();
886 newtree
->node
= tree
->node
;
888 newtree
->left
= tree
->left
;
889 if(newtree
->left
== LTTV_TREE_NODE
) {
890 newtree
->l_child
.t
= lttv_filter_tree_clone(tree
->l_child
.t
);
891 } else if(newtree
->left
== LTTV_TREE_LEAF
) {
892 newtree
->l_child
.leaf
= lttv_simple_expression_new();
893 newtree
->l_child
.leaf
->field
= tree
->l_child
.leaf
->field
;
894 newtree
->l_child
.leaf
->offset
= tree
->l_child
.leaf
->offset
;
895 newtree
->l_child
.leaf
->op
= tree
->l_child
.leaf
->op
;
896 /* FIXME: special case for string copy ! */
897 newtree
->l_child
.leaf
->value
= tree
->l_child
.leaf
->value
;
900 newtree
->right
= tree
->right
;
901 if(newtree
->right
== LTTV_TREE_NODE
) {
902 newtree
->r_child
.t
= lttv_filter_tree_clone(tree
->r_child
.t
);
903 } else if(newtree
->right
== LTTV_TREE_LEAF
) {
904 newtree
->r_child
.leaf
= lttv_simple_expression_new();
905 newtree
->r_child
.leaf
->field
= tree
->r_child
.leaf
->field
;
906 newtree
->r_child
.leaf
->offset
= tree
->r_child
.leaf
->offset
;
907 newtree
->r_child
.leaf
->op
= tree
->r_child
.leaf
->op
;
908 newtree
->r_child
.leaf
->value
= tree
->r_child
.leaf
->value
;
916 * @fn LttvFilter* lttv_filter_clone(LttvFilter*)
918 * Makes a copy of the current filter
919 * @param filter pointer to the current filter
920 * @return new copy of the filter
923 lttv_filter_clone(LttvFilter
* filter
) {
926 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
928 // newfilter->expression = g_new(char,1)
929 strcpy(newfilter
->expression
,filter
->expression
);
931 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
939 * @fn LttvFilter* lttv_filter_new()
941 * Creates a new lttv_filter
942 * @param expression filtering options string
943 * @param t pointer to the current LttvTrace
944 * @return the current lttv_filter or NULL if error
949 LttvFilter
* filter
= g_new(LttvFilter
,1);
950 filter
->expression
= NULL
;
956 * @fn gboolean lttv_filter_update(LttvFilter*)
958 * Updates the current LttvFilter by building
959 * its tree based upon the expression string
960 * @param filter pointer to the current LttvFilter
961 * @return Failure/Success of operation
964 lttv_filter_update(LttvFilter
* filter
) {
966 g_print("filter::lttv_filter_new()\n"); /* debug */
968 if(filter
->expression
== NULL
) return FALSE
;
972 p_nesting
=0; /* parenthesis nesting value */
976 *tree
= lttv_filter_tree_new(), /* main tree */
977 *subtree
= NULL
, /* buffer for subtrees */
983 * If the tree already exists,
984 * destroy it and build a new one
986 if(filter
->head
!= NULL
) lttv_filter_tree_destroy(filter
->head
);
987 filter
->head
= NULL
; /* will be assigned at the end */
991 * each element of the list
992 * is a sub tree created
993 * by the use of parenthesis in the
994 * global expression. The final tree
995 * will be the one left at the root of
998 GPtrArray
*tree_stack
= g_ptr_array_new();
999 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
1001 /* temporary values */
1002 GString
*a_field_component
= g_string_new("");
1003 GPtrArray
*a_field_path
= g_ptr_array_new();
1005 /* simple expression buffer */
1006 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
1009 * Parse entire expression and construct
1010 * the binary tree. There are two steps
1011 * in browsing that string
1012 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
1013 * 2. finding simple expressions
1014 * - field path ( separated by dots )
1015 * - op ( >, <, =, >=, <=, !=)
1016 * - value ( integer, string ... )
1017 * To spare computing time, the whole
1018 * string is parsed in this loop for a
1019 * O(n) complexity order.
1021 * When encountering logical op &,|,^
1022 * 1. parse the last value if any
1023 * 2. create a new tree
1024 * 3. add the expression (simple exp, or exp (subtree)) to the tree
1025 * 4. concatenate this tree with the current tree on top of the stack
1026 * When encountering math ops >,>=,<,<=,=,!=
1027 * 1. add to op to the simple expression
1028 * 2. concatenate last field component to field path
1029 * When encountering concatening ops .
1030 * 1. concatenate last field component to field path
1031 * When encountering opening parenthesis (,{,[
1032 * 1. create a new subtree on top of tree stack
1033 * When encountering closing parenthesis ),},]
1034 * 1. add the expression on right child of the current tree
1035 * 2. the subtree is completed, allocate a new subtree
1036 * 3. pop the tree value from the tree stack
1039 // g_print("expression: %s\n",filter->expression);
1040 // g_print("strlen(expression): %i\n",strlen(filter->expression));
1041 for(i
=0;i
<strlen(filter
->expression
);i
++) {
1043 g_print("%c ",filter
->expression
[i
]);
1044 switch(filter
->expression
[i
]) {
1050 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1051 while(t1
->right
!= LTTV_TREE_IDLE
) {
1052 g_assert(t1
->right
== LTTV_TREE_NODE
);
1055 t2
= lttv_filter_tree_new();
1056 t2
->node
= LTTV_LOGICAL_AND
;
1057 if(subtree
!= NULL
) { /* append subtree to current tree */
1058 t2
->left
= LTTV_TREE_NODE
;
1059 t2
->l_child
.t
= subtree
;
1061 t1
->right
= LTTV_TREE_NODE
;
1063 } else { /* append a simple expression */
1064 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1065 // a_simple_expression->value = g_string_free(a_field_component,FALSE);
1066 a_field_component
= g_string_new("");
1067 t2
->left
= LTTV_TREE_LEAF
;
1068 t2
->l_child
.leaf
= a_simple_expression
;
1069 a_simple_expression
= lttv_simple_expression_new();
1070 t1
->right
= LTTV_TREE_NODE
;
1072 g_print("t1:%p t1->child:%p\n",t1
,t1
->r_child
.t
);
1078 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1079 while(t1
->right
!= LTTV_TREE_IDLE
) {
1080 g_assert(t1
->right
== LTTV_TREE_NODE
);
1083 t2
= lttv_filter_tree_new();
1084 t2
->node
= LTTV_LOGICAL_OR
;
1085 if(subtree
!= NULL
) { /* append subtree to current tree */
1086 t2
->left
= LTTV_TREE_NODE
;
1087 t2
->l_child
.t
= subtree
;
1089 t1
->right
= LTTV_TREE_NODE
;
1091 } else { /* append a simple expression */
1092 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1093 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1094 a_field_component
= g_string_new("");
1095 t2
->left
= LTTV_TREE_LEAF
;
1096 t2
->l_child
.leaf
= a_simple_expression
;
1097 a_simple_expression
= lttv_simple_expression_new();
1098 t1
->right
= LTTV_TREE_NODE
;
1105 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1106 while(t1
->right
!= LTTV_TREE_IDLE
) {
1107 g_assert(t1
->right
== LTTV_TREE_NODE
);
1110 t2
= lttv_filter_tree_new();
1111 t2
->node
= LTTV_LOGICAL_XOR
;
1112 if(subtree
!= NULL
) { /* append subtree to current tree */
1113 t2
->left
= LTTV_TREE_NODE
;
1114 t2
->l_child
.t
= subtree
;
1116 t1
->right
= LTTV_TREE_NODE
;
1118 } else { /* append a simple expression */
1119 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1120 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1121 a_field_component
= g_string_new("");
1122 t2
->left
= LTTV_TREE_LEAF
;
1123 t2
->l_child
.leaf
= a_simple_expression
;
1124 a_simple_expression
= lttv_simple_expression_new();
1125 t1
->right
= LTTV_TREE_NODE
;
1130 case '!': /* not, or not equal (math op) */
1132 if(filter
->expression
[i
+1] == '=') { /* != */
1133 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1134 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1135 a_field_component
= g_string_new("");
1136 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_NE
);
1139 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1140 while(t1
->right
!= LTTV_TREE_IDLE
) {
1141 g_assert(t1
->right
== LTTV_TREE_NODE
);
1144 t2
= lttv_filter_tree_new();
1145 t2
->node
= LTTV_LOGICAL_NOT
;
1146 t1
->right
= LTTV_TREE_NODE
;
1151 case '(': /* start of parenthesis */
1155 p_nesting
++; /* incrementing parenthesis nesting value */
1156 t1
= lttv_filter_tree_new();
1157 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
1160 case ')': /* end of parenthesis */
1164 p_nesting
--; /* decrementing parenthesis nesting value */
1165 if(p_nesting
<0 || tree_stack
->len
<2) {
1166 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1167 is not valid due to parenthesis incorrect use",filter
->expression
);
1171 /* there must at least be the root tree left in the array */
1172 g_assert(tree_stack
->len
>0);
1174 if(subtree
!= NULL
) { /* append subtree to current tree */
1175 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1176 while(t1
->right
!= LTTV_TREE_IDLE
) {
1177 g_assert(t1
->right
== LTTV_TREE_NODE
);
1180 t1
->right
= LTTV_TREE_NODE
;
1181 t1
->r_child
.t
= subtree
;
1182 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1183 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1184 } else { /* assign subtree as current tree */
1185 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1186 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1187 a_field_component
= g_string_new("");
1188 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1189 while(t1
->right
!= LTTV_TREE_IDLE
) {
1190 g_print("while right:%i %p->child:%p\n",t1
->right
,t1
,t1
->r_child
.t
);
1191 g_assert(t1
->right
== LTTV_TREE_NODE
);
1192 g_assert(t1
->r_child
.t
!= NULL
);
1195 t1
->right
= LTTV_TREE_LEAF
;
1196 t1
->r_child
.leaf
= a_simple_expression
;
1197 a_simple_expression
= lttv_simple_expression_new();
1198 subtree
= g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1203 * mathematic operators
1205 case '<': /* lower, lower or equal */
1207 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1208 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1209 a_field_component
= g_string_new("");
1210 if(filter
->expression
[i
+1] == '=') { /* <= */
1212 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LE
);
1213 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LT
);
1216 case '>': /* higher, higher or equal */
1218 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1219 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1220 a_field_component
= g_string_new("");
1221 if(filter
->expression
[i
+1] == '=') { /* >= */
1223 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GE
);
1224 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GT
);
1227 case '=': /* equal */
1229 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1230 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1231 a_field_component
= g_string_new("");
1232 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1236 * Field concatening caracter
1241 * divide field expression into elements
1242 * in a_field_path array.
1244 /* FIXME: check for double values */
1245 if(a_simple_expression
->field
== LTTV_FILTER_UNDEFINED
) {
1246 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1247 a_field_component
= g_string_new("");
1253 default: /* concatening current string */
1254 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1258 // g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree,tree,t1,t2);
1259 // g_print("stack size: %i\n",tree_stack->len);
1262 * Preliminary check to see
1263 * if tree was constructed correctly
1266 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1267 is not valid due to parenthesis incorrect use",filter
->expression
);
1271 if(tree_stack
->len
!= 1) /* only root tree should remain */
1274 /* processing last element of expression */
1275 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1276 while(t1
->right
!= LTTV_TREE_IDLE
) {
1277 g_assert(t1
->right
== LTTV_TREE_NODE
);
1280 if(subtree
!= NULL
) { /* add the subtree */
1281 t1
->right
= LTTV_TREE_NODE
;
1282 t1
->r_child
.t
= subtree
;
1284 } else { /* add a leaf */
1285 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1286 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1287 a_field_component
= NULL
;
1288 t1
->right
= LTTV_TREE_LEAF
;
1289 t1
->r_child
.leaf
= a_simple_expression
;
1290 a_simple_expression
= NULL
;
1294 /* free the pointer array */
1295 g_assert(a_field_path
->len
== 0);
1296 g_ptr_array_free(a_field_path
,TRUE
);
1298 /* free the tree stack -- but keep the root tree */
1299 // g_ptr_array_free(tree_stack,FALSE);
1300 filter
->head
= g_ptr_array_remove_index(tree_stack
,0);
1301 g_ptr_array_free(tree_stack
,TRUE
);
1303 /* free the field buffer if allocated */
1304 if(a_field_component
!= NULL
) g_string_free(a_field_component
,TRUE
);
1306 /* free the simple expression buffer if allocated */
1307 if(a_simple_expression
!= NULL
) lttv_simple_expression_destroy(a_simple_expression
);
1309 g_assert(filter
->head
!= NULL
); /* tree should exist */
1310 g_assert(subtree
== NULL
); /* remaining subtree should be included in main tree */
1313 g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1314 lttv_print_tree(filter
->head
) ;
1315 g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1323 * @fn void lttv_filter_destroy(LttvFilter*)
1325 * Destroy the current LttvFilter
1326 * @param filter pointer to the current LttvFilter
1329 lttv_filter_destroy(LttvFilter
* filter
) {
1331 g_free(filter
->expression
);
1332 lttv_filter_tree_destroy(filter
->head
);
1338 * @fn LttvFilterTree* lttv_filter_tree_new()
1340 * Assign a new tree for the current expression
1342 * @return pointer of LttvFilterTree
1345 lttv_filter_tree_new() {
1346 LttvFilterTree
* tree
;
1348 tree
= g_new(LttvFilterTree
,1);
1349 tree
->node
= 0; //g_new(lttv_expression,1);
1350 tree
->left
= LTTV_TREE_IDLE
;
1351 tree
->right
= LTTV_TREE_IDLE
;
1352 tree
->r_child
.t
= NULL
;
1353 tree
->l_child
.t
= NULL
;
1359 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1361 * Append a new expression to the expression
1362 * defined in the current filter
1363 * @param filter pointer to the current LttvFilter
1364 * @param expression string that must be appended
1365 * @return Success/Failure of operation
1367 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, char *expression
) {
1369 if(expression
== NULL
) return FALSE
;
1370 if(filter
== NULL
) {
1371 filter
= lttv_filter_new();
1372 filter
->expression
= expression
;
1373 } else if(filter
->expression
== NULL
) {
1374 filter
->expression
= expression
;
1376 filter
->expression
= g_strconcat(filter
->expression
,"&",expression
);
1379 return lttv_filter_update(filter
);
1384 * @fn void lttv_filter_clear_expression(LttvFilter*)
1386 * Clear the filter expression from the
1387 * current filter and sets its pointer to NULL
1388 * @param filter pointer to the current LttvFilter
1390 void lttv_filter_clear_expression(LttvFilter
* filter
) {
1392 if(filter
->expression
!= NULL
) {
1393 g_free(filter
->expression
);
1394 filter
->expression
= NULL
;
1400 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1402 * Destroys the tree and his sub-trees
1403 * @param tree Tree which must be destroyed
1406 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1408 if(tree
== NULL
) return;
1410 if(tree
->left
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->l_child
.leaf
);
1411 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1413 if(tree
->right
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->r_child
.leaf
);
1414 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1416 // g_free(tree->node);
1421 * @fn gboolean lttv_filter_tree_parse(LttvFilterTree*,LttEvent,LttTracefile,LttTrace,LttvProcessState)
1423 * Global parsing function for the current
1425 * @param tree pointer to the current LttvFilterTree
1426 * @param event current LttEvent, NULL if not used
1427 * @param tracefile current LttTracefile, NULL if not used
1428 * @param trace current LttTrace, NULL if not used
1429 * @param state current LttvProcessState, NULL if not used
1432 lttv_filter_tree_parse(
1435 LttTracefile
* tracefile
,
1437 LttvProcessState
* state
1442 * Each tree is parsed in inorder.
1443 * This way, it's possible to apply the left filter of the
1444 * tree, then decide whether or not the right branch should
1445 * be parsed depending on the linking logical operator
1447 * Each node consists in a
1448 * 1. logical operator
1449 * 2. left child ( node or simple expression )
1450 * 3. right child ( node or simple expression )
1452 * When the child is a simple expression, we must
1453 * before all determine if the expression refers to
1454 * a structure which is whithin observation ( not NULL ).
1455 * -If so, the expression is evaluated.
1456 * -If not, the result is set to TRUE since this particular
1457 * operation does not interfere with the lttv structure
1459 * The result of each simple expression will directly
1460 * affect the next branch. This way, depending on
1461 * the linking logical operator, the parser will decide
1462 * to explore or not the next branch.
1464 * -If result of left branch is 0 / FALSE
1465 * then don't explore right branch and return 0;
1466 * -If result of left branch is 1 / TRUE then explore
1468 * -If result of left branch is 1 / TRUE
1469 * then don't explore right branch and return 1;
1470 * -If result of left branch is 0 / FALSE then explore
1472 * -Result of left branch will not affect exploration of
1475 g_print("filter::lttv_parse_tree(...)\n");
1477 gboolean lresult
= FALSE
, rresult
= FALSE
;
1482 if(t
->left
== LTTV_TREE_NODE
) lresult
= lttv_filter_tree_parse(t
->l_child
.t
,event
,tracefile
,trace
,state
);
1483 else if(t
->left
== LTTV_TREE_LEAF
) {
1484 //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);
1486 v
= t
->l_child
.leaf
->value
;
1487 switch(t
->l_child
.leaf
->field
) {
1489 case LTTV_FILTER_TRACE_NAME
:
1490 if(trace
== NULL
) lresult
= TRUE
;
1491 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_trace_name(trace
),v
);
1493 case LTTV_FILTER_TRACEFILE_NAME
:
1494 if(tracefile
== NULL
) lresult
= TRUE
;
1495 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_tracefile_name(tracefile
),v
);
1497 case LTTV_FILTER_STATE_PID
:
1498 if(state
== NULL
) lresult
= TRUE
;
1499 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1501 case LTTV_FILTER_STATE_PPID
:
1502 if(state
== NULL
) lresult
= TRUE
;
1503 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1505 case LTTV_FILTER_STATE_CT
:
1506 if(state
== NULL
) lresult
= TRUE
;
1508 double val
= ltt_time_to_double(state
->creation_time
);
1509 lresult
= t
->l_child
.leaf
->op((gpointer
)&val
,v
);
1512 case LTTV_FILTER_STATE_IT
:
1513 if(state
== NULL
) lresult
= TRUE
;
1515 double val
= ltt_time_to_double(state
->insertion_time
);
1516 lresult
= t
->l_child
.leaf
->op((gpointer
)&val
,v
);
1519 case LTTV_FILTER_STATE_P_NAME
:
1521 * FIXME: Yet to be done ( I think ? )
1525 case LTTV_FILTER_STATE_EX_MODE
:
1526 if(state
== NULL
) lresult
= TRUE
;
1527 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->t
,v
);
1529 case LTTV_FILTER_STATE_EX_SUBMODE
:
1530 if(state
== NULL
) lresult
= TRUE
;
1531 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->n
,v
);
1533 case LTTV_FILTER_STATE_P_STATUS
:
1534 if(state
== NULL
) lresult
= TRUE
;
1535 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->s
,v
);
1537 case LTTV_FILTER_STATE_CPU
:
1539 * FIXME: What is the comparison value ?
1543 case LTTV_FILTER_EVENT_NAME
:
1544 if(event
== NULL
) lresult
= TRUE
;
1545 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_event_eventtype(event
),v
);
1548 case LTTV_FILTER_EVENT_CATEGORY
:
1550 * FIXME: Not yet implemented
1554 case LTTV_FILTER_EVENT_TIME
:
1555 // if(event == NULL) lresult = TRUE;
1557 // double val = ltt_time_to_double(event->event_time);
1558 // lresult = t->l_child.leaf->op((gpointer)&val,v);
1562 case LTTV_FILTER_EVENT_TSC
:
1563 // if(event == NULL) lresult = TRUE;
1565 // double val = ltt_time_to_double(event->event_time);
1566 // lresult = t->l_child.leaf->op((gpointer)&val,v);
1569 * FIXME: Where is event.tsc
1573 case LTTV_FILTER_EVENT_FIELD
:
1575 * TODO: Use the offset to
1576 * find the dynamic field
1577 * in the event struct
1582 * This case should never be
1583 * parsed, if so, the whole
1584 * filtering is cancelled
1586 g_warning("Error while parsing the filter tree");
1592 * Parse linking operator
1593 * make a cutoff if possible
1595 if((t
->node
& LTTV_LOGICAL_OR
) && lresult
== TRUE
) return TRUE
;
1596 if((t
->node
& LTTV_LOGICAL_AND
) && lresult
== FALSE
) return FALSE
;
1599 * Parse right branch
1601 if(t
->right
== LTTV_TREE_NODE
) rresult
= lttv_filter_tree_parse(t
->r_child
.t
,event
,tracefile
,trace
,state
);
1602 else if(t
->right
== LTTV_TREE_LEAF
) {
1603 //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);
1605 v
= t
->r_child
.leaf
->value
;
1606 switch(t
->r_child
.leaf
->field
) {
1608 case LTTV_FILTER_TRACE_NAME
:
1609 if(trace
== NULL
) rresult
= TRUE
;
1610 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_trace_name(trace
),v
);
1612 case LTTV_FILTER_TRACEFILE_NAME
:
1613 if(tracefile
== NULL
) rresult
= TRUE
;
1614 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_tracefile_name(tracefile
),v
);
1616 case LTTV_FILTER_STATE_PID
:
1617 if(state
== NULL
) rresult
= TRUE
;
1618 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1620 case LTTV_FILTER_STATE_PPID
:
1621 if(state
== NULL
) rresult
= TRUE
;
1622 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1624 case LTTV_FILTER_STATE_CT
:
1625 if(state
== NULL
) rresult
= TRUE
;
1627 double val
= ltt_time_to_double(state
->creation_time
);
1628 rresult
= t
->r_child
.leaf
->op((gpointer
)&val
,v
);
1631 case LTTV_FILTER_STATE_IT
:
1632 if(state
== NULL
) rresult
= TRUE
;
1634 double val
= ltt_time_to_double(state
->insertion_time
);
1635 rresult
= t
->r_child
.leaf
->op((gpointer
)&val
,v
);
1638 case LTTV_FILTER_STATE_P_NAME
:
1640 * FIXME: Yet to be done ( I think ? )
1644 case LTTV_FILTER_STATE_EX_MODE
:
1645 if(state
== NULL
) rresult
= TRUE
;
1646 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->t
,v
);
1648 case LTTV_FILTER_STATE_EX_SUBMODE
:
1649 if(state
== NULL
) rresult
= TRUE
;
1650 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->n
,v
);
1652 case LTTV_FILTER_STATE_P_STATUS
:
1653 if(state
== NULL
) rresult
= TRUE
;
1654 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->s
,v
);
1656 case LTTV_FILTER_STATE_CPU
:
1658 * FIXME: What is the comparison value ?
1662 case LTTV_FILTER_EVENT_NAME
:
1663 if(event
== NULL
) rresult
= TRUE
;
1664 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_event_eventtype(event
),v
);
1667 case LTTV_FILTER_EVENT_CATEGORY
:
1669 * FIXME: Not yet implemented
1673 case LTTV_FILTER_EVENT_TIME
:
1674 // if(event == NULL) rresult = TRUE;
1676 // double val = ltt_time_to_double(event->event_time);
1677 // rresult = t->r_child.leaf->op((gpointer)&val,v);
1681 case LTTV_FILTER_EVENT_TSC
:
1682 // if(event == NULL) rresult = TRUE;
1684 // double val = ltt_time_to_double(event->event_time);
1685 // rresult = t->r_child.leaf->op((gpointer)&val,v);
1688 * FIXME: Where is event.tsc
1692 case LTTV_FILTER_EVENT_FIELD
:
1694 * TODO: Use the offset to
1695 * find the dynamic field
1696 * in the event struct
1701 * This case should never be
1702 * parsed, if so, this subtree
1705 g_warning("Error while parsing the filter tree");
1711 * Apply and return the
1712 * logical link between the
1716 case LTTV_LOGICAL_OR
: return (lresult
| rresult
);
1717 case LTTV_LOGICAL_AND
: return (lresult
& rresult
);
1718 case LTTV_LOGICAL_NOT
: return (!rresult
);
1719 case LTTV_LOGICAL_XOR
: return (lresult
^ rresult
);
1720 case 0: return (rresult
);
1723 * This case should never be
1724 * parsed, if so, this subtree
1733 * @fn void lttv_print_tree(LttvFilterTree*)
1736 * @param t the pointer to the current LttvFilterTree
1739 lttv_print_tree(LttvFilterTree
* t
) {
1741 g_print("node:%p lchild:%p rchild:%p\n",t
, //t->l_child.t,t->r_child.t);
1742 (t
->left
==LTTV_TREE_NODE
)?t
->l_child
.t
:NULL
,
1743 (t
->right
==LTTV_TREE_NODE
)?t
->r_child
.t
:NULL
);
1744 g_print("node type: %i / [left] %i / [right] %i\n",t
->node
,t
->left
,t
->right
);
1745 if(t
->left
== LTTV_TREE_NODE
) lttv_print_tree(t
->l_child
.t
);
1746 else if(t
->left
== LTTV_TREE_LEAF
) {
1747 // g_assert(t->l_child.leaf->value != NULL);
1748 g_print("%p: left is %i %p value\n",t
,t
->l_child
.leaf
->field
,t
->l_child
.leaf
->op
);
1750 if(t
->right
== LTTV_TREE_NODE
) lttv_print_tree(t
->r_child
.t
);
1751 else if(t
->right
== LTTV_TREE_LEAF
) {
1752 // g_assert(t->r_child.leaf->value != NULL);
1753 g_print("%p: right is %i %p value\n",t
,t
->r_child
.leaf
->field
,t
->r_child
.leaf
->op
);
1759 * @fn gboolean lttv_filter_tracefile(LttvFilter*, LttTracefile*)
1761 * Apply the filter to a specific trace
1762 * @param filter the current filter applied
1763 * @param tracefile the trace to apply the filter to
1764 * @return success/failure of operation
1767 lttv_filter_tracefile(LttvFilter
*filter
, LttTracefile
*tracefile
) {
1769 return lttv_filter_tree_parse(filter
->head
,NULL
,tracefile
,NULL
,NULL
);
1774 * @fn gboolean lttv_filter_tracestate(LttvFilter*,LttvTraceState*)
1776 * Parse the current tracestate
1777 * @param filter pointer to the current LttvFilter
1778 * @param tracestate pointer to the current tracestate
1781 lttv_filter_tracestate(LttvFilter
*filter
, LttvTraceState
*tracestate
) {
1786 * @fn gboolean lttv_filter_event(LttvFilter*,LttEvent*)
1788 * Apply the filter to a specific event
1789 * @param filter the current filter applied
1790 * @param event the event to apply the filter to
1791 * @return success/failure of operation
1794 lttv_filter_event(LttvFilter
*filter
, LttEvent
*event
) {
1799 * @fn static void module_init()
1801 * Initializes the filter module and specific values
1803 static void module_init()
1809 * @fn Destroys the filter module and specific values
1811 static void module_destroy()
1817 LTTV_MODULE("filter", "Filters traceset and events", \
1818 "Filters traceset and events specifically to user input", \
1819 module_init
, module_destroy
)