1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2005 Michel Dagenais
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 simple expr [ op expr ]
26 read_simple_expression
27 read_field_path [ rel value ]
30 read_field_component [. field path]
39 path(component...) -> field
41 consist in AND, OR and NOT nested expressions, forming a tree with
42 simple relations as leaves. The simple relations test is a field
43 in an event is equal, not equal, smaller, smaller or equal, larger, or
44 larger or equal to a specified value.
54 * - refine switch of expression in multiple uses functions
55 * - remove the idle expressions in the tree ****
56 * - add the current simple expression to the tree
57 * * clear the field_path array after use
60 #include <lttv/filter.h>
67 LTTV_FILTER_TRACEFILE,
80 LTTV_FILTER_EX_SUBMODE,
87 * @fn LttvSimpleExpression* lttv_simple_expression_new()
89 * Constructor for LttvSimpleExpression
90 * @return pointer to new LttvSimpleExpression
93 lttv_simple_expression_new() {
95 LttvSimpleExpression
* se
= g_new(LttvSimpleExpression
,1);
97 se
->field
= LTTV_FILTER_UNDEFINED
;
100 // se->value.v_uint64 = 0;
106 * @fn gboolean lttv_simple_expression_add_field(GPtrArray*,LttvSimpleExpression*)
108 * Parse through filtering field hierarchy as specified
109 * by user. This function compares each value to
110 * predetermined quarks
111 * @param fp The field path list
112 * @param se current simple expression
113 * @return success/failure of operation
116 lttv_simple_expression_assign_field(GPtrArray
* fp
, LttvSimpleExpression
* se
) {
120 if(fp
->len
< 2) return FALSE
;
121 g_assert(f
=g_ptr_array_remove_index(fp
,0));
124 * Parse through the specified
127 * Take note however that the
128 * 'event' subfields might change
129 * depending on values specified
130 * in core.xml file. Hence, if
131 * none of the subfields in the
132 * array match the hardcoded
133 * subfields, it will be considered
136 if(!g_strcasecmp(f
->str
,"trace") ) {
141 g_string_free(f
,TRUE
);
142 f
=g_ptr_array_remove_index(fp
,0);
143 if(!g_strcasecmp(f
->str
,"name")) {
144 se
->field
= LTTV_FILTER_TRACE_NAME
;
146 } else if(!g_strcasecmp(f
->str
,"traceset") ) {
148 * FIXME: not yet implemented !
150 } else if(!g_strcasecmp(f
->str
,"tracefile") ) {
155 g_string_free(f
,TRUE
);
156 f
=g_ptr_array_remove_index(fp
,0);
157 if(!g_strcasecmp(f
->str
,"name")) {
158 se
->field
= LTTV_FILTER_TRACEFILE_NAME
;
160 } else if(!g_strcasecmp(f
->str
,"state") ) {
165 * state.creation_time
166 * state.insertion_time
168 * state.execution_mode
169 * state.execution_submode
170 * state.process_status
173 g_string_free(f
,TRUE
);
174 f
=g_ptr_array_remove_index(fp
,0);
175 if(!g_strcasecmp(f
->str
,"pid") ) {
176 se
->field
= LTTV_FILTER_STATE_PID
;
178 else if(!g_strcasecmp(f
->str
,"ppid") ) {
179 se
->field
= LTTV_FILTER_STATE_PPID
;
181 else if(!g_strcasecmp(f
->str
,"creation_time") ) {
182 se
->field
= LTTV_FILTER_STATE_CT
;
184 else if(!g_strcasecmp(f
->str
,"insertion_time") ) {
185 se
->field
= LTTV_FILTER_STATE_IT
;
187 else if(!g_strcasecmp(f
->str
,"process_name") ) {
188 se
->field
= LTTV_FILTER_STATE_P_NAME
;
190 else if(!g_strcasecmp(f
->str
,"execution_mode") ) {
191 se
->field
= LTTV_FILTER_STATE_EX_MODE
;
193 else if(!g_strcasecmp(f
->str
,"execution_submode") ) {
194 se
->field
= LTTV_FILTER_STATE_EX_SUBMODE
;
196 else if(!g_strcasecmp(f
->str
,"process_status") ) {
197 se
->field
= LTTV_FILTER_STATE_P_STATUS
;
199 else if(!g_strcasecmp(f
->str
,"cpu") ) {
200 se
->field
= LTTV_FILTER_STATE_CPU
;
202 } else if(!g_strcasecmp(f
->str
,"event") ) {
210 g_string_free(f
,TRUE
);
211 f
=g_ptr_array_remove_index(fp
,0);
212 if(!g_strcasecmp(f
->str
,"name") ) {
213 se
->field
= LTTV_FILTER_EVENT_NAME
;
215 else if(!g_strcasecmp(f
->str
,"category") ) {
217 * FIXME: Category not yet functional in lttv
219 se
->field
= LTTV_FILTER_EVENT_CATEGORY
;
221 else if(!g_strcasecmp(f
->str
,"time") ) {
222 se
->field
= LTTV_FILTER_EVENT_TIME
;
224 else if(!g_strcasecmp(f
->str
,"tsc") ) {
225 se
->field
= LTTV_FILTER_EVENT_TSC
;
227 else { /* core.xml specified options */
228 se
->field
= LTTV_FILTER_EVENT_FIELD
;
231 g_warning("Unrecognized field in filter string");
234 /* free memory for last string */
235 g_string_free(f
,TRUE
);
237 /* array should be empty */
238 g_assert(fp
->len
== 0);
240 if(se
->field
== LTTV_FILTER_UNDEFINED
) {
241 g_warning("The specified field was not recognized !");
248 * @fn gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression*,LttvExpressionOp)
250 * Sets the function pointer for the current
252 * @param se current simple expression
253 * @return success/failure of operation
255 gboolean
lttv_simple_expression_assign_operator(LttvSimpleExpression
* se
, LttvExpressionOp op
) {
261 case LTTV_FILTER_TRACE_NAME
:
262 case LTTV_FILTER_TRACEFILE_NAME
:
263 case LTTV_FILTER_STATE_P_NAME
:
264 case LTTV_FILTER_EVENT_NAME
:
267 se
->op
= lttv_apply_op_eq_string
;
270 se
->op
= lttv_apply_op_ne_string
;
273 g_warning("Error encountered in operator assignment = or != expected");
280 case LTTV_FILTER_STATE_PID
:
281 case LTTV_FILTER_STATE_PPID
:
282 case LTTV_FILTER_STATE_EX_MODE
:
283 case LTTV_FILTER_STATE_EX_SUBMODE
:
284 case LTTV_FILTER_STATE_P_STATUS
:
287 se
->op
= lttv_apply_op_eq_uint64
;
290 se
->op
= lttv_apply_op_ne_uint64
;
293 se
->op
= lttv_apply_op_lt_uint64
;
296 se
->op
= lttv_apply_op_le_uint64
;
299 se
->op
= lttv_apply_op_gt_uint64
;
302 se
->op
= lttv_apply_op_ge_uint64
;
305 g_warning("Error encountered in operator assignment");
312 case LTTV_FILTER_STATE_CT
:
313 case LTTV_FILTER_STATE_IT
:
314 case LTTV_FILTER_EVENT_TIME
:
315 case LTTV_FILTER_EVENT_TSC
:
318 se
->op
= lttv_apply_op_eq_ltttime
;
321 se
->op
= lttv_apply_op_ne_ltttime
;
324 se
->op
= lttv_apply_op_lt_ltttime
;
327 se
->op
= lttv_apply_op_le_ltttime
;
330 se
->op
= lttv_apply_op_gt_ltttime
;
333 se
->op
= lttv_apply_op_ge_ltttime
;
336 g_warning("Error encountered in operator assignment");
341 g_warning("Error encountered in operator assignation ! Field type:%i",se
->field
);
350 * @fn void lttv_simple_expression_assign_value(LttvSimpleExpression*,char*)
352 * Assign the value field to the current LttvSimpleExpression
353 * @param se pointer to the current LttvSimpleExpression
354 * @param value string value for simple expression
356 gboolean
lttv_simple_expression_assign_value(LttvSimpleExpression
* se
, char* value
) {
358 // g_print("se->value:%s\n",value);
360 gboolean is_double
= FALSE
;
368 case LTTV_FILTER_TRACE_NAME
:
369 case LTTV_FILTER_TRACEFILE_NAME
:
370 case LTTV_FILTER_STATE_P_NAME
:
371 case LTTV_FILTER_EVENT_NAME
:
372 se
->value
.v_string
= value
;
377 case LTTV_FILTER_STATE_PID
:
378 case LTTV_FILTER_STATE_PPID
:
379 case LTTV_FILTER_STATE_EX_MODE
:
380 case LTTV_FILTER_STATE_EX_SUBMODE
:
381 case LTTV_FILTER_STATE_P_STATUS
:
382 se
->value
.v_uint64
= atoi(value
);
388 case LTTV_FILTER_STATE_CT
:
389 case LTTV_FILTER_STATE_IT
:
390 case LTTV_FILTER_EVENT_TIME
:
391 case LTTV_FILTER_EVENT_TSC
:
392 //se->value.v_double = atof(value);
394 * parsing logic could be optimised,
395 * but as for now, simpler this way
397 v
= g_string_new("");
398 for(i
=0;i
<strlen(value
);i
++) {
399 if(value
[i
] == '.') {
400 /* cannot specify number with more than one '.' */
401 if(is_double
) return FALSE
;
402 else is_double
= TRUE
;
404 g_string_free(v
,TRUE
);
405 v
= g_string_new("");
406 } else g_string_append_c(v
,value
[i
]);
408 /* number can be integer or double */
409 if(is_double
) t
.tv_nsec
= atoi(v
);
411 g_string_free(v
,TRUE
);
413 se
->value
.v_ltttime
= t
;
417 g_warning("Error encountered in value assignation ! Field type = %i",se
->field
);
426 * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*)
428 * Disallocate memory for the current
430 * @param se pointer to the current LttvSimpleExpression
433 lttv_simple_expression_destroy(LttvSimpleExpression
* se
) {
435 // g_free(se->value);
437 case LTTV_FILTER_TRACE_NAME
:
438 case LTTV_FILTER_TRACEFILE_NAME
:
439 case LTTV_FILTER_STATE_P_NAME
:
440 case LTTV_FILTER_EVENT_NAME
:
441 g_free(se
->value
.v_string
);
449 * @fn gint lttv_struct_type(gint)
451 * Finds the structure type depending
452 * on the fields in parameters
453 * @params ft Field of the current structure
454 * @return LttvStructType enum or -1 for error
457 lttv_struct_type(gint ft
) {
460 case LTTV_FILTER_TRACE_NAME
:
461 return LTTV_FILTER_TRACE
;
463 case LTTV_FILTER_TRACEFILE_NAME
:
464 return LTTV_FILTER_TRACEFILE
;
466 case LTTV_FILTER_STATE_PID
:
467 case LTTV_FILTER_STATE_PPID
:
468 case LTTV_FILTER_STATE_CT
:
469 case LTTV_FILTER_STATE_IT
:
470 case LTTV_FILTER_STATE_P_NAME
:
471 case LTTV_FILTER_STATE_EX_MODE
:
472 case LTTV_FILTER_STATE_EX_SUBMODE
:
473 case LTTV_FILTER_STATE_P_STATUS
:
474 case LTTV_FILTER_STATE_CPU
:
475 return LTTV_FILTER_STATE
;
477 case LTTV_FILTER_EVENT_NAME
:
478 case LTTV_FILTER_EVENT_CATEGORY
:
479 case LTTV_FILTER_EVENT_TIME
:
480 case LTTV_FILTER_EVENT_TSC
:
481 case LTTV_FILTER_EVENT_FIELD
:
482 return LTTV_FILTER_EVENT
;
490 * @fn gboolean lttv_apply_op_eq_uint64(const gpointer,LttvFieldValue)
492 * Applies the 'equal' operator to the
493 * specified structure and value
494 * @param v1 left member of comparison
495 * @param v2 right member of comparison
496 * @return success/failure of operation
498 gboolean
lttv_apply_op_eq_uint64(const gpointer v1
, LttvFieldValue v2
) {
500 guint64
* r
= (guint64
*) v1
;
501 return (*r
== v2
.v_uint64
);
506 * @fn gboolean lttv_apply_op_eq_uint32(const 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_uint32(const gpointer v1
, LttvFieldValue v2
) {
515 guint32
* r
= (guint32
*) v1
;
516 return (*r
== v2
.v_uint32
);
520 * @fn gboolean lttv_apply_op_eq_uint16(const 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_uint16(const gpointer v1
, LttvFieldValue v2
) {
529 guint16
* r
= (guint16
*) v1
;
530 return (*r
== v2
.v_uint16
);
534 * @fn gboolean lttv_apply_op_eq_double(const 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_double(const gpointer v1
, LttvFieldValue v2
) {
543 double* r
= (double*) v1
;
544 return (*r
== v2
.v_double
);
548 * @fn gboolean lttv_apply_op_eq_string(const 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_string(const gpointer v1
, LttvFieldValue v2
) {
557 char* r
= (char*) v1
;
558 return (!g_strcasecmp(r
,v2
.v_string
));
562 * @fn gboolean lttv_apply_op_eq_ltttime(const gpointer,LttvFieldValue)
564 * Applies the 'equal' operator to the
565 * specified structure and value
566 * @param v1 left member of comparison
567 * @param v2 right member of comparison
568 * @return success/failure of operation
570 gboolean
lttv_apply_op_eq_ltttime(const gpointer v1
, LttvFieldValue v2
) {
571 LttTime
* r
= (LttTime
*) v1
;
572 return ((r
->tv_sec
== v2
.v_ltttime
.tv_sec
) && (r
->tv_nsec
== v2
.v_ltttime
.tv_nsec
));
577 * @fn gboolean lttv_apply_op_ne_uint64(const gpointer,LttvFieldValue)
579 * Applies the 'not equal' operator to the
580 * specified structure and value
581 * @param v1 left member of comparison
582 * @param v2 right member of comparison
583 * @return success/failure of operation
585 gboolean
lttv_apply_op_ne_uint64(const gpointer v1
, LttvFieldValue v2
) {
586 guint64
* r
= (guint64
*) v1
;
587 return (*r
!= v2
.v_uint64
);
591 * @fn gboolean lttv_apply_op_ne_uint32(const gpointer,LttvFieldValue)
593 * Applies the 'not equal' operator to the
594 * specified structure and value
595 * @param v1 left member of comparison
596 * @param v2 right member of comparison
597 * @return success/failure of operation
599 gboolean
lttv_apply_op_ne_uint32(const gpointer v1
, LttvFieldValue v2
) {
600 guint32
* r
= (guint32
*) v1
;
601 return (*r
!= v2
.v_uint32
);
605 * @fn gboolean lttv_apply_op_ne_uint16(const gpointer,LttvFieldValue)
607 * Applies the 'not equal' operator to the
608 * specified structure and value
609 * @param v1 left member of comparison
610 * @param v2 right member of comparison
611 * @return success/failure of operation
613 gboolean
lttv_apply_op_ne_uint16(const gpointer v1
, LttvFieldValue v2
) {
614 guint16
* r
= (guint16
*) v1
;
615 return (*r
!= v2
.v_uint16
);
619 * @fn gboolean lttv_apply_op_ne_double(const gpointer,LttvFieldValue)
621 * Applies the 'not equal' operator to the
622 * specified structure and value
623 * @param v1 left member of comparison
624 * @param v2 right member of comparison
625 * @return success/failure of operation
627 gboolean
lttv_apply_op_ne_double(const gpointer v1
, LttvFieldValue v2
) {
628 double* r
= (double*) v1
;
629 return (*r
!= v2
.v_double
);
633 * @fn gboolean lttv_apply_op_ne_string(const gpointer,LttvFieldValue)
635 * Applies the 'not equal' operator to the
636 * specified structure and value
637 * @param v1 left member of comparison
638 * @param v2 right member of comparison
639 * @return success/failure of operation
641 gboolean
lttv_apply_op_ne_string(const gpointer v1
, LttvFieldValue v2
) {
642 char* r
= (char*) v1
;
643 return (g_strcasecmp(r
,v2
.v_string
));
647 * @fn gboolean lttv_apply_op_ne_ltttime(const gpointer,LttvFieldValue)
649 * Applies the 'not equal' operator to the
650 * specified structure and value
651 * @param v1 left member of comparison
652 * @param v2 right member of comparison
653 * @return success/failure of operation
655 gboolean
lttv_apply_op_ne_ltttime(const gpointer v1
, LttvFieldValue v2
) {
656 LttTime
* r
= (LttTime
*) v1
;
657 return ltt_time_compare(*r
, v2
.v_ltttime
)!=0?1:0;
662 * @fn gboolean lttv_apply_op_lt_uint64(const gpointer,LttvFieldValue)
664 * Applies the 'lower than' operator to the
665 * specified structure and value
666 * @param v1 left member of comparison
667 * @param v2 right member of comparison
668 * @return success/failure of operation
670 gboolean
lttv_apply_op_lt_uint64(const gpointer v1
, LttvFieldValue v2
) {
671 guint64
* r
= (guint64
*) v1
;
672 return (*r
< v2
.v_uint64
);
676 * @fn gboolean lttv_apply_op_lt_uint32(const gpointer,LttvFieldValue)
678 * Applies the 'lower than' operator to the
679 * specified structure and value
680 * @param v1 left member of comparison
681 * @param v2 right member of comparison
682 * @return success/failure of operation
684 gboolean
lttv_apply_op_lt_uint32(const gpointer v1
, LttvFieldValue v2
) {
685 guint32
* r
= (guint32
*) v1
;
686 return (*r
< v2
.v_uint32
);
690 * @fn gboolean lttv_apply_op_lt_uint16(const gpointer,LttvFieldValue)
692 * Applies the 'lower than' operator to the
693 * specified structure and value
694 * @param v1 left member of comparison
695 * @param v2 right member of comparison
696 * @return success/failure of operation
698 gboolean
lttv_apply_op_lt_uint16(const gpointer v1
, LttvFieldValue v2
) {
699 guint16
* r
= (guint16
*) v1
;
700 return (*r
< v2
.v_uint16
);
704 * @fn gboolean lttv_apply_op_lt_double(const gpointer,LttvFieldValue)
706 * Applies the 'lower than' operator to the
707 * specified structure and value
708 * @param v1 left member of comparison
709 * @param v2 right member of comparison
710 * @return success/failure of operation
712 gboolean
lttv_apply_op_lt_double(const gpointer v1
, LttvFieldValue v2
) {
713 double* r
= (double*) v1
;
714 return (*r
< v2
.v_double
);
718 * @fn gboolean lttv_apply_op_lt_ltttime(const gpointer,LttvFieldValue)
720 * Applies the 'lower than' operator to the
721 * specified structure and value
722 * @param v1 left member of comparison
723 * @param v2 right member of comparison
724 * @return success/failure of operation
726 gboolean
lttv_apply_op_lt_ltttime(const gpointer v1
, LttvFieldValue v2
) {
727 LttTime
* r
= (LttTime
*) v1
;
728 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
)));
733 * @fn gboolean lttv_apply_op_le_uint64(const gpointer,LttvFieldValue)
735 * Applies the 'lower or equal' operator to the
736 * specified structure and value
737 * @param v1 left member of comparison
738 * @param v2 right member of comparison
739 * @return success/failure of operation
741 gboolean
lttv_apply_op_le_uint64(const gpointer v1
, LttvFieldValue v2
) {
742 guint64
* r
= (guint64
*) v1
;
743 return (*r
<= v2
.v_uint64
);
747 * @fn gboolean lttv_apply_op_le_uint32(const gpointer,LttvFieldValue)
749 * Applies the 'lower or equal' operator to the
750 * specified structure and value
751 * @param v1 left member of comparison
752 * @param v2 right member of comparison
753 * @return success/failure of operation
755 gboolean
lttv_apply_op_le_uint32(const gpointer v1
, LttvFieldValue v2
) {
756 guint32
* r
= (guint32
*) v1
;
757 return (*r
<= v2
.v_uint32
);
761 * @fn gboolean lttv_apply_op_le_uint16(const gpointer,LttvFieldValue)
763 * Applies the 'lower or equal' operator to the
764 * specified structure and value
765 * @param v1 left member of comparison
766 * @param v2 right member of comparison
767 * @return success/failure of operation
769 gboolean
lttv_apply_op_le_uint16(const gpointer v1
, LttvFieldValue v2
) {
770 guint16
* r
= (guint16
*) v1
;
771 return (*r
<= v2
.v_uint16
);
775 * @fn gboolean lttv_apply_op_le_double(const gpointer,LttvFieldValue)
777 * Applies the 'lower or equal' operator to the
778 * specified structure and value
779 * @param v1 left member of comparison
780 * @param v2 right member of comparison
781 * @return success/failure of operation
783 gboolean
lttv_apply_op_le_double(const gpointer v1
, LttvFieldValue v2
) {
784 double* r
= (double*) v1
;
785 return (*r
<= v2
.v_double
);
789 * @fn gboolean lttv_apply_op_le_ltttime(const gpointer,LttvFieldValue)
791 * Applies the 'lower or equal' operator to the
792 * specified structure and value
793 * @param v1 left member of comparison
794 * @param v2 right member of comparison
795 * @return success/failure of operation
797 gboolean
lttv_apply_op_le_ltttime(const gpointer v1
, LttvFieldValue v2
) {
798 LttTime
* r
= (LttTime
*) v1
;
799 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
)));
804 * @fn gboolean lttv_apply_op_gt_uint64(const gpointer,LttvFieldValue)
806 * Applies the 'greater than' operator to the
807 * specified structure and value
808 * @param v1 left member of comparison
809 * @param v2 right member of comparison
810 * @return success/failure of operation
812 gboolean
lttv_apply_op_gt_uint64(const gpointer v1
, LttvFieldValue v2
) {
813 guint64
* r
= (guint64
*) v1
;
814 return (*r
> v2
.v_uint64
);
818 * @fn gboolean lttv_apply_op_gt_uint32(const gpointer,LttvFieldValue)
820 * Applies the 'greater than' operator to the
821 * specified structure and value
822 * @param v1 left member of comparison
823 * @param v2 right member of comparison
824 * @return success/failure of operation
826 gboolean
lttv_apply_op_gt_uint32(const gpointer v1
, LttvFieldValue v2
) {
827 guint32
* r
= (guint32
*) v1
;
828 return (*r
> v2
.v_uint32
);
832 * @fn gboolean lttv_apply_op_gt_uint16(const gpointer,LttvFieldValue)
834 * Applies the 'greater than' operator to the
835 * specified structure and value
836 * @param v1 left member of comparison
837 * @param v2 right member of comparison
838 * @return success/failure of operation
840 gboolean
lttv_apply_op_gt_uint16(const gpointer v1
, LttvFieldValue v2
) {
841 guint16
* r
= (guint16
*) v1
;
842 return (*r
> v2
.v_uint16
);
846 * @fn gboolean lttv_apply_op_gt_double(const gpointer,LttvFieldValue)
848 * Applies the 'greater than' operator to the
849 * specified structure and value
850 * @param v1 left member of comparison
851 * @param v2 right member of comparison
852 * @return success/failure of operation
854 gboolean
lttv_apply_op_gt_double(const gpointer v1
, LttvFieldValue v2
) {
855 double* r
= (double*) v1
;
856 return (*r
> v2
.v_double
);
860 * @fn gboolean lttv_apply_op_gt_ltttime(const gpointer,LttvFieldValue)
862 * Applies the 'greater than' operator to the
863 * specified structure and value
864 * @param v1 left member of comparison
865 * @param v2 right member of comparison
866 * @return success/failure of operation
868 gboolean
lttv_apply_op_gt_ltttime(const gpointer v1
, LttvFieldValue v2
) {
869 LttTime
* r
= (LttTime
*) v1
;
870 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
)));
875 * @fn gboolean lttv_apply_op_ge_uint64(const gpointer,LttvFieldValue)
877 * Applies the 'greater or equal' operator to the
878 * specified structure and value
879 * @param v1 left member of comparison
880 * @param v2 right member of comparison
881 * @return success/failure of operation
883 gboolean
lttv_apply_op_ge_uint64(const gpointer v1
, LttvFieldValue v2
) {
884 guint64
* r
= (guint64
*) v1
;
885 return (*r
>= v2
.v_uint64
);
889 * @fn gboolean lttv_apply_op_ge_uint32(const gpointer,LttvFieldValue)
891 * Applies the 'greater or equal' operator to the
892 * specified structure and value
893 * @param v1 left member of comparison
894 * @param v2 right member of comparison
895 * @return success/failure of operation
897 gboolean
lttv_apply_op_ge_uint32(const gpointer v1
, LttvFieldValue v2
) {
898 guint32
* r
= (guint32
*) v1
;
899 return (*r
>= v2
.v_uint32
);
903 * @fn gboolean lttv_apply_op_ge_uint16(const gpointer,LttvFieldValue)
905 * Applies the 'greater or equal' operator to the
906 * specified structure and value
907 * @param v1 left member of comparison
908 * @param v2 right member of comparison
909 * @return success/failure of operation
911 gboolean
lttv_apply_op_ge_uint16(const gpointer v1
, LttvFieldValue v2
) {
912 guint16
* r
= (guint16
*) v1
;
913 return (*r
>= v2
.v_uint16
);
917 * @fn gboolean lttv_apply_op_ge_double(const gpointer,LttvFieldValue)
919 * Applies the 'greater or equal' operator to the
920 * specified structure and value
921 * @param v1 left member of comparison
922 * @param v2 right member of comparison
923 * @return success/failure of operation
925 gboolean
lttv_apply_op_ge_double(const gpointer v1
, LttvFieldValue v2
) {
926 double* r
= (double*) v1
;
927 return (*r
>= v2
.v_double
);
931 * @fn gboolean lttv_apply_op_ge_ltttime(const gpointer,LttvFieldValue)
933 * Applies the 'greater or equal' operator to the
934 * specified structure and value
935 * @param v1 left member of comparison
936 * @param v2 right member of comparison
937 * @return success/failure of operation
939 gboolean
lttv_apply_op_ge_ltttime(const gpointer v1
, LttvFieldValue v2
) {
940 LttTime
* r
= (LttTime
*) v1
;
941 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
)));
947 * @fn LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree*)
949 * Makes a copy of the current filter tree
950 * @param tree pointer to the current tree
951 * @return new copy of the filter tree
954 lttv_filter_tree_clone(const LttvFilterTree
* tree
) {
956 LttvFilterTree
* newtree
= lttv_filter_tree_new();
958 newtree
->node
= tree
->node
;
960 newtree
->left
= tree
->left
;
961 if(newtree
->left
== LTTV_TREE_NODE
) {
962 newtree
->l_child
.t
= lttv_filter_tree_clone(tree
->l_child
.t
);
963 } else if(newtree
->left
== LTTV_TREE_LEAF
) {
964 newtree
->l_child
.leaf
= lttv_simple_expression_new();
965 newtree
->l_child
.leaf
->field
= tree
->l_child
.leaf
->field
;
966 newtree
->l_child
.leaf
->offset
= tree
->l_child
.leaf
->offset
;
967 newtree
->l_child
.leaf
->op
= tree
->l_child
.leaf
->op
;
968 /* FIXME: special case for string copy ! */
969 newtree
->l_child
.leaf
->value
= tree
->l_child
.leaf
->value
;
972 newtree
->right
= tree
->right
;
973 if(newtree
->right
== LTTV_TREE_NODE
) {
974 newtree
->r_child
.t
= lttv_filter_tree_clone(tree
->r_child
.t
);
975 } else if(newtree
->right
== LTTV_TREE_LEAF
) {
976 newtree
->r_child
.leaf
= lttv_simple_expression_new();
977 newtree
->r_child
.leaf
->field
= tree
->r_child
.leaf
->field
;
978 newtree
->r_child
.leaf
->offset
= tree
->r_child
.leaf
->offset
;
979 newtree
->r_child
.leaf
->op
= tree
->r_child
.leaf
->op
;
980 newtree
->r_child
.leaf
->value
= tree
->r_child
.leaf
->value
;
988 * @fn LttvFilter* lttv_filter_clone(LttvFilter*)
990 * Makes a copy of the current filter
991 * @param filter pointer to the current filter
992 * @return new copy of the filter
995 lttv_filter_clone(const LttvFilter
* filter
) {
997 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
999 // newfilter->expression = g_new(char,1)
1000 strcpy(newfilter
->expression
,filter
->expression
);
1002 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
1010 * @fn LttvFilter* lttv_filter_new()
1012 * Creates a new lttv_filter
1013 * @param expression filtering options string
1014 * @param t pointer to the current LttvTrace
1015 * @return the current lttv_filter or NULL if error
1020 LttvFilter
* filter
= g_new(LttvFilter
,1);
1021 filter
->expression
= NULL
;
1022 filter
->head
= NULL
;
1027 * @fn gboolean lttv_filter_update(LttvFilter*)
1029 * Updates the current LttvFilter by building
1030 * its tree based upon the expression string
1031 * @param filter pointer to the current LttvFilter
1032 * @return Failure/Success of operation
1035 lttv_filter_update(LttvFilter
* filter
) {
1037 // g_print("filter::lttv_filter_new()\n"); /* debug */
1039 if(filter
->expression
== NULL
) return FALSE
;
1043 p_nesting
=0; /* parenthesis nesting value */
1047 *tree
= lttv_filter_tree_new(), /* main tree */
1048 *subtree
= NULL
, /* buffer for subtrees */
1049 *t1
, /* buffer #1 */
1050 *t2
; /* buffer #2 */
1054 * If the tree already exists,
1055 * destroy it and build a new one
1057 if(filter
->head
!= NULL
) lttv_filter_tree_destroy(filter
->head
);
1058 filter
->head
= NULL
; /* will be assigned at the end */
1062 * each element of the list
1063 * is a sub tree created
1064 * by the use of parenthesis in the
1065 * global expression. The final tree
1066 * will be the one left at the root of
1069 GPtrArray
*tree_stack
= g_ptr_array_new();
1070 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
1072 /* temporary values */
1073 GString
*a_field_component
= g_string_new("");
1074 GPtrArray
*a_field_path
= g_ptr_array_new();
1076 /* simple expression buffer */
1077 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
1080 * Parse entire expression and construct
1081 * the binary tree. There are two steps
1082 * in browsing that string
1083 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
1084 * 2. finding simple expressions
1085 * - field path ( separated by dots )
1086 * - op ( >, <, =, >=, <=, !=)
1087 * - value ( integer, string ... )
1088 * To spare computing time, the whole
1089 * string is parsed in this loop for a
1090 * O(n) complexity order.
1092 * When encountering logical op &,|,^
1093 * 1. parse the last value if any
1094 * 2. create a new tree
1095 * 3. add the expression (simple exp, or exp (subtree)) to the tree
1096 * 4. concatenate this tree with the current tree on top of the stack
1097 * When encountering math ops >,>=,<,<=,=,!=
1098 * 1. add to op to the simple expression
1099 * 2. concatenate last field component to field path
1100 * When encountering concatening ops .
1101 * 1. concatenate last field component to field path
1102 * When encountering opening parenthesis (,{,[
1103 * 1. create a new subtree on top of tree stack
1104 * When encountering closing parenthesis ),},]
1105 * 1. add the expression on right child of the current tree
1106 * 2. the subtree is completed, allocate a new subtree
1107 * 3. pop the tree value from the tree stack
1110 for(i
=0;i
<strlen(filter
->expression
);i
++) {
1112 //g_print("%c ",filter->expression[i]);
1114 switch(filter
->expression
[i
]) {
1120 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1121 while(t1
->right
!= LTTV_TREE_IDLE
) {
1122 g_assert(t1
->right
== LTTV_TREE_NODE
);
1125 t2
= lttv_filter_tree_new();
1126 t2
->node
= LTTV_LOGICAL_AND
;
1127 if(subtree
!= NULL
) { /* append subtree to current tree */
1128 t2
->left
= LTTV_TREE_NODE
;
1129 t2
->l_child
.t
= subtree
;
1131 t1
->right
= LTTV_TREE_NODE
;
1133 } else { /* append a simple expression */
1134 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1135 a_field_component
= g_string_new("");
1136 t2
->left
= LTTV_TREE_LEAF
;
1137 t2
->l_child
.leaf
= a_simple_expression
;
1138 a_simple_expression
= lttv_simple_expression_new();
1139 t1
->right
= LTTV_TREE_NODE
;
1146 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1147 while(t1
->right
!= LTTV_TREE_IDLE
) {
1148 g_assert(t1
->right
== LTTV_TREE_NODE
);
1151 t2
= lttv_filter_tree_new();
1152 t2
->node
= LTTV_LOGICAL_OR
;
1153 if(subtree
!= NULL
) { /* append subtree to current tree */
1154 t2
->left
= LTTV_TREE_NODE
;
1155 t2
->l_child
.t
= subtree
;
1157 t1
->right
= LTTV_TREE_NODE
;
1159 } else { /* append a simple expression */
1160 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1161 a_field_component
= g_string_new("");
1162 t2
->left
= LTTV_TREE_LEAF
;
1163 t2
->l_child
.leaf
= a_simple_expression
;
1164 a_simple_expression
= lttv_simple_expression_new();
1165 t1
->right
= LTTV_TREE_NODE
;
1172 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1173 while(t1
->right
!= LTTV_TREE_IDLE
) {
1174 g_assert(t1
->right
== LTTV_TREE_NODE
);
1177 t2
= lttv_filter_tree_new();
1178 t2
->node
= LTTV_LOGICAL_XOR
;
1179 if(subtree
!= NULL
) { /* append subtree to current tree */
1180 t2
->left
= LTTV_TREE_NODE
;
1181 t2
->l_child
.t
= subtree
;
1183 t1
->right
= LTTV_TREE_NODE
;
1185 } else { /* append a simple expression */
1186 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1187 a_field_component
= g_string_new("");
1188 t2
->left
= LTTV_TREE_LEAF
;
1189 t2
->l_child
.leaf
= a_simple_expression
;
1190 a_simple_expression
= lttv_simple_expression_new();
1191 t1
->right
= LTTV_TREE_NODE
;
1196 case '!': /* not, or not equal (math op) */
1198 if(filter
->expression
[i
+1] == '=') { /* != */
1199 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1200 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1201 a_field_component
= g_string_new("");
1202 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_NE
);
1205 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1206 while(t1
->right
!= LTTV_TREE_IDLE
) {
1207 g_assert(t1
->right
== LTTV_TREE_NODE
);
1210 t2
= lttv_filter_tree_new();
1211 t2
->node
= LTTV_LOGICAL_NOT
;
1212 t1
->right
= LTTV_TREE_NODE
;
1217 case '(': /* start of parenthesis */
1221 p_nesting
++; /* incrementing parenthesis nesting value */
1222 t1
= lttv_filter_tree_new();
1223 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
1226 case ')': /* end of parenthesis */
1230 p_nesting
--; /* decrementing parenthesis nesting value */
1231 if(p_nesting
<0 || tree_stack
->len
<2) {
1232 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1233 is not valid due to parenthesis incorrect use",filter
->expression
);
1237 /* there must at least be the root tree left in the array */
1238 g_assert(tree_stack
->len
>0);
1240 if(subtree
!= NULL
) { /* append subtree to current tree */
1241 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1242 while(t1
->right
!= LTTV_TREE_IDLE
) {
1243 g_assert(t1
->right
== LTTV_TREE_NODE
);
1246 t1
->right
= LTTV_TREE_NODE
;
1247 t1
->r_child
.t
= subtree
;
1248 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1249 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1250 } else { /* assign subtree as current tree */
1251 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1252 a_field_component
= g_string_new("");
1253 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1254 while(t1
->right
!= LTTV_TREE_IDLE
) {
1255 g_assert(t1
->right
== LTTV_TREE_NODE
);
1256 g_assert(t1
->r_child
.t
!= NULL
);
1259 t1
->right
= LTTV_TREE_LEAF
;
1260 t1
->r_child
.leaf
= a_simple_expression
;
1261 a_simple_expression
= lttv_simple_expression_new();
1262 subtree
= g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1267 * mathematic operators
1269 case '<': /* lower, lower or equal */
1271 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1272 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1273 a_field_component
= g_string_new("");
1274 if(filter
->expression
[i
+1] == '=') { /* <= */
1276 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LE
);
1277 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LT
);
1280 case '>': /* higher, higher or equal */
1282 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1283 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1284 a_field_component
= g_string_new("");
1285 if(filter
->expression
[i
+1] == '=') { /* >= */
1287 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GE
);
1288 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GT
);
1291 case '=': /* equal */
1293 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1294 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1295 a_field_component
= g_string_new("");
1296 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1300 * Field concatening caracter
1305 * divide field expression into elements
1306 * in a_field_path array.
1308 * A dot can also be present in double values
1310 if(a_simple_expression
->field
== LTTV_FILTER_UNDEFINED
) {
1311 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1312 a_field_component
= g_string_new("");
1315 case ' ': /* ignore */
1316 case '\n': /* ignore */
1318 default: /* concatening current string */
1319 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1324 * Preliminary check to see
1325 * if tree was constructed correctly
1328 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1329 is not valid due to parenthesis incorrect use",filter
->expression
);
1333 if(tree_stack
->len
!= 1) /* only root tree should remain */
1336 /* processing last element of expression */
1337 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1338 while(t1
->right
!= LTTV_TREE_IDLE
) {
1339 g_assert(t1
->right
== LTTV_TREE_NODE
);
1342 if(subtree
!= NULL
) { /* add the subtree */
1343 t1
->right
= LTTV_TREE_NODE
;
1344 t1
->r_child
.t
= subtree
;
1346 } else { /* add a leaf */
1347 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1348 a_field_component
= NULL
;
1349 t1
->right
= LTTV_TREE_LEAF
;
1350 t1
->r_child
.leaf
= a_simple_expression
;
1351 a_simple_expression
= NULL
;
1355 /* free the pointer array */
1356 g_assert(a_field_path
->len
== 0);
1357 g_ptr_array_free(a_field_path
,TRUE
);
1359 /* free the tree stack -- but keep the root tree */
1360 filter
->head
= g_ptr_array_remove_index(tree_stack
,0);
1361 g_ptr_array_free(tree_stack
,TRUE
);
1363 /* free the field buffer if allocated */
1364 if(a_field_component
!= NULL
) g_string_free(a_field_component
,TRUE
);
1366 /* free the simple expression buffer if allocated */
1367 if(a_simple_expression
!= NULL
) lttv_simple_expression_destroy(a_simple_expression
);
1369 g_assert(filter
->head
!= NULL
); /* tree should exist */
1370 g_assert(subtree
== NULL
); /* remaining subtree should be included in main tree */
1373 g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1374 lttv_print_tree(filter
->head
) ;
1375 g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1383 * @fn void lttv_filter_destroy(LttvFilter*)
1385 * Destroy the current LttvFilter
1386 * @param filter pointer to the current LttvFilter
1389 lttv_filter_destroy(LttvFilter
* filter
) {
1391 g_free(filter
->expression
);
1392 lttv_filter_tree_destroy(filter
->head
);
1398 * @fn LttvFilterTree* lttv_filter_tree_new()
1400 * Assign a new tree for the current expression
1402 * @return pointer of LttvFilterTree
1405 lttv_filter_tree_new() {
1406 LttvFilterTree
* tree
;
1408 tree
= g_new(LttvFilterTree
,1);
1409 tree
->node
= 0; //g_new(lttv_expression,1);
1410 tree
->left
= LTTV_TREE_IDLE
;
1411 tree
->right
= LTTV_TREE_IDLE
;
1412 tree
->r_child
.t
= NULL
;
1413 tree
->l_child
.t
= NULL
;
1419 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1421 * Append a new expression to the expression
1422 * defined in the current filter
1423 * @param filter pointer to the current LttvFilter
1424 * @param expression string that must be appended
1425 * @return Success/Failure of operation
1427 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, char *expression
) {
1429 if(expression
== NULL
) return FALSE
;
1430 if(filter
== NULL
) {
1431 filter
= lttv_filter_new();
1432 filter
->expression
= expression
;
1433 } else if(filter
->expression
== NULL
) {
1434 filter
->expression
= expression
;
1436 filter
->expression
= g_strconcat(filter
->expression
,"&",expression
);
1438 /* clear expression */
1442 return lttv_filter_update(filter
);
1447 * @fn void lttv_filter_clear_expression(LttvFilter*)
1449 * Clear the filter expression from the
1450 * current filter and sets its pointer to NULL
1451 * @param filter pointer to the current LttvFilter
1453 void lttv_filter_clear_expression(LttvFilter
* filter
) {
1455 if(filter
->expression
!= NULL
) {
1456 g_free(filter
->expression
);
1457 filter
->expression
= NULL
;
1463 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1465 * Destroys the tree and his sub-trees
1466 * @param tree Tree which must be destroyed
1469 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1471 if(tree
== NULL
) return;
1473 if(tree
->left
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->l_child
.leaf
);
1474 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1476 if(tree
->right
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->r_child
.leaf
);
1477 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1479 // g_free(tree->node);
1484 * @fn gboolean lttv_filter_tree_parse(LttvFilterTree*,LttEvent,LttTracefile,LttTrace,LttvProcessState)
1486 * Global parsing function for the current
1488 * @param tree pointer to the current LttvFilterTree
1489 * @param event current LttEvent, NULL if not used
1490 * @param tracefile current LttTracefile, NULL if not used
1491 * @param trace current LttTrace, NULL if not used
1492 * @param state current LttvProcessState, NULL if not used
1493 * @param context current LttvTracefileContext, NULL if not used
1494 * @return response of filter
1497 lttv_filter_tree_parse(
1498 const LttvFilterTree
* t
,
1499 const LttEvent
* event
,
1500 const LttTracefile
* tracefile
,
1501 const LttTrace
* trace
,
1502 const LttvProcessState
* state
,
1503 const LttvTracefileContext
* context
1508 * Each tree is parsed in inorder.
1509 * This way, it's possible to apply the left filter of the
1510 * tree, then decide whether or not the right branch should
1511 * be parsed depending on the linking logical operator
1513 * Each node consists in a
1514 * 1. logical operator
1515 * 2. left child ( node or simple expression )
1516 * 3. right child ( node or simple expression )
1518 * When the child is a simple expression, we must
1519 * before all determine if the expression refers to
1520 * a structure which is whithin observation ( not NULL ).
1521 * -If so, the expression is evaluated.
1522 * -If not, the result is set to TRUE since this particular
1523 * operation does not interfere with the lttv structure
1525 * The result of each simple expression will directly
1526 * affect the next branch. This way, depending on
1527 * the linking logical operator, the parser will decide
1528 * to explore or not the next branch.
1530 * -If result of left branch is 0 / FALSE
1531 * then don't explore right branch and return 0;
1532 * -If result of left branch is 1 / TRUE then explore
1534 * -If result of left branch is 1 / TRUE
1535 * then don't explore right branch and return 1;
1536 * -If result of left branch is 0 / FALSE then explore
1538 * -Result of left branch will not affect exploration of
1542 gboolean lresult
= FALSE
, rresult
= FALSE
;
1547 if(t
->left
== LTTV_TREE_NODE
) {
1548 lresult
= lttv_filter_tree_parse(t
->l_child
.t
,event
,tracefile
,trace
,state
,context
);
1550 else if(t
->left
== LTTV_TREE_LEAF
) {
1551 lresult
= lttv_filter_tree_parse_branch(t
->l_child
.leaf
,event
,tracefile
,trace
,state
,context
);
1555 * Parse linking operator
1556 * make a cutoff if possible
1558 if((t
->node
& LTTV_LOGICAL_OR
) && lresult
== TRUE
) return TRUE
;
1559 if((t
->node
& LTTV_LOGICAL_AND
) && lresult
== FALSE
) return FALSE
;
1562 * Parse right branch
1564 if(t
->right
== LTTV_TREE_NODE
) {
1565 rresult
= lttv_filter_tree_parse(t
->r_child
.t
,event
,tracefile
,trace
,state
,context
);
1567 else if(t
->right
== LTTV_TREE_LEAF
) {
1568 rresult
= lttv_filter_tree_parse_branch(t
->r_child
.leaf
,event
,tracefile
,trace
,state
,context
);
1572 * Apply and return the
1573 * logical link between the
1577 case LTTV_LOGICAL_OR
: return (lresult
| rresult
);
1578 case LTTV_LOGICAL_AND
: return (lresult
& rresult
);
1579 case LTTV_LOGICAL_NOT
: return (!rresult
);
1580 case LTTV_LOGICAL_XOR
: return (lresult
^ rresult
);
1581 case 0: return (rresult
);
1584 * This case should never be
1585 * parsed, if so, this subtree
1594 * @fn gboolean lttv_filter_tree_parse_branch(LttvFilterTree*,LttEvent*,LttTracefile*,LttTrace*,LttvProcessState*,LttvTracefileContext*)
1596 * This function parses a particular branch of the tree
1597 * @param tree pointer to the current LttvFilterTree
1598 * @param event current LttEvent, NULL if not used
1599 * @param tracefile current LttTracefile, NULL if not used
1600 * @param trace current LttTrace, NULL if not used
1601 * @param state current LttvProcessState, NULL if not used
1602 * @param context current LttvTracefileContext, NULL if not used
1603 * @return response of filter
1605 gboolean
lttv_filter_tree_parse_branch(
1606 const LttvSimpleExpression
* se
,
1607 const LttEvent
* event
,
1608 const LttTracefile
* tracefile
,
1609 const LttTrace
* trace
,
1610 const LttvProcessState
* state
,
1611 const LttvTracefileContext
* context
) {
1616 case LTTV_FILTER_TRACE_NAME
:
1617 if(trace
== NULL
) return TRUE
;
1618 else return se
->op((gpointer
)ltt_trace_name(trace
),v
);
1620 case LTTV_FILTER_TRACEFILE_NAME
:
1621 if(tracefile
== NULL
) return TRUE
;
1622 else return se
->op((gpointer
)ltt_tracefile_name(tracefile
),v
);
1624 case LTTV_FILTER_STATE_PID
:
1625 if(state
== NULL
) return TRUE
;
1626 else return se
->op((gpointer
)&state
->pid
,v
);
1628 case LTTV_FILTER_STATE_PPID
:
1629 if(state
== NULL
) return TRUE
;
1630 else return se
->op((gpointer
)&state
->ppid
,v
);
1632 case LTTV_FILTER_STATE_CT
:
1633 if(state
== NULL
) return TRUE
;
1635 return se
->op((gpointer
)&state
->creation_time
,v
);
1638 case LTTV_FILTER_STATE_IT
:
1639 if(state
== NULL
) return TRUE
;
1641 return se
->op((gpointer
)&state
->insertion_time
,v
);
1644 case LTTV_FILTER_STATE_P_NAME
:
1646 * All 'unnamed' for the moment
1648 if(state
== NULL
) return TRUE
;
1650 return se
->op((gpointer
)g_quark_to_string(state
->name
),v
);
1653 case LTTV_FILTER_STATE_EX_MODE
:
1654 if(state
== NULL
) return TRUE
;
1655 else return se
->op((gpointer
)&state
->state
->t
,v
);
1657 case LTTV_FILTER_STATE_EX_SUBMODE
:
1658 if(state
== NULL
) return TRUE
;
1659 else return se
->op((gpointer
)&state
->state
->n
,v
);
1661 case LTTV_FILTER_STATE_P_STATUS
:
1662 if(state
== NULL
) return TRUE
;
1663 else return se
->op((gpointer
)&state
->state
->s
,v
);
1665 case LTTV_FILTER_STATE_CPU
:
1666 if(context
== NULL
) return TRUE
;
1668 return se
->op((gpointer
)g_quark_to_string(((LttvTracefileState
*)context
)->cpu_name
),v
);
1671 case LTTV_FILTER_EVENT_NAME
:
1672 if(event
== NULL
) return TRUE
;
1675 et
= ltt_event_eventtype(event
);
1676 return se
->op((gpointer
)ltt_eventtype_name(et
),v
);
1680 case LTTV_FILTER_EVENT_CATEGORY
:
1682 * FIXME: Not yet implemented
1686 case LTTV_FILTER_EVENT_TIME
:
1687 if(event
== NULL
) return TRUE
;
1689 LttTime time
= ltt_event_time(event
);
1690 return se
->op((gpointer
)&time
,v
);
1693 case LTTV_FILTER_EVENT_TSC
:
1694 // if(event == NULL) return TRUE;
1696 // double val = ltt_time_to_double(event->event_time);
1697 // return se->op((gpointer)&val,v);
1700 * FIXME: Where is event.tsc
1704 case LTTV_FILTER_EVENT_FIELD
:
1706 * TODO: Use the offset to
1707 * find the dynamic field
1708 * in the event struct
1713 * This case should never be
1714 * parsed, if so, the whole
1715 * filtering is cancelled
1717 g_warning("Error while parsing the filter tree");
1721 /* should never get here */
1729 * @fn void lttv_print_tree(LttvFilterTree*)
1732 * @param t the pointer to the current LttvFilterTree
1735 lttv_print_tree(const LttvFilterTree
* t
) {
1737 g_print("node:%p lchild:%p rchild:%p\n",t
, //t->l_child.t,t->r_child.t);
1738 (t
->left
==LTTV_TREE_NODE
)?t
->l_child
.t
:NULL
,
1739 (t
->right
==LTTV_TREE_NODE
)?t
->r_child
.t
:NULL
);
1740 g_print("node type: %i / [left] %i / [right] %i\n",t
->node
,t
->left
,t
->right
);
1741 if(t
->left
== LTTV_TREE_NODE
) lttv_print_tree(t
->l_child
.t
);
1742 else if(t
->left
== LTTV_TREE_LEAF
) {
1743 g_print("%p: left is %i %p value\n",t
,t
->l_child
.leaf
->field
,t
->l_child
.leaf
->op
);
1745 if(t
->right
== LTTV_TREE_NODE
) lttv_print_tree(t
->r_child
.t
);
1746 else if(t
->right
== LTTV_TREE_LEAF
) {
1747 g_print("%p: right is %i %p value\n",t
,t
->r_child
.leaf
->field
,t
->r_child
.leaf
->op
);
1753 * @fn static void module_init()
1755 * Initializes the filter module and specific values
1757 static void module_init()
1763 * @fn Destroys the filter module and specific values
1765 static void module_destroy()
1771 LTTV_MODULE("filter", "Filters traceset and events", \
1772 "Filters traceset and events specifically to user input", \
1773 module_init
, module_destroy
)