// 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.
* 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 !
* 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:
* 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;
}
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:
* 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;
}
}
} 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;
}
// 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:
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;
}
break;
default:
- g_warning("Error encountered in operator assignment");
+ g_warning("Error encountered in operator assignment ! Bad field type ...");
return FALSE;
}
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;i<strlen(filter->expression);i++) {
// debug
- int t;
-// for(t=0;t<a_field_path->len;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]) {
/*
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;
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;
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;
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;
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]);
}
}
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;
* -Result of left branchwill not affect exploration of
* right branch
*/
-
+ g_print("filter::lttv_parse_tree(...)\n");
+
gboolean lresult = FALSE, rresult = FALSE;
/*
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");
*a_file_name = NULL,
*a_string = NULL;
-GString
- *a_filter_string = NULL;
-
static LttvHooks
*before_traceset,
*event_hook;
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;
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);
}
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);
}
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);
}
/**
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);
"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);
-
}
/**
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")