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