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