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)
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
:
249 se
->op
= lttv_apply_op_eq_quark
;
252 se
->op
= lttv_apply_op_ne_quark
;
255 g_warning("Error encountered in operator assignment = or != expected");
262 case LTTV_FILTER_STATE_PID
:
263 case LTTV_FILTER_STATE_PPID
:
264 case LTTV_FILTER_STATE_EX_MODE
:
265 case LTTV_FILTER_STATE_EX_SUBMODE
:
266 case LTTV_FILTER_STATE_P_STATUS
:
269 se
->op
= lttv_apply_op_eq_uint64
;
272 se
->op
= lttv_apply_op_ne_uint64
;
275 se
->op
= lttv_apply_op_lt_uint64
;
278 se
->op
= lttv_apply_op_le_uint64
;
281 se
->op
= lttv_apply_op_gt_uint64
;
284 se
->op
= lttv_apply_op_ge_uint64
;
287 g_warning("Error encountered in operator assignment");
294 case LTTV_FILTER_STATE_CT
:
295 case LTTV_FILTER_STATE_IT
:
296 case LTTV_FILTER_EVENT_TIME
:
297 case LTTV_FILTER_EVENT_TSC
:
300 se
->op
= lttv_apply_op_eq_ltttime
;
303 se
->op
= lttv_apply_op_ne_ltttime
;
306 se
->op
= lttv_apply_op_lt_ltttime
;
309 se
->op
= lttv_apply_op_le_ltttime
;
312 se
->op
= lttv_apply_op_gt_ltttime
;
315 se
->op
= lttv_apply_op_ge_ltttime
;
318 g_warning("Error encountered in operator assignment");
323 g_warning("Error encountered in operator assignation ! Field type:%i",se
->field
);
332 * @fn gboolean lttv_simple_expression_assign_value(LttvSimpleExpression*,char*)
334 * Assign the value field to the current LttvSimpleExpression
335 * @param se pointer to the current LttvSimpleExpression
336 * @param value string value for simple expression
338 gboolean
lttv_simple_expression_assign_value(LttvSimpleExpression
* se
, char* value
) {
341 gboolean is_double
= FALSE
;
342 LttTime t
= ltt_time_zero
;
350 case LTTV_FILTER_TRACE_NAME
:
351 case LTTV_FILTER_TRACEFILE_NAME
:
352 case LTTV_FILTER_STATE_P_NAME
:
353 case LTTV_FILTER_EVENT_NAME
:
354 // se->value.v_string = value;
355 se
->value
.v_uint32
= g_quark_to_string(value
);
361 case LTTV_FILTER_STATE_PID
:
362 case LTTV_FILTER_STATE_PPID
:
363 case LTTV_FILTER_STATE_EX_MODE
:
364 case LTTV_FILTER_STATE_EX_SUBMODE
:
365 case LTTV_FILTER_STATE_P_STATUS
:
366 se
->value
.v_uint64
= atoi(value
);
372 case LTTV_FILTER_STATE_CT
:
373 case LTTV_FILTER_STATE_IT
:
374 case LTTV_FILTER_EVENT_TIME
:
375 case LTTV_FILTER_EVENT_TSC
:
376 //se->value.v_double = atof(value);
378 * parsing logic could be optimised,
379 * but as for now, simpler this way
381 v
= g_string_new("");
382 for(i
=0;i
<strlen(value
);i
++) {
383 if(value
[i
] == '.') {
384 /* cannot specify number with more than one '.' */
385 if(is_double
) return FALSE
;
386 else is_double
= TRUE
;
388 g_string_free(v
,TRUE
);
389 v
= g_string_new("");
390 } else g_string_append_c(v
,value
[i
]);
392 /* number can be integer or double */
393 if(is_double
) t
.tv_nsec
= atoi(v
);
394 else t
.tv_sec
= atoi(v
);
396 g_string_free(v
,TRUE
);
398 se
->value
.v_ltttime
= t
;
402 g_warning("Error encountered in value assignation ! Field type = %i",se
->field
);
412 * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*)
414 * Disallocate memory for the current
416 * @param se pointer to the current LttvSimpleExpression
419 lttv_simple_expression_destroy(LttvSimpleExpression
* se
) {
421 // g_free(se->value);
423 case LTTV_FILTER_TRACE_NAME
:
424 case LTTV_FILTER_TRACEFILE_NAME
:
425 case LTTV_FILTER_STATE_P_NAME
:
426 case LTTV_FILTER_EVENT_NAME
:
427 g_free(se
->value
.v_string
);
435 * @fn gint lttv_struct_type(gint)
437 * Finds the structure type depending
438 * on the fields in parameters
439 * @params ft Field of the current structure
440 * @return LttvStructType enum or -1 for error
443 lttv_struct_type(gint ft
) {
446 case LTTV_FILTER_TRACE_NAME
:
447 return LTTV_FILTER_TRACE
;
449 case LTTV_FILTER_TRACEFILE_NAME
:
450 return LTTV_FILTER_TRACEFILE
;
452 case LTTV_FILTER_STATE_PID
:
453 case LTTV_FILTER_STATE_PPID
:
454 case LTTV_FILTER_STATE_CT
:
455 case LTTV_FILTER_STATE_IT
:
456 case LTTV_FILTER_STATE_P_NAME
:
457 case LTTV_FILTER_STATE_EX_MODE
:
458 case LTTV_FILTER_STATE_EX_SUBMODE
:
459 case LTTV_FILTER_STATE_P_STATUS
:
460 case LTTV_FILTER_STATE_CPU
:
461 return LTTV_FILTER_STATE
;
463 case LTTV_FILTER_EVENT_NAME
:
464 case LTTV_FILTER_EVENT_CATEGORY
:
465 case LTTV_FILTER_EVENT_TIME
:
466 case LTTV_FILTER_EVENT_TSC
:
467 case LTTV_FILTER_EVENT_FIELD
:
468 return LTTV_FILTER_EVENT
;
476 * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue)
478 * Applies the 'equal' operator to the
479 * specified structure and value
480 * @param v1 left member of comparison
481 * @param v2 right member of comparison
482 * @return success/failure of operation
484 gboolean
lttv_apply_op_eq_uint64(const gpointer v1
, LttvFieldValue v2
) {
486 guint64
* r
= (guint64
*) v1
;
487 return (*r
== v2
.v_uint64
);
492 * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue)
494 * Applies the 'equal' operator to the
495 * specified structure and value
496 * @param v1 left member of comparison
497 * @param v2 right member of comparison
498 * @return success/failure of operation
500 gboolean
lttv_apply_op_eq_uint32(const gpointer v1
, LttvFieldValue v2
) {
501 guint32
* r
= (guint32
*) v1
;
502 return (*r
== v2
.v_uint32
);
506 * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue)
508 * Applies the 'equal' operator to the
509 * specified structure and value
510 * @param v1 left member of comparison
511 * @param v2 right member of comparison
512 * @return success/failure of operation
514 gboolean
lttv_apply_op_eq_uint16(const gpointer v1
, LttvFieldValue v2
) {
515 guint16
* r
= (guint16
*) v1
;
516 return (*r
== v2
.v_uint16
);
520 * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue)
522 * Applies the 'equal' operator to the
523 * specified structure and value
524 * @param v1 left member of comparison
525 * @param v2 right member of comparison
526 * @return success/failure of operation
528 gboolean
lttv_apply_op_eq_double(const gpointer v1
, LttvFieldValue v2
) {
529 double* r
= (double*) v1
;
530 return (*r
== v2
.v_double
);
534 * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue)
536 * Applies the 'equal' operator to the
537 * specified structure and value
538 * @param v1 left member of comparison
539 * @param v2 right member of comparison
540 * @return success/failure of operation
542 gboolean
lttv_apply_op_eq_string(const gpointer v1
, LttvFieldValue v2
) {
543 char* r
= (char*) v1
;
544 return (!g_strcasecmp(r
,v2
.v_string
));
548 * @fn gboolean lttv_apply_op_eq_quark(gpointer,LttvFieldValue)
550 * Applies the 'equal' operator to the
551 * specified structure and value
552 * @param v1 left member of comparison
553 * @param v2 right member of comparison
554 * @return success/failure of operation
556 gboolean
lttv_apply_op_eq_quark(const gpointer v1
, LttvFieldValue v2
) {
557 GQuark
* r
= (GQuark
*) v1
;
558 g_print("v1:%i v2:%i\n",*r
,v2
.v_uint32
);
559 return (*r
== v2
.v_uint32
);
563 * @fn gboolean lttv_apply_op_eq_ltttime(gpointer,LttvFieldValue)
565 * Applies the 'equal' operator to the
566 * specified structure and value
567 * @param v1 left member of comparison
568 * @param v2 right member of comparison
569 * @return success/failure of operation
571 gboolean
lttv_apply_op_eq_ltttime(const gpointer v1
, LttvFieldValue v2
) {
572 LttTime
* r
= (LttTime
*) v1
;
573 // return ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec == v2.v_ltttime.tv_nsec));
574 return ltt_time_compare(*r
, v2
.v_ltttime
)==0?1:0;
579 * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue)
581 * Applies the 'not equal' operator to the
582 * specified structure and value
583 * @param v1 left member of comparison
584 * @param v2 right member of comparison
585 * @return success/failure of operation
587 gboolean
lttv_apply_op_ne_uint64(const gpointer v1
, LttvFieldValue v2
) {
588 guint64
* r
= (guint64
*) v1
;
589 return (*r
!= v2
.v_uint64
);
593 * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue)
595 * Applies the 'not equal' operator to the
596 * specified structure and value
597 * @param v1 left member of comparison
598 * @param v2 right member of comparison
599 * @return success/failure of operation
601 gboolean
lttv_apply_op_ne_uint32(const gpointer v1
, LttvFieldValue v2
) {
602 guint32
* r
= (guint32
*) v1
;
603 return (*r
!= v2
.v_uint32
);
607 * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue)
609 * Applies the 'not equal' operator to the
610 * specified structure and value
611 * @param v1 left member of comparison
612 * @param v2 right member of comparison
613 * @return success/failure of operation
615 gboolean
lttv_apply_op_ne_uint16(const gpointer v1
, LttvFieldValue v2
) {
616 guint16
* r
= (guint16
*) v1
;
617 return (*r
!= v2
.v_uint16
);
621 * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue)
623 * Applies the 'not equal' operator to the
624 * specified structure and value
625 * @param v1 left member of comparison
626 * @param v2 right member of comparison
627 * @return success/failure of operation
629 gboolean
lttv_apply_op_ne_double(const gpointer v1
, LttvFieldValue v2
) {
630 double* r
= (double*) v1
;
631 return (*r
!= v2
.v_double
);
635 * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue)
637 * Applies the 'not equal' operator to the
638 * specified structure and value
639 * @param v1 left member of comparison
640 * @param v2 right member of comparison
641 * @return success/failure of operation
643 gboolean
lttv_apply_op_ne_string(const gpointer v1
, LttvFieldValue v2
) {
644 char* r
= (char*) v1
;
645 return (g_strcasecmp(r
,v2
.v_string
));
649 * @fn gboolean lttv_apply_op_ne_quark(gpointer,LttvFieldValue)
651 * Applies the 'not equal' operator to the
652 * specified structure and value
653 * @param v1 left member of comparison
654 * @param v2 right member of comparison
655 * @return success/failure of operation
657 gboolean
lttv_apply_op_ne_quark(const gpointer v1
, LttvFieldValue v2
) {
658 GQuark
* r
= (GQuark
*) v1
;
659 return (*r
!= v2
.v_uint32
);
664 * @fn gboolean lttv_apply_op_ne_ltttime(gpointer,LttvFieldValue)
666 * Applies the 'not equal' operator to the
667 * specified structure and value
668 * @param v1 left member of comparison
669 * @param v2 right member of comparison
670 * @return success/failure of operation
672 gboolean
lttv_apply_op_ne_ltttime(const gpointer v1
, LttvFieldValue v2
) {
673 LttTime
* r
= (LttTime
*) v1
;
674 return ltt_time_compare(*r
, v2
.v_ltttime
)!=0?1:0;
679 * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue)
681 * Applies the 'lower than' operator to the
682 * specified structure and value
683 * @param v1 left member of comparison
684 * @param v2 right member of comparison
685 * @return success/failure of operation
687 gboolean
lttv_apply_op_lt_uint64(const gpointer v1
, LttvFieldValue v2
) {
688 guint64
* r
= (guint64
*) v1
;
689 return (*r
< v2
.v_uint64
);
693 * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue)
695 * Applies the 'lower than' operator to the
696 * specified structure and value
697 * @param v1 left member of comparison
698 * @param v2 right member of comparison
699 * @return success/failure of operation
701 gboolean
lttv_apply_op_lt_uint32(const gpointer v1
, LttvFieldValue v2
) {
702 guint32
* r
= (guint32
*) v1
;
703 return (*r
< v2
.v_uint32
);
707 * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue)
709 * Applies the 'lower than' operator to the
710 * specified structure and value
711 * @param v1 left member of comparison
712 * @param v2 right member of comparison
713 * @return success/failure of operation
715 gboolean
lttv_apply_op_lt_uint16(const gpointer v1
, LttvFieldValue v2
) {
716 guint16
* r
= (guint16
*) v1
;
717 return (*r
< v2
.v_uint16
);
721 * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue)
723 * Applies the 'lower than' operator to the
724 * specified structure and value
725 * @param v1 left member of comparison
726 * @param v2 right member of comparison
727 * @return success/failure of operation
729 gboolean
lttv_apply_op_lt_double(const gpointer v1
, LttvFieldValue v2
) {
730 double* r
= (double*) v1
;
731 return (*r
< v2
.v_double
);
735 * @fn gboolean lttv_apply_op_lt_ltttime(gpointer,LttvFieldValue)
737 * Applies the 'lower than' operator to the
738 * specified structure and value
739 * @param v1 left member of comparison
740 * @param v2 right member of comparison
741 * @return success/failure of operation
743 gboolean
lttv_apply_op_lt_ltttime(const gpointer v1
, LttvFieldValue v2
) {
744 LttTime
* r
= (LttTime
*) v1
;
745 // 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)));
746 return ltt_time_compare(*r
, v2
.v_ltttime
)==-1?1:0;
751 * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue)
753 * Applies the 'lower or equal' operator to the
754 * specified structure and value
755 * @param v1 left member of comparison
756 * @param v2 right member of comparison
757 * @return success/failure of operation
759 gboolean
lttv_apply_op_le_uint64(const gpointer v1
, LttvFieldValue v2
) {
760 guint64
* r
= (guint64
*) v1
;
761 return (*r
<= v2
.v_uint64
);
765 * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue)
767 * Applies the 'lower or equal' operator to the
768 * specified structure and value
769 * @param v1 left member of comparison
770 * @param v2 right member of comparison
771 * @return success/failure of operation
773 gboolean
lttv_apply_op_le_uint32(const gpointer v1
, LttvFieldValue v2
) {
774 guint32
* r
= (guint32
*) v1
;
775 return (*r
<= v2
.v_uint32
);
779 * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue)
781 * Applies the 'lower or equal' operator to the
782 * specified structure and value
783 * @param v1 left member of comparison
784 * @param v2 right member of comparison
785 * @return success/failure of operation
787 gboolean
lttv_apply_op_le_uint16(const gpointer v1
, LttvFieldValue v2
) {
788 guint16
* r
= (guint16
*) v1
;
789 return (*r
<= v2
.v_uint16
);
793 * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue)
795 * Applies the 'lower or equal' operator to the
796 * specified structure and value
797 * @param v1 left member of comparison
798 * @param v2 right member of comparison
799 * @return success/failure of operation
801 gboolean
lttv_apply_op_le_double(const gpointer v1
, LttvFieldValue v2
) {
802 double* r
= (double*) v1
;
803 return (*r
<= v2
.v_double
);
807 * @fn gboolean lttv_apply_op_le_ltttime(gpointer,LttvFieldValue)
809 * Applies the 'lower or equal' operator to the
810 * specified structure and value
811 * @param v1 left member of comparison
812 * @param v2 right member of comparison
813 * @return success/failure of operation
815 gboolean
lttv_apply_op_le_ltttime(const gpointer v1
, LttvFieldValue v2
) {
816 LttTime
* r
= (LttTime
*) v1
;
817 // 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)));
818 return ltt_time_compare(*r
, v2
.v_ltttime
)<1?1:0;
823 * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue)
825 * Applies the 'greater than' operator to the
826 * specified structure and value
827 * @param v1 left member of comparison
828 * @param v2 right member of comparison
829 * @return success/failure of operation
831 gboolean
lttv_apply_op_gt_uint64(const gpointer v1
, LttvFieldValue v2
) {
832 guint64
* r
= (guint64
*) v1
;
833 return (*r
> v2
.v_uint64
);
837 * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue)
839 * Applies the 'greater than' operator to the
840 * specified structure and value
841 * @param v1 left member of comparison
842 * @param v2 right member of comparison
843 * @return success/failure of operation
845 gboolean
lttv_apply_op_gt_uint32(const gpointer v1
, LttvFieldValue v2
) {
846 guint32
* r
= (guint32
*) v1
;
847 return (*r
> v2
.v_uint32
);
851 * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue)
853 * Applies the 'greater than' operator to the
854 * specified structure and value
855 * @param v1 left member of comparison
856 * @param v2 right member of comparison
857 * @return success/failure of operation
859 gboolean
lttv_apply_op_gt_uint16(const gpointer v1
, LttvFieldValue v2
) {
860 guint16
* r
= (guint16
*) v1
;
861 return (*r
> v2
.v_uint16
);
865 * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue)
867 * Applies the 'greater than' operator to the
868 * specified structure and value
869 * @param v1 left member of comparison
870 * @param v2 right member of comparison
871 * @return success/failure of operation
873 gboolean
lttv_apply_op_gt_double(const gpointer v1
, LttvFieldValue v2
) {
874 double* r
= (double*) v1
;
875 return (*r
> v2
.v_double
);
879 * @fn gboolean lttv_apply_op_gt_ltttime(gpointer,LttvFieldValue)
881 * Applies the 'greater than' operator to the
882 * specified structure and value
883 * @param v1 left member of comparison
884 * @param v2 right member of comparison
885 * @return success/failure of operation
887 gboolean
lttv_apply_op_gt_ltttime(const gpointer v1
, LttvFieldValue v2
) {
888 LttTime
* r
= (LttTime
*) v1
;
889 // 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)));
890 return ltt_time_compare(*r
, v2
.v_ltttime
)==1?1:0;
895 * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue)
897 * Applies the 'greater or equal' operator to the
898 * specified structure and value
899 * @param v1 left member of comparison
900 * @param v2 right member of comparison
901 * @return success/failure of operation
903 gboolean
lttv_apply_op_ge_uint64(const gpointer v1
, LttvFieldValue v2
) {
904 guint64
* r
= (guint64
*) v1
;
905 return (*r
>= v2
.v_uint64
);
909 * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue)
911 * Applies the 'greater or equal' operator to the
912 * specified structure and value
913 * @param v1 left member of comparison
914 * @param v2 right member of comparison
915 * @return success/failure of operation
917 gboolean
lttv_apply_op_ge_uint32(const gpointer v1
, LttvFieldValue v2
) {
918 guint32
* r
= (guint32
*) v1
;
919 return (*r
>= v2
.v_uint32
);
923 * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue)
925 * Applies the 'greater or equal' operator to the
926 * specified structure and value
927 * @param v1 left member of comparison
928 * @param v2 right member of comparison
929 * @return success/failure of operation
931 gboolean
lttv_apply_op_ge_uint16(const gpointer v1
, LttvFieldValue v2
) {
932 guint16
* r
= (guint16
*) v1
;
933 return (*r
>= v2
.v_uint16
);
937 * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue)
939 * Applies the 'greater or equal' operator to the
940 * specified structure and value
941 * @param v1 left member of comparison
942 * @param v2 right member of comparison
943 * @return success/failure of operation
945 gboolean
lttv_apply_op_ge_double(const gpointer v1
, LttvFieldValue v2
) {
946 double* r
= (double*) v1
;
947 return (*r
>= v2
.v_double
);
951 * @fn gboolean lttv_apply_op_ge_ltttime(gpointer,LttvFieldValue)
953 * Applies the 'greater or equal' operator to the
954 * specified structure and value
955 * @param v1 left member of comparison
956 * @param v2 right member of comparison
957 * @return success/failure of operation
959 gboolean
lttv_apply_op_ge_ltttime(const gpointer v1
, LttvFieldValue v2
) {
960 LttTime
* r
= (LttTime
*) v1
;
961 // 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)));
962 return ltt_time_compare(*r
, v2
.v_ltttime
)>-1?1:0;
968 * Makes a copy of the current filter tree
969 * @param tree pointer to the current tree
970 * @return new copy of the filter tree
973 lttv_filter_tree_clone(const LttvFilterTree
* tree
) {
975 LttvFilterTree
* newtree
= lttv_filter_tree_new();
977 newtree
->node
= tree
->node
;
979 newtree
->left
= tree
->left
;
980 if(newtree
->left
== LTTV_TREE_NODE
) {
981 newtree
->l_child
.t
= lttv_filter_tree_clone(tree
->l_child
.t
);
982 } else if(newtree
->left
== LTTV_TREE_LEAF
) {
983 newtree
->l_child
.leaf
= lttv_simple_expression_new();
984 newtree
->l_child
.leaf
->field
= tree
->l_child
.leaf
->field
;
985 newtree
->l_child
.leaf
->offset
= tree
->l_child
.leaf
->offset
;
986 newtree
->l_child
.leaf
->op
= tree
->l_child
.leaf
->op
;
987 /* FIXME: special case for string copy ! */
988 newtree
->l_child
.leaf
->value
= tree
->l_child
.leaf
->value
;
991 newtree
->right
= tree
->right
;
992 if(newtree
->right
== LTTV_TREE_NODE
) {
993 newtree
->r_child
.t
= lttv_filter_tree_clone(tree
->r_child
.t
);
994 } else if(newtree
->right
== LTTV_TREE_LEAF
) {
995 newtree
->r_child
.leaf
= lttv_simple_expression_new();
996 newtree
->r_child
.leaf
->field
= tree
->r_child
.leaf
->field
;
997 newtree
->r_child
.leaf
->offset
= tree
->r_child
.leaf
->offset
;
998 newtree
->r_child
.leaf
->op
= tree
->r_child
.leaf
->op
;
999 newtree
->r_child
.leaf
->value
= tree
->r_child
.leaf
->value
;
1007 * Makes a copy of the current filter
1008 * @param filter pointer to the current filter
1009 * @return new copy of the filter
1012 lttv_filter_clone(const LttvFilter
* filter
) {
1014 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
1016 strcpy(newfilter
->expression
,filter
->expression
);
1018 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
1026 * @fn LttvFilter* lttv_filter_new()
1028 * Creates a new LttvFilter
1029 * @return the current LttvFilter or NULL if error
1034 LttvFilter
* filter
= g_new(LttvFilter
,1);
1035 filter
->expression
= NULL
;
1036 filter
->head
= NULL
;
1043 * @fn gboolean lttv_filter_update(LttvFilter*)
1045 * Updates the current LttvFilter by building
1046 * its tree based upon the expression string
1047 * @param filter pointer to the current LttvFilter
1048 * @return Failure/Success of operation
1051 lttv_filter_update(LttvFilter
* filter
) {
1053 // g_print("filter::lttv_filter_new()\n"); /* debug */
1055 if(filter
->expression
== NULL
) return FALSE
;
1059 p_nesting
=0; /* parenthesis nesting value */
1063 *tree
= lttv_filter_tree_new(), /* main tree */
1064 *subtree
= NULL
, /* buffer for subtrees */
1065 *t1
, /* buffer #1 */
1066 *t2
; /* buffer #2 */
1070 * If the tree already exists,
1071 * destroy it and build a new one
1073 if(filter
->head
!= NULL
) lttv_filter_tree_destroy(filter
->head
);
1074 filter
->head
= NULL
; /* will be assigned at the end */
1078 * each element of the list
1079 * is a sub tree created
1080 * by the use of parenthesis in the
1081 * global expression. The final tree
1082 * will be the one left at the root of
1085 GPtrArray
*tree_stack
= g_ptr_array_new();
1086 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
1088 /* temporary values */
1089 GString
*a_field_component
= g_string_new("");
1090 GPtrArray
*a_field_path
= g_ptr_array_new();
1092 /* simple expression buffer */
1093 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
1096 * Parse entire expression and construct
1097 * the binary tree. There are two steps
1098 * in browsing that string
1099 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
1100 * 2. finding simple expressions
1101 * - field path ( separated by dots )
1102 * - op ( >, <, =, >=, <=, !=)
1103 * - value ( integer, string ... )
1104 * To spare computing time, the whole
1105 * string is parsed in this loop for a
1106 * O(n) complexity order.
1108 * When encountering logical op &,|,^
1109 * 1. parse the last value if any
1110 * 2. create a new tree
1111 * 3. add the expression (simple exp, or exp (subtree)) to the tree
1112 * 4. concatenate this tree with the current tree on top of the stack
1113 * When encountering math ops >,>=,<,<=,=,!=
1114 * 1. add to op to the simple expression
1115 * 2. concatenate last field component to field path
1116 * When encountering concatening ops .
1117 * 1. concatenate last field component to field path
1118 * When encountering opening parenthesis (,{,[
1119 * 1. create a new subtree on top of tree stack
1120 * When encountering closing parenthesis ),},]
1121 * 1. add the expression on right child of the current tree
1122 * 2. the subtree is completed, allocate a new subtree
1123 * 3. pop the tree value from the tree stack
1126 for(i
=0;i
<strlen(filter
->expression
);i
++) {
1128 //g_print("%c ",filter->expression[i]);
1130 switch(filter
->expression
[i
]) {
1136 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1137 while(t1
->right
!= LTTV_TREE_IDLE
) {
1138 g_assert(t1
->right
== LTTV_TREE_NODE
);
1141 t2
= lttv_filter_tree_new();
1142 t2
->node
= LTTV_LOGICAL_AND
;
1143 if(subtree
!= NULL
) { /* append subtree to current tree */
1144 t2
->left
= LTTV_TREE_NODE
;
1145 t2
->l_child
.t
= subtree
;
1147 t1
->right
= LTTV_TREE_NODE
;
1149 } else { /* append a simple expression */
1150 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1151 a_field_component
= g_string_new("");
1152 t2
->left
= LTTV_TREE_LEAF
;
1153 t2
->l_child
.leaf
= a_simple_expression
;
1154 a_simple_expression
= lttv_simple_expression_new();
1155 t1
->right
= LTTV_TREE_NODE
;
1162 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1163 while(t1
->right
!= LTTV_TREE_IDLE
) {
1164 g_assert(t1
->right
== LTTV_TREE_NODE
);
1167 t2
= lttv_filter_tree_new();
1168 t2
->node
= LTTV_LOGICAL_OR
;
1169 if(subtree
!= NULL
) { /* append subtree to current tree */
1170 t2
->left
= LTTV_TREE_NODE
;
1171 t2
->l_child
.t
= subtree
;
1173 t1
->right
= LTTV_TREE_NODE
;
1175 } else { /* append a simple expression */
1176 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1177 a_field_component
= g_string_new("");
1178 t2
->left
= LTTV_TREE_LEAF
;
1179 t2
->l_child
.leaf
= a_simple_expression
;
1180 a_simple_expression
= lttv_simple_expression_new();
1181 t1
->right
= LTTV_TREE_NODE
;
1188 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1189 while(t1
->right
!= LTTV_TREE_IDLE
) {
1190 g_assert(t1
->right
== LTTV_TREE_NODE
);
1193 t2
= lttv_filter_tree_new();
1194 t2
->node
= LTTV_LOGICAL_XOR
;
1195 if(subtree
!= NULL
) { /* append subtree to current tree */
1196 t2
->left
= LTTV_TREE_NODE
;
1197 t2
->l_child
.t
= subtree
;
1199 t1
->right
= LTTV_TREE_NODE
;
1201 } else { /* append a simple expression */
1202 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1203 a_field_component
= g_string_new("");
1204 t2
->left
= LTTV_TREE_LEAF
;
1205 t2
->l_child
.leaf
= a_simple_expression
;
1206 a_simple_expression
= lttv_simple_expression_new();
1207 t1
->right
= LTTV_TREE_NODE
;
1212 case '!': /* not, or not equal (math op) */
1214 if(filter
->expression
[i
+1] == '=') { /* != */
1215 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1216 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1217 a_field_component
= g_string_new("");
1218 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_NE
);
1221 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1222 while(t1
->right
!= LTTV_TREE_IDLE
) {
1223 g_assert(t1
->right
== LTTV_TREE_NODE
);
1226 t2
= lttv_filter_tree_new();
1227 t2
->node
= LTTV_LOGICAL_NOT
;
1228 t1
->right
= LTTV_TREE_NODE
;
1233 case '(': /* start of parenthesis */
1237 p_nesting
++; /* incrementing parenthesis nesting value */
1238 t1
= lttv_filter_tree_new();
1239 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
1242 case ')': /* end of parenthesis */
1246 p_nesting
--; /* decrementing parenthesis nesting value */
1247 if(p_nesting
<0 || tree_stack
->len
<2) {
1248 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1249 is not valid due to parenthesis incorrect use",filter
->expression
);
1253 /* there must at least be the root tree left in the array */
1254 g_assert(tree_stack
->len
>0);
1256 if(subtree
!= NULL
) { /* append subtree to current tree */
1257 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1258 while(t1
->right
!= LTTV_TREE_IDLE
) {
1259 g_assert(t1
->right
== LTTV_TREE_NODE
);
1262 t1
->right
= LTTV_TREE_NODE
;
1263 t1
->r_child
.t
= subtree
;
1264 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1265 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1266 } else { /* assign subtree as current tree */
1267 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1268 a_field_component
= g_string_new("");
1269 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1270 while(t1
->right
!= LTTV_TREE_IDLE
) {
1271 g_assert(t1
->right
== LTTV_TREE_NODE
);
1272 g_assert(t1
->r_child
.t
!= NULL
);
1275 t1
->right
= LTTV_TREE_LEAF
;
1276 t1
->r_child
.leaf
= a_simple_expression
;
1277 a_simple_expression
= lttv_simple_expression_new();
1278 subtree
= g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1283 * mathematic operators
1285 case '<': /* lower, lower or equal */
1287 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1288 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1289 a_field_component
= g_string_new("");
1290 if(filter
->expression
[i
+1] == '=') { /* <= */
1292 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LE
);
1293 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LT
);
1296 case '>': /* higher, higher or equal */
1298 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1299 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1300 a_field_component
= g_string_new("");
1301 if(filter
->expression
[i
+1] == '=') { /* >= */
1303 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GE
);
1304 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GT
);
1307 case '=': /* equal */
1309 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1310 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1311 a_field_component
= g_string_new("");
1312 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1316 * Field concatening caracter
1321 * divide field expression into elements
1322 * in a_field_path array.
1324 * A dot can also be present in double values
1326 if(a_simple_expression
->field
== LTTV_FILTER_UNDEFINED
) {
1327 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1328 a_field_component
= g_string_new("");
1331 case ' ': /* ignore */
1332 case '\n': /* ignore */
1334 default: /* concatening current string */
1335 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1340 * Preliminary check to see
1341 * if tree was constructed correctly
1344 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1345 is not valid due to parenthesis incorrect use",filter
->expression
);
1349 if(tree_stack
->len
!= 1) /* only root tree should remain */
1352 /* processing last element of expression */
1353 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1354 while(t1
->right
!= LTTV_TREE_IDLE
) {
1355 g_assert(t1
->right
== LTTV_TREE_NODE
);
1358 if(subtree
!= NULL
) { /* add the subtree */
1359 t1
->right
= LTTV_TREE_NODE
;
1360 t1
->r_child
.t
= subtree
;
1362 } else { /* add a leaf */
1363 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1364 a_field_component
= NULL
;
1365 t1
->right
= LTTV_TREE_LEAF
;
1366 t1
->r_child
.leaf
= a_simple_expression
;
1367 a_simple_expression
= NULL
;
1371 /* free the pointer array */
1372 g_assert(a_field_path
->len
== 0);
1373 g_ptr_array_free(a_field_path
,TRUE
);
1375 /* free the tree stack -- but keep the root tree */
1376 filter
->head
= g_ptr_array_remove_index(tree_stack
,0);
1377 g_ptr_array_free(tree_stack
,TRUE
);
1379 /* free the field buffer if allocated */
1380 if(a_field_component
!= NULL
) g_string_free(a_field_component
,TRUE
);
1382 /* free the simple expression buffer if allocated */
1383 if(a_simple_expression
!= NULL
) lttv_simple_expression_destroy(a_simple_expression
);
1385 g_assert(filter
->head
!= NULL
); /* tree should exist */
1386 g_assert(subtree
== NULL
); /* remaining subtree should be included in main tree */
1389 g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1390 lttv_print_tree(filter
->head
) ;
1391 g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1399 * @fn void lttv_filter_destroy(LttvFilter*)
1401 * Destroy the current LttvFilter
1402 * @param filter pointer to the current LttvFilter
1405 lttv_filter_destroy(LttvFilter
* filter
) {
1407 g_free(filter
->expression
);
1408 lttv_filter_tree_destroy(filter
->head
);
1414 * @fn LttvFilterTree* lttv_filter_tree_new()
1416 * Assign a new tree for the current expression
1418 * @return pointer of LttvFilterTree
1421 lttv_filter_tree_new() {
1422 LttvFilterTree
* tree
;
1424 tree
= g_new(LttvFilterTree
,1);
1425 tree
->node
= 0; //g_new(lttv_expression,1);
1426 tree
->left
= LTTV_TREE_IDLE
;
1427 tree
->right
= LTTV_TREE_IDLE
;
1428 tree
->r_child
.t
= NULL
;
1429 tree
->l_child
.t
= NULL
;
1435 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1437 * Append a new expression to the expression
1438 * defined in the current filter
1439 * @param filter pointer to the current LttvFilter
1440 * @param expression string that must be appended
1441 * @return Success/Failure of operation
1443 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, const char *expression
) {
1445 if(expression
== NULL
) return FALSE
;
1446 if(filter
== NULL
) return FALSE
;
1448 GString
* s
= g_string_new("");
1449 if(filter
->expression
!= NULL
) {
1450 g_string_append(s
,filter
->expression
);
1451 g_string_append_c(s
,'&');
1453 g_string_append(s
,expression
);
1455 filter
->expression
= g_string_free(s
,FALSE
);
1457 /* TRUE if construction of tree proceeded without errors */
1458 return lttv_filter_update(filter
);
1463 * @fn void lttv_filter_clear_expression(LttvFilter*)
1465 * Clear the filter expression from the
1466 * current filter and sets its pointer to NULL
1467 * @param filter pointer to the current LttvFilter
1469 void lttv_filter_clear_expression(LttvFilter
* filter
) {
1471 if(filter
->expression
!= NULL
) {
1472 g_free(filter
->expression
);
1473 filter
->expression
= NULL
;
1479 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1481 * Destroys the tree and his sub-trees
1482 * @param tree Tree which must be destroyed
1485 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1487 if(tree
== NULL
) return;
1489 if(tree
->left
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->l_child
.leaf
);
1490 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1492 if(tree
->right
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->r_child
.leaf
);
1493 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1495 // g_free(tree->node);
1500 * Global parsing function for the current
1502 * @param t pointer to the current LttvFilterTree
1503 * @param event current LttEvent, NULL if not used
1504 * @param tracefile current LttTracefile, NULL if not used
1505 * @param trace current LttTrace, NULL if not used
1506 * @param state current LttvProcessState, NULL if not used
1507 * @param context current LttvTracefileContext, NULL if not used
1508 * @return response of filter
1511 lttv_filter_tree_parse(
1512 const LttvFilterTree
* t
,
1513 const LttEvent
* event
,
1514 const LttTracefile
* tracefile
,
1515 const LttTrace
* trace
,
1516 const LttvProcessState
* state
,
1517 const LttvTracefileContext
* context
1522 * Each tree is parsed in inorder.
1523 * This way, it's possible to apply the left filter of the
1524 * tree, then decide whether or not the right branch should
1525 * be parsed depending on the linking logical operator
1527 * Each node consists in a
1528 * 1. logical operator
1529 * 2. left child ( node or simple expression )
1530 * 3. right child ( node or simple expression )
1532 * When the child is a simple expression, we must
1533 * before all determine if the expression refers to
1534 * a structure which is whithin observation ( not NULL ).
1535 * -If so, the expression is evaluated.
1536 * -If not, the result is set to TRUE since this particular
1537 * operation does not interfere with the lttv structure
1539 * The result of each simple expression will directly
1540 * affect the next branch. This way, depending on
1541 * the linking logical operator, the parser will decide
1542 * to explore or not the next branch.
1544 * -If result of left branch is 0 / FALSE
1545 * then don't explore right branch and return 0;
1546 * -If result of left branch is 1 / TRUE then explore
1548 * -If result of left branch is 1 / TRUE
1549 * then don't explore right branch and return 1;
1550 * -If result of left branch is 0 / FALSE then explore
1552 * -Result of left branch will not affect exploration of
1556 gboolean lresult
= FALSE
, rresult
= FALSE
;
1561 if(t
->left
== LTTV_TREE_NODE
) {
1562 lresult
= lttv_filter_tree_parse(t
->l_child
.t
,event
,tracefile
,trace
,state
,context
);
1564 else if(t
->left
== LTTV_TREE_LEAF
) {
1565 lresult
= lttv_filter_tree_parse_branch(t
->l_child
.leaf
,event
,tracefile
,trace
,state
,context
);
1569 * Parse linking operator
1570 * make a cutoff if possible
1572 if((t
->node
& LTTV_LOGICAL_OR
) && lresult
== TRUE
) return TRUE
;
1573 if((t
->node
& LTTV_LOGICAL_AND
) && lresult
== FALSE
) return FALSE
;
1576 * Parse right branch
1578 if(t
->right
== LTTV_TREE_NODE
) {
1579 rresult
= lttv_filter_tree_parse(t
->r_child
.t
,event
,tracefile
,trace
,state
,context
);
1581 else if(t
->right
== LTTV_TREE_LEAF
) {
1582 rresult
= lttv_filter_tree_parse_branch(t
->r_child
.leaf
,event
,tracefile
,trace
,state
,context
);
1586 * Apply and return the
1587 * logical link between the
1591 case LTTV_LOGICAL_OR
: return (lresult
| rresult
);
1592 case LTTV_LOGICAL_AND
: return (lresult
& rresult
);
1593 case LTTV_LOGICAL_NOT
: return (!rresult
);
1594 case LTTV_LOGICAL_XOR
: return (lresult
^ rresult
);
1595 case 0: return (rresult
);
1598 * This case should never be
1599 * parsed, if so, this subtree
1608 * This function parses a particular branch of the tree
1609 * @param se pointer to the current LttvSimpleExpression
1610 * @param event current LttEvent, NULL if not used
1611 * @param tracefile current LttTracefile, NULL if not used
1612 * @param trace current LttTrace, NULL if not used
1613 * @param state current LttvProcessState, NULL if not used
1614 * @param context current LttvTracefileContext, NULL if not used
1615 * @return response of filter
1617 gboolean
lttv_filter_tree_parse_branch(
1618 const LttvSimpleExpression
* se
,
1619 const LttEvent
* event
,
1620 const LttTracefile
* tracefile
,
1621 const LttTrace
* trace
,
1622 const LttvProcessState
* state
,
1623 const LttvTracefileContext
* context
) {
1628 case LTTV_FILTER_TRACE_NAME
:
1629 if(trace
== NULL
) return TRUE
;
1631 GQuark quark
= g_quark_to_string(ltt_trace_name(trace
));
1632 return se
->op((gpointer
)&quark
,v
);
1635 case LTTV_FILTER_TRACEFILE_NAME
:
1636 if(tracefile
== NULL
) return TRUE
;
1638 GQuark quark
= g_quark_to_string(ltt_tracefile_name(tracefile
));
1639 return se
->op((gpointer
)&quark
,v
);
1642 case LTTV_FILTER_STATE_PID
:
1643 if(state
== NULL
) return TRUE
;
1644 else return se
->op((gpointer
)&state
->pid
,v
);
1646 case LTTV_FILTER_STATE_PPID
:
1647 if(state
== NULL
) return TRUE
;
1648 else return se
->op((gpointer
)&state
->ppid
,v
);
1650 case LTTV_FILTER_STATE_CT
:
1651 if(state
== NULL
) return TRUE
;
1653 return se
->op((gpointer
)&state
->creation_time
,v
);
1656 case LTTV_FILTER_STATE_IT
:
1657 if(state
== NULL
) return TRUE
;
1659 return se
->op((gpointer
)&state
->insertion_time
,v
);
1662 case LTTV_FILTER_STATE_P_NAME
:
1664 * All 'unnamed' for the moment
1666 if(state
== NULL
) return TRUE
;
1668 GQuark quark
= g_quark_to_string(state
->name
);
1669 return se
->op((gpointer
)&quark
,v
);
1672 case LTTV_FILTER_STATE_EX_MODE
:
1673 if(state
== NULL
) return TRUE
;
1674 else return se
->op((gpointer
)&state
->state
->t
,v
);
1676 case LTTV_FILTER_STATE_EX_SUBMODE
:
1677 if(state
== NULL
) return TRUE
;
1678 else return se
->op((gpointer
)&state
->state
->n
,v
);
1680 case LTTV_FILTER_STATE_P_STATUS
:
1681 if(state
== NULL
) return TRUE
;
1682 else return se
->op((gpointer
)&state
->state
->s
,v
);
1684 case LTTV_FILTER_STATE_CPU
:
1685 if(context
== NULL
) return TRUE
;
1687 /* FIXME: not sure of that one */
1688 return se
->op((gpointer
)g_quark_to_string(((LttvTracefileState
*)context
)->cpu_name
),v
);
1691 case LTTV_FILTER_EVENT_NAME
:
1692 if(event
== NULL
) return TRUE
;
1695 et
= ltt_event_eventtype(event
);
1696 g_print("v:%s\n",ltt_eventtype_name(et
));
1697 GQuark quark
= g_quark_to_string(ltt_eventtype_name(et
));
1698 return se
->op((gpointer
)&quark
,v
);
1702 case LTTV_FILTER_EVENT_CATEGORY
:
1704 * TODO: Not yet implemented
1708 case LTTV_FILTER_EVENT_TIME
:
1709 if(event
== NULL
) return TRUE
;
1711 LttTime time
= ltt_event_time(event
);
1712 return se
->op((gpointer
)&time
,v
);
1715 case LTTV_FILTER_EVENT_TSC
:
1716 // if(event == NULL) return TRUE;
1718 // double val = ltt_time_to_double(event->event_time);
1719 // return se->op((gpointer)&val,v);
1722 * FIXME: Where is event.tsc
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
)