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