thread brand
[lttv.git] / ltt / branches / poly / lttv / lttv / filter.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2005 Michel Dagenais and Simon Bouvier-Zappa
3 *
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;
7 *
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.
12 *
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,
16 * MA 02111-1307, USA.
17 */
18
19 /*! \file lttv/lttv/filter.c
20 * \brief Defines the core filter of application
21 *
22 * consist in AND, OR and NOT nested expressions, forming a tree with
23 * simple relations as leaves. The simple relations test if a field
24 * in an event is equal, not equal, smaller, smaller or equal, larger, or
25 * larger or equal to a specified value.
26 *
27 * Fields specified in a simple expression can take following
28 * values
29 *
30 * \verbatim
31 * LttvTracefileContext{}
32 * |->event\
33 * | |->name (String, converted to GQuark)
34 * | |->facility (String, converted to GQuark)
35 * | |->category (String, not yet implemented)
36 * | |->time (LttTime)
37 * | |->tsc (LttCycleCount --> uint64)
38 * | |->fields
39 * | |->"facility_name
40 * | |->"event name"
41 * | |->"field name"
42 * | |->"sub-field name"
43 * | |->...
44 * | |->"leaf-field name" (field type)
45 * |->tracefile
46 * | |->name (String, converted to GQuark)
47 * |->trace
48 * | |->name (String, converted to GQuark)
49 * |->state
50 * |->pid (guint)
51 * |->ppid (guint)
52 * |->creation_time (LttTime)
53 * |->insertion_time (LttTime)
54 * |->process_name (String, converted to GQuark)
55 * |->thread_brand (String, converted to GQuark)
56 * |->execution_mode (LttvExecutionMode)
57 * |->execution_submode (LttvExecutionSubmode)
58 * |->process_status (LttvProcessStatus)
59 * |->cpu (guint)
60 * \endverbatim
61 */
62
63 /*
64 * \todo
65 * - refine switch of expression in multiple uses functions
66 * - remove the idle expressions in the tree
67 */
68
69 #ifdef HAVE_CONFIG_H
70 #include <config.h>
71 #endif
72
73 //#define TEST
74 #ifdef TEST
75 #include <time.h>
76 #include <sys/time.h>
77 #endif
78
79 #include <lttv/lttv.h>
80 #include <lttv/filter.h>
81 #include <ltt/trace.h>
82 #include <ltt/type.h>
83 #include <ltt/facility.h>
84 #include <stdlib.h>
85 #include <string.h>
86
87 /**
88 * @fn LttvSimpleExpression* lttv_simple_expression_new()
89 *
90 * Constructor for LttvSimpleExpression
91 * @return pointer to new LttvSimpleExpression
92 */
93 LttvSimpleExpression*
94 lttv_simple_expression_new() {
95
96 LttvSimpleExpression* se = g_new(LttvSimpleExpression,1);
97
98 se->field = LTTV_FILTER_UNDEFINED;
99 se->op = NULL;
100 se->offset = 0;
101
102 return se;
103 }
104
105 /**
106 * @fn gboolean lttv_simple_expression_assign_field(GPtrArray*,LttvSimpleExpression*)
107 *
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
114 */
115 gboolean
116 lttv_simple_expression_assign_field(GPtrArray* fp, LttvSimpleExpression* se) {
117
118 GString* f = NULL;
119
120 if(fp->len < 2) return FALSE;
121 g_assert((f=g_ptr_array_remove_index(fp,0)));
122
123 /*
124 * Parse through the specified
125 * hardcoded fields.
126 *
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
134 * as a dynamic field
135 */
136 if(!g_strcasecmp(f->str,"trace") ) {
137 /*
138 * Possible values:
139 * trace.name
140 */
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;
145 }
146 } else if(!g_strcasecmp(f->str,"traceset") ) {
147 /*
148 * FIXME: not yet implemented !
149 */
150 } else if(!g_strcasecmp(f->str,"tracefile") ) {
151 /*
152 * Possible values:
153 * tracefile.name
154 */
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;
159 }
160 } else if(!g_strcasecmp(f->str,"state") ) {
161 /*
162 * Possible values:
163 * state.pid
164 * state.ppid
165 * state.creation_time
166 * state.insertion_time
167 * state.process_name
168 * state.thread_brand
169 * state.execution_mode
170 * state.execution_submode
171 * state.process_status
172 * state.cpu
173 */
174 g_string_free(f,TRUE);
175 f=g_ptr_array_remove_index(fp,0);
176 if(!g_strcasecmp(f->str,"pid") ) {
177 se->field = LTTV_FILTER_STATE_PID;
178 }
179 else if(!g_strcasecmp(f->str,"ppid") ) {
180 se->field = LTTV_FILTER_STATE_PPID;
181 }
182 else if(!g_strcasecmp(f->str,"creation_time") ) {
183 se->field = LTTV_FILTER_STATE_CT;
184 }
185 else if(!g_strcasecmp(f->str,"insertion_time") ) {
186 se->field = LTTV_FILTER_STATE_IT;
187 }
188 else if(!g_strcasecmp(f->str,"process_name") ) {
189 se->field = LTTV_FILTER_STATE_P_NAME;
190 }
191 else if(!g_strcasecmp(f->str,"thread_brand") ) {
192 se->field = LTTV_FILTER_STATE_T_BRAND;
193 }
194 else if(!g_strcasecmp(f->str,"execution_mode") ) {
195 se->field = LTTV_FILTER_STATE_EX_MODE;
196 }
197 else if(!g_strcasecmp(f->str,"execution_submode") ) {
198 se->field = LTTV_FILTER_STATE_EX_SUBMODE;
199 }
200 else if(!g_strcasecmp(f->str,"process_status") ) {
201 se->field = LTTV_FILTER_STATE_P_STATUS;
202 }
203 else if(!g_strcasecmp(f->str,"cpu") ) {
204 se->field = LTTV_FILTER_STATE_CPU;
205 }
206 } else if(!g_strcasecmp(f->str,"event") ) {
207 /*
208 * Possible values:
209 * event.name
210 * event.category
211 * event.time
212 * event.tsc
213 * event.field
214 */
215 g_string_free(f,TRUE);
216 f=g_ptr_array_remove_index(fp,0);
217 if(!g_strcasecmp(f->str,"name") ) {
218 se->field = LTTV_FILTER_EVENT_NAME;
219 }
220 else if(!g_strcasecmp(f->str,"facility") ) {
221 se->field = LTTV_FILTER_EVENT_FACILITY;
222 }
223 else if(!g_strcasecmp(f->str,"category") ) {
224 /*
225 * FIXME: Category not yet functional in lttv
226 */
227 se->field = LTTV_FILTER_EVENT_CATEGORY;
228 }
229 else if(!g_strcasecmp(f->str,"time") ) {
230 se->field = LTTV_FILTER_EVENT_TIME;
231 }
232 else if(!g_strcasecmp(f->str,"tsc") ) {
233 se->field = LTTV_FILTER_EVENT_TSC;
234 }
235 else if(!g_strcasecmp(f->str,"field") ) {
236 se->field = LTTV_FILTER_EVENT_FIELD;
237 g_string_free(f,TRUE);
238 f=g_ptr_array_remove_index(fp,0);
239
240 } else {
241 g_string_free(f,TRUE);
242 f=g_ptr_array_remove_index(fp,0);
243 g_warning("Unknown event filter subtype %s", f->str);
244 }
245 } else {
246 g_string_free(f,TRUE);
247 f=g_ptr_array_remove_index(fp,0);
248
249 g_warning("Unrecognized field in filter string");
250 }
251
252 /* free memory for last string */
253 g_string_free(f,TRUE);
254
255 /* array should be empty */
256 g_assert(fp->len == 0);
257
258 if(se->field == LTTV_FILTER_UNDEFINED) {
259 g_warning("The specified field was not recognized !");
260 return FALSE;
261 }
262 return TRUE;
263 }
264
265 /**
266 * @fn gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression*,LttvExpressionOp)
267 *
268 * Sets the function pointer for the current
269 * Simple Expression
270 * @param se current simple expression
271 * @param op current operator
272 * @return success/failure of operation
273 */
274 gboolean
275 lttv_simple_expression_assign_operator(LttvSimpleExpression* se, LttvExpressionOp op) {
276
277 switch(se->field) {
278 /*
279 * string
280 */
281 case LTTV_FILTER_TRACE_NAME:
282 case LTTV_FILTER_TRACEFILE_NAME:
283 case LTTV_FILTER_STATE_P_NAME:
284 case LTTV_FILTER_STATE_T_BRAND:
285 case LTTV_FILTER_EVENT_NAME:
286 case LTTV_FILTER_EVENT_FACILITY:
287 case LTTV_FILTER_STATE_EX_MODE:
288 case LTTV_FILTER_STATE_EX_SUBMODE:
289 case LTTV_FILTER_STATE_P_STATUS:
290 switch(op) {
291 case LTTV_FIELD_EQ:
292 se->op = lttv_apply_op_eq_quark;
293 break;
294 case LTTV_FIELD_NE:
295 se->op = lttv_apply_op_ne_quark;
296 break;
297 default:
298 g_warning("Error encountered in operator assignment = or != expected");
299 return FALSE;
300 }
301 break;
302 /*
303 * integer
304 */
305 case LTTV_FILTER_EVENT_TSC:
306 switch(op) {
307 case LTTV_FIELD_EQ:
308 se->op = lttv_apply_op_eq_uint64;
309 break;
310 case LTTV_FIELD_NE:
311 se->op = lttv_apply_op_ne_uint64;
312 break;
313 case LTTV_FIELD_LT:
314 se->op = lttv_apply_op_lt_uint64;
315 break;
316 case LTTV_FIELD_LE:
317 se->op = lttv_apply_op_le_uint64;
318 break;
319 case LTTV_FIELD_GT:
320 se->op = lttv_apply_op_gt_uint64;
321 break;
322 case LTTV_FIELD_GE:
323 se->op = lttv_apply_op_ge_uint64;
324 break;
325 default:
326 g_warning("Error encountered in operator assignment");
327 return FALSE;
328 }
329 break;
330 /*
331 * unsigned integers
332 */
333 case LTTV_FILTER_STATE_CPU:
334 case LTTV_FILTER_STATE_PID:
335 case LTTV_FILTER_STATE_PPID:
336 switch(op) {
337 case LTTV_FIELD_EQ:
338 se->op = lttv_apply_op_eq_uint;
339 break;
340 case LTTV_FIELD_NE:
341 se->op = lttv_apply_op_ne_uint;
342 break;
343 case LTTV_FIELD_LT:
344 se->op = lttv_apply_op_lt_uint;
345 break;
346 case LTTV_FIELD_LE:
347 se->op = lttv_apply_op_le_uint;
348 break;
349 case LTTV_FIELD_GT:
350 se->op = lttv_apply_op_gt_uint;
351 break;
352 case LTTV_FIELD_GE:
353 se->op = lttv_apply_op_ge_uint;
354 break;
355 default:
356 g_warning("Error encountered in operator assignment");
357 return FALSE;
358 }
359 break;
360
361 /*
362 * Enums
363 * Entered as string, converted to enum
364 *
365 * can only be compared with 'equal' or 'not equal' operators
366 *
367 * unsigned int of 16 bits are used here since enums
368 * should not go over 2^16-1 values
369 */
370 // case /*NOTHING*/:
371 // switch(op) {
372 // case LTTV_FIELD_EQ:
373 // se->op = lttv_apply_op_eq_uint16;
374 // break;
375 // case LTTV_FIELD_NE:
376 // se->op = lttv_apply_op_ne_uint16;
377 // break;
378 // default:
379 // g_warning("Error encountered in operator assignment = or != expected");
380 // return FALSE;
381 // }
382 // break;
383 /*
384 * Ltttime
385 */
386 case LTTV_FILTER_STATE_CT:
387 case LTTV_FILTER_STATE_IT:
388 case LTTV_FILTER_EVENT_TIME:
389 switch(op) {
390 case LTTV_FIELD_EQ:
391 se->op = lttv_apply_op_eq_ltttime;
392 break;
393 case LTTV_FIELD_NE:
394 se->op = lttv_apply_op_ne_ltttime;
395 break;
396 case LTTV_FIELD_LT:
397 se->op = lttv_apply_op_lt_ltttime;
398 break;
399 case LTTV_FIELD_LE:
400 se->op = lttv_apply_op_le_ltttime;
401 break;
402 case LTTV_FIELD_GT:
403 se->op = lttv_apply_op_gt_ltttime;
404 break;
405 case LTTV_FIELD_GE:
406 se->op = lttv_apply_op_ge_ltttime;
407 break;
408 default:
409 g_warning("Error encountered in operator assignment");
410 return FALSE;
411 }
412 break;
413 default:
414 g_warning("Error encountered in operator assignation ! Field type:%i",se->field);
415 return FALSE;
416 }
417
418 return TRUE;
419
420 }
421
422 /**
423 * @fn gboolean lttv_simple_expression_assign_value(LttvSimpleExpression*,char*)
424 *
425 * Assign the value field to the current LttvSimpleExpression
426 * @param se pointer to the current LttvSimpleExpression
427 * @param value string value for simple expression
428 */
429 gboolean
430 lttv_simple_expression_assign_value(LttvSimpleExpression* se, char* value) {
431
432 unsigned i;
433 gboolean is_double = FALSE;
434 LttTime t = ltt_time_zero;
435 GString* v;
436
437 switch(se->field) {
438 /*
439 * Strings
440 * entered as strings, converted to Quarks
441 */
442 case LTTV_FILTER_TRACE_NAME:
443 case LTTV_FILTER_TRACEFILE_NAME:
444 case LTTV_FILTER_STATE_P_NAME:
445 case LTTV_FILTER_STATE_T_BRAND:
446 case LTTV_FILTER_EVENT_NAME:
447 case LTTV_FILTER_EVENT_FACILITY:
448 case LTTV_FILTER_STATE_EX_MODE:
449 case LTTV_FILTER_STATE_EX_SUBMODE:
450 case LTTV_FILTER_STATE_P_STATUS:
451 // se->value.v_string = value;
452 se->value.v_quark = g_quark_from_string(value);
453 g_free(value);
454 break;
455 /*
456 * integer -- supposed to be uint64
457 */
458 case LTTV_FILTER_EVENT_TSC:
459 se->value.v_uint64 = atoi(value);
460 g_free(value);
461 break;
462 /*
463 * unsigned integers
464 */
465 case LTTV_FILTER_STATE_PID:
466 case LTTV_FILTER_STATE_PPID:
467 case LTTV_FILTER_STATE_CPU:
468 se->value.v_uint = atoi(value);
469 g_free(value);
470 break;
471 /*
472 * LttTime
473 */
474 case LTTV_FILTER_STATE_CT:
475 case LTTV_FILTER_STATE_IT:
476 case LTTV_FILTER_EVENT_TIME:
477 //se->value.v_double = atof(value);
478 /*
479 * parsing logic could be optimised,
480 * but as for now, simpler this way
481 */
482 v = g_string_new("");
483 for(i=0;i<strlen(value);i++) {
484 if(value[i] == '.') {
485 /* cannot specify number with more than one '.' */
486 if(is_double) return FALSE;
487 else is_double = TRUE;
488 t.tv_sec = atoi(v->str);
489 g_string_free(v,TRUE);
490 v = g_string_new("");
491 } else g_string_append_c(v,value[i]);
492 }
493 /* number can be integer or double */
494 if(is_double) t.tv_nsec = atoi(v->str);
495 else t.tv_sec = atoi(v->str);
496
497 g_string_free(v,TRUE);
498
499 se->value.v_ltttime = t;
500 g_free(value);
501 break;
502 default:
503 g_warning("Error encountered in value assignation ! Field type = %i",se->field);
504 g_free(value);
505 return FALSE;
506 }
507
508 return TRUE;
509
510 }
511
512 /**
513 * @fn void lttv_simple_expression_destroy(LttvSimpleExpression*)
514 *
515 * Disallocate memory for the current
516 * simple expression
517 * @param se pointer to the current LttvSimpleExpression
518 */
519 void
520 lttv_simple_expression_destroy(LttvSimpleExpression* se) {
521
522 // g_free(se->value);
523 // switch(se->field) {
524 // case LTTV_FILTER_TRACE_NAME:
525 // case LTTV_FILTER_TRACEFILE_NAME:
526 // case LTTV_FILTER_STATE_P_NAME:
527 // case LTTV_FILTER_EVENT_NAME:
528 // g_free(se->value.v_string);
529 // break;
530 // }
531 g_free(se);
532
533 }
534
535 /**
536 * @fn gint lttv_struct_type(gint)
537 *
538 * Finds the structure type depending
539 * on the fields in parameters
540 * @params ft Field of the current structure
541 * @return LttvStructType enum or -1 for error
542 */
543 gint
544 lttv_struct_type(gint ft) {
545
546 switch(ft) {
547 case LTTV_FILTER_TRACE_NAME:
548 return LTTV_FILTER_TRACE;
549 break;
550 case LTTV_FILTER_TRACEFILE_NAME:
551 return LTTV_FILTER_TRACEFILE;
552 break;
553 case LTTV_FILTER_STATE_PID:
554 case LTTV_FILTER_STATE_PPID:
555 case LTTV_FILTER_STATE_CT:
556 case LTTV_FILTER_STATE_IT:
557 case LTTV_FILTER_STATE_P_NAME:
558 case LTTV_FILTER_STATE_T_BRAND:
559 case LTTV_FILTER_STATE_EX_MODE:
560 case LTTV_FILTER_STATE_EX_SUBMODE:
561 case LTTV_FILTER_STATE_P_STATUS:
562 case LTTV_FILTER_STATE_CPU:
563 return LTTV_FILTER_STATE;
564 break;
565 case LTTV_FILTER_EVENT_NAME:
566 case LTTV_FILTER_EVENT_FACILITY:
567 case LTTV_FILTER_EVENT_CATEGORY:
568 case LTTV_FILTER_EVENT_TIME:
569 case LTTV_FILTER_EVENT_TSC:
570 case LTTV_FILTER_EVENT_FIELD:
571 return LTTV_FILTER_EVENT;
572 break;
573 default:
574 return -1;
575 }
576 }
577
578 /**
579 * @fn gboolean lttv_apply_op_eq_uint(gpointer,LttvFieldValue)
580 *
581 * Applies the 'equal' operator to the
582 * specified structure and value
583 * @param v1 left member of comparison
584 * @param v2 right member of comparison
585 * @return success/failure of operation
586 */
587 gboolean lttv_apply_op_eq_uint(const gpointer v1, LttvFieldValue v2) {
588
589 guint* r = (guint*) v1;
590 return (*r == v2.v_uint);
591
592 }
593
594 /**
595 * @fn gboolean lttv_apply_op_eq_uint64(gpointer,LttvFieldValue)
596 *
597 * Applies the 'equal' operator to the
598 * specified structure and value
599 * @param v1 left member of comparison
600 * @param v2 right member of comparison
601 * @return success/failure of operation
602 */
603 gboolean lttv_apply_op_eq_uint64(const gpointer v1, LttvFieldValue v2) {
604
605 guint64* r = (guint64*) v1;
606 return (*r == v2.v_uint64);
607
608 }
609
610 /**
611 * @fn gboolean lttv_apply_op_eq_uint32(gpointer,LttvFieldValue)
612 *
613 * Applies the '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
618 */
619 gboolean lttv_apply_op_eq_uint32(const gpointer v1, LttvFieldValue v2) {
620 guint32* r = (guint32*) v1;
621 return (*r == v2.v_uint32);
622 }
623
624 /**
625 * @fn gboolean lttv_apply_op_eq_uint16(gpointer,LttvFieldValue)
626 *
627 * Applies the '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
632 */
633 gboolean lttv_apply_op_eq_uint16(const gpointer v1, LttvFieldValue v2) {
634 guint16* r = (guint16*) v1;
635 return (*r == v2.v_uint16);
636 }
637
638 /**
639 * @fn gboolean lttv_apply_op_eq_double(gpointer,LttvFieldValue)
640 *
641 * Applies the '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
646 */
647 gboolean lttv_apply_op_eq_double(const gpointer v1, LttvFieldValue v2) {
648 double* r = (double*) v1;
649 return (*r == v2.v_double);
650 }
651
652 /**
653 * @fn gboolean lttv_apply_op_eq_string(gpointer,LttvFieldValue)
654 *
655 * Applies the '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
660 */
661 gboolean lttv_apply_op_eq_string(const gpointer v1, LttvFieldValue v2) {
662 char* r = (char*) v1;
663 return (!g_strcasecmp(r,v2.v_string));
664 }
665
666 /**
667 * @fn gboolean lttv_apply_op_eq_quark(gpointer,LttvFieldValue)
668 *
669 * Applies the '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
674 */
675 gboolean lttv_apply_op_eq_quark(const gpointer v1, LttvFieldValue v2) {
676 GQuark* r = (GQuark*) v1;
677 return (*r == v2.v_quark);
678 }
679
680 /**
681 * @fn gboolean lttv_apply_op_eq_ltttime(gpointer,LttvFieldValue)
682 *
683 * Applies the 'equal' operator to the
684 * specified structure and value
685 * @param v1 left member of comparison
686 * @param v2 right member of comparison
687 * @return success/failure of operation
688 */
689 gboolean lttv_apply_op_eq_ltttime(const gpointer v1, LttvFieldValue v2) {
690 LttTime* r = (LttTime*) v1;
691 return ltt_time_compare(*r, v2.v_ltttime)==0?1:0;
692 }
693
694 /**
695 * @fn gboolean lttv_apply_op_ne_uint(gpointer,LttvFieldValue)
696 *
697 * Applies the 'not equal' operator to the
698 * specified structure and value
699 * @param v1 left member of comparison
700 * @param v2 right member of comparison
701 * @return success/failure of operation
702 */
703 gboolean lttv_apply_op_ne_uint(const gpointer v1, LttvFieldValue v2) {
704 guint* r = (guint*) v1;
705 return (*r != v2.v_uint);
706 }
707
708 /**
709 * @fn gboolean lttv_apply_op_ne_uint64(gpointer,LttvFieldValue)
710 *
711 * Applies the 'not equal' operator to the
712 * specified structure and value
713 * @param v1 left member of comparison
714 * @param v2 right member of comparison
715 * @return success/failure of operation
716 */
717 gboolean lttv_apply_op_ne_uint64(const gpointer v1, LttvFieldValue v2) {
718 guint64* r = (guint64*) v1;
719 return (*r != v2.v_uint64);
720 }
721
722 /**
723 * @fn gboolean lttv_apply_op_ne_uint32(gpointer,LttvFieldValue)
724 *
725 * Applies the 'not equal' operator to the
726 * specified structure and value
727 * @param v1 left member of comparison
728 * @param v2 right member of comparison
729 * @return success/failure of operation
730 */
731 gboolean lttv_apply_op_ne_uint32(const gpointer v1, LttvFieldValue v2) {
732 guint32* r = (guint32*) v1;
733 return (*r != v2.v_uint32);
734 }
735
736 /**
737 * @fn gboolean lttv_apply_op_ne_uint16(gpointer,LttvFieldValue)
738 *
739 * Applies the 'not equal' operator to the
740 * specified structure and value
741 * @param v1 left member of comparison
742 * @param v2 right member of comparison
743 * @return success/failure of operation
744 */
745 gboolean lttv_apply_op_ne_uint16(const gpointer v1, LttvFieldValue v2) {
746 guint16* r = (guint16*) v1;
747 return (*r != v2.v_uint16);
748 }
749
750 /**
751 * @fn gboolean lttv_apply_op_ne_double(gpointer,LttvFieldValue)
752 *
753 * Applies the 'not equal' operator to the
754 * specified structure and value
755 * @param v1 left member of comparison
756 * @param v2 right member of comparison
757 * @return success/failure of operation
758 */
759 gboolean lttv_apply_op_ne_double(const gpointer v1, LttvFieldValue v2) {
760 double* r = (double*) v1;
761 return (*r != v2.v_double);
762 }
763
764 /**
765 * @fn gboolean lttv_apply_op_ne_string(gpointer,LttvFieldValue)
766 *
767 * Applies the 'not equal' operator to the
768 * specified structure and value
769 * @param v1 left member of comparison
770 * @param v2 right member of comparison
771 * @return success/failure of operation
772 */
773 gboolean lttv_apply_op_ne_string(const gpointer v1, LttvFieldValue v2) {
774 char* r = (char*) v1;
775 return (g_strcasecmp(r,v2.v_string));
776 }
777
778 /**
779 * @fn gboolean lttv_apply_op_ne_quark(gpointer,LttvFieldValue)
780 *
781 * Applies the 'not equal' operator to the
782 * specified structure and value
783 * @param v1 left member of comparison
784 * @param v2 right member of comparison
785 * @return success/failure of operation
786 */
787 gboolean lttv_apply_op_ne_quark(const gpointer v1, LttvFieldValue v2) {
788 GQuark* r = (GQuark*) v1;
789 return (*r != v2.v_quark);
790 }
791
792
793 /**
794 * @fn gboolean lttv_apply_op_ne_ltttime(gpointer,LttvFieldValue)
795 *
796 * Applies the 'not equal' operator to the
797 * specified structure and value
798 * @param v1 left member of comparison
799 * @param v2 right member of comparison
800 * @return success/failure of operation
801 */
802 gboolean lttv_apply_op_ne_ltttime(const gpointer v1, LttvFieldValue v2) {
803 LttTime* r = (LttTime*) v1;
804 return ltt_time_compare(*r, v2.v_ltttime)!=0?1:0;
805 }
806
807 /**
808 * @fn gboolean lttv_apply_op_lt_uint(gpointer,LttvFieldValue)
809 *
810 * Applies the 'lower than' operator to the
811 * specified structure and value
812 * @param v1 left member of comparison
813 * @param v2 right member of comparison
814 * @return success/failure of operation
815 */
816 gboolean lttv_apply_op_lt_uint(const gpointer v1, LttvFieldValue v2) {
817 guint* r = (guint*) v1;
818 return (*r < v2.v_uint);
819 }
820
821 /**
822 * @fn gboolean lttv_apply_op_lt_uint64(gpointer,LttvFieldValue)
823 *
824 * Applies the 'lower than' operator to the
825 * specified structure and value
826 * @param v1 left member of comparison
827 * @param v2 right member of comparison
828 * @return success/failure of operation
829 */
830 gboolean lttv_apply_op_lt_uint64(const gpointer v1, LttvFieldValue v2) {
831 guint64* r = (guint64*) v1;
832 return (*r < v2.v_uint64);
833 }
834
835 /**
836 * @fn gboolean lttv_apply_op_lt_uint32(gpointer,LttvFieldValue)
837 *
838 * Applies the 'lower than' operator to the
839 * specified structure and value
840 * @param v1 left member of comparison
841 * @param v2 right member of comparison
842 * @return success/failure of operation
843 */
844 gboolean lttv_apply_op_lt_uint32(const gpointer v1, LttvFieldValue v2) {
845 guint32* r = (guint32*) v1;
846 return (*r < v2.v_uint32);
847 }
848
849 /**
850 * @fn gboolean lttv_apply_op_lt_uint16(gpointer,LttvFieldValue)
851 *
852 * Applies the 'lower than' operator to the
853 * specified structure and value
854 * @param v1 left member of comparison
855 * @param v2 right member of comparison
856 * @return success/failure of operation
857 */
858 gboolean lttv_apply_op_lt_uint16(const gpointer v1, LttvFieldValue v2) {
859 guint16* r = (guint16*) v1;
860 return (*r < v2.v_uint16);
861 }
862
863 /**
864 * @fn gboolean lttv_apply_op_lt_double(gpointer,LttvFieldValue)
865 *
866 * Applies the 'lower than' operator to the
867 * specified structure and value
868 * @param v1 left member of comparison
869 * @param v2 right member of comparison
870 * @return success/failure of operation
871 */
872 gboolean lttv_apply_op_lt_double(const gpointer v1, LttvFieldValue v2) {
873 double* r = (double*) v1;
874 return (*r < v2.v_double);
875 }
876
877 /**
878 * @fn gboolean lttv_apply_op_lt_ltttime(gpointer,LttvFieldValue)
879 *
880 * Applies the 'lower than' operator to the
881 * specified structure and value
882 * @param v1 left member of comparison
883 * @param v2 right member of comparison
884 * @return success/failure of operation
885 */
886 gboolean lttv_apply_op_lt_ltttime(const gpointer v1, LttvFieldValue v2) {
887 LttTime* r = (LttTime*) v1;
888 // 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)));
889 return ltt_time_compare(*r, v2.v_ltttime)==-1?1:0;
890 }
891
892 /**
893 * @fn gboolean lttv_apply_op_le_uint(gpointer,LttvFieldValue)
894 *
895 * Applies the 'lower or equal' operator to the
896 * specified structure and value
897 * @param v1 left member of comparison
898 * @param v2 right member of comparison
899 * @return success/failure of operation
900 */
901 gboolean lttv_apply_op_le_uint(const gpointer v1, LttvFieldValue v2) {
902 guint* r = (guint*) v1;
903 return (*r <= v2.v_uint);
904 }
905
906 /**
907 * @fn gboolean lttv_apply_op_le_uint64(gpointer,LttvFieldValue)
908 *
909 * Applies the 'lower or equal' operator to the
910 * specified structure and value
911 * @param v1 left member of comparison
912 * @param v2 right member of comparison
913 * @return success/failure of operation
914 */
915 gboolean lttv_apply_op_le_uint64(const gpointer v1, LttvFieldValue v2) {
916 guint64* r = (guint64*) v1;
917 return (*r <= v2.v_uint64);
918 }
919
920 /**
921 * @fn gboolean lttv_apply_op_le_uint32(gpointer,LttvFieldValue)
922 *
923 * Applies the 'lower or equal' operator to the
924 * specified structure and value
925 * @param v1 left member of comparison
926 * @param v2 right member of comparison
927 * @return success/failure of operation
928 */
929 gboolean lttv_apply_op_le_uint32(const gpointer v1, LttvFieldValue v2) {
930 guint32* r = (guint32*) v1;
931 return (*r <= v2.v_uint32);
932 }
933
934 /**
935 * @fn gboolean lttv_apply_op_le_uint16(gpointer,LttvFieldValue)
936 *
937 * Applies the 'lower or equal' operator to the
938 * specified structure and value
939 * @param v1 left member of comparison
940 * @param v2 right member of comparison
941 * @return success/failure of operation
942 */
943 gboolean lttv_apply_op_le_uint16(const gpointer v1, LttvFieldValue v2) {
944 guint16* r = (guint16*) v1;
945 return (*r <= v2.v_uint16);
946 }
947
948 /**
949 * @fn gboolean lttv_apply_op_le_double(gpointer,LttvFieldValue)
950 *
951 * Applies the 'lower or equal' operator to the
952 * specified structure and value
953 * @param v1 left member of comparison
954 * @param v2 right member of comparison
955 * @return success/failure of operation
956 */
957 gboolean lttv_apply_op_le_double(const gpointer v1, LttvFieldValue v2) {
958 double* r = (double*) v1;
959 return (*r <= v2.v_double);
960 }
961
962 /**
963 * @fn gboolean lttv_apply_op_le_ltttime(gpointer,LttvFieldValue)
964 *
965 * Applies the 'lower or equal' operator to the
966 * specified structure and value
967 * @param v1 left member of comparison
968 * @param v2 right member of comparison
969 * @return success/failure of operation
970 */
971 gboolean lttv_apply_op_le_ltttime(const gpointer v1, LttvFieldValue v2) {
972 LttTime* r = (LttTime*) v1;
973 // 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)));
974 return ltt_time_compare(*r, v2.v_ltttime)<1?1:0;
975 }
976
977
978 /**
979 * @fn gboolean lttv_apply_op_gt_uint(gpointer,LttvFieldValue)
980 *
981 * Applies the 'greater than' operator to the
982 * specified structure and value
983 * @param v1 left member of comparison
984 * @param v2 right member of comparison
985 * @return success/failure of operation
986 */
987 gboolean lttv_apply_op_gt_uint(const gpointer v1, LttvFieldValue v2) {
988 guint* r = (guint*) v1;
989 return (*r > v2.v_uint);
990 }
991
992 /**
993 * @fn gboolean lttv_apply_op_gt_uint64(gpointer,LttvFieldValue)
994 *
995 * Applies the 'greater than' operator to the
996 * specified structure and value
997 * @param v1 left member of comparison
998 * @param v2 right member of comparison
999 * @return success/failure of operation
1000 */
1001 gboolean lttv_apply_op_gt_uint64(const gpointer v1, LttvFieldValue v2) {
1002 guint64* r = (guint64*) v1;
1003 return (*r > v2.v_uint64);
1004 }
1005
1006 /**
1007 * @fn gboolean lttv_apply_op_gt_uint32(gpointer,LttvFieldValue)
1008 *
1009 * Applies the 'greater than' operator to the
1010 * specified structure and value
1011 * @param v1 left member of comparison
1012 * @param v2 right member of comparison
1013 * @return success/failure of operation
1014 */
1015 gboolean lttv_apply_op_gt_uint32(const gpointer v1, LttvFieldValue v2) {
1016 guint32* r = (guint32*) v1;
1017 return (*r > v2.v_uint32);
1018 }
1019
1020 /**
1021 * @fn gboolean lttv_apply_op_gt_uint16(gpointer,LttvFieldValue)
1022 *
1023 * Applies the 'greater than' operator to the
1024 * specified structure and value
1025 * @param v1 left member of comparison
1026 * @param v2 right member of comparison
1027 * @return success/failure of operation
1028 */
1029 gboolean lttv_apply_op_gt_uint16(const gpointer v1, LttvFieldValue v2) {
1030 guint16* r = (guint16*) v1;
1031 return (*r > v2.v_uint16);
1032 }
1033
1034 /**
1035 * @fn gboolean lttv_apply_op_gt_double(gpointer,LttvFieldValue)
1036 *
1037 * Applies the 'greater than' operator to the
1038 * specified structure and value
1039 * @param v1 left member of comparison
1040 * @param v2 right member of comparison
1041 * @return success/failure of operation
1042 */
1043 gboolean lttv_apply_op_gt_double(const gpointer v1, LttvFieldValue v2) {
1044 double* r = (double*) v1;
1045 return (*r > v2.v_double);
1046 }
1047
1048 /**
1049 * @fn gboolean lttv_apply_op_gt_ltttime(gpointer,LttvFieldValue)
1050 *
1051 * Applies the 'greater than' operator to the
1052 * specified structure and value
1053 * @param v1 left member of comparison
1054 * @param v2 right member of comparison
1055 * @return success/failure of operation
1056 */
1057 gboolean lttv_apply_op_gt_ltttime(const gpointer v1, LttvFieldValue v2) {
1058 LttTime* r = (LttTime*) v1;
1059 // 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)));
1060 return ltt_time_compare(*r, v2.v_ltttime)==1?1:0;
1061 }
1062
1063 /**
1064 * @fn gboolean lttv_apply_op_ge_uint(gpointer,LttvFieldValue)
1065 *
1066 * Applies the 'greater or equal' operator to the
1067 * specified structure and value
1068 * @param v1 left member of comparison
1069 * @param v2 right member of comparison
1070 * @return success/failure of operation
1071 */
1072 gboolean lttv_apply_op_ge_uint(const gpointer v1, LttvFieldValue v2) {
1073 guint* r = (guint*) v1;
1074 return (*r >= v2.v_uint);
1075 }
1076
1077 /**
1078 * @fn gboolean lttv_apply_op_ge_uint64(gpointer,LttvFieldValue)
1079 *
1080 * Applies the 'greater or equal' operator to the
1081 * specified structure and value
1082 * @param v1 left member of comparison
1083 * @param v2 right member of comparison
1084 * @return success/failure of operation
1085 */
1086 gboolean lttv_apply_op_ge_uint64(const gpointer v1, LttvFieldValue v2) {
1087 guint64* r = (guint64*) v1;
1088 return (*r >= v2.v_uint64);
1089 }
1090
1091 /**
1092 * @fn gboolean lttv_apply_op_ge_uint32(gpointer,LttvFieldValue)
1093 *
1094 * Applies the 'greater or equal' operator to the
1095 * specified structure and value
1096 * @param v1 left member of comparison
1097 * @param v2 right member of comparison
1098 * @return success/failure of operation
1099 */
1100 gboolean lttv_apply_op_ge_uint32(const gpointer v1, LttvFieldValue v2) {
1101 guint32* r = (guint32*) v1;
1102 return (*r >= v2.v_uint32);
1103 }
1104
1105 /**
1106 * @fn gboolean lttv_apply_op_ge_uint16(gpointer,LttvFieldValue)
1107 *
1108 * Applies the 'greater or equal' operator to the
1109 * specified structure and value
1110 * @param v1 left member of comparison
1111 * @param v2 right member of comparison
1112 * @return success/failure of operation
1113 */
1114 gboolean lttv_apply_op_ge_uint16(const gpointer v1, LttvFieldValue v2) {
1115 guint16* r = (guint16*) v1;
1116 return (*r >= v2.v_uint16);
1117 }
1118
1119 /**
1120 * @fn gboolean lttv_apply_op_ge_double(gpointer,LttvFieldValue)
1121 *
1122 * Applies the 'greater or equal' operator to the
1123 * specified structure and value
1124 * @param v1 left member of comparison
1125 * @param v2 right member of comparison
1126 * @return success/failure of operation
1127 */
1128 gboolean lttv_apply_op_ge_double(const gpointer v1, LttvFieldValue v2) {
1129 double* r = (double*) v1;
1130 return (*r >= v2.v_double);
1131 }
1132
1133 /**
1134 * @fn gboolean lttv_apply_op_ge_ltttime(gpointer,LttvFieldValue)
1135 *
1136 * Applies the 'greater or equal' operator to the
1137 * specified structure and value
1138 * @param v1 left member of comparison
1139 * @param v2 right member of comparison
1140 * @return success/failure of operation
1141 */
1142 gboolean lttv_apply_op_ge_ltttime(const gpointer v1, LttvFieldValue v2) {
1143 LttTime* r = (LttTime*) v1;
1144 // 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)));
1145 return ltt_time_compare(*r, v2.v_ltttime)>-1?1:0;
1146 }
1147
1148
1149
1150 /**
1151 * Makes a copy of the current filter tree
1152 * @param tree pointer to the current tree
1153 * @return new copy of the filter tree
1154 */
1155 LttvFilterTree*
1156 lttv_filter_tree_clone(const LttvFilterTree* tree) {
1157
1158 LttvFilterTree* newtree = lttv_filter_tree_new();
1159
1160 newtree->node = tree->node;
1161
1162 newtree->left = tree->left;
1163 if(newtree->left == LTTV_TREE_NODE) {
1164 newtree->l_child.t = lttv_filter_tree_clone(tree->l_child.t);
1165 } else if(newtree->left == LTTV_TREE_LEAF) {
1166 newtree->l_child.leaf = lttv_simple_expression_new();
1167 newtree->l_child.leaf->field = tree->l_child.leaf->field;
1168 newtree->l_child.leaf->offset = tree->l_child.leaf->offset;
1169 newtree->l_child.leaf->op = tree->l_child.leaf->op;
1170 /* FIXME: special case for string copy ! */
1171 newtree->l_child.leaf->value = tree->l_child.leaf->value;
1172 }
1173
1174 newtree->right = tree->right;
1175 if(newtree->right == LTTV_TREE_NODE) {
1176 newtree->r_child.t = lttv_filter_tree_clone(tree->r_child.t);
1177 } else if(newtree->right == LTTV_TREE_LEAF) {
1178 newtree->r_child.leaf = lttv_simple_expression_new();
1179 newtree->r_child.leaf->field = tree->r_child.leaf->field;
1180 newtree->r_child.leaf->offset = tree->r_child.leaf->offset;
1181 newtree->r_child.leaf->op = tree->r_child.leaf->op;
1182 newtree->r_child.leaf->value = tree->r_child.leaf->value;
1183 }
1184
1185 return newtree;
1186
1187 }
1188
1189 /**
1190 * Makes a copy of the current filter
1191 * @param filter pointer to the current filter
1192 * @return new copy of the filter
1193 */
1194 LttvFilter*
1195 lttv_filter_clone(const LttvFilter* filter) {
1196
1197 if(!filter) return NULL;
1198
1199 LttvFilter* newfilter = g_new(LttvFilter,1);
1200
1201 strcpy(newfilter->expression,filter->expression);
1202
1203 newfilter->head = lttv_filter_tree_clone(filter->head);
1204
1205 return newfilter;
1206
1207 }
1208
1209
1210 /**
1211 * @fn LttvFilter* lttv_filter_new()
1212 *
1213 * Creates a new LttvFilter
1214 * @return the current LttvFilter or NULL if error
1215 */
1216 LttvFilter*
1217 lttv_filter_new() {
1218
1219 LttvFilter* filter = g_new(LttvFilter,1);
1220 filter->expression = NULL;
1221 filter->head = NULL;
1222
1223 return filter;
1224
1225 }
1226
1227 /**
1228 * @fn gboolean lttv_filter_update(LttvFilter*)
1229 *
1230 * Updates the current LttvFilter by building
1231 * its tree based upon the expression string
1232 * @param filter pointer to the current LttvFilter
1233 * @return Failure/Success of operation
1234 */
1235 gboolean
1236 lttv_filter_update(LttvFilter* filter) {
1237
1238 // g_print("filter::lttv_filter_new()\n"); /* debug */
1239
1240 if(filter->expression == NULL) return FALSE;
1241
1242 int
1243 i,
1244 p_nesting=0, /* parenthesis nesting value */
1245 not=0;
1246
1247 /* trees */
1248 LttvFilterTree
1249 *tree = lttv_filter_tree_new(), /* main tree */
1250 *subtree = NULL, /* buffer for subtrees */
1251 *t1, /* buffer #1 */
1252 *t2, /* buffer #2 */
1253 *t3; /* buffer #3 */
1254
1255 /*
1256 * the filter
1257 * If the tree already exists,
1258 * destroy it and build a new one
1259 */
1260 if(filter->head != NULL) lttv_filter_tree_destroy(filter->head);
1261 filter->head = NULL; /* will be assigned at the end */
1262
1263 /*
1264 * Tree Stack
1265 * each element of the list
1266 * is a sub tree created
1267 * by the use of parenthesis in the
1268 * global expression. The final tree
1269 * will be the one left at the root of
1270 * the list
1271 */
1272 GPtrArray *tree_stack = g_ptr_array_new();
1273 g_ptr_array_add( tree_stack,(gpointer) tree );
1274
1275 /* temporary values */
1276 GString *a_field_component = g_string_new("");
1277 GString *a_string_spaces = g_string_new("");
1278 GPtrArray *a_field_path = g_ptr_array_new();
1279
1280 /* simple expression buffer */
1281 LttvSimpleExpression* a_simple_expression = lttv_simple_expression_new();
1282
1283 /*
1284 * Parse entire expression and construct
1285 * the binary tree. There are two steps
1286 * in browsing that string
1287 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
1288 * 2. finding simple expressions
1289 * - field path ( separated by dots )
1290 * - op ( >, <, =, >=, <=, !=)
1291 * - value ( integer, string ... )
1292 * To spare computing time, the whole
1293 * string is parsed in this loop for a
1294 * O(n) complexity order.
1295 *
1296 * When encountering logical op &,|,^
1297 * 1. parse the last value if any
1298 * 2. create a new tree
1299 * 3. add the expression (simple exp, or exp (subtree)) to the tree
1300 * 4. concatenate this tree with the current tree on top of the stack
1301 * When encountering math ops >,>=,<,<=,=,!=
1302 * 1. add to op to the simple expression
1303 * 2. concatenate last field component to field path
1304 * When encountering concatening ops .
1305 * 1. concatenate last field component to field path
1306 * When encountering opening parenthesis (,{,[
1307 * 1. create a new subtree on top of tree stack
1308 * When encountering closing parenthesis ),},]
1309 * 1. add the expression on right child of the current tree
1310 * 2. the subtree is completed, allocate a new subtree
1311 * 3. pop the tree value from the tree stack
1312 */
1313
1314 #ifdef TEST
1315 struct timeval starttime;
1316 struct timeval endtime;
1317 gettimeofday(&starttime, NULL);
1318 #endif
1319
1320 for(i=0;i<strlen(filter->expression);i++) {
1321 // debug
1322 // g_print("%c\n ",filter->expression[i]);
1323
1324 switch(filter->expression[i]) {
1325 /*
1326 * logical operators
1327 */
1328 case '&': /* and */
1329
1330 /* get current tree in tree stack */
1331 t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1);
1332
1333 /* get current node at absolute right */
1334 while(t1->right != LTTV_TREE_IDLE) {
1335 g_assert(t1->right == LTTV_TREE_NODE);
1336 t1 = t1->r_child.t;
1337 }
1338 t2 = lttv_filter_tree_new();
1339 t2->node = LTTV_LOGICAL_AND;
1340 t1->right = LTTV_TREE_NODE;
1341 t1->r_child.t = t2;
1342 if(not) { /* add not operator to tree */
1343 t3 = lttv_filter_tree_new();
1344 t3->node = LTTV_LOGICAL_NOT;
1345 t2->left = LTTV_TREE_NODE;
1346 t2->l_child.t = t3;
1347 t2 = t3;
1348 not = 0;
1349 }
1350 if(subtree != NULL) { /* append subtree to current tree */
1351 t2->left = LTTV_TREE_NODE;
1352 t2->l_child.t = subtree;
1353 subtree = NULL;
1354 } else { /* append a simple expression */
1355 lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE));
1356 a_field_component = g_string_new("");
1357 g_string_free(a_string_spaces, TRUE);
1358 a_string_spaces = g_string_new("");
1359 t2->left = LTTV_TREE_LEAF;
1360 t2->l_child.leaf = a_simple_expression;
1361 a_simple_expression = lttv_simple_expression_new();
1362 }
1363 break;
1364
1365 case '|': /* or */
1366
1367 t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1);
1368 while(t1->right != LTTV_TREE_IDLE) {
1369 g_assert(t1->right == LTTV_TREE_NODE);
1370 t1 = t1->r_child.t;
1371 }
1372 t2 = lttv_filter_tree_new();
1373 t2->node = LTTV_LOGICAL_OR;
1374 t1->right = LTTV_TREE_NODE;
1375 t1->r_child.t = t2;
1376 if(not) { // add not operator to tree
1377 t3 = lttv_filter_tree_new();
1378 t3->node = LTTV_LOGICAL_NOT;
1379 t2->left = LTTV_TREE_NODE;
1380 t2->l_child.t = t3;
1381 t2 = t3;
1382 not = 0;
1383 }
1384 if(subtree != NULL) { /* append subtree to current tree */
1385 t2->left = LTTV_TREE_NODE;
1386 t2->l_child.t = subtree;
1387 subtree = NULL;
1388 } else { /* append a simple expression */
1389 lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE));
1390 a_field_component = g_string_new("");
1391 g_string_free(a_string_spaces, TRUE);
1392 a_string_spaces = g_string_new("");
1393 t2->left = LTTV_TREE_LEAF;
1394 t2->l_child.leaf = a_simple_expression;
1395 a_simple_expression = lttv_simple_expression_new();
1396 }
1397 break;
1398
1399 case '^': /* xor */
1400
1401 t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1);
1402 while(t1->right != LTTV_TREE_IDLE) {
1403 g_assert(t1->right == LTTV_TREE_NODE);
1404 t1 = t1->r_child.t;
1405 }
1406 t2 = lttv_filter_tree_new();
1407 t2->node = LTTV_LOGICAL_XOR;
1408 t1->right = LTTV_TREE_NODE;
1409 t1->r_child.t = t2;
1410 if(not) { // add not operator to tree
1411 t3 = lttv_filter_tree_new();
1412 t3->node = LTTV_LOGICAL_NOT;
1413 t2->left = LTTV_TREE_NODE;
1414 t2->l_child.t = t3;
1415 t2 = t3;
1416 not = 0;
1417 }
1418 if(subtree != NULL) { /* append subtree to current tree */
1419 t2->left = LTTV_TREE_NODE;
1420 t2->l_child.t = subtree;
1421 subtree = NULL;
1422 } else { /* append a simple expression */
1423 lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE));
1424 a_field_component = g_string_new("");
1425 g_string_free(a_string_spaces, TRUE);
1426 a_string_spaces = g_string_new("");
1427 t2->left = LTTV_TREE_LEAF;
1428 t2->l_child.leaf = a_simple_expression;
1429 a_simple_expression = lttv_simple_expression_new();
1430 }
1431 break;
1432
1433 case '!': /* not, or not equal (math op) */
1434
1435 if(filter->expression[i+1] == '=') { /* != */
1436 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
1437 lttv_simple_expression_assign_field(a_field_path,a_simple_expression);
1438 a_field_component = g_string_new("");
1439 g_string_free(a_string_spaces, TRUE);
1440 a_string_spaces = g_string_new("");
1441 lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_NE);
1442 i++;
1443 } else { /* ! */
1444 not=1;
1445 }
1446 break;
1447
1448 case '(': /* start of parenthesis */
1449 case '[':
1450 case '{':
1451
1452 p_nesting++; /* incrementing parenthesis nesting value */
1453 t1 = lttv_filter_tree_new();
1454 if(not) { /* add not operator to tree */
1455 t3 = lttv_filter_tree_new();
1456 t3->node = LTTV_LOGICAL_NOT;
1457 t1->right = LTTV_TREE_NODE;
1458 t1->r_child.t = t3;
1459 not = 0;
1460 }
1461 g_ptr_array_add( tree_stack,(gpointer) t1 );
1462 break;
1463
1464 case ')': /* end of parenthesis */
1465 case ']':
1466 case '}':
1467
1468 p_nesting--; /* decrementing parenthesis nesting value */
1469 if(p_nesting<0 || tree_stack->len<2) {
1470 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1471 is not valid due to parenthesis incorrect use",filter->expression);
1472 return FALSE;
1473 }
1474
1475 /* there must at least be the root tree left in the array */
1476 g_assert(tree_stack->len>0);
1477
1478 t1 = g_ptr_array_index(tree_stack,tree_stack->len-1);
1479 while(t1->right != LTTV_TREE_IDLE) {
1480 t1 = t1->r_child.t;
1481 }
1482 if(not) { // add not operator to tree
1483 g_print("ici");
1484 t3 = lttv_filter_tree_new();
1485 t3->node = LTTV_LOGICAL_NOT;
1486 t1->right = LTTV_TREE_NODE;
1487 t1->r_child.t = t3;
1488 t1 = t3;
1489 not = 0;
1490 }
1491 if(subtree != NULL) { /* append subtree to current tree */
1492 t1->right = LTTV_TREE_NODE;
1493 t1->r_child.t = subtree;
1494 subtree = g_ptr_array_index(tree_stack,tree_stack->len-1);
1495 g_ptr_array_remove_index(tree_stack,tree_stack->len-1);
1496 } else { /* assign subtree as current tree */
1497 lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE));
1498 a_field_component = g_string_new("");
1499 g_string_free(a_string_spaces, TRUE);
1500 a_string_spaces = g_string_new("");
1501 t1->right = LTTV_TREE_LEAF;
1502 t1->r_child.leaf = a_simple_expression;
1503 a_simple_expression = lttv_simple_expression_new();
1504 subtree = g_ptr_array_remove_index(tree_stack,tree_stack->len-1);
1505 }
1506 break;
1507
1508 /*
1509 * mathematic operators
1510 */
1511 case '<': /* lower, lower or equal */
1512
1513 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
1514 lttv_simple_expression_assign_field(a_field_path,a_simple_expression);
1515 a_field_component = g_string_new("");
1516 g_string_free(a_string_spaces, TRUE);
1517 a_string_spaces = g_string_new("");
1518 if(filter->expression[i+1] == '=') { /* <= */
1519 i++;
1520 lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LE);
1521 } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_LT);
1522 break;
1523
1524 case '>': /* higher, higher or equal */
1525
1526 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
1527 lttv_simple_expression_assign_field(a_field_path,a_simple_expression);
1528 a_field_component = g_string_new("");
1529 g_string_free(a_string_spaces, TRUE);
1530 a_string_spaces = g_string_new("");
1531 if(filter->expression[i+1] == '=') { /* >= */
1532 i++;
1533 lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GE);
1534 } else lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_GT);
1535 break;
1536
1537 case '=': /* equal */
1538
1539 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
1540 lttv_simple_expression_assign_field(a_field_path,a_simple_expression);
1541 a_field_component = g_string_new("");
1542 g_string_free(a_string_spaces, TRUE);
1543 a_string_spaces = g_string_new("");
1544 lttv_simple_expression_assign_operator(a_simple_expression,LTTV_FIELD_EQ);
1545 break;
1546
1547 /*
1548 * Field concatening caracter
1549 */
1550 case '.': /* dot */
1551
1552 /*
1553 * divide field expression into elements
1554 * in a_field_path array.
1555 *
1556 * A dot can also be present in double values
1557 */
1558 if(a_simple_expression->field == LTTV_FILTER_UNDEFINED) {
1559 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
1560 a_field_component = g_string_new("");
1561 g_string_free(a_string_spaces, TRUE);
1562 a_string_spaces = g_string_new("");
1563 }
1564 break;
1565 case ' ': /* keep spaces that are within a field component */
1566 if(a_field_component->len == 0) break; /* ignore */
1567 else
1568 a_string_spaces = g_string_append_c(a_string_spaces,
1569 filter->expression[i]);
1570
1571 case '\n': /* ignore */
1572 break;
1573 default: /* concatening current string */
1574 if(a_string_spaces->len != 0) {
1575 g_string_append(a_field_component, a_string_spaces->str);
1576 a_string_spaces = g_string_set_size(a_string_spaces, 0);
1577 }
1578 a_field_component = g_string_append_c(a_field_component,
1579 filter->expression[i]);
1580 }
1581 }
1582
1583 /*
1584 * Preliminary check to see
1585 * if tree was constructed correctly
1586 */
1587 if( p_nesting>0 ) {
1588 g_warning("Wrong filtering options, the string\n\"%s\"\n\
1589 is not valid due to parenthesis incorrect use",filter->expression);
1590 return FALSE;
1591 }
1592
1593 if(tree_stack->len != 1) /* only root tree should remain */
1594 return FALSE;
1595
1596 /*
1597 * processing last element of expression
1598 */
1599 t1 = g_ptr_array_index(tree_stack,tree_stack->len-1);
1600 while(t1->right != LTTV_TREE_IDLE) {
1601 g_assert(t1->right == LTTV_TREE_NODE);
1602 t1 = t1->r_child.t;
1603 }
1604 if(not) { // add not operator to tree
1605 t3 = lttv_filter_tree_new();
1606 t3->node = LTTV_LOGICAL_NOT;
1607 t1->right = LTTV_TREE_NODE;
1608 t1->r_child.t = t3;
1609 t1 = t3;
1610 not = 0;
1611 }
1612 if(subtree != NULL) { /* add the subtree */
1613 t1->right = LTTV_TREE_NODE;
1614 t1->r_child.t = subtree;
1615 subtree = NULL;
1616 } else { /* add a leaf */
1617 lttv_simple_expression_assign_value(a_simple_expression,g_string_free(a_field_component,FALSE));
1618 a_field_component = NULL;
1619 g_string_free(a_string_spaces, TRUE);
1620 a_string_spaces = NULL;
1621 t1->right = LTTV_TREE_LEAF;
1622 t1->r_child.leaf = a_simple_expression;
1623 a_simple_expression = NULL;
1624 }
1625
1626
1627 /* free the pointer array */
1628 g_assert(a_field_path->len == 0);
1629 g_ptr_array_free(a_field_path,TRUE);
1630
1631 /* free the tree stack -- but keep the root tree */
1632 filter->head = g_ptr_array_remove_index(tree_stack,0);
1633 g_ptr_array_free(tree_stack,TRUE);
1634
1635 /* free the field buffer if allocated */
1636 if(a_field_component != NULL) g_string_free(a_field_component,TRUE);
1637 if(a_string_spaces != NULL) g_string_free(a_string_spaces, TRUE);
1638
1639 /* free the simple expression buffer if allocated */
1640 if(a_simple_expression != NULL) lttv_simple_expression_destroy(a_simple_expression);
1641
1642 g_assert(filter->head != NULL); /* tree should exist */
1643 g_assert(subtree == NULL); /* remaining subtree should be included in main tree */
1644
1645 #ifdef TEST
1646 gettimeofday(&endtime, NULL);
1647
1648 /* Calcul du temps de l'algorithme */
1649 double time1 = starttime.tv_sec + (starttime.tv_usec/1000000.0);
1650 double time2 = endtime.tv_sec + (endtime.tv_usec/1000000.0);
1651 // g_print("Tree build took %.10f ms for strlen of %i\n",(time2-time1)*1000,strlen(filter->expression));
1652 g_print("%.10f %i\n",(time2-time1)*1000,strlen(filter->expression));
1653 #endif
1654
1655 /* debug */
1656 g_debug("+++++++++++++++ BEGIN PRINT ++++++++++++++++\n");
1657 lttv_print_tree(filter->head,0) ;
1658 g_debug("+++++++++++++++ END PRINT ++++++++++++++++++\n");
1659
1660 /* success */
1661 return TRUE;
1662
1663 }
1664
1665 /**
1666 * @fn void lttv_filter_destroy(LttvFilter*)
1667 *
1668 * Destroy the current LttvFilter
1669 * @param filter pointer to the current LttvFilter
1670 */
1671 void
1672 lttv_filter_destroy(LttvFilter* filter) {
1673
1674 if(!filter) return;
1675
1676 if(filter->expression)
1677 g_free(filter->expression);
1678 if(filter->head)
1679 lttv_filter_tree_destroy(filter->head);
1680 g_free(filter);
1681
1682 }
1683
1684 /**
1685 * @fn LttvFilterTree* lttv_filter_tree_new()
1686 *
1687 * Assign a new tree for the current expression
1688 * or sub expression
1689 * @return pointer of LttvFilterTree
1690 */
1691 LttvFilterTree*
1692 lttv_filter_tree_new() {
1693 LttvFilterTree* tree;
1694
1695 tree = g_new(LttvFilterTree,1);
1696 tree->node = 0; //g_new(lttv_expression,1);
1697 tree->left = LTTV_TREE_IDLE;
1698 tree->right = LTTV_TREE_IDLE;
1699 tree->r_child.t = NULL;
1700 tree->l_child.t = NULL;
1701
1702 return tree;
1703 }
1704
1705 /**
1706 * @fn void lttv_filter_append_expression(LttvFilter*,char*)
1707 *
1708 * Append a new expression to the expression
1709 * defined in the current filter
1710 * @param filter pointer to the current LttvFilter
1711 * @param expression string that must be appended
1712 * @return Success/Failure of operation
1713 */
1714 gboolean
1715 lttv_filter_append_expression(LttvFilter* filter, const char *expression) {
1716
1717 if(expression == NULL) return FALSE;
1718 if(filter == NULL) return FALSE;
1719 if(expression[0] == '\0') return FALSE; /* Empty expression */
1720
1721 GString* s = g_string_new("");
1722 if(filter->expression != NULL) {
1723 g_string_append(s,filter->expression);
1724 g_string_append_c(s,'&');
1725 }
1726 g_string_append(s,expression);
1727
1728 g_free(filter->expression);
1729 filter->expression = g_string_free(s,FALSE);
1730
1731 /* TRUE if construction of tree proceeded without errors */
1732 return lttv_filter_update(filter);
1733
1734 }
1735
1736 /**
1737 * @fn void lttv_filter_clear_expression(LttvFilter*)
1738 *
1739 * Clear the filter expression from the
1740 * current filter and sets its pointer to NULL
1741 * @param filter pointer to the current LttvFilter
1742 */
1743 void
1744 lttv_filter_clear_expression(LttvFilter* filter) {
1745
1746 if(filter->expression != NULL) {
1747 g_free(filter->expression);
1748 filter->expression = NULL;
1749 }
1750
1751 }
1752
1753 /**
1754 * @fn void lttv_filter_tree_destroy(LttvFilterTree*)
1755 *
1756 * Destroys the tree and his sub-trees
1757 * @param tree Tree which must be destroyed
1758 */
1759 void
1760 lttv_filter_tree_destroy(LttvFilterTree* tree) {
1761
1762 if(tree == NULL) return;
1763
1764 if(tree->left == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->l_child.leaf);
1765 else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t);
1766
1767 if(tree->right == LTTV_TREE_LEAF) lttv_simple_expression_destroy(tree->r_child.leaf);
1768 else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t);
1769
1770 // g_free(tree->node);
1771 g_free(tree);
1772 }
1773
1774 /**
1775 * Global parsing function for the current
1776 * LttvFilterTree
1777 * @param t pointer to the current LttvFilterTree
1778 * @param event current LttEvent, NULL if not used
1779 * @param tracefile current LttTracefile, NULL if not used
1780 * @param trace current LttTrace, NULL if not used
1781 * @param state current LttvProcessState, NULL if not used
1782 * @param context current LttvTracefileContext, NULL if not used
1783 * @return response of filter
1784 */
1785 gboolean
1786 lttv_filter_tree_parse(
1787 const LttvFilterTree* t,
1788 const LttEvent* event,
1789 const LttTracefile* tracefile,
1790 const LttTrace* trace,
1791 const LttvTracefileContext* context
1792 /*,...*/)
1793 {
1794
1795 /*
1796 * Each tree is parsed in inorder.
1797 * This way, it's possible to apply the left filter of the
1798 * tree, then decide whether or not the right branch should
1799 * be parsed depending on the linking logical operator
1800 *
1801 * Each node consists in a
1802 * 1. logical operator
1803 * 2. left child ( node or simple expression )
1804 * 3. right child ( node or simple expression )
1805 *
1806 * When the child is a simple expression, we must
1807 * before all determine if the expression refers to
1808 * a structure which is whithin observation ( not NULL ).
1809 * -If so, the expression is evaluated.
1810 * -If not, the result is set to TRUE since this particular
1811 * operation does not interfere with the lttv structure
1812 *
1813 * The result of each simple expression will directly
1814 * affect the next branch. This way, depending on
1815 * the linking logical operator, the parser will decide
1816 * to explore or not the next branch.
1817 * 1. AND OPERATOR
1818 * -If result of left branch is 0 / FALSE
1819 * then don't explore right branch and return 0;
1820 * -If result of left branch is 1 / TRUE then explore
1821 * 2. OR OPERATOR
1822 * -If result of left branch is 1 / TRUE
1823 * then don't explore right branch and return 1;
1824 * -If result of left branch is 0 / FALSE then explore
1825 * 3. XOR OPERATOR
1826 * -Result of left branch will not affect exploration of
1827 * right branch
1828 */
1829
1830 gboolean lresult = FALSE, rresult = FALSE;
1831
1832 LttvProcessState* state;
1833
1834 LttvTraceState *ts = (LttvTraceState*)context->t_context;
1835 LttvTracefileState *tfs = (LttvTracefileState*)context;
1836 guint cpu = tfs->cpu;
1837 state = ts->running_process[cpu];
1838
1839 /*
1840 * Parse left branch
1841 */
1842 if(t->left == LTTV_TREE_NODE) {
1843 lresult = lttv_filter_tree_parse(t->l_child.t,event,tracefile,trace,context);
1844 }
1845 else if(t->left == LTTV_TREE_LEAF) {
1846 lresult = lttv_filter_tree_parse_branch(t->l_child.leaf,event,tracefile,trace,state,context);
1847 }
1848
1849 /*
1850 * Parse linking operator
1851 * make a cutoff if possible
1852 */
1853 if((t->node & LTTV_LOGICAL_OR) && lresult == TRUE) return TRUE;
1854 if((t->node & LTTV_LOGICAL_AND) && lresult == FALSE) return FALSE;
1855
1856 /*
1857 * Parse right branch
1858 */
1859 if(t->right == LTTV_TREE_NODE) {
1860 rresult = lttv_filter_tree_parse(t->r_child.t,event,tracefile,trace,context);
1861 }
1862 else if(t->right == LTTV_TREE_LEAF) {
1863 rresult = lttv_filter_tree_parse_branch(t->r_child.leaf,event,tracefile,trace,state,context);
1864 }
1865
1866
1867 /*
1868 * Apply and return the
1869 * logical link between the
1870 * two operation
1871 */
1872 switch(t->node) {
1873 case LTTV_LOGICAL_OR: return (lresult | rresult);
1874 case LTTV_LOGICAL_AND: return (lresult & rresult);
1875 case LTTV_LOGICAL_NOT:
1876 return (t->left==LTTV_TREE_LEAF)?!lresult:((t->right==LTTV_TREE_LEAF)?!rresult:TRUE);
1877 case LTTV_LOGICAL_XOR: return (lresult ^ rresult);
1878 case 0: return (rresult);
1879 default:
1880 /*
1881 * This case should never be
1882 * parsed, if so, this subtree
1883 * is cancelled !
1884 */
1885 return TRUE;
1886 }
1887
1888 }
1889
1890 /**
1891 * This function parses a particular branch of the tree
1892 * @param se pointer to the current LttvSimpleExpression
1893 * @param event current LttEvent, NULL if not used
1894 * @param tracefile current LttTracefile, NULL if not used
1895 * @param trace current LttTrace, NULL if not used
1896 * @param state current LttvProcessState, NULL if not used
1897 * @param context current LttvTracefileContext, NULL if not used
1898 * @return response of filter
1899 */
1900 gboolean
1901 lttv_filter_tree_parse_branch(
1902 const LttvSimpleExpression* se,
1903 const LttEvent* event,
1904 const LttTracefile* tracefile,
1905 const LttTrace* trace,
1906 const LttvProcessState* state,
1907 const LttvTracefileContext* context) {
1908
1909 LttvFieldValue v;
1910 v = se->value;
1911 switch(se->field) {
1912 case LTTV_FILTER_TRACE_NAME:
1913 if(trace == NULL) return TRUE;
1914 else {
1915 GQuark quark = ltt_trace_name(trace);
1916 return se->op((gpointer)&quark,v);
1917 }
1918 break;
1919 case LTTV_FILTER_TRACEFILE_NAME:
1920 if(tracefile == NULL) return TRUE;
1921 else {
1922 GQuark quark = ltt_tracefile_name(tracefile);
1923 return se->op((gpointer)&quark,v);
1924 }
1925 break;
1926 case LTTV_FILTER_STATE_PID:
1927 if(state == NULL) return TRUE;
1928 else return se->op((gpointer)&state->pid,v);
1929 break;
1930 case LTTV_FILTER_STATE_PPID:
1931 if(state == NULL) return TRUE;
1932 else return se->op((gpointer)&state->ppid,v);
1933 break;
1934 case LTTV_FILTER_STATE_CT:
1935 if(state == NULL) return TRUE;
1936 else {
1937 return se->op((gpointer)&state->creation_time,v);
1938 }
1939 break;
1940 case LTTV_FILTER_STATE_IT:
1941 if(state == NULL) return TRUE;
1942 else {
1943 return se->op((gpointer)&state->insertion_time,v);
1944 }
1945 break;
1946 case LTTV_FILTER_STATE_P_NAME:
1947 if(state == NULL) return TRUE;
1948 else {
1949 GQuark quark = state->name;
1950 return se->op((gpointer)&quark,v);
1951 }
1952 break;
1953 case LTTV_FILTER_STATE_T_BRAND:
1954 if(state == NULL) return TRUE;
1955 else {
1956 GQuark quark = state->brand;
1957 return se->op((gpointer)&quark,v);
1958 }
1959 break;
1960 case LTTV_FILTER_STATE_EX_MODE:
1961 if(state == NULL) return TRUE;
1962 else return se->op((gpointer)&state->state->t,v);
1963 break;
1964 case LTTV_FILTER_STATE_EX_SUBMODE:
1965 if(state == NULL) return TRUE;
1966 else return se->op((gpointer)&state->state->n,v);
1967 break;
1968 case LTTV_FILTER_STATE_P_STATUS:
1969 if(state == NULL) return TRUE;
1970 else return se->op((gpointer)&state->state->s,v);
1971 break;
1972 case LTTV_FILTER_STATE_CPU:
1973 if(context == NULL) return TRUE;
1974 else {
1975 if(state == NULL) return TRUE;
1976 else return se->op((gpointer)&state->cpu,v);
1977 }
1978 break;
1979 case LTTV_FILTER_EVENT_NAME:
1980 if(event == NULL) return TRUE;
1981 else {
1982 LttEventType* et;
1983 et = ltt_event_eventtype(event);
1984 GQuark quark = ltt_eventtype_name(et);
1985 return se->op((gpointer)&quark,v);
1986 }
1987 break;
1988 case LTTV_FILTER_EVENT_FACILITY:
1989 if(event == NULL) return TRUE;
1990 else {
1991 LttFacility* fac;
1992 fac = ltt_event_facility(event);
1993 GQuark quark = ltt_facility_name(fac);
1994 return se->op((gpointer)&quark,v);
1995 }
1996 break;
1997 case LTTV_FILTER_EVENT_CATEGORY:
1998 /*
1999 * TODO: Not yet implemented
2000 */
2001 return TRUE;
2002 break;
2003 case LTTV_FILTER_EVENT_TIME:
2004 if(event == NULL) return TRUE;
2005 else {
2006 LttTime time = ltt_event_time(event);
2007 return se->op((gpointer)&time,v);
2008 }
2009 break;
2010 case LTTV_FILTER_EVENT_TSC:
2011 if(event == NULL) return TRUE;
2012 else {
2013 LttCycleCount count = ltt_event_cycle_count(event);
2014 return se->op((gpointer)&count,v);
2015 }
2016 break;
2017 case LTTV_FILTER_EVENT_FIELD:
2018 /*
2019 * TODO: Use the offset to
2020 * find the dynamic field
2021 * in the event struct
2022 */
2023 return TRUE;
2024 default:
2025 /*
2026 * This case should never be
2027 * parsed, if so, the whole
2028 * filtering is cancelled
2029 */
2030 g_warning("Error while parsing the filter tree");
2031 return TRUE;
2032 }
2033
2034 /* should never get here */
2035 return TRUE;
2036
2037 }
2038
2039
2040
2041 /**
2042 * Debug function. Prints tree memory allocation.
2043 * @param t the pointer to the current LttvFilterTree
2044 */
2045 void
2046 lttv_print_tree(const LttvFilterTree* t, const int count) {
2047
2048 g_debug("node:%p lchild:%p rchild:%p depth:%i\n",t, //t->l_child.t,t->r_child.t);
2049 (t->left==LTTV_TREE_NODE)?t->l_child.t:NULL,
2050 (t->right==LTTV_TREE_NODE)?t->r_child.t:NULL,
2051 count);
2052 g_debug("logic operator: %s\n",(t->node&1)?"OR":((t->node&2)?"AND":((t->node&4)?"NOT":((t->node&8)?"XOR":"IDLE"))));
2053 g_debug("|-> left branch %p is a %s\n",t->l_child.t,(t->left==LTTV_TREE_NODE)?"NODE":((t->left==LTTV_TREE_LEAF)?"LEAF":"IDLE"));
2054 if(t->left == LTTV_TREE_LEAF) {
2055 g_debug("| |-> field type number: %i\n",t->l_child.leaf->field);
2056 g_debug("| |-> offset is: %i\n",t->l_child.leaf->offset);
2057 g_debug("| |-> operator function is: %p\n",t->l_child.leaf->op);
2058 }
2059 g_debug("|-> right branch %p is a %s\n",t->r_child.t,(t->right==LTTV_TREE_NODE)?"NODE":((t->right==LTTV_TREE_LEAF)?"LEAF":"IDLE"));
2060 if(t->right == LTTV_TREE_LEAF) {
2061 g_debug("| |-> field type number: %i\n",t->r_child.leaf->field);
2062 g_debug("| |-> offset is: %i\n",t->r_child.leaf->offset);
2063 g_debug("| |-> operator function is: %p\n",t->r_child.leaf->op);
2064 }
2065
2066 if(t->left == LTTV_TREE_NODE) lttv_print_tree(t->l_child.t,count+1);
2067 if(t->right == LTTV_TREE_NODE) lttv_print_tree(t->r_child.t,count+1);
2068 }
2069
2070 /**
2071 * @fn static void module_init()
2072 *
2073 * Initializes the filter module and specific values
2074 */
2075 static void module_init()
2076 {
2077
2078 }
2079
2080 /**
2081 * Destroys the filter module and specific values
2082 */
2083 static void module_destroy()
2084 {
2085
2086 }
2087
2088
2089 LTTV_MODULE("filter", "Filters traceset and events", \
2090 "Filters traceset and events specifically to user input", \
2091 module_init, module_destroy)
2092
2093
2094
This page took 0.072679 seconds and 4 git commands to generate.