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