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