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