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