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