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