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
57 */
58
59#include <lttv/filter.h>
60
61/*
1a7fa682 62GQuark
63 LTTV_FILTER_TRACE,
64 LTTV_FILTER_TRACESET,
65 LTTV_FILTER_TRACEFILE,
66 LTTV_FILTER_STATE,
91ad3f0a 67 LTTV_FILTER_EVENT,
68 LTTV_FILTER_NAME,
69 LTTV_FILTER_CATEGORY,
70 LTTV_FILTER_TIME,
71 LTTV_FILTER_TSC,
72 LTTV_FILTER_PID,
73 LTTV_FILTER_PPID,
74 LTTV_FILTER_C_TIME,
75 LTTV_FILTER_I_TIME,
76 LTTV_FILTER_P_NAME,
77 LTTV_FILTER_EX_MODE,
78 LTTV_FILTER_EX_SUBMODE,
79 LTTV_FILTER_P_STATUS,
80 LTTV_FILTER_CPU;
150f0d33 81*/
0cdc2470 82
2ea36caf 83LttvSimpleExpression*
0cdc2470 84lttv_simple_expression_new() {
85
86}
f4e9dd16 87/**
150f0d33 88 * add a node to the current tree
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
2ea36caf 94lttv_filter_tree_add_node(GPtrArray* stack, LttvFilter* subtree, LttvLogicalOp op) {
0cdc2470 95
2ea36caf 96 LttvFilter* t1 = NULL;
97 LttvFilter* t2 = NULL;
0cdc2470 98
2ea36caf 99 t1 = (LttvFilter*)g_ptr_array_index(stack,stack->len-1);
0cdc2470 100 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
101 t2 = lttv_filter_tree_new();
102 t2->node = op;
103 if(subtree != NULL) {
104 t2->left = LTTV_TREE_NODE;
105 t2->l_child.t = subtree;
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
0769c82f 121/**
122 * Parse through filtering field hierarchy as specified
123 * by user. This function compares each value to
124 * predetermined quarks
125 * @param fp The field path list
126 * @return success/failure of operation
127 */
128gboolean
f4e9dd16 129parse_field_path(GPtrArray* fp) {
0769c82f 130
f4e9dd16 131 GString* f = NULL;
2b99ec10 132 if(fp->len < 2) return FALSE;
f4e9dd16 133 g_assert(f=g_ptr_array_index(fp,0)); //list_first(fp)->data;
0769c82f 134
91ad3f0a 135 if(g_quark_try_string(f->str) == LTTV_FILTER_EVENT) {
2b99ec10 136 f=g_ptr_array_index(fp,1);
137 if(g_quark_try_string(f->str) == LTTV_FILTER_NAME) {}
138 else if(g_quark_try_string(f->str) == LTTV_FILTER_CATEGORY) {}
139 else if(g_quark_try_string(f->str) == LTTV_FILTER_TIME) {
140 // offset = &((LttEvent*)NULL)->event_time);
141 }
142 else if(g_quark_try_string(f->str) == LTTV_FILTER_TSC) {
143 // offset = &((LttEvent*)NULL)->event_cycle_count);
144 }
145 else { /* core.xml specified options */
146
147 }
91ad3f0a 148 } else if(g_quark_try_string(f->str) == LTTV_FILTER_TRACEFILE) {
2b99ec10 149 f=g_ptr_array_index(fp,1);
150 if(g_quark_try_string(f->str) == LTTV_FILTER_NAME) {}
151 else return FALSE;
91ad3f0a 152 } else if(g_quark_try_string(f->str) == LTTV_FILTER_TRACE) {
2b99ec10 153 f=g_ptr_array_index(fp,1);
154 if(g_quark_try_string(f->str) == LTTV_FILTER_NAME) {}
155 else return FALSE;
91ad3f0a 156
157 } else if(g_quark_try_string(f->str) == LTTV_FILTER_STATE) {
2b99ec10 158 f=g_ptr_array_index(fp,1);
159 if(g_quark_try_string(f->str) == LTTV_FILTER_PID) {}
160 else if(g_quark_try_string(f->str) == LTTV_FILTER_PPID) {}
161 else if(g_quark_try_string(f->str) == LTTV_FILTER_C_TIME) {}
162 else if(g_quark_try_string(f->str) == LTTV_FILTER_I_TIME) {}
163 else if(g_quark_try_string(f->str) == LTTV_FILTER_P_NAME) {}
164 else if(g_quark_try_string(f->str) == LTTV_FILTER_EX_MODE) {}
165 else if(g_quark_try_string(f->str) == LTTV_FILTER_EX_SUBMODE) {}
166 else if(g_quark_try_string(f->str) == LTTV_FILTER_P_STATUS) {}
167 else if(g_quark_try_string(f->str) == LTTV_FILTER_CPU) {}
168 else return FALSE;
91ad3f0a 169
170 } else {
171 g_warning("Unrecognized field in filter string");
172 return FALSE;
0769c82f 173 }
91ad3f0a 174 return TRUE;
0769c82f 175}
176
31452f49 177/**
84a333d6 178 * Add an filtering option to the current tree
179 * @param expression Current expression to parse
180 * @return success/failure of operation
181 */
182gboolean
183parse_simple_expression(GString* expression) {
184
185 unsigned i;
186
a4c292d4 187
0769c82f 188
a4c292d4 189
84a333d6 190}
191
150f0d33 192/**
193 * Applies the 'equal' operator to the
194 * specified structure and value
195 * @return success/failure of operation
196 */
197gboolean lttv_apply_op_eq() {
198
199}
200
201/**
202 * Applies the 'not equal' operator to the
203 * specified structure and value
204 * @return success/failure of operation
205 */
206gboolean lttv_apply_op_ne() {
207
208}
209
210/**
211 * Applies the 'lower than' operator to the
212 * specified structure and value
213 * @return success/failure of operation
214 */
215gboolean lttv_apply_op_lt() {
216
217}
218
219/**
220 * Applies the 'lower or equal' operator to the
221 * specified structure and value
222 * @return success/failure of operation
223 */
224gboolean lttv_apply_op_le() {
225
226}
227
228/**
229 * Applies the 'greater than' operator to the
230 * specified structure and value
231 * @return success/failure of operation
232 */
233gboolean lttv_apply_op_gt() {
234
235}
236
237/**
238 * Applies the 'greater or equal' operator to the
239 * specified structure and value
240 * @return success/failure of operation
241 */
242gboolean lttv_apply_op_ge() {
243
244}
245
246
247
248/**
249 * Makes a copy of the current filter tree
250 * @param tree pointer to the current tree
251 * @return new copy of the filter tree
252 */
253LttvFilterTree*
254lttv_filter_tree_clone(LttvFilterTree* tree) {
255
256
257
258}
259
260/**
261 * Makes a copy of the current filter
262 * @param filter pointer to the current filter
263 * @return new copy of the filter
264 */
265LttvFilter*
266lttv_filter_clone(LttvFilter* filter) {
267
268
269 LttvFilter* newfilter = g_new(LttvFilter,1);
270
271 // newfilter->expression = g_new(char,1)
272 strcpy(newfilter->expression,filter->expression);
273
274 newfilter->head = lttv_filter_tree_clone(filter->head);
275
276 return newfilter;
277
278}
279
280
84a333d6 281/**
282 * Creates a new lttv_filter
31452f49 283 * @param expression filtering options string
284 * @param t pointer to the current LttvTrace
84a333d6 285 * @return the current lttv_filter or NULL if error
31452f49 286 */
2ea36caf 287LttvFilter*
0769c82f 288lttv_filter_new(char *expression, LttvTraceState *tcs) {
a4c292d4 289
0769c82f 290 g_print("filter::lttv_filter_new()\n"); /* debug */
a4c292d4 291
a4c292d4 292 unsigned
293 i,
91ad3f0a 294 p_nesting=0, /* parenthesis nesting value */
a4c292d4 295 b=0; /* current breakpoint in expression string */
1601b365 296
297 /* trees */
2ea36caf 298 LttvFilter
1601b365 299 *tree = lttv_filter_tree_new(), /* main tree */
300 *subtree = NULL, /* buffer for subtrees */
301 *t1, /* buffer #1 */
302 *t2; /* buffer #2 */
303
304 /*
305 * Tree Stack
f4e9dd16 306 * each element of the list
307 * is a sub tree created
308 * by the use of parenthesis in the
309 * global expression. The final tree
1601b365 310 * will be the one left at the root of
f4e9dd16 311 * the list
312 */
18d1226f 313 GPtrArray *tree_stack = g_ptr_array_new();
314 g_ptr_array_add( tree_stack,(gpointer) tree );
f4e9dd16 315
a4c292d4 316 /* temporary values */
0769c82f 317 GString *a_field_component = g_string_new("");
f4e9dd16 318 GPtrArray *a_field_path = NULL;
319
2ea36caf 320 LttvSimpleExpression* a_simple_expression = g_new(LttvSimpleExpression,1);
0769c82f 321
a4c292d4 322 /*
323 * Parse entire expression and construct
324 * the binary tree. There are two steps
325 * in browsing that string
f4e9dd16 326 * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} "
a4c292d4 327 * 2. finding simple expressions
0769c82f 328 * - field path ( separated by dots )
a4c292d4 329 * - op ( >, <, =, >=, <=, !=)
0769c82f 330 * - value ( integer, string ... )
331 * To spare computing time, the whole
332 * string is parsed in this loop for a
333 * O(n) complexity order.
1601b365 334 *
18d1226f 335 * When encountering logical op &,|,^
336 * 1. parse the last value if any
337 * 2. create a new tree
338 * 3. add the expression (simple exp, or exp (subtree)) to the tree
339 * 4. concatenate this tree with the current tree on top of the stack
340 * When encountering math ops >,>=,<,<=,=,!=
341 * 1. add to op to the simple expression
342 * 2. concatenate last field component to field path
343 * When encountering concatening ops .
344 * 1. concatenate last field component to field path
345 * When encountering opening parenthesis (,{,[
346 * 1. create a new subtree on top of tree stack
347 * When encountering closing parenthesis ),},]
348 * 1. add the expression on right child of the current tree
349 * 2. the subtree is completed, allocate a new subtree
350 * 3. pop the tree value from the tree stack
351 */
352
f4e9dd16 353 a_field_path = g_ptr_array_new();
354 g_ptr_array_set_size(a_field_path,2); /* by default, recording 2 field expressions */
355
18d1226f 356
a4c292d4 357 for(i=0;i<strlen(expression);i++) {
18d1226f 358// g_print("%s\n",a_field_component->str);
410c83da 359 g_print("%c ",expression[i]);
1601b365 360// g_print("switch:%c -->subtree:%p\n",expression[i],subtree);
a4c292d4 361 switch(expression[i]) {
362 /*
363 * logical operators
364 */
365 case '&': /* and */
2ea36caf 366 t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 367 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
18d1226f 368 t2 = lttv_filter_tree_new();
0cdc2470 369 t2->node = LTTV_LOGICAL_AND;
1601b365 370 if(subtree != NULL) {
18d1226f 371 t2->left = LTTV_TREE_NODE;
372 t2->l_child.t = subtree;
f4e9dd16 373 subtree = NULL;
18d1226f 374 t1->right = LTTV_TREE_NODE;
410c83da 375 t1->r_child.t = t2;
f4e9dd16 376 } else {
0cdc2470 377 a_simple_expression->value = a_field_component->str;
18d1226f 378 a_field_component = g_string_new("");
379 t2->left = LTTV_TREE_LEAF;
0cdc2470 380 t2->l_child.leaf = a_simple_expression;
2ea36caf 381 a_simple_expression = g_new(LttvSimpleExpression,1);
18d1226f 382 t1->right = LTTV_TREE_NODE;
410c83da 383 t1->r_child.t = t2;
f4e9dd16 384 }
385
386 break;
a4c292d4 387 case '|': /* or */
2ea36caf 388 t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 389 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
1601b365 390 t2 = lttv_filter_tree_new();
0cdc2470 391 t2->node = LTTV_LOGICAL_OR;
1601b365 392 if(subtree != NULL) {
393 t2->left = LTTV_TREE_NODE;
394 t2->l_child.t = subtree;
395 subtree = NULL;
396 t1->right = LTTV_TREE_NODE;
397 t1->r_child.t = t2;
398 } else {
0cdc2470 399 a_simple_expression->value = a_field_component->str;
1601b365 400 a_field_component = g_string_new("");
401 t2->left = LTTV_TREE_LEAF;
0cdc2470 402 t2->l_child.leaf = a_simple_expression;
2ea36caf 403 a_simple_expression = g_new(LttvSimpleExpression,1);
1601b365 404 t1->right = LTTV_TREE_NODE;
405 t1->r_child.t = t2;
406 }
f4e9dd16 407 break;
a4c292d4 408 case '^': /* xor */
2ea36caf 409 t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 410 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
1601b365 411 t2 = lttv_filter_tree_new();
0cdc2470 412 t2->node = LTTV_LOGICAL_XOR;
1601b365 413 if(subtree != NULL) {
414 t2->left = LTTV_TREE_NODE;
415 t2->l_child.t = subtree;
416 subtree = NULL;
417 t1->right = LTTV_TREE_NODE;
418 t1->r_child.t = t2;
419 } else {
0cdc2470 420 a_simple_expression->value = a_field_component->str;
1601b365 421 a_field_component = g_string_new("");
422 t2->left = LTTV_TREE_LEAF;
0cdc2470 423 t2->l_child.leaf = a_simple_expression;
2ea36caf 424 a_simple_expression = g_new(LttvSimpleExpression,1);
1601b365 425 t1->right = LTTV_TREE_NODE;
426 t1->r_child.t = t2;
427 }
a4c292d4 428 break;
429 case '!': /* not, or not equal (math op) */
430 if(expression[i+1] == '=') { /* != */
0cdc2470 431 a_simple_expression->op = LTTV_FIELD_NE;
a4c292d4 432 i++;
0cdc2470 433 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
434 a_field_component = g_string_new("");
a4c292d4 435 } else { /* ! */
1601b365 436 // g_print("%s\n",a_field_component);
437 // a_field_component = g_string_new("");
2ea36caf 438 t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 439 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
1601b365 440 t2 = lttv_filter_tree_new();
0cdc2470 441 t2->node = LTTV_LOGICAL_NOT;
1601b365 442 t1->right = LTTV_TREE_NODE;
443 t1->r_child.t = t2;
a4c292d4 444 }
445 break;
446 case '(': /* start of parenthesis */
91ad3f0a 447 case '[':
448 case '{':
449 p_nesting++; /* incrementing parenthesis nesting value */
1601b365 450 t1 = lttv_filter_tree_new();
451 g_ptr_array_add( tree_stack,(gpointer) t1 );
a4c292d4 452 break;
453 case ')': /* end of parenthesis */
91ad3f0a 454 case ']':
455 case '}':
456 p_nesting--; /* decrementing parenthesis nesting value */
18d1226f 457 if(p_nesting<0 || tree_stack->len<2) {
f4e9dd16 458 g_warning("Wrong filtering options, the string\n\"%s\"\n\
459 is not valid due to parenthesis incorrect use",expression);
460 return NULL;
461 }
18d1226f 462
463 g_assert(tree_stack->len>0);
464 if(subtree != NULL) {
465 t1 = g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 466 while(t1->right != LTTV_TREE_IDLE && t1->right != LTTV_TREE_LEAF) {
18d1226f 467 g_assert(t1!=NULL && t1->r_child.t != NULL);
468 t1 = t1->r_child.t;
469 }
470 t1->right = LTTV_TREE_NODE;
471 t1->r_child.t = subtree;
472 subtree = g_ptr_array_index(tree_stack,tree_stack->len-1);
473 g_ptr_array_remove_index(tree_stack,tree_stack->len-1);
474 } else {
0cdc2470 475 a_simple_expression->value = a_field_component->str;
18d1226f 476 a_field_component = g_string_new("");
477 t1 = g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 478 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
18d1226f 479 t1->right = LTTV_TREE_LEAF;
0cdc2470 480 t1->r_child.leaf = a_simple_expression;
2ea36caf 481 a_simple_expression = g_new(LttvSimpleExpression,1);
18d1226f 482 subtree = g_ptr_array_index(tree_stack,tree_stack->len-1);
1601b365 483 g_assert(subtree != NULL);
18d1226f 484 g_ptr_array_remove_index(tree_stack,tree_stack->len-1);
485 }
a4c292d4 486 break;
487
488 /*
489 * mathematic operators
490 */
491 case '<': /* lower, lower or equal */
492 if(expression[i+1] == '=') { /* <= */
493 i++;
0cdc2470 494 a_simple_expression->op = LTTV_FIELD_LE;
495 } else a_simple_expression->op = LTTV_FIELD_LT;
f4e9dd16 496 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
497 a_field_component = g_string_new("");
a4c292d4 498 break;
499 case '>': /* higher, higher or equal */
500 if(expression[i+1] == '=') { /* >= */
501 i++;
0cdc2470 502 a_simple_expression->op = LTTV_FIELD_GE;
503 } else a_simple_expression->op = LTTV_FIELD_GT;
f4e9dd16 504 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
505 a_field_component = g_string_new("");
a4c292d4 506 break;
507 case '=': /* equal */
0cdc2470 508 a_simple_expression->op = LTTV_FIELD_EQ;
f4e9dd16 509 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
510 a_field_component = g_string_new("");
a4c292d4 511 break;
0769c82f 512 /*
513 * Field concatening caracter
514 */
515 case '.': /* dot */
f4e9dd16 516 g_ptr_array_add( a_field_path,(gpointer) a_field_component );
0769c82f 517 a_field_component = g_string_new("");
518 break;
a4c292d4 519 default: /* concatening current string */
1a7fa682 520 g_string_append_c(a_field_component,expression[i]);
a4c292d4 521 }
522 }
1601b365 523
524 g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree,tree,t1,t2);
0cdc2470 525 g_print("stack size: %i\n",tree_stack->len);
526
527 /*
528 * Preliminary check to see
529 * if tree was constructed correctly
530 */
531 if( p_nesting>0 ) {
532 g_warning("Wrong filtering options, the string\n\"%s\"\n\
533 is not valid due to parenthesis incorrect use",expression);
534 return NULL;
535 }
536
537 if(tree_stack->len != 1) /* only root tree should remain */
538 return NULL;
1601b365 539
410c83da 540 /* processing last element of expression */
410c83da 541 t1 = g_ptr_array_index(tree_stack,tree_stack->len-1);
2a734d8e 542 while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t;
410c83da 543 if(subtree != NULL) { /* add the subtree */
544 t1->right = LTTV_TREE_NODE;
0cdc2470 545 t1->r_child.t = subtree;
410c83da 546 subtree = NULL;
547 } else { /* add a leaf */
0cdc2470 548 a_simple_expression->value = a_field_component->str;
410c83da 549 a_field_component = g_string_new("");
550 t1->right = LTTV_TREE_LEAF;
0cdc2470 551 t1->r_child.leaf = a_simple_expression;
2ea36caf 552 /*
553 * FIXME: is it really necessary to reallocate
554 * LttvSimpleExpression at this point ??
555 */
556 a_simple_expression = g_new(LttvSimpleExpression,1);
410c83da 557 }
558
559 g_assert(tree != NULL);
560 g_assert(subtree == NULL);
a4c292d4 561
1601b365 562 lttv_filter_tracefile(tree,NULL);
563
410c83da 564 return tree;
565
31452f49 566}
567
1da1525d 568void
2ea36caf 569lttv_filter_destroy(LttvFilter* filter) {
1da1525d 570
571}
572
150f0d33 573/**
574 * Assign a new tree for the current expression
575 * or sub expression
576 * @return pointer of LttvFilterTree
577 */
578LttvFilterTree* lttv_filter_tree_new() {
579 LttvFilterTree* tree;
580
581 tree = g_new(LttvFilter,1);
582 tree->node = 0; //g_new(lttv_expression,1);
583// tree->node->type = LTTV_UNDEFINED_EXPRESSION;
584 tree->left = LTTV_TREE_IDLE;
585 tree->right = LTTV_TREE_IDLE;
586
587 return tree;
588}
589
590/**
591 * Destroys the tree and his sub-trees
592 * @param tree Tree which must be destroyed
593 */
594void lttv_filter_tree_destroy(LttvFilterTree* tree) {
595
596 if(tree == NULL) return;
597
598 if(tree->left == LTTV_TREE_LEAF) g_free(tree->l_child.leaf);
599 else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t);
600
601 if(tree->right == LTTV_TREE_LEAF) g_free(tree->r_child.leaf);
602 else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t);
603
604 g_free(tree->node);
605 g_free(tree);
606}
607
608
84a333d6 609/**
610 * Apply the filter to a specific trace
611 * @param filter the current filter applied
612 * @param tracefile the trace to apply the filter to
613 * @return success/failure of operation
614 */
31452f49 615gboolean
2ea36caf 616lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile) {
0769c82f 617
1601b365 618 /*
619 * Each tree is parsed in inorder.
620 * This way, it's possible to apply the left filter of the
621 * tree, then decide whether or not the right branch should
622 * be parsed depending on the linking logical operator
623 *
624 * As for the filtering structure, since we are trying
625 * to remove elements from the trace, it might be better
626 * managing an array of all items to be removed ..
627 */
0769c82f 628
1601b365 629 g_print("node:%p lchild:%p rchild:%p\n",filter,filter->l_child.t,filter->r_child.t);
0cdc2470 630 g_print("node type%i\n",filter->node);
1601b365 631 if(filter->left == LTTV_TREE_NODE) lttv_filter_tracefile(filter->l_child.t,NULL);
0cdc2470 632 else if(filter->left == LTTV_TREE_LEAF) {
633 g_assert(filter->l_child.leaf->value != NULL);
634 g_print("%p: left is qqch %i %s\n",filter,filter->l_child.leaf->op,filter->l_child.leaf->value);
635 }
1601b365 636 if(filter->right == LTTV_TREE_NODE) lttv_filter_tracefile(filter->r_child.t,NULL);
0cdc2470 637 else if(filter->right == LTTV_TREE_LEAF) {
638 g_assert(filter->r_child.leaf->value != NULL);
639 g_print("%p: right is qqch %i %s\n",filter,filter->r_child.leaf->op,filter->r_child.leaf->value);
640 }
0769c82f 641
642 /* test */
643/* int i, nb;
644 char *f_name, *e_name;
31452f49 645
0769c82f 646 char* field = "cpu";
647
648 LttvTraceHook h;
649
650 LttEventType *et;
651
652 LttType *t;
653
654 GString *fe_name = g_string_new("");
655
656 nb = ltt_trace_eventtype_number(tcs->parent.t);
657 g_print("NB:%i\n",nb);
658 for(i = 0 ; i < nb ; i++) {
659 et = ltt_trace_eventtype_get(tcs->parent.t, i);
660 e_name = ltt_eventtype_name(et);
661 f_name = ltt_facility_name(ltt_eventtype_facility(et));
662 g_string_printf(fe_name, "%s.%s", f_name, e_name);
663 g_print("facility:%s and event:%s\n",f_name,e_name);
664 }
665 */
31452f49 666}
667
1a7fa682 668gboolean
2ea36caf 669lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate) {
341aa948 670
671}
1a7fa682 672
84a333d6 673/**
674 * Apply the filter to a specific event
675 * @param filter the current filter applied
676 * @param event the event to apply the filter to
677 * @return success/failure of operation
678 */
31452f49 679gboolean
2ea36caf 680lttv_filter_event(LttvFilter *filter, LttEvent *event) {
31452f49 681
682}
1a7fa682 683
91ad3f0a 684/**
685 * Initializes the filter module and specific values
686 */
1a7fa682 687static void module_init()
688{
91ad3f0a 689
690 /*
691 * Quarks initialization
692 * for hardcoded filtering options
693 *
694 * TODO: traceset has no yet been defined
695 */
696
697 /* top fields */
698 LTTV_FILTER_EVENT = g_quark_from_string("event");
699 LTTV_FILTER_TRACE = g_quark_from_string("trace");
700 LTTV_FILTER_TRACESET = g_quark_from_string("traceset");
701 LTTV_FILTER_STATE = g_quark_from_string("state");
702 LTTV_FILTER_TRACEFILE = g_quark_from_string("tracefile");
1a7fa682 703
91ad3f0a 704 /* event.name, tracefile.name, trace.name */
705 LTTV_FILTER_NAME = g_quark_from_string("name");
706
707 /* event sub fields */
708 LTTV_FILTER_CATEGORY = g_quark_from_string("category");
709 LTTV_FILTER_TIME = g_quark_from_string("time");
710 LTTV_FILTER_TSC = g_quark_from_string("tsc");
711
712 /* state sub fields */
713 LTTV_FILTER_PID = g_quark_from_string("pid");
714 LTTV_FILTER_PPID = g_quark_from_string("ppid");
715 LTTV_FILTER_C_TIME = g_quark_from_string("creation_time");
716 LTTV_FILTER_I_TIME = g_quark_from_string("insertion_time");
717 LTTV_FILTER_P_NAME = g_quark_from_string("process_name");
718 LTTV_FILTER_EX_MODE = g_quark_from_string("execution_mode");
719 LTTV_FILTER_EX_SUBMODE = g_quark_from_string("execution_submode");
720 LTTV_FILTER_P_STATUS = g_quark_from_string("process_status");
721 LTTV_FILTER_CPU = g_quark_from_string("cpu");
722
1a7fa682 723}
724
91ad3f0a 725/**
726 * Destroys the filter module and specific values
727 */
1a7fa682 728static void module_destroy()
729{
730}
731
732
91ad3f0a 733LTTV_MODULE("filter", "Filters traceset and events", \
734 "Filters traceset and events specifically to user input", \
1a7fa682 735 module_init, module_destroy)
736
737
738
This page took 0.065229 seconds and 4 git commands to generate.