* 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 <lttv/filter.h>
-
/*
read_token
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 <lttv/filter.h>
+
+/*
GQuark
LTTV_FILTER_TRACE,
LTTV_FILTER_TRACESET,
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) {
}
+/**
+ * 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
}
+/**
+ * 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
#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
*/
-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,
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 */
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;
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. */