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_STATE_EX_MODE
:
266 case LTTV_FILTER_STATE_EX_SUBMODE
:
267 case LTTV_FILTER_STATE_P_STATUS
:
268 case LTTV_FILTER_EVENT_TSC
:
271 se
->op
= lttv_apply_op_eq_uint64
;
274 se
->op
= lttv_apply_op_ne_uint64
;
277 se
->op
= lttv_apply_op_lt_uint64
;
280 se
->op
= lttv_apply_op_le_uint64
;
283 se
->op
= lttv_apply_op_gt_uint64
;
286 se
->op
= lttv_apply_op_ge_uint64
;
289 g_warning("Error encountered in operator assignment");
296 case LTTV_FILTER_STATE_CT
:
297 case LTTV_FILTER_STATE_IT
:
298 case LTTV_FILTER_EVENT_TIME
:
301 se
->op
= lttv_apply_op_eq_ltttime
;
304 se
->op
= lttv_apply_op_ne_ltttime
;
307 se
->op
= lttv_apply_op_lt_ltttime
;
310 se
->op
= lttv_apply_op_le_ltttime
;
313 se
->op
= lttv_apply_op_gt_ltttime
;
316 se
->op
= lttv_apply_op_ge_ltttime
;
319 g_warning("Error encountered in operator assignment");
324 g_warning("Error encountered in operator assignation ! Field type:%i",se
->field
);
333 * @fn gboolean lttv_simple_expression_assign_value(LttvSimpleExpression*,char*)
335 * Assign the value field to the current LttvSimpleExpression
336 * @param se pointer to the current LttvSimpleExpression
337 * @param value string value for simple expression
339 gboolean
lttv_simple_expression_assign_value(LttvSimpleExpression
* se
, char* value
) {
342 gboolean is_double
= FALSE
;
343 LttTime t
= ltt_time_zero
;
351 case LTTV_FILTER_TRACE_NAME
:
352 case LTTV_FILTER_TRACEFILE_NAME
:
353 case LTTV_FILTER_STATE_P_NAME
:
354 case LTTV_FILTER_EVENT_NAME
:
355 case LTTV_FILTER_STATE_CPU
:
356 // se->value.v_string = value;
357 se
->value
.v_uint32
= g_quark_from_string(value
);
363 case LTTV_FILTER_STATE_PID
:
364 case LTTV_FILTER_STATE_PPID
:
365 case LTTV_FILTER_STATE_EX_MODE
:
366 case LTTV_FILTER_STATE_EX_SUBMODE
:
367 case LTTV_FILTER_STATE_P_STATUS
:
368 case LTTV_FILTER_EVENT_TSC
:
369 se
->value
.v_uint64
= atoi(value
);
375 case LTTV_FILTER_STATE_CT
:
376 case LTTV_FILTER_STATE_IT
:
377 case LTTV_FILTER_EVENT_TIME
:
378 //se->value.v_double = atof(value);
380 * parsing logic could be optimised,
381 * but as for now, simpler this way
383 v
= g_string_new("");
384 for(i
=0;i
<strlen(value
);i
++) {
385 if(value
[i
] == '.') {
386 /* cannot specify number with more than one '.' */
387 if(is_double
) return FALSE
;
388 else is_double
= TRUE
;
390 g_string_free(v
,TRUE
);
391 v
= g_string_new("");
392 } else g_string_append_c(v
,value
[i
]);
394 /* number can be integer or double */
395 if(is_double
) t
.tv_nsec
= atoi(v
);
396 else t
.tv_sec
= atoi(v
);
398 g_string_free(v
,TRUE
);
400 se
->value
.v_ltttime
= t
;
404 g_warning("Error encountered in value assignation ! Field type = %i",se
->field
);
414 * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*)
416 * Disallocate memory for the current
418 * @param se pointer to the current LttvSimpleExpression
421 lttv_simple_expression_destroy(LttvSimpleExpression
* se
) {
423 // g_free(se->value);
425 case LTTV_FILTER_TRACE_NAME
:
426 case LTTV_FILTER_TRACEFILE_NAME
:
427 case LTTV_FILTER_STATE_P_NAME
:
428 case LTTV_FILTER_EVENT_NAME
:
429 g_free(se
->value
.v_string
);
437 * @fn gint lttv_struct_type(gint)
439 * Finds the structure type depending
440 * on the fields in parameters
441 * @params ft Field of the current structure
442 * @return LttvStructType enum or -1 for error
445 lttv_struct_type(gint ft
) {
448 case LTTV_FILTER_TRACE_NAME
:
449 return LTTV_FILTER_TRACE
;
451 case LTTV_FILTER_TRACEFILE_NAME
:
452 return LTTV_FILTER_TRACEFILE
;
454 case LTTV_FILTER_STATE_PID
:
455 case LTTV_FILTER_STATE_PPID
:
456 case LTTV_FILTER_STATE_CT
:
457 case LTTV_FILTER_STATE_IT
:
458 case LTTV_FILTER_STATE_P_NAME
:
459 case LTTV_FILTER_STATE_EX_MODE
:
460 case LTTV_FILTER_STATE_EX_SUBMODE
:
461 case LTTV_FILTER_STATE_P_STATUS
:
462 case LTTV_FILTER_STATE_CPU
:
463 return LTTV_FILTER_STATE
;
465 case LTTV_FILTER_EVENT_NAME
:
466 case LTTV_FILTER_EVENT_CATEGORY
:
467 case LTTV_FILTER_EVENT_TIME
:
468 case LTTV_FILTER_EVENT_TSC
:
469 case LTTV_FILTER_EVENT_FIELD
:
470 return LTTV_FILTER_EVENT
;
478 * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue)
480 * Applies the 'equal' operator to the
481 * specified structure and value
482 * @param v1 left member of comparison
483 * @param v2 right member of comparison
484 * @return success/failure of operation
486 gboolean
lttv_apply_op_eq_uint64(const gpointer v1
, LttvFieldValue v2
) {
488 guint64
* r
= (guint64
*) v1
;
489 return (*r
== v2
.v_uint64
);
494 * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue)
496 * Applies the 'equal' operator to the
497 * specified structure and value
498 * @param v1 left member of comparison
499 * @param v2 right member of comparison
500 * @return success/failure of operation
502 gboolean
lttv_apply_op_eq_uint32(const gpointer v1
, LttvFieldValue v2
) {
503 guint32
* r
= (guint32
*) v1
;
504 return (*r
== v2
.v_uint32
);
508 * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue)
510 * Applies the 'equal' operator to the
511 * specified structure and value
512 * @param v1 left member of comparison
513 * @param v2 right member of comparison
514 * @return success/failure of operation
516 gboolean
lttv_apply_op_eq_uint16(const gpointer v1
, LttvFieldValue v2
) {
517 guint16
* r
= (guint16
*) v1
;
518 return (*r
== v2
.v_uint16
);
522 * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue)
524 * Applies the 'equal' operator to the
525 * specified structure and value
526 * @param v1 left member of comparison
527 * @param v2 right member of comparison
528 * @return success/failure of operation
530 gboolean
lttv_apply_op_eq_double(const gpointer v1
, LttvFieldValue v2
) {
531 double* r
= (double*) v1
;
532 return (*r
== v2
.v_double
);
536 * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue)
538 * Applies the 'equal' operator to the
539 * specified structure and value
540 * @param v1 left member of comparison
541 * @param v2 right member of comparison
542 * @return success/failure of operation
544 gboolean
lttv_apply_op_eq_string(const gpointer v1
, LttvFieldValue v2
) {
545 char* r
= (char*) v1
;
546 return (!g_strcasecmp(r
,v2
.v_string
));
550 * @fn gboolean lttv_apply_op_eq_quark(gpointer,LttvFieldValue)
552 * Applies the 'equal' operator to the
553 * specified structure and value
554 * @param v1 left member of comparison
555 * @param v2 right member of comparison
556 * @return success/failure of operation
558 gboolean
lttv_apply_op_eq_quark(const gpointer v1
, LttvFieldValue v2
) {
559 GQuark
* r
= (GQuark
*) v1
;
560 g_print("v1:%i v2:%i\n",*r
,v2
.v_uint32
);
561 return (*r
== v2
.v_uint32
);
565 * @fn gboolean lttv_apply_op_eq_ltttime(gpointer,LttvFieldValue)
567 * Applies the 'equal' operator to the
568 * specified structure and value
569 * @param v1 left member of comparison
570 * @param v2 right member of comparison
571 * @return success/failure of operation
573 gboolean
lttv_apply_op_eq_ltttime(const gpointer v1
, LttvFieldValue v2
) {
574 LttTime
* r
= (LttTime
*) v1
;
575 return ltt_time_compare(*r
, v2
.v_ltttime
)==0?1:0;
580 * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue)
582 * Applies the 'not equal' operator to the
583 * specified structure and value
584 * @param v1 left member of comparison
585 * @param v2 right member of comparison
586 * @return success/failure of operation
588 gboolean
lttv_apply_op_ne_uint64(const gpointer v1
, LttvFieldValue v2
) {
589 guint64
* r
= (guint64
*) v1
;
590 return (*r
!= v2
.v_uint64
);
594 * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue)
596 * Applies the 'not equal' operator to the
597 * specified structure and value
598 * @param v1 left member of comparison
599 * @param v2 right member of comparison
600 * @return success/failure of operation
602 gboolean
lttv_apply_op_ne_uint32(const gpointer v1
, LttvFieldValue v2
) {
603 guint32
* r
= (guint32
*) v1
;
604 return (*r
!= v2
.v_uint32
);
608 * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue)
610 * Applies the 'not equal' operator to the
611 * specified structure and value
612 * @param v1 left member of comparison
613 * @param v2 right member of comparison
614 * @return success/failure of operation
616 gboolean
lttv_apply_op_ne_uint16(const gpointer v1
, LttvFieldValue v2
) {
617 guint16
* r
= (guint16
*) v1
;
618 return (*r
!= v2
.v_uint16
);
622 * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue)
624 * Applies the 'not equal' operator to the
625 * specified structure and value
626 * @param v1 left member of comparison
627 * @param v2 right member of comparison
628 * @return success/failure of operation
630 gboolean
lttv_apply_op_ne_double(const gpointer v1
, LttvFieldValue v2
) {
631 double* r
= (double*) v1
;
632 return (*r
!= v2
.v_double
);
636 * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue)
638 * Applies the 'not equal' operator to the
639 * specified structure and value
640 * @param v1 left member of comparison
641 * @param v2 right member of comparison
642 * @return success/failure of operation
644 gboolean
lttv_apply_op_ne_string(const gpointer v1
, LttvFieldValue v2
) {
645 char* r
= (char*) v1
;
646 return (g_strcasecmp(r
,v2
.v_string
));
650 * @fn gboolean lttv_apply_op_ne_quark(gpointer,LttvFieldValue)
652 * Applies the 'not equal' operator to the
653 * specified structure and value
654 * @param v1 left member of comparison
655 * @param v2 right member of comparison
656 * @return success/failure of operation
658 gboolean
lttv_apply_op_ne_quark(const gpointer v1
, LttvFieldValue v2
) {
659 GQuark
* r
= (GQuark
*) v1
;
660 return (*r
!= v2
.v_uint32
);
665 * @fn gboolean lttv_apply_op_ne_ltttime(gpointer,LttvFieldValue)
667 * Applies the 'not equal' operator to the
668 * specified structure and value
669 * @param v1 left member of comparison
670 * @param v2 right member of comparison
671 * @return success/failure of operation
673 gboolean
lttv_apply_op_ne_ltttime(const gpointer v1
, LttvFieldValue v2
) {
674 LttTime
* r
= (LttTime
*) v1
;
675 return ltt_time_compare(*r
, v2
.v_ltttime
)!=0?1:0;
680 * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue)
682 * Applies the 'lower than' operator to the
683 * specified structure and value
684 * @param v1 left member of comparison
685 * @param v2 right member of comparison
686 * @return success/failure of operation
688 gboolean
lttv_apply_op_lt_uint64(const gpointer v1
, LttvFieldValue v2
) {
689 guint64
* r
= (guint64
*) v1
;
690 return (*r
< v2
.v_uint64
);
694 * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue)
696 * Applies the 'lower than' operator to the
697 * specified structure and value
698 * @param v1 left member of comparison
699 * @param v2 right member of comparison
700 * @return success/failure of operation
702 gboolean
lttv_apply_op_lt_uint32(const gpointer v1
, LttvFieldValue v2
) {
703 guint32
* r
= (guint32
*) v1
;
704 return (*r
< v2
.v_uint32
);
708 * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue)
710 * Applies the 'lower than' operator to the
711 * specified structure and value
712 * @param v1 left member of comparison
713 * @param v2 right member of comparison
714 * @return success/failure of operation
716 gboolean
lttv_apply_op_lt_uint16(const gpointer v1
, LttvFieldValue v2
) {
717 guint16
* r
= (guint16
*) v1
;
718 return (*r
< v2
.v_uint16
);
722 * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue)
724 * Applies the 'lower than' operator to the
725 * specified structure and value
726 * @param v1 left member of comparison
727 * @param v2 right member of comparison
728 * @return success/failure of operation
730 gboolean
lttv_apply_op_lt_double(const gpointer v1
, LttvFieldValue v2
) {
731 double* r
= (double*) v1
;
732 return (*r
< v2
.v_double
);
736 * @fn gboolean lttv_apply_op_lt_ltttime(gpointer,LttvFieldValue)
738 * Applies the 'lower than' operator to the
739 * specified structure and value
740 * @param v1 left member of comparison
741 * @param v2 right member of comparison
742 * @return success/failure of operation
744 gboolean
lttv_apply_op_lt_ltttime(const gpointer v1
, LttvFieldValue v2
) {
745 LttTime
* r
= (LttTime
*) v1
;
746 // 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)));
747 return ltt_time_compare(*r
, v2
.v_ltttime
)==-1?1:0;
752 * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue)
754 * Applies the 'lower or equal' operator to the
755 * specified structure and value
756 * @param v1 left member of comparison
757 * @param v2 right member of comparison
758 * @return success/failure of operation
760 gboolean
lttv_apply_op_le_uint64(const gpointer v1
, LttvFieldValue v2
) {
761 guint64
* r
= (guint64
*) v1
;
762 return (*r
<= v2
.v_uint64
);
766 * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue)
768 * Applies the 'lower or equal' operator to the
769 * specified structure and value
770 * @param v1 left member of comparison
771 * @param v2 right member of comparison
772 * @return success/failure of operation
774 gboolean
lttv_apply_op_le_uint32(const gpointer v1
, LttvFieldValue v2
) {
775 guint32
* r
= (guint32
*) v1
;
776 return (*r
<= v2
.v_uint32
);
780 * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue)
782 * Applies the 'lower or equal' operator to the
783 * specified structure and value
784 * @param v1 left member of comparison
785 * @param v2 right member of comparison
786 * @return success/failure of operation
788 gboolean
lttv_apply_op_le_uint16(const gpointer v1
, LttvFieldValue v2
) {
789 guint16
* r
= (guint16
*) v1
;
790 return (*r
<= v2
.v_uint16
);
794 * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue)
796 * Applies the 'lower or equal' operator to the
797 * specified structure and value
798 * @param v1 left member of comparison
799 * @param v2 right member of comparison
800 * @return success/failure of operation
802 gboolean
lttv_apply_op_le_double(const gpointer v1
, LttvFieldValue v2
) {
803 double* r
= (double*) v1
;
804 return (*r
<= v2
.v_double
);
808 * @fn gboolean lttv_apply_op_le_ltttime(gpointer,LttvFieldValue)
810 * Applies the 'lower or equal' operator to the
811 * specified structure and value
812 * @param v1 left member of comparison
813 * @param v2 right member of comparison
814 * @return success/failure of operation
816 gboolean
lttv_apply_op_le_ltttime(const gpointer v1
, LttvFieldValue v2
) {
817 LttTime
* r
= (LttTime
*) v1
;
818 // 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)));
819 return ltt_time_compare(*r
, v2
.v_ltttime
)<1?1:0;
824 * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue)
826 * Applies the 'greater than' operator to the
827 * specified structure and value
828 * @param v1 left member of comparison
829 * @param v2 right member of comparison
830 * @return success/failure of operation
832 gboolean
lttv_apply_op_gt_uint64(const gpointer v1
, LttvFieldValue v2
) {
833 guint64
* r
= (guint64
*) v1
;
834 return (*r
> v2
.v_uint64
);
838 * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue)
840 * Applies the 'greater than' operator to the
841 * specified structure and value
842 * @param v1 left member of comparison
843 * @param v2 right member of comparison
844 * @return success/failure of operation
846 gboolean
lttv_apply_op_gt_uint32(const gpointer v1
, LttvFieldValue v2
) {
847 guint32
* r
= (guint32
*) v1
;
848 return (*r
> v2
.v_uint32
);
852 * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue)
854 * Applies the 'greater than' operator to the
855 * specified structure and value
856 * @param v1 left member of comparison
857 * @param v2 right member of comparison
858 * @return success/failure of operation
860 gboolean
lttv_apply_op_gt_uint16(const gpointer v1
, LttvFieldValue v2
) {
861 guint16
* r
= (guint16
*) v1
;
862 return (*r
> v2
.v_uint16
);
866 * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue)
868 * Applies the 'greater than' operator to the
869 * specified structure and value
870 * @param v1 left member of comparison
871 * @param v2 right member of comparison
872 * @return success/failure of operation
874 gboolean
lttv_apply_op_gt_double(const gpointer v1
, LttvFieldValue v2
) {
875 double* r
= (double*) v1
;
876 return (*r
> v2
.v_double
);
880 * @fn gboolean lttv_apply_op_gt_ltttime(gpointer,LttvFieldValue)
882 * Applies the 'greater than' operator to the
883 * specified structure and value
884 * @param v1 left member of comparison
885 * @param v2 right member of comparison
886 * @return success/failure of operation
888 gboolean
lttv_apply_op_gt_ltttime(const gpointer v1
, LttvFieldValue v2
) {
889 LttTime
* r
= (LttTime
*) v1
;
890 // 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)));
891 return ltt_time_compare(*r
, v2
.v_ltttime
)==1?1:0;
896 * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue)
898 * Applies the 'greater or equal' operator to the
899 * specified structure and value
900 * @param v1 left member of comparison
901 * @param v2 right member of comparison
902 * @return success/failure of operation
904 gboolean
lttv_apply_op_ge_uint64(const gpointer v1
, LttvFieldValue v2
) {
905 guint64
* r
= (guint64
*) v1
;
906 return (*r
>= v2
.v_uint64
);
910 * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue)
912 * Applies the 'greater or equal' operator to the
913 * specified structure and value
914 * @param v1 left member of comparison
915 * @param v2 right member of comparison
916 * @return success/failure of operation
918 gboolean
lttv_apply_op_ge_uint32(const gpointer v1
, LttvFieldValue v2
) {
919 guint32
* r
= (guint32
*) v1
;
920 return (*r
>= v2
.v_uint32
);
924 * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue)
926 * Applies the 'greater or equal' operator to the
927 * specified structure and value
928 * @param v1 left member of comparison
929 * @param v2 right member of comparison
930 * @return success/failure of operation
932 gboolean
lttv_apply_op_ge_uint16(const gpointer v1
, LttvFieldValue v2
) {
933 guint16
* r
= (guint16
*) v1
;
934 return (*r
>= v2
.v_uint16
);
938 * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue)
940 * Applies the 'greater or equal' operator to the
941 * specified structure and value
942 * @param v1 left member of comparison
943 * @param v2 right member of comparison
944 * @return success/failure of operation
946 gboolean
lttv_apply_op_ge_double(const gpointer v1
, LttvFieldValue v2
) {
947 double* r
= (double*) v1
;
948 return (*r
>= v2
.v_double
);
952 * @fn gboolean lttv_apply_op_ge_ltttime(gpointer,LttvFieldValue)
954 * Applies the 'greater or equal' operator to the
955 * specified structure and value
956 * @param v1 left member of comparison
957 * @param v2 right member of comparison
958 * @return success/failure of operation
960 gboolean
lttv_apply_op_ge_ltttime(const gpointer v1
, LttvFieldValue v2
) {
961 LttTime
* r
= (LttTime
*) v1
;
962 // 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)));
963 return ltt_time_compare(*r
, v2
.v_ltttime
)>-1?1:0;
969 * Makes a copy of the current filter tree
970 * @param tree pointer to the current tree
971 * @return new copy of the filter tree
974 lttv_filter_tree_clone(const LttvFilterTree
* tree
) {
976 LttvFilterTree
* newtree
= lttv_filter_tree_new();
978 newtree
->node
= tree
->node
;
980 newtree
->left
= tree
->left
;
981 if(newtree
->left
== LTTV_TREE_NODE
) {
982 newtree
->l_child
.t
= lttv_filter_tree_clone(tree
->l_child
.t
);
983 } else if(newtree
->left
== LTTV_TREE_LEAF
) {
984 newtree
->l_child
.leaf
= lttv_simple_expression_new();
985 newtree
->l_child
.leaf
->field
= tree
->l_child
.leaf
->field
;
986 newtree
->l_child
.leaf
->offset
= tree
->l_child
.leaf
->offset
;
987 newtree
->l_child
.leaf
->op
= tree
->l_child
.leaf
->op
;
988 /* FIXME: special case for string copy ! */
989 newtree
->l_child
.leaf
->value
= tree
->l_child
.leaf
->value
;
992 newtree
->right
= tree
->right
;
993 if(newtree
->right
== LTTV_TREE_NODE
) {
994 newtree
->r_child
.t
= lttv_filter_tree_clone(tree
->r_child
.t
);
995 } else if(newtree
->right
== LTTV_TREE_LEAF
) {
996 newtree
->r_child
.leaf
= lttv_simple_expression_new();
997 newtree
->r_child
.leaf
->field
= tree
->r_child
.leaf
->field
;
998 newtree
->r_child
.leaf
->offset
= tree
->r_child
.leaf
->offset
;
999 newtree
->r_child
.leaf
->op
= tree
->r_child
.leaf
->op
;
1000 newtree
->r_child
.leaf
->value
= tree
->r_child
.leaf
->value
;
1008 * Makes a copy of the current filter
1009 * @param filter pointer to the current filter
1010 * @return new copy of the filter
1013 lttv_filter_clone(const LttvFilter
* filter
) {
1015 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
1017 strcpy(newfilter
->expression
,filter
->expression
);
1019 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
1027 * @fn LttvFilter* lttv_filter_new()
1029 * Creates a new LttvFilter
1030 * @return the current LttvFilter or NULL if error
1035 LttvFilter
* filter
= g_new(LttvFilter
,1);
1036 filter
->expression
= NULL
;
1037 filter
->head
= NULL
;
1044 * @fn gboolean lttv_filter_update(LttvFilter*)
1046 * Updates the current LttvFilter by building
1047 * its tree based upon the expression string
1048 * @param filter pointer to the current LttvFilter
1049 * @return Failure/Success of operation
1052 lttv_filter_update(LttvFilter
* filter
) {
1054 // g_print("filter::lttv_filter_new()\n"); /* debug */
1056 if(filter
->expression
== NULL
) return FALSE
;
1060 p_nesting
=0; /* parenthesis nesting value */
1064 *tree
= lttv_filter_tree_new(), /* main tree */
1065 *subtree
= NULL
, /* buffer for subtrees */
1066 *t1
, /* buffer #1 */
1067 *t2
; /* buffer #2 */
1071 * If the tree already exists,
1072 * destroy it and build a new one
1074 if(filter
->head
!= NULL
) lttv_filter_tree_destroy(filter
->head
);
1075 filter
->head
= NULL
; /* will be assigned at the end */
1079 * each element of the list
1080 * is a sub tree created
1081 * by the use of parenthesis in the
1082 * global expression. The final tree
1083 * will be the one left at the root of
1086 GPtrArray
*tree_stack
= g_ptr_array_new();
1087 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
1089 /* temporary values */
1090 GString
*a_field_component
= g_string_new("");
1091 GPtrArray
*a_field_path
= g_ptr_array_new();
1093 /* simple expression buffer */
1094 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
1097 * Parse entire expression and construct
1098 * the binary tree. There are two steps
1099 * in browsing that string
1100 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
1101 * 2. finding simple expressions
1102 * - field path ( separated by dots )
1103 * - op ( >, <, =, >=, <=, !=)
1104 * - value ( integer, string ... )
1105 * To spare computing time, the whole
1106 * string is parsed in this loop for a
1107 * O(n) complexity order.
1109 * When encountering logical op &,|,^
1110 * 1. parse the last value if any
1111 * 2. create a new tree
1112 * 3. add the expression (simple exp, or exp (subtree)) to the tree
1113 * 4. concatenate this tree with the current tree on top of the stack
1114 * When encountering math ops >,>=,<,<=,=,!=
1115 * 1. add to op to the simple expression
1116 * 2. concatenate last field component to field path
1117 * When encountering concatening ops .
1118 * 1. concatenate last field component to field path
1119 * When encountering opening parenthesis (,{,[
1120 * 1. create a new subtree on top of tree stack
1121 * When encountering closing parenthesis ),},]
1122 * 1. add the expression on right child of the current tree
1123 * 2. the subtree is completed, allocate a new subtree
1124 * 3. pop the tree value from the tree stack
1127 for(i
=0;i
<strlen(filter
->expression
);i
++) {
1129 //g_print("%c ",filter->expression[i]);
1131 switch(filter
->expression
[i
]) {
1137 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1138 while(t1
->right
!= LTTV_TREE_IDLE
) {
1139 g_assert(t1
->right
== LTTV_TREE_NODE
);
1142 t2
= lttv_filter_tree_new();
1143 t2
->node
= LTTV_LOGICAL_AND
;
1144 if(subtree
!= NULL
) { /* append subtree to current tree */
1145 t2
->left
= LTTV_TREE_NODE
;
1146 t2
->l_child
.t
= subtree
;
1148 t1
->right
= LTTV_TREE_NODE
;
1150 } else { /* append a simple expression */
1151 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1152 a_field_component
= g_string_new("");
1153 t2
->left
= LTTV_TREE_LEAF
;
1154 t2
->l_child
.leaf
= a_simple_expression
;
1155 a_simple_expression
= lttv_simple_expression_new();
1156 t1
->right
= LTTV_TREE_NODE
;
1163 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1164 while(t1
->right
!= LTTV_TREE_IDLE
) {
1165 g_assert(t1
->right
== LTTV_TREE_NODE
);
1168 t2
= lttv_filter_tree_new();
1169 t2
->node
= LTTV_LOGICAL_OR
;
1170 if(subtree
!= NULL
) { /* append subtree to current tree */
1171 t2
->left
= LTTV_TREE_NODE
;
1172 t2
->l_child
.t
= subtree
;
1174 t1
->right
= LTTV_TREE_NODE
;
1176 } else { /* append a simple expression */
1177 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1178 a_field_component
= g_string_new("");
1179 t2
->left
= LTTV_TREE_LEAF
;
1180 t2
->l_child
.leaf
= a_simple_expression
;
1181 a_simple_expression
= lttv_simple_expression_new();
1182 t1
->right
= LTTV_TREE_NODE
;
1189 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1190 while(t1
->right
!= LTTV_TREE_IDLE
) {
1191 g_assert(t1
->right
== LTTV_TREE_NODE
);
1194 t2
= lttv_filter_tree_new();
1195 t2
->node
= LTTV_LOGICAL_XOR
;
1196 if(subtree
!= NULL
) { /* append subtree to current tree */
1197 t2
->left
= LTTV_TREE_NODE
;
1198 t2
->l_child
.t
= subtree
;
1200 t1
->right
= LTTV_TREE_NODE
;
1202 } else { /* append a simple expression */
1203 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1204 a_field_component
= g_string_new("");
1205 t2
->left
= LTTV_TREE_LEAF
;
1206 t2
->l_child
.leaf
= a_simple_expression
;
1207 a_simple_expression
= lttv_simple_expression_new();
1208 t1
->right
= LTTV_TREE_NODE
;
1213 case '!': /* not, or not equal (math op) */
1215 if(filter
->expression
[i
+1] == '=') { /* != */
1216 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1217 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1218 a_field_component
= g_string_new("");
1219 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_NE
);
1222 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1223 while(t1
->right
!= LTTV_TREE_IDLE
) {
1224 g_assert(t1
->right
== LTTV_TREE_NODE
);
1227 t2
= lttv_filter_tree_new();
1228 t2
->node
= LTTV_LOGICAL_NOT
;
1229 t1
->right
= LTTV_TREE_NODE
;
1234 case '(': /* start of parenthesis */
1238 p_nesting
++; /* incrementing parenthesis nesting value */
1239 t1
= lttv_filter_tree_new();
1240 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
1243 case ')': /* end of parenthesis */
1247 p_nesting
--; /* decrementing parenthesis nesting value */
1248 if(p_nesting
<0 || tree_stack
->len
<2) {
1249 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1250 is not valid due to parenthesis incorrect use",filter
->expression
);
1254 /* there must at least be the root tree left in the array */
1255 g_assert(tree_stack
->len
>0);
1257 if(subtree
!= NULL
) { /* append subtree to current tree */
1258 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1259 while(t1
->right
!= LTTV_TREE_IDLE
) {
1260 g_assert(t1
->right
== LTTV_TREE_NODE
);
1263 t1
->right
= LTTV_TREE_NODE
;
1264 t1
->r_child
.t
= subtree
;
1265 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1266 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1267 } else { /* assign subtree as current tree */
1268 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1269 a_field_component
= g_string_new("");
1270 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1271 while(t1
->right
!= LTTV_TREE_IDLE
) {
1272 g_assert(t1
->right
== LTTV_TREE_NODE
);
1273 g_assert(t1
->r_child
.t
!= NULL
);
1276 t1
->right
= LTTV_TREE_LEAF
;
1277 t1
->r_child
.leaf
= a_simple_expression
;
1278 a_simple_expression
= lttv_simple_expression_new();
1279 subtree
= g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1284 * mathematic operators
1286 case '<': /* lower, lower or equal */
1288 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1289 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1290 a_field_component
= g_string_new("");
1291 if(filter
->expression
[i
+1] == '=') { /* <= */
1293 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LE
);
1294 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LT
);
1297 case '>': /* higher, higher or equal */
1299 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1300 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1301 a_field_component
= g_string_new("");
1302 if(filter
->expression
[i
+1] == '=') { /* >= */
1304 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GE
);
1305 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GT
);
1308 case '=': /* equal */
1310 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1311 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1312 a_field_component
= g_string_new("");
1313 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1317 * Field concatening caracter
1322 * divide field expression into elements
1323 * in a_field_path array.
1325 * A dot can also be present in double values
1327 if(a_simple_expression
->field
== LTTV_FILTER_UNDEFINED
) {
1328 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1329 a_field_component
= g_string_new("");
1332 case ' ': /* ignore */
1333 case '\n': /* ignore */
1335 default: /* concatening current string */
1336 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1341 * Preliminary check to see
1342 * if tree was constructed correctly
1345 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1346 is not valid due to parenthesis incorrect use",filter
->expression
);
1350 if(tree_stack
->len
!= 1) /* only root tree should remain */
1353 /* processing last element of expression */
1354 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1355 while(t1
->right
!= LTTV_TREE_IDLE
) {
1356 g_assert(t1
->right
== LTTV_TREE_NODE
);
1359 if(subtree
!= NULL
) { /* add the subtree */
1360 t1
->right
= LTTV_TREE_NODE
;
1361 t1
->r_child
.t
= subtree
;
1363 } else { /* add a leaf */
1364 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1365 a_field_component
= NULL
;
1366 t1
->right
= LTTV_TREE_LEAF
;
1367 t1
->r_child
.leaf
= a_simple_expression
;
1368 a_simple_expression
= NULL
;
1372 /* free the pointer array */
1373 g_assert(a_field_path
->len
== 0);
1374 g_ptr_array_free(a_field_path
,TRUE
);
1376 /* free the tree stack -- but keep the root tree */
1377 filter
->head
= g_ptr_array_remove_index(tree_stack
,0);
1378 g_ptr_array_free(tree_stack
,TRUE
);
1380 /* free the field buffer if allocated */
1381 if(a_field_component
!= NULL
) g_string_free(a_field_component
,TRUE
);
1383 /* free the simple expression buffer if allocated */
1384 if(a_simple_expression
!= NULL
) lttv_simple_expression_destroy(a_simple_expression
);
1386 g_assert(filter
->head
!= NULL
); /* tree should exist */
1387 g_assert(subtree
== NULL
); /* remaining subtree should be included in main tree */
1390 g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1391 lttv_print_tree(filter
->head
) ;
1392 g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1400 * @fn void lttv_filter_destroy(LttvFilter*)
1402 * Destroy the current LttvFilter
1403 * @param filter pointer to the current LttvFilter
1406 lttv_filter_destroy(LttvFilter
* filter
) {
1408 g_free(filter
->expression
);
1409 lttv_filter_tree_destroy(filter
->head
);
1415 * @fn LttvFilterTree* lttv_filter_tree_new()
1417 * Assign a new tree for the current expression
1419 * @return pointer of LttvFilterTree
1422 lttv_filter_tree_new() {
1423 LttvFilterTree
* tree
;
1425 tree
= g_new(LttvFilterTree
,1);
1426 tree
->node
= 0; //g_new(lttv_expression,1);
1427 tree
->left
= LTTV_TREE_IDLE
;
1428 tree
->right
= LTTV_TREE_IDLE
;
1429 tree
->r_child
.t
= NULL
;
1430 tree
->l_child
.t
= NULL
;
1436 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1438 * Append a new expression to the expression
1439 * defined in the current filter
1440 * @param filter pointer to the current LttvFilter
1441 * @param expression string that must be appended
1442 * @return Success/Failure of operation
1444 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, const char *expression
) {
1446 if(expression
== NULL
) return FALSE
;
1447 if(filter
== NULL
) return FALSE
;
1449 GString
* s
= g_string_new("");
1450 if(filter
->expression
!= NULL
) {
1451 g_string_append(s
,filter
->expression
);
1452 g_string_append_c(s
,'&');
1454 g_string_append(s
,expression
);
1456 filter
->expression
= g_string_free(s
,FALSE
);
1458 /* TRUE if construction of tree proceeded without errors */
1459 return lttv_filter_update(filter
);
1464 * @fn void lttv_filter_clear_expression(LttvFilter*)
1466 * Clear the filter expression from the
1467 * current filter and sets its pointer to NULL
1468 * @param filter pointer to the current LttvFilter
1470 void lttv_filter_clear_expression(LttvFilter
* filter
) {
1472 if(filter
->expression
!= NULL
) {
1473 g_free(filter
->expression
);
1474 filter
->expression
= NULL
;
1480 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1482 * Destroys the tree and his sub-trees
1483 * @param tree Tree which must be destroyed
1486 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1488 if(tree
== NULL
) return;
1490 if(tree
->left
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->l_child
.leaf
);
1491 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1493 if(tree
->right
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->r_child
.leaf
);
1494 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1496 // g_free(tree->node);
1501 * Global parsing function for the current
1503 * @param t pointer to the current LttvFilterTree
1504 * @param event current LttEvent, NULL if not used
1505 * @param tracefile current LttTracefile, NULL if not used
1506 * @param trace current LttTrace, NULL if not used
1507 * @param state current LttvProcessState, NULL if not used
1508 * @param context current LttvTracefileContext, NULL if not used
1509 * @return response of filter
1512 lttv_filter_tree_parse(
1513 const LttvFilterTree
* t
,
1514 const LttEvent
* event
,
1515 const LttTracefile
* tracefile
,
1516 const LttTrace
* trace
,
1517 const LttvProcessState
* state
,
1518 const LttvTracefileContext
* context
1523 * Each tree is parsed in inorder.
1524 * This way, it's possible to apply the left filter of the
1525 * tree, then decide whether or not the right branch should
1526 * be parsed depending on the linking logical operator
1528 * Each node consists in a
1529 * 1. logical operator
1530 * 2. left child ( node or simple expression )
1531 * 3. right child ( node or simple expression )
1533 * When the child is a simple expression, we must
1534 * before all determine if the expression refers to
1535 * a structure which is whithin observation ( not NULL ).
1536 * -If so, the expression is evaluated.
1537 * -If not, the result is set to TRUE since this particular
1538 * operation does not interfere with the lttv structure
1540 * The result of each simple expression will directly
1541 * affect the next branch. This way, depending on
1542 * the linking logical operator, the parser will decide
1543 * to explore or not the next branch.
1545 * -If result of left branch is 0 / FALSE
1546 * then don't explore right branch and return 0;
1547 * -If result of left branch is 1 / TRUE then explore
1549 * -If result of left branch is 1 / TRUE
1550 * then don't explore right branch and return 1;
1551 * -If result of left branch is 0 / FALSE then explore
1553 * -Result of left branch will not affect exploration of
1557 gboolean lresult
= FALSE
, rresult
= FALSE
;
1562 if(t
->left
== LTTV_TREE_NODE
) {
1563 lresult
= lttv_filter_tree_parse(t
->l_child
.t
,event
,tracefile
,trace
,state
,context
);
1565 else if(t
->left
== LTTV_TREE_LEAF
) {
1566 lresult
= lttv_filter_tree_parse_branch(t
->l_child
.leaf
,event
,tracefile
,trace
,state
,context
);
1570 * Parse linking operator
1571 * make a cutoff if possible
1573 if((t
->node
& LTTV_LOGICAL_OR
) && lresult
== TRUE
) return TRUE
;
1574 if((t
->node
& LTTV_LOGICAL_AND
) && lresult
== FALSE
) return FALSE
;
1577 * Parse right branch
1579 if(t
->right
== LTTV_TREE_NODE
) {
1580 rresult
= lttv_filter_tree_parse(t
->r_child
.t
,event
,tracefile
,trace
,state
,context
);
1582 else if(t
->right
== LTTV_TREE_LEAF
) {
1583 rresult
= lttv_filter_tree_parse_branch(t
->r_child
.leaf
,event
,tracefile
,trace
,state
,context
);
1587 * Apply and return the
1588 * logical link between the
1592 case LTTV_LOGICAL_OR
: return (lresult
| rresult
);
1593 case LTTV_LOGICAL_AND
: return (lresult
& rresult
);
1594 case LTTV_LOGICAL_NOT
: return (!rresult
);
1595 case LTTV_LOGICAL_XOR
: return (lresult
^ rresult
);
1596 case 0: return (rresult
);
1599 * This case should never be
1600 * parsed, if so, this subtree
1609 * This function parses a particular branch of the tree
1610 * @param se pointer to the current LttvSimpleExpression
1611 * @param event current LttEvent, NULL if not used
1612 * @param tracefile current LttTracefile, NULL if not used
1613 * @param trace current LttTrace, NULL if not used
1614 * @param state current LttvProcessState, NULL if not used
1615 * @param context current LttvTracefileContext, NULL if not used
1616 * @return response of filter
1618 gboolean
lttv_filter_tree_parse_branch(
1619 const LttvSimpleExpression
* se
,
1620 const LttEvent
* event
,
1621 const LttTracefile
* tracefile
,
1622 const LttTrace
* trace
,
1623 const LttvProcessState
* state
,
1624 const LttvTracefileContext
* context
) {
1629 case LTTV_FILTER_TRACE_NAME
:
1630 if(trace
== NULL
) return TRUE
;
1632 char* trace_name
= ltt_trace_name(trace
);
1633 GQuark quark
= g_quark_from_string(trace_name
);
1634 return se
->op((gpointer
)&quark
,v
);
1637 case LTTV_FILTER_TRACEFILE_NAME
:
1638 if(tracefile
== NULL
) return TRUE
;
1640 char* tracefile_name
= ltt_tracefile_name(tracefile
);
1641 GQuark quark
= g_quark_from_string(tracefile_name
);
1642 return se
->op((gpointer
)&quark
,v
);
1645 case LTTV_FILTER_STATE_PID
:
1646 if(state
== NULL
) return TRUE
;
1647 else return se
->op((gpointer
)&state
->pid
,v
);
1649 case LTTV_FILTER_STATE_PPID
:
1650 if(state
== NULL
) return TRUE
;
1651 else return se
->op((gpointer
)&state
->ppid
,v
);
1653 case LTTV_FILTER_STATE_CT
:
1654 if(state
== NULL
) return TRUE
;
1656 return se
->op((gpointer
)&state
->creation_time
,v
);
1659 case LTTV_FILTER_STATE_IT
:
1660 if(state
== NULL
) return TRUE
;
1662 return se
->op((gpointer
)&state
->insertion_time
,v
);
1665 case LTTV_FILTER_STATE_P_NAME
:
1667 * All 'unnamed' for the moment
1669 if(state
== NULL
) return TRUE
;
1671 GQuark quark
= state
->name
;
1672 return se
->op((gpointer
)&quark
,v
);
1675 case LTTV_FILTER_STATE_EX_MODE
:
1676 if(state
== NULL
) return TRUE
;
1677 else return se
->op((gpointer
)&state
->state
->t
,v
);
1679 case LTTV_FILTER_STATE_EX_SUBMODE
:
1680 if(state
== NULL
) return TRUE
;
1681 else return se
->op((gpointer
)&state
->state
->n
,v
);
1683 case LTTV_FILTER_STATE_P_STATUS
:
1684 if(state
== NULL
) return TRUE
;
1685 else return se
->op((gpointer
)&state
->state
->s
,v
);
1687 case LTTV_FILTER_STATE_CPU
:
1688 if(context
== NULL
) return TRUE
;
1690 /* FIXME: not sure of that one */
1691 GQuark quark
= ((LttvTracefileState
*)context
)->cpu_name
;
1692 return se
->op((gpointer
)&quark
,v
);
1695 case LTTV_FILTER_EVENT_NAME
:
1696 if(event
== NULL
) return TRUE
;
1699 et
= ltt_event_eventtype(event
);
1700 char* event_name
= ltt_eventtype_name(et
);
1701 GQuark quark
= g_quark_from_string(event_name
);
1702 return se
->op((gpointer
)&quark
,v
);
1706 case LTTV_FILTER_EVENT_CATEGORY
:
1708 * TODO: Not yet implemented
1712 case LTTV_FILTER_EVENT_TIME
:
1713 if(event
== NULL
) return TRUE
;
1715 LttTime time
= ltt_event_time(event
);
1716 return se
->op((gpointer
)&time
,v
);
1719 case LTTV_FILTER_EVENT_TSC
:
1720 if(event
== NULL
) return TRUE
;
1722 LttCycleCount count
= ltt_event_cycle_count(event
);
1723 return se
->op((gpointer
)&count
,v
);
1726 case LTTV_FILTER_EVENT_FIELD
:
1728 * TODO: Use the offset to
1729 * find the dynamic field
1730 * in the event struct
1735 * This case should never be
1736 * parsed, if so, the whole
1737 * filtering is cancelled
1739 g_warning("Error while parsing the filter tree");
1743 /* should never get here */
1751 * Debug function. Prints tree memory allocation.
1752 * @param t the pointer to the current LttvFilterTree
1755 lttv_print_tree(const LttvFilterTree
* t
) {
1757 g_print("node:%p lchild:%p rchild:%p\n",t
, //t->l_child.t,t->r_child.t);
1758 (t
->left
==LTTV_TREE_NODE
)?t
->l_child
.t
:NULL
,
1759 (t
->right
==LTTV_TREE_NODE
)?t
->r_child
.t
:NULL
);
1760 g_print("node type: %i / [left] %i / [right] %i\n",t
->node
,t
->left
,t
->right
);
1761 if(t
->left
== LTTV_TREE_NODE
) lttv_print_tree(t
->l_child
.t
);
1762 else if(t
->left
== LTTV_TREE_LEAF
) {
1763 g_print("%p: left is %i %p value\n",t
,t
->l_child
.leaf
->field
,t
->l_child
.leaf
->op
);
1765 if(t
->right
== LTTV_TREE_NODE
) lttv_print_tree(t
->r_child
.t
);
1766 else if(t
->right
== LTTV_TREE_LEAF
) {
1767 g_print("%p: right is %i %p value\n",t
,t
->r_child
.leaf
->field
,t
->r_child
.leaf
->op
);
1773 * @fn static void module_init()
1775 * Initializes the filter module and specific values
1777 static void module_init()
1783 * Destroys the filter module and specific values
1785 static void module_destroy()
1791 LTTV_MODULE("filter", "Filters traceset and events", \
1792 "Filters traceset and events specifically to user input", \
1793 module_init
, module_destroy
)