9c312311 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
0769c82f |
2 | * Copyright (C) 2003-2005 Michel Dagenais |
9c312311 |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
18 | |
31452f49 |
19 | /* |
a4c292d4 |
20 | read_token |
48f6f3c2 |
21 | |
a4c292d4 |
22 | read_expression |
23 | ( read expr ) |
24 | simple expr [ op expr ] |
48f6f3c2 |
25 | |
a4c292d4 |
26 | read_simple_expression |
27 | read_field_path [ rel value ] |
48f6f3c2 |
28 | |
a4c292d4 |
29 | read_field_path |
30 | read_field_component [. field path] |
48f6f3c2 |
31 | |
a4c292d4 |
32 | read_field_component |
33 | name [ \[ value \] ] |
48f6f3c2 |
34 | |
a4c292d4 |
35 | data struct: |
36 | and/or(left/right) |
37 | not(child) |
38 | op(left/right) |
39 | path(component...) -> field |
150f0d33 |
40 | |
41 | consist in AND, OR and NOT nested expressions, forming a tree with |
42 | simple relations as leaves. The simple relations test is a field |
43 | in an event is equal, not equal, smaller, smaller or equal, larger, or |
44 | larger or equal to a specified value. |
31452f49 |
45 | */ |
46 | |
150f0d33 |
47 | /* |
48 | * YET TO BE ANSWERED |
49 | * - none yet |
50 | */ |
51 | |
52 | /* |
53 | * TODO |
54 | * - refine switch of expression in multiple uses functions |
55 | * - remove the idle expressions in the tree **** |
56 | * - add the current simple expression to the tree |
389ba50e |
57 | * * clear the field_path array after use |
150f0d33 |
58 | */ |
59 | |
60 | #include <lttv/filter.h> |
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; |
150f0d33 |
82 | */ |
0cdc2470 |
83 | |
f4e9dd16 |
84 | /** |
150f0d33 |
85 | * add a node to the current tree |
bb87caa7 |
86 | * FIXME: Might be used to lower coding in lttv_filter_new switch expression |
150f0d33 |
87 | * @param stack the tree stack |
88 | * @param subtree the subtree if available (pointer or NULL) |
89 | * @param op the logical operator that will form the node |
f4e9dd16 |
90 | */ |
0cdc2470 |
91 | void |
5b729fcf |
92 | lttv_filter_tree_add_node(GPtrArray* stack, LttvFilterTree* subtree, LttvLogicalOp op) { |
0cdc2470 |
93 | |
5b729fcf |
94 | LttvFilterTree* t1 = NULL; |
95 | LttvFilterTree* t2 = NULL; |
0cdc2470 |
96 | |
5b729fcf |
97 | t1 = (LttvFilterTree*)g_ptr_array_index(stack,stack->len-1); |
0cdc2470 |
98 | while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t; |
99 | t2 = lttv_filter_tree_new(); |
100 | t2->node = op; |
101 | if(subtree != NULL) { |
102 | t2->left = LTTV_TREE_NODE; |
103 | t2->l_child.t = subtree; |
104 | subtree = NULL; |
105 | t1->right = LTTV_TREE_NODE; |
106 | t1->r_child.t = t2; |
107 | } else { |
108 | // a_simple_expression->value = a_field_component->str; |
109 | // a_field_component = g_string_new(""); |
110 | t2->left = LTTV_TREE_LEAF; |
111 | // t2->l_child.leaf = a_simple_expression; |
112 | // a_simple_expression = g_new(lttv_simple_expression,1); |
113 | t1->right = LTTV_TREE_NODE; |
114 | t1->r_child.t = t2; |
115 | } |
116 | |
117 | } |
118 | |
80f9611a |
119 | |
120 | /** |
121 | * Constructor for LttvSimpleExpression |
122 | * @return pointer to new LttvSimpleExpression |
123 | */ |
124 | LttvSimpleExpression* |
125 | lttv_simple_expression_new() { |
126 | |
127 | LttvSimpleExpression* se = g_new(LttvSimpleExpression,1); |
128 | |
129 | se->field = LTTV_FILTER_UNDEFINED; |
130 | se->op = NULL; |
131 | se->offset = 0; |
132 | se->value = NULL; |
133 | |
134 | return se; |
135 | } |
136 | |
0769c82f |
137 | /** |
138 | * Parse through filtering field hierarchy as specified |
139 | * by user. This function compares each value to |
140 | * predetermined quarks |
141 | * @param fp The field path list |
bb87caa7 |
142 | * @param se current simple expression |
0769c82f |
143 | * @return success/failure of operation |
144 | */ |
145 | gboolean |
47aa6e58 |
146 | parse_field_path(GPtrArray* fp, LttvSimpleExpression* se) { |
0769c82f |
147 | |
f4e9dd16 |
148 | GString* f = NULL; |
cec3d7b0 |
149 | // g_print("fp->len:%i\n",fp->len); |
150 | // int i; |
151 | // for(i=0;i<fp->len;i++) { |
152 | // GString* f2 = g_ptr_array_index(fp,i); |
153 | // g_print("%i=%s",i,f2->str); |
154 | // } |
2b99ec10 |
155 | if(fp->len < 2) return FALSE; |
f4e9dd16 |
156 | g_assert(f=g_ptr_array_index(fp,0)); //list_first(fp)->data; |
47aa6e58 |
157 | |
158 | /* |
159 | * Parse through the specified |
160 | * hardcoded fields. |
161 | * |
162 | * Take note however that the |
163 | * 'event' subfields might change |
164 | * depending on values specified |
165 | * in core.xml file. Hence, if |
166 | * none of the subfields in the |
167 | * array match the hardcoded |
168 | * subfields, it will be considered |
169 | * as a dynamic field |
170 | */ |
80f9611a |
171 | if(!g_strcasecmp(f->str,"trace") ) { |
47aa6e58 |
172 | /* |
173 | * Possible values: |
174 | * trace.name |
175 | */ |
176 | f=g_ptr_array_index(fp,1); |
80f9611a |
177 | if(!g_strcasecmp(f->str,"name")) { |
389ba50e |
178 | se->field = LTTV_FILTER_TRACE_NAME; |
179 | } |
47aa6e58 |
180 | else return FALSE; |
80f9611a |
181 | } else if(!g_strcasecmp(f->str,"traceset") ) { |
47aa6e58 |
182 | /* |
183 | * FIXME: not yet implemented ! |
184 | */ |
80f9611a |
185 | } else if(!g_strcasecmp(f->str,"tracefile") ) { |
47aa6e58 |
186 | /* |
187 | * Possible values: |
188 | * tracefile.name |
189 | */ |
190 | f=g_ptr_array_index(fp,1); |
80f9611a |
191 | if(!g_strcasecmp(f->str,"name")) { |
389ba50e |
192 | se->field = LTTV_FILTER_TRACEFILE_NAME; |
193 | } |
47aa6e58 |
194 | else return FALSE; |
80f9611a |
195 | } else if(!g_strcasecmp(f->str,"state") ) { |
47aa6e58 |
196 | /* |
197 | * Possible values: |
198 | * state.pid |
199 | * state.ppid |
200 | * state.creation_time |
201 | * state.insertion_time |
202 | * state.process_name |
203 | * state.execution_mode |
204 | * state.execution_submode |
205 | * state.process_status |
206 | * state.cpu |
207 | */ |
208 | f=g_ptr_array_index(fp,1); |
80f9611a |
209 | if(!g_strcasecmp(f->str,"pid") ) { |
389ba50e |
210 | se->field = LTTV_FILTER_STATE_PID; |
211 | } |
80f9611a |
212 | else if(!g_strcasecmp(f->str,"ppid") ) { |
389ba50e |
213 | se->field = LTTV_FILTER_STATE_PPID; |
214 | } |
80f9611a |
215 | else if(!g_strcasecmp(f->str,"creation_time") ) { |
389ba50e |
216 | se->field = LTTV_FILTER_STATE_CT; |
217 | } |
80f9611a |
218 | else if(!g_strcasecmp(f->str,"insertion_time") ) { |
389ba50e |
219 | se->field = LTTV_FILTER_STATE_IT; |
220 | } |
80f9611a |
221 | else if(!g_strcasecmp(f->str,"process_name") ) { |
389ba50e |
222 | se->field = LTTV_FILTER_STATE_P_NAME; |
223 | } |
80f9611a |
224 | else if(!g_strcasecmp(f->str,"execution_mode") ) { |
389ba50e |
225 | se->field = LTTV_FILTER_STATE_EX_MODE; |
226 | } |
80f9611a |
227 | else if(!g_strcasecmp(f->str,"execution_submode") ) { |
389ba50e |
228 | se->field = LTTV_FILTER_STATE_EX_SUBMODE; |
229 | } |
80f9611a |
230 | else if(!g_strcasecmp(f->str,"process_status") ) { |
389ba50e |
231 | se->field = LTTV_FILTER_STATE_P_STATUS; |
232 | } |
80f9611a |
233 | else if(!g_strcasecmp(f->str,"cpu") ) { |
389ba50e |
234 | se->field = LTTV_FILTER_STATE_CPU; |
235 | } |
47aa6e58 |
236 | else return FALSE; |
80f9611a |
237 | } else if(!g_strcasecmp(f->str,"event") ) { |
389ba50e |
238 | /* |
239 | * Possible values: |
240 | * event.name |
241 | * event.category |
242 | * event.time |
243 | * event.tsc |
244 | */ |
2b99ec10 |
245 | f=g_ptr_array_index(fp,1); |
80f9611a |
246 | if(!g_strcasecmp(f->str,"name") ) { |
389ba50e |
247 | se->field = LTTV_FILTER_EVENT_NAME; |
248 | } |
80f9611a |
249 | else if(!g_strcasecmp(f->str,"category") ) { |
389ba50e |
250 | /* |
251 | * FIXME: Category not yet functional in lttv |
252 | */ |
253 | se->field = LTTV_FILTER_EVENT_CATEGORY; |
254 | } |
80f9611a |
255 | else if(!g_strcasecmp(f->str,"time") ) { |
389ba50e |
256 | se->field = LTTV_FILTER_EVENT_TIME; |
2b99ec10 |
257 | // offset = &((LttEvent*)NULL)->event_time); |
258 | } |
80f9611a |
259 | else if(!g_strcasecmp(f->str,"tsc") ) { |
389ba50e |
260 | se->field = LTTV_FILTER_EVENT_TSC; |
2b99ec10 |
261 | // offset = &((LttEvent*)NULL)->event_cycle_count); |
262 | } |
263 | else { /* core.xml specified options */ |
389ba50e |
264 | se->field = LTTV_FILTER_EVENT_FIELD; |
265 | //se->offset = (...); |
2b99ec10 |
266 | } |
91ad3f0a |
267 | } else { |
268 | g_warning("Unrecognized field in filter string"); |
269 | return FALSE; |
0769c82f |
270 | } |
47aa6e58 |
271 | |
bb87caa7 |
272 | /* free the pointer array */ |
273 | g_ptr_array_free(fp,FALSE); |
274 | |
91ad3f0a |
275 | return TRUE; |
0769c82f |
276 | } |
277 | |
bb87caa7 |
278 | /** |
279 | * Sets the function pointer for the current |
280 | * Simple Expression |
281 | * @param se current simple expression |
282 | * @return success/failure of operation |
283 | */ |
284 | gboolean assign_operator(LttvSimpleExpression* se, LttvExpressionOp op) { |
aa4600f3 |
285 | |
cec3d7b0 |
286 | // g_print("se->field = %i\n",se->field); |
287 | // g_print("se->offset = %i\n",se->offset); |
288 | // g_print("se->op = %p\n",se->op); |
289 | // g_print("se->value = %s\n",se->value); |
aa4600f3 |
290 | |
bb87caa7 |
291 | switch(se->field) { |
292 | /* char */ |
293 | case LTTV_FILTER_TRACE_NAME: |
294 | case LTTV_FILTER_TRACEFILE_NAME: |
295 | case LTTV_FILTER_STATE_P_NAME: |
296 | case LTTV_FILTER_EVENT_NAME: |
297 | switch(op) { |
298 | case LTTV_FIELD_EQ: |
299 | se->op = lttv_apply_op_eq_string; |
300 | break; |
301 | case LTTV_FIELD_NE: |
302 | se->op = lttv_apply_op_eq_string; |
303 | break; |
304 | default: |
305 | g_warning("Error encountered in operator assignment"); |
306 | return FALSE; |
307 | } |
308 | break; |
309 | case LTTV_FILTER_STATE_PID: |
310 | case LTTV_FILTER_STATE_PPID: |
311 | case LTTV_FILTER_STATE_EX_MODE: |
312 | case LTTV_FILTER_STATE_EX_SUBMODE: |
313 | case LTTV_FILTER_STATE_P_STATUS: |
314 | switch(op) { |
315 | case LTTV_FIELD_EQ: |
316 | se->op = lttv_apply_op_eq_uint64; |
317 | break; |
318 | case LTTV_FIELD_NE: |
319 | se->op = lttv_apply_op_ne_uint64; |
320 | break; |
321 | case LTTV_FIELD_LT: |
322 | se->op = lttv_apply_op_lt_uint64; |
323 | break; |
324 | case LTTV_FIELD_LE: |
325 | se->op = lttv_apply_op_le_uint64; |
326 | break; |
327 | case LTTV_FIELD_GT: |
328 | se->op = lttv_apply_op_gt_uint64; |
329 | break; |
330 | case LTTV_FIELD_GE: |
331 | se->op = lttv_apply_op_ge_uint64; |
332 | break; |
333 | default: |
334 | g_warning("Error encountered in operator assignment"); |
335 | return FALSE; |
336 | } |
337 | break; |
338 | case LTTV_FILTER_STATE_CT: |
339 | case LTTV_FILTER_STATE_IT: |
340 | case LTTV_FILTER_EVENT_TIME: |
341 | case LTTV_FILTER_EVENT_TSC: |
342 | switch(op) { |
343 | case LTTV_FIELD_EQ: |
344 | se->op = lttv_apply_op_eq_double; |
345 | break; |
346 | case LTTV_FIELD_NE: |
347 | se->op = lttv_apply_op_ne_double; |
348 | break; |
349 | case LTTV_FIELD_LT: |
350 | se->op = lttv_apply_op_lt_double; |
351 | break; |
352 | case LTTV_FIELD_LE: |
353 | se->op = lttv_apply_op_le_double; |
354 | break; |
355 | case LTTV_FIELD_GT: |
356 | se->op = lttv_apply_op_gt_double; |
357 | break; |
358 | case LTTV_FIELD_GE: |
359 | se->op = lttv_apply_op_ge_double; |
360 | break; |
361 | default: |
362 | g_warning("Error encountered in operator assignment"); |
363 | return FALSE; |
364 | } |
365 | break; |
366 | default: |
367 | g_warning("Error encountered in operator assignment"); |
368 | return FALSE; |
369 | } |
aa4600f3 |
370 | |
371 | return TRUE; |
bb87caa7 |
372 | |
373 | } |
374 | |
31452f49 |
375 | /** |
80f9611a |
376 | * Finds the structure type depending |
377 | * on the fields in parameters |
378 | * @params ft Field of the current structure |
379 | * @return LttvStructType enum or -1 for error |
84a333d6 |
380 | */ |
80f9611a |
381 | gint |
382 | lttv_struct_type(gint ft) { |
5f185a2b |
383 | |
80f9611a |
384 | switch(ft) { |
385 | case LTTV_FILTER_TRACE_NAME: |
386 | return LTTV_FILTER_TRACE; |
387 | break; |
388 | case LTTV_FILTER_TRACEFILE_NAME: |
389 | return LTTV_FILTER_TRACEFILE; |
390 | break; |
391 | case LTTV_FILTER_STATE_PID: |
392 | case LTTV_FILTER_STATE_PPID: |
393 | case LTTV_FILTER_STATE_CT: |
394 | case LTTV_FILTER_STATE_IT: |
395 | case LTTV_FILTER_STATE_P_NAME: |
396 | case LTTV_FILTER_STATE_EX_MODE: |
397 | case LTTV_FILTER_STATE_EX_SUBMODE: |
398 | case LTTV_FILTER_STATE_P_STATUS: |
399 | case LTTV_FILTER_STATE_CPU: |
400 | return LTTV_FILTER_STATE; |
401 | break; |
402 | case LTTV_FILTER_EVENT_NAME: |
403 | case LTTV_FILTER_EVENT_CATEGORY: |
404 | case LTTV_FILTER_EVENT_TIME: |
405 | case LTTV_FILTER_EVENT_TSC: |
406 | case LTTV_FILTER_EVENT_FIELD: |
407 | return LTTV_FILTER_EVENT; |
408 | break; |
409 | default: |
410 | return -1; |
411 | } |
84a333d6 |
412 | } |
413 | |
150f0d33 |
414 | /** |
415 | * Applies the 'equal' operator to the |
47aa6e58 |
416 | * specified structure and value |
417 | * @param v1 left member of comparison |
418 | * @param v2 right member of comparison |
150f0d33 |
419 | * @return success/failure of operation |
420 | */ |
83aa92fc |
421 | gboolean lttv_apply_op_eq_uint64(gpointer v1, char* v2) { |
422 | |
423 | guint64* r = (guint64*) v1; |
424 | guint64 l = atoi(v2); |
425 | return (*r == l); |
426 | |
427 | } |
150f0d33 |
428 | |
5b729fcf |
429 | /** |
430 | * Applies the 'equal' operator to the |
47aa6e58 |
431 | * specified structure and value |
432 | * @param v1 left member of comparison |
433 | * @param v2 right member of comparison |
5b729fcf |
434 | * @return success/failure of operation |
435 | */ |
83aa92fc |
436 | gboolean lttv_apply_op_eq_uint32(gpointer v1, char* v2) { |
437 | guint32* r = (guint32*) v1; |
438 | guint32 l = atoi(v2); |
439 | return (*r == l); |
440 | } |
5b729fcf |
441 | |
442 | /** |
443 | * Applies the 'equal' operator to the |
47aa6e58 |
444 | * specified structure and value |
445 | * @param v1 left member of comparison |
446 | * @param v2 right member of comparison |
5b729fcf |
447 | * @return success/failure of operation |
448 | */ |
83aa92fc |
449 | gboolean lttv_apply_op_eq_uint16(gpointer v1, char* v2) { |
450 | guint16* r = (guint16*) v1; |
451 | guint16 l = atoi(v2); |
452 | return (*r == l); |
453 | } |
5b729fcf |
454 | |
455 | /** |
456 | * Applies the 'equal' operator to the |
47aa6e58 |
457 | * specified structure and value |
458 | * @param v1 left member of comparison |
459 | * @param v2 right member of comparison |
5b729fcf |
460 | * @return success/failure of operation |
461 | */ |
83aa92fc |
462 | gboolean lttv_apply_op_eq_double(gpointer v1, char* v2) { |
463 | double* r = (double*) v1; |
464 | double l = atof(v2); |
465 | return (*r == l); |
466 | } |
5b729fcf |
467 | |
468 | /** |
469 | * Applies the 'equal' operator to the |
47aa6e58 |
470 | * specified structure and value |
471 | * @param v1 left member of comparison |
472 | * @param v2 right member of comparison |
5b729fcf |
473 | * @return success/failure of operation |
474 | */ |
83aa92fc |
475 | gboolean lttv_apply_op_eq_string(gpointer v1, char* v2) { |
476 | char* r = (char*) v1; |
80f9611a |
477 | return (!g_strcasecmp(r,v2)); |
83aa92fc |
478 | } |
150f0d33 |
479 | |
480 | /** |
481 | * Applies the 'not equal' operator to the |
47aa6e58 |
482 | * specified structure and value |
483 | * @param v1 left member of comparison |
484 | * @param v2 right member of comparison |
150f0d33 |
485 | * @return success/failure of operation |
486 | */ |
83aa92fc |
487 | gboolean lttv_apply_op_ne_uint64(gpointer v1, char* v2) { |
488 | guint64* r = (guint64*) v1; |
489 | guint64 l = atoi(v2); |
490 | return (*r != l); |
491 | } |
150f0d33 |
492 | |
5b729fcf |
493 | /** |
494 | * Applies the 'not equal' operator to the |
47aa6e58 |
495 | * specified structure and value |
496 | * @param v1 left member of comparison |
497 | * @param v2 right member of comparison |
5b729fcf |
498 | * @return success/failure of operation |
499 | */ |
83aa92fc |
500 | gboolean lttv_apply_op_ne_uint32(gpointer v1, char* v2) { |
501 | guint32* r = (guint32*) v1; |
502 | guint32 l = atoi(v2); |
503 | return (*r != l); |
504 | } |
5b729fcf |
505 | |
506 | /** |
507 | * Applies the 'not equal' operator to the |
47aa6e58 |
508 | * specified structure and value |
509 | * @param v1 left member of comparison |
510 | * @param v2 right member of comparison |
5b729fcf |
511 | * @return success/failure of operation |
512 | */ |
83aa92fc |
513 | gboolean lttv_apply_op_ne_uint16(gpointer v1, char* v2) { |
514 | guint16* r = (guint16*) v1; |
515 | guint16 l = atoi(v2); |
516 | return (*r != l); |
517 | } |
5b729fcf |
518 | |
519 | /** |
520 | * Applies the 'not equal' operator to the |
47aa6e58 |
521 | * specified structure and value |
522 | * @param v1 left member of comparison |
523 | * @param v2 right member of comparison |
5b729fcf |
524 | * @return success/failure of operation |
525 | */ |
83aa92fc |
526 | gboolean lttv_apply_op_ne_double(gpointer v1, char* v2) { |
527 | double* r = (double*) v1; |
528 | double l = atof(v2); |
529 | return (*r != l); |
530 | } |
5b729fcf |
531 | |
532 | /** |
533 | * Applies the 'not equal' operator to the |
47aa6e58 |
534 | * specified structure and value |
535 | * @param v1 left member of comparison |
536 | * @param v2 right member of comparison |
5b729fcf |
537 | * @return success/failure of operation |
538 | */ |
83aa92fc |
539 | gboolean lttv_apply_op_ne_string(gpointer v1, char* v2) { |
540 | char* r = (char*) v1; |
80f9611a |
541 | return (g_strcasecmp(r,v2)); |
83aa92fc |
542 | } |
150f0d33 |
543 | |
544 | /** |
545 | * Applies the 'lower than' operator to the |
47aa6e58 |
546 | * specified structure and value |
547 | * @param v1 left member of comparison |
548 | * @param v2 right member of comparison |
150f0d33 |
549 | * @return success/failure of operation |
550 | */ |
83aa92fc |
551 | gboolean lttv_apply_op_lt_uint64(gpointer v1, char* v2) { |
552 | guint64* r = (guint64*) v1; |
553 | guint64 l = atoi(v2); |
554 | return (*r < l); |
555 | } |
150f0d33 |
556 | |
5b729fcf |
557 | /** |
558 | * Applies the 'lower than' operator to the |
47aa6e58 |
559 | * specified structure and value |
560 | * @param v1 left member of comparison |
561 | * @param v2 right member of comparison |
5b729fcf |
562 | * @return success/failure of operation |
563 | */ |
83aa92fc |
564 | gboolean lttv_apply_op_lt_uint32(gpointer v1, char* v2) { |
565 | guint32* r = (guint32*) v1; |
566 | guint32 l = atoi(v2); |
567 | return (*r < l); |
568 | } |
5b729fcf |
569 | |
570 | /** |
571 | * Applies the 'lower than' operator to the |
47aa6e58 |
572 | * specified structure and value |
573 | * @param v1 left member of comparison |
574 | * @param v2 right member of comparison |
5b729fcf |
575 | * @return success/failure of operation |
576 | */ |
83aa92fc |
577 | gboolean lttv_apply_op_lt_uint16(gpointer v1, char* v2) { |
578 | guint16* r = (guint16*) v1; |
579 | guint16 l = atoi(v2); |
580 | return (*r < l); |
581 | } |
5b729fcf |
582 | |
583 | /** |
584 | * Applies the 'lower than' operator to the |
47aa6e58 |
585 | * specified structure and value |
586 | * @param v1 left member of comparison |
587 | * @param v2 right member of comparison |
5b729fcf |
588 | * @return success/failure of operation |
589 | */ |
83aa92fc |
590 | gboolean lttv_apply_op_lt_double(gpointer v1, char* v2) { |
591 | double* r = (double*) v1; |
592 | double l = atof(v2); |
593 | return (*r < l); |
594 | } |
5b729fcf |
595 | |
596 | /** |
597 | * Applies the 'lower than' operator to the |
47aa6e58 |
598 | * specified structure and value |
599 | * @param v1 left member of comparison |
600 | * @param v2 right member of comparison |
5b729fcf |
601 | * @return success/failure of operation |
602 | */ |
83aa92fc |
603 | gboolean lttv_apply_op_le_uint64(gpointer v1, char* v2) { |
604 | guint64* r = (guint64*) v1; |
605 | guint64 l = atoi(v2); |
606 | return (*r <= l); |
607 | } |
150f0d33 |
608 | |
609 | /** |
610 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
611 | * specified structure and value |
612 | * @param v1 left member of comparison |
613 | * @param v2 right member of comparison |
150f0d33 |
614 | * @return success/failure of operation |
615 | */ |
83aa92fc |
616 | gboolean lttv_apply_op_le_uint32(gpointer v1, char* v2) { |
617 | guint32* r = (guint32*) v1; |
618 | guint32 l = atoi(v2); |
619 | return (*r <= l); |
620 | } |
150f0d33 |
621 | |
5b729fcf |
622 | /** |
623 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
624 | * specified structure and value |
625 | * @param v1 left member of comparison |
626 | * @param v2 right member of comparison |
5b729fcf |
627 | * @return success/failure of operation |
628 | */ |
83aa92fc |
629 | gboolean lttv_apply_op_le_uint16(gpointer v1, char* v2) { |
630 | guint16* r = (guint16*) v1; |
631 | guint16 l = atoi(v2); |
632 | return (*r <= l); |
633 | } |
5b729fcf |
634 | |
635 | /** |
636 | * Applies the 'lower or equal' operator to the |
47aa6e58 |
637 | * specified structure and value |
638 | * @param v1 left member of comparison |
639 | * @param v2 right member of comparison |
5b729fcf |
640 | * @return success/failure of operation |
641 | */ |
83aa92fc |
642 | gboolean lttv_apply_op_le_double(gpointer v1, char* v2) { |
643 | double* r = (double*) v1; |
644 | double l = atof(v2); |
645 | return (*r <= l); |
646 | } |
5b729fcf |
647 | |
648 | /** |
83aa92fc |
649 | * Applies the 'greater than' operator to the |
47aa6e58 |
650 | * specified structure and value |
651 | * @param v1 left member of comparison |
652 | * @param v2 right member of comparison |
5b729fcf |
653 | * @return success/failure of operation |
654 | */ |
83aa92fc |
655 | gboolean lttv_apply_op_gt_uint64(gpointer v1, char* v2) { |
656 | guint64* r = (guint64*) v1; |
657 | guint64 l = atoi(v2); |
658 | return (*r > l); |
659 | } |
150f0d33 |
660 | |
661 | /** |
662 | * Applies the 'greater than' operator to the |
47aa6e58 |
663 | * specified structure and value |
664 | * @param v1 left member of comparison |
665 | * @param v2 right member of comparison |
150f0d33 |
666 | * @return success/failure of operation |
667 | */ |
83aa92fc |
668 | gboolean lttv_apply_op_gt_uint32(gpointer v1, char* v2) { |
669 | guint32* r = (guint32*) v1; |
670 | guint32 l = atoi(v2); |
671 | return (*r > l); |
672 | } |
150f0d33 |
673 | |
5b729fcf |
674 | /** |
675 | * Applies the 'greater than' operator to the |
47aa6e58 |
676 | * specified structure and value |
677 | * @param v1 left member of comparison |
678 | * @param v2 right member of comparison |
5b729fcf |
679 | * @return success/failure of operation |
680 | */ |
83aa92fc |
681 | gboolean lttv_apply_op_gt_uint16(gpointer v1, char* v2) { |
682 | guint16* r = (guint16*) v1; |
683 | guint16 l = atoi(v2); |
684 | return (*r > l); |
685 | } |
5b729fcf |
686 | |
687 | /** |
688 | * Applies the 'greater than' operator to the |
47aa6e58 |
689 | * specified structure and value |
690 | * @param v1 left member of comparison |
691 | * @param v2 right member of comparison |
5b729fcf |
692 | * @return success/failure of operation |
693 | */ |
83aa92fc |
694 | gboolean lttv_apply_op_gt_double(gpointer v1, char* v2) { |
695 | double* r = (double*) v1; |
696 | double l = atof(v2); |
697 | return (*r > l); |
698 | } |
5b729fcf |
699 | |
700 | /** |
83aa92fc |
701 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
702 | * specified structure and value |
703 | * @param v1 left member of comparison |
704 | * @param v2 right member of comparison |
5b729fcf |
705 | * @return success/failure of operation |
706 | */ |
83aa92fc |
707 | gboolean lttv_apply_op_ge_uint64(gpointer v1, char* v2) { |
708 | guint64* r = (guint64*) v1; |
709 | guint64 l = atoi(v2); |
710 | return (*r >= l); |
711 | } |
150f0d33 |
712 | |
713 | /** |
714 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
715 | * specified structure and value |
716 | * @param v1 left member of comparison |
717 | * @param v2 right member of comparison |
150f0d33 |
718 | * @return success/failure of operation |
719 | */ |
83aa92fc |
720 | gboolean lttv_apply_op_ge_uint32(gpointer v1, char* v2) { |
721 | guint32* r = (guint32*) v1; |
722 | guint32 l = atoi(v2); |
723 | return (*r >= l); |
724 | } |
150f0d33 |
725 | |
5b729fcf |
726 | /** |
727 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
728 | * specified structure and value |
729 | * @param v1 left member of comparison |
730 | * @param v2 right member of comparison |
5b729fcf |
731 | * @return success/failure of operation |
732 | */ |
83aa92fc |
733 | gboolean lttv_apply_op_ge_uint16(gpointer v1, char* v2) { |
734 | guint16* r = (guint16*) v1; |
735 | guint16 l = atoi(v2); |
736 | return (*r >= l); |
737 | } |
150f0d33 |
738 | |
5b729fcf |
739 | /** |
740 | * Applies the 'greater or equal' operator to the |
47aa6e58 |
741 | * specified structure and value |
742 | * @param v1 left member of comparison |
743 | * @param v2 right member of comparison |
5b729fcf |
744 | * @return success/failure of operation |
745 | */ |
83aa92fc |
746 | gboolean lttv_apply_op_ge_double(gpointer v1, char* v2) { |
747 | double* r = (double*) v1; |
748 | double l = atof(v2); |
749 | return (*r >= l); |
750 | } |
150f0d33 |
751 | |
752 | |
753 | /** |
754 | * Makes a copy of the current filter tree |
755 | * @param tree pointer to the current tree |
756 | * @return new copy of the filter tree |
757 | */ |
758 | LttvFilterTree* |
759 | lttv_filter_tree_clone(LttvFilterTree* tree) { |
760 | |
8c89f5a8 |
761 | LttvFilterTree* newtree = lttv_filter_tree_new(); |
150f0d33 |
762 | |
8c89f5a8 |
763 | newtree->node = tree->node; |
764 | |
765 | newtree->left = tree->left; |
766 | if(newtree->left == LTTV_TREE_NODE) { |
767 | newtree->l_child.t = lttv_filter_tree_clone(tree->l_child.t); |
768 | } else if(newtree->left == LTTV_TREE_LEAF) { |
769 | newtree->l_child.leaf = lttv_simple_expression_new(); |
770 | newtree->l_child.leaf->field = tree->l_child.leaf->field; |
771 | newtree->l_child.leaf->offset = tree->l_child.leaf->offset; |
772 | newtree->l_child.leaf->op = tree->l_child.leaf->op; |
773 | newtree->l_child.leaf->value = g_strconcat(tree->l_child.leaf->value); |
774 | } |
775 | |
776 | newtree->right = tree->right; |
777 | if(newtree->right == LTTV_TREE_NODE) { |
778 | newtree->r_child.t = lttv_filter_tree_clone(tree->r_child.t); |
779 | } else if(newtree->right == LTTV_TREE_LEAF) { |
780 | newtree->r_child.leaf = lttv_simple_expression_new(); |
781 | newtree->r_child.leaf->field = tree->r_child.leaf->field; |
782 | newtree->r_child.leaf->offset = tree->r_child.leaf->offset; |
783 | newtree->r_child.leaf->op = tree->r_child.leaf->op; |
784 | newtree->r_child.leaf->value = g_strconcat(tree->r_child.leaf->value); |
785 | } |
786 | |
787 | return newtree; |
788 | |
150f0d33 |
789 | } |
790 | |
791 | /** |
792 | * Makes a copy of the current filter |
793 | * @param filter pointer to the current filter |
794 | * @return new copy of the filter |
795 | */ |
796 | LttvFilter* |
797 | lttv_filter_clone(LttvFilter* filter) { |
798 | |
799 | |
800 | LttvFilter* newfilter = g_new(LttvFilter,1); |
801 | |
802 | // newfilter->expression = g_new(char,1) |
803 | strcpy(newfilter->expression,filter->expression); |
804 | |
805 | newfilter->head = lttv_filter_tree_clone(filter->head); |
806 | |
807 | return newfilter; |
808 | |
809 | } |
810 | |
811 | |
84a333d6 |
812 | /** |
813 | * Creates a new lttv_filter |
31452f49 |
814 | * @param expression filtering options string |
815 | * @param t pointer to the current LttvTrace |
84a333d6 |
816 | * @return the current lttv_filter or NULL if error |
31452f49 |
817 | */ |
2ea36caf |
818 | LttvFilter* |
5f185a2b |
819 | lttv_filter_new() { |
a4c292d4 |
820 | |
5f185a2b |
821 | LttvFilter* filter = g_new(LttvFilter,1); |
822 | filter->expression = NULL; |
823 | filter->head = NULL; |
824 | |
825 | } |
a4c292d4 |
826 | |
8c89f5a8 |
827 | /** |
828 | * Updates the current LttvFilter by building |
829 | * its tree based upon the expression string |
830 | * @param filter pointer to the current LttvFilter |
831 | * @return Failure/Success of operation |
832 | */ |
5f185a2b |
833 | gboolean |
834 | lttv_filter_update(LttvFilter* filter) { |
835 | |
836 | g_print("filter::lttv_filter_new()\n"); /* debug */ |
837 | |
838 | if(filter->expression == NULL) return FALSE; |
839 | |
a4c292d4 |
840 | unsigned |
841 | i, |
91ad3f0a |
842 | p_nesting=0, /* parenthesis nesting value */ |
a4c292d4 |
843 | b=0; /* current breakpoint in expression string */ |
1601b365 |
844 | |
845 | /* trees */ |
5b729fcf |
846 | LttvFilterTree |
1601b365 |
847 | *tree = lttv_filter_tree_new(), /* main tree */ |
848 | *subtree = NULL, /* buffer for subtrees */ |
849 | *t1, /* buffer #1 */ |
850 | *t2; /* buffer #2 */ |
851 | |
5f185a2b |
852 | /* |
853 | * the filter |
854 | * If the tree already exists, |
855 | * destroy it and build a new one |
856 | */ |
857 | if(filter->head != NULL) lttv_filter_tree_destroy(filter->head); |
858 | filter->head = tree; |
859 | |
1601b365 |
860 | /* |
861 | * Tree Stack |
f4e9dd16 |
862 | * each element of the list |
863 | * is a sub tree created |
864 | * by the use of parenthesis in the |
865 | * global expression. The final tree |
1601b365 |
866 | * will be the one left at the root of |
f4e9dd16 |
867 | * the list |
868 | */ |
18d1226f |
869 | GPtrArray *tree_stack = g_ptr_array_new(); |
870 | g_ptr_array_add( tree_stack,(gpointer) tree ); |
f4e9dd16 |
871 | |
a4c292d4 |
872 | /* temporary values */ |
0769c82f |
873 | GString *a_field_component = g_string_new(""); |
f4e9dd16 |
874 | GPtrArray *a_field_path = NULL; |
875 | |
389ba50e |
876 | LttvSimpleExpression* a_simple_expression = lttv_simple_expression_new(); |
0769c82f |
877 | |
a4c292d4 |
878 | /* |
879 | * Parse entire expression and construct |
880 | * the binary tree. There are two steps |
881 | * in browsing that string |
f4e9dd16 |
882 | * 1. finding boolean ops " &,|,^,! " and parenthesis " {,(,[,],),} " |
a4c292d4 |
883 | * 2. finding simple expressions |
0769c82f |
884 | * - field path ( separated by dots ) |
a4c292d4 |
885 | * - op ( >, <, =, >=, <=, !=) |
0769c82f |
886 | * - value ( integer, string ... ) |
887 | * To spare computing time, the whole |
888 | * string is parsed in this loop for a |
889 | * O(n) complexity order. |
1601b365 |
890 | * |
18d1226f |
891 | * When encountering logical op &,|,^ |
892 | * 1. parse the last value if any |
893 | * 2. create a new tree |
894 | * 3. add the expression (simple exp, or exp (subtree)) to the tree |
895 | * 4. concatenate this tree with the current tree on top of the stack |
896 | * When encountering math ops >,>=,<,<=,=,!= |
897 | * 1. add to op to the simple expression |
898 | * 2. concatenate last field component to field path |
899 | * When encountering concatening ops . |
900 | * 1. concatenate last field component to field path |
901 | * When encountering opening parenthesis (,{,[ |
902 | * 1. create a new subtree on top of tree stack |
903 | * When encountering closing parenthesis ),},] |
904 | * 1. add the expression on right child of the current tree |
905 | * 2. the subtree is completed, allocate a new subtree |
906 | * 3. pop the tree value from the tree stack |
907 | */ |
908 | |
f4e9dd16 |
909 | a_field_path = g_ptr_array_new(); |
80f9611a |
910 | // g_ptr_array_set_size(a_field_path,2); /* by default, recording 2 field expressions */ |
f4e9dd16 |
911 | |
18d1226f |
912 | |
5f185a2b |
913 | for(i=0;i<strlen(filter->expression);i++) { |
914 | // debug |
80f9611a |
915 | int t; |
916 | // for(t=0;t<a_field_path->len;t++) { |
917 | // GString* t3 = g_ptr_array_index(a_field_path,t); |
918 | // g_print("%i=%s ",t,t3->str); |
919 | // } |
5f185a2b |
920 | g_print("%c ",filter->expression[i]); |
921 | switch(filter->expression[i]) { |
a4c292d4 |
922 | /* |
923 | * logical operators |
924 | */ |
925 | case '&': /* and */ |
aa4600f3 |
926 | |
5b729fcf |
927 | t1 = (LttvFilterTree*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
2a734d8e |
928 | while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t; |
18d1226f |
929 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
930 | t2->node = LTTV_LOGICAL_AND; |
bb87caa7 |
931 | if(subtree != NULL) { /* append subtree to current tree */ |
18d1226f |
932 | t2->left = LTTV_TREE_NODE; |
933 | t2->l_child.t = subtree; |
f4e9dd16 |
934 | subtree = NULL; |
18d1226f |
935 | t1->right = LTTV_TREE_NODE; |
410c83da |
936 | t1->r_child.t = t2; |
bb87caa7 |
937 | } else { /* append a simple expression */ |
0cdc2470 |
938 | a_simple_expression->value = a_field_component->str; |
18d1226f |
939 | a_field_component = g_string_new(""); |
940 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
941 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
942 | a_simple_expression = lttv_simple_expression_new(); |
18d1226f |
943 | t1->right = LTTV_TREE_NODE; |
410c83da |
944 | t1->r_child.t = t2; |
f4e9dd16 |
945 | } |
f4e9dd16 |
946 | break; |
aa4600f3 |
947 | |
a4c292d4 |
948 | case '|': /* or */ |
aa4600f3 |
949 | |
2ea36caf |
950 | t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
2a734d8e |
951 | while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t; |
1601b365 |
952 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
953 | t2->node = LTTV_LOGICAL_OR; |
bb87caa7 |
954 | if(subtree != NULL) { /* append subtree to current tree */ |
1601b365 |
955 | t2->left = LTTV_TREE_NODE; |
956 | t2->l_child.t = subtree; |
957 | subtree = NULL; |
958 | t1->right = LTTV_TREE_NODE; |
959 | t1->r_child.t = t2; |
bb87caa7 |
960 | } else { /* append a simple expression */ |
0cdc2470 |
961 | a_simple_expression->value = a_field_component->str; |
1601b365 |
962 | a_field_component = g_string_new(""); |
963 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
964 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
965 | a_simple_expression = lttv_simple_expression_new(); |
1601b365 |
966 | t1->right = LTTV_TREE_NODE; |
967 | t1->r_child.t = t2; |
968 | } |
f4e9dd16 |
969 | break; |
aa4600f3 |
970 | |
a4c292d4 |
971 | case '^': /* xor */ |
aa4600f3 |
972 | |
2ea36caf |
973 | t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
2a734d8e |
974 | while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t; |
1601b365 |
975 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
976 | t2->node = LTTV_LOGICAL_XOR; |
bb87caa7 |
977 | if(subtree != NULL) { /* append subtree to current tree */ |
1601b365 |
978 | t2->left = LTTV_TREE_NODE; |
979 | t2->l_child.t = subtree; |
980 | subtree = NULL; |
981 | t1->right = LTTV_TREE_NODE; |
982 | t1->r_child.t = t2; |
bb87caa7 |
983 | } else { /* append a simple expression */ |
0cdc2470 |
984 | a_simple_expression->value = a_field_component->str; |
1601b365 |
985 | a_field_component = g_string_new(""); |
986 | t2->left = LTTV_TREE_LEAF; |
0cdc2470 |
987 | t2->l_child.leaf = a_simple_expression; |
389ba50e |
988 | a_simple_expression = lttv_simple_expression_new(); |
1601b365 |
989 | t1->right = LTTV_TREE_NODE; |
990 | t1->r_child.t = t2; |
991 | } |
a4c292d4 |
992 | break; |
aa4600f3 |
993 | |
a4c292d4 |
994 | case '!': /* not, or not equal (math op) */ |
aa4600f3 |
995 | |
5f185a2b |
996 | if(filter->expression[i+1] == '=') { /* != */ |
0cdc2470 |
997 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
389ba50e |
998 | parse_field_path(a_field_path,a_simple_expression); |
0cdc2470 |
999 | a_field_component = g_string_new(""); |
aa4600f3 |
1000 | assign_operator(a_simple_expression,LTTV_FIELD_NE); |
1001 | i++; |
a4c292d4 |
1002 | } else { /* ! */ |
1601b365 |
1003 | // g_print("%s\n",a_field_component); |
1004 | // a_field_component = g_string_new(""); |
2ea36caf |
1005 | t1 = (LttvFilter*)g_ptr_array_index(tree_stack,tree_stack->len-1); |
2a734d8e |
1006 | while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t; |
1601b365 |
1007 | t2 = lttv_filter_tree_new(); |
0cdc2470 |
1008 | t2->node = LTTV_LOGICAL_NOT; |
1601b365 |
1009 | t1->right = LTTV_TREE_NODE; |
1010 | t1->r_child.t = t2; |
a4c292d4 |
1011 | } |
1012 | break; |
aa4600f3 |
1013 | |
a4c292d4 |
1014 | case '(': /* start of parenthesis */ |
91ad3f0a |
1015 | case '[': |
1016 | case '{': |
aa4600f3 |
1017 | |
91ad3f0a |
1018 | p_nesting++; /* incrementing parenthesis nesting value */ |
1601b365 |
1019 | t1 = lttv_filter_tree_new(); |
1020 | g_ptr_array_add( tree_stack,(gpointer) t1 ); |
a4c292d4 |
1021 | break; |
aa4600f3 |
1022 | |
a4c292d4 |
1023 | case ')': /* end of parenthesis */ |
91ad3f0a |
1024 | case ']': |
1025 | case '}': |
aa4600f3 |
1026 | |
91ad3f0a |
1027 | p_nesting--; /* decrementing parenthesis nesting value */ |
18d1226f |
1028 | if(p_nesting<0 || tree_stack->len<2) { |
f4e9dd16 |
1029 | g_warning("Wrong filtering options, the string\n\"%s\"\n\ |
5f185a2b |
1030 | is not valid due to parenthesis incorrect use",filter->expression); |
1031 | return FALSE; |
f4e9dd16 |
1032 | } |
18d1226f |
1033 | |
1034 | g_assert(tree_stack->len>0); |
bb87caa7 |
1035 | if(subtree != NULL) { /* append subtree to current tree */ |
18d1226f |
1036 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
2a734d8e |
1037 | while(t1->right != LTTV_TREE_IDLE && t1->right != LTTV_TREE_LEAF) { |
18d1226f |
1038 | g_assert(t1!=NULL && t1->r_child.t != NULL); |
1039 | t1 = t1->r_child.t; |
1040 | } |
1041 | t1->right = LTTV_TREE_NODE; |
1042 | t1->r_child.t = subtree; |
1043 | subtree = g_ptr_array_index(tree_stack,tree_stack->len-1); |
1044 | g_ptr_array_remove_index(tree_stack,tree_stack->len-1); |
bb87caa7 |
1045 | } else { /* assign subtree as current tree */ |
0cdc2470 |
1046 | a_simple_expression->value = a_field_component->str; |
18d1226f |
1047 | a_field_component = g_string_new(""); |
1048 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
2a734d8e |
1049 | while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t; |
18d1226f |
1050 | t1->right = LTTV_TREE_LEAF; |
0cdc2470 |
1051 | t1->r_child.leaf = a_simple_expression; |
389ba50e |
1052 | a_simple_expression = lttv_simple_expression_new(); |
18d1226f |
1053 | subtree = g_ptr_array_index(tree_stack,tree_stack->len-1); |
1601b365 |
1054 | g_assert(subtree != NULL); |
18d1226f |
1055 | g_ptr_array_remove_index(tree_stack,tree_stack->len-1); |
1056 | } |
a4c292d4 |
1057 | break; |
1058 | |
1059 | /* |
1060 | * mathematic operators |
1061 | */ |
1062 | case '<': /* lower, lower or equal */ |
aa4600f3 |
1063 | |
1064 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
1065 | parse_field_path(a_field_path,a_simple_expression); |
1066 | a_field_component = g_string_new(""); |
5f185a2b |
1067 | if(filter->expression[i+1] == '=') { /* <= */ |
a4c292d4 |
1068 | i++; |
bb87caa7 |
1069 | assign_operator(a_simple_expression,LTTV_FIELD_LE); |
1070 | } else assign_operator(a_simple_expression,LTTV_FIELD_LT); |
aa4600f3 |
1071 | break; |
1072 | |
1073 | case '>': /* higher, higher or equal */ |
1074 | |
1075 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
389ba50e |
1076 | parse_field_path(a_field_path,a_simple_expression); |
f4e9dd16 |
1077 | a_field_component = g_string_new(""); |
5f185a2b |
1078 | if(filter->expression[i+1] == '=') { /* >= */ |
a4c292d4 |
1079 | i++; |
bb87caa7 |
1080 | assign_operator(a_simple_expression,LTTV_FIELD_GE); |
1081 | } else assign_operator(a_simple_expression,LTTV_FIELD_GT); |
aa4600f3 |
1082 | break; |
1083 | |
a4c292d4 |
1084 | case '=': /* equal */ |
aa4600f3 |
1085 | |
f4e9dd16 |
1086 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
389ba50e |
1087 | parse_field_path(a_field_path,a_simple_expression); |
f4e9dd16 |
1088 | a_field_component = g_string_new(""); |
aa4600f3 |
1089 | assign_operator(a_simple_expression,LTTV_FIELD_EQ); |
a4c292d4 |
1090 | break; |
aa4600f3 |
1091 | |
0769c82f |
1092 | /* |
1093 | * Field concatening caracter |
1094 | */ |
1095 | case '.': /* dot */ |
aa4600f3 |
1096 | |
bb87caa7 |
1097 | /* |
1098 | * divide field expression into elements |
1099 | * in a_field_path array. |
1100 | */ |
80f9611a |
1101 | // if(a_simple_expression->op == NULL) { |
bb87caa7 |
1102 | g_ptr_array_add( a_field_path,(gpointer) a_field_component ); |
1103 | a_field_component = g_string_new(""); |
80f9611a |
1104 | // } |
0769c82f |
1105 | break; |
aa4600f3 |
1106 | |
a4c292d4 |
1107 | default: /* concatening current string */ |
5f185a2b |
1108 | g_string_append_c(a_field_component,filter->expression[i]); |
a4c292d4 |
1109 | } |
1110 | } |
1601b365 |
1111 | |
1112 | g_print("subtree:%p, tree:%p, t1:%p, t2:%p\n",subtree,tree,t1,t2); |
0cdc2470 |
1113 | g_print("stack size: %i\n",tree_stack->len); |
1114 | |
1115 | /* |
1116 | * Preliminary check to see |
1117 | * if tree was constructed correctly |
1118 | */ |
1119 | if( p_nesting>0 ) { |
1120 | g_warning("Wrong filtering options, the string\n\"%s\"\n\ |
5f185a2b |
1121 | is not valid due to parenthesis incorrect use",filter->expression); |
1122 | return FALSE; |
0cdc2470 |
1123 | } |
1124 | |
1125 | if(tree_stack->len != 1) /* only root tree should remain */ |
5f185a2b |
1126 | return FALSE; |
1601b365 |
1127 | |
410c83da |
1128 | /* processing last element of expression */ |
410c83da |
1129 | t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); |
2a734d8e |
1130 | while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t; |
410c83da |
1131 | if(subtree != NULL) { /* add the subtree */ |
1132 | t1->right = LTTV_TREE_NODE; |
0cdc2470 |
1133 | t1->r_child.t = subtree; |
410c83da |
1134 | subtree = NULL; |
1135 | } else { /* add a leaf */ |
0cdc2470 |
1136 | a_simple_expression->value = a_field_component->str; |
410c83da |
1137 | a_field_component = g_string_new(""); |
1138 | t1->right = LTTV_TREE_LEAF; |
0cdc2470 |
1139 | t1->r_child.leaf = a_simple_expression; |
2ea36caf |
1140 | /* |
1141 | * FIXME: is it really necessary to reallocate |
1142 | * LttvSimpleExpression at this point ?? |
1143 | */ |
389ba50e |
1144 | a_simple_expression = lttv_simple_expression_new(); |
410c83da |
1145 | } |
1146 | |
1147 | g_assert(tree != NULL); |
1148 | g_assert(subtree == NULL); |
a4c292d4 |
1149 | |
80f9611a |
1150 | lttv_print_tree(filter->head) ; |
aa4600f3 |
1151 | |
80f9611a |
1152 | g_print("ended update tree!\n"); |
5f185a2b |
1153 | return TRUE; |
80f9611a |
1154 | |
5f185a2b |
1155 | // return filter; |
410c83da |
1156 | |
31452f49 |
1157 | } |
1158 | |
8c89f5a8 |
1159 | /** |
1160 | * Destroy the current LttvFilter |
1161 | * @param filter pointer to the current LttvFilter |
1162 | */ |
1da1525d |
1163 | void |
2ea36caf |
1164 | lttv_filter_destroy(LttvFilter* filter) { |
5f185a2b |
1165 | |
1166 | g_free(filter->expression); |
1167 | lttv_filter_tree_destroy(filter->head); |
1168 | g_free(filter); |
1169 | |
1da1525d |
1170 | } |
1171 | |
150f0d33 |
1172 | /** |
1173 | * Assign a new tree for the current expression |
1174 | * or sub expression |
1175 | * @return pointer of LttvFilterTree |
1176 | */ |
5f185a2b |
1177 | LttvFilterTree* |
1178 | lttv_filter_tree_new() { |
150f0d33 |
1179 | LttvFilterTree* tree; |
1180 | |
1181 | tree = g_new(LttvFilter,1); |
1182 | tree->node = 0; //g_new(lttv_expression,1); |
150f0d33 |
1183 | tree->left = LTTV_TREE_IDLE; |
1184 | tree->right = LTTV_TREE_IDLE; |
1185 | |
1186 | return tree; |
1187 | } |
1188 | |
80f9611a |
1189 | /** |
1190 | * Append a new expression to the expression |
1191 | * defined in the current filter |
1192 | * @param filter pointer to the current LttvFilter |
1193 | * @param expression string that must be appended |
1194 | */ |
1195 | void lttv_filter_append_expression(LttvFilter* filter, char *expression) { |
1196 | |
1197 | if(expression == NULL) return; |
1198 | if(filter == NULL) { |
1199 | filter = lttv_filter_new(); |
1200 | filter->expression = expression; |
1201 | } else if(filter->expression == NULL) { |
1202 | filter->expression = expression; |
1203 | } else { |
1204 | filter->expression = g_strconcat(filter->expression,"&",expression); |
1205 | } |
1206 | |
1207 | lttv_filter_update(filter); |
1208 | |
1209 | } |
1210 | |
1211 | /** |
1212 | * Clear the filter expression from the |
1213 | * current filter and sets its pointer to NULL |
1214 | * @param filter pointer to the current LttvFilter |
1215 | */ |
1216 | void lttv_filter_clear_expression(LttvFilter* filter) { |
1217 | |
1218 | if(filter->expression != NULL) { |
1219 | g_free(filter->expression); |
1220 | filter->expression = NULL; |
1221 | } |
1222 | |
1223 | } |
1224 | |
150f0d33 |
1225 | /** |
1226 | * Destroys the tree and his sub-trees |
1227 | * @param tree Tree which must be destroyed |
1228 | */ |
5f185a2b |
1229 | void |
1230 | lttv_filter_tree_destroy(LttvFilterTree* tree) { |
150f0d33 |
1231 | |
1232 | if(tree == NULL) return; |
1233 | |
1234 | if(tree->left == LTTV_TREE_LEAF) g_free(tree->l_child.leaf); |
1235 | else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t); |
1236 | |
1237 | if(tree->right == LTTV_TREE_LEAF) g_free(tree->r_child.leaf); |
1238 | else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t); |
1239 | |
1240 | g_free(tree->node); |
1241 | g_free(tree); |
1242 | } |
1243 | |
84a333d6 |
1244 | /** |
80f9611a |
1245 | * Global parsing function for the current |
1246 | * LttvFilterTree |
1247 | * @param tree pointer to the current LttvFilterTree |
1248 | * @param event current LttEvent, NULL if not used |
1249 | * @param tracefile current LttTracefile, NULL if not used |
1250 | * @param trace current LttTrace, NULL if not used |
1251 | * @param state current LttvProcessState, NULL if not used |
84a333d6 |
1252 | */ |
31452f49 |
1253 | gboolean |
80f9611a |
1254 | lttv_filter_tree_parse( |
1255 | LttvFilterTree* t, |
1256 | LttEvent* event, |
1257 | LttTracefile* tracefile, |
1258 | LttTrace* trace, |
1259 | LttvProcessState* state |
1260 | /*,...*/) |
1261 | { |
0769c82f |
1262 | |
80f9611a |
1263 | /* |
1601b365 |
1264 | * Each tree is parsed in inorder. |
1265 | * This way, it's possible to apply the left filter of the |
1266 | * tree, then decide whether or not the right branch should |
1267 | * be parsed depending on the linking logical operator |
1268 | * |
80f9611a |
1269 | * Each node consists in a |
1270 | * 1. logical operator |
1271 | * 2. left child ( node or simple expression ) |
1272 | * 3. right child ( node or simple expression ) |
1273 | * |
1274 | * When the child is a simple expression, we must |
1275 | * before all determine if the expression refers to |
1276 | * a structure which is whithin observation ( not NULL ). |
1277 | * -If so, the expression is evaluated. |
1278 | * -If not, the result is set to TRUE since this particular |
1279 | * operation does not interfere with the lttv structure |
1280 | * |
1281 | * The result of each simple expression will directly |
1282 | * affect the next branch. This way, depending on |
1283 | * the linking logical operator, the parser will decide |
1284 | * to explore or not the next branch. |
1285 | * 1. AND OPERATOR |
1286 | * -If result of left branch is 0 / FALSE |
1287 | * then don't explore right branch and return 0; |
1288 | * -If result of left branch is 1 / TRUE then explore |
1289 | * 2. OR OPERATOR |
1290 | * -If result of left branch is 1 / TRUE |
1291 | * then don't explore right branch and return 1; |
1292 | * -If result of left branch is 0 / FALSE then explore |
1293 | * 3. XOR OPERATOR |
1294 | * -Result of left branchwill not affect exploration of |
1295 | * right branch |
1601b365 |
1296 | */ |
80f9611a |
1297 | |
1298 | gboolean lresult = FALSE, rresult = FALSE; |
0769c82f |
1299 | |
80f9611a |
1300 | /* |
1301 | * Parse left branch |
1302 | */ |
1303 | if(t->left == LTTV_TREE_NODE) lresult = lttv_filter_tree_parse(t->l_child.t,event,tracefile,trace,state); |
5b729fcf |
1304 | else if(t->left == LTTV_TREE_LEAF) { |
80f9611a |
1305 | //g_print("%p: left is %i %p %s\n",t,t->l_child.leaf->field,t->l_child.leaf->op,t->l_child.leaf->value); |
1306 | char* v; |
1307 | g_assert(v = t->l_child.leaf->value); |
1308 | switch(t->l_child.leaf->field) { |
1309 | |
1310 | case LTTV_FILTER_TRACE_NAME: |
1311 | if(trace == NULL) lresult = TRUE; |
1312 | else lresult = t->l_child.leaf->op((gpointer)ltt_trace_name(trace),v); |
1313 | break; |
1314 | case LTTV_FILTER_TRACEFILE_NAME: |
1315 | if(tracefile == NULL) lresult = TRUE; |
1316 | else lresult = t->l_child.leaf->op((gpointer)ltt_tracefile_name(tracefile),v); |
1317 | break; |
1318 | case LTTV_FILTER_STATE_PID: |
1319 | if(state == NULL) lresult = TRUE; |
1320 | else lresult = t->l_child.leaf->op((gpointer)&state->pid,v); |
1321 | break; |
1322 | case LTTV_FILTER_STATE_PPID: |
1323 | if(state == NULL) lresult = TRUE; |
1324 | else lresult = t->l_child.leaf->op((gpointer)&state->ppid,v); |
1325 | break; |
1326 | case LTTV_FILTER_STATE_CT: |
1327 | if(state == NULL) lresult = TRUE; |
1328 | else { |
1329 | double val = ltt_time_to_double(state->creation_time); |
1330 | lresult = t->l_child.leaf->op((gpointer)&val,v); |
1331 | } |
1332 | break; |
1333 | case LTTV_FILTER_STATE_IT: |
1334 | if(state == NULL) lresult = TRUE; |
1335 | else { |
1336 | double val = ltt_time_to_double(state->insertion_time); |
1337 | lresult = t->l_child.leaf->op((gpointer)&val,v); |
1338 | } |
1339 | break; |
1340 | case LTTV_FILTER_STATE_P_NAME: |
1341 | /* |
1342 | * FIXME: Yet to be done ( I think ? ) |
1343 | */ |
1344 | lresult = TRUE; |
1345 | break; |
1346 | case LTTV_FILTER_STATE_EX_MODE: |
1347 | if(state == NULL) lresult = TRUE; |
1348 | else lresult = t->l_child.leaf->op((gpointer)&state->state->t,v); |
1349 | break; |
1350 | case LTTV_FILTER_STATE_EX_SUBMODE: |
1351 | if(state == NULL) lresult = TRUE; |
1352 | else lresult = t->l_child.leaf->op((gpointer)&state->state->n,v); |
1353 | break; |
1354 | case LTTV_FILTER_STATE_P_STATUS: |
1355 | if(state == NULL) lresult = TRUE; |
1356 | else lresult = t->l_child.leaf->op((gpointer)&state->state->s,v); |
1357 | break; |
1358 | case LTTV_FILTER_STATE_CPU: |
1359 | /* |
1360 | * FIXME: What is the comparison value ? |
1361 | */ |
1362 | lresult = TRUE; |
1363 | break; |
1364 | case LTTV_FILTER_EVENT_NAME: |
1365 | if(event == NULL) lresult = TRUE; |
1366 | else lresult = t->l_child.leaf->op((gpointer)ltt_event_eventtype(event),v); |
1367 | break; |
1368 | |
1369 | case LTTV_FILTER_EVENT_CATEGORY: |
1370 | /* |
1371 | * FIXME: Not yet implemented |
1372 | */ |
1373 | lresult = TRUE; |
1374 | break; |
1375 | case LTTV_FILTER_EVENT_TIME: |
1376 | // if(event == NULL) lresult = TRUE; |
1377 | // else { |
1378 | // double val = ltt_time_to_double(event->event_time); |
1379 | // lresult = t->l_child.leaf->op((gpointer)&val,v); |
1380 | // } |
1381 | lresult = TRUE; |
1382 | break; |
1383 | case LTTV_FILTER_EVENT_TSC: |
1384 | // if(event == NULL) lresult = TRUE; |
1385 | // else { |
1386 | // double val = ltt_time_to_double(event->event_time); |
1387 | // lresult = t->l_child.leaf->op((gpointer)&val,v); |
1388 | // } |
1389 | /* |
1390 | * FIXME: Where is event.tsc |
1391 | */ |
1392 | lresult = TRUE; |
1393 | break; |
1394 | case LTTV_FILTER_EVENT_FIELD: |
1395 | /* |
1396 | * TODO: Use the offset to |
1397 | * find the dynamic field |
1398 | * in the event struct |
1399 | */ |
1400 | lresult = TRUE; |
1401 | default: |
1402 | /* |
1403 | * This case should never be |
1404 | * parsed, if so, the whole |
1405 | * filtering is cancelled |
1406 | */ |
1407 | g_warning("Error while parsing the filter tree"); |
1408 | return TRUE; |
1409 | } |
0cdc2470 |
1410 | } |
80f9611a |
1411 | |
1412 | /* |
1413 | * Parse linking operator |
1414 | * make a cutoff if possible |
1415 | */ |
1416 | if((t->node & LTTV_LOGICAL_OR) && lresult == TRUE) return TRUE; |
1417 | if((t->node & LTTV_LOGICAL_AND) && lresult == FALSE) return FALSE; |
1418 | |
1419 | /* |
1420 | * Parse right branch |
1421 | */ |
1422 | if(t->right == LTTV_TREE_NODE) rresult = lttv_filter_tree_parse(t->r_child.t,event,tracefile,trace,state); |
5b729fcf |
1423 | else if(t->right == LTTV_TREE_LEAF) { |
80f9611a |
1424 | //g_print("%p: right is %i %p %s\n",t,t->r_child.leaf->field,t->r_child.leaf->op,t->r_child.leaf->value); |
1425 | char* v; |
1426 | g_assert(v = t->r_child.leaf->value); |
1427 | switch(t->r_child.leaf->field) { |
1428 | |
1429 | case LTTV_FILTER_TRACE_NAME: |
1430 | if(trace == NULL) rresult = TRUE; |
1431 | else rresult = t->r_child.leaf->op((gpointer)ltt_trace_name(trace),v); |
1432 | break; |
1433 | case LTTV_FILTER_TRACEFILE_NAME: |
1434 | if(tracefile == NULL) rresult = TRUE; |
1435 | else rresult = t->r_child.leaf->op((gpointer)ltt_tracefile_name(tracefile),v); |
1436 | break; |
1437 | case LTTV_FILTER_STATE_PID: |
1438 | if(state == NULL) rresult = TRUE; |
1439 | else rresult = t->r_child.leaf->op((gpointer)&state->pid,v); |
1440 | break; |
1441 | case LTTV_FILTER_STATE_PPID: |
1442 | if(state == NULL) rresult = TRUE; |
1443 | else rresult = t->r_child.leaf->op((gpointer)&state->ppid,v); |
1444 | break; |
1445 | case LTTV_FILTER_STATE_CT: |
1446 | if(state == NULL) rresult = TRUE; |
1447 | else { |
1448 | double val = ltt_time_to_double(state->creation_time); |
1449 | rresult = t->r_child.leaf->op((gpointer)&val,v); |
1450 | } |
1451 | break; |
1452 | case LTTV_FILTER_STATE_IT: |
1453 | if(state == NULL) rresult = TRUE; |
1454 | else { |
1455 | double val = ltt_time_to_double(state->insertion_time); |
1456 | rresult = t->r_child.leaf->op((gpointer)&val,v); |
1457 | } |
1458 | break; |
1459 | case LTTV_FILTER_STATE_P_NAME: |
1460 | /* |
1461 | * FIXME: Yet to be done ( I think ? ) |
1462 | */ |
1463 | rresult = TRUE; |
1464 | break; |
1465 | case LTTV_FILTER_STATE_EX_MODE: |
1466 | if(state == NULL) rresult = TRUE; |
1467 | else rresult = t->r_child.leaf->op((gpointer)&state->state->t,v); |
1468 | break; |
1469 | case LTTV_FILTER_STATE_EX_SUBMODE: |
1470 | if(state == NULL) rresult = TRUE; |
1471 | else rresult = t->r_child.leaf->op((gpointer)&state->state->n,v); |
1472 | break; |
1473 | case LTTV_FILTER_STATE_P_STATUS: |
1474 | if(state == NULL) rresult = TRUE; |
1475 | else rresult = t->r_child.leaf->op((gpointer)&state->state->s,v); |
1476 | break; |
1477 | case LTTV_FILTER_STATE_CPU: |
1478 | /* |
1479 | * FIXME: What is the comparison value ? |
1480 | */ |
1481 | rresult = TRUE; |
1482 | break; |
1483 | case LTTV_FILTER_EVENT_NAME: |
1484 | if(event == NULL) rresult = TRUE; |
1485 | else rresult = t->r_child.leaf->op((gpointer)ltt_event_eventtype(event),v); |
1486 | break; |
1487 | |
1488 | case LTTV_FILTER_EVENT_CATEGORY: |
1489 | /* |
1490 | * FIXME: Not yet implemented |
1491 | */ |
1492 | rresult = TRUE; |
1493 | break; |
1494 | case LTTV_FILTER_EVENT_TIME: |
1495 | // if(event == NULL) rresult = TRUE; |
1496 | // else { |
1497 | // double val = ltt_time_to_double(event->event_time); |
1498 | // rresult = t->r_child.leaf->op((gpointer)&val,v); |
1499 | // } |
1500 | rresult = TRUE; |
1501 | break; |
1502 | case LTTV_FILTER_EVENT_TSC: |
1503 | // if(event == NULL) rresult = TRUE; |
1504 | // else { |
1505 | // double val = ltt_time_to_double(event->event_time); |
1506 | // rresult = t->r_child.leaf->op((gpointer)&val,v); |
1507 | // } |
1508 | /* |
1509 | * FIXME: Where is event.tsc |
1510 | */ |
1511 | rresult = TRUE; |
1512 | break; |
1513 | case LTTV_FILTER_EVENT_FIELD: |
1514 | /* |
1515 | * TODO: Use the offset to |
1516 | * find the dynamic field |
1517 | * in the event struct |
1518 | */ |
1519 | rresult = TRUE; |
1520 | default: |
1521 | /* |
1522 | * This case should never be |
1523 | * parsed, if so, this subtree |
1524 | * is cancelled ! |
1525 | */ |
1526 | g_warning("Error while parsing the filter tree"); |
1527 | return TRUE; |
1528 | } |
0cdc2470 |
1529 | } |
5f185a2b |
1530 | |
80f9611a |
1531 | /* |
1532 | * Apply and return the |
1533 | * logical link between the |
1534 | * two operation |
1535 | */ |
1536 | switch(t->node) { |
1537 | case LTTV_LOGICAL_OR: return (lresult | rresult); |
1538 | case LTTV_LOGICAL_AND: return (lresult & rresult); |
1539 | case LTTV_LOGICAL_NOT: return (!rresult); |
1540 | case LTTV_LOGICAL_XOR: return (lresult ^ rresult); |
1541 | default: |
1542 | /* |
1543 | * This case should never be |
1544 | * parsed, if so, this subtree |
1545 | * is cancelled ! |
1546 | */ |
1547 | return TRUE; |
1548 | } |
0769c82f |
1549 | |
80f9611a |
1550 | } |
0769c82f |
1551 | |
80f9611a |
1552 | /** |
1553 | * Debug |
1554 | */ |
1555 | void |
1556 | lttv_print_tree(LttvFilterTree* t) { |
0769c82f |
1557 | |
80f9611a |
1558 | g_print("node:%p lchild:%p rchild:%p\n",t, |
1559 | (t->left==LTTV_TREE_NODE)?t->l_child.t:NULL, |
1560 | (t->right==LTTV_TREE_NODE)?t->r_child.t:NULL); |
1561 | g_print("node type: %i / [left] %i / [right] %i\n",t->node,t->left,t->right); |
1562 | if(t->left == LTTV_TREE_NODE) lttv_print_tree(t->l_child.t); |
1563 | else if(t->left == LTTV_TREE_LEAF) { |
1564 | g_assert(t->l_child.leaf->value != NULL); |
1565 | g_print("%p: left is %i %p %s\n",t,t->l_child.leaf->field,t->l_child.leaf->op,t->l_child.leaf->value); |
0769c82f |
1566 | } |
80f9611a |
1567 | g_print("1\n"); |
1568 | if(t->right == LTTV_TREE_NODE) lttv_print_tree(t->r_child.t); |
1569 | else if(t->right == LTTV_TREE_LEAF) { |
1570 | g_assert(t->r_child.leaf->value != NULL); |
1571 | g_print("%p: right is %i %p %s\n",t,t->r_child.leaf->field,t->r_child.leaf->op,t->r_child.leaf->value); |
1572 | } |
1573 | g_print("end\n"); |
1574 | |
1575 | } |
1576 | |
1577 | /** |
1578 | * Apply the filter to a specific trace |
1579 | * @param filter the current filter applied |
1580 | * @param tracefile the trace to apply the filter to |
1581 | * @return success/failure of operation |
0769c82f |
1582 | */ |
80f9611a |
1583 | gboolean |
1584 | lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile) { |
1585 | |
1586 | return lttv_filter_tree_parse(filter->head,NULL,tracefile,NULL,NULL); |
1587 | |
31452f49 |
1588 | } |
1589 | |
1a7fa682 |
1590 | gboolean |
2ea36caf |
1591 | lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate) { |
341aa948 |
1592 | |
1593 | } |
1a7fa682 |
1594 | |
84a333d6 |
1595 | /** |
1596 | * Apply the filter to a specific event |
1597 | * @param filter the current filter applied |
1598 | * @param event the event to apply the filter to |
1599 | * @return success/failure of operation |
1600 | */ |
31452f49 |
1601 | gboolean |
2ea36caf |
1602 | lttv_filter_event(LttvFilter *filter, LttEvent *event) { |
31452f49 |
1603 | |
1604 | } |
1a7fa682 |
1605 | |
91ad3f0a |
1606 | /** |
1607 | * Initializes the filter module and specific values |
1608 | */ |
1a7fa682 |
1609 | static void module_init() |
1610 | { |
91ad3f0a |
1611 | |
1612 | /* |
1613 | * Quarks initialization |
1614 | * for hardcoded filtering options |
1615 | * |
1616 | * TODO: traceset has no yet been defined |
1617 | */ |
1618 | |
1619 | /* top fields */ |
5b729fcf |
1620 | // LTTV_FILTER_EVENT = g_quark_from_string("event"); |
1621 | // LTTV_FILTER_TRACE = g_quark_from_string("trace"); |
1622 | // LTTV_FILTER_TRACESET = g_quark_from_string("traceset"); |
1623 | // LTTV_FILTER_STATE = g_quark_from_string("state"); |
1624 | // LTTV_FILTER_TRACEFILE = g_quark_from_string("tracefile"); |
1a7fa682 |
1625 | |
91ad3f0a |
1626 | /* event.name, tracefile.name, trace.name */ |
5b729fcf |
1627 | // LTTV_FILTER_NAME = g_quark_from_string("name"); |
91ad3f0a |
1628 | |
1629 | /* event sub fields */ |
5b729fcf |
1630 | // LTTV_FILTER_CATEGORY = g_quark_from_string("category"); |
1631 | // LTTV_FILTER_TIME = g_quark_from_string("time"); |
1632 | // LTTV_FILTER_TSC = g_quark_from_string("tsc"); |
91ad3f0a |
1633 | |
1634 | /* state sub fields */ |
5b729fcf |
1635 | // LTTV_FILTER_PID = g_quark_from_string("pid"); |
1636 | // LTTV_FILTER_PPID = g_quark_from_string("ppid"); |
1637 | // LTTV_FILTER_C_TIME = g_quark_from_string("creation_time"); |
1638 | // LTTV_FILTER_I_TIME = g_quark_from_string("insertion_time"); |
1639 | // LTTV_FILTER_P_NAME = g_quark_from_string("process_name"); |
1640 | // LTTV_FILTER_EX_MODE = g_quark_from_string("execution_mode"); |
1641 | // LTTV_FILTER_EX_SUBMODE = g_quark_from_string("execution_submode"); |
1642 | // LTTV_FILTER_P_STATUS = g_quark_from_string("process_status"); |
1643 | // LTTV_FILTER_CPU = g_quark_from_string("cpu"); |
91ad3f0a |
1644 | |
1a7fa682 |
1645 | } |
1646 | |
91ad3f0a |
1647 | /** |
1648 | * Destroys the filter module and specific values |
1649 | */ |
1a7fa682 |
1650 | static void module_destroy() |
1651 | { |
1652 | } |
1653 | |
1654 | |
91ad3f0a |
1655 | LTTV_MODULE("filter", "Filters traceset and events", \ |
1656 | "Filters traceset and events specifically to user input", \ |
1a7fa682 |
1657 | module_init, module_destroy) |
1658 | |
1659 | |
1660 | |