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
;
105 * @fn gboolean lttv_simple_expression_add_field(GPtrArray*,LttvSimpleExpression*)
107 * Parse through filtering field hierarchy as specified
108 * by user. This function compares each value to
109 * predetermined quarks
110 * @param fp The field path list
111 * @param se current simple expression
112 * @return success/failure of operation
115 lttv_simple_expression_assign_field(GPtrArray
* fp
, LttvSimpleExpression
* se
) {
119 if(fp
->len
< 2) return FALSE
;
120 g_assert(f
=g_ptr_array_remove_index(fp
,0));
123 * Parse through the specified
126 * Take note however that the
127 * 'event' subfields might change
128 * depending on values specified
129 * in core.xml file. Hence, if
130 * none of the subfields in the
131 * array match the hardcoded
132 * subfields, it will be considered
135 if(!g_strcasecmp(f
->str
,"trace") ) {
140 g_string_free(f
,TRUE
);
141 f
=g_ptr_array_remove_index(fp
,0);
142 if(!g_strcasecmp(f
->str
,"name")) {
143 se
->field
= LTTV_FILTER_TRACE_NAME
;
145 } else if(!g_strcasecmp(f
->str
,"traceset") ) {
147 * FIXME: not yet implemented !
149 } else if(!g_strcasecmp(f
->str
,"tracefile") ) {
154 g_string_free(f
,TRUE
);
155 f
=g_ptr_array_remove_index(fp
,0);
156 if(!g_strcasecmp(f
->str
,"name")) {
157 se
->field
= LTTV_FILTER_TRACEFILE_NAME
;
159 } else if(!g_strcasecmp(f
->str
,"state") ) {
164 * state.creation_time
165 * state.insertion_time
167 * state.execution_mode
168 * state.execution_submode
169 * state.process_status
172 g_string_free(f
,TRUE
);
173 f
=g_ptr_array_remove_index(fp
,0);
174 if(!g_strcasecmp(f
->str
,"pid") ) {
175 se
->field
= LTTV_FILTER_STATE_PID
;
177 else if(!g_strcasecmp(f
->str
,"ppid") ) {
178 se
->field
= LTTV_FILTER_STATE_PPID
;
180 else if(!g_strcasecmp(f
->str
,"creation_time") ) {
181 se
->field
= LTTV_FILTER_STATE_CT
;
183 else if(!g_strcasecmp(f
->str
,"insertion_time") ) {
184 se
->field
= LTTV_FILTER_STATE_IT
;
186 else if(!g_strcasecmp(f
->str
,"process_name") ) {
187 se
->field
= LTTV_FILTER_STATE_P_NAME
;
189 else if(!g_strcasecmp(f
->str
,"execution_mode") ) {
190 se
->field
= LTTV_FILTER_STATE_EX_MODE
;
192 else if(!g_strcasecmp(f
->str
,"execution_submode") ) {
193 se
->field
= LTTV_FILTER_STATE_EX_SUBMODE
;
195 else if(!g_strcasecmp(f
->str
,"process_status") ) {
196 se
->field
= LTTV_FILTER_STATE_P_STATUS
;
198 else if(!g_strcasecmp(f
->str
,"cpu") ) {
199 se
->field
= LTTV_FILTER_STATE_CPU
;
201 } else if(!g_strcasecmp(f
->str
,"event") ) {
209 g_string_free(f
,TRUE
);
210 f
=g_ptr_array_remove_index(fp
,0);
211 if(!g_strcasecmp(f
->str
,"name") ) {
212 se
->field
= LTTV_FILTER_EVENT_NAME
;
214 else if(!g_strcasecmp(f
->str
,"category") ) {
216 * FIXME: Category not yet functional in lttv
218 se
->field
= LTTV_FILTER_EVENT_CATEGORY
;
220 else if(!g_strcasecmp(f
->str
,"time") ) {
221 se
->field
= LTTV_FILTER_EVENT_TIME
;
223 else if(!g_strcasecmp(f
->str
,"tsc") ) {
224 se
->field
= LTTV_FILTER_EVENT_TSC
;
226 else { /* core.xml specified options */
227 se
->field
= LTTV_FILTER_EVENT_FIELD
;
230 g_warning("Unrecognized field in filter string");
233 /* free memory for last string */
234 g_string_free(f
,TRUE
);
236 /* array should be empty */
237 g_assert(fp
->len
== 0);
239 if(se
->field
== LTTV_FILTER_UNDEFINED
) {
240 g_warning("The specified field was not recognized !");
247 * @fn gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression*,LttvExpressionOp)
249 * Sets the function pointer for the current
251 * @param se current simple expression
252 * @return success/failure of operation
254 gboolean
lttv_simple_expression_assign_operator(LttvSimpleExpression
* se
, LttvExpressionOp op
) {
260 case LTTV_FILTER_TRACE_NAME
:
261 case LTTV_FILTER_TRACEFILE_NAME
:
262 case LTTV_FILTER_STATE_P_NAME
:
263 case LTTV_FILTER_EVENT_NAME
:
266 se
->op
= lttv_apply_op_eq_quark
;
269 se
->op
= lttv_apply_op_ne_quark
;
272 g_warning("Error encountered in operator assignment = or != expected");
279 case LTTV_FILTER_STATE_PID
:
280 case LTTV_FILTER_STATE_PPID
:
281 case LTTV_FILTER_STATE_EX_MODE
:
282 case LTTV_FILTER_STATE_EX_SUBMODE
:
283 case LTTV_FILTER_STATE_P_STATUS
:
286 se
->op
= lttv_apply_op_eq_uint64
;
289 se
->op
= lttv_apply_op_ne_uint64
;
292 se
->op
= lttv_apply_op_lt_uint64
;
295 se
->op
= lttv_apply_op_le_uint64
;
298 se
->op
= lttv_apply_op_gt_uint64
;
301 se
->op
= lttv_apply_op_ge_uint64
;
304 g_warning("Error encountered in operator assignment");
311 case LTTV_FILTER_STATE_CT
:
312 case LTTV_FILTER_STATE_IT
:
313 case LTTV_FILTER_EVENT_TIME
:
314 case LTTV_FILTER_EVENT_TSC
:
317 se
->op
= lttv_apply_op_eq_ltttime
;
320 se
->op
= lttv_apply_op_ne_ltttime
;
323 se
->op
= lttv_apply_op_lt_ltttime
;
326 se
->op
= lttv_apply_op_le_ltttime
;
329 se
->op
= lttv_apply_op_gt_ltttime
;
332 se
->op
= lttv_apply_op_ge_ltttime
;
335 g_warning("Error encountered in operator assignment");
340 g_warning("Error encountered in operator assignation ! Field type:%i",se
->field
);
349 * @fn void lttv_simple_expression_assign_value(LttvSimpleExpression*,char*)
351 * Assign the value field to the current LttvSimpleExpression
352 * @param se pointer to the current LttvSimpleExpression
353 * @param value string value for simple expression
355 gboolean
lttv_simple_expression_assign_value(LttvSimpleExpression
* se
, char* value
) {
357 // g_print("se->value:%s\n",value);
359 gboolean is_double
= FALSE
;
360 LttTime t
= ltt_time_zero
;
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;
373 se
->value
.v_uint32
= g_quark_try_string(value
);
379 case LTTV_FILTER_STATE_PID
:
380 case LTTV_FILTER_STATE_PPID
:
381 case LTTV_FILTER_STATE_EX_MODE
:
382 case LTTV_FILTER_STATE_EX_SUBMODE
:
383 case LTTV_FILTER_STATE_P_STATUS
:
384 se
->value
.v_uint64
= atoi(value
);
390 case LTTV_FILTER_STATE_CT
:
391 case LTTV_FILTER_STATE_IT
:
392 case LTTV_FILTER_EVENT_TIME
:
393 case LTTV_FILTER_EVENT_TSC
:
394 //se->value.v_double = atof(value);
396 * parsing logic could be optimised,
397 * but as for now, simpler this way
399 v
= g_string_new("");
400 for(i
=0;i
<strlen(value
);i
++) {
401 if(value
[i
] == '.') {
402 /* cannot specify number with more than one '.' */
403 if(is_double
) return FALSE
;
404 else is_double
= TRUE
;
406 g_string_free(v
,TRUE
);
407 v
= g_string_new("");
408 } else g_string_append_c(v
,value
[i
]);
410 /* number can be integer or double */
411 if(is_double
) t
.tv_nsec
= atoi(v
);
412 else t
.tv_sec
= atoi(v
);
414 g_string_free(v
,TRUE
);
416 se
->value
.v_ltttime
= t
;
420 g_warning("Error encountered in value assignation ! Field type = %i",se
->field
);
430 * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*)
432 * Disallocate memory for the current
434 * @param se pointer to the current LttvSimpleExpression
437 lttv_simple_expression_destroy(LttvSimpleExpression
* se
) {
439 // g_free(se->value);
441 case LTTV_FILTER_TRACE_NAME
:
442 case LTTV_FILTER_TRACEFILE_NAME
:
443 case LTTV_FILTER_STATE_P_NAME
:
444 case LTTV_FILTER_EVENT_NAME
:
445 g_free(se
->value
.v_string
);
453 * @fn gint lttv_struct_type(gint)
455 * Finds the structure type depending
456 * on the fields in parameters
457 * @params ft Field of the current structure
458 * @return LttvStructType enum or -1 for error
461 lttv_struct_type(gint ft
) {
464 case LTTV_FILTER_TRACE_NAME
:
465 return LTTV_FILTER_TRACE
;
467 case LTTV_FILTER_TRACEFILE_NAME
:
468 return LTTV_FILTER_TRACEFILE
;
470 case LTTV_FILTER_STATE_PID
:
471 case LTTV_FILTER_STATE_PPID
:
472 case LTTV_FILTER_STATE_CT
:
473 case LTTV_FILTER_STATE_IT
:
474 case LTTV_FILTER_STATE_P_NAME
:
475 case LTTV_FILTER_STATE_EX_MODE
:
476 case LTTV_FILTER_STATE_EX_SUBMODE
:
477 case LTTV_FILTER_STATE_P_STATUS
:
478 case LTTV_FILTER_STATE_CPU
:
479 return LTTV_FILTER_STATE
;
481 case LTTV_FILTER_EVENT_NAME
:
482 case LTTV_FILTER_EVENT_CATEGORY
:
483 case LTTV_FILTER_EVENT_TIME
:
484 case LTTV_FILTER_EVENT_TSC
:
485 case LTTV_FILTER_EVENT_FIELD
:
486 return LTTV_FILTER_EVENT
;
494 * @fn gboolean lttv_apply_op_eq_uint64(const gpointer,LttvFieldValue)
496 * Applies the 'equal' operator to the
497 * specified structure and value
498 * @param v1 left member of comparison
499 * @param v2 right member of comparison
500 * @return success/failure of operation
502 gboolean
lttv_apply_op_eq_uint64(const gpointer v1
, LttvFieldValue v2
) {
504 guint64
* r
= (guint64
*) v1
;
505 return (*r
== v2
.v_uint64
);
510 * @fn gboolean lttv_apply_op_eq_uint32(const gpointer,LttvFieldValue)
512 * Applies the 'equal' operator to the
513 * specified structure and value
514 * @param v1 left member of comparison
515 * @param v2 right member of comparison
516 * @return success/failure of operation
518 gboolean
lttv_apply_op_eq_uint32(const gpointer v1
, LttvFieldValue v2
) {
519 guint32
* r
= (guint32
*) v1
;
520 return (*r
== v2
.v_uint32
);
524 * @fn gboolean lttv_apply_op_eq_uint16(const gpointer,LttvFieldValue)
526 * Applies the 'equal' operator to the
527 * specified structure and value
528 * @param v1 left member of comparison
529 * @param v2 right member of comparison
530 * @return success/failure of operation
532 gboolean
lttv_apply_op_eq_uint16(const gpointer v1
, LttvFieldValue v2
) {
533 guint16
* r
= (guint16
*) v1
;
534 return (*r
== v2
.v_uint16
);
538 * @fn gboolean lttv_apply_op_eq_double(const gpointer,LttvFieldValue)
540 * Applies the 'equal' operator to the
541 * specified structure and value
542 * @param v1 left member of comparison
543 * @param v2 right member of comparison
544 * @return success/failure of operation
546 gboolean
lttv_apply_op_eq_double(const gpointer v1
, LttvFieldValue v2
) {
547 double* r
= (double*) v1
;
548 return (*r
== v2
.v_double
);
552 * @fn gboolean lttv_apply_op_eq_string(const gpointer,LttvFieldValue)
554 * Applies the 'equal' operator to the
555 * specified structure and value
556 * @param v1 left member of comparison
557 * @param v2 right member of comparison
558 * @return success/failure of operation
560 gboolean
lttv_apply_op_eq_string(const gpointer v1
, LttvFieldValue v2
) {
561 char* r
= (char*) v1
;
562 return (!g_strcasecmp(r
,v2
.v_string
));
566 * @fn gboolean lttv_apply_op_eq_quark(const gpointer,LttvFieldValue)
568 * Applies the 'equal' operator to the
569 * specified structure and value
570 * @param v1 left member of comparison
571 * @param v2 right member of comparison
572 * @return success/failure of operation
574 gboolean
lttv_apply_op_eq_quark(const gpointer v1
, LttvFieldValue v2
) {
575 GQuark
* r
= (GQuark
*) v1
;
576 g_print("v1:%i v2:%i\n",*r
,v2
.v_uint32
);
577 return (*r
== v2
.v_uint32
);
581 * @fn gboolean lttv_apply_op_eq_ltttime(const gpointer,LttvFieldValue)
583 * Applies the 'equal' operator to the
584 * specified structure and value
585 * @param v1 left member of comparison
586 * @param v2 right member of comparison
587 * @return success/failure of operation
589 gboolean
lttv_apply_op_eq_ltttime(const gpointer v1
, LttvFieldValue v2
) {
590 LttTime
* r
= (LttTime
*) v1
;
591 // return ((r->tv_sec == v2.v_ltttime.tv_sec) && (r->tv_nsec == v2.v_ltttime.tv_nsec));
592 return ltt_time_compare(*r
, v2
.v_ltttime
)==0?1:0;
597 * @fn gboolean lttv_apply_op_ne_uint64(const gpointer,LttvFieldValue)
599 * Applies the 'not equal' operator to the
600 * specified structure and value
601 * @param v1 left member of comparison
602 * @param v2 right member of comparison
603 * @return success/failure of operation
605 gboolean
lttv_apply_op_ne_uint64(const gpointer v1
, LttvFieldValue v2
) {
606 guint64
* r
= (guint64
*) v1
;
607 return (*r
!= v2
.v_uint64
);
611 * @fn gboolean lttv_apply_op_ne_uint32(const gpointer,LttvFieldValue)
613 * Applies the 'not equal' operator to the
614 * specified structure and value
615 * @param v1 left member of comparison
616 * @param v2 right member of comparison
617 * @return success/failure of operation
619 gboolean
lttv_apply_op_ne_uint32(const gpointer v1
, LttvFieldValue v2
) {
620 guint32
* r
= (guint32
*) v1
;
621 return (*r
!= v2
.v_uint32
);
625 * @fn gboolean lttv_apply_op_ne_uint16(const gpointer,LttvFieldValue)
627 * Applies the 'not equal' operator to the
628 * specified structure and value
629 * @param v1 left member of comparison
630 * @param v2 right member of comparison
631 * @return success/failure of operation
633 gboolean
lttv_apply_op_ne_uint16(const gpointer v1
, LttvFieldValue v2
) {
634 guint16
* r
= (guint16
*) v1
;
635 return (*r
!= v2
.v_uint16
);
639 * @fn gboolean lttv_apply_op_ne_double(const gpointer,LttvFieldValue)
641 * Applies the 'not equal' operator to the
642 * specified structure and value
643 * @param v1 left member of comparison
644 * @param v2 right member of comparison
645 * @return success/failure of operation
647 gboolean
lttv_apply_op_ne_double(const gpointer v1
, LttvFieldValue v2
) {
648 double* r
= (double*) v1
;
649 return (*r
!= v2
.v_double
);
653 * @fn gboolean lttv_apply_op_ne_string(const gpointer,LttvFieldValue)
655 * Applies the 'not equal' operator to the
656 * specified structure and value
657 * @param v1 left member of comparison
658 * @param v2 right member of comparison
659 * @return success/failure of operation
661 gboolean
lttv_apply_op_ne_string(const gpointer v1
, LttvFieldValue v2
) {
662 char* r
= (char*) v1
;
663 return (g_strcasecmp(r
,v2
.v_string
));
667 * @fn gboolean lttv_apply_op_ne_quark(const gpointer,LttvFieldValue)
669 * Applies the 'not equal' operator to the
670 * specified structure and value
671 * @param v1 left member of comparison
672 * @param v2 right member of comparison
673 * @return success/failure of operation
675 gboolean
lttv_apply_op_ne_quark(const gpointer v1
, LttvFieldValue v2
) {
676 GQuark
* r
= (GQuark
*) v1
;
677 return (*r
!= v2
.v_uint32
);
682 * @fn gboolean lttv_apply_op_ne_ltttime(const gpointer,LttvFieldValue)
684 * Applies the 'not equal' operator to the
685 * specified structure and value
686 * @param v1 left member of comparison
687 * @param v2 right member of comparison
688 * @return success/failure of operation
690 gboolean
lttv_apply_op_ne_ltttime(const gpointer v1
, LttvFieldValue v2
) {
691 LttTime
* r
= (LttTime
*) v1
;
692 return ltt_time_compare(*r
, v2
.v_ltttime
)!=0?1:0;
697 * @fn gboolean lttv_apply_op_lt_uint64(const gpointer,LttvFieldValue)
699 * Applies the 'lower than' operator to the
700 * specified structure and value
701 * @param v1 left member of comparison
702 * @param v2 right member of comparison
703 * @return success/failure of operation
705 gboolean
lttv_apply_op_lt_uint64(const gpointer v1
, LttvFieldValue v2
) {
706 guint64
* r
= (guint64
*) v1
;
707 return (*r
< v2
.v_uint64
);
711 * @fn gboolean lttv_apply_op_lt_uint32(const gpointer,LttvFieldValue)
713 * Applies the 'lower than' operator to the
714 * specified structure and value
715 * @param v1 left member of comparison
716 * @param v2 right member of comparison
717 * @return success/failure of operation
719 gboolean
lttv_apply_op_lt_uint32(const gpointer v1
, LttvFieldValue v2
) {
720 guint32
* r
= (guint32
*) v1
;
721 return (*r
< v2
.v_uint32
);
725 * @fn gboolean lttv_apply_op_lt_uint16(const gpointer,LttvFieldValue)
727 * Applies the 'lower than' operator to the
728 * specified structure and value
729 * @param v1 left member of comparison
730 * @param v2 right member of comparison
731 * @return success/failure of operation
733 gboolean
lttv_apply_op_lt_uint16(const gpointer v1
, LttvFieldValue v2
) {
734 guint16
* r
= (guint16
*) v1
;
735 return (*r
< v2
.v_uint16
);
739 * @fn gboolean lttv_apply_op_lt_double(const gpointer,LttvFieldValue)
741 * Applies the 'lower than' operator to the
742 * specified structure and value
743 * @param v1 left member of comparison
744 * @param v2 right member of comparison
745 * @return success/failure of operation
747 gboolean
lttv_apply_op_lt_double(const gpointer v1
, LttvFieldValue v2
) {
748 double* r
= (double*) v1
;
749 return (*r
< v2
.v_double
);
753 * @fn gboolean lttv_apply_op_lt_ltttime(const gpointer,LttvFieldValue)
755 * Applies the 'lower than' operator to the
756 * specified structure and value
757 * @param v1 left member of comparison
758 * @param v2 right member of comparison
759 * @return success/failure of operation
761 gboolean
lttv_apply_op_lt_ltttime(const gpointer v1
, LttvFieldValue v2
) {
762 LttTime
* r
= (LttTime
*) v1
;
763 // 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)));
764 return ltt_time_compare(*r
, v2
.v_ltttime
)==-1?1:0;
769 * @fn gboolean lttv_apply_op_le_uint64(const gpointer,LttvFieldValue)
771 * Applies the 'lower or equal' operator to the
772 * specified structure and value
773 * @param v1 left member of comparison
774 * @param v2 right member of comparison
775 * @return success/failure of operation
777 gboolean
lttv_apply_op_le_uint64(const gpointer v1
, LttvFieldValue v2
) {
778 guint64
* r
= (guint64
*) v1
;
779 return (*r
<= v2
.v_uint64
);
783 * @fn gboolean lttv_apply_op_le_uint32(const gpointer,LttvFieldValue)
785 * Applies the 'lower or equal' operator to the
786 * specified structure and value
787 * @param v1 left member of comparison
788 * @param v2 right member of comparison
789 * @return success/failure of operation
791 gboolean
lttv_apply_op_le_uint32(const gpointer v1
, LttvFieldValue v2
) {
792 guint32
* r
= (guint32
*) v1
;
793 return (*r
<= v2
.v_uint32
);
797 * @fn gboolean lttv_apply_op_le_uint16(const gpointer,LttvFieldValue)
799 * Applies the 'lower or equal' operator to the
800 * specified structure and value
801 * @param v1 left member of comparison
802 * @param v2 right member of comparison
803 * @return success/failure of operation
805 gboolean
lttv_apply_op_le_uint16(const gpointer v1
, LttvFieldValue v2
) {
806 guint16
* r
= (guint16
*) v1
;
807 return (*r
<= v2
.v_uint16
);
811 * @fn gboolean lttv_apply_op_le_double(const gpointer,LttvFieldValue)
813 * Applies the 'lower or equal' operator to the
814 * specified structure and value
815 * @param v1 left member of comparison
816 * @param v2 right member of comparison
817 * @return success/failure of operation
819 gboolean
lttv_apply_op_le_double(const gpointer v1
, LttvFieldValue v2
) {
820 double* r
= (double*) v1
;
821 return (*r
<= v2
.v_double
);
825 * @fn gboolean lttv_apply_op_le_ltttime(const gpointer,LttvFieldValue)
827 * Applies the 'lower or equal' operator to the
828 * specified structure and value
829 * @param v1 left member of comparison
830 * @param v2 right member of comparison
831 * @return success/failure of operation
833 gboolean
lttv_apply_op_le_ltttime(const gpointer v1
, LttvFieldValue v2
) {
834 LttTime
* r
= (LttTime
*) v1
;
835 // 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)));
836 return ltt_time_compare(*r
, v2
.v_ltttime
)<1?1:0;
841 * @fn gboolean lttv_apply_op_gt_uint64(const gpointer,LttvFieldValue)
843 * Applies the 'greater than' operator to the
844 * specified structure and value
845 * @param v1 left member of comparison
846 * @param v2 right member of comparison
847 * @return success/failure of operation
849 gboolean
lttv_apply_op_gt_uint64(const gpointer v1
, LttvFieldValue v2
) {
850 guint64
* r
= (guint64
*) v1
;
851 return (*r
> v2
.v_uint64
);
855 * @fn gboolean lttv_apply_op_gt_uint32(const gpointer,LttvFieldValue)
857 * Applies the 'greater than' operator to the
858 * specified structure and value
859 * @param v1 left member of comparison
860 * @param v2 right member of comparison
861 * @return success/failure of operation
863 gboolean
lttv_apply_op_gt_uint32(const gpointer v1
, LttvFieldValue v2
) {
864 guint32
* r
= (guint32
*) v1
;
865 return (*r
> v2
.v_uint32
);
869 * @fn gboolean lttv_apply_op_gt_uint16(const gpointer,LttvFieldValue)
871 * Applies the 'greater than' operator to the
872 * specified structure and value
873 * @param v1 left member of comparison
874 * @param v2 right member of comparison
875 * @return success/failure of operation
877 gboolean
lttv_apply_op_gt_uint16(const gpointer v1
, LttvFieldValue v2
) {
878 guint16
* r
= (guint16
*) v1
;
879 return (*r
> v2
.v_uint16
);
883 * @fn gboolean lttv_apply_op_gt_double(const gpointer,LttvFieldValue)
885 * Applies the 'greater than' operator to the
886 * specified structure and value
887 * @param v1 left member of comparison
888 * @param v2 right member of comparison
889 * @return success/failure of operation
891 gboolean
lttv_apply_op_gt_double(const gpointer v1
, LttvFieldValue v2
) {
892 double* r
= (double*) v1
;
893 return (*r
> v2
.v_double
);
897 * @fn gboolean lttv_apply_op_gt_ltttime(const gpointer,LttvFieldValue)
899 * Applies the 'greater than' operator to the
900 * specified structure and value
901 * @param v1 left member of comparison
902 * @param v2 right member of comparison
903 * @return success/failure of operation
905 gboolean
lttv_apply_op_gt_ltttime(const gpointer v1
, LttvFieldValue v2
) {
906 LttTime
* r
= (LttTime
*) v1
;
907 // 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)));
908 return ltt_time_compare(*r
, v2
.v_ltttime
)==1?1:0;
913 * @fn gboolean lttv_apply_op_ge_uint64(const gpointer,LttvFieldValue)
915 * Applies the 'greater or equal' operator to the
916 * specified structure and value
917 * @param v1 left member of comparison
918 * @param v2 right member of comparison
919 * @return success/failure of operation
921 gboolean
lttv_apply_op_ge_uint64(const gpointer v1
, LttvFieldValue v2
) {
922 guint64
* r
= (guint64
*) v1
;
923 return (*r
>= v2
.v_uint64
);
927 * @fn gboolean lttv_apply_op_ge_uint32(const gpointer,LttvFieldValue)
929 * Applies the 'greater or equal' operator to the
930 * specified structure and value
931 * @param v1 left member of comparison
932 * @param v2 right member of comparison
933 * @return success/failure of operation
935 gboolean
lttv_apply_op_ge_uint32(const gpointer v1
, LttvFieldValue v2
) {
936 guint32
* r
= (guint32
*) v1
;
937 return (*r
>= v2
.v_uint32
);
941 * @fn gboolean lttv_apply_op_ge_uint16(const gpointer,LttvFieldValue)
943 * Applies the 'greater or equal' operator to the
944 * specified structure and value
945 * @param v1 left member of comparison
946 * @param v2 right member of comparison
947 * @return success/failure of operation
949 gboolean
lttv_apply_op_ge_uint16(const gpointer v1
, LttvFieldValue v2
) {
950 guint16
* r
= (guint16
*) v1
;
951 return (*r
>= v2
.v_uint16
);
955 * @fn gboolean lttv_apply_op_ge_double(const gpointer,LttvFieldValue)
957 * Applies the 'greater or equal' operator to the
958 * specified structure and value
959 * @param v1 left member of comparison
960 * @param v2 right member of comparison
961 * @return success/failure of operation
963 gboolean
lttv_apply_op_ge_double(const gpointer v1
, LttvFieldValue v2
) {
964 double* r
= (double*) v1
;
965 return (*r
>= v2
.v_double
);
969 * @fn gboolean lttv_apply_op_ge_ltttime(const gpointer,LttvFieldValue)
971 * Applies the 'greater or equal' operator to the
972 * specified structure and value
973 * @param v1 left member of comparison
974 * @param v2 right member of comparison
975 * @return success/failure of operation
977 gboolean
lttv_apply_op_ge_ltttime(const gpointer v1
, LttvFieldValue v2
) {
978 LttTime
* r
= (LttTime
*) v1
;
979 // 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)));
980 return ltt_time_compare(*r
, v2
.v_ltttime
)>-1?1:0;
986 * @fn LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree*)
988 * Makes a copy of the current filter tree
989 * @param tree pointer to the current tree
990 * @return new copy of the filter tree
993 lttv_filter_tree_clone(const LttvFilterTree
* tree
) {
995 LttvFilterTree
* newtree
= lttv_filter_tree_new();
997 newtree
->node
= tree
->node
;
999 newtree
->left
= tree
->left
;
1000 if(newtree
->left
== LTTV_TREE_NODE
) {
1001 newtree
->l_child
.t
= lttv_filter_tree_clone(tree
->l_child
.t
);
1002 } else if(newtree
->left
== LTTV_TREE_LEAF
) {
1003 newtree
->l_child
.leaf
= lttv_simple_expression_new();
1004 newtree
->l_child
.leaf
->field
= tree
->l_child
.leaf
->field
;
1005 newtree
->l_child
.leaf
->offset
= tree
->l_child
.leaf
->offset
;
1006 newtree
->l_child
.leaf
->op
= tree
->l_child
.leaf
->op
;
1007 /* FIXME: special case for string copy ! */
1008 newtree
->l_child
.leaf
->value
= tree
->l_child
.leaf
->value
;
1011 newtree
->right
= tree
->right
;
1012 if(newtree
->right
== LTTV_TREE_NODE
) {
1013 newtree
->r_child
.t
= lttv_filter_tree_clone(tree
->r_child
.t
);
1014 } else if(newtree
->right
== LTTV_TREE_LEAF
) {
1015 newtree
->r_child
.leaf
= lttv_simple_expression_new();
1016 newtree
->r_child
.leaf
->field
= tree
->r_child
.leaf
->field
;
1017 newtree
->r_child
.leaf
->offset
= tree
->r_child
.leaf
->offset
;
1018 newtree
->r_child
.leaf
->op
= tree
->r_child
.leaf
->op
;
1019 newtree
->r_child
.leaf
->value
= tree
->r_child
.leaf
->value
;
1027 * @fn LttvFilter* lttv_filter_clone(LttvFilter*)
1029 * Makes a copy of the current filter
1030 * @param filter pointer to the current filter
1031 * @return new copy of the filter
1034 lttv_filter_clone(const LttvFilter
* filter
) {
1036 LttvFilter
* newfilter
= g_new(LttvFilter
,1);
1038 // newfilter->expression = g_new(char,1)
1039 strcpy(newfilter
->expression
,filter
->expression
);
1041 newfilter
->head
= lttv_filter_tree_clone(filter
->head
);
1049 * @fn LttvFilter* lttv_filter_new()
1051 * Creates a new lttv_filter
1052 * @param expression filtering options string
1053 * @param t pointer to the current LttvTrace
1054 * @return the current lttv_filter or NULL if error
1059 LttvFilter
* filter
= g_new(LttvFilter
,1);
1060 filter
->expression
= NULL
;
1061 filter
->head
= NULL
;
1066 * @fn gboolean lttv_filter_update(LttvFilter*)
1068 * Updates the current LttvFilter by building
1069 * its tree based upon the expression string
1070 * @param filter pointer to the current LttvFilter
1071 * @return Failure/Success of operation
1074 lttv_filter_update(LttvFilter
* filter
) {
1076 // g_print("filter::lttv_filter_new()\n"); /* debug */
1078 if(filter
->expression
== NULL
) return FALSE
;
1082 p_nesting
=0; /* parenthesis nesting value */
1086 *tree
= lttv_filter_tree_new(), /* main tree */
1087 *subtree
= NULL
, /* buffer for subtrees */
1088 *t1
, /* buffer #1 */
1089 *t2
; /* buffer #2 */
1093 * If the tree already exists,
1094 * destroy it and build a new one
1096 if(filter
->head
!= NULL
) lttv_filter_tree_destroy(filter
->head
);
1097 filter
->head
= NULL
; /* will be assigned at the end */
1101 * each element of the list
1102 * is a sub tree created
1103 * by the use of parenthesis in the
1104 * global expression. The final tree
1105 * will be the one left at the root of
1108 GPtrArray
*tree_stack
= g_ptr_array_new();
1109 g_ptr_array_add( tree_stack
,(gpointer
) tree
);
1111 /* temporary values */
1112 GString
*a_field_component
= g_string_new("");
1113 GPtrArray
*a_field_path
= g_ptr_array_new();
1115 /* simple expression buffer */
1116 LttvSimpleExpression
* a_simple_expression
= lttv_simple_expression_new();
1119 * Parse entire expression and construct
1120 * the binary tree. There are two steps
1121 * in browsing that string
1122 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
1123 * 2. finding simple expressions
1124 * - field path ( separated by dots )
1125 * - op ( >, <, =, >=, <=, !=)
1126 * - value ( integer, string ... )
1127 * To spare computing time, the whole
1128 * string is parsed in this loop for a
1129 * O(n) complexity order.
1131 * When encountering logical op &,|,^
1132 * 1. parse the last value if any
1133 * 2. create a new tree
1134 * 3. add the expression (simple exp, or exp (subtree)) to the tree
1135 * 4. concatenate this tree with the current tree on top of the stack
1136 * When encountering math ops >,>=,<,<=,=,!=
1137 * 1. add to op to the simple expression
1138 * 2. concatenate last field component to field path
1139 * When encountering concatening ops .
1140 * 1. concatenate last field component to field path
1141 * When encountering opening parenthesis (,{,[
1142 * 1. create a new subtree on top of tree stack
1143 * When encountering closing parenthesis ),},]
1144 * 1. add the expression on right child of the current tree
1145 * 2. the subtree is completed, allocate a new subtree
1146 * 3. pop the tree value from the tree stack
1149 for(i
=0;i
<strlen(filter
->expression
);i
++) {
1151 //g_print("%c ",filter->expression[i]);
1153 switch(filter
->expression
[i
]) {
1159 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1160 while(t1
->right
!= LTTV_TREE_IDLE
) {
1161 g_assert(t1
->right
== LTTV_TREE_NODE
);
1164 t2
= lttv_filter_tree_new();
1165 t2
->node
= LTTV_LOGICAL_AND
;
1166 if(subtree
!= NULL
) { /* append subtree to current tree */
1167 t2
->left
= LTTV_TREE_NODE
;
1168 t2
->l_child
.t
= subtree
;
1170 t1
->right
= LTTV_TREE_NODE
;
1172 } else { /* append a simple expression */
1173 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1174 a_field_component
= g_string_new("");
1175 t2
->left
= LTTV_TREE_LEAF
;
1176 t2
->l_child
.leaf
= a_simple_expression
;
1177 a_simple_expression
= lttv_simple_expression_new();
1178 t1
->right
= LTTV_TREE_NODE
;
1185 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1186 while(t1
->right
!= LTTV_TREE_IDLE
) {
1187 g_assert(t1
->right
== LTTV_TREE_NODE
);
1190 t2
= lttv_filter_tree_new();
1191 t2
->node
= LTTV_LOGICAL_OR
;
1192 if(subtree
!= NULL
) { /* append subtree to current tree */
1193 t2
->left
= LTTV_TREE_NODE
;
1194 t2
->l_child
.t
= subtree
;
1196 t1
->right
= LTTV_TREE_NODE
;
1198 } else { /* append a simple expression */
1199 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1200 a_field_component
= g_string_new("");
1201 t2
->left
= LTTV_TREE_LEAF
;
1202 t2
->l_child
.leaf
= a_simple_expression
;
1203 a_simple_expression
= lttv_simple_expression_new();
1204 t1
->right
= LTTV_TREE_NODE
;
1211 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1212 while(t1
->right
!= LTTV_TREE_IDLE
) {
1213 g_assert(t1
->right
== LTTV_TREE_NODE
);
1216 t2
= lttv_filter_tree_new();
1217 t2
->node
= LTTV_LOGICAL_XOR
;
1218 if(subtree
!= NULL
) { /* append subtree to current tree */
1219 t2
->left
= LTTV_TREE_NODE
;
1220 t2
->l_child
.t
= subtree
;
1222 t1
->right
= LTTV_TREE_NODE
;
1224 } else { /* append a simple expression */
1225 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1226 a_field_component
= g_string_new("");
1227 t2
->left
= LTTV_TREE_LEAF
;
1228 t2
->l_child
.leaf
= a_simple_expression
;
1229 a_simple_expression
= lttv_simple_expression_new();
1230 t1
->right
= LTTV_TREE_NODE
;
1235 case '!': /* not, or not equal (math op) */
1237 if(filter
->expression
[i
+1] == '=') { /* != */
1238 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1239 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1240 a_field_component
= g_string_new("");
1241 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_NE
);
1244 t1
= (LttvFilterTree
*)g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1245 while(t1
->right
!= LTTV_TREE_IDLE
) {
1246 g_assert(t1
->right
== LTTV_TREE_NODE
);
1249 t2
= lttv_filter_tree_new();
1250 t2
->node
= LTTV_LOGICAL_NOT
;
1251 t1
->right
= LTTV_TREE_NODE
;
1256 case '(': /* start of parenthesis */
1260 p_nesting
++; /* incrementing parenthesis nesting value */
1261 t1
= lttv_filter_tree_new();
1262 g_ptr_array_add( tree_stack
,(gpointer
) t1
);
1265 case ')': /* end of parenthesis */
1269 p_nesting
--; /* decrementing parenthesis nesting value */
1270 if(p_nesting
<0 || tree_stack
->len
<2) {
1271 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1272 is not valid due to parenthesis incorrect use",filter
->expression
);
1276 /* there must at least be the root tree left in the array */
1277 g_assert(tree_stack
->len
>0);
1279 if(subtree
!= NULL
) { /* append subtree to current tree */
1280 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1281 while(t1
->right
!= LTTV_TREE_IDLE
) {
1282 g_assert(t1
->right
== LTTV_TREE_NODE
);
1285 t1
->right
= LTTV_TREE_NODE
;
1286 t1
->r_child
.t
= subtree
;
1287 subtree
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1288 g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1289 } else { /* assign subtree as current tree */
1290 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1291 a_field_component
= g_string_new("");
1292 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1293 while(t1
->right
!= LTTV_TREE_IDLE
) {
1294 g_assert(t1
->right
== LTTV_TREE_NODE
);
1295 g_assert(t1
->r_child
.t
!= NULL
);
1298 t1
->right
= LTTV_TREE_LEAF
;
1299 t1
->r_child
.leaf
= a_simple_expression
;
1300 a_simple_expression
= lttv_simple_expression_new();
1301 subtree
= g_ptr_array_remove_index(tree_stack
,tree_stack
->len
-1);
1306 * mathematic operators
1308 case '<': /* lower, lower or equal */
1310 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1311 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1312 a_field_component
= g_string_new("");
1313 if(filter
->expression
[i
+1] == '=') { /* <= */
1315 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LE
);
1316 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_LT
);
1319 case '>': /* higher, higher or equal */
1321 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1322 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1323 a_field_component
= g_string_new("");
1324 if(filter
->expression
[i
+1] == '=') { /* >= */
1326 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GE
);
1327 } else lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_GT
);
1330 case '=': /* equal */
1332 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1333 lttv_simple_expression_assign_field(a_field_path
,a_simple_expression
);
1334 a_field_component
= g_string_new("");
1335 lttv_simple_expression_assign_operator(a_simple_expression
,LTTV_FIELD_EQ
);
1339 * Field concatening caracter
1344 * divide field expression into elements
1345 * in a_field_path array.
1347 * A dot can also be present in double values
1349 if(a_simple_expression
->field
== LTTV_FILTER_UNDEFINED
) {
1350 g_ptr_array_add( a_field_path
,(gpointer
) a_field_component
);
1351 a_field_component
= g_string_new("");
1354 case ' ': /* ignore */
1355 case '\n': /* ignore */
1357 default: /* concatening current string */
1358 g_string_append_c(a_field_component
,filter
->expression
[i
]);
1363 * Preliminary check to see
1364 * if tree was constructed correctly
1367 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1368 is not valid due to parenthesis incorrect use",filter
->expression
);
1372 if(tree_stack
->len
!= 1) /* only root tree should remain */
1375 /* processing last element of expression */
1376 t1
= g_ptr_array_index(tree_stack
,tree_stack
->len
-1);
1377 while(t1
->right
!= LTTV_TREE_IDLE
) {
1378 g_assert(t1
->right
== LTTV_TREE_NODE
);
1381 if(subtree
!= NULL
) { /* add the subtree */
1382 t1
->right
= LTTV_TREE_NODE
;
1383 t1
->r_child
.t
= subtree
;
1385 } else { /* add a leaf */
1386 lttv_simple_expression_assign_value(a_simple_expression
,g_string_free(a_field_component
,FALSE
));
1387 a_field_component
= NULL
;
1388 t1
->right
= LTTV_TREE_LEAF
;
1389 t1
->r_child
.leaf
= a_simple_expression
;
1390 a_simple_expression
= NULL
;
1394 /* free the pointer array */
1395 g_assert(a_field_path
->len
== 0);
1396 g_ptr_array_free(a_field_path
,TRUE
);
1398 /* free the tree stack -- but keep the root tree */
1399 filter
->head
= g_ptr_array_remove_index(tree_stack
,0);
1400 g_ptr_array_free(tree_stack
,TRUE
);
1402 /* free the field buffer if allocated */
1403 if(a_field_component
!= NULL
) g_string_free(a_field_component
,TRUE
);
1405 /* free the simple expression buffer if allocated */
1406 if(a_simple_expression
!= NULL
) lttv_simple_expression_destroy(a_simple_expression
);
1408 g_assert(filter
->head
!= NULL
); /* tree should exist */
1409 g_assert(subtree
== NULL
); /* remaining subtree should be included in main tree */
1412 g_print("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1413 lttv_print_tree(filter
->head
) ;
1414 g_print("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1422 * @fn void lttv_filter_destroy(LttvFilter*)
1424 * Destroy the current LttvFilter
1425 * @param filter pointer to the current LttvFilter
1428 lttv_filter_destroy(LttvFilter
* filter
) {
1430 g_free(filter
->expression
);
1431 lttv_filter_tree_destroy(filter
->head
);
1437 * @fn LttvFilterTree* lttv_filter_tree_new()
1439 * Assign a new tree for the current expression
1441 * @return pointer of LttvFilterTree
1444 lttv_filter_tree_new() {
1445 LttvFilterTree
* tree
;
1447 tree
= g_new(LttvFilterTree
,1);
1448 tree
->node
= 0; //g_new(lttv_expression,1);
1449 tree
->left
= LTTV_TREE_IDLE
;
1450 tree
->right
= LTTV_TREE_IDLE
;
1451 tree
->r_child
.t
= NULL
;
1452 tree
->l_child
.t
= NULL
;
1458 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1460 * Append a new expression to the expression
1461 * defined in the current filter
1462 * @param filter pointer to the current LttvFilter
1463 * @param expression string that must be appended
1464 * @return Success/Failure of operation
1466 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, char *expression
) {
1468 if(expression
== NULL
) return FALSE
;
1469 if(filter
== NULL
) {
1470 filter
= lttv_filter_new();
1471 filter
->expression
= expression
;
1472 } else if(filter
->expression
== NULL
) {
1473 filter
->expression
= expression
;
1475 filter
->expression
= g_strconcat(filter
->expression
,"&",expression
);
1477 /* clear expression */
1481 return lttv_filter_update(filter
);
1486 * @fn void lttv_filter_clear_expression(LttvFilter*)
1488 * Clear the filter expression from the
1489 * current filter and sets its pointer to NULL
1490 * @param filter pointer to the current LttvFilter
1492 void lttv_filter_clear_expression(LttvFilter
* filter
) {
1494 if(filter
->expression
!= NULL
) {
1495 g_free(filter
->expression
);
1496 filter
->expression
= NULL
;
1502 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1504 * Destroys the tree and his sub-trees
1505 * @param tree Tree which must be destroyed
1508 lttv_filter_tree_destroy(LttvFilterTree
* tree
) {
1510 if(tree
== NULL
) return;
1512 if(tree
->left
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->l_child
.leaf
);
1513 else if(tree
->left
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->l_child
.t
);
1515 if(tree
->right
== LTTV_TREE_LEAF
) lttv_simple_expression_destroy(tree
->r_child
.leaf
);
1516 else if(tree
->right
== LTTV_TREE_NODE
) lttv_filter_tree_destroy(tree
->r_child
.t
);
1518 // g_free(tree->node);
1523 * @fn gboolean lttv_filter_tree_parse(LttvFilterTree*,LttEvent,LttTracefile,LttTrace,LttvProcessState)
1525 * Global parsing function for the current
1527 * @param tree pointer to the current LttvFilterTree
1528 * @param event current LttEvent, NULL if not used
1529 * @param tracefile current LttTracefile, NULL if not used
1530 * @param trace current LttTrace, NULL if not used
1531 * @param state current LttvProcessState, NULL if not used
1532 * @param context current LttvTracefileContext, NULL if not used
1533 * @return response of filter
1536 lttv_filter_tree_parse(
1537 const LttvFilterTree
* t
,
1538 const LttEvent
* event
,
1539 const LttTracefile
* tracefile
,
1540 const LttTrace
* trace
,
1541 const LttvProcessState
* state
,
1542 const LttvTracefileContext
* context
1547 * Each tree is parsed in inorder.
1548 * This way, it's possible to apply the left filter of the
1549 * tree, then decide whether or not the right branch should
1550 * be parsed depending on the linking logical operator
1552 * Each node consists in a
1553 * 1. logical operator
1554 * 2. left child ( node or simple expression )
1555 * 3. right child ( node or simple expression )
1557 * When the child is a simple expression, we must
1558 * before all determine if the expression refers to
1559 * a structure which is whithin observation ( not NULL ).
1560 * -If so, the expression is evaluated.
1561 * -If not, the result is set to TRUE since this particular
1562 * operation does not interfere with the lttv structure
1564 * The result of each simple expression will directly
1565 * affect the next branch. This way, depending on
1566 * the linking logical operator, the parser will decide
1567 * to explore or not the next branch.
1569 * -If result of left branch is 0 / FALSE
1570 * then don't explore right branch and return 0;
1571 * -If result of left branch is 1 / TRUE then explore
1573 * -If result of left branch is 1 / TRUE
1574 * then don't explore right branch and return 1;
1575 * -If result of left branch is 0 / FALSE then explore
1577 * -Result of left branch will not affect exploration of
1581 gboolean lresult
= FALSE
, rresult
= FALSE
;
1586 if(t
->left
== LTTV_TREE_NODE
) {
1587 lresult
= lttv_filter_tree_parse(t
->l_child
.t
,event
,tracefile
,trace
,state
,context
);
1589 else if(t
->left
== LTTV_TREE_LEAF
) {
1590 lresult
= lttv_filter_tree_parse_branch(t
->l_child
.leaf
,event
,tracefile
,trace
,state
,context
);
1594 * Parse linking operator
1595 * make a cutoff if possible
1597 if((t
->node
& LTTV_LOGICAL_OR
) && lresult
== TRUE
) return TRUE
;
1598 if((t
->node
& LTTV_LOGICAL_AND
) && lresult
== FALSE
) return FALSE
;
1601 * Parse right branch
1603 if(t
->right
== LTTV_TREE_NODE
) {
1604 rresult
= lttv_filter_tree_parse(t
->r_child
.t
,event
,tracefile
,trace
,state
,context
);
1606 else if(t
->right
== LTTV_TREE_LEAF
) {
1607 rresult
= lttv_filter_tree_parse_branch(t
->r_child
.leaf
,event
,tracefile
,trace
,state
,context
);
1611 * Apply and return the
1612 * logical link between the
1616 case LTTV_LOGICAL_OR
: return (lresult
| rresult
);
1617 case LTTV_LOGICAL_AND
: return (lresult
& rresult
);
1618 case LTTV_LOGICAL_NOT
: return (!rresult
);
1619 case LTTV_LOGICAL_XOR
: return (lresult
^ rresult
);
1620 case 0: return (rresult
);
1623 * This case should never be
1624 * parsed, if so, this subtree
1633 * @fn gboolean lttv_filter_tree_parse_branch(LttvFilterTree*,LttEvent*,LttTracefile*,LttTrace*,LttvProcessState*,LttvTracefileContext*)
1635 * This function parses a particular branch of the tree
1636 * @param tree pointer to the current LttvFilterTree
1637 * @param event current LttEvent, NULL if not used
1638 * @param tracefile current LttTracefile, NULL if not used
1639 * @param trace current LttTrace, NULL if not used
1640 * @param state current LttvProcessState, NULL if not used
1641 * @param context current LttvTracefileContext, NULL if not used
1642 * @return response of filter
1644 gboolean
lttv_filter_tree_parse_branch(
1645 const LttvSimpleExpression
* se
,
1646 const LttEvent
* event
,
1647 const LttTracefile
* tracefile
,
1648 const LttTrace
* trace
,
1649 const LttvProcessState
* state
,
1650 const LttvTracefileContext
* context
) {
1655 case LTTV_FILTER_TRACE_NAME
:
1656 if(trace
== NULL
) return TRUE
;
1658 GQuark quark
= g_quark_try_string(ltt_trace_name(trace
));
1659 return se
->op((gpointer
)&quark
,v
);
1662 case LTTV_FILTER_TRACEFILE_NAME
:
1663 if(tracefile
== NULL
) return TRUE
;
1665 GQuark quark
= g_quark_try_string(ltt_tracefile_name(tracefile
));
1666 return se
->op((gpointer
)&quark
,v
);
1669 case LTTV_FILTER_STATE_PID
:
1670 if(state
== NULL
) return TRUE
;
1671 else return se
->op((gpointer
)&state
->pid
,v
);
1673 case LTTV_FILTER_STATE_PPID
:
1674 if(state
== NULL
) return TRUE
;
1675 else return se
->op((gpointer
)&state
->ppid
,v
);
1677 case LTTV_FILTER_STATE_CT
:
1678 if(state
== NULL
) return TRUE
;
1680 return se
->op((gpointer
)&state
->creation_time
,v
);
1683 case LTTV_FILTER_STATE_IT
:
1684 if(state
== NULL
) return TRUE
;
1686 return se
->op((gpointer
)&state
->insertion_time
,v
);
1689 case LTTV_FILTER_STATE_P_NAME
:
1691 * All 'unnamed' for the moment
1693 if(state
== NULL
) return TRUE
;
1695 GQuark quark
= g_quark_try_string(state
->name
);
1696 return se
->op((gpointer
)&quark
,v
);
1699 case LTTV_FILTER_STATE_EX_MODE
:
1700 if(state
== NULL
) return TRUE
;
1701 else return se
->op((gpointer
)&state
->state
->t
,v
);
1703 case LTTV_FILTER_STATE_EX_SUBMODE
:
1704 if(state
== NULL
) return TRUE
;
1705 else return se
->op((gpointer
)&state
->state
->n
,v
);
1707 case LTTV_FILTER_STATE_P_STATUS
:
1708 if(state
== NULL
) return TRUE
;
1709 else return se
->op((gpointer
)&state
->state
->s
,v
);
1711 case LTTV_FILTER_STATE_CPU
:
1712 if(context
== NULL
) return TRUE
;
1714 /* FIXME: not sure of that one */
1715 return se
->op((gpointer
)g_quark_try_string(((LttvTracefileState
*)context
)->cpu_name
),v
);
1718 case LTTV_FILTER_EVENT_NAME
:
1719 if(event
== NULL
) return TRUE
;
1722 et
= ltt_event_eventtype(event
);
1723 g_print("v:%s\n",ltt_eventtype_name(et
));
1724 GQuark quark
= g_quark_try_string(ltt_eventtype_name(et
));
1725 return se
->op((gpointer
)&quark
,v
);
1729 case LTTV_FILTER_EVENT_CATEGORY
:
1731 * TODO: Not yet implemented
1735 case LTTV_FILTER_EVENT_TIME
:
1736 if(event
== NULL
) return TRUE
;
1738 LttTime time
= ltt_event_time(event
);
1739 return se
->op((gpointer
)&time
,v
);
1742 case LTTV_FILTER_EVENT_TSC
:
1743 // if(event == NULL) return TRUE;
1745 // double val = ltt_time_to_double(event->event_time);
1746 // return se->op((gpointer)&val,v);
1749 * FIXME: Where is event.tsc
1753 case LTTV_FILTER_EVENT_FIELD
:
1755 * TODO: Use the offset to
1756 * find the dynamic field
1757 * in the event struct
1762 * This case should never be
1763 * parsed, if so, the whole
1764 * filtering is cancelled
1766 g_warning("Error while parsing the filter tree");
1770 /* should never get here */
1778 * @fn void lttv_print_tree(LttvFilterTree*)
1781 * @param t the pointer to the current LttvFilterTree
1784 lttv_print_tree(const LttvFilterTree
* t
) {
1786 g_print("node:%p lchild:%p rchild:%p\n",t
, //t->l_child.t,t->r_child.t);
1787 (t
->left
==LTTV_TREE_NODE
)?t
->l_child
.t
:NULL
,
1788 (t
->right
==LTTV_TREE_NODE
)?t
->r_child
.t
:NULL
);
1789 g_print("node type: %i / [left] %i / [right] %i\n",t
->node
,t
->left
,t
->right
);
1790 if(t
->left
== LTTV_TREE_NODE
) lttv_print_tree(t
->l_child
.t
);
1791 else if(t
->left
== LTTV_TREE_LEAF
) {
1792 g_print("%p: left is %i %p value\n",t
,t
->l_child
.leaf
->field
,t
->l_child
.leaf
->op
);
1794 if(t
->right
== LTTV_TREE_NODE
) lttv_print_tree(t
->r_child
.t
);
1795 else if(t
->right
== LTTV_TREE_LEAF
) {
1796 g_print("%p: right is %i %p value\n",t
,t
->r_child
.leaf
->field
,t
->r_child
.leaf
->op
);
1802 * @fn static void module_init()
1804 * Initializes the filter module and specific values
1806 static void module_init()
1812 * @fn Destroys the filter module and specific values
1814 static void module_destroy()
1820 LTTV_MODULE("filter", "Filters traceset and events", \
1821 "Filters traceset and events specifically to user input", \
1822 module_init
, module_destroy
)