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