From: siboud Date: Sat, 12 Feb 2005 22:25:40 +0000 (+0000) Subject: work on core filter X-Git-Tag: v0.12.20~2620 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a4c292d42202029a5153c487fd01263a183a0af2;p=lttv.git work on core filter - fixed string parsing - began to work on the LttField output git-svn-id: http://ltt.polymtl.ca/svn@869 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/Makefile.am b/ltt/branches/poly/Makefile.am index 1fc073f1..9b5e422f 100644 --- a/ltt/branches/poly/Makefile.am +++ b/ltt/branches/poly/Makefile.am @@ -1,6 +1,6 @@ # WARNING : ltt must come before lttv, so that the traceread library is # up to date -SUBDIRS = ltt lttv lttd +SUBDIRS = ltt lttv lttd doc diff --git a/ltt/branches/poly/lttv/lttv/filter.c b/ltt/branches/poly/lttv/lttv/filter.c index 61422353..8e9aa8fc 100644 --- a/ltt/branches/poly/lttv/lttv/filter.c +++ b/ltt/branches/poly/lttv/lttv/filter.c @@ -20,31 +20,32 @@ consist in AND, OR and NOT nested expressions, forming a tree with simple relations as leaves. The simple relations test is a field in an event is equal, not equal, smaller, smaller or equal, larger, or - larger or equal to a specified value. */ + larger or equal to a specified value. +*/ #include /* - read_token + read_token - read_expression - ( read expr ) - simple expr [ op expr ] + read_expression + ( read expr ) + simple expr [ op expr ] - read_simple_expression - read_field_path [ rel value ] + read_simple_expression + read_field_path [ rel value ] - read_field_path - read_field_component [. field path] + read_field_path + read_field_component [. field path] - read_field_component - name [ \[ value \] ] + read_field_component + name [ \[ value \] ] - data struct: - and/or(left/right) - not(child) - op(left/right) - path(component...) -> field + data struct: + and/or(left/right) + not(child) + op(left/right) + path(component...) -> field */ /** @@ -57,9 +58,8 @@ parse_simple_expression(GString* expression) { unsigned i; -// for(i=0;i, <, =, >=, <=, !=) - * - value - */ - - for(i=0;i': /* higher, higher or equal */ - if(expression[i+1] == '=') { /* >= */ - i++; - current_expression.op = LTTV_FIELD_GE; - } else current_expression.op = LTTV_FIELD_GT; - break; - case '=': /* equal */ - current_expression.op = LTTV_FIELD_EQ; - break; - default: /* concatening current string */ - g_string_append_c(current_option,expression[i]); - } - } +lttv_filter_new(char *expression, LttvTraceState *tfs) { + + /* test */ + char* field = "cpu"; + LttEventType *et; + + // LttField* a_ltt_field = NULL; + // a_ltt_field = find_field(NULL,field); + + // g_print("%s\n",a_ltt_field->field_type->type_name); + + return NULL; + + unsigned + i, + p=0, /* parenthesis nesting value */ + b=0; /* current breakpoint in expression string */ - if( p>0 ) { - g_warning("Wrong filtering options, the string\n\"%s\"\n\ - is not valid due to parenthesis incorrect use",expression); - return NULL; - } + gpointer tree = NULL; + + /* temporary values */ + GString *current_option = g_string_new(""); + lttv_simple_expression a_simple_expression; + + g_print("filter::lttv_filter_new()\n"); /* debug */ + + /* + * 1. parse expression + * 2. construct binary tree + * 3. return corresponding filter + */ + + /* + * Binary tree memory allocation + * - based upon a preliminary block size + */ + gulong size = (strlen(expression)/AVERAGE_EXPRESSION_LENGTH)*MAX_FACTOR; + tree = g_malloc(size*sizeof(lttv_filter_tree)); + + /* + * Parse entire expression and construct + * the binary tree. There are two steps + * in browsing that string + * 1. finding boolean ops ( &,|,^,! ) and parenthesis + * 2. finding simple expressions + * - field path + * - op ( >, <, =, >=, <=, !=) + * - value + */ + + for(i=0;istr); + switch(expression[i]) { + /* + * logical operators + */ + case '&': /* and */ + case '|': /* or */ + case '^': /* xor */ + current_option = g_string_new(""); + break; + case '!': /* not, or not equal (math op) */ + if(expression[i+1] == '=') { /* != */ + a_simple_expression.op = LTTV_FIELD_NE; + i++; + } else { /* ! */ + g_print("%s\n",current_option); + current_option = g_string_new(""); + } + break; + case '(': /* start of parenthesis */ + p++; /* incrementing parenthesis nesting value */ + break; + case ')': /* end of parenthesis */ + p--; /* decrementing parenthesis nesting value */ + break; + + /* + * mathematic operators + */ + case '<': /* lower, lower or equal */ + if(expression[i+1] == '=') { /* <= */ + i++; + a_simple_expression.op = LTTV_FIELD_LE; + } else a_simple_expression.op = LTTV_FIELD_LT; + break; + case '>': /* higher, higher or equal */ + if(expression[i+1] == '=') { /* >= */ + i++; + a_simple_expression.op = LTTV_FIELD_GE; + } else a_simple_expression.op = LTTV_FIELD_GT; + break; + case '=': /* equal */ + a_simple_expression.op = LTTV_FIELD_EQ; + break; + default: /* concatening current string */ + g_string_append_c(current_option,expression[i]); + } + } + + + + if( p>0 ) { + g_warning("Wrong filtering options, the string\n\"%s\"\n\ + is not valid due to parenthesis incorrect use",expression); + return NULL; + } } /** @@ -178,7 +185,7 @@ lttv_filter_new(char *expression, LttvTrace *t) { * @return success/failure of operation */ gboolean -lttv_filter_tracefile(lttv_filter *filter, void *tracefile) { +lttv_filter_tracefile(lttv_filter *filter, LttvTrace *tracefile) { } @@ -189,6 +196,6 @@ lttv_filter_tracefile(lttv_filter *filter, void *tracefile) { * @return success/failure of operation */ gboolean -lttv_filter_event(lttv_filter *filter, void *event) { +lttv_filter_event(lttv_filter *filter, LttEvent *event) { } diff --git a/ltt/branches/poly/lttv/lttv/filter.h b/ltt/branches/poly/lttv/lttv/filter.h index 2135f5f3..9224a9a5 100644 --- a/ltt/branches/poly/lttv/lttv/filter.h +++ b/ltt/branches/poly/lttv/lttv/filter.h @@ -20,6 +20,13 @@ #define FILTER_H #include +#include +#include +#include +#include + +#define AVERAGE_EXPRESSION_LENGTH 6 +#define MAX_FACTOR 1.5 /* A filter expression consists in nested AND, OR and NOT expressions involving boolean relation (>, >=, =, !=, <, <=) between event fields and @@ -71,6 +78,12 @@ typedef struct _lttv_simple_expression char *value; } lttv_simple_expression; + +//typedef union _tmp { +// struct lttv_expression *e; +// lttv_field_relation *se; +//} tmp; +/* typedef struct _lttv_expression { gboolean or; @@ -78,11 +91,13 @@ typedef struct _lttv_expression gboolean and; gboolean xor; gboolean simple_expression; -// union e -// { -// struct lttv_expression *e; -// lttv_field_relation *se; -// }; +// tmp e; +} lttv_expression; +*/ + +typedef union _lttv_expression { + lttv_simple_expression se; + } lttv_expression; typedef struct _lttv_filter_tree { @@ -103,15 +118,15 @@ gboolean parse_simple_expression(GString* expression); /* Compile the filter expression into an efficient data structure */ -lttv_filter *lttv_filter_new(char *expression, LttvTrace *t); +lttv_filter *lttv_filter_new(char *expression, LttvTraceState *tfs); /* Check if the tracefile or event satisfies the filter. The arguments are declared as void * to allow these functions to be used as hooks. */ -gboolean lttv_filter_tracefile(lttv_filter *filter, void *tracefile); +gboolean lttv_filter_tracefile(lttv_filter *filter, LttvTrace *tracefile); -gboolean lttv_filter_event(lttv_filter *filter, void *event); +gboolean lttv_filter_event(lttv_filter *filter, LttEvent *event); #endif // FILTER_H diff --git a/ltt/branches/poly/lttv/modules/text/textFilter.c b/ltt/branches/poly/lttv/modules/text/textFilter.c index 41d3ad1d..c0e56ee1 100644 --- a/ltt/branches/poly/lttv/modules/text/textFilter.c +++ b/ltt/branches/poly/lttv/modules/text/textFilter.c @@ -65,7 +65,7 @@ static void parse_filter_options(void *hook_data, void *call_data) { LttvTracefileState *tfs = (LttvTracefileState *)call_data; - LttvTrace* lt = tfc->t_context->vt; +// LttvTrace* lt = tfc->t_context->vt; /* hook header */ g_info("TextFilter options parser"); @@ -91,7 +91,7 @@ static void parse_filter_options(void *hook_data, void *call_data) { g_warning("textFilter::parser_filter_options() no filtering options specified !"); /* send the filtering string to the core */ - lttv_filter_new(parsed_string,lt); + lttv_filter_new(parsed_string,tfs); }