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