work on core filter
authorsiboud <siboud@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 12 Feb 2005 22:25:40 +0000 (22:25 +0000)
committersiboud <siboud@04897980-b3bd-0310-b5e0-8ef037075253>
Sat, 12 Feb 2005 22:25:40 +0000 (22:25 +0000)
- fixed string parsing
- began to work on the LttField output

git-svn-id: http://ltt.polymtl.ca/svn@869 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/Makefile.am
ltt/branches/poly/lttv/lttv/filter.c
ltt/branches/poly/lttv/lttv/filter.h
ltt/branches/poly/lttv/modules/text/textFilter.c

index 1fc073f17181cc5d3e067ec4f791f886c18ee7d3..9b5e422fec6a65c807d2f257be1f69d2a7074725 100644 (file)
@@ -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
 
 
index 6142235309a9fd9c62187483758c7cba0e3fdba7..8e9aa8fc7aa11249e5d655219fee7658c7841614 100644 (file)
    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 <lttv/filter.h>
 
 /*
-       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<strlen(expression);i++) {
-//
-//     }
+  
+
 }
 
 /**
@@ -69,106 +69,113 @@ parse_simple_expression(GString* expression) {
  *     @return the current lttv_filter or NULL if error
  */
 lttv_filter*
-lttv_filter_new(char *expression, LttvTrace *t) {
-
-       unsigned        
-               i, 
-               p=0,    /* parenthesis nesting value */
-               b=0;    /* current breakpoint in expression string */
-       
-       gpointer tree;
-               
-       GString *current_option = g_string_new(""); 
-       lttv_simple_expression current_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)/6) * 1.5;     
-       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;i<strlen(expression);i++) {
-               switch(expression[i]) {
-                       /*
-                        *   boolean operators
-                        */
-                       case '&':               /* and */
-                               parse_simple_expression(current_option);
-                               g_print("%s\n",&current_option);
-                               current_option = g_string_new("");
-                               break;
-                       case '|':               /* or */
-                               g_print("%s\n",current_option);
-                               current_option = g_string_new("");
-                               break;
-                       case '^':               /* xor */
-                               g_print("%s\n",current_option);
-                               current_option = g_string_new("");
-                               break;
-                       case '!':               /* not, or not equal (math op) */
-                               if(expression[i+1] == '=') {  /* != */
-                                 current_expression.op = LTTV_FIELD_NE;
-                                 i++;
-                               } else {  /* ! */
-                                 g_print("%s\n",current_option);
-                                 current_option = g_string_new("");
-                               }
-                               break;
-                       case '(':               /* start of parenthesis */
-                               p++;
-                               break;
-                       case ')':               /* end of parenthesis */
-                               p--;
-                               break;
-
-                       /*      
-                        *      mathematic operators
-                        */
-                       case '<':   /* lower, lower or equal */
-                               if(expression[i+1] == '=') { /* <= */
-                                 i++;
-                                 current_expression.op = LTTV_FIELD_LE;                  
-                               } else current_expression.op = LTTV_FIELD_LT;
-                               break;
-                       case '>':   /* 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;i<strlen(expression);i++) {
+    g_print("%s\n",current_option->str);
+    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) {
 
 }
index 2135f5f3b10a72223c20933bee7e9b246af38c2f..9224a9a51e6cbef7898387af740d297b231d9c2c 100644 (file)
 #define FILTER_H
 
 #include <lttv/traceset.h>
+#include <lttv/tracecontext.h>
+#include <lttv/state.h>
+#include <ltt/ltt.h>
+#include <ltt/event.h>
+
+#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
 
index 41d3ad1d75f384bd16b3c50c8c9698a3df033edd..c0e56ee14781a0f6219a3fd85c9ea955b598324b 100644 (file)
@@ -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);     
        
 }
 
This page took 0.032714 seconds and 4 git commands to generate.