From 150f0d33179740736dba89c0a2ac632c54645c55 Mon Sep 17 00:00:00 2001 From: siboud Date: Sun, 20 Mar 2005 15:41:21 +0000 Subject: [PATCH] filter core: - added some comments for the structures and functions - added functions prototypes for the operator values git-svn-id: http://ltt.polymtl.ca/svn@895 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/lttv/lttv/filter.c | 220 ++++++++++++++++++--------- ltt/branches/poly/lttv/lttv/filter.h | 174 +++++++++++++-------- 2 files changed, 260 insertions(+), 134 deletions(-) diff --git a/ltt/branches/poly/lttv/lttv/filter.c b/ltt/branches/poly/lttv/lttv/filter.c index 0f339a59..0a6dfbca 100644 --- a/ltt/branches/poly/lttv/lttv/filter.c +++ b/ltt/branches/poly/lttv/lttv/filter.c @@ -16,27 +16,6 @@ * MA 02111-1307, USA. */ -/* - 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. -*/ - -/* - * YET TO BE ANSWERED - * - the exists an other lttv_filter which conflicts with this one - */ - -/* - * TODO - * - refine switch of expression in multiple uses functions - * - remove the idle expressions in the tree **** - * - add the current simple expression to the tree - */ - -#include - /* read_token @@ -58,8 +37,28 @@ not(child) op(left/right) path(component...) -> field + + 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. */ +/* + * YET TO BE ANSWERED + * - none yet + */ + +/* + * TODO + * - refine switch of expression in multiple uses functions + * - remove the idle expressions in the tree **** + * - add the current simple expression to the tree + */ + +#include + +/* GQuark LTTV_FILTER_TRACE, LTTV_FILTER_TRACESET, @@ -79,62 +78,18 @@ GQuark LTTV_FILTER_EX_SUBMODE, LTTV_FILTER_P_STATUS, LTTV_FILTER_CPU; +*/ LttvSimpleExpression* lttv_simple_expression_new() { } - /** - * Assign a new tree for the current expression - * or sub expression - * @return pointer of LttvFilter + * add a node to the current tree + * @param stack the tree stack + * @param subtree the subtree if available (pointer or NULL) + * @param op the logical operator that will form the node */ -LttvFilter* lttv_filter_tree_new() { - LttvFilter* tree; - - tree = g_new(LttvFilter,1); - tree->node = 0; //g_new(lttv_expression,1); -// tree->node->type = LTTV_UNDEFINED_EXPRESSION; - tree->left = LTTV_TREE_IDLE; - tree->right = LTTV_TREE_IDLE; - - return tree; -} - -/** - * Destroys the tree and his sub-trees - * @param tree Tree which must be destroyed - */ -void lttv_filter_tree_destroy(LttvFilter* tree) { - - if(tree == NULL) return; - - if(tree->left == LTTV_TREE_LEAF) g_free(tree->l_child.leaf); - else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t); - - if(tree->right == LTTV_TREE_LEAF) g_free(tree->r_child.leaf); - else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t); - - g_free(tree->node); - g_free(tree); -} - -LttvFilter* -lttv_filter_clone(LttvFilter* tree) { - - if(tree == NULL) return NULL; - - LttvFilter* newtree = lttv_filter_tree_new(); - - /* - * TODO : Copy tree into new tree - */ - - return newtree; - -} - void lttv_filter_tree_add_node(GPtrArray* stack, LttvFilter* subtree, LttvLogicalOp op) { @@ -234,6 +189,95 @@ parse_simple_expression(GString* expression) { } +/** + * Applies the 'equal' operator to the + * specified structure and value + * @return success/failure of operation + */ +gboolean lttv_apply_op_eq() { + +} + +/** + * Applies the 'not equal' operator to the + * specified structure and value + * @return success/failure of operation + */ +gboolean lttv_apply_op_ne() { + +} + +/** + * Applies the 'lower than' operator to the + * specified structure and value + * @return success/failure of operation + */ +gboolean lttv_apply_op_lt() { + +} + +/** + * Applies the 'lower or equal' operator to the + * specified structure and value + * @return success/failure of operation + */ +gboolean lttv_apply_op_le() { + +} + +/** + * Applies the 'greater than' operator to the + * specified structure and value + * @return success/failure of operation + */ +gboolean lttv_apply_op_gt() { + +} + +/** + * Applies the 'greater or equal' operator to the + * specified structure and value + * @return success/failure of operation + */ +gboolean lttv_apply_op_ge() { + +} + + + +/** + * Makes a copy of the current filter tree + * @param tree pointer to the current tree + * @return new copy of the filter tree + */ +LttvFilterTree* +lttv_filter_tree_clone(LttvFilterTree* tree) { + + + +} + +/** + * Makes a copy of the current filter + * @param filter pointer to the current filter + * @return new copy of the filter + */ +LttvFilter* +lttv_filter_clone(LttvFilter* filter) { + + + LttvFilter* newfilter = g_new(LttvFilter,1); + + // newfilter->expression = g_new(char,1) + strcpy(newfilter->expression,filter->expression); + + newfilter->head = lttv_filter_tree_clone(filter->head); + + return newfilter; + +} + + /** * Creates a new lttv_filter * @param expression filtering options string @@ -526,6 +570,42 @@ lttv_filter_destroy(LttvFilter* filter) { } +/** + * Assign a new tree for the current expression + * or sub expression + * @return pointer of LttvFilterTree + */ +LttvFilterTree* lttv_filter_tree_new() { + LttvFilterTree* tree; + + tree = g_new(LttvFilter,1); + tree->node = 0; //g_new(lttv_expression,1); +// tree->node->type = LTTV_UNDEFINED_EXPRESSION; + tree->left = LTTV_TREE_IDLE; + tree->right = LTTV_TREE_IDLE; + + return tree; +} + +/** + * Destroys the tree and his sub-trees + * @param tree Tree which must be destroyed + */ +void lttv_filter_tree_destroy(LttvFilterTree* tree) { + + if(tree == NULL) return; + + if(tree->left == LTTV_TREE_LEAF) g_free(tree->l_child.leaf); + else if(tree->left == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->l_child.t); + + if(tree->right == LTTV_TREE_LEAF) g_free(tree->r_child.leaf); + else if(tree->right == LTTV_TREE_NODE) lttv_filter_tree_destroy(tree->r_child.t); + + g_free(tree->node); + g_free(tree); +} + + /** * Apply the filter to a specific trace * @param filter the current filter applied diff --git a/ltt/branches/poly/lttv/lttv/filter.h b/ltt/branches/poly/lttv/lttv/filter.h index 8a017690..ab559d03 100644 --- a/ltt/branches/poly/lttv/lttv/filter.h +++ b/ltt/branches/poly/lttv/lttv/filter.h @@ -26,8 +26,6 @@ #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 @@ -53,7 +51,16 @@ */ -extern GQuark +/** + * @enum LttvFieldType + * @brief Structures and their fields + * + * the LttvFieldType enum consists on + * all the hardcoded structures and + * their appropriate fields on which + * filters can be applied. + */ +enum _LttvFieldType { LTTV_FILTER_TRACE, LTTV_FILTER_TRACESET, LTTV_FILTER_TRACEFILE, @@ -71,45 +78,64 @@ extern GQuark LTTV_FILTER_EX_MODE, LTTV_FILTER_EX_SUBMODE, LTTV_FILTER_P_STATUS, - LTTV_FILTER_CPU; + LTTV_FILTER_CPU +} LttvFieldType; /** - * @enum lttv_expression_op + * @enum LttvExpressionOp */ typedef enum _LttvExpressionOp { - LTTV_FIELD_EQ, /** equal */ - LTTV_FIELD_NE, /** not equal */ - LTTV_FIELD_LT, /** lower than */ - LTTV_FIELD_LE, /** lower or equal */ - LTTV_FIELD_GT, /** greater than */ - LTTV_FIELD_GE /** greater or equal */ + LTTV_FIELD_EQ, /** equal */ + LTTV_FIELD_NE, /** not equal */ + LTTV_FIELD_LT, /** lower than */ + LTTV_FIELD_LE, /** lower or equal */ + LTTV_FIELD_GT, /** greater than */ + LTTV_FIELD_GE /** greater or equal */ } LttvExpressionOp; -/* - * FIXME: Unused enum ? +/** + * @enum LttvTreeElement + * @brief element types for the tree nodes + * + * LttvTreeElement defines the possible + * types of nodes which build the LttvFilterTree. */ -typedef enum _LttvExpressionType -{ - LTTV_EXPRESSION, - LTTV_SIMPLE_EXPRESSION, - LTTV_EXPRESSION_OP, - LTTV_UNDEFINED_EXPRESSION -} LttvExpressionType; - typedef enum _LttvTreeElement { - LTTV_TREE_IDLE, - LTTV_TREE_NODE, - LTTV_TREE_LEAF + LTTV_TREE_IDLE, /** this node does nothing */ + LTTV_TREE_NODE, /** this node contains a logical operator */ + LTTV_TREE_LEAF /** this node is a leaf and contains a simple expression */ } LttvTreeElement; +/** + * @enum LttvSimpleExpression + * @brief simple expression structure + * + * An LttvSimpleExpression is the base + * of all filtering operations. It also + * populates the leaves of the + * LttvFilterTree. Each expression + * consists basically in a structure + * field, an operator and a specific + * value. + */ typedef struct _LttvSimpleExpression { char *field_name; - LttvExpressionOp op; +// LttvExpressionOp op; + gboolean (*op)(); char *value; } LttvSimpleExpression; +/** + * @enum LttvLogicalOp + * @brief logical operators + * + * Contains the possible values taken + * by logical operator used to link + * simple expression. Values are + * AND, OR, XOR or NOT + */ typedef enum _LttvLogicalOp { LTTV_LOGICAL_OR = 1, /* 1 */ LTTV_LOGICAL_AND = 1<<1, /* 2 */ @@ -117,33 +143,14 @@ typedef enum _LttvLogicalOp { LTTV_LOGICAL_XOR = 1<<3 /* 8 */ } LttvLogicalOp; -/* - * Ah .. that's my tree - */ -//typedef struct _lttv_expression -//{ -// gboolean simple_expression; -// int op; -// lttv_expression_type type; -// union { -// struct lttv_expression *e; - // lttv_field_relation *se; /* --> simple expression */ -// } e; -//} lttv_expression; - -/* - * FIXME: Unused struct +/** + * @struct LttvFilterTree + * The filtering tree is used to represent the + * expression string in its entire hierarchy + * composed of simple expressions and logical + * operators */ -typedef struct _LttvExpression { - LttvExpressionType type; - union { - LttvSimpleExpression *se; - int op; - } e; -} LttvExpression; - -typedef struct _LttvFilter { -// lttv_expression* node; +typedef struct _LttvFilterTree { int node; /** value of LttvLogicalOp */ LttvTreeElement left; LttvTreeElement right; @@ -155,37 +162,76 @@ typedef struct _LttvFilter { struct LttvFilter* t; LttvSimpleExpression* leaf; } r_child; -} LttvFilter; +} LttvFilterTree; /** * @struct lttv_filter - * ( will later contain a binary tree of filtering options ) + * Contains a binary tree of filtering options along + * with the expression itself. */ -//typedef struct _lttv_filter_t { -// lttv_filter_tree* tree; -//} lttv_filter_t; +typedef struct _LttvFilter { + char *expression; + LttvFilterTree *head; +} +/* + * General Data Handling functions + */ LttvSimpleExpression* lttv_simple_expression_new(); -LttvFilter* lttv_filter_tree_new(); - -void lttv_filter_tree_destroy(LttvFilter* tree); - -LttvFilter* lttv_filter_clone(LttvFilter* tree); - void lttv_filter_tree_add_node(GPtrArray* stack, LttvFilter* subtree, LttvLogicalOp op); -/* Parse field path contained in list */ gboolean parse_field_path(GPtrArray* fp); gboolean parse_simple_expression(GString* expression); -/* Compile the filter expression into an efficient data structure */ +/* + * Logical operators functions + */ + +gboolean lttv_apply_op_eq(); + +gboolean lttv_apply_op_ne(); + +gboolean lttv_apply_op_lt(); + +gboolean lttv_apply_op_le(); + +gboolean lttv_apply_op_gt(); + +gboolean lttv_apply_op_ge(); + +/* + * Cloning + */ + +LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree* tree); + +LttvFilter* lttv_filter_clone(LttvFilter* filter); + +/* + * Constructors/Destructors + */ + +/* LttvFilter */ LttvFilter *lttv_filter_new(char *expression, LttvTraceState *tfs); void lttv_filter_destroy(LttvFilter* filter); +/* LttvFilterTree */ +LttvFilterTree* lttv_filter_tree_new(); + +void lttv_filter_tree_destroy(LttvFilterTree* tree); + + +/* + * Hook functions + * + * These hook functions will be the one called when filtering + * an event, a trace, a state, etc. + */ + /* Check if the tracefile or event satisfies the filter. The arguments are declared as void * to allow these functions to be used as hooks. */ -- 2.34.1