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 return (!g_strcasecmp(r
,v2
.v_string
));
579 * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue)
581 * Applies the 'not equal' operator to the
582 * specified structure and value
583 * @param v1 left member of comparison
584 * @param v2 right member of comparison
585 * @return success/failure of operation
587 gboolean
lttv_apply_op_ne_uint64(gpointer v1
, LttvFieldValue v2
) {
588 guint64
* r
= (guint64
*) v1
;
589 return (*r
!= v2
.v_uint64
);
593 * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue)
595 * Applies the 'not equal' operator to the
596 * specified structure and value
597 * @param v1 left member of comparison
598 * @param v2 right member of comparison
599 * @return success/failure of operation
601 gboolean
lttv_apply_op_ne_uint32(gpointer v1
, LttvFieldValue v2
) {
602 guint32
* r
= (guint32
*) v1
;
603 return (*r
!= v2
.v_uint32
);
607 * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue)
609 * Applies the 'not equal' operator to the
610 * specified structure and value
611 * @param v1 left member of comparison
612 * @param v2 right member of comparison
613 * @return success/failure of operation
615 gboolean
lttv_apply_op_ne_uint16(gpointer v1
, LttvFieldValue v2
) {
616 guint16
* r
= (guint16
*) v1
;
617 return (*r
!= v2
.v_uint16
);
621 * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue)
623 * Applies the 'not equal' operator to the
624 * specified structure and value
625 * @param v1 left member of comparison
626 * @param v2 right member of comparison
627 * @return success/failure of operation
629 gboolean
lttv_apply_op_ne_double(gpointer v1
, LttvFieldValue v2
) {
630 double* r
= (double*) v1
;
631 return (*r
!= v2
.v_double
);
635 * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue)
637 * Applies the 'not equal' operator to the
638 * specified structure and value
639 * @param v1 left member of comparison
640 * @param v2 right member of comparison
641 * @return success/failure of operation
643 gboolean
lttv_apply_op_ne_string(gpointer v1
, LttvFieldValue v2
) {
644 char* r
= (char*) v1
;
645 return (g_strcasecmp(r
,v2
.v_string
));
649 * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue)
651 * Applies the 'lower than' operator to the
652 * specified structure and value
653 * @param v1 left member of comparison
654 * @param v2 right member of comparison
655 * @return success/failure of operation
657 gboolean
lttv_apply_op_lt_uint64(gpointer v1
, LttvFieldValue v2
) {
658 guint64
* r
= (guint64
*) v1
;
659 return (*r
< v2
.v_uint64
);
663 * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue)
665 * Applies the 'lower than' operator to the
666 * specified structure and value
667 * @param v1 left member of comparison
668 * @param v2 right member of comparison
669 * @return success/failure of operation
671 gboolean
lttv_apply_op_lt_uint32(gpointer v1
, LttvFieldValue v2
) {
672 guint32
* r
= (guint32
*) v1
;
673 return (*r
< v2
.v_uint32
);
677 * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue)
679 * Applies the 'lower than' operator to the
680 * specified structure and value
681 * @param v1 left member of comparison
682 * @param v2 right member of comparison
683 * @return success/failure of operation
685 gboolean
lttv_apply_op_lt_uint16(gpointer v1
, LttvFieldValue v2
) {
686 guint16
* r
= (guint16
*) v1
;
687 return (*r
< v2
.v_uint16
);
691 * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue)
693 * Applies the 'lower than' operator to the
694 * specified structure and value
695 * @param v1 left member of comparison
696 * @param v2 right member of comparison
697 * @return success/failure of operation
699 gboolean
lttv_apply_op_lt_double(gpointer v1
, LttvFieldValue v2
) {
700 double* r
= (double*) v1
;
701 return (*r
< v2
.v_double
);
705 * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue)
707 * Applies the 'lower or equal' 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_le_uint64(gpointer v1
, LttvFieldValue v2
) {
714 guint64
* r
= (guint64
*) v1
;
715 return (*r
<= v2
.v_uint64
);
719 * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue)
721 * Applies the 'lower or equal' 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_le_uint32(gpointer v1
, LttvFieldValue v2
) {
728 guint32
* r
= (guint32
*) v1
;
729 return (*r
<= v2
.v_uint32
);
733 * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue)
735 * Applies the 'lower or equal' 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_le_uint16(gpointer v1
, LttvFieldValue v2
) {
742 guint16
* r
= (guint16
*) v1
;
743 return (*r
<= v2
.v_uint16
);
747 * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue)
749 * Applies the 'lower or equal' 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_le_double(gpointer v1
, LttvFieldValue v2
) {
756 double* r
= (double*) v1
;
757 return (*r
<= v2
.v_double
);
761 * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue)
763 * Applies the 'greater 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_gt_uint64(gpointer v1
, LttvFieldValue v2
) {
770 guint64
* r
= (guint64
*) v1
;
771 return (*r
> v2
.v_uint64
);
775 * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue)
777 * Applies the 'greater than' operator to the
778 * specified structure and value
779 * @param v1 left member of comparison
780 * @param v2 right member of comparison
781 * @return success/failure of operation
783 gboolean
lttv_apply_op_gt_uint32(gpointer v1
, LttvFieldValue v2
) {
784 guint32
* r
= (guint32
*) v1
;
785 return (*r
> v2
.v_uint32
);
789 * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue)
791 * Applies the 'greater than' operator to the
792 * specified structure and value
793 * @param v1 left member of comparison
794 * @param v2 right member of comparison
795 * @return success/failure of operation
797 gboolean
lttv_apply_op_gt_uint16(gpointer v1
, LttvFieldValue v2
) {
798 guint16
* r
= (guint16
*) v1
;
799 return (*r
> v2
.v_uint16
);
803 * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue)
805 * Applies the 'greater than' operator to the
806 * specified structure and value
807 * @param v1 left member of comparison
808 * @param v2 right member of comparison
809 * @return success/failure of operation
811 gboolean
lttv_apply_op_gt_double(gpointer v1
, LttvFieldValue v2
) {
812 double* r
= (double*) v1
;
813 return (*r
> v2
.v_double
);
817 * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue)
819 * Applies the 'greater or equal' operator to the
820 * specified structure and value
821 * @param v1 left member of comparison
822 * @param v2 right member of comparison
823 * @return success/failure of operation
825 gboolean
lttv_apply_op_ge_uint64(gpointer v1
, LttvFieldValue v2
) {
826 guint64
* r
= (guint64
*) v1
;
827 return (*r
>= v2
.v_uint64
);
831 * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue)
833 * Applies the 'greater or equal' operator to the
834 * specified structure and value
835 * @param v1 left member of comparison
836 * @param v2 right member of comparison
837 * @return success/failure of operation
839 gboolean
lttv_apply_op_ge_uint32(gpointer v1
, LttvFieldValue v2
) {
840 guint32
* r
= (guint32
*) v1
;
841 return (*r
>= v2
.v_uint32
);
845 * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue)
847 * Applies the 'greater or equal' operator to the
848 * specified structure and value
849 * @param v1 left member of comparison
850 * @param v2 right member of comparison
851 * @return success/failure of operation
853 gboolean
lttv_apply_op_ge_uint16(gpointer v1
, LttvFieldValue v2
) {
854 guint16
* r
= (guint16
*) v1
;
855 return (*r
>= v2
.v_uint16
);
859 * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue)
861 * Applies the 'greater or equal' operator to the
862 * specified structure and value
863 * @param v1 left member of comparison
864 * @param v2 right member of comparison
865 * @return success/failure of operation
867 gboolean
lttv_apply_op_ge_double(gpointer v1
, LttvFieldValue v2
) {
868 double* r
= (double*) v1
;
869 return (*r
>= v2
.v_double
);
874 * @fn LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree*)
876 * Makes a copy of the current filter tree
877 * @param tree pointer to the current tree
878 * @return new copy of the filter tree
881 lttv_filter_tree_clone(LttvFilterTree
* tree
) {
883 LttvFilterTree
* newtree
= lttv_filter_tree_new();
885 newtree
->node
= tree
->node
;
887 newtree
->left
= tree
->left
;
888 if(newtree
->left
== LTTV_TREE_NODE
) {
889 newtree
->l_child
.t
= lttv_filter_tree_clone(tree
->l_child
.t
);
890 } else if(newtree
->left
== LTTV_TREE_LEAF
) {
891 newtree
->l_child
.leaf
= lttv_simple_expression_new();
892 newtree
->l_child
.leaf
->field
= tree
->l_child
.leaf
->field
;
893 newtree
->l_child
.leaf
->offset
= tree
->l_child
.leaf
->offset
;
894 newtree
->l_child
.leaf
->op
= tree
->l_child
.leaf
->op
;
895 /* FIXME: special case for string copy ! */
896 newtree
->l_child
.leaf
->value
= tree
->l_child
.leaf
->value
;
899 newtree
->right
= tree
->right
;
900 if(newtree
->right
== LTTV_TREE_NODE
) {
901 newtree
->r_child
.t
= lttv_filter_tree_clone(tree
->r_child
.t
);
902 } else if(newtree
->right
== LTTV_TREE_LEAF
) {
903 newtree
->r_child
.leaf
= lttv_simple_expression_new();
904 newtree
->r_child
.leaf
->field
= tree
->r_child
.leaf
->field
;
905 newtree
->r_child
.leaf
->offset
= tree
->r_child
.leaf
->offset
;
906 newtree
->r_child
.leaf
->op
= tree
->r_child
.leaf
->op
;
907 newtree
->r_child
.leaf
->value
= tree
->r_child
.leaf
->value
;
915 * @fn LttvFilter* lttv_filter_clone(LttvFilter*)
917 * Makes a copy of the current filter
918 * @param filter pointer to the current filter
919 * @return new copy of the filter
922 lttv_filter_clone(LttvFilter
* filter
) {
925 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
927 // newfilter->expression = g_new(char,1)
928 strcpy(newfilter
->expression
,filter
->expression
);
930 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
938 * @fn LttvFilter* lttv_filter_new()
940 * Creates a new lttv_filter
941 * @param expression filtering options string
942 * @param t pointer to the current LttvTrace
943 * @return the current lttv_filter or NULL if error
948 LttvFilter
* filter
= g_new(LttvFilter
,1);
949 filter
->expression
= NULL
;
955 * @fn gboolean lttv_filter_update(LttvFilter*)
957 * Updates the current LttvFilter by building
958 * its tree based upon the expression string
959 * @param filter pointer to the current LttvFilter
960 * @return Failure/Success of operation
963 lttv_filter_update(LttvFilter
* filter
) {
965 g_print("filter::lttv_filter_new()\n"); /* debug */
967 if(filter
->expression
== NULL
) return FALSE
;
971 p_nesting
=0; /* parenthesis nesting value */
975 *tree
= lttv_filter_tree_new(), /* main tree */
976 *subtree
= NULL
, /* buffer for subtrees */
982 * If the tree already exists,
983 * destroy it and build a new one
985 if(filter
->head
!= NULL
) lttv_filter_tree_destroy(filter
->head
);
986 filter
->head
= NULL
; /* will be assigned at the end */
990 * each element of the list
991 * is a sub tree created
992 * by the use of parenthesis in the
993 * global expression. The final tree
994 * will be the one left at the root of
997 GPtrArray
*tree_stack
= g_ptr_array_new();
998 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
1000 /* temporary values */
1001 GString
*a_field_component
= g_string_new("");
1002 GPtrArray
*a_field_path
= g_ptr_array_new();
1004 /* simple expression buffer */
1005 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
1008 * Parse entire expression and construct
1009 * the binary tree. There are two steps
1010 * in browsing that string
1011 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
1012 * 2. finding simple expressions
1013 * - field path ( separated by dots )
1014 * - op ( >, <, =, >=, <=, !=)
1015 * - value ( integer, string ... )
1016 * To spare computing time, the whole
1017 * string is parsed in this loop for a
1018 * O(n) complexity order.
1020 * When encountering logical op &,|,^
1021 * 1. parse the last value if any
1022 * 2. create a new tree
1023 * 3. add the expression (simple exp, or exp (subtree)) to the tree
1024 * 4. concatenate this tree with the current tree on top of the stack
1025 * When encountering math ops >,>=,<,<=,=,!=
1026 * 1. add to op to the simple expression
1027 * 2. concatenate last field component to field path
1028 * When encountering concatening ops .
1029 * 1. concatenate last field component to field path
1030 * When encountering opening parenthesis (,{,[
1031 * 1. create a new subtree on top of tree stack
1032 * When encountering closing parenthesis ),},]
1033 * 1. add the expression on right child of the current tree
1034 * 2. the subtree is completed, allocate a new subtree
1035 * 3. pop the tree value from the tree stack
1038 g_print("expression: %s\n",filter
->expression
);
1039 g_print("strlen(expression): %i\n",strlen(filter
->expression
));
1040 for(i
=0;i
<strlen(filter
->expression
);i
++) {
1042 g_print("%c ",filter
->expression
[i
]);
1043 switch(filter
->expression
[i
]) {
1049 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1050 while(t1
->right
!= LTTV_TREE_IDLE
) {
1051 g_assert(t1
->right
== LTTV_TREE_NODE
);
1054 t2
= lttv_filter_tree_new();
1055 t2
->node
= LTTV_LOGICAL_AND
;
1056 if(subtree
!= NULL
) { /* append subtree to current tree */
1057 t2
->left
= LTTV_TREE_NODE
;
1058 t2
->l_child
.t
= subtree
;
1060 t1
->right
= LTTV_TREE_NODE
;
1062 } else { /* append a simple expression */
1063 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1064 // a_simple_expression->value = g_string_free(a_field_component,FALSE);
1065 a_field_component
= g_string_new("");
1066 t2
->left
= LTTV_TREE_LEAF
;
1067 t2
->l_child
.leaf
= a_simple_expression
;
1068 a_simple_expression
= lttv_simple_expression_new();
1069 t1
->right
= LTTV_TREE_NODE
;
1071 g_print("t1:%p t1->child:%p\n",t1
,t1
->r_child
.t
);
1077 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1078 while(t1
->right
!= LTTV_TREE_IDLE
) {
1079 g_assert(t1
->right
== LTTV_TREE_NODE
);
1082 t2
= lttv_filter_tree_new();
1083 t2
->node
= LTTV_LOGICAL_OR
;
1084 if(subtree
!= NULL
) { /* append subtree to current tree */
1085 t2
->left
= LTTV_TREE_NODE
;
1086 t2
->l_child
.t
= subtree
;
1088 t1
->right
= LTTV_TREE_NODE
;
1090 } else { /* append a simple expression */
1091 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1092 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1093 a_field_component
= g_string_new("");
1094 t2
->left
= LTTV_TREE_LEAF
;
1095 t2
->l_child
.leaf
= a_simple_expression
;
1096 a_simple_expression
= lttv_simple_expression_new();
1097 t1
->right
= LTTV_TREE_NODE
;
1104 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1105 while(t1
->right
!= LTTV_TREE_IDLE
) {
1106 g_assert(t1
->right
== LTTV_TREE_NODE
);
1109 t2
= lttv_filter_tree_new();
1110 t2
->node
= LTTV_LOGICAL_XOR
;
1111 if(subtree
!= NULL
) { /* append subtree to current tree */
1112 t2
->left
= LTTV_TREE_NODE
;
1113 t2
->l_child
.t
= subtree
;
1115 t1
->right
= LTTV_TREE_NODE
;
1117 } else { /* append a simple expression */
1118 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1119 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1120 a_field_component
= g_string_new("");
1121 t2
->left
= LTTV_TREE_LEAF
;
1122 t2
->l_child
.leaf
= a_simple_expression
;
1123 a_simple_expression
= lttv_simple_expression_new();
1124 t1
->right
= LTTV_TREE_NODE
;
1129 case '!': /* not, or not equal (math op) */
1131 if(filter
->expression
[i
+1] == '=') { /* != */
1132 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1133 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1134 a_field_component
= g_string_new("");
1135 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_NE
);
1138 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1139 while(t1
->right
!= LTTV_TREE_IDLE
) {
1140 g_assert(t1
->right
== LTTV_TREE_NODE
);
1143 t2
= lttv_filter_tree_new();
1144 t2
->node
= LTTV_LOGICAL_NOT
;
1145 t1
->right
= LTTV_TREE_NODE
;
1150 case '(': /* start of parenthesis */
1154 p_nesting
++; /* incrementing parenthesis nesting value */
1155 t1
= lttv_filter_tree_new();
1156 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
1159 case ')': /* end of parenthesis */
1163 p_nesting
--; /* decrementing parenthesis nesting value */
1164 if(p_nesting
<0 || tree_stack
->len
<2) {
1165 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1166 is not valid due to parenthesis incorrect use",filter
->expression
);
1170 /* there must at least be the root tree left in the array */
1171 g_assert(tree_stack
->len
>0);
1173 if(subtree
!= NULL
) { /* append subtree to current tree */
1174 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1175 while(t1
->right
!= LTTV_TREE_IDLE
) {
1176 g_assert(t1
->right
== LTTV_TREE_NODE
);
1179 t1
->right
= LTTV_TREE_NODE
;
1180 t1
->r_child
.t
= subtree
;
1181 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1182 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1183 } else { /* assign subtree as current tree */
1184 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1185 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1186 a_field_component
= g_string_new("");
1187 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1189 while(t1
->right
!= LTTV_TREE_IDLE
) {
1190 g_print("while right:%i %p->child:%p\n",t1
->right
,t1
,t1
->r_child
.t
);
1191 g_assert(t1
->right
== LTTV_TREE_NODE
);
1192 g_assert(t1
->r_child
.t
!= NULL
);
1196 t1
->right
= LTTV_TREE_LEAF
;
1197 t1
->r_child
.leaf
= a_simple_expression
;
1198 a_simple_expression
= lttv_simple_expression_new();
1199 subtree
= g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1204 * mathematic operators
1206 case '<': /* lower, lower or equal */
1208 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1209 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1210 a_field_component
= g_string_new("");
1211 if(filter
->expression
[i
+1] == '=') { /* <= */
1213 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LE
);
1214 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LT
);
1217 case '>': /* higher, higher or equal */
1219 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1220 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1221 a_field_component
= g_string_new("");
1222 if(filter
->expression
[i
+1] == '=') { /* >= */
1224 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GE
);
1225 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GT
);
1228 case '=': /* equal */
1230 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1231 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1232 a_field_component
= g_string_new("");
1233 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1237 * Field concatening caracter
1242 * divide field expression into elements
1243 * in a_field_path array.
1245 /* FIXME: check for double values */
1246 // if(a_simple_expression->op == NULL) {
1247 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1248 a_field_component
= g_string_new("");
1254 default: /* concatening current string */
1255 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1259 g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree
,tree
,t1
,t2
);
1260 g_print("stack size: %i\n",tree_stack
->len
);
1263 * Preliminary check to see
1264 * if tree was constructed correctly
1267 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1268 is not valid due to parenthesis incorrect use",filter
->expression
);
1272 if(tree_stack
->len
!= 1) /* only root tree should remain */
1275 /* processing last element of expression */
1276 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1277 while(t1
->right
!= LTTV_TREE_IDLE
) {
1278 g_assert(t1
->right
== LTTV_TREE_NODE
);
1281 if(subtree
!= NULL
) { /* add the subtree */
1282 t1
->right
= LTTV_TREE_NODE
;
1283 t1
->r_child
.t
= subtree
;
1285 } else { /* add a leaf */
1286 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1287 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1288 a_field_component
= NULL
;
1289 t1
->right
= LTTV_TREE_LEAF
;
1290 t1
->r_child
.leaf
= a_simple_expression
;
1291 a_simple_expression
= NULL
;
1295 /* free the pointer array */
1296 g_assert(a_field_path
->len
== 0);
1297 g_ptr_array_free(a_field_path
,TRUE
);
1299 /* free the tree stack -- but keep the root tree */
1300 // g_ptr_array_free(tree_stack,FALSE);
1301 filter
->head
= g_ptr_array_remove_index(tree_stack
,0);
1302 g_ptr_array_free(tree_stack
,TRUE
);
1304 /* free the field buffer if allocated */
1305 if(a_field_component
!= NULL
) g_string_free(a_field_component
,TRUE
);
1307 /* free the simple expression buffer if allocated */
1308 if(a_simple_expression
!= NULL
) lttv_simple_expression_destroy(a_simple_expression
);
1310 g_assert(filter
->head
!= NULL
); /* tree should exist */
1311 g_assert(subtree
== NULL
); /* remaining subtree should be included in main tree */
1314 g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1315 lttv_print_tree(filter
->head
) ;
1316 g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1324 * @fn void lttv_filter_destroy(LttvFilter*)
1326 * Destroy the current LttvFilter
1327 * @param filter pointer to the current LttvFilter
1330 lttv_filter_destroy(LttvFilter
* filter
) {
1332 g_free(filter
->expression
);
1333 lttv_filter_tree_destroy(filter
->head
);
1339 * LttvFilterTree* lttv_filter_tree_new()
1341 * Assign a new tree for the current expression
1343 * @return pointer of LttvFilterTree
1346 lttv_filter_tree_new() {
1347 LttvFilterTree
* tree
;
1349 tree
= g_new(LttvFilterTree
,1);
1350 tree
->node
= 0; //g_new(lttv_expression,1);
1351 tree
->left
= LTTV_TREE_IDLE
;
1352 tree
->right
= LTTV_TREE_IDLE
;
1353 tree
->r_child
.t
= NULL
;
1354 tree
->l_child
.t
= NULL
;
1360 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1362 * Append a new expression to the expression
1363 * defined in the current filter
1364 * @param filter pointer to the current LttvFilter
1365 * @param expression string that must be appended
1366 * @return Success/Failure of operation
1368 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, char *expression
) {
1370 if(expression
== NULL
) return FALSE
;
1371 if(filter
== NULL
) {
1372 filter
= lttv_filter_new();
1373 filter
->expression
= expression
;
1374 } else if(filter
->expression
== NULL
) {
1375 filter
->expression
= expression
;
1377 filter
->expression
= g_strconcat(filter
->expression
,"&",expression
);
1380 return lttv_filter_update(filter
);
1385 * @fn void lttv_filter_clear_expression(LttvFilter*)
1387 * Clear the filter expression from the
1388 * current filter and sets its pointer to NULL
1389 * @param filter pointer to the current LttvFilter
1391 void lttv_filter_clear_expression(LttvFilter
* filter
) {
1393 if(filter
->expression
!= NULL
) {
1394 g_free(filter
->expression
);
1395 filter
->expression
= NULL
;
1401 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1403 * Destroys the tree and his sub-trees
1404 * @param tree Tree which must be destroyed
1407 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1409 if(tree
== NULL
) return;
1411 if(tree
->left
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->l_child
.leaf
);
1412 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1414 if(tree
->right
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->r_child
.leaf
);
1415 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1417 // g_free(tree->node);
1422 * gboolean lttv_filter_tree_parse(LttvFilterTree*,LttEvent,LttTracefile,LttTrace,LttvProcessState)
1424 * Global parsing function for the current
1426 * @param tree pointer to the current LttvFilterTree
1427 * @param event current LttEvent, NULL if not used
1428 * @param tracefile current LttTracefile, NULL if not used
1429 * @param trace current LttTrace, NULL if not used
1430 * @param state current LttvProcessState, NULL if not used
1433 lttv_filter_tree_parse(
1436 LttTracefile
* tracefile
,
1438 LttvProcessState
* state
1443 * Each tree is parsed in inorder.
1444 * This way, it's possible to apply the left filter of the
1445 * tree, then decide whether or not the right branch should
1446 * be parsed depending on the linking logical operator
1448 * Each node consists in a
1449 * 1. logical operator
1450 * 2. left child ( node or simple expression )
1451 * 3. right child ( node or simple expression )
1453 * When the child is a simple expression, we must
1454 * before all determine if the expression refers to
1455 * a structure which is whithin observation ( not NULL ).
1456 * -If so, the expression is evaluated.
1457 * -If not, the result is set to TRUE since this particular
1458 * operation does not interfere with the lttv structure
1460 * The result of each simple expression will directly
1461 * affect the next branch. This way, depending on
1462 * the linking logical operator, the parser will decide
1463 * to explore or not the next branch.
1465 * -If result of left branch is 0 / FALSE
1466 * then don't explore right branch and return 0;
1467 * -If result of left branch is 1 / TRUE then explore
1469 * -If result of left branch is 1 / TRUE
1470 * then don't explore right branch and return 1;
1471 * -If result of left branch is 0 / FALSE then explore
1473 * -Result of left branch will not affect exploration of
1476 g_print("filter::lttv_parse_tree(...)\n");
1478 gboolean lresult
= FALSE
, rresult
= FALSE
;
1483 if(t
->left
== LTTV_TREE_NODE
) lresult
= lttv_filter_tree_parse(t
->l_child
.t
,event
,tracefile
,trace
,state
);
1484 else if(t
->left
== LTTV_TREE_LEAF
) {
1485 //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);
1487 v
= t
->l_child
.leaf
->value
;
1488 switch(t
->l_child
.leaf
->field
) {
1490 case LTTV_FILTER_TRACE_NAME
:
1491 if(trace
== NULL
) lresult
= TRUE
;
1492 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_trace_name(trace
),v
);
1494 case LTTV_FILTER_TRACEFILE_NAME
:
1495 if(tracefile
== NULL
) lresult
= TRUE
;
1496 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_tracefile_name(tracefile
),v
);
1498 case LTTV_FILTER_STATE_PID
:
1499 if(state
== NULL
) lresult
= TRUE
;
1500 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1502 case LTTV_FILTER_STATE_PPID
:
1503 if(state
== NULL
) lresult
= TRUE
;
1504 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1506 case LTTV_FILTER_STATE_CT
:
1507 if(state
== NULL
) lresult
= TRUE
;
1509 double val
= ltt_time_to_double(state
->creation_time
);
1510 lresult
= t
->l_child
.leaf
->op((gpointer
)&val
,v
);
1513 case LTTV_FILTER_STATE_IT
:
1514 if(state
== NULL
) lresult
= TRUE
;
1516 double val
= ltt_time_to_double(state
->insertion_time
);
1517 lresult
= t
->l_child
.leaf
->op((gpointer
)&val
,v
);
1520 case LTTV_FILTER_STATE_P_NAME
:
1522 * FIXME: Yet to be done ( I think ? )
1526 case LTTV_FILTER_STATE_EX_MODE
:
1527 if(state
== NULL
) lresult
= TRUE
;
1528 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->t
,v
);
1530 case LTTV_FILTER_STATE_EX_SUBMODE
:
1531 if(state
== NULL
) lresult
= TRUE
;
1532 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->n
,v
);
1534 case LTTV_FILTER_STATE_P_STATUS
:
1535 if(state
== NULL
) lresult
= TRUE
;
1536 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->s
,v
);
1538 case LTTV_FILTER_STATE_CPU
:
1540 * FIXME: What is the comparison value ?
1544 case LTTV_FILTER_EVENT_NAME
:
1545 if(event
== NULL
) lresult
= TRUE
;
1546 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_event_eventtype(event
),v
);
1549 case LTTV_FILTER_EVENT_CATEGORY
:
1551 * FIXME: Not yet implemented
1555 case LTTV_FILTER_EVENT_TIME
:
1556 // if(event == NULL) lresult = TRUE;
1558 // double val = ltt_time_to_double(event->event_time);
1559 // lresult = t->l_child.leaf->op((gpointer)&val,v);
1563 case LTTV_FILTER_EVENT_TSC
:
1564 // if(event == NULL) lresult = TRUE;
1566 // double val = ltt_time_to_double(event->event_time);
1567 // lresult = t->l_child.leaf->op((gpointer)&val,v);
1570 * FIXME: Where is event.tsc
1574 case LTTV_FILTER_EVENT_FIELD
:
1576 * TODO: Use the offset to
1577 * find the dynamic field
1578 * in the event struct
1583 * This case should never be
1584 * parsed, if so, the whole
1585 * filtering is cancelled
1587 g_warning("Error while parsing the filter tree");
1593 * Parse linking operator
1594 * make a cutoff if possible
1596 if((t
->node
& LTTV_LOGICAL_OR
) && lresult
== TRUE
) return TRUE
;
1597 if((t
->node
& LTTV_LOGICAL_AND
) && lresult
== FALSE
) return FALSE
;
1600 * Parse right branch
1602 if(t
->right
== LTTV_TREE_NODE
) rresult
= lttv_filter_tree_parse(t
->r_child
.t
,event
,tracefile
,trace
,state
);
1603 else if(t
->right
== LTTV_TREE_LEAF
) {
1604 //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);
1606 v
= t
->r_child
.leaf
->value
;
1607 switch(t
->r_child
.leaf
->field
) {
1609 case LTTV_FILTER_TRACE_NAME
:
1610 if(trace
== NULL
) rresult
= TRUE
;
1611 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_trace_name(trace
),v
);
1613 case LTTV_FILTER_TRACEFILE_NAME
:
1614 if(tracefile
== NULL
) rresult
= TRUE
;
1615 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_tracefile_name(tracefile
),v
);
1617 case LTTV_FILTER_STATE_PID
:
1618 if(state
== NULL
) rresult
= TRUE
;
1619 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1621 case LTTV_FILTER_STATE_PPID
:
1622 if(state
== NULL
) rresult
= TRUE
;
1623 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1625 case LTTV_FILTER_STATE_CT
:
1626 if(state
== NULL
) rresult
= TRUE
;
1628 double val
= ltt_time_to_double(state
->creation_time
);
1629 rresult
= t
->r_child
.leaf
->op((gpointer
)&val
,v
);
1632 case LTTV_FILTER_STATE_IT
:
1633 if(state
== NULL
) rresult
= TRUE
;
1635 double val
= ltt_time_to_double(state
->insertion_time
);
1636 rresult
= t
->r_child
.leaf
->op((gpointer
)&val
,v
);
1639 case LTTV_FILTER_STATE_P_NAME
:
1641 * FIXME: Yet to be done ( I think ? )
1645 case LTTV_FILTER_STATE_EX_MODE
:
1646 if(state
== NULL
) rresult
= TRUE
;
1647 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->t
,v
);
1649 case LTTV_FILTER_STATE_EX_SUBMODE
:
1650 if(state
== NULL
) rresult
= TRUE
;
1651 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->n
,v
);
1653 case LTTV_FILTER_STATE_P_STATUS
:
1654 if(state
== NULL
) rresult
= TRUE
;
1655 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->s
,v
);
1657 case LTTV_FILTER_STATE_CPU
:
1659 * FIXME: What is the comparison value ?
1663 case LTTV_FILTER_EVENT_NAME
:
1664 if(event
== NULL
) rresult
= TRUE
;
1665 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_event_eventtype(event
),v
);
1668 case LTTV_FILTER_EVENT_CATEGORY
:
1670 * FIXME: Not yet implemented
1674 case LTTV_FILTER_EVENT_TIME
:
1675 // if(event == NULL) rresult = TRUE;
1677 // double val = ltt_time_to_double(event->event_time);
1678 // rresult = t->r_child.leaf->op((gpointer)&val,v);
1682 case LTTV_FILTER_EVENT_TSC
:
1683 // if(event == NULL) rresult = TRUE;
1685 // double val = ltt_time_to_double(event->event_time);
1686 // rresult = t->r_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, this subtree
1706 g_warning("Error while parsing the filter tree");
1712 * Apply and return the
1713 * logical link between the
1717 case LTTV_LOGICAL_OR
: return (lresult
| rresult
);
1718 case LTTV_LOGICAL_AND
: return (lresult
& rresult
);
1719 case LTTV_LOGICAL_NOT
: return (!rresult
);
1720 case LTTV_LOGICAL_XOR
: return (lresult
^ rresult
);
1723 * This case should never be
1724 * parsed, if so, this subtree
1733 * @fn void lttv_print_tree(LttvFilterTree*)
1736 * @param t the pointer to the current LttvFilterTree
1739 lttv_print_tree(LttvFilterTree
* t
) {
1741 g_print("node:%p lchild:%p rchild:%p\n",t
, //t->l_child.t,t->r_child.t);
1742 (t
->left
==LTTV_TREE_NODE
)?t
->l_child
.t
:NULL
,
1743 (t
->right
==LTTV_TREE_NODE
)?t
->r_child
.t
:NULL
);
1744 g_print("node type: %i / [left] %i / [right] %i\n",t
->node
,t
->left
,t
->right
);
1745 if(t
->left
== LTTV_TREE_NODE
) lttv_print_tree(t
->l_child
.t
);
1746 else if(t
->left
== LTTV_TREE_LEAF
) {
1747 // g_assert(t->l_child.leaf->value != NULL);
1748 g_print("%p: left is %i %p value\n",t
,t
->l_child
.leaf
->field
,t
->l_child
.leaf
->op
);
1750 if(t
->right
== LTTV_TREE_NODE
) lttv_print_tree(t
->r_child
.t
);
1751 else if(t
->right
== LTTV_TREE_LEAF
) {
1752 // g_assert(t->r_child.leaf->value != NULL);
1753 g_print("%p: right is %i %p value\n",t
,t
->r_child
.leaf
->field
,t
->r_child
.leaf
->op
);
1759 * gboolean lttv_filter_tracefile(LttvFilter*, LttTracefile*)
1761 * Apply the filter to a specific trace
1762 * @param filter the current filter applied
1763 * @param tracefile the trace to apply the filter to
1764 * @return success/failure of operation
1767 lttv_filter_tracefile(LttvFilter
*filter
, LttTracefile
*tracefile
) {
1769 return lttv_filter_tree_parse(filter
->head
,NULL
,tracefile
,NULL
,NULL
);
1774 * @fn gboolean lttv_filter_tracestate(LttvFilter*,LttvTraceState*)
1776 * Parse the current tracestate
1777 * @param filter pointer to the current LttvFilter
1778 * @param tracestate pointer to the current tracestate
1781 lttv_filter_tracestate(LttvFilter
*filter
, LttvTraceState
*tracestate
) {
1786 * @fn gboolean lttv_filter_event(LttvFilter*,LttEvent*)
1788 * Apply the filter to a specific event
1789 * @param filter the current filter applied
1790 * @param event the event to apply the filter to
1791 * @return success/failure of operation
1794 lttv_filter_event(LttvFilter
*filter
, LttEvent
*event
) {
1799 * @fn static void module_init()
1801 * Initializes the filter module and specific values
1803 static void module_init()
1809 * Destroys the filter module and specific values
1811 static void module_destroy()
1817 LTTV_MODULE("filter", "Filters traceset and events", \
1818 "Filters traceset and events specifically to user input", \
1819 module_init
, module_destroy
)