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