1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2005 Michel Dagenais
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 simple expr [ op expr ]
26 read_simple_expression
27 read_field_path [ rel value ]
30 read_field_component [. field path]
39 path(component...) -> field
41 consist in AND, OR and NOT nested expressions, forming a tree with
42 simple relations as leaves. The simple relations test is a field
43 in an event is equal, not equal, smaller, smaller or equal, larger, or
44 larger or equal to a specified value.
54 * - refine switch of expression in multiple uses functions
55 * - remove the idle expressions in the tree ****
56 * - add the current simple expression to the tree
57 * * clear the field_path array after use
60 #include <lttv/filter.h>
66 LTTV_FILTER_TRACEFILE,
79 LTTV_FILTER_EX_SUBMODE,
85 * @fn void lttv_filter_tree_add_node(GPtrArray*,LttvFilterTree*,LttvLogicalOp)
87 * add a node to the current tree
88 * FIXME: Might be used to lower coding in lttv_filter_new switch expression
89 * @param stack the tree stack
90 * @param subtree the subtree if available (pointer or NULL)
91 * @param op the logical operator that will form the node
94 lttv_filter_tree_add_node(GPtrArray
* stack
, LttvFilterTree
* subtree
, LttvLogicalOp op
) {
96 LttvFilterTree
* t1
= NULL
;
97 LttvFilterTree
* t2
= NULL
;
99 t1
= (LttvFilterTree
*)g_ptr_array_index(stack
,stack
->len
-1);
100 while(t1
->right
!= LTTV_TREE_IDLE
) t1
= (LttvFilterTree
*)t1
->r_child
.t
;
101 t2
= lttv_filter_tree_new();
103 if(subtree
!= NULL
) {
104 t2
->left
= LTTV_TREE_NODE
;
105 t2
->l_child
.t
= (LttvFilterTree
*)subtree
;
107 t1
->right
= LTTV_TREE_NODE
;
110 // a_simple_expression->value = a_field_component->str;
111 // a_field_component = g_string_new("");
112 t2
->left
= LTTV_TREE_LEAF
;
113 // t2->l_child.leaf = a_simple_expression;
114 // a_simple_expression = g_new(lttv_simple_expression,1);
115 t1
->right
= LTTV_TREE_NODE
;
123 * @fn LttvSimpleExpression* lttv_simple_expression_new()
125 * Constructor for LttvSimpleExpression
126 * @return pointer to new LttvSimpleExpression
128 LttvSimpleExpression
*
129 lttv_simple_expression_new() {
131 LttvSimpleExpression
* se
= g_new(LttvSimpleExpression
,1);
133 se
->field
= LTTV_FILTER_UNDEFINED
;
142 * @fn gboolean lttv_simple_expression_add_field(GPtrArray*,LttvSimpleExpression*)
144 * Parse through filtering field hierarchy as specified
145 * by user. This function compares each value to
146 * predetermined quarks
147 * @param fp The field path list
148 * @param se current simple expression
149 * @return success/failure of operation
152 lttv_simple_expression_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);
458 * @fn gint lttv_struct_type(gint)
460 * Finds the structure type depending
461 * on the fields in parameters
462 * @params ft Field of the current structure
463 * @return LttvStructType enum or -1 for error
466 lttv_struct_type(gint ft
) {
469 case LTTV_FILTER_TRACE_NAME
:
470 return LTTV_FILTER_TRACE
;
472 case LTTV_FILTER_TRACEFILE_NAME
:
473 return LTTV_FILTER_TRACEFILE
;
475 case LTTV_FILTER_STATE_PID
:
476 case LTTV_FILTER_STATE_PPID
:
477 case LTTV_FILTER_STATE_CT
:
478 case LTTV_FILTER_STATE_IT
:
479 case LTTV_FILTER_STATE_P_NAME
:
480 case LTTV_FILTER_STATE_EX_MODE
:
481 case LTTV_FILTER_STATE_EX_SUBMODE
:
482 case LTTV_FILTER_STATE_P_STATUS
:
483 case LTTV_FILTER_STATE_CPU
:
484 return LTTV_FILTER_STATE
;
486 case LTTV_FILTER_EVENT_NAME
:
487 case LTTV_FILTER_EVENT_CATEGORY
:
488 case LTTV_FILTER_EVENT_TIME
:
489 case LTTV_FILTER_EVENT_TSC
:
490 case LTTV_FILTER_EVENT_FIELD
:
491 return LTTV_FILTER_EVENT
;
499 * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue)
501 * Applies the 'equal' operator to the
502 * specified structure and value
503 * @param v1 left member of comparison
504 * @param v2 right member of comparison
505 * @return success/failure of operation
507 gboolean
lttv_apply_op_eq_uint64(gpointer v1
, LttvFieldValue v2
) {
509 guint64
* r
= (guint64
*) v1
;
510 return (*r
== v2
.v_uint64
);
515 * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue)
517 * Applies the 'equal' operator to the
518 * specified structure and value
519 * @param v1 left member of comparison
520 * @param v2 right member of comparison
521 * @return success/failure of operation
523 gboolean
lttv_apply_op_eq_uint32(gpointer v1
, LttvFieldValue v2
) {
524 guint32
* r
= (guint32
*) v1
;
525 return (*r
== v2
.v_uint32
);
529 * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue)
531 * Applies the 'equal' operator to the
532 * specified structure and value
533 * @param v1 left member of comparison
534 * @param v2 right member of comparison
535 * @return success/failure of operation
537 gboolean
lttv_apply_op_eq_uint16(gpointer v1
, LttvFieldValue v2
) {
538 guint16
* r
= (guint16
*) v1
;
539 return (*r
== v2
.v_uint16
);
543 * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue)
545 * Applies the 'equal' operator to the
546 * specified structure and value
547 * @param v1 left member of comparison
548 * @param v2 right member of comparison
549 * @return success/failure of operation
551 gboolean
lttv_apply_op_eq_double(gpointer v1
, LttvFieldValue v2
) {
552 double* r
= (double*) v1
;
553 return (*r
== v2
.v_double
);
557 * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue)
559 * Applies the 'equal' operator to the
560 * specified structure and value
561 * @param v1 left member of comparison
562 * @param v2 right member of comparison
563 * @return success/failure of operation
565 gboolean
lttv_apply_op_eq_string(gpointer v1
, LttvFieldValue v2
) {
566 char* r
= (char*) v1
;
567 return (!g_strcasecmp(r
,v2
.v_string
));
571 * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue)
573 * Applies the 'not equal' operator to the
574 * specified structure and value
575 * @param v1 left member of comparison
576 * @param v2 right member of comparison
577 * @return success/failure of operation
579 gboolean
lttv_apply_op_ne_uint64(gpointer v1
, LttvFieldValue v2
) {
580 guint64
* r
= (guint64
*) v1
;
581 return (*r
!= v2
.v_uint64
);
585 * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue)
587 * Applies the 'not equal' operator to the
588 * specified structure and value
589 * @param v1 left member of comparison
590 * @param v2 right member of comparison
591 * @return success/failure of operation
593 gboolean
lttv_apply_op_ne_uint32(gpointer v1
, LttvFieldValue v2
) {
594 guint32
* r
= (guint32
*) v1
;
595 return (*r
!= v2
.v_uint32
);
599 * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue)
601 * Applies the 'not equal' operator to the
602 * specified structure and value
603 * @param v1 left member of comparison
604 * @param v2 right member of comparison
605 * @return success/failure of operation
607 gboolean
lttv_apply_op_ne_uint16(gpointer v1
, LttvFieldValue v2
) {
608 guint16
* r
= (guint16
*) v1
;
609 return (*r
!= v2
.v_uint16
);
613 * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue)
615 * Applies the 'not equal' operator to the
616 * specified structure and value
617 * @param v1 left member of comparison
618 * @param v2 right member of comparison
619 * @return success/failure of operation
621 gboolean
lttv_apply_op_ne_double(gpointer v1
, LttvFieldValue v2
) {
622 double* r
= (double*) v1
;
623 return (*r
!= v2
.v_double
);
627 * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue)
629 * Applies the 'not equal' operator to the
630 * specified structure and value
631 * @param v1 left member of comparison
632 * @param v2 right member of comparison
633 * @return success/failure of operation
635 gboolean
lttv_apply_op_ne_string(gpointer v1
, LttvFieldValue v2
) {
636 char* r
= (char*) v1
;
637 return (g_strcasecmp(r
,v2
.v_string
));
641 * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue)
643 * Applies the 'lower than' operator to the
644 * specified structure and value
645 * @param v1 left member of comparison
646 * @param v2 right member of comparison
647 * @return success/failure of operation
649 gboolean
lttv_apply_op_lt_uint64(gpointer v1
, LttvFieldValue v2
) {
650 guint64
* r
= (guint64
*) v1
;
651 return (*r
< v2
.v_uint64
);
655 * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue)
657 * Applies the 'lower than' operator to the
658 * specified structure and value
659 * @param v1 left member of comparison
660 * @param v2 right member of comparison
661 * @return success/failure of operation
663 gboolean
lttv_apply_op_lt_uint32(gpointer v1
, LttvFieldValue v2
) {
664 guint32
* r
= (guint32
*) v1
;
665 return (*r
< v2
.v_uint32
);
669 * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue)
671 * Applies the 'lower than' operator to the
672 * specified structure and value
673 * @param v1 left member of comparison
674 * @param v2 right member of comparison
675 * @return success/failure of operation
677 gboolean
lttv_apply_op_lt_uint16(gpointer v1
, LttvFieldValue v2
) {
678 guint16
* r
= (guint16
*) v1
;
679 return (*r
< v2
.v_uint16
);
683 * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue)
685 * Applies the 'lower than' operator to the
686 * specified structure and value
687 * @param v1 left member of comparison
688 * @param v2 right member of comparison
689 * @return success/failure of operation
691 gboolean
lttv_apply_op_lt_double(gpointer v1
, LttvFieldValue v2
) {
692 double* r
= (double*) v1
;
693 return (*r
< v2
.v_double
);
697 * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue)
699 * Applies the 'lower or equal' operator to the
700 * specified structure and value
701 * @param v1 left member of comparison
702 * @param v2 right member of comparison
703 * @return success/failure of operation
705 gboolean
lttv_apply_op_le_uint64(gpointer v1
, LttvFieldValue v2
) {
706 guint64
* r
= (guint64
*) v1
;
707 return (*r
<= v2
.v_uint64
);
711 * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue)
713 * Applies the 'lower or equal' operator to the
714 * specified structure and value
715 * @param v1 left member of comparison
716 * @param v2 right member of comparison
717 * @return success/failure of operation
719 gboolean
lttv_apply_op_le_uint32(gpointer v1
, LttvFieldValue v2
) {
720 guint32
* r
= (guint32
*) v1
;
721 return (*r
<= v2
.v_uint32
);
725 * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue)
727 * Applies the 'lower or equal' operator to the
728 * specified structure and value
729 * @param v1 left member of comparison
730 * @param v2 right member of comparison
731 * @return success/failure of operation
733 gboolean
lttv_apply_op_le_uint16(gpointer v1
, LttvFieldValue v2
) {
734 guint16
* r
= (guint16
*) v1
;
735 return (*r
<= v2
.v_uint16
);
739 * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue)
741 * Applies the 'lower or equal' operator to the
742 * specified structure and value
743 * @param v1 left member of comparison
744 * @param v2 right member of comparison
745 * @return success/failure of operation
747 gboolean
lttv_apply_op_le_double(gpointer v1
, LttvFieldValue v2
) {
748 double* r
= (double*) v1
;
749 return (*r
<= v2
.v_double
);
753 * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue)
755 * Applies the 'greater than' operator to the
756 * specified structure and value
757 * @param v1 left member of comparison
758 * @param v2 right member of comparison
759 * @return success/failure of operation
761 gboolean
lttv_apply_op_gt_uint64(gpointer v1
, LttvFieldValue v2
) {
762 guint64
* r
= (guint64
*) v1
;
763 return (*r
> v2
.v_uint64
);
767 * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue)
769 * Applies the 'greater than' operator to the
770 * specified structure and value
771 * @param v1 left member of comparison
772 * @param v2 right member of comparison
773 * @return success/failure of operation
775 gboolean
lttv_apply_op_gt_uint32(gpointer v1
, LttvFieldValue v2
) {
776 guint32
* r
= (guint32
*) v1
;
777 return (*r
> v2
.v_uint32
);
781 * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue)
783 * Applies the 'greater than' operator to the
784 * specified structure and value
785 * @param v1 left member of comparison
786 * @param v2 right member of comparison
787 * @return success/failure of operation
789 gboolean
lttv_apply_op_gt_uint16(gpointer v1
, LttvFieldValue v2
) {
790 guint16
* r
= (guint16
*) v1
;
791 return (*r
> v2
.v_uint16
);
795 * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue)
797 * Applies the 'greater than' operator to the
798 * specified structure and value
799 * @param v1 left member of comparison
800 * @param v2 right member of comparison
801 * @return success/failure of operation
803 gboolean
lttv_apply_op_gt_double(gpointer v1
, LttvFieldValue v2
) {
804 double* r
= (double*) v1
;
805 return (*r
> v2
.v_double
);
809 * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue)
811 * Applies the 'greater or equal' operator to the
812 * specified structure and value
813 * @param v1 left member of comparison
814 * @param v2 right member of comparison
815 * @return success/failure of operation
817 gboolean
lttv_apply_op_ge_uint64(gpointer v1
, LttvFieldValue v2
) {
818 guint64
* r
= (guint64
*) v1
;
819 return (*r
>= v2
.v_uint64
);
823 * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue)
825 * Applies the 'greater or equal' operator to the
826 * specified structure and value
827 * @param v1 left member of comparison
828 * @param v2 right member of comparison
829 * @return success/failure of operation
831 gboolean
lttv_apply_op_ge_uint32(gpointer v1
, LttvFieldValue v2
) {
832 guint32
* r
= (guint32
*) v1
;
833 return (*r
>= v2
.v_uint32
);
837 * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue)
839 * Applies the 'greater or equal' operator to the
840 * specified structure and value
841 * @param v1 left member of comparison
842 * @param v2 right member of comparison
843 * @return success/failure of operation
845 gboolean
lttv_apply_op_ge_uint16(gpointer v1
, LttvFieldValue v2
) {
846 guint16
* r
= (guint16
*) v1
;
847 return (*r
>= v2
.v_uint16
);
851 * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue)
853 * Applies the 'greater or equal' operator to the
854 * specified structure and value
855 * @param v1 left member of comparison
856 * @param v2 right member of comparison
857 * @return success/failure of operation
859 gboolean
lttv_apply_op_ge_double(gpointer v1
, LttvFieldValue v2
) {
860 double* r
= (double*) v1
;
861 return (*r
>= v2
.v_double
);
866 * @fn LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree*)
868 * Makes a copy of the current filter tree
869 * @param tree pointer to the current tree
870 * @return new copy of the filter tree
873 lttv_filter_tree_clone(LttvFilterTree
* tree
) {
875 LttvFilterTree
* newtree
= lttv_filter_tree_new();
877 newtree
->node
= tree
->node
;
879 newtree
->left
= tree
->left
;
880 if(newtree
->left
== LTTV_TREE_NODE
) {
881 newtree
->l_child
.t
= lttv_filter_tree_clone(tree
->l_child
.t
);
882 } else if(newtree
->left
== LTTV_TREE_LEAF
) {
883 newtree
->l_child
.leaf
= lttv_simple_expression_new();
884 newtree
->l_child
.leaf
->field
= tree
->l_child
.leaf
->field
;
885 newtree
->l_child
.leaf
->offset
= tree
->l_child
.leaf
->offset
;
886 newtree
->l_child
.leaf
->op
= tree
->l_child
.leaf
->op
;
887 /* FIXME: special case for string copy ! */
888 newtree
->l_child
.leaf
->value
= tree
->l_child
.leaf
->value
;
891 newtree
->right
= tree
->right
;
892 if(newtree
->right
== LTTV_TREE_NODE
) {
893 newtree
->r_child
.t
= lttv_filter_tree_clone(tree
->r_child
.t
);
894 } else if(newtree
->right
== LTTV_TREE_LEAF
) {
895 newtree
->r_child
.leaf
= lttv_simple_expression_new();
896 newtree
->r_child
.leaf
->field
= tree
->r_child
.leaf
->field
;
897 newtree
->r_child
.leaf
->offset
= tree
->r_child
.leaf
->offset
;
898 newtree
->r_child
.leaf
->op
= tree
->r_child
.leaf
->op
;
899 newtree
->r_child
.leaf
->value
= tree
->r_child
.leaf
->value
;
907 * @fn LttvFilter* lttv_filter_clone(LttvFilter*)
909 * Makes a copy of the current filter
910 * @param filter pointer to the current filter
911 * @return new copy of the filter
914 lttv_filter_clone(LttvFilter
* filter
) {
917 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
919 // newfilter->expression = g_new(char,1)
920 strcpy(newfilter
->expression
,filter
->expression
);
922 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
930 * @fn LttvFilter* lttv_filter_new()
932 * Creates a new lttv_filter
933 * @param expression filtering options string
934 * @param t pointer to the current LttvTrace
935 * @return the current lttv_filter or NULL if error
940 LttvFilter
* filter
= g_new(LttvFilter
,1);
941 filter
->expression
= NULL
;
947 * @fn gboolean lttv_filter_update(LttvFilter*)
949 * Updates the current LttvFilter by building
950 * its tree based upon the expression string
951 * @param filter pointer to the current LttvFilter
952 * @return Failure/Success of operation
955 lttv_filter_update(LttvFilter
* filter
) {
957 g_print("filter::lttv_filter_new()\n"); /* debug */
959 if(filter
->expression
== NULL
) return FALSE
;
963 p_nesting
=0; /* parenthesis nesting value */
967 *tree
= lttv_filter_tree_new(), /* main tree */
968 *subtree
= NULL
, /* buffer for subtrees */
974 * If the tree already exists,
975 * destroy it and build a new one
977 if(filter
->head
!= NULL
) lttv_filter_tree_destroy(filter
->head
);
982 * each element of the list
983 * is a sub tree created
984 * by the use of parenthesis in the
985 * global expression. The final tree
986 * will be the one left at the root of
989 GPtrArray
*tree_stack
= g_ptr_array_new();
990 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
992 /* temporary values */
993 GString
*a_field_component
= g_string_new("");
994 GPtrArray
*a_field_path
= g_ptr_array_new();
996 /* simple expression buffer */
997 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
1000 * Parse entire expression and construct
1001 * the binary tree. There are two steps
1002 * in browsing that string
1003 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
1004 * 2. finding simple expressions
1005 * - field path ( separated by dots )
1006 * - op ( >, <, =, >=, <=, !=)
1007 * - value ( integer, string ... )
1008 * To spare computing time, the whole
1009 * string is parsed in this loop for a
1010 * O(n) complexity order.
1012 * When encountering logical op &,|,^
1013 * 1. parse the last value if any
1014 * 2. create a new tree
1015 * 3. add the expression (simple exp, or exp (subtree)) to the tree
1016 * 4. concatenate this tree with the current tree on top of the stack
1017 * When encountering math ops >,>=,<,<=,=,!=
1018 * 1. add to op to the simple expression
1019 * 2. concatenate last field component to field path
1020 * When encountering concatening ops .
1021 * 1. concatenate last field component to field path
1022 * When encountering opening parenthesis (,{,[
1023 * 1. create a new subtree on top of tree stack
1024 * When encountering closing parenthesis ),},]
1025 * 1. add the expression on right child of the current tree
1026 * 2. the subtree is completed, allocate a new subtree
1027 * 3. pop the tree value from the tree stack
1030 g_print("expression: %s\n",filter
->expression
);
1031 g_print("strlen(expression): %i\n",strlen(filter
->expression
));
1032 for(i
=0;i
<strlen(filter
->expression
);i
++) {
1034 g_print("%c ",filter
->expression
[i
]);
1035 switch(filter
->expression
[i
]) {
1041 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1042 while(t1
->right
!= LTTV_TREE_IDLE
) {
1043 g_assert(t1
->right
== LTTV_TREE_NODE
);
1046 t2
= lttv_filter_tree_new();
1047 t2
->node
= LTTV_LOGICAL_AND
;
1048 if(subtree
!= NULL
) { /* append subtree to current tree */
1049 t2
->left
= LTTV_TREE_NODE
;
1050 t2
->l_child
.t
= subtree
;
1052 t1
->right
= LTTV_TREE_NODE
;
1054 } else { /* append a simple expression */
1055 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1056 // a_simple_expression->value = g_string_free(a_field_component,FALSE);
1057 a_field_component
= g_string_new("");
1058 t2
->left
= LTTV_TREE_LEAF
;
1059 t2
->l_child
.leaf
= a_simple_expression
;
1060 a_simple_expression
= lttv_simple_expression_new();
1061 t1
->right
= LTTV_TREE_NODE
;
1063 g_print("t1:%p t1->child:%p\n",t1
,t1
->r_child
.t
);
1069 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1070 while(t1
->right
!= LTTV_TREE_IDLE
) {
1071 g_assert(t1
->right
== LTTV_TREE_NODE
);
1074 t2
= lttv_filter_tree_new();
1075 t2
->node
= LTTV_LOGICAL_OR
;
1076 if(subtree
!= NULL
) { /* append subtree to current tree */
1077 t2
->left
= LTTV_TREE_NODE
;
1078 t2
->l_child
.t
= subtree
;
1080 t1
->right
= LTTV_TREE_NODE
;
1082 } else { /* append a simple expression */
1083 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1084 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1085 a_field_component
= g_string_new("");
1086 t2
->left
= LTTV_TREE_LEAF
;
1087 t2
->l_child
.leaf
= a_simple_expression
;
1088 a_simple_expression
= lttv_simple_expression_new();
1089 t1
->right
= LTTV_TREE_NODE
;
1096 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1097 while(t1
->right
!= LTTV_TREE_IDLE
) {
1098 g_assert(t1
->right
== LTTV_TREE_NODE
);
1101 t2
= lttv_filter_tree_new();
1102 t2
->node
= LTTV_LOGICAL_XOR
;
1103 if(subtree
!= NULL
) { /* append subtree to current tree */
1104 t2
->left
= LTTV_TREE_NODE
;
1105 t2
->l_child
.t
= subtree
;
1107 t1
->right
= LTTV_TREE_NODE
;
1109 } else { /* append a simple expression */
1110 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1111 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1112 a_field_component
= g_string_new("");
1113 t2
->left
= LTTV_TREE_LEAF
;
1114 t2
->l_child
.leaf
= a_simple_expression
;
1115 a_simple_expression
= lttv_simple_expression_new();
1116 t1
->right
= LTTV_TREE_NODE
;
1121 case '!': /* not, or not equal (math op) */
1123 if(filter
->expression
[i
+1] == '=') { /* != */
1124 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1125 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1126 a_field_component
= g_string_new("");
1127 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_NE
);
1130 t1
= (LttvFilter
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1131 while(t1
->right
!= LTTV_TREE_IDLE
) {
1132 g_assert(t1
->right
== LTTV_TREE_NODE
);
1135 t2
= lttv_filter_tree_new();
1136 t2
->node
= LTTV_LOGICAL_NOT
;
1137 t1
->right
= LTTV_TREE_NODE
;
1142 case '(': /* start of parenthesis */
1146 p_nesting
++; /* incrementing parenthesis nesting value */
1147 t1
= lttv_filter_tree_new();
1148 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
1151 case ')': /* end of parenthesis */
1155 p_nesting
--; /* decrementing parenthesis nesting value */
1156 if(p_nesting
<0 || tree_stack
->len
<2) {
1157 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1158 is not valid due to parenthesis incorrect use",filter
->expression
);
1162 /* there must at least be the root tree left in the array */
1163 g_assert(tree_stack
->len
>0);
1165 if(subtree
!= NULL
) { /* append subtree to current tree */
1166 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1167 while(t1
->right
!= LTTV_TREE_IDLE
) {
1168 g_assert(t1
->right
== LTTV_TREE_NODE
);
1171 t1
->right
= LTTV_TREE_NODE
;
1172 t1
->r_child
.t
= subtree
;
1173 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1174 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1175 } else { /* assign subtree as current tree */
1176 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1177 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1178 a_field_component
= g_string_new("");
1179 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1181 while(t1
->right
!= LTTV_TREE_IDLE
) {
1182 g_print("while right:%i %p->child:%p\n",t1
->right
,t1
,t1
->r_child
.t
);
1183 g_assert(t1
->right
== LTTV_TREE_NODE
);
1184 g_assert(t1
->r_child
.t
!= NULL
);
1188 t1
->right
= LTTV_TREE_LEAF
;
1189 t1
->r_child
.leaf
= a_simple_expression
;
1190 a_simple_expression
= lttv_simple_expression_new();
1191 subtree
= g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1196 * mathematic operators
1198 case '<': /* lower, lower or equal */
1200 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1201 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1202 a_field_component
= g_string_new("");
1203 if(filter
->expression
[i
+1] == '=') { /* <= */
1205 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LE
);
1206 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LT
);
1209 case '>': /* higher, higher or equal */
1211 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1212 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1213 a_field_component
= g_string_new("");
1214 if(filter
->expression
[i
+1] == '=') { /* >= */
1216 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GE
);
1217 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GT
);
1220 case '=': /* equal */
1222 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1223 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1224 a_field_component
= g_string_new("");
1225 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1229 * Field concatening caracter
1234 * divide field expression into elements
1235 * in a_field_path array.
1237 /* FIXME: check for double values */
1238 // if(a_simple_expression->op == NULL) {
1239 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1240 a_field_component
= g_string_new("");
1246 default: /* concatening current string */
1247 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1251 g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree
,tree
,t1
,t2
);
1252 g_print("stack size: %i\n",tree_stack
->len
);
1255 * Preliminary check to see
1256 * if tree was constructed correctly
1259 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1260 is not valid due to parenthesis incorrect use",filter
->expression
);
1264 if(tree_stack
->len
!= 1) /* only root tree should remain */
1267 /* processing last element of expression */
1268 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1269 while(t1
->right
!= LTTV_TREE_IDLE
) {
1270 g_assert(t1
->right
== LTTV_TREE_NODE
);
1273 if(subtree
!= NULL
) { /* add the subtree */
1274 t1
->right
= LTTV_TREE_NODE
;
1275 t1
->r_child
.t
= subtree
;
1277 } else { /* add a leaf */
1278 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1279 //a_simple_expression->value = g_string_free(a_field_component,FALSE);
1280 a_field_component
= NULL
;
1281 t1
->right
= LTTV_TREE_LEAF
;
1282 t1
->r_child
.leaf
= a_simple_expression
;
1283 a_simple_expression
= NULL
;
1287 /* free the pointer array */
1288 g_assert(a_field_path
->len
== 0);
1289 g_ptr_array_free(a_field_path
,TRUE
);
1291 /* free the tree stack -- but keep the root tree */
1292 g_ptr_array_free(tree_stack
,FALSE
);
1294 /* free the field buffer if allocated */
1295 if(a_field_component
!= NULL
) g_string_free(a_field_component
,TRUE
);
1297 /* free the simple expression buffer if allocated */
1298 if(a_simple_expression
!= NULL
) lttv_simple_expression_destroy(a_simple_expression
);
1300 g_assert(tree
!= NULL
); /* tree should exist */
1301 g_assert(subtree
== NULL
); /* remaining subtree should be included in main tree */
1304 g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1305 lttv_print_tree(filter
->head
) ;
1306 g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1314 * @fn void lttv_filter_destroy(LttvFilter*)
1316 * Destroy the current LttvFilter
1317 * @param filter pointer to the current LttvFilter
1320 lttv_filter_destroy(LttvFilter
* filter
) {
1322 g_free(filter
->expression
);
1323 lttv_filter_tree_destroy(filter
->head
);
1329 * LttvFilterTree* lttv_filter_tree_new()
1331 * Assign a new tree for the current expression
1333 * @return pointer of LttvFilterTree
1336 lttv_filter_tree_new() {
1337 LttvFilterTree
* tree
;
1339 tree
= g_new(LttvFilter
,1);
1340 tree
->node
= 0; //g_new(lttv_expression,1);
1341 tree
->left
= LTTV_TREE_IDLE
;
1342 tree
->right
= LTTV_TREE_IDLE
;
1348 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1350 * Append a new expression to the expression
1351 * defined in the current filter
1352 * @param filter pointer to the current LttvFilter
1353 * @param expression string that must be appended
1354 * @return Success/Failure of operation
1356 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, char *expression
) {
1358 if(expression
== NULL
) return FALSE
;
1359 if(filter
== NULL
) {
1360 filter
= lttv_filter_new();
1361 filter
->expression
= expression
;
1362 } else if(filter
->expression
== NULL
) {
1363 filter
->expression
= expression
;
1365 filter
->expression
= g_strconcat(filter
->expression
,"&",expression
);
1368 return lttv_filter_update(filter
);
1373 * @fn void lttv_filter_clear_expression(LttvFilter*)
1375 * Clear the filter expression from the
1376 * current filter and sets its pointer to NULL
1377 * @param filter pointer to the current LttvFilter
1379 void lttv_filter_clear_expression(LttvFilter
* filter
) {
1381 if(filter
->expression
!= NULL
) {
1382 g_free(filter
->expression
);
1383 filter
->expression
= NULL
;
1389 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1391 * Destroys the tree and his sub-trees
1392 * @param tree Tree which must be destroyed
1395 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1397 if(tree
== NULL
) return;
1399 if(tree
->left
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->l_child
.leaf
);
1400 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1402 if(tree
->right
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->r_child
.leaf
);
1403 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1410 * gboolean lttv_filter_tree_parse(LttvFilterTree*,LttEvent,LttTracefile,LttTrace,LttvProcessState)
1412 * Global parsing function for the current
1414 * @param tree pointer to the current LttvFilterTree
1415 * @param event current LttEvent, NULL if not used
1416 * @param tracefile current LttTracefile, NULL if not used
1417 * @param trace current LttTrace, NULL if not used
1418 * @param state current LttvProcessState, NULL if not used
1421 lttv_filter_tree_parse(
1424 LttTracefile
* tracefile
,
1426 LttvProcessState
* state
1431 * Each tree is parsed in inorder.
1432 * This way, it's possible to apply the left filter of the
1433 * tree, then decide whether or not the right branch should
1434 * be parsed depending on the linking logical operator
1436 * Each node consists in a
1437 * 1. logical operator
1438 * 2. left child ( node or simple expression )
1439 * 3. right child ( node or simple expression )
1441 * When the child is a simple expression, we must
1442 * before all determine if the expression refers to
1443 * a structure which is whithin observation ( not NULL ).
1444 * -If so, the expression is evaluated.
1445 * -If not, the result is set to TRUE since this particular
1446 * operation does not interfere with the lttv structure
1448 * The result of each simple expression will directly
1449 * affect the next branch. This way, depending on
1450 * the linking logical operator, the parser will decide
1451 * to explore or not the next branch.
1453 * -If result of left branch is 0 / FALSE
1454 * then don't explore right branch and return 0;
1455 * -If result of left branch is 1 / TRUE then explore
1457 * -If result of left branch is 1 / TRUE
1458 * then don't explore right branch and return 1;
1459 * -If result of left branch is 0 / FALSE then explore
1461 * -Result of left branch will not affect exploration of
1464 g_print("filter::lttv_parse_tree(...)\n");
1466 gboolean lresult
= FALSE
, rresult
= FALSE
;
1471 if(t
->left
== LTTV_TREE_NODE
) lresult
= lttv_filter_tree_parse(t
->l_child
.t
,event
,tracefile
,trace
,state
);
1472 else if(t
->left
== LTTV_TREE_LEAF
) {
1473 //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);
1475 v
= t
->l_child
.leaf
->value
;
1476 switch(t
->l_child
.leaf
->field
) {
1478 case LTTV_FILTER_TRACE_NAME
:
1479 if(trace
== NULL
) lresult
= TRUE
;
1480 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_trace_name(trace
),v
);
1482 case LTTV_FILTER_TRACEFILE_NAME
:
1483 if(tracefile
== NULL
) lresult
= TRUE
;
1484 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_tracefile_name(tracefile
),v
);
1486 case LTTV_FILTER_STATE_PID
:
1487 if(state
== NULL
) lresult
= TRUE
;
1488 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1490 case LTTV_FILTER_STATE_PPID
:
1491 if(state
== NULL
) lresult
= TRUE
;
1492 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1494 case LTTV_FILTER_STATE_CT
:
1495 if(state
== NULL
) lresult
= TRUE
;
1497 double val
= ltt_time_to_double(state
->creation_time
);
1498 lresult
= t
->l_child
.leaf
->op((gpointer
)&val
,v
);
1501 case LTTV_FILTER_STATE_IT
:
1502 if(state
== NULL
) lresult
= TRUE
;
1504 double val
= ltt_time_to_double(state
->insertion_time
);
1505 lresult
= t
->l_child
.leaf
->op((gpointer
)&val
,v
);
1508 case LTTV_FILTER_STATE_P_NAME
:
1510 * FIXME: Yet to be done ( I think ? )
1514 case LTTV_FILTER_STATE_EX_MODE
:
1515 if(state
== NULL
) lresult
= TRUE
;
1516 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->t
,v
);
1518 case LTTV_FILTER_STATE_EX_SUBMODE
:
1519 if(state
== NULL
) lresult
= TRUE
;
1520 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->n
,v
);
1522 case LTTV_FILTER_STATE_P_STATUS
:
1523 if(state
== NULL
) lresult
= TRUE
;
1524 else lresult
= t
->l_child
.leaf
->op((gpointer
)&state
->state
->s
,v
);
1526 case LTTV_FILTER_STATE_CPU
:
1528 * FIXME: What is the comparison value ?
1532 case LTTV_FILTER_EVENT_NAME
:
1533 if(event
== NULL
) lresult
= TRUE
;
1534 else lresult
= t
->l_child
.leaf
->op((gpointer
)ltt_event_eventtype(event
),v
);
1537 case LTTV_FILTER_EVENT_CATEGORY
:
1539 * FIXME: Not yet implemented
1543 case LTTV_FILTER_EVENT_TIME
:
1544 // if(event == NULL) lresult = TRUE;
1546 // double val = ltt_time_to_double(event->event_time);
1547 // lresult = t->l_child.leaf->op((gpointer)&val,v);
1551 case LTTV_FILTER_EVENT_TSC
:
1552 // if(event == NULL) lresult = TRUE;
1554 // double val = ltt_time_to_double(event->event_time);
1555 // lresult = t->l_child.leaf->op((gpointer)&val,v);
1558 * FIXME: Where is event.tsc
1562 case LTTV_FILTER_EVENT_FIELD
:
1564 * TODO: Use the offset to
1565 * find the dynamic field
1566 * in the event struct
1571 * This case should never be
1572 * parsed, if so, the whole
1573 * filtering is cancelled
1575 g_warning("Error while parsing the filter tree");
1581 * Parse linking operator
1582 * make a cutoff if possible
1584 if((t
->node
& LTTV_LOGICAL_OR
) && lresult
== TRUE
) return TRUE
;
1585 if((t
->node
& LTTV_LOGICAL_AND
) && lresult
== FALSE
) return FALSE
;
1588 * Parse right branch
1590 if(t
->right
== LTTV_TREE_NODE
) rresult
= lttv_filter_tree_parse(t
->r_child
.t
,event
,tracefile
,trace
,state
);
1591 else if(t
->right
== LTTV_TREE_LEAF
) {
1592 //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);
1594 v
= t
->r_child
.leaf
->value
;
1595 switch(t
->r_child
.leaf
->field
) {
1597 case LTTV_FILTER_TRACE_NAME
:
1598 if(trace
== NULL
) rresult
= TRUE
;
1599 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_trace_name(trace
),v
);
1601 case LTTV_FILTER_TRACEFILE_NAME
:
1602 if(tracefile
== NULL
) rresult
= TRUE
;
1603 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_tracefile_name(tracefile
),v
);
1605 case LTTV_FILTER_STATE_PID
:
1606 if(state
== NULL
) rresult
= TRUE
;
1607 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->pid
,v
);
1609 case LTTV_FILTER_STATE_PPID
:
1610 if(state
== NULL
) rresult
= TRUE
;
1611 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->ppid
,v
);
1613 case LTTV_FILTER_STATE_CT
:
1614 if(state
== NULL
) rresult
= TRUE
;
1616 double val
= ltt_time_to_double(state
->creation_time
);
1617 rresult
= t
->r_child
.leaf
->op((gpointer
)&val
,v
);
1620 case LTTV_FILTER_STATE_IT
:
1621 if(state
== NULL
) rresult
= TRUE
;
1623 double val
= ltt_time_to_double(state
->insertion_time
);
1624 rresult
= t
->r_child
.leaf
->op((gpointer
)&val
,v
);
1627 case LTTV_FILTER_STATE_P_NAME
:
1629 * FIXME: Yet to be done ( I think ? )
1633 case LTTV_FILTER_STATE_EX_MODE
:
1634 if(state
== NULL
) rresult
= TRUE
;
1635 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->t
,v
);
1637 case LTTV_FILTER_STATE_EX_SUBMODE
:
1638 if(state
== NULL
) rresult
= TRUE
;
1639 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->n
,v
);
1641 case LTTV_FILTER_STATE_P_STATUS
:
1642 if(state
== NULL
) rresult
= TRUE
;
1643 else rresult
= t
->r_child
.leaf
->op((gpointer
)&state
->state
->s
,v
);
1645 case LTTV_FILTER_STATE_CPU
:
1647 * FIXME: What is the comparison value ?
1651 case LTTV_FILTER_EVENT_NAME
:
1652 if(event
== NULL
) rresult
= TRUE
;
1653 else rresult
= t
->r_child
.leaf
->op((gpointer
)ltt_event_eventtype(event
),v
);
1656 case LTTV_FILTER_EVENT_CATEGORY
:
1658 * FIXME: Not yet implemented
1662 case LTTV_FILTER_EVENT_TIME
:
1663 // if(event == NULL) rresult = TRUE;
1665 // double val = ltt_time_to_double(event->event_time);
1666 // rresult = t->r_child.leaf->op((gpointer)&val,v);
1670 case LTTV_FILTER_EVENT_TSC
:
1671 // if(event == NULL) rresult = TRUE;
1673 // double val = ltt_time_to_double(event->event_time);
1674 // rresult = t->r_child.leaf->op((gpointer)&val,v);
1677 * FIXME: Where is event.tsc
1681 case LTTV_FILTER_EVENT_FIELD
:
1683 * TODO: Use the offset to
1684 * find the dynamic field
1685 * in the event struct
1690 * This case should never be
1691 * parsed, if so, this subtree
1694 g_warning("Error while parsing the filter tree");
1700 * Apply and return the
1701 * logical link between the
1705 case LTTV_LOGICAL_OR
: return (lresult
| rresult
);
1706 case LTTV_LOGICAL_AND
: return (lresult
& rresult
);
1707 case LTTV_LOGICAL_NOT
: return (!rresult
);
1708 case LTTV_LOGICAL_XOR
: return (lresult
^ rresult
);
1711 * This case should never be
1712 * parsed, if so, this subtree
1721 * @fn void lttv_print_tree(LttvFilterTree*)
1724 * @param t the pointer to the current LttvFilterTree
1727 lttv_print_tree(LttvFilterTree
* t
) {
1729 g_print("node:%p lchild:%p rchild:%p\n",t
, //t->l_child.t,t->r_child.t);
1730 (t
->left
==LTTV_TREE_NODE
)?t
->l_child
.t
:NULL
,
1731 (t
->right
==LTTV_TREE_NODE
)?t
->r_child
.t
:NULL
);
1732 g_print("node type: %i / [left] %i / [right] %i\n",t
->node
,t
->left
,t
->right
);
1733 if(t
->left
== LTTV_TREE_NODE
) lttv_print_tree(t
->l_child
.t
);
1734 else if(t
->left
== LTTV_TREE_LEAF
) {
1735 // g_assert(t->l_child.leaf->value != NULL);
1736 g_print("%p: left is %i %p value\n",t
,t
->l_child
.leaf
->field
,t
->l_child
.leaf
->op
);
1738 if(t
->right
== LTTV_TREE_NODE
) lttv_print_tree(t
->r_child
.t
);
1739 else if(t
->right
== LTTV_TREE_LEAF
) {
1740 // g_assert(t->r_child.leaf->value != NULL);
1741 g_print("%p: right is %i %p value\n",t
,t
->r_child
.leaf
->field
,t
->r_child
.leaf
->op
);
1747 * gboolean lttv_filter_tracefile(LttvFilter*, LttTracefile*)
1749 * Apply the filter to a specific trace
1750 * @param filter the current filter applied
1751 * @param tracefile the trace to apply the filter to
1752 * @return success/failure of operation
1755 lttv_filter_tracefile(LttvFilter
*filter
, LttTracefile
*tracefile
) {
1757 return lttv_filter_tree_parse(filter
->head
,NULL
,tracefile
,NULL
,NULL
);
1762 * @fn gboolean lttv_filter_tracestate(LttvFilter*,LttvTraceState*)
1764 * Parse the current tracestate
1765 * @param filter pointer to the current LttvFilter
1766 * @param tracestate pointer to the current tracestate
1769 lttv_filter_tracestate(LttvFilter
*filter
, LttvTraceState
*tracestate
) {
1774 * @fn gboolean lttv_filter_event(LttvFilter*,LttEvent*)
1776 * Apply the filter to a specific event
1777 * @param filter the current filter applied
1778 * @param event the event to apply the filter to
1779 * @return success/failure of operation
1782 lttv_filter_event(LttvFilter
*filter
, LttEvent
*event
) {
1787 * @fn static void module_init()
1789 * Initializes the filter module and specific values
1791 static void module_init()
1797 * Destroys the filter module and specific values
1799 static void module_destroy()
1805 LTTV_MODULE("filter", "Filters traceset and events", \
1806 "Filters traceset and events specifically to user input", \
1807 module_init
, module_destroy
)