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