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