1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2005 Michel Dagenais and Simon Bouvier-Zappa
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,
19 /*! \file lttv/lttv/filter.c
20 * \brief Defines the core filter of application
22 * consist in AND, OR and NOT nested expressions, forming a tree with
23 * simple relations as leaves. The simple relations test if a field
24 * in an event is equal, not equal, smaller, smaller or equal, larger, or
25 * larger or equal to a specified value.
27 * Fields specified in a simple expression can take following
31 * LttvTracefileContext{}
33 * | |->name (String, converted to GQuark)
34 * | |->category (String, not yet implemented)
36 * | |->tsc (LttCycleCount --> uint64)
40 * | |->"sub-field name"
42 * | |->"leaf-field name" (field type)
44 * | |->name (String, converted to GQuark)
46 * | |->name (String, converted to GQuark)
50 * |->creation_time (LttTime)
51 * |->insertion_time (LttTime)
52 * |->process_name (String, converted to GQuark)
53 * |->execution_mode (LttvExecutionMode)
54 * |->execution_submode (LttvExecutionSubmode)
55 * |->process_status (LttvProcessStatus)
62 * - refine switch of expression in multiple uses functions
63 * - remove the idle expressions in the tree
66 #include <lttv/filter.h>
69 * @fn LttvSimpleExpression* lttv_simple_expression_new()
71 * Constructor for LttvSimpleExpression
72 * @return pointer to new LttvSimpleExpression
75 lttv_simple_expression_new() {
77 LttvSimpleExpression
* se
= g_new(LttvSimpleExpression
,1);
79 se
->field
= LTTV_FILTER_UNDEFINED
;
87 * @fn gboolean lttv_simple_expression_assign_field(GPtrArray*,LttvSimpleExpression*)
89 * Parse through filtering field hierarchy as specified
90 * by user. This function compares each value to
91 * predetermined quarks
92 * @param fp The field path list
93 * @param se current simple expression
94 * @return success/failure of operation
97 lttv_simple_expression_assign_field(GPtrArray
* fp
, LttvSimpleExpression
* se
) {
101 if(fp
->len
< 2) return FALSE
;
102 g_assert(f
=g_ptr_array_remove_index(fp
,0));
105 * Parse through the specified
108 * Take note however that the
109 * 'event' subfields might change
110 * depending on values specified
111 * in core.xml file. Hence, if
112 * none of the subfields in the
113 * array match the hardcoded
114 * subfields, it will be considered
117 if(!g_strcasecmp(f
->str
,"trace") ) {
122 g_string_free(f
,TRUE
);
123 f
=g_ptr_array_remove_index(fp
,0);
124 if(!g_strcasecmp(f
->str
,"name")) {
125 se
->field
= LTTV_FILTER_TRACE_NAME
;
127 } else if(!g_strcasecmp(f
->str
,"traceset") ) {
129 * FIXME: not yet implemented !
131 } else if(!g_strcasecmp(f
->str
,"tracefile") ) {
136 g_string_free(f
,TRUE
);
137 f
=g_ptr_array_remove_index(fp
,0);
138 if(!g_strcasecmp(f
->str
,"name")) {
139 se
->field
= LTTV_FILTER_TRACEFILE_NAME
;
141 } else if(!g_strcasecmp(f
->str
,"state") ) {
146 * state.creation_time
147 * state.insertion_time
149 * state.execution_mode
150 * state.execution_submode
151 * state.process_status
154 g_string_free(f
,TRUE
);
155 f
=g_ptr_array_remove_index(fp
,0);
156 if(!g_strcasecmp(f
->str
,"pid") ) {
157 se
->field
= LTTV_FILTER_STATE_PID
;
159 else if(!g_strcasecmp(f
->str
,"ppid") ) {
160 se
->field
= LTTV_FILTER_STATE_PPID
;
162 else if(!g_strcasecmp(f
->str
,"creation_time") ) {
163 se
->field
= LTTV_FILTER_STATE_CT
;
165 else if(!g_strcasecmp(f
->str
,"insertion_time") ) {
166 se
->field
= LTTV_FILTER_STATE_IT
;
168 else if(!g_strcasecmp(f
->str
,"process_name") ) {
169 se
->field
= LTTV_FILTER_STATE_P_NAME
;
171 else if(!g_strcasecmp(f
->str
,"execution_mode") ) {
172 se
->field
= LTTV_FILTER_STATE_EX_MODE
;
174 else if(!g_strcasecmp(f
->str
,"execution_submode") ) {
175 se
->field
= LTTV_FILTER_STATE_EX_SUBMODE
;
177 else if(!g_strcasecmp(f
->str
,"process_status") ) {
178 se
->field
= LTTV_FILTER_STATE_P_STATUS
;
180 else if(!g_strcasecmp(f
->str
,"cpu") ) {
181 se
->field
= LTTV_FILTER_STATE_CPU
;
183 } else if(!g_strcasecmp(f
->str
,"event") ) {
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_EVENT_NAME
;
196 else if(!g_strcasecmp(f
->str
,"category") ) {
198 * FIXME: Category not yet functional in lttv
200 se
->field
= LTTV_FILTER_EVENT_CATEGORY
;
202 else if(!g_strcasecmp(f
->str
,"time") ) {
203 se
->field
= LTTV_FILTER_EVENT_TIME
;
205 else if(!g_strcasecmp(f
->str
,"tsc") ) {
206 se
->field
= LTTV_FILTER_EVENT_TSC
;
208 else { /* core.xml specified options */
209 se
->field
= LTTV_FILTER_EVENT_FIELD
;
212 g_warning("Unrecognized field in filter string");
215 /* free memory for last string */
216 g_string_free(f
,TRUE
);
218 /* array should be empty */
219 g_assert(fp
->len
== 0);
221 if(se
->field
== LTTV_FILTER_UNDEFINED
) {
222 g_warning("The specified field was not recognized !");
229 * @fn gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression*,LttvExpressionOp)
231 * Sets the function pointer for the current
233 * @param se current simple expression
234 * @param op current operator
235 * @return success/failure of operation
237 gboolean
lttv_simple_expression_assign_operator(LttvSimpleExpression
* se
, LttvExpressionOp op
) {
243 case LTTV_FILTER_TRACE_NAME
:
244 case LTTV_FILTER_TRACEFILE_NAME
:
245 case LTTV_FILTER_STATE_P_NAME
:
246 case LTTV_FILTER_EVENT_NAME
:
247 case LTTV_FILTER_STATE_CPU
:
250 se
->op
= lttv_apply_op_eq_quark
;
253 se
->op
= lttv_apply_op_ne_quark
;
256 g_warning("Error encountered in operator assignment = or != expected");
263 case LTTV_FILTER_STATE_PID
:
264 case LTTV_FILTER_STATE_PPID
:
265 case LTTV_FILTER_EVENT_TSC
:
268 se
->op
= lttv_apply_op_eq_uint64
;
271 se
->op
= lttv_apply_op_ne_uint64
;
274 se
->op
= lttv_apply_op_lt_uint64
;
277 se
->op
= lttv_apply_op_le_uint64
;
280 se
->op
= lttv_apply_op_gt_uint64
;
283 se
->op
= lttv_apply_op_ge_uint64
;
286 g_warning("Error encountered in operator assignment");
292 * can only be compared with 'equal' or 'not equal' operators
294 * unsigned int of 16 bits are used here since enums
295 * should not over 2^16-1 values
297 case LTTV_FILTER_STATE_EX_MODE
:
298 case LTTV_FILTER_STATE_EX_SUBMODE
:
299 case LTTV_FILTER_STATE_P_STATUS
:
302 se
->op
= lttv_apply_op_eq_uint16
;
305 se
->op
= lttv_apply_op_ne_uint16
;
308 g_warning("Error encountered in operator assignment = or != expected");
315 case LTTV_FILTER_STATE_CT
:
316 case LTTV_FILTER_STATE_IT
:
317 case LTTV_FILTER_EVENT_TIME
:
320 se
->op
= lttv_apply_op_eq_ltttime
;
323 se
->op
= lttv_apply_op_ne_ltttime
;
326 se
->op
= lttv_apply_op_lt_ltttime
;
329 se
->op
= lttv_apply_op_le_ltttime
;
332 se
->op
= lttv_apply_op_gt_ltttime
;
335 se
->op
= lttv_apply_op_ge_ltttime
;
338 g_warning("Error encountered in operator assignment");
343 g_warning("Error encountered in operator assignation ! Field type:%i",se
->field
);
352 * @fn gboolean lttv_simple_expression_assign_value(LttvSimpleExpression*,char*)
354 * Assign the value field to the current LttvSimpleExpression
355 * @param se pointer to the current LttvSimpleExpression
356 * @param value string value for simple expression
358 gboolean
lttv_simple_expression_assign_value(LttvSimpleExpression
* se
, char* value
) {
361 gboolean is_double
= FALSE
;
362 LttTime t
= ltt_time_zero
;
370 case LTTV_FILTER_TRACE_NAME
:
371 case LTTV_FILTER_TRACEFILE_NAME
:
372 case LTTV_FILTER_STATE_P_NAME
:
373 case LTTV_FILTER_EVENT_NAME
:
374 case LTTV_FILTER_STATE_CPU
:
375 // se->value.v_string = value;
376 se
->value
.v_uint32
= g_quark_from_string(value
);
382 case LTTV_FILTER_STATE_PID
:
383 case LTTV_FILTER_STATE_PPID
:
384 case LTTV_FILTER_STATE_EX_MODE
:
385 case LTTV_FILTER_STATE_EX_SUBMODE
:
386 case LTTV_FILTER_STATE_P_STATUS
:
387 case LTTV_FILTER_EVENT_TSC
:
388 se
->value
.v_uint64
= atoi(value
);
394 case LTTV_FILTER_STATE_CT
:
395 case LTTV_FILTER_STATE_IT
:
396 case LTTV_FILTER_EVENT_TIME
:
397 //se->value.v_double = atof(value);
399 * parsing logic could be optimised,
400 * but as for now, simpler this way
402 v
= g_string_new("");
403 for(i
=0;i
<strlen(value
);i
++) {
404 if(value
[i
] == '.') {
405 /* cannot specify number with more than one '.' */
406 if(is_double
) return FALSE
;
407 else is_double
= TRUE
;
409 g_string_free(v
,TRUE
);
410 v
= g_string_new("");
411 } else g_string_append_c(v
,value
[i
]);
413 /* number can be integer or double */
414 if(is_double
) t
.tv_nsec
= atoi(v
);
415 else t
.tv_sec
= atoi(v
);
417 g_string_free(v
,TRUE
);
419 se
->value
.v_ltttime
= t
;
423 g_warning("Error encountered in value assignation ! Field type = %i",se
->field
);
433 * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*)
435 * Disallocate memory for the current
437 * @param se pointer to the current LttvSimpleExpression
440 lttv_simple_expression_destroy(LttvSimpleExpression
* se
) {
442 // g_free(se->value);
443 // switch(se->field) {
444 // case LTTV_FILTER_TRACE_NAME:
445 // case LTTV_FILTER_TRACEFILE_NAME:
446 // case LTTV_FILTER_STATE_P_NAME:
447 // case LTTV_FILTER_EVENT_NAME:
448 // g_free(se->value.v_string);
456 * @fn gint lttv_struct_type(gint)
458 * Finds the structure type depending
459 * on the fields in parameters
460 * @params ft Field of the current structure
461 * @return LttvStructType enum or -1 for error
464 lttv_struct_type(gint ft
) {
467 case LTTV_FILTER_TRACE_NAME
:
468 return LTTV_FILTER_TRACE
;
470 case LTTV_FILTER_TRACEFILE_NAME
:
471 return LTTV_FILTER_TRACEFILE
;
473 case LTTV_FILTER_STATE_PID
:
474 case LTTV_FILTER_STATE_PPID
:
475 case LTTV_FILTER_STATE_CT
:
476 case LTTV_FILTER_STATE_IT
:
477 case LTTV_FILTER_STATE_P_NAME
:
478 case LTTV_FILTER_STATE_EX_MODE
:
479 case LTTV_FILTER_STATE_EX_SUBMODE
:
480 case LTTV_FILTER_STATE_P_STATUS
:
481 case LTTV_FILTER_STATE_CPU
:
482 return LTTV_FILTER_STATE
;
484 case LTTV_FILTER_EVENT_NAME
:
485 case LTTV_FILTER_EVENT_CATEGORY
:
486 case LTTV_FILTER_EVENT_TIME
:
487 case LTTV_FILTER_EVENT_TSC
:
488 case LTTV_FILTER_EVENT_FIELD
:
489 return LTTV_FILTER_EVENT
;
497 * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue)
499 * Applies the 'equal' operator to the
500 * specified structure and value
501 * @param v1 left member of comparison
502 * @param v2 right member of comparison
503 * @return success/failure of operation
505 gboolean
lttv_apply_op_eq_uint64(const gpointer v1
, LttvFieldValue v2
) {
507 guint64
* r
= (guint64
*) v1
;
508 return (*r
== v2
.v_uint64
);
513 * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue)
515 * Applies the 'equal' operator to the
516 * specified structure and value
517 * @param v1 left member of comparison
518 * @param v2 right member of comparison
519 * @return success/failure of operation
521 gboolean
lttv_apply_op_eq_uint32(const gpointer v1
, LttvFieldValue v2
) {
522 guint32
* r
= (guint32
*) v1
;
523 return (*r
== v2
.v_uint32
);
527 * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue)
529 * Applies the 'equal' operator to the
530 * specified structure and value
531 * @param v1 left member of comparison
532 * @param v2 right member of comparison
533 * @return success/failure of operation
535 gboolean
lttv_apply_op_eq_uint16(const gpointer v1
, LttvFieldValue v2
) {
536 guint16
* r
= (guint16
*) v1
;
537 return (*r
== v2
.v_uint16
);
541 * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue)
543 * Applies the 'equal' operator to the
544 * specified structure and value
545 * @param v1 left member of comparison
546 * @param v2 right member of comparison
547 * @return success/failure of operation
549 gboolean
lttv_apply_op_eq_double(const gpointer v1
, LttvFieldValue v2
) {
550 double* r
= (double*) v1
;
551 return (*r
== v2
.v_double
);
555 * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue)
557 * Applies the 'equal' operator to the
558 * specified structure and value
559 * @param v1 left member of comparison
560 * @param v2 right member of comparison
561 * @return success/failure of operation
563 gboolean
lttv_apply_op_eq_string(const gpointer v1
, LttvFieldValue v2
) {
564 char* r
= (char*) v1
;
565 return (!g_strcasecmp(r
,v2
.v_string
));
569 * @fn gboolean lttv_apply_op_eq_quark(gpointer,LttvFieldValue)
571 * Applies the 'equal' operator to the
572 * specified structure and value
573 * @param v1 left member of comparison
574 * @param v2 right member of comparison
575 * @return success/failure of operation
577 gboolean
lttv_apply_op_eq_quark(const gpointer v1
, LttvFieldValue v2
) {
578 GQuark
* r
= (GQuark
*) v1
;
579 g_print("v1:%i v2:%i\n",*r
,v2
.v_uint32
);
580 return (*r
== v2
.v_uint32
);
584 * @fn gboolean lttv_apply_op_eq_ltttime(gpointer,LttvFieldValue)
586 * Applies the 'equal' operator to the
587 * specified structure and value
588 * @param v1 left member of comparison
589 * @param v2 right member of comparison
590 * @return success/failure of operation
592 gboolean
lttv_apply_op_eq_ltttime(const gpointer v1
, LttvFieldValue v2
) {
593 LttTime
* r
= (LttTime
*) v1
;
594 return ltt_time_compare(*r
, v2
.v_ltttime
)==0?1:0;
599 * @fn gboolean lttv_apply_op_ne_uint64(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_uint64(const gpointer v1
, LttvFieldValue v2
) {
608 guint64
* r
= (guint64
*) v1
;
609 return (*r
!= v2
.v_uint64
);
613 * @fn gboolean lttv_apply_op_ne_uint32(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_uint32(const gpointer v1
, LttvFieldValue v2
) {
622 guint32
* r
= (guint32
*) v1
;
623 return (*r
!= v2
.v_uint32
);
627 * @fn gboolean lttv_apply_op_ne_uint16(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_uint16(const gpointer v1
, LttvFieldValue v2
) {
636 guint16
* r
= (guint16
*) v1
;
637 return (*r
!= v2
.v_uint16
);
641 * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue)
643 * Applies the 'not equal' 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_ne_double(const gpointer v1
, LttvFieldValue v2
) {
650 double* r
= (double*) v1
;
651 return (*r
!= v2
.v_double
);
655 * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue)
657 * Applies the 'not equal' 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_ne_string(const gpointer v1
, LttvFieldValue v2
) {
664 char* r
= (char*) v1
;
665 return (g_strcasecmp(r
,v2
.v_string
));
669 * @fn gboolean lttv_apply_op_ne_quark(gpointer,LttvFieldValue)
671 * Applies the 'not equal' 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_ne_quark(const gpointer v1
, LttvFieldValue v2
) {
678 GQuark
* r
= (GQuark
*) v1
;
679 return (*r
!= v2
.v_uint32
);
684 * @fn gboolean lttv_apply_op_ne_ltttime(gpointer,LttvFieldValue)
686 * Applies the 'not equal' operator to the
687 * specified structure and value
688 * @param v1 left member of comparison
689 * @param v2 right member of comparison
690 * @return success/failure of operation
692 gboolean
lttv_apply_op_ne_ltttime(const gpointer v1
, LttvFieldValue v2
) {
693 LttTime
* r
= (LttTime
*) v1
;
694 return ltt_time_compare(*r
, v2
.v_ltttime
)!=0?1:0;
699 * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue)
701 * Applies the 'lower than' operator to the
702 * specified structure and value
703 * @param v1 left member of comparison
704 * @param v2 right member of comparison
705 * @return success/failure of operation
707 gboolean
lttv_apply_op_lt_uint64(const gpointer v1
, LttvFieldValue v2
) {
708 guint64
* r
= (guint64
*) v1
;
709 return (*r
< v2
.v_uint64
);
713 * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue)
715 * Applies the 'lower than' operator to the
716 * specified structure and value
717 * @param v1 left member of comparison
718 * @param v2 right member of comparison
719 * @return success/failure of operation
721 gboolean
lttv_apply_op_lt_uint32(const gpointer v1
, LttvFieldValue v2
) {
722 guint32
* r
= (guint32
*) v1
;
723 return (*r
< v2
.v_uint32
);
727 * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue)
729 * Applies the 'lower than' operator to the
730 * specified structure and value
731 * @param v1 left member of comparison
732 * @param v2 right member of comparison
733 * @return success/failure of operation
735 gboolean
lttv_apply_op_lt_uint16(const gpointer v1
, LttvFieldValue v2
) {
736 guint16
* r
= (guint16
*) v1
;
737 return (*r
< v2
.v_uint16
);
741 * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue)
743 * Applies the 'lower than' operator to the
744 * specified structure and value
745 * @param v1 left member of comparison
746 * @param v2 right member of comparison
747 * @return success/failure of operation
749 gboolean
lttv_apply_op_lt_double(const gpointer v1
, LttvFieldValue v2
) {
750 double* r
= (double*) v1
;
751 return (*r
< v2
.v_double
);
755 * @fn gboolean lttv_apply_op_lt_ltttime(gpointer,LttvFieldValue)
757 * Applies the 'lower than' operator to the
758 * specified structure and value
759 * @param v1 left member of comparison
760 * @param v2 right member of comparison
761 * @return success/failure of operation
763 gboolean
lttv_apply_op_lt_ltttime(const gpointer v1
, LttvFieldValue v2
) {
764 LttTime
* r
= (LttTime
*) v1
;
765 // return ((r->tv_sec < v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec < v2.v_ltttime.tv_nsec)));
766 return ltt_time_compare(*r
, v2
.v_ltttime
)==-1?1:0;
771 * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue)
773 * Applies the 'lower or equal' operator to the
774 * specified structure and value
775 * @param v1 left member of comparison
776 * @param v2 right member of comparison
777 * @return success/failure of operation
779 gboolean
lttv_apply_op_le_uint64(const gpointer v1
, LttvFieldValue v2
) {
780 guint64
* r
= (guint64
*) v1
;
781 return (*r
<= v2
.v_uint64
);
785 * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue)
787 * Applies the 'lower or equal' operator to the
788 * specified structure and value
789 * @param v1 left member of comparison
790 * @param v2 right member of comparison
791 * @return success/failure of operation
793 gboolean
lttv_apply_op_le_uint32(const gpointer v1
, LttvFieldValue v2
) {
794 guint32
* r
= (guint32
*) v1
;
795 return (*r
<= v2
.v_uint32
);
799 * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue)
801 * Applies the 'lower or equal' operator to the
802 * specified structure and value
803 * @param v1 left member of comparison
804 * @param v2 right member of comparison
805 * @return success/failure of operation
807 gboolean
lttv_apply_op_le_uint16(const gpointer v1
, LttvFieldValue v2
) {
808 guint16
* r
= (guint16
*) v1
;
809 return (*r
<= v2
.v_uint16
);
813 * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue)
815 * Applies the 'lower or equal' operator to the
816 * specified structure and value
817 * @param v1 left member of comparison
818 * @param v2 right member of comparison
819 * @return success/failure of operation
821 gboolean
lttv_apply_op_le_double(const gpointer v1
, LttvFieldValue v2
) {
822 double* r
= (double*) v1
;
823 return (*r
<= v2
.v_double
);
827 * @fn gboolean lttv_apply_op_le_ltttime(gpointer,LttvFieldValue)
829 * Applies the 'lower or equal' operator to the
830 * specified structure and value
831 * @param v1 left member of comparison
832 * @param v2 right member of comparison
833 * @return success/failure of operation
835 gboolean
lttv_apply_op_le_ltttime(const gpointer v1
, LttvFieldValue v2
) {
836 LttTime
* r
= (LttTime
*) v1
;
837 // return ((r->tv_sec < v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec <= v2.v_ltttime.tv_nsec)));
838 return ltt_time_compare(*r
, v2
.v_ltttime
)<1?1:0;
843 * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue)
845 * Applies the 'greater than' operator to the
846 * specified structure and value
847 * @param v1 left member of comparison
848 * @param v2 right member of comparison
849 * @return success/failure of operation
851 gboolean
lttv_apply_op_gt_uint64(const gpointer v1
, LttvFieldValue v2
) {
852 guint64
* r
= (guint64
*) v1
;
853 return (*r
> v2
.v_uint64
);
857 * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue)
859 * Applies the 'greater than' operator to the
860 * specified structure and value
861 * @param v1 left member of comparison
862 * @param v2 right member of comparison
863 * @return success/failure of operation
865 gboolean
lttv_apply_op_gt_uint32(const gpointer v1
, LttvFieldValue v2
) {
866 guint32
* r
= (guint32
*) v1
;
867 return (*r
> v2
.v_uint32
);
871 * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue)
873 * Applies the 'greater than' operator to the
874 * specified structure and value
875 * @param v1 left member of comparison
876 * @param v2 right member of comparison
877 * @return success/failure of operation
879 gboolean
lttv_apply_op_gt_uint16(const gpointer v1
, LttvFieldValue v2
) {
880 guint16
* r
= (guint16
*) v1
;
881 return (*r
> v2
.v_uint16
);
885 * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue)
887 * Applies the 'greater than' operator to the
888 * specified structure and value
889 * @param v1 left member of comparison
890 * @param v2 right member of comparison
891 * @return success/failure of operation
893 gboolean
lttv_apply_op_gt_double(const gpointer v1
, LttvFieldValue v2
) {
894 double* r
= (double*) v1
;
895 return (*r
> v2
.v_double
);
899 * @fn gboolean lttv_apply_op_gt_ltttime(gpointer,LttvFieldValue)
901 * Applies the 'greater than' operator to the
902 * specified structure and value
903 * @param v1 left member of comparison
904 * @param v2 right member of comparison
905 * @return success/failure of operation
907 gboolean
lttv_apply_op_gt_ltttime(const gpointer v1
, LttvFieldValue v2
) {
908 LttTime
* r
= (LttTime
*) v1
;
909 // return ((r->tv_sec > v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec > v2.v_ltttime.tv_nsec)));
910 return ltt_time_compare(*r
, v2
.v_ltttime
)==1?1:0;
915 * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue)
917 * Applies the 'greater or equal' operator to the
918 * specified structure and value
919 * @param v1 left member of comparison
920 * @param v2 right member of comparison
921 * @return success/failure of operation
923 gboolean
lttv_apply_op_ge_uint64(const gpointer v1
, LttvFieldValue v2
) {
924 guint64
* r
= (guint64
*) v1
;
925 return (*r
>= v2
.v_uint64
);
929 * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue)
931 * Applies the 'greater or equal' operator to the
932 * specified structure and value
933 * @param v1 left member of comparison
934 * @param v2 right member of comparison
935 * @return success/failure of operation
937 gboolean
lttv_apply_op_ge_uint32(const gpointer v1
, LttvFieldValue v2
) {
938 guint32
* r
= (guint32
*) v1
;
939 return (*r
>= v2
.v_uint32
);
943 * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue)
945 * Applies the 'greater or equal' operator to the
946 * specified structure and value
947 * @param v1 left member of comparison
948 * @param v2 right member of comparison
949 * @return success/failure of operation
951 gboolean
lttv_apply_op_ge_uint16(const gpointer v1
, LttvFieldValue v2
) {
952 guint16
* r
= (guint16
*) v1
;
953 return (*r
>= v2
.v_uint16
);
957 * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue)
959 * Applies the 'greater or equal' operator to the
960 * specified structure and value
961 * @param v1 left member of comparison
962 * @param v2 right member of comparison
963 * @return success/failure of operation
965 gboolean
lttv_apply_op_ge_double(const gpointer v1
, LttvFieldValue v2
) {
966 double* r
= (double*) v1
;
967 return (*r
>= v2
.v_double
);
971 * @fn gboolean lttv_apply_op_ge_ltttime(gpointer,LttvFieldValue)
973 * Applies the 'greater or equal' operator to the
974 * specified structure and value
975 * @param v1 left member of comparison
976 * @param v2 right member of comparison
977 * @return success/failure of operation
979 gboolean
lttv_apply_op_ge_ltttime(const gpointer v1
, LttvFieldValue v2
) {
980 LttTime
* r
= (LttTime
*) v1
;
981 // return ((r->tv_sec > v2.v_ltttime.tv_sec) || ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec >= v2.v_ltttime.tv_nsec)));
982 return ltt_time_compare(*r
, v2
.v_ltttime
)>-1?1:0;
988 * Makes a copy of the current filter tree
989 * @param tree pointer to the current tree
990 * @return new copy of the filter tree
993 lttv_filter_tree_clone(const LttvFilterTree
* tree
) {
995 LttvFilterTree
* newtree
= lttv_filter_tree_new();
997 newtree
->node
= tree
->node
;
999 newtree
->left
= tree
->left
;
1000 if(newtree
->left
== LTTV_TREE_NODE
) {
1001 newtree
->l_child
.t
= lttv_filter_tree_clone(tree
->l_child
.t
);
1002 } else if(newtree
->left
== LTTV_TREE_LEAF
) {
1003 newtree
->l_child
.leaf
= lttv_simple_expression_new();
1004 newtree
->l_child
.leaf
->field
= tree
->l_child
.leaf
->field
;
1005 newtree
->l_child
.leaf
->offset
= tree
->l_child
.leaf
->offset
;
1006 newtree
->l_child
.leaf
->op
= tree
->l_child
.leaf
->op
;
1007 /* FIXME: special case for string copy ! */
1008 newtree
->l_child
.leaf
->value
= tree
->l_child
.leaf
->value
;
1011 newtree
->right
= tree
->right
;
1012 if(newtree
->right
== LTTV_TREE_NODE
) {
1013 newtree
->r_child
.t
= lttv_filter_tree_clone(tree
->r_child
.t
);
1014 } else if(newtree
->right
== LTTV_TREE_LEAF
) {
1015 newtree
->r_child
.leaf
= lttv_simple_expression_new();
1016 newtree
->r_child
.leaf
->field
= tree
->r_child
.leaf
->field
;
1017 newtree
->r_child
.leaf
->offset
= tree
->r_child
.leaf
->offset
;
1018 newtree
->r_child
.leaf
->op
= tree
->r_child
.leaf
->op
;
1019 newtree
->r_child
.leaf
->value
= tree
->r_child
.leaf
->value
;
1027 * Makes a copy of the current filter
1028 * @param filter pointer to the current filter
1029 * @return new copy of the filter
1032 lttv_filter_clone(const LttvFilter
* filter
) {
1034 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
1036 strcpy(newfilter
->expression
,filter
->expression
);
1038 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
1046 * @fn LttvFilter* lttv_filter_new()
1048 * Creates a new LttvFilter
1049 * @return the current LttvFilter or NULL if error
1054 LttvFilter
* filter
= g_new(LttvFilter
,1);
1055 filter
->expression
= NULL
;
1056 filter
->head
= NULL
;
1063 * @fn gboolean lttv_filter_update(LttvFilter*)
1065 * Updates the current LttvFilter by building
1066 * its tree based upon the expression string
1067 * @param filter pointer to the current LttvFilter
1068 * @return Failure/Success of operation
1071 lttv_filter_update(LttvFilter
* filter
) {
1073 // g_print("filter::lttv_filter_new()\n"); /* debug */
1075 if(filter
->expression
== NULL
) return FALSE
;
1079 p_nesting
=0; /* parenthesis nesting value */
1083 *tree
= lttv_filter_tree_new(), /* main tree */
1084 *subtree
= NULL
, /* buffer for subtrees */
1085 *t1
, /* buffer #1 */
1086 *t2
; /* buffer #2 */
1090 * If the tree already exists,
1091 * destroy it and build a new one
1093 if(filter
->head
!= NULL
) lttv_filter_tree_destroy(filter
->head
);
1094 filter
->head
= NULL
; /* will be assigned at the end */
1098 * each element of the list
1099 * is a sub tree created
1100 * by the use of parenthesis in the
1101 * global expression. The final tree
1102 * will be the one left at the root of
1105 GPtrArray
*tree_stack
= g_ptr_array_new();
1106 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
1108 /* temporary values */
1109 GString
*a_field_component
= g_string_new("");
1110 GPtrArray
*a_field_path
= g_ptr_array_new();
1112 /* simple expression buffer */
1113 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
1116 * Parse entire expression and construct
1117 * the binary tree. There are two steps
1118 * in browsing that string
1119 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
1120 * 2. finding simple expressions
1121 * - field path ( separated by dots )
1122 * - op ( >, <, =, >=, <=, !=)
1123 * - value ( integer, string ... )
1124 * To spare computing time, the whole
1125 * string is parsed in this loop for a
1126 * O(n) complexity order.
1128 * When encountering logical op &,|,^
1129 * 1. parse the last value if any
1130 * 2. create a new tree
1131 * 3. add the expression (simple exp, or exp (subtree)) to the tree
1132 * 4. concatenate this tree with the current tree on top of the stack
1133 * When encountering math ops >,>=,<,<=,=,!=
1134 * 1. add to op to the simple expression
1135 * 2. concatenate last field component to field path
1136 * When encountering concatening ops .
1137 * 1. concatenate last field component to field path
1138 * When encountering opening parenthesis (,{,[
1139 * 1. create a new subtree on top of tree stack
1140 * When encountering closing parenthesis ),},]
1141 * 1. add the expression on right child of the current tree
1142 * 2. the subtree is completed, allocate a new subtree
1143 * 3. pop the tree value from the tree stack
1146 for(i
=0;i
<strlen(filter
->expression
);i
++) {
1148 //g_print("%c ",filter->expression[i]);
1150 switch(filter
->expression
[i
]) {
1156 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1157 while(t1
->right
!= LTTV_TREE_IDLE
) {
1158 g_assert(t1
->right
== LTTV_TREE_NODE
);
1161 t2
= lttv_filter_tree_new();
1162 t2
->node
= LTTV_LOGICAL_AND
;
1163 if(subtree
!= NULL
) { /* append subtree to current tree */
1164 t2
->left
= LTTV_TREE_NODE
;
1165 t2
->l_child
.t
= subtree
;
1167 t1
->right
= LTTV_TREE_NODE
;
1169 } else { /* append a simple expression */
1170 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1171 a_field_component
= g_string_new("");
1172 t2
->left
= LTTV_TREE_LEAF
;
1173 t2
->l_child
.leaf
= a_simple_expression
;
1174 a_simple_expression
= lttv_simple_expression_new();
1175 t1
->right
= LTTV_TREE_NODE
;
1182 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1183 while(t1
->right
!= LTTV_TREE_IDLE
) {
1184 g_assert(t1
->right
== LTTV_TREE_NODE
);
1187 t2
= lttv_filter_tree_new();
1188 t2
->node
= LTTV_LOGICAL_OR
;
1189 if(subtree
!= NULL
) { /* append subtree to current tree */
1190 t2
->left
= LTTV_TREE_NODE
;
1191 t2
->l_child
.t
= subtree
;
1193 t1
->right
= LTTV_TREE_NODE
;
1195 } else { /* append a simple expression */
1196 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1197 a_field_component
= g_string_new("");
1198 t2
->left
= LTTV_TREE_LEAF
;
1199 t2
->l_child
.leaf
= a_simple_expression
;
1200 a_simple_expression
= lttv_simple_expression_new();
1201 t1
->right
= LTTV_TREE_NODE
;
1208 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1209 while(t1
->right
!= LTTV_TREE_IDLE
) {
1210 g_assert(t1
->right
== LTTV_TREE_NODE
);
1213 t2
= lttv_filter_tree_new();
1214 t2
->node
= LTTV_LOGICAL_XOR
;
1215 if(subtree
!= NULL
) { /* append subtree to current tree */
1216 t2
->left
= LTTV_TREE_NODE
;
1217 t2
->l_child
.t
= subtree
;
1219 t1
->right
= LTTV_TREE_NODE
;
1221 } else { /* append a simple expression */
1222 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1223 a_field_component
= g_string_new("");
1224 t2
->left
= LTTV_TREE_LEAF
;
1225 t2
->l_child
.leaf
= a_simple_expression
;
1226 a_simple_expression
= lttv_simple_expression_new();
1227 t1
->right
= LTTV_TREE_NODE
;
1232 case '!': /* not, or not equal (math op) */
1234 if(filter
->expression
[i
+1] == '=') { /* != */
1235 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1236 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1237 a_field_component
= g_string_new("");
1238 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_NE
);
1241 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1242 while(t1
->right
!= LTTV_TREE_IDLE
) {
1243 g_assert(t1
->right
== LTTV_TREE_NODE
);
1246 t2
= lttv_filter_tree_new();
1247 t2
->node
= LTTV_LOGICAL_NOT
;
1248 t1
->right
= LTTV_TREE_NODE
;
1253 case '(': /* start of parenthesis */
1257 p_nesting
++; /* incrementing parenthesis nesting value */
1258 t1
= lttv_filter_tree_new();
1259 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
1262 case ')': /* end of parenthesis */
1266 p_nesting
--; /* decrementing parenthesis nesting value */
1267 if(p_nesting
<0 || tree_stack
->len
<2) {
1268 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1269 is not valid due to parenthesis incorrect use",filter
->expression
);
1273 /* there must at least be the root tree left in the array */
1274 g_assert(tree_stack
->len
>0);
1276 if(subtree
!= NULL
) { /* append subtree to current tree */
1277 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1278 while(t1
->right
!= LTTV_TREE_IDLE
) {
1279 g_assert(t1
->right
== LTTV_TREE_NODE
);
1282 t1
->right
= LTTV_TREE_NODE
;
1283 t1
->r_child
.t
= subtree
;
1284 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1285 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1286 } else { /* assign subtree as current tree */
1287 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1288 a_field_component
= g_string_new("");
1289 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1290 while(t1
->right
!= LTTV_TREE_IDLE
) {
1291 g_assert(t1
->right
== LTTV_TREE_NODE
);
1292 g_assert(t1
->r_child
.t
!= NULL
);
1295 t1
->right
= LTTV_TREE_LEAF
;
1296 t1
->r_child
.leaf
= a_simple_expression
;
1297 a_simple_expression
= lttv_simple_expression_new();
1298 subtree
= g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1303 * mathematic operators
1305 case '<': /* lower, lower or equal */
1307 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1308 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1309 a_field_component
= g_string_new("");
1310 if(filter
->expression
[i
+1] == '=') { /* <= */
1312 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LE
);
1313 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LT
);
1316 case '>': /* higher, higher or equal */
1318 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1319 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1320 a_field_component
= g_string_new("");
1321 if(filter
->expression
[i
+1] == '=') { /* >= */
1323 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GE
);
1324 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GT
);
1327 case '=': /* equal */
1329 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1330 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1331 a_field_component
= g_string_new("");
1332 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1336 * Field concatening caracter
1341 * divide field expression into elements
1342 * in a_field_path array.
1344 * A dot can also be present in double values
1346 if(a_simple_expression
->field
== LTTV_FILTER_UNDEFINED
) {
1347 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1348 a_field_component
= g_string_new("");
1351 case ' ': /* ignore */
1352 case '\n': /* ignore */
1354 default: /* concatening current string */
1355 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1360 * Preliminary check to see
1361 * if tree was constructed correctly
1364 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1365 is not valid due to parenthesis incorrect use",filter
->expression
);
1369 if(tree_stack
->len
!= 1) /* only root tree should remain */
1372 /* processing last element of expression */
1373 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1374 while(t1
->right
!= LTTV_TREE_IDLE
) {
1375 g_assert(t1
->right
== LTTV_TREE_NODE
);
1378 if(subtree
!= NULL
) { /* add the subtree */
1379 t1
->right
= LTTV_TREE_NODE
;
1380 t1
->r_child
.t
= subtree
;
1382 } else { /* add a leaf */
1383 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1384 a_field_component
= NULL
;
1385 t1
->right
= LTTV_TREE_LEAF
;
1386 t1
->r_child
.leaf
= a_simple_expression
;
1387 a_simple_expression
= NULL
;
1391 /* free the pointer array */
1392 g_assert(a_field_path
->len
== 0);
1393 g_ptr_array_free(a_field_path
,TRUE
);
1395 /* free the tree stack -- but keep the root tree */
1396 filter
->head
= g_ptr_array_remove_index(tree_stack
,0);
1397 g_ptr_array_free(tree_stack
,TRUE
);
1399 /* free the field buffer if allocated */
1400 if(a_field_component
!= NULL
) g_string_free(a_field_component
,TRUE
);
1402 /* free the simple expression buffer if allocated */
1403 if(a_simple_expression
!= NULL
) lttv_simple_expression_destroy(a_simple_expression
);
1405 g_assert(filter
->head
!= NULL
); /* tree should exist */
1406 g_assert(subtree
== NULL
); /* remaining subtree should be included in main tree */
1409 g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1410 lttv_print_tree(filter
->head
) ;
1411 g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1419 * @fn void lttv_filter_destroy(LttvFilter*)
1421 * Destroy the current LttvFilter
1422 * @param filter pointer to the current LttvFilter
1425 lttv_filter_destroy(LttvFilter
* filter
) {
1427 g_free(filter
->expression
);
1428 lttv_filter_tree_destroy(filter
->head
);
1434 * @fn LttvFilterTree* lttv_filter_tree_new()
1436 * Assign a new tree for the current expression
1438 * @return pointer of LttvFilterTree
1441 lttv_filter_tree_new() {
1442 LttvFilterTree
* tree
;
1444 tree
= g_new(LttvFilterTree
,1);
1445 tree
->node
= 0; //g_new(lttv_expression,1);
1446 tree
->left
= LTTV_TREE_IDLE
;
1447 tree
->right
= LTTV_TREE_IDLE
;
1448 tree
->r_child
.t
= NULL
;
1449 tree
->l_child
.t
= NULL
;
1455 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1457 * Append a new expression to the expression
1458 * defined in the current filter
1459 * @param filter pointer to the current LttvFilter
1460 * @param expression string that must be appended
1461 * @return Success/Failure of operation
1463 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, const char *expression
) {
1465 if(expression
== NULL
) return FALSE
;
1466 if(filter
== NULL
) return FALSE
;
1468 GString
* s
= g_string_new("");
1469 if(filter
->expression
!= NULL
) {
1470 g_string_append(s
,filter
->expression
);
1471 g_string_append_c(s
,'&');
1473 g_string_append(s
,expression
);
1475 g_free(filter
->expression
);
1476 filter
->expression
= g_string_free(s
,FALSE
);
1478 /* TRUE if construction of tree proceeded without errors */
1479 return lttv_filter_update(filter
);
1484 * @fn void lttv_filter_clear_expression(LttvFilter*)
1486 * Clear the filter expression from the
1487 * current filter and sets its pointer to NULL
1488 * @param filter pointer to the current LttvFilter
1490 void lttv_filter_clear_expression(LttvFilter
* filter
) {
1492 if(filter
->expression
!= NULL
) {
1493 g_free(filter
->expression
);
1494 filter
->expression
= NULL
;
1500 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1502 * Destroys the tree and his sub-trees
1503 * @param tree Tree which must be destroyed
1506 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1508 if(tree
== NULL
) return;
1510 if(tree
->left
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->l_child
.leaf
);
1511 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1513 if(tree
->right
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->r_child
.leaf
);
1514 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1516 // g_free(tree->node);
1521 * Global parsing function for the current
1523 * @param t pointer to the current LttvFilterTree
1524 * @param event current LttEvent, NULL if not used
1525 * @param tracefile current LttTracefile, NULL if not used
1526 * @param trace current LttTrace, NULL if not used
1527 * @param state current LttvProcessState, NULL if not used
1528 * @param context current LttvTracefileContext, NULL if not used
1529 * @return response of filter
1532 lttv_filter_tree_parse(
1533 const LttvFilterTree
* t
,
1534 const LttEvent
* event
,
1535 const LttTracefile
* tracefile
,
1536 const LttTrace
* trace
,
1537 const LttvProcessState
* state
,
1538 const LttvTracefileContext
* context
1543 * Each tree is parsed in inorder.
1544 * This way, it's possible to apply the left filter of the
1545 * tree, then decide whether or not the right branch should
1546 * be parsed depending on the linking logical operator
1548 * Each node consists in a
1549 * 1. logical operator
1550 * 2. left child ( node or simple expression )
1551 * 3. right child ( node or simple expression )
1553 * When the child is a simple expression, we must
1554 * before all determine if the expression refers to
1555 * a structure which is whithin observation ( not NULL ).
1556 * -If so, the expression is evaluated.
1557 * -If not, the result is set to TRUE since this particular
1558 * operation does not interfere with the lttv structure
1560 * The result of each simple expression will directly
1561 * affect the next branch. This way, depending on
1562 * the linking logical operator, the parser will decide
1563 * to explore or not the next branch.
1565 * -If result of left branch is 0 / FALSE
1566 * then don't explore right branch and return 0;
1567 * -If result of left branch is 1 / TRUE then explore
1569 * -If result of left branch is 1 / TRUE
1570 * then don't explore right branch and return 1;
1571 * -If result of left branch is 0 / FALSE then explore
1573 * -Result of left branch will not affect exploration of
1577 gboolean lresult
= FALSE
, rresult
= FALSE
;
1582 if(t
->left
== LTTV_TREE_NODE
) {
1583 lresult
= lttv_filter_tree_parse(t
->l_child
.t
,event
,tracefile
,trace
,state
,context
);
1585 else if(t
->left
== LTTV_TREE_LEAF
) {
1586 lresult
= lttv_filter_tree_parse_branch(t
->l_child
.leaf
,event
,tracefile
,trace
,state
,context
);
1590 * Parse linking operator
1591 * make a cutoff if possible
1593 if((t
->node
& LTTV_LOGICAL_OR
) && lresult
== TRUE
) return TRUE
;
1594 if((t
->node
& LTTV_LOGICAL_AND
) && lresult
== FALSE
) return FALSE
;
1597 * Parse right branch
1599 if(t
->right
== LTTV_TREE_NODE
) {
1600 rresult
= lttv_filter_tree_parse(t
->r_child
.t
,event
,tracefile
,trace
,state
,context
);
1602 else if(t
->right
== LTTV_TREE_LEAF
) {
1603 rresult
= lttv_filter_tree_parse_branch(t
->r_child
.leaf
,event
,tracefile
,trace
,state
,context
);
1607 * Apply and return the
1608 * logical link between the
1612 case LTTV_LOGICAL_OR
: return (lresult
| rresult
);
1613 case LTTV_LOGICAL_AND
: return (lresult
& rresult
);
1614 case LTTV_LOGICAL_NOT
: return (!rresult
);
1615 case LTTV_LOGICAL_XOR
: return (lresult
^ rresult
);
1616 case 0: return (rresult
);
1619 * This case should never be
1620 * parsed, if so, this subtree
1629 * This function parses a particular branch of the tree
1630 * @param se pointer to the current LttvSimpleExpression
1631 * @param event current LttEvent, NULL if not used
1632 * @param tracefile current LttTracefile, NULL if not used
1633 * @param trace current LttTrace, NULL if not used
1634 * @param state current LttvProcessState, NULL if not used
1635 * @param context current LttvTracefileContext, NULL if not used
1636 * @return response of filter
1638 gboolean
lttv_filter_tree_parse_branch(
1639 const LttvSimpleExpression
* se
,
1640 const LttEvent
* event
,
1641 const LttTracefile
* tracefile
,
1642 const LttTrace
* trace
,
1643 const LttvProcessState
* state
,
1644 const LttvTracefileContext
* context
) {
1649 case LTTV_FILTER_TRACE_NAME
:
1650 if(trace
== NULL
) return TRUE
;
1652 char* trace_name
= ltt_trace_name(trace
);
1653 GQuark quark
= g_quark_from_string(trace_name
);
1654 return se
->op((gpointer
)&quark
,v
);
1657 case LTTV_FILTER_TRACEFILE_NAME
:
1658 if(tracefile
== NULL
) return TRUE
;
1660 char* tracefile_name
= ltt_tracefile_name(tracefile
);
1661 GQuark quark
= g_quark_from_string(tracefile_name
);
1662 return se
->op((gpointer
)&quark
,v
);
1665 case LTTV_FILTER_STATE_PID
:
1666 if(state
== NULL
) return TRUE
;
1667 else return se
->op((gpointer
)&state
->pid
,v
);
1669 case LTTV_FILTER_STATE_PPID
:
1670 if(state
== NULL
) return TRUE
;
1671 else return se
->op((gpointer
)&state
->ppid
,v
);
1673 case LTTV_FILTER_STATE_CT
:
1674 if(state
== NULL
) return TRUE
;
1676 return se
->op((gpointer
)&state
->creation_time
,v
);
1679 case LTTV_FILTER_STATE_IT
:
1680 if(state
== NULL
) return TRUE
;
1682 return se
->op((gpointer
)&state
->insertion_time
,v
);
1685 case LTTV_FILTER_STATE_P_NAME
:
1687 * All 'unnamed' for the moment
1689 if(state
== NULL
) return TRUE
;
1691 GQuark quark
= state
->name
;
1692 return se
->op((gpointer
)&quark
,v
);
1695 case LTTV_FILTER_STATE_EX_MODE
:
1696 if(state
== NULL
) return TRUE
;
1697 else return se
->op((gpointer
)&state
->state
->t
,v
);
1699 case LTTV_FILTER_STATE_EX_SUBMODE
:
1700 if(state
== NULL
) return TRUE
;
1701 else return se
->op((gpointer
)&state
->state
->n
,v
);
1703 case LTTV_FILTER_STATE_P_STATUS
:
1704 if(state
== NULL
) return TRUE
;
1705 else return se
->op((gpointer
)&state
->state
->s
,v
);
1707 case LTTV_FILTER_STATE_CPU
:
1708 if(context
== NULL
) return TRUE
;
1710 /* FIXME: not sure of that one */
1711 GQuark quark
= ((LttvTracefileState
*)context
)->cpu_name
;
1712 return se
->op((gpointer
)&quark
,v
);
1715 case LTTV_FILTER_EVENT_NAME
:
1716 if(event
== NULL
) return TRUE
;
1719 et
= ltt_event_eventtype(event
);
1720 char* event_name
= ltt_eventtype_name(et
);
1721 GQuark quark
= g_quark_from_string(event_name
);
1722 return se
->op((gpointer
)&quark
,v
);
1726 case LTTV_FILTER_EVENT_CATEGORY
:
1728 * TODO: Not yet implemented
1732 case LTTV_FILTER_EVENT_TIME
:
1733 if(event
== NULL
) return TRUE
;
1735 LttTime time
= ltt_event_time(event
);
1736 return se
->op((gpointer
)&time
,v
);
1739 case LTTV_FILTER_EVENT_TSC
:
1740 if(event
== NULL
) return TRUE
;
1742 LttCycleCount count
= ltt_event_cycle_count(event
);
1743 return se
->op((gpointer
)&count
,v
);
1746 case LTTV_FILTER_EVENT_FIELD
:
1748 * TODO: Use the offset to
1749 * find the dynamic field
1750 * in the event struct
1755 * This case should never be
1756 * parsed, if so, the whole
1757 * filtering is cancelled
1759 g_warning("Error while parsing the filter tree");
1763 /* should never get here */
1771 * Debug function. Prints tree memory allocation.
1772 * @param t the pointer to the current LttvFilterTree
1775 lttv_print_tree(const LttvFilterTree
* t
) {
1777 g_print("node:%p lchild:%p rchild:%p\n",t
, //t->l_child.t,t->r_child.t);
1778 (t
->left
==LTTV_TREE_NODE
)?t
->l_child
.t
:NULL
,
1779 (t
->right
==LTTV_TREE_NODE
)?t
->r_child
.t
:NULL
);
1780 g_print("node type: %i / [left] %i / [right] %i\n",t
->node
,t
->left
,t
->right
);
1781 if(t
->left
== LTTV_TREE_NODE
) lttv_print_tree(t
->l_child
.t
);
1782 else if(t
->left
== LTTV_TREE_LEAF
) {
1783 g_print("%p: left is %i %p value\n",t
,t
->l_child
.leaf
->field
,t
->l_child
.leaf
->op
);
1785 if(t
->right
== LTTV_TREE_NODE
) lttv_print_tree(t
->r_child
.t
);
1786 else if(t
->right
== LTTV_TREE_LEAF
) {
1787 g_print("%p: right is %i %p value\n",t
,t
->r_child
.leaf
->field
,t
->r_child
.leaf
->op
);
1793 * @fn static void module_init()
1795 * Initializes the filter module and specific values
1797 static void module_init()
1803 * Destroys the filter module and specific values
1805 static void module_destroy()
1811 LTTV_MODULE("filter", "Filters traceset and events", \
1812 "Filters traceset and events specifically to user input", \
1813 module_init
, module_destroy
)