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