From 73050a5ffb71a9a78b82baba0316d3416738372d Mon Sep 17 00:00:00 2001 From: siboud Date: Wed, 30 Mar 2005 22:22:16 +0000 Subject: [PATCH] Massive debugging in lttv filter core: - for tree construction - for lttv simple expression assignation Still to do: - seg fault occuring when loading trace with the actual tree - changing op functions (type conversion) - look for memory assignation whithin the tree git-svn-id: http://ltt.polymtl.ca/svn@907 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/lttv/lttv/filter.c | 80 +++++++++------- .../poly/lttv/modules/text/batchAnalysis.c | 14 ++- .../poly/lttv/modules/text/textDump.c | 4 +- .../poly/lttv/modules/text/textFilter.c | 93 +++++++++---------- 4 files changed, 102 insertions(+), 89 deletions(-) diff --git a/ltt/branches/poly/lttv/lttv/filter.c b/ltt/branches/poly/lttv/lttv/filter.c index b5986c9a..7219c967 100644 --- a/ltt/branches/poly/lttv/lttv/filter.c +++ b/ltt/branches/poly/lttv/lttv/filter.c @@ -152,9 +152,10 @@ parse_field_path(GPtrArray* fp, LttvSimpleExpression* se) { // GString* f2 = g_ptr_array_index(fp,i); // g_print("%i=%s",i,f2->str); // } + if(fp->len < 2) return FALSE; - g_assert(f=g_ptr_array_index(fp,0)); //list_first(fp)->data; - + g_assert(f=g_ptr_array_remove_index(fp,0)); //list_first(fp)->data; + /* * Parse through the specified * hardcoded fields. @@ -173,11 +174,12 @@ parse_field_path(GPtrArray* fp, LttvSimpleExpression* se) { * Possible values: * trace.name */ - f=g_ptr_array_index(fp,1); + g_string_free(f,TRUE); + f=g_ptr_array_remove_index(fp,0); if(!g_strcasecmp(f->str,"name")) { se->field = LTTV_FILTER_TRACE_NAME; } - else return FALSE; +// else return FALSE; } else if(!g_strcasecmp(f->str,"traceset") ) { /* * FIXME: not yet implemented ! @@ -187,11 +189,12 @@ parse_field_path(GPtrArray* fp, LttvSimpleExpression* se) { * Possible values: * tracefile.name */ - f=g_ptr_array_index(fp,1); + g_string_free(f,TRUE); + f=g_ptr_array_remove_index(fp,0); if(!g_strcasecmp(f->str,"name")) { se->field = LTTV_FILTER_TRACEFILE_NAME; } - else return FALSE; +// else return FALSE; } else if(!g_strcasecmp(f->str,"state") ) { /* * Possible values: @@ -205,7 +208,8 @@ parse_field_path(GPtrArray* fp, LttvSimpleExpression* se) { * state.process_status * state.cpu */ - f=g_ptr_array_index(fp,1); + g_string_free(f,TRUE); + f=g_ptr_array_remove_index(fp,0); if(!g_strcasecmp(f->str,"pid") ) { se->field = LTTV_FILTER_STATE_PID; } @@ -233,7 +237,7 @@ parse_field_path(GPtrArray* fp, LttvSimpleExpression* se) { else if(!g_strcasecmp(f->str,"cpu") ) { se->field = LTTV_FILTER_STATE_CPU; } - else return FALSE; +// else return FALSE; } else if(!g_strcasecmp(f->str,"event") ) { /* * Possible values: @@ -242,7 +246,8 @@ parse_field_path(GPtrArray* fp, LttvSimpleExpression* se) { * event.time * event.tsc */ - f=g_ptr_array_index(fp,1); + g_string_free(f,TRUE); + f=g_ptr_array_remove_index(fp,0); if(!g_strcasecmp(f->str,"name") ) { se->field = LTTV_FILTER_EVENT_NAME; } @@ -266,12 +271,13 @@ parse_field_path(GPtrArray* fp, LttvSimpleExpression* se) { } } else { g_warning("Unrecognized field in filter string"); - return FALSE; +// return FALSE; } - /* free the pointer array */ - g_ptr_array_free(fp,FALSE); + g_string_free(f,TRUE); + g_assert(fp->len == 0); + if(se->field == LTTV_FILTER_UNDEFINED) return FALSE; return TRUE; } @@ -287,7 +293,7 @@ gboolean assign_operator(LttvSimpleExpression* se, LttvExpressionOp op) { // g_print("se->offset = %i\n",se->offset); // g_print("se->op = %p\n",se->op); // g_print("se->value = %s\n",se->value); - + switch(se->field) { /* char */ case LTTV_FILTER_TRACE_NAME: @@ -302,7 +308,7 @@ gboolean assign_operator(LttvSimpleExpression* se, LttvExpressionOp op) { se->op = lttv_apply_op_eq_string; break; default: - g_warning("Error encountered in operator assignment"); + g_warning("Error encountered in operator assignment = or != expected"); return FALSE; } break; @@ -364,7 +370,7 @@ gboolean assign_operator(LttvSimpleExpression* se, LttvExpressionOp op) { } break; default: - g_warning("Error encountered in operator assignment"); + g_warning("Error encountered in operator assignment ! Bad field type ..."); return FALSE; } @@ -909,14 +915,11 @@ lttv_filter_update(LttvFilter* filter) { a_field_path = g_ptr_array_new(); // g_ptr_array_set_size(a_field_path,2); /* by default, recording 2 field expressions */ - + + g_print("expression: %s\n",filter->expression); + g_print("strlen(expression): %i\n",strlen(filter->expression)); for(i=0;iexpression);i++) { // debug - int t; -// for(t=0;tlen;t++) { -// GString* t3 = g_ptr_array_index(a_field_path,t); -// g_print("%i=%s ",t,t3->str); -// } g_print("%c ",filter->expression[i]); switch(filter->expression[i]) { /* @@ -935,7 +938,7 @@ lttv_filter_update(LttvFilter* filter) { t1->right = LTTV_TREE_NODE; t1->r_child.t = t2; } else { /* append a simple expression */ - a_simple_expression->value = a_field_component->str; + a_simple_expression->value = g_string_free(a_field_component,FALSE); a_field_component = g_string_new(""); t2->left = LTTV_TREE_LEAF; t2->l_child.leaf = a_simple_expression; @@ -958,7 +961,7 @@ lttv_filter_update(LttvFilter* filter) { t1->right = LTTV_TREE_NODE; t1->r_child.t = t2; } else { /* append a simple expression */ - a_simple_expression->value = a_field_component->str; + a_simple_expression->value = g_string_free(a_field_component,FALSE); a_field_component = g_string_new(""); t2->left = LTTV_TREE_LEAF; t2->l_child.leaf = a_simple_expression; @@ -981,7 +984,7 @@ lttv_filter_update(LttvFilter* filter) { t1->right = LTTV_TREE_NODE; t1->r_child.t = t2; } else { /* append a simple expression */ - a_simple_expression->value = a_field_component->str; + a_simple_expression->value = g_string_free(a_field_component,FALSE); a_field_component = g_string_new(""); t2->left = LTTV_TREE_LEAF; t2->l_child.leaf = a_simple_expression; @@ -1043,7 +1046,7 @@ lttv_filter_update(LttvFilter* filter) { subtree = g_ptr_array_index(tree_stack,tree_stack->len-1); g_ptr_array_remove_index(tree_stack,tree_stack->len-1); } else { /* assign subtree as current tree */ - a_simple_expression->value = a_field_component->str; + a_simple_expression->value = g_string_free(a_field_component,FALSE); a_field_component = g_string_new(""); t1 = g_ptr_array_index(tree_stack,tree_stack->len-1); while(t1->right != LTTV_TREE_IDLE) t1 = t1->r_child.t; @@ -1105,7 +1108,8 @@ lttv_filter_update(LttvFilter* filter) { break; default: /* concatening current string */ - g_string_append_c(a_field_component,filter->expression[i]); + // fprintf(stderr,"%i>> %p:%s et %p\n",i,a_field_component,a_field_component->str,filter->expression[i]); + g_string_append_c(a_field_component,filter->expression[i]); } } @@ -1133,21 +1137,25 @@ lttv_filter_update(LttvFilter* filter) { t1->r_child.t = subtree; subtree = NULL; } else { /* add a leaf */ - a_simple_expression->value = a_field_component->str; - a_field_component = g_string_new(""); + a_simple_expression->value = g_string_free(a_field_component,FALSE); +// a_field_component = g_string_new(""); t1->right = LTTV_TREE_LEAF; t1->r_child.leaf = a_simple_expression; /* * FIXME: is it really necessary to reallocate * LttvSimpleExpression at this point ?? */ - a_simple_expression = lttv_simple_expression_new(); +// a_simple_expression = lttv_simple_expression_new(); } + /* free the pointer array */ + g_assert(a_field_path->len == 0); + g_ptr_array_free(a_field_path,TRUE); + g_assert(tree != NULL); g_assert(subtree == NULL); - lttv_print_tree(filter->head) ; +// lttv_print_tree(filter->head) ; g_print("ended update tree!\n"); return TRUE; @@ -1294,7 +1302,8 @@ lttv_filter_tree_parse( * -Result of left branchwill not affect exploration of * right branch */ - + g_print("filter::lttv_parse_tree(...)\n"); + gboolean lresult = FALSE, rresult = FALSE; /* @@ -1555,20 +1564,21 @@ lttv_filter_tree_parse( void lttv_print_tree(LttvFilterTree* t) { - g_print("node:%p lchild:%p rchild:%p\n",t, + g_print("node:%p lchild:%p rchild:%p\n",t, //t->l_child.t,t->r_child.t); (t->left==LTTV_TREE_NODE)?t->l_child.t:NULL, (t->right==LTTV_TREE_NODE)?t->r_child.t:NULL); g_print("node type: %i / [left] %i / [right] %i\n",t->node,t->left,t->right); if(t->left == LTTV_TREE_NODE) lttv_print_tree(t->l_child.t); else if(t->left == LTTV_TREE_LEAF) { - g_assert(t->l_child.leaf->value != NULL); +// g_assert(t->l_child.leaf->value != NULL); g_print("%p: left is %i %p %s\n",t,t->l_child.leaf->field,t->l_child.leaf->op,t->l_child.leaf->value); } g_print("1\n"); if(t->right == LTTV_TREE_NODE) lttv_print_tree(t->r_child.t); else if(t->right == LTTV_TREE_LEAF) { - g_assert(t->r_child.leaf->value != NULL); - g_print("%p: right is %i %p %s\n",t,t->r_child.leaf->field,t->r_child.leaf->op,t->r_child.leaf->value); + fprintf(stderr,"leaf!\n"); +// g_assert(t->r_child.leaf->value != NULL); + fprintf(stderr,"%p: right is %i %p %s\n",t,t->r_child.leaf->field,t->r_child.leaf->op,t->r_child.leaf->value); } g_print("end\n"); diff --git a/ltt/branches/poly/lttv/modules/text/batchAnalysis.c b/ltt/branches/poly/lttv/modules/text/batchAnalysis.c index 4482a35c..05dd091c 100644 --- a/ltt/branches/poly/lttv/modules/text/batchAnalysis.c +++ b/ltt/branches/poly/lttv/modules/text/batchAnalysis.c @@ -47,9 +47,7 @@ static char *a_trace; static gboolean a_stats; -static LttvFilter *a_lttv_filter; - -extern GString *a_filter_string; +LttvFilter *a_lttv_filter; void lttv_trace_option(void *hook_data) { @@ -63,6 +61,10 @@ void lttv_trace_option(void *hook_data) static gboolean process_traceset(void *hook_data, void *call_data) { + LttvAttributeValue value; + + LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + LttvTracesetStats *tscs; LttvTracesetContext *tc; @@ -80,8 +82,12 @@ static gboolean process_traceset(void *hook_data, void *call_data) lttv_state_add_event_hooks(&tscs->parent); if(a_stats) lttv_stats_add_event_hooks(tscs); + g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression", + LTTV_POINTER, &value)); + a_lttv_filter = lttv_filter_new(); - lttv_filter_append_expression(a_lttv_filter,a_filter_string->str); + g_debug("Filter string: %s",((GString*)*(value.v_pointer))->str); + lttv_filter_append_expression(a_lttv_filter,((GString*)*(value.v_pointer))->str); //lttv_traceset_context_add_hooks(tc, //before_traceset, after_traceset, NULL, before_trace, after_trace, diff --git a/ltt/branches/poly/lttv/modules/text/textDump.c b/ltt/branches/poly/lttv/modules/text/textDump.c index fea42ef0..1b4a1a4c 100644 --- a/ltt/branches/poly/lttv/modules/text/textDump.c +++ b/ltt/branches/poly/lttv/modules/text/textDump.c @@ -50,6 +50,8 @@ static LttvHooks *before_trace, *event_hook; +extern LttvFilter *a_lttv_filter; + void print_field(LttEvent *e, LttField *f, GString *s, gboolean field_names) { LttType *type; @@ -338,7 +340,7 @@ static int write_event_content(void *hook_data, void *call_data) /* * call to the filter if available */ - // lttv_filter_tree_parse(f->head,e,NULL,NULL,NULL); + lttv_filter_tree_parse(a_lttv_filter->head,e,NULL,NULL,NULL); lttv_event_to_string(e, a_string, TRUE, a_field_names, tfs); g_string_append_printf(a_string,"\n"); diff --git a/ltt/branches/poly/lttv/modules/text/textFilter.c b/ltt/branches/poly/lttv/modules/text/textFilter.c index 27b878a3..08d0cc97 100644 --- a/ltt/branches/poly/lttv/modules/text/textFilter.c +++ b/ltt/branches/poly/lttv/modules/text/textFilter.c @@ -53,9 +53,6 @@ static char *a_file_name = NULL, *a_string = NULL; -GString - *a_filter_string = NULL; - static LttvHooks *before_traceset, *event_hook; @@ -71,12 +68,17 @@ void filter_analyze_file(void *hook_data) { g_print("textFilter::filter_analyze_file\n"); + LttvAttributeValue value; + + LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + /* * User may specify filtering options through static file * and/or command line string. From these sources, an * option string is rebuilded and sent to the filter core */ - a_file = fopen(a_file_name, "r"); + GString* a_file_content = g_string_new(""); + a_file = fopen(a_file_name, "r"); if(a_file == NULL) { g_warning("file %s does not exist", a_file_name); return; @@ -84,22 +86,21 @@ void filter_analyze_file(void *hook_data) { char* line = NULL; size_t len = 0; - - if(a_filter_string == NULL) { - a_filter_string = g_string_new(""); - } - else { - g_string_append(a_filter_string,"&"); /*conjonction between expression*/ - } while(!feof(a_file)) { - getline(&line,&len,a_file); - g_string_append(a_filter_string,line); - line = NULL; + len = getline(&line,&len,a_file); + g_string_append(a_file_content,line); } - -// lttv_filter_append_expression(lttvfilter_t,a_filter_string->str); + free(line); + g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression", + LTTV_POINTER, &value)); + + g_debug("Filter file string b: %s",((GString*)*(value.v_pointer))->str); + if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&'); + g_string_append((GString*)*(value.v_pointer),a_file_content->str); + g_debug("Filter file string a: %s",((GString*)*(value.v_pointer))->str); + // lttv_filter_append_expression(lttvfilter_t,a_filter_string->str); fclose(a_file); } @@ -112,12 +113,16 @@ void filter_analyze_string(void *hook_data) { g_print("textFilter::filter_analyze_string\n"); + LttvAttributeValue value; + + LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + /* * User may specify filtering options through static file * and/or command line string. From these sources, an * option string is rebuilded and sent to the filter core */ - if(a_filter_string==NULL) { +/* if(a_filter_string==NULL) { a_filter_string = g_string_new(""); g_string_append(a_filter_string,a_string); } @@ -125,21 +130,16 @@ void filter_analyze_string(void *hook_data) { g_string_append(a_filter_string,"&"); g_string_append(a_filter_string,a_string); } - +*/ // lttv_filter_append_expression(lttvfilter_t,a_string); + g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression", + LTTV_POINTER, &value)); -} - -/** - * filter to current event depending on the - * filter options tree - * @param hook_data the hook data - * @param call_data the call data - * @return success/error of operation - */ -static gboolean filter_event_content(void *hook_data, void *call_data) { - g_print("textFilter::filter_event_content\n"); /* debug */ + g_debug("Filter string string b: %s",((GString*)*(value.v_pointer))->str); + if(((GString*)*(value.v_pointer))->len != 0) g_string_append_c((GString*)*(value.v_pointer),'&'); + g_string_append((GString*)*(value.v_pointer),a_string); + g_debug("Filter string string a: %s",((GString*)*(value.v_pointer))->str); } /** @@ -153,10 +153,15 @@ static void init() { LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression", + LTTV_POINTER, &value)); + + *(value.v_pointer) = g_string_new(""); + g_info("Init textFilter.c"); a_string = NULL; - lttv_option_add("string", 's', + lttv_option_add("expression", 'e', "filters a string issued by the user on the command line", "string", LTTV_OPT_STRING, &a_string, filter_analyze_string, NULL); @@ -167,22 +172,7 @@ static void init() { "browse the filter options contained in specified file", "file name", LTTV_OPT_STRING, &a_file_name, filter_analyze_file, NULL); - - /* - * Note to myself ! - * LttvAttributeValue::v_pointer is a gpointer* --> void** - * see union LttvAttributeValue for more info - */ - g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event", - LTTV_POINTER, &value)); - g_assert((event_hook = *(value.v_pointer)) != NULL); - lttv_hooks_add(event_hook, filter_event_content, NULL, LTTV_PRIO_DEFAULT); -// g_assert(lttv_iattribute_find_by_path(attributes,"hooks/trace/before", -// LTTV_POINTER, &value)); -// g_assert((before_traceset = *(value.v_pointer)) != NULL); -// lttv_hooks_add(before_traceset, parse_filter_options, NULL, LTTV_PRIO_DEFAULT); - } /** @@ -191,18 +181,23 @@ static void init() { static void destroy() { g_info("Destroy textFilter"); - lttv_option_remove("string"); + lttv_option_remove("expression"); lttv_option_remove("filename"); - lttv_hooks_remove_data(event_hook, filter_event_content, NULL); + LttvAttributeValue value; + + LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); -// lttv_hooks_remove_data(before_traceset, parse_filter_options, NULL); + g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression", + LTTV_POINTER, &value)); + + g_string_free((GString*)*(value.v_pointer),TRUE); } LTTV_MODULE("textFilter", "Filters traces", \ "Filter the trace following commands issued by user input", \ - init, destroy, "batchAnalysis", "option") + init, destroy, "option") -- 2.34.1