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