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