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