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