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);
1190 while(t1
->right
!= LTTV_TREE_IDLE
) {
1191 g_print("while right:%i %p->child:%p\n",t1
->right
,t1
,t1
->r_child
.t
);
1192 g_assert(t1
->right
== LTTV_TREE_NODE
);
1193 g_assert(t1
->r_child
.t
!= NULL
);
1197 t1
->right
= LTTV_TREE_LEAF
;
1198 t1
->r_child
.leaf
= a_simple_expression
;
1199 a_simple_expression
= lttv_simple_expression_new();
1200 subtree
= g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1205 * mathematic operators
1207 case '<': /* lower, lower or equal */
1209 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1210 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1211 a_field_component
= g_string_new("");
1212 if(filter
->expression
[i
+1] == '=') { /* <= */
1214 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LE
);
1215 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LT
);
1218 case '>': /* higher, higher or equal */
1220 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1221 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1222 a_field_component
= g_string_new("");
1223 if(filter
->expression
[i
+1] == '=') { /* >= */
1225 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GE
);
1226 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GT
);
1229 case '=': /* equal */
1231 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1232 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1233 a_field_component
= g_string_new("");
1234 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1238 * Field concatening caracter
1243 * divide field expression into elements
1244 * in a_field_path array.
1246 /* FIXME: check for double values */
1247 if(a_simple_expression
->field
== LTTV_FILTER_UNDEFINED
) {
1248 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1249 a_field_component
= g_string_new("");
1255 default: /* concatening current string */
1256 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1260 g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree
,tree
,t1
,t2
);
1261 g_print("stack size: %i\n",tree_stack
->len
);
1264 * Preliminary check to see
1265 * if tree was constructed correctly
1268 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1269 is not valid due to parenthesis incorrect use",filter
->expression
);
1273 if(tree_stack
->len
!= 1) /* only root tree should remain */
1276 /* processing last element of expression */
1277 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1278 while(t1
->right
!= LTTV_TREE_IDLE
) {
1279 g_assert(t1
->right
== LTTV_TREE_NODE
);
1282 if(subtree
!= NULL
) { /* add the subtree */
1283 t1
->right
= LTTV_TREE_NODE
;
1284 t1
->r_child
.t
= subtree
;
1286 } else { /* add a leaf */
1287 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1288 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1289 a_field_component
= NULL
;
1290 t1
->right
= LTTV_TREE_LEAF
;
1291 t1
->r_child
.leaf
= a_simple_expression
;
1292 a_simple_expression
= NULL
;
1296 /* free the pointer array */
1297 g_assert(a_field_path
->len
== 0);
1298 g_ptr_array_free(a_field_path
,TRUE
);
1300 /* free the tree stack -- but keep the root tree */
1301 // g_ptr_array_free(tree_stack,FALSE);
1302 filter
->head
= g_ptr_array_remove_index(tree_stack
,0);
1303 g_ptr_array_free(tree_stack
,TRUE
);
1305 /* free the field buffer if allocated */
1306 if(a_field_component
!= NULL
) g_string_free(a_field_component
,TRUE
);
1308 /* free the simple expression buffer if allocated */
1309 if(a_simple_expression
!= NULL
) lttv_simple_expression_destroy(a_simple_expression
);
1311 g_assert(filter
->head
!= NULL
); /* tree should exist */
1312 g_assert(subtree
== NULL
); /* remaining subtree should be included in main tree */
1315 g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1316 lttv_print_tree(filter
->head
) ;
1317 g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1325 * @fn void lttv_filter_destroy(LttvFilter*)
1327 * Destroy the current LttvFilter
1328 * @param filter pointer to the current LttvFilter
1331 lttv_filter_destroy(LttvFilter
* filter
) {
1333 g_free(filter
->expression
);
1334 lttv_filter_tree_destroy(filter
->head
);
1340 * @fn LttvFilterTree* lttv_filter_tree_new()
1342 * Assign a new tree for the current expression
1344 * @return pointer of LttvFilterTree
1347 lttv_filter_tree_new() {
1348 LttvFilterTree
* tree
;
1350 tree
= g_new(LttvFilterTree
,1);
1351 tree
->node
= 0; //g_new(lttv_expression,1);
1352 tree
->left
= LTTV_TREE_IDLE
;
1353 tree
->right
= LTTV_TREE_IDLE
;
1354 tree
->r_child
.t
= NULL
;
1355 tree
->l_child
.t
= NULL
;
1361 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1363 * Append a new expression to the expression
1364 * defined in the current filter
1365 * @param filter pointer to the current LttvFilter
1366 * @param expression string that must be appended
1367 * @return Success/Failure of operation
1369 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, char *expression
) {
1371 if(expression
== NULL
) return FALSE
;
1372 if(filter
== NULL
) {
1373 filter
= lttv_filter_new();
1374 filter
->expression
= expression
;
1375 } else if(filter
->expression
== NULL
) {
1376 filter
->expression
= expression
;
1378 filter
->expression
= g_strconcat(filter
->expression
,"&",expression
);
1381 return lttv_filter_update(filter
);
1386 * @fn void lttv_filter_clear_expression(LttvFilter*)
1388 * Clear the filter expression from the
1389 * current filter and sets its pointer to NULL
1390 * @param filter pointer to the current LttvFilter
1392 void lttv_filter_clear_expression(LttvFilter
* filter
) {
1394 if(filter
->expression
!= NULL
) {
1395 g_free(filter
->expression
);
1396 filter
->expression
= NULL
;
1402 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1404 * Destroys the tree and his sub-trees
1405 * @param tree Tree which must be destroyed
1408 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1410 if(tree
== NULL
) return;
1412 if(tree
->left
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->l_child
.leaf
);
1413 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1415 if(tree
->right
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->r_child
.leaf
);
1416 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1418 // g_free(tree->node);
1423 * @fn gboolean lttv_filter_tree_parse(LttvFilterTree*,LttEvent,LttTracefile,LttTrace,LttvProcessState)
1425 * Global parsing function for the current
1427 * @param tree pointer to the current LttvFilterTree
1428 * @param event current LttEvent, NULL if not used
1429 * @param tracefile current LttTracefile, NULL if not used
1430 * @param trace current LttTrace, NULL if not used
1431 * @param state current LttvProcessState, NULL if not used
1434 lttv_filter_tree_parse(
1437 LttTracefile
* tracefile
,
1439 LttvProcessState
* state
1444 * Each tree is parsed in inorder.
1445 * This way, it's possible to apply the left filter of the
1446 * tree, then decide whether or not the right branch should
1447 * be parsed depending on the linking logical operator
1449 * Each node consists in a
1450 * 1. logical operator
1451 * 2. left child ( node or simple expression )
1452 * 3. right child ( node or simple expression )
1454 * When the child is a simple expression, we must
1455 * before all determine if the expression refers to
1456 * a structure which is whithin observation ( not NULL ).
1457 * -If so, the expression is evaluated.
1458 * -If not, the result is set to TRUE since this particular
1459 * operation does not interfere with the lttv structure
1461 * The result of each simple expression will directly
1462 * affect the next branch. This way, depending on
1463 * the linking logical operator, the parser will decide
1464 * to explore or not the next branch.
1466 * -If result of left branch is 0 / FALSE
1467 * then don't explore right branch and return 0;
1468 * -If result of left branch is 1 / TRUE then explore
1470 * -If result of left branch is 1 / TRUE
1471 * then don't explore right branch and return 1;
1472 * -If result of left branch is 0 / FALSE then explore
1474 * -Result of left branch will not affect exploration of
1477 g_print("filter::lttv_parse_tree(...)\n");
1479 gboolean lresult
= FALSE
, rresult
= FALSE
;
1484 if(t
->left
== LTTV_TREE_NODE
) lresult
= lttv_filter_tree_parse(t
->l_child
.t
,event
,tracefile
,trace
,state
);
1485 else if(t
->left
== LTTV_TREE_LEAF
) {
1486 //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);
1488 v
= t
->l_child
.leaf
->value
;
1489 switch(t
->l_child
.leaf
->field
) {
1491 case LTTV_FILTER_TRACE_NAME
:
1492 if(trace
== NULL
) lresult
= TRUE
;
1493 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_trace_name(trace
),v
);
1495 case LTTV_FILTER_TRACEFILE_NAME
:
1496 if(tracefile
== NULL
) lresult
= TRUE
;
1497 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_tracefile_name(tracefile
),v
);
1499 case LTTV_FILTER_STATE_PID
:
1500 if(state
== NULL
) lresult
= TRUE
;
1501 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1503 case LTTV_FILTER_STATE_PPID
:
1504 if(state
== NULL
) lresult
= TRUE
;
1505 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1507 case LTTV_FILTER_STATE_CT
:
1508 if(state
== NULL
) lresult
= TRUE
;
1510 double val
= ltt_time_to_double(state
->creation_time
);
1511 lresult
= t
->l_child
.leaf
->op((gpointer
)&val
,v
);
1514 case LTTV_FILTER_STATE_IT
:
1515 if(state
== NULL
) lresult
= TRUE
;
1517 double val
= ltt_time_to_double(state
->insertion_time
);
1518 lresult
= t
->l_child
.leaf
->op((gpointer
)&val
,v
);
1521 case LTTV_FILTER_STATE_P_NAME
:
1523 * FIXME: Yet to be done ( I think ? )
1527 case LTTV_FILTER_STATE_EX_MODE
:
1528 if(state
== NULL
) lresult
= TRUE
;
1529 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->t
,v
);
1531 case LTTV_FILTER_STATE_EX_SUBMODE
:
1532 if(state
== NULL
) lresult
= TRUE
;
1533 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->n
,v
);
1535 case LTTV_FILTER_STATE_P_STATUS
:
1536 if(state
== NULL
) lresult
= TRUE
;
1537 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->s
,v
);
1539 case LTTV_FILTER_STATE_CPU
:
1541 * FIXME: What is the comparison value ?
1545 case LTTV_FILTER_EVENT_NAME
:
1546 if(event
== NULL
) lresult
= TRUE
;
1547 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_event_eventtype(event
),v
);
1550 case LTTV_FILTER_EVENT_CATEGORY
:
1552 * FIXME: Not yet implemented
1556 case LTTV_FILTER_EVENT_TIME
:
1557 // if(event == NULL) lresult = TRUE;
1559 // double val = ltt_time_to_double(event->event_time);
1560 // lresult = t->l_child.leaf->op((gpointer)&val,v);
1564 case LTTV_FILTER_EVENT_TSC
:
1565 // if(event == NULL) lresult = TRUE;
1567 // double val = ltt_time_to_double(event->event_time);
1568 // lresult = t->l_child.leaf->op((gpointer)&val,v);
1571 * FIXME: Where is event.tsc
1575 case LTTV_FILTER_EVENT_FIELD
:
1577 * TODO: Use the offset to
1578 * find the dynamic field
1579 * in the event struct
1584 * This case should never be
1585 * parsed, if so, the whole
1586 * filtering is cancelled
1588 g_warning("Error while parsing the filter tree");
1594 * Parse linking operator
1595 * make a cutoff if possible
1597 if((t
->node
& LTTV_LOGICAL_OR
) && lresult
== TRUE
) return TRUE
;
1598 if((t
->node
& LTTV_LOGICAL_AND
) && lresult
== FALSE
) return FALSE
;
1601 * Parse right branch
1603 if(t
->right
== LTTV_TREE_NODE
) rresult
= lttv_filter_tree_parse(t
->r_child
.t
,event
,tracefile
,trace
,state
);
1604 else if(t
->right
== LTTV_TREE_LEAF
) {
1605 //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);
1607 v
= t
->r_child
.leaf
->value
;
1608 switch(t
->r_child
.leaf
->field
) {
1610 case LTTV_FILTER_TRACE_NAME
:
1611 if(trace
== NULL
) rresult
= TRUE
;
1612 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_trace_name(trace
),v
);
1614 case LTTV_FILTER_TRACEFILE_NAME
:
1615 if(tracefile
== NULL
) rresult
= TRUE
;
1616 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_tracefile_name(tracefile
),v
);
1618 case LTTV_FILTER_STATE_PID
:
1619 if(state
== NULL
) rresult
= TRUE
;
1620 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1622 case LTTV_FILTER_STATE_PPID
:
1623 if(state
== NULL
) rresult
= TRUE
;
1624 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1626 case LTTV_FILTER_STATE_CT
:
1627 if(state
== NULL
) rresult
= TRUE
;
1629 double val
= ltt_time_to_double(state
->creation_time
);
1630 rresult
= t
->r_child
.leaf
->op((gpointer
)&val
,v
);
1633 case LTTV_FILTER_STATE_IT
:
1634 if(state
== NULL
) rresult
= TRUE
;
1636 double val
= ltt_time_to_double(state
->insertion_time
);
1637 rresult
= t
->r_child
.leaf
->op((gpointer
)&val
,v
);
1640 case LTTV_FILTER_STATE_P_NAME
:
1642 * FIXME: Yet to be done ( I think ? )
1646 case LTTV_FILTER_STATE_EX_MODE
:
1647 if(state
== NULL
) rresult
= TRUE
;
1648 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->t
,v
);
1650 case LTTV_FILTER_STATE_EX_SUBMODE
:
1651 if(state
== NULL
) rresult
= TRUE
;
1652 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->n
,v
);
1654 case LTTV_FILTER_STATE_P_STATUS
:
1655 if(state
== NULL
) rresult
= TRUE
;
1656 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->s
,v
);
1658 case LTTV_FILTER_STATE_CPU
:
1660 * FIXME: What is the comparison value ?
1664 case LTTV_FILTER_EVENT_NAME
:
1665 if(event
== NULL
) rresult
= TRUE
;
1666 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_event_eventtype(event
),v
);
1669 case LTTV_FILTER_EVENT_CATEGORY
:
1671 * FIXME: Not yet implemented
1675 case LTTV_FILTER_EVENT_TIME
:
1676 // if(event == NULL) rresult = TRUE;
1678 // double val = ltt_time_to_double(event->event_time);
1679 // rresult = t->r_child.leaf->op((gpointer)&val,v);
1683 case LTTV_FILTER_EVENT_TSC
:
1684 // if(event == NULL) rresult = TRUE;
1686 // double val = ltt_time_to_double(event->event_time);
1687 // rresult = t->r_child.leaf->op((gpointer)&val,v);
1690 * FIXME: Where is event.tsc
1694 case LTTV_FILTER_EVENT_FIELD
:
1696 * TODO: Use the offset to
1697 * find the dynamic field
1698 * in the event struct
1703 * This case should never be
1704 * parsed, if so, this subtree
1707 g_warning("Error while parsing the filter tree");
1713 * Apply and return the
1714 * logical link between the
1718 case LTTV_LOGICAL_OR
: return (lresult
| rresult
);
1719 case LTTV_LOGICAL_AND
: return (lresult
& rresult
);
1720 case LTTV_LOGICAL_NOT
: return (!rresult
);
1721 case LTTV_LOGICAL_XOR
: return (lresult
^ rresult
);
1722 case 0: return (rresult
);
1725 * This case should never be
1726 * parsed, if so, this subtree
1735 * @fn void lttv_print_tree(LttvFilterTree*)
1738 * @param t the pointer to the current LttvFilterTree
1741 lttv_print_tree(LttvFilterTree
* t
) {
1743 g_print("node:%p lchild:%p rchild:%p\n",t
, //t->l_child.t,t->r_child.t);
1744 (t
->left
==LTTV_TREE_NODE
)?t
->l_child
.t
:NULL
,
1745 (t
->right
==LTTV_TREE_NODE
)?t
->r_child
.t
:NULL
);
1746 g_print("node type: %i / [left] %i / [right] %i\n",t
->node
,t
->left
,t
->right
);
1747 if(t
->left
== LTTV_TREE_NODE
) lttv_print_tree(t
->l_child
.t
);
1748 else if(t
->left
== LTTV_TREE_LEAF
) {
1749 // g_assert(t->l_child.leaf->value != NULL);
1750 g_print("%p: left is %i %p value\n",t
,t
->l_child
.leaf
->field
,t
->l_child
.leaf
->op
);
1752 if(t
->right
== LTTV_TREE_NODE
) lttv_print_tree(t
->r_child
.t
);
1753 else if(t
->right
== LTTV_TREE_LEAF
) {
1754 // g_assert(t->r_child.leaf->value != NULL);
1755 g_print("%p: right is %i %p value\n",t
,t
->r_child
.leaf
->field
,t
->r_child
.leaf
->op
);
1761 * @fn gboolean lttv_filter_tracefile(LttvFilter*, LttTracefile*)
1763 * Apply the filter to a specific trace
1764 * @param filter the current filter applied
1765 * @param tracefile the trace to apply the filter to
1766 * @return success/failure of operation
1769 lttv_filter_tracefile(LttvFilter
*filter
, LttTracefile
*tracefile
) {
1771 return lttv_filter_tree_parse(filter
->head
,NULL
,tracefile
,NULL
,NULL
);
1776 * @fn gboolean lttv_filter_tracestate(LttvFilter*,LttvTraceState*)
1778 * Parse the current tracestate
1779 * @param filter pointer to the current LttvFilter
1780 * @param tracestate pointer to the current tracestate
1783 lttv_filter_tracestate(LttvFilter
*filter
, LttvTraceState
*tracestate
) {
1788 * @fn gboolean lttv_filter_event(LttvFilter*,LttEvent*)
1790 * Apply the filter to a specific event
1791 * @param filter the current filter applied
1792 * @param event the event to apply the filter to
1793 * @return success/failure of operation
1796 lttv_filter_event(LttvFilter
*filter
, LttEvent
*event
) {
1801 * @fn static void module_init()
1803 * Initializes the filter module and specific values
1805 static void module_init()
1811 * @fn Destroys the filter module and specific values
1813 static void module_destroy()
1819 LTTV_MODULE("filter", "Filters traceset and events", \
1820 "Filters traceset and events specifically to user input", \
1821 module_init
, module_destroy
)