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>
67 LTTV_FILTER_TRACEFILE,
80 LTTV_FILTER_EX_SUBMODE,
86 * @fn void lttv_filter_tree_add_node(GPtrArray*,LttvFilterTree*,LttvLogicalOp)
88 * add a node to the current tree
89 * FIXME: Might be used to lower coding in lttv_filter_new switch expression
90 * @param stack the tree stack
91 * @param subtree the subtree if available (pointer or NULL)
92 * @param op the logical operator that will form the node
95 lttv_filter_tree_add_node(GPtrArray
* stack
, LttvFilterTree
* subtree
, LttvLogicalOp op
) {
97 LttvFilterTree
* t1
= NULL
;
98 LttvFilterTree
* t2
= NULL
;
100 t1
= (LttvFilterTree
*)g_ptr_array_index(stack
,stack
->len
-1);
101 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= (LttvFilterTree
*)t1
->r_child
.t
;
102 t2
= lttv_filter_tree_new();
104 if(subtree
!= NULL
) {
105 t2
->left
= LTTV_TREE_NODE
;
106 t2
->l_child
.t
= subtree
;
108 t1
->right
= LTTV_TREE_NODE
;
111 // a_simple_expression->value = a_field_component->str;
112 // a_field_component = g_string_new("");
113 t2
->left
= LTTV_TREE_LEAF
;
114 // t2->l_child.leaf = a_simple_expression;
115 // a_simple_expression = g_new(lttv_simple_expression,1);
116 t1
->right
= LTTV_TREE_NODE
;
124 * @fn LttvSimpleExpression* lttv_simple_expression_new()
126 * Constructor for LttvSimpleExpression
127 * @return pointer to new LttvSimpleExpression
129 LttvSimpleExpression
*
130 lttv_simple_expression_new() {
132 LttvSimpleExpression
* se
= g_new(LttvSimpleExpression
,1);
134 se
->field
= LTTV_FILTER_UNDEFINED
;
137 // se->value.v_uint64 = 0;
143 * @fn gboolean lttv_simple_expression_add_field(GPtrArray*,LttvSimpleExpression*)
145 * Parse through filtering field hierarchy as specified
146 * by user. This function compares each value to
147 * predetermined quarks
148 * @param fp The field path list
149 * @param se current simple expression
150 * @return success/failure of operation
153 lttv_simple_expression_assign_field(GPtrArray
* fp
, LttvSimpleExpression
* se
) {
157 if(fp
->len
< 2) return FALSE
;
158 g_assert(f
=g_ptr_array_remove_index(fp
,0));
161 * Parse through the specified
164 * Take note however that the
165 * 'event' subfields might change
166 * depending on values specified
167 * in core.xml file. Hence, if
168 * none of the subfields in the
169 * array match the hardcoded
170 * subfields, it will be considered
173 if(!g_strcasecmp(f
->str
,"trace") ) {
178 g_string_free(f
,TRUE
);
179 f
=g_ptr_array_remove_index(fp
,0);
180 if(!g_strcasecmp(f
->str
,"name")) {
181 se
->field
= LTTV_FILTER_TRACE_NAME
;
183 } else if(!g_strcasecmp(f
->str
,"traceset") ) {
185 * FIXME: not yet implemented !
187 } else if(!g_strcasecmp(f
->str
,"tracefile") ) {
192 g_string_free(f
,TRUE
);
193 f
=g_ptr_array_remove_index(fp
,0);
194 if(!g_strcasecmp(f
->str
,"name")) {
195 se
->field
= LTTV_FILTER_TRACEFILE_NAME
;
197 } else if(!g_strcasecmp(f
->str
,"state") ) {
202 * state.creation_time
203 * state.insertion_time
205 * state.execution_mode
206 * state.execution_submode
207 * state.process_status
210 g_string_free(f
,TRUE
);
211 f
=g_ptr_array_remove_index(fp
,0);
212 if(!g_strcasecmp(f
->str
,"pid") ) {
213 se
->field
= LTTV_FILTER_STATE_PID
;
215 else if(!g_strcasecmp(f
->str
,"ppid") ) {
216 se
->field
= LTTV_FILTER_STATE_PPID
;
218 else if(!g_strcasecmp(f
->str
,"creation_time") ) {
219 se
->field
= LTTV_FILTER_STATE_CT
;
221 else if(!g_strcasecmp(f
->str
,"insertion_time") ) {
222 se
->field
= LTTV_FILTER_STATE_IT
;
224 else if(!g_strcasecmp(f
->str
,"process_name") ) {
225 se
->field
= LTTV_FILTER_STATE_P_NAME
;
227 else if(!g_strcasecmp(f
->str
,"execution_mode") ) {
228 se
->field
= LTTV_FILTER_STATE_EX_MODE
;
230 else if(!g_strcasecmp(f
->str
,"execution_submode") ) {
231 se
->field
= LTTV_FILTER_STATE_EX_SUBMODE
;
233 else if(!g_strcasecmp(f
->str
,"process_status") ) {
234 se
->field
= LTTV_FILTER_STATE_P_STATUS
;
236 else if(!g_strcasecmp(f
->str
,"cpu") ) {
237 se
->field
= LTTV_FILTER_STATE_CPU
;
239 } else if(!g_strcasecmp(f
->str
,"event") ) {
247 g_string_free(f
,TRUE
);
248 f
=g_ptr_array_remove_index(fp
,0);
249 if(!g_strcasecmp(f
->str
,"name") ) {
250 se
->field
= LTTV_FILTER_EVENT_NAME
;
252 else if(!g_strcasecmp(f
->str
,"category") ) {
254 * FIXME: Category not yet functional in lttv
256 se
->field
= LTTV_FILTER_EVENT_CATEGORY
;
258 else if(!g_strcasecmp(f
->str
,"time") ) {
259 se
->field
= LTTV_FILTER_EVENT_TIME
;
261 else if(!g_strcasecmp(f
->str
,"tsc") ) {
262 se
->field
= LTTV_FILTER_EVENT_TSC
;
264 else { /* core.xml specified options */
265 se
->field
= LTTV_FILTER_EVENT_FIELD
;
268 g_warning("Unrecognized field in filter string");
271 /* free memory for last string */
272 g_string_free(f
,TRUE
);
274 /* array should be empty */
275 g_assert(fp
->len
== 0);
277 g_print("field: %i\n",se
->field
);
278 if(se
->field
== LTTV_FILTER_UNDEFINED
) {
279 g_warning("The specified field was not recognized !");
286 * @fn gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression*,LttvExpressionOp)
288 * Sets the function pointer for the current
290 * @param se current simple expression
291 * @return success/failure of operation
293 gboolean
lttv_simple_expression_assign_operator(LttvSimpleExpression
* se
, LttvExpressionOp op
) {
295 // g_print("se->field = %i\n",se->field);
296 // g_print("se->offset = %i\n",se->offset);
297 // g_print("se->op = %p\n",se->op);
298 // g_print("se->value = %s\n",se->value);
304 case LTTV_FILTER_TRACE_NAME
:
305 case LTTV_FILTER_TRACEFILE_NAME
:
306 case LTTV_FILTER_STATE_P_NAME
:
307 case LTTV_FILTER_EVENT_NAME
:
310 se
->op
= lttv_apply_op_eq_string
;
313 se
->op
= lttv_apply_op_ne_string
;
316 g_warning("Error encountered in operator assignment = or != expected");
323 case LTTV_FILTER_STATE_PID
:
324 case LTTV_FILTER_STATE_PPID
:
325 case LTTV_FILTER_STATE_EX_MODE
:
326 case LTTV_FILTER_STATE_EX_SUBMODE
:
327 case LTTV_FILTER_STATE_P_STATUS
:
330 se
->op
= lttv_apply_op_eq_uint64
;
333 se
->op
= lttv_apply_op_ne_uint64
;
336 se
->op
= lttv_apply_op_lt_uint64
;
339 se
->op
= lttv_apply_op_le_uint64
;
342 se
->op
= lttv_apply_op_gt_uint64
;
345 se
->op
= lttv_apply_op_ge_uint64
;
348 g_warning("Error encountered in operator assignment");
355 case LTTV_FILTER_STATE_CT
:
356 case LTTV_FILTER_STATE_IT
:
357 case LTTV_FILTER_EVENT_TIME
:
358 case LTTV_FILTER_EVENT_TSC
:
361 se
->op
= lttv_apply_op_eq_ltttime
;
364 se
->op
= lttv_apply_op_ne_ltttime
;
367 se
->op
= lttv_apply_op_lt_ltttime
;
370 se
->op
= lttv_apply_op_le_ltttime
;
373 se
->op
= lttv_apply_op_gt_ltttime
;
376 se
->op
= lttv_apply_op_ge_ltttime
;
379 g_warning("Error encountered in operator assignment");
384 g_warning("Error encountered in operator assignation ! Field type:%i",se
->field
);
393 * @fn void lttv_simple_expression_assign_value(LttvSimpleExpression*,char*)
395 * Assign the value field to the current LttvSimpleExpression
396 * @param se pointer to the current LttvSimpleExpression
397 * @param value string value for simple expression
399 gboolean
lttv_simple_expression_assign_value(LttvSimpleExpression
* se
, char* value
) {
401 // g_print("se->value:%s\n",value);
403 gboolean is_double
= FALSE
;
411 case LTTV_FILTER_TRACE_NAME
:
412 case LTTV_FILTER_TRACEFILE_NAME
:
413 case LTTV_FILTER_STATE_P_NAME
:
414 case LTTV_FILTER_EVENT_NAME
:
415 se
->value
.v_string
= value
;
420 case LTTV_FILTER_STATE_PID
:
421 case LTTV_FILTER_STATE_PPID
:
422 case LTTV_FILTER_STATE_EX_MODE
:
423 case LTTV_FILTER_STATE_EX_SUBMODE
:
424 case LTTV_FILTER_STATE_P_STATUS
:
425 se
->value
.v_uint64
= atoi(value
);
431 case LTTV_FILTER_STATE_CT
:
432 case LTTV_FILTER_STATE_IT
:
433 case LTTV_FILTER_EVENT_TIME
:
434 case LTTV_FILTER_EVENT_TSC
:
435 //se->value.v_double = atof(value);
437 * parsing logic could be optimised,
438 * but as for now, simpler this way
440 v
= g_string_new("");
441 for(i
=0;i
<strlen(value
);i
++) {
442 if(value
[i
] == '.') {
443 /* cannot specify number with more than one '.' */
444 if(is_double
) return FALSE
;
445 else is_double
= TRUE
;
447 g_string_free(v
,TRUE
);
448 v
= g_string_new("");
449 } else g_string_append_c(v
,value
[i
]);
451 /* number can be integer or double */
452 if(is_double
) t
.tv_nsec
= atoi(v
);
454 g_string_free(v
,TRUE
);
456 se
->value
.v_ltttime
= t
;
460 g_warning("Error encountered in value assignation ! Field type = %i",se
->field
);
469 * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*)
471 * Disallocate memory for the current
473 * @param se pointer to the current LttvSimpleExpression
476 lttv_simple_expression_destroy(LttvSimpleExpression
* se
) {
478 // g_free(se->value);
480 case LTTV_FILTER_TRACE_NAME
:
481 case LTTV_FILTER_TRACEFILE_NAME
:
482 case LTTV_FILTER_STATE_P_NAME
:
483 case LTTV_FILTER_EVENT_NAME
:
484 g_free(se
->value
.v_string
);
492 * @fn gint lttv_struct_type(gint)
494 * Finds the structure type depending
495 * on the fields in parameters
496 * @params ft Field of the current structure
497 * @return LttvStructType enum or -1 for error
500 lttv_struct_type(gint ft
) {
503 case LTTV_FILTER_TRACE_NAME
:
504 return LTTV_FILTER_TRACE
;
506 case LTTV_FILTER_TRACEFILE_NAME
:
507 return LTTV_FILTER_TRACEFILE
;
509 case LTTV_FILTER_STATE_PID
:
510 case LTTV_FILTER_STATE_PPID
:
511 case LTTV_FILTER_STATE_CT
:
512 case LTTV_FILTER_STATE_IT
:
513 case LTTV_FILTER_STATE_P_NAME
:
514 case LTTV_FILTER_STATE_EX_MODE
:
515 case LTTV_FILTER_STATE_EX_SUBMODE
:
516 case LTTV_FILTER_STATE_P_STATUS
:
517 case LTTV_FILTER_STATE_CPU
:
518 return LTTV_FILTER_STATE
;
520 case LTTV_FILTER_EVENT_NAME
:
521 case LTTV_FILTER_EVENT_CATEGORY
:
522 case LTTV_FILTER_EVENT_TIME
:
523 case LTTV_FILTER_EVENT_TSC
:
524 case LTTV_FILTER_EVENT_FIELD
:
525 return LTTV_FILTER_EVENT
;
533 * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue)
535 * Applies the 'equal' operator to the
536 * specified structure and value
537 * @param v1 left member of comparison
538 * @param v2 right member of comparison
539 * @return success/failure of operation
541 gboolean
lttv_apply_op_eq_uint64(gpointer v1
, LttvFieldValue v2
) {
543 guint64
* r
= (guint64
*) v1
;
544 return (*r
== v2
.v_uint64
);
549 * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue)
551 * Applies the 'equal' operator to the
552 * specified structure and value
553 * @param v1 left member of comparison
554 * @param v2 right member of comparison
555 * @return success/failure of operation
557 gboolean
lttv_apply_op_eq_uint32(gpointer v1
, LttvFieldValue v2
) {
558 guint32
* r
= (guint32
*) v1
;
559 return (*r
== v2
.v_uint32
);
563 * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue)
565 * Applies the 'equal' operator to the
566 * specified structure and value
567 * @param v1 left member of comparison
568 * @param v2 right member of comparison
569 * @return success/failure of operation
571 gboolean
lttv_apply_op_eq_uint16(gpointer v1
, LttvFieldValue v2
) {
572 guint16
* r
= (guint16
*) v1
;
573 return (*r
== v2
.v_uint16
);
577 * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue)
579 * Applies the 'equal' operator to the
580 * specified structure and value
581 * @param v1 left member of comparison
582 * @param v2 right member of comparison
583 * @return success/failure of operation
585 gboolean
lttv_apply_op_eq_double(gpointer v1
, LttvFieldValue v2
) {
586 double* r
= (double*) v1
;
587 return (*r
== v2
.v_double
);
591 * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue)
593 * Applies the 'equal' operator to the
594 * specified structure and value
595 * @param v1 left member of comparison
596 * @param v2 right member of comparison
597 * @return success/failure of operation
599 gboolean
lttv_apply_op_eq_string(gpointer v1
, LttvFieldValue v2
) {
600 char* r
= (char*) v1
;
601 return (!g_strcasecmp(r
,v2
.v_string
));
605 * @fn gboolean lttv_apply_op_eq_ltttime(gpointer,LttvFieldValue)
607 * Applies the 'equal' operator to the
608 * specified structure and value
609 * @param v1 left member of comparison
610 * @param v2 right member of comparison
611 * @return success/failure of operation
613 gboolean
lttv_apply_op_eq_ltttime(gpointer v1
, LttvFieldValue v2
) {
614 LttTime
* r
= (LttTime
*) v1
;
615 return ((r
->tv_sec
== v2
.v_ltttime
.tv_sec
) && (r
->tv_nsec
== v2
.v_ltttime
.tv_nsec
));
620 * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue)
622 * Applies the 'not equal' operator to the
623 * specified structure and value
624 * @param v1 left member of comparison
625 * @param v2 right member of comparison
626 * @return success/failure of operation
628 gboolean
lttv_apply_op_ne_uint64(gpointer v1
, LttvFieldValue v2
) {
629 guint64
* r
= (guint64
*) v1
;
630 return (*r
!= v2
.v_uint64
);
634 * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue)
636 * Applies the 'not equal' operator to the
637 * specified structure and value
638 * @param v1 left member of comparison
639 * @param v2 right member of comparison
640 * @return success/failure of operation
642 gboolean
lttv_apply_op_ne_uint32(gpointer v1
, LttvFieldValue v2
) {
643 guint32
* r
= (guint32
*) v1
;
644 return (*r
!= v2
.v_uint32
);
648 * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue)
650 * Applies the 'not equal' operator to the
651 * specified structure and value
652 * @param v1 left member of comparison
653 * @param v2 right member of comparison
654 * @return success/failure of operation
656 gboolean
lttv_apply_op_ne_uint16(gpointer v1
, LttvFieldValue v2
) {
657 guint16
* r
= (guint16
*) v1
;
658 return (*r
!= v2
.v_uint16
);
662 * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue)
664 * Applies the 'not equal' operator to the
665 * specified structure and value
666 * @param v1 left member of comparison
667 * @param v2 right member of comparison
668 * @return success/failure of operation
670 gboolean
lttv_apply_op_ne_double(gpointer v1
, LttvFieldValue v2
) {
671 double* r
= (double*) v1
;
672 return (*r
!= v2
.v_double
);
676 * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue)
678 * Applies the 'not equal' operator to the
679 * specified structure and value
680 * @param v1 left member of comparison
681 * @param v2 right member of comparison
682 * @return success/failure of operation
684 gboolean
lttv_apply_op_ne_string(gpointer v1
, LttvFieldValue v2
) {
685 char* r
= (char*) v1
;
686 return (g_strcasecmp(r
,v2
.v_string
));
690 * @fn gboolean lttv_apply_op_ne_ltttime(gpointer,LttvFieldValue)
692 * Applies the 'not equal' operator to the
693 * specified structure and value
694 * @param v1 left member of comparison
695 * @param v2 right member of comparison
696 * @return success/failure of operation
698 gboolean
lttv_apply_op_ne_ltttime(gpointer v1
, LttvFieldValue v2
) {
699 LttTime
* r
= (LttTime
*) v1
;
700 return ltt_time_compare(*r
, v2
.v_ltttime
)!=0?1:0;
705 * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue)
707 * Applies the 'lower than' operator to the
708 * specified structure and value
709 * @param v1 left member of comparison
710 * @param v2 right member of comparison
711 * @return success/failure of operation
713 gboolean
lttv_apply_op_lt_uint64(gpointer v1
, LttvFieldValue v2
) {
714 guint64
* r
= (guint64
*) v1
;
715 return (*r
< v2
.v_uint64
);
719 * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue)
721 * Applies the 'lower than' operator to the
722 * specified structure and value
723 * @param v1 left member of comparison
724 * @param v2 right member of comparison
725 * @return success/failure of operation
727 gboolean
lttv_apply_op_lt_uint32(gpointer v1
, LttvFieldValue v2
) {
728 guint32
* r
= (guint32
*) v1
;
729 return (*r
< v2
.v_uint32
);
733 * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue)
735 * Applies the 'lower than' operator to the
736 * specified structure and value
737 * @param v1 left member of comparison
738 * @param v2 right member of comparison
739 * @return success/failure of operation
741 gboolean
lttv_apply_op_lt_uint16(gpointer v1
, LttvFieldValue v2
) {
742 guint16
* r
= (guint16
*) v1
;
743 return (*r
< v2
.v_uint16
);
747 * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue)
749 * Applies the 'lower than' operator to the
750 * specified structure and value
751 * @param v1 left member of comparison
752 * @param v2 right member of comparison
753 * @return success/failure of operation
755 gboolean
lttv_apply_op_lt_double(gpointer v1
, LttvFieldValue v2
) {
756 double* r
= (double*) v1
;
757 return (*r
< v2
.v_double
);
761 * @fn gboolean lttv_apply_op_lt_ltttime(gpointer,LttvFieldValue)
763 * Applies the 'lower than' operator to the
764 * specified structure and value
765 * @param v1 left member of comparison
766 * @param v2 right member of comparison
767 * @return success/failure of operation
769 gboolean
lttv_apply_op_lt_ltttime(gpointer v1
, LttvFieldValue v2
) {
770 LttTime
* r
= (LttTime
*) v1
;
771 return ((r
->tv_sec
< v2
.v_ltttime
.tv_sec
) || ((r
->tv_sec
== v2
.v_ltttime
.tv_sec
) && (r
->tv_nsec
< v2
.v_ltttime
.tv_nsec
)));
776 * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue)
778 * Applies the 'lower or equal' 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_le_uint64(gpointer v1
, LttvFieldValue v2
) {
785 guint64
* r
= (guint64
*) v1
;
786 return (*r
<= v2
.v_uint64
);
790 * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue)
792 * Applies the 'lower or equal' 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_le_uint32(gpointer v1
, LttvFieldValue v2
) {
799 guint32
* r
= (guint32
*) v1
;
800 return (*r
<= v2
.v_uint32
);
804 * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue)
806 * Applies the 'lower or equal' 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_le_uint16(gpointer v1
, LttvFieldValue v2
) {
813 guint16
* r
= (guint16
*) v1
;
814 return (*r
<= v2
.v_uint16
);
818 * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue)
820 * Applies the 'lower 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_le_double(gpointer v1
, LttvFieldValue v2
) {
827 double* r
= (double*) v1
;
828 return (*r
<= v2
.v_double
);
832 * @fn gboolean lttv_apply_op_le_ltttime(gpointer,LttvFieldValue)
834 * Applies the 'lower 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_le_ltttime(gpointer v1
, LttvFieldValue v2
) {
841 LttTime
* r
= (LttTime
*) v1
;
842 return ((r
->tv_sec
< v2
.v_ltttime
.tv_sec
) || ((r
->tv_sec
== v2
.v_ltttime
.tv_sec
) && (r
->tv_nsec
<= v2
.v_ltttime
.tv_nsec
)));
847 * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue)
849 * Applies the 'greater than' operator to the
850 * specified structure and value
851 * @param v1 left member of comparison
852 * @param v2 right member of comparison
853 * @return success/failure of operation
855 gboolean
lttv_apply_op_gt_uint64(gpointer v1
, LttvFieldValue v2
) {
856 guint64
* r
= (guint64
*) v1
;
857 return (*r
> v2
.v_uint64
);
861 * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue)
863 * Applies the 'greater than' operator to the
864 * specified structure and value
865 * @param v1 left member of comparison
866 * @param v2 right member of comparison
867 * @return success/failure of operation
869 gboolean
lttv_apply_op_gt_uint32(gpointer v1
, LttvFieldValue v2
) {
870 guint32
* r
= (guint32
*) v1
;
871 return (*r
> v2
.v_uint32
);
875 * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue)
877 * Applies the 'greater than' operator to the
878 * specified structure and value
879 * @param v1 left member of comparison
880 * @param v2 right member of comparison
881 * @return success/failure of operation
883 gboolean
lttv_apply_op_gt_uint16(gpointer v1
, LttvFieldValue v2
) {
884 guint16
* r
= (guint16
*) v1
;
885 return (*r
> v2
.v_uint16
);
889 * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue)
891 * Applies the 'greater than' operator to the
892 * specified structure and value
893 * @param v1 left member of comparison
894 * @param v2 right member of comparison
895 * @return success/failure of operation
897 gboolean
lttv_apply_op_gt_double(gpointer v1
, LttvFieldValue v2
) {
898 double* r
= (double*) v1
;
899 return (*r
> v2
.v_double
);
903 * @fn gboolean lttv_apply_op_gt_ltttime(gpointer,LttvFieldValue)
905 * Applies the 'greater than' operator to the
906 * specified structure and value
907 * @param v1 left member of comparison
908 * @param v2 right member of comparison
909 * @return success/failure of operation
911 gboolean
lttv_apply_op_gt_ltttime(gpointer v1
, LttvFieldValue v2
) {
912 LttTime
* r
= (LttTime
*) v1
;
913 return ((r
->tv_sec
> v2
.v_ltttime
.tv_sec
) || ((r
->tv_sec
== v2
.v_ltttime
.tv_sec
) && (r
->tv_nsec
> v2
.v_ltttime
.tv_nsec
)));
918 * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue)
920 * Applies the 'greater or equal' operator to the
921 * specified structure and value
922 * @param v1 left member of comparison
923 * @param v2 right member of comparison
924 * @return success/failure of operation
926 gboolean
lttv_apply_op_ge_uint64(gpointer v1
, LttvFieldValue v2
) {
927 guint64
* r
= (guint64
*) v1
;
928 return (*r
>= v2
.v_uint64
);
932 * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue)
934 * Applies the 'greater or equal' operator to the
935 * specified structure and value
936 * @param v1 left member of comparison
937 * @param v2 right member of comparison
938 * @return success/failure of operation
940 gboolean
lttv_apply_op_ge_uint32(gpointer v1
, LttvFieldValue v2
) {
941 guint32
* r
= (guint32
*) v1
;
942 return (*r
>= v2
.v_uint32
);
946 * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue)
948 * Applies the 'greater or equal' operator to the
949 * specified structure and value
950 * @param v1 left member of comparison
951 * @param v2 right member of comparison
952 * @return success/failure of operation
954 gboolean
lttv_apply_op_ge_uint16(gpointer v1
, LttvFieldValue v2
) {
955 guint16
* r
= (guint16
*) v1
;
956 return (*r
>= v2
.v_uint16
);
960 * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue)
962 * Applies the 'greater or equal' operator to the
963 * specified structure and value
964 * @param v1 left member of comparison
965 * @param v2 right member of comparison
966 * @return success/failure of operation
968 gboolean
lttv_apply_op_ge_double(gpointer v1
, LttvFieldValue v2
) {
969 double* r
= (double*) v1
;
970 return (*r
>= v2
.v_double
);
974 * @fn gboolean lttv_apply_op_ge_ltttime(gpointer,LttvFieldValue)
976 * Applies the 'greater or equal' operator to the
977 * specified structure and value
978 * @param v1 left member of comparison
979 * @param v2 right member of comparison
980 * @return success/failure of operation
982 gboolean
lttv_apply_op_ge_ltttime(gpointer v1
, LttvFieldValue v2
) {
983 LttTime
* r
= (LttTime
*) v1
;
984 return ((r
->tv_sec
> v2
.v_ltttime
.tv_sec
) || ((r
->tv_sec
== v2
.v_ltttime
.tv_sec
) && (r
->tv_nsec
>= v2
.v_ltttime
.tv_nsec
)));
990 * @fn LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree*)
992 * Makes a copy of the current filter tree
993 * @param tree pointer to the current tree
994 * @return new copy of the filter tree
997 lttv_filter_tree_clone(LttvFilterTree
* tree
) {
999 LttvFilterTree
* newtree
= lttv_filter_tree_new();
1001 newtree
->node
= tree
->node
;
1003 newtree
->left
= tree
->left
;
1004 if(newtree
->left
== LTTV_TREE_NODE
) {
1005 newtree
->l_child
.t
= lttv_filter_tree_clone(tree
->l_child
.t
);
1006 } else if(newtree
->left
== LTTV_TREE_LEAF
) {
1007 newtree
->l_child
.leaf
= lttv_simple_expression_new();
1008 newtree
->l_child
.leaf
->field
= tree
->l_child
.leaf
->field
;
1009 newtree
->l_child
.leaf
->offset
= tree
->l_child
.leaf
->offset
;
1010 newtree
->l_child
.leaf
->op
= tree
->l_child
.leaf
->op
;
1011 /* FIXME: special case for string copy ! */
1012 newtree
->l_child
.leaf
->value
= tree
->l_child
.leaf
->value
;
1015 newtree
->right
= tree
->right
;
1016 if(newtree
->right
== LTTV_TREE_NODE
) {
1017 newtree
->r_child
.t
= lttv_filter_tree_clone(tree
->r_child
.t
);
1018 } else if(newtree
->right
== LTTV_TREE_LEAF
) {
1019 newtree
->r_child
.leaf
= lttv_simple_expression_new();
1020 newtree
->r_child
.leaf
->field
= tree
->r_child
.leaf
->field
;
1021 newtree
->r_child
.leaf
->offset
= tree
->r_child
.leaf
->offset
;
1022 newtree
->r_child
.leaf
->op
= tree
->r_child
.leaf
->op
;
1023 newtree
->r_child
.leaf
->value
= tree
->r_child
.leaf
->value
;
1031 * @fn LttvFilter* lttv_filter_clone(LttvFilter*)
1033 * Makes a copy of the current filter
1034 * @param filter pointer to the current filter
1035 * @return new copy of the filter
1038 lttv_filter_clone(LttvFilter
* filter
) {
1041 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
1043 // newfilter->expression = g_new(char,1)
1044 strcpy(newfilter
->expression
,filter
->expression
);
1046 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
1054 * @fn LttvFilter* lttv_filter_new()
1056 * Creates a new lttv_filter
1057 * @param expression filtering options string
1058 * @param t pointer to the current LttvTrace
1059 * @return the current lttv_filter or NULL if error
1064 LttvFilter
* filter
= g_new(LttvFilter
,1);
1065 filter
->expression
= NULL
;
1066 filter
->head
= NULL
;
1071 * @fn gboolean lttv_filter_update(LttvFilter*)
1073 * Updates the current LttvFilter by building
1074 * its tree based upon the expression string
1075 * @param filter pointer to the current LttvFilter
1076 * @return Failure/Success of operation
1079 lttv_filter_update(LttvFilter
* filter
) {
1081 g_print("filter::lttv_filter_new()\n"); /* debug */
1083 if(filter
->expression
== NULL
) return FALSE
;
1087 p_nesting
=0; /* parenthesis nesting value */
1091 *tree
= lttv_filter_tree_new(), /* main tree */
1092 *subtree
= NULL
, /* buffer for subtrees */
1093 *t1
, /* buffer #1 */
1094 *t2
; /* buffer #2 */
1098 * If the tree already exists,
1099 * destroy it and build a new one
1101 if(filter
->head
!= NULL
) lttv_filter_tree_destroy(filter
->head
);
1102 filter
->head
= NULL
; /* will be assigned at the end */
1106 * each element of the list
1107 * is a sub tree created
1108 * by the use of parenthesis in the
1109 * global expression. The final tree
1110 * will be the one left at the root of
1113 GPtrArray
*tree_stack
= g_ptr_array_new();
1114 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
1116 /* temporary values */
1117 GString
*a_field_component
= g_string_new("");
1118 GPtrArray
*a_field_path
= g_ptr_array_new();
1120 /* simple expression buffer */
1121 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
1124 * Parse entire expression and construct
1125 * the binary tree. There are two steps
1126 * in browsing that string
1127 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
1128 * 2. finding simple expressions
1129 * - field path ( separated by dots )
1130 * - op ( >, <, =, >=, <=, !=)
1131 * - value ( integer, string ... )
1132 * To spare computing time, the whole
1133 * string is parsed in this loop for a
1134 * O(n) complexity order.
1136 * When encountering logical op &,|,^
1137 * 1. parse the last value if any
1138 * 2. create a new tree
1139 * 3. add the expression (simple exp, or exp (subtree)) to the tree
1140 * 4. concatenate this tree with the current tree on top of the stack
1141 * When encountering math ops >,>=,<,<=,=,!=
1142 * 1. add to op to the simple expression
1143 * 2. concatenate last field component to field path
1144 * When encountering concatening ops .
1145 * 1. concatenate last field component to field path
1146 * When encountering opening parenthesis (,{,[
1147 * 1. create a new subtree on top of tree stack
1148 * When encountering closing parenthesis ),},]
1149 * 1. add the expression on right child of the current tree
1150 * 2. the subtree is completed, allocate a new subtree
1151 * 3. pop the tree value from the tree stack
1154 // g_print("expression: %s\n",filter->expression);
1155 // g_print("strlen(expression): %i\n",strlen(filter->expression));
1156 for(i
=0;i
<strlen(filter
->expression
);i
++) {
1158 g_print("%c ",filter
->expression
[i
]);
1159 switch(filter
->expression
[i
]) {
1165 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1166 while(t1
->right
!= LTTV_TREE_IDLE
) {
1167 g_assert(t1
->right
== LTTV_TREE_NODE
);
1170 t2
= lttv_filter_tree_new();
1171 t2
->node
= LTTV_LOGICAL_AND
;
1172 if(subtree
!= NULL
) { /* append subtree to current tree */
1173 t2
->left
= LTTV_TREE_NODE
;
1174 t2
->l_child
.t
= subtree
;
1176 t1
->right
= LTTV_TREE_NODE
;
1178 } else { /* append a simple expression */
1179 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1180 // a_simple_expression->value = g_string_free(a_field_component,FALSE);
1181 a_field_component
= g_string_new("");
1182 t2
->left
= LTTV_TREE_LEAF
;
1183 t2
->l_child
.leaf
= a_simple_expression
;
1184 a_simple_expression
= lttv_simple_expression_new();
1185 t1
->right
= LTTV_TREE_NODE
;
1187 g_print("t1:%p t1->child:%p\n",t1
,t1
->r_child
.t
);
1193 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1194 while(t1
->right
!= LTTV_TREE_IDLE
) {
1195 g_assert(t1
->right
== LTTV_TREE_NODE
);
1198 t2
= lttv_filter_tree_new();
1199 t2
->node
= LTTV_LOGICAL_OR
;
1200 if(subtree
!= NULL
) { /* append subtree to current tree */
1201 t2
->left
= LTTV_TREE_NODE
;
1202 t2
->l_child
.t
= subtree
;
1204 t1
->right
= LTTV_TREE_NODE
;
1206 } else { /* append a simple expression */
1207 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1208 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1209 a_field_component
= g_string_new("");
1210 t2
->left
= LTTV_TREE_LEAF
;
1211 t2
->l_child
.leaf
= a_simple_expression
;
1212 a_simple_expression
= lttv_simple_expression_new();
1213 t1
->right
= LTTV_TREE_NODE
;
1220 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1221 while(t1
->right
!= LTTV_TREE_IDLE
) {
1222 g_assert(t1
->right
== LTTV_TREE_NODE
);
1225 t2
= lttv_filter_tree_new();
1226 t2
->node
= LTTV_LOGICAL_XOR
;
1227 if(subtree
!= NULL
) { /* append subtree to current tree */
1228 t2
->left
= LTTV_TREE_NODE
;
1229 t2
->l_child
.t
= subtree
;
1231 t1
->right
= LTTV_TREE_NODE
;
1233 } else { /* append a simple expression */
1234 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1235 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1236 a_field_component
= g_string_new("");
1237 t2
->left
= LTTV_TREE_LEAF
;
1238 t2
->l_child
.leaf
= a_simple_expression
;
1239 a_simple_expression
= lttv_simple_expression_new();
1240 t1
->right
= LTTV_TREE_NODE
;
1245 case '!': /* not, or not equal (math op) */
1247 if(filter
->expression
[i
+1] == '=') { /* != */
1248 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1249 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1250 a_field_component
= g_string_new("");
1251 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_NE
);
1254 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1255 while(t1
->right
!= LTTV_TREE_IDLE
) {
1256 g_assert(t1
->right
== LTTV_TREE_NODE
);
1259 t2
= lttv_filter_tree_new();
1260 t2
->node
= LTTV_LOGICAL_NOT
;
1261 t1
->right
= LTTV_TREE_NODE
;
1266 case '(': /* start of parenthesis */
1270 p_nesting
++; /* incrementing parenthesis nesting value */
1271 t1
= lttv_filter_tree_new();
1272 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
1275 case ')': /* end of parenthesis */
1279 p_nesting
--; /* decrementing parenthesis nesting value */
1280 if(p_nesting
<0 || tree_stack
->len
<2) {
1281 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1282 is not valid due to parenthesis incorrect use",filter
->expression
);
1286 /* there must at least be the root tree left in the array */
1287 g_assert(tree_stack
->len
>0);
1289 if(subtree
!= NULL
) { /* append subtree to current tree */
1290 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1291 while(t1
->right
!= LTTV_TREE_IDLE
) {
1292 g_assert(t1
->right
== LTTV_TREE_NODE
);
1295 t1
->right
= LTTV_TREE_NODE
;
1296 t1
->r_child
.t
= subtree
;
1297 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1298 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1299 } else { /* assign subtree as current tree */
1300 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1301 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1302 a_field_component
= g_string_new("");
1303 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1304 while(t1
->right
!= LTTV_TREE_IDLE
) {
1305 g_print("while right:%i %p->child:%p\n",t1
->right
,t1
,t1
->r_child
.t
);
1306 g_assert(t1
->right
== LTTV_TREE_NODE
);
1307 g_assert(t1
->r_child
.t
!= NULL
);
1310 t1
->right
= LTTV_TREE_LEAF
;
1311 t1
->r_child
.leaf
= a_simple_expression
;
1312 a_simple_expression
= lttv_simple_expression_new();
1313 subtree
= g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1318 * mathematic operators
1320 case '<': /* lower, lower or equal */
1322 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1323 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1324 a_field_component
= g_string_new("");
1325 if(filter
->expression
[i
+1] == '=') { /* <= */
1327 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LE
);
1328 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LT
);
1331 case '>': /* higher, higher or equal */
1333 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1334 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1335 a_field_component
= g_string_new("");
1336 if(filter
->expression
[i
+1] == '=') { /* >= */
1338 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GE
);
1339 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GT
);
1342 case '=': /* equal */
1344 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1345 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1346 a_field_component
= g_string_new("");
1347 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1351 * Field concatening caracter
1356 * divide field expression into elements
1357 * in a_field_path array.
1359 /* FIXME: check for double values */
1360 if(a_simple_expression
->field
== LTTV_FILTER_UNDEFINED
) {
1361 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1362 a_field_component
= g_string_new("");
1368 default: /* concatening current string */
1369 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1373 // g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree,tree,t1,t2);
1374 // g_print("stack size: %i\n",tree_stack->len);
1377 * Preliminary check to see
1378 * if tree was constructed correctly
1381 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1382 is not valid due to parenthesis incorrect use",filter
->expression
);
1386 if(tree_stack
->len
!= 1) /* only root tree should remain */
1389 /* processing last element of expression */
1390 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1391 while(t1
->right
!= LTTV_TREE_IDLE
) {
1392 g_assert(t1
->right
== LTTV_TREE_NODE
);
1395 if(subtree
!= NULL
) { /* add the subtree */
1396 t1
->right
= LTTV_TREE_NODE
;
1397 t1
->r_child
.t
= subtree
;
1399 } else { /* add a leaf */
1400 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1401 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1402 a_field_component
= NULL
;
1403 t1
->right
= LTTV_TREE_LEAF
;
1404 t1
->r_child
.leaf
= a_simple_expression
;
1405 a_simple_expression
= NULL
;
1409 /* free the pointer array */
1410 g_assert(a_field_path
->len
== 0);
1411 g_ptr_array_free(a_field_path
,TRUE
);
1413 /* free the tree stack -- but keep the root tree */
1414 // g_ptr_array_free(tree_stack,FALSE);
1415 filter
->head
= g_ptr_array_remove_index(tree_stack
,0);
1416 g_ptr_array_free(tree_stack
,TRUE
);
1418 /* free the field buffer if allocated */
1419 if(a_field_component
!= NULL
) g_string_free(a_field_component
,TRUE
);
1421 /* free the simple expression buffer if allocated */
1422 if(a_simple_expression
!= NULL
) lttv_simple_expression_destroy(a_simple_expression
);
1424 g_assert(filter
->head
!= NULL
); /* tree should exist */
1425 g_assert(subtree
== NULL
); /* remaining subtree should be included in main tree */
1428 g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1429 lttv_print_tree(filter
->head
) ;
1430 g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1438 * @fn void lttv_filter_destroy(LttvFilter*)
1440 * Destroy the current LttvFilter
1441 * @param filter pointer to the current LttvFilter
1444 lttv_filter_destroy(LttvFilter
* filter
) {
1446 g_free(filter
->expression
);
1447 lttv_filter_tree_destroy(filter
->head
);
1453 * @fn LttvFilterTree* lttv_filter_tree_new()
1455 * Assign a new tree for the current expression
1457 * @return pointer of LttvFilterTree
1460 lttv_filter_tree_new() {
1461 LttvFilterTree
* tree
;
1463 tree
= g_new(LttvFilterTree
,1);
1464 tree
->node
= 0; //g_new(lttv_expression,1);
1465 tree
->left
= LTTV_TREE_IDLE
;
1466 tree
->right
= LTTV_TREE_IDLE
;
1467 tree
->r_child
.t
= NULL
;
1468 tree
->l_child
.t
= NULL
;
1474 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1476 * Append a new expression to the expression
1477 * defined in the current filter
1478 * @param filter pointer to the current LttvFilter
1479 * @param expression string that must be appended
1480 * @return Success/Failure of operation
1482 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, char *expression
) {
1484 if(expression
== NULL
) return FALSE
;
1485 if(filter
== NULL
) {
1486 filter
= lttv_filter_new();
1487 filter
->expression
= expression
;
1488 } else if(filter
->expression
== NULL
) {
1489 filter
->expression
= expression
;
1491 filter
->expression
= g_strconcat(filter
->expression
,"&",expression
);
1494 return lttv_filter_update(filter
);
1499 * @fn void lttv_filter_clear_expression(LttvFilter*)
1501 * Clear the filter expression from the
1502 * current filter and sets its pointer to NULL
1503 * @param filter pointer to the current LttvFilter
1505 void lttv_filter_clear_expression(LttvFilter
* filter
) {
1507 if(filter
->expression
!= NULL
) {
1508 g_free(filter
->expression
);
1509 filter
->expression
= NULL
;
1515 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1517 * Destroys the tree and his sub-trees
1518 * @param tree Tree which must be destroyed
1521 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1523 if(tree
== NULL
) return;
1525 if(tree
->left
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->l_child
.leaf
);
1526 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1528 if(tree
->right
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->r_child
.leaf
);
1529 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1531 // g_free(tree->node);
1536 * @fn gboolean lttv_filter_tree_parse(LttvFilterTree*,LttEvent,LttTracefile,LttTrace,LttvProcessState)
1538 * Global parsing function for the current
1540 * @param tree pointer to the current LttvFilterTree
1541 * @param event current LttEvent, NULL if not used
1542 * @param tracefile current LttTracefile, NULL if not used
1543 * @param trace current LttTrace, NULL if not used
1544 * @param state current LttvProcessState, NULL if not used
1547 lttv_filter_tree_parse(
1550 LttTracefile
* tracefile
,
1552 LttvProcessState
* state
,
1553 LttvTracefileContext
* context
1558 * Each tree is parsed in inorder.
1559 * This way, it's possible to apply the left filter of the
1560 * tree, then decide whether or not the right branch should
1561 * be parsed depending on the linking logical operator
1563 * Each node consists in a
1564 * 1. logical operator
1565 * 2. left child ( node or simple expression )
1566 * 3. right child ( node or simple expression )
1568 * When the child is a simple expression, we must
1569 * before all determine if the expression refers to
1570 * a structure which is whithin observation ( not NULL ).
1571 * -If so, the expression is evaluated.
1572 * -If not, the result is set to TRUE since this particular
1573 * operation does not interfere with the lttv structure
1575 * The result of each simple expression will directly
1576 * affect the next branch. This way, depending on
1577 * the linking logical operator, the parser will decide
1578 * to explore or not the next branch.
1580 * -If result of left branch is 0 / FALSE
1581 * then don't explore right branch and return 0;
1582 * -If result of left branch is 1 / TRUE then explore
1584 * -If result of left branch is 1 / TRUE
1585 * then don't explore right branch and return 1;
1586 * -If result of left branch is 0 / FALSE then explore
1588 * -Result of left branch will not affect exploration of
1591 // g_print("filter::lttv_parse_tree(...)\n");
1593 gboolean lresult
= FALSE
, rresult
= FALSE
;
1598 if(t
->left
== LTTV_TREE_NODE
) lresult
= lttv_filter_tree_parse(t
->l_child
.t
,event
,tracefile
,trace
,state
,context
);
1599 else if(t
->left
== LTTV_TREE_LEAF
) {
1600 //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);
1602 v
= t
->l_child
.leaf
->value
;
1603 switch(t
->l_child
.leaf
->field
) {
1605 case LTTV_FILTER_TRACE_NAME
:
1606 if(trace
== NULL
) lresult
= TRUE
;
1607 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_trace_name(trace
),v
);
1609 case LTTV_FILTER_TRACEFILE_NAME
:
1610 if(tracefile
== NULL
) lresult
= TRUE
;
1611 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_tracefile_name(tracefile
),v
);
1613 case LTTV_FILTER_STATE_PID
:
1614 if(state
== NULL
) lresult
= TRUE
;
1615 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1617 case LTTV_FILTER_STATE_PPID
:
1618 if(state
== NULL
) lresult
= TRUE
;
1619 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1621 case LTTV_FILTER_STATE_CT
:
1622 if(state
== NULL
) lresult
= TRUE
;
1624 lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->creation_time
,v
);
1627 case LTTV_FILTER_STATE_IT
:
1628 if(state
== NULL
) lresult
= TRUE
;
1630 lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->insertion_time
,v
);
1633 case LTTV_FILTER_STATE_P_NAME
:
1635 * All 'unnamed' for the moment
1637 if(state
== NULL
) lresult
= TRUE
;
1639 lresult
= t
->l_child
.leaf
->op((gpointer
)g_quark_to_string(state
->name
),v
);
1642 case LTTV_FILTER_STATE_EX_MODE
:
1643 if(state
== NULL
) lresult
= TRUE
;
1644 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->t
,v
);
1646 case LTTV_FILTER_STATE_EX_SUBMODE
:
1647 if(state
== NULL
) lresult
= TRUE
;
1648 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->n
,v
);
1650 case LTTV_FILTER_STATE_P_STATUS
:
1651 if(state
== NULL
) lresult
= TRUE
;
1652 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->s
,v
);
1654 case LTTV_FILTER_STATE_CPU
:
1655 if(context
== NULL
) lresult
= TRUE
;
1657 lresult
= t
->l_child
.leaf
->op((gpointer
)g_quark_to_string(((LttvTracefileState
*)context
)->cpu_name
),v
);
1660 case LTTV_FILTER_EVENT_NAME
:
1661 if(event
== NULL
) lresult
= TRUE
;
1664 et
= ltt_event_eventtype(event
);
1665 lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_eventtype_name(et
),v
);
1669 case LTTV_FILTER_EVENT_CATEGORY
:
1671 * FIXME: Not yet implemented
1675 case LTTV_FILTER_EVENT_TIME
:
1676 if(event
== NULL
) lresult
= TRUE
;
1678 LttTime time
= ltt_event_time(event
);
1679 lresult
= t
->l_child
.leaf
->op((gpointer
)&t
,v
);
1682 case LTTV_FILTER_EVENT_TSC
:
1683 // if(event == NULL) lresult = TRUE;
1685 // double val = ltt_time_to_double(event->event_time);
1686 // lresult = t->l_child.leaf->op((gpointer)&val,v);
1689 * FIXME: Where is event.tsc
1693 case LTTV_FILTER_EVENT_FIELD
:
1695 * TODO: Use the offset to
1696 * find the dynamic field
1697 * in the event struct
1702 * This case should never be
1703 * parsed, if so, the whole
1704 * filtering is cancelled
1706 g_warning("Error while parsing the filter tree");
1712 * Parse linking operator
1713 * make a cutoff if possible
1715 if((t
->node
& LTTV_LOGICAL_OR
) && lresult
== TRUE
) return TRUE
;
1716 if((t
->node
& LTTV_LOGICAL_AND
) && lresult
== FALSE
) return FALSE
;
1719 * Parse right branch
1721 if(t
->right
== LTTV_TREE_NODE
) rresult
= lttv_filter_tree_parse(t
->r_child
.t
,event
,tracefile
,trace
,state
,context
);
1722 else if(t
->right
== LTTV_TREE_LEAF
) {
1723 //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);
1725 v
= t
->r_child
.leaf
->value
;
1726 switch(t
->r_child
.leaf
->field
) {
1728 case LTTV_FILTER_TRACE_NAME
:
1729 if(trace
== NULL
) rresult
= TRUE
;
1730 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_trace_name(trace
),v
);
1732 case LTTV_FILTER_TRACEFILE_NAME
:
1733 if(tracefile
== NULL
) rresult
= TRUE
;
1734 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_tracefile_name(tracefile
),v
);
1736 case LTTV_FILTER_STATE_PID
:
1737 if(state
== NULL
) rresult
= TRUE
;
1738 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1740 case LTTV_FILTER_STATE_PPID
:
1741 if(state
== NULL
) rresult
= TRUE
;
1742 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1744 case LTTV_FILTER_STATE_CT
:
1745 if(state
== NULL
) rresult
= TRUE
;
1747 // double val = ltt_time_to_double(state->creation_time);
1748 rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->creation_time
,v
);
1751 case LTTV_FILTER_STATE_IT
:
1752 if(state
== NULL
) rresult
= TRUE
;
1754 // double val = ltt_time_to_double(state->insertion_time);
1755 rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->insertion_time
,v
);
1758 case LTTV_FILTER_STATE_P_NAME
:
1760 * FIXME: Yet to be done ( I think ? )
1762 if(state
== NULL
) rresult
= TRUE
;
1764 rresult
= t
->r_child
.leaf
->op((gpointer
)g_quark_to_string(state
->name
),v
);
1767 case LTTV_FILTER_STATE_EX_MODE
:
1768 if(state
== NULL
) rresult
= TRUE
;
1769 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->t
,v
);
1771 case LTTV_FILTER_STATE_EX_SUBMODE
:
1772 if(state
== NULL
) rresult
= TRUE
;
1773 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->n
,v
);
1775 case LTTV_FILTER_STATE_P_STATUS
:
1776 if(state
== NULL
) rresult
= TRUE
;
1777 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->s
,v
);
1779 case LTTV_FILTER_STATE_CPU
:
1781 * FIXME: What is the comparison value ?
1783 if(context
== NULL
) rresult
= TRUE
;
1785 rresult
= t
->r_child
.leaf
->op((gpointer
)g_quark_to_string(((LttvTracefileState
*)context
)->cpu_name
),v
);
1788 case LTTV_FILTER_EVENT_NAME
:
1789 if(event
== NULL
) rresult
= TRUE
;
1792 et
= ltt_event_eventtype(event
);
1793 rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_eventtype_name(et
),v
);
1796 case LTTV_FILTER_EVENT_CATEGORY
:
1798 * FIXME: Not yet implemented
1802 case LTTV_FILTER_EVENT_TIME
:
1803 if(event
== NULL
) rresult
= TRUE
;
1805 LttTime time
= ltt_event_time(event
);
1806 rresult
= t
->r_child
.leaf
->op((gpointer
)&t
,v
);
1809 case LTTV_FILTER_EVENT_TSC
:
1810 // if(event == NULL) rresult = TRUE;
1812 // double val = ltt_time_to_double(event->event_time);
1813 // rresult = t->r_child.leaf->op((gpointer)&val,v);
1816 * FIXME: Where is event.tsc
1820 case LTTV_FILTER_EVENT_FIELD
:
1822 * TODO: Use the offset to
1823 * find the dynamic field
1824 * in the event struct
1829 * This case should never be
1830 * parsed, if so, this subtree
1833 g_warning("Error while parsing the filter tree");
1839 * Apply and return the
1840 * logical link between the
1844 case LTTV_LOGICAL_OR
: return (lresult
| rresult
);
1845 case LTTV_LOGICAL_AND
: return (lresult
& rresult
);
1846 case LTTV_LOGICAL_NOT
: return (!rresult
);
1847 case LTTV_LOGICAL_XOR
: return (lresult
^ rresult
);
1848 case 0: return (rresult
);
1851 * This case should never be
1852 * parsed, if so, this subtree
1861 * @fn void lttv_print_tree(LttvFilterTree*)
1864 * @param t the pointer to the current LttvFilterTree
1867 lttv_print_tree(LttvFilterTree
* t
) {
1869 g_print("node:%p lchild:%p rchild:%p\n",t
, //t->l_child.t,t->r_child.t);
1870 (t
->left
==LTTV_TREE_NODE
)?t
->l_child
.t
:NULL
,
1871 (t
->right
==LTTV_TREE_NODE
)?t
->r_child
.t
:NULL
);
1872 g_print("node type: %i / [left] %i / [right] %i\n",t
->node
,t
->left
,t
->right
);
1873 if(t
->left
== LTTV_TREE_NODE
) lttv_print_tree(t
->l_child
.t
);
1874 else if(t
->left
== LTTV_TREE_LEAF
) {
1875 // g_assert(t->l_child.leaf->value != NULL);
1876 g_print("%p: left is %i %p value\n",t
,t
->l_child
.leaf
->field
,t
->l_child
.leaf
->op
);
1878 if(t
->right
== LTTV_TREE_NODE
) lttv_print_tree(t
->r_child
.t
);
1879 else if(t
->right
== LTTV_TREE_LEAF
) {
1880 // g_assert(t->r_child.leaf->value != NULL);
1881 g_print("%p: right is %i %p value\n",t
,t
->r_child
.leaf
->field
,t
->r_child
.leaf
->op
);
1887 * @fn gboolean lttv_filter_tracefile(LttvFilter*, LttTracefile*)
1889 * Apply the filter to a specific trace
1890 * @param filter the current filter applied
1891 * @param tracefile the trace to apply the filter to
1892 * @return success/failure of operation
1895 lttv_filter_tracefile(LttvFilter
*filter
, LttTracefile
*tracefile
) {
1897 return lttv_filter_tree_parse(filter
->head
,NULL
,tracefile
,NULL
,NULL
,NULL
);
1902 * @fn gboolean lttv_filter_tracestate(LttvFilter*,LttvTraceState*)
1904 * Parse the current tracestate
1905 * @param filter pointer to the current LttvFilter
1906 * @param tracestate pointer to the current tracestate
1909 lttv_filter_tracestate(LttvFilter
*filter
, LttvTraceState
*tracestate
) {
1914 * @fn gboolean lttv_filter_event(LttvFilter*,LttEvent*)
1916 * Apply the filter to a specific event
1917 * @param filter the current filter applied
1918 * @param event the event to apply the filter to
1919 * @return success/failure of operation
1922 lttv_filter_event(LttvFilter
*filter
, LttEvent
*event
) {
1927 * @fn static void module_init()
1929 * Initializes the filter module and specific values
1931 static void module_init()
1937 * @fn Destroys the filter module and specific values
1939 static void module_destroy()
1945 LTTV_MODULE("filter", "Filters traceset and events", \
1946 "Filters traceset and events specifically to user input", \
1947 module_init
, module_destroy
)