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