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