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