X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Flttv%2Ffilter.h;h=ab559d038339487eba542051cf9a2af2ed3bc36d;hb=150f0d33179740736dba89c0a2ac632c54645c55;hp=99f3c403a2422f7f9e44b780d3610f89e494a2e5;hpb=0769c82fae5a39a6965f63439671ecca48b2d9b5;p=lttv.git diff --git a/ltt/branches/poly/lttv/lttv/filter.h b/ltt/branches/poly/lttv/lttv/filter.h index 99f3c403..ab559d03 100644 --- a/ltt/branches/poly/lttv/lttv/filter.h +++ b/ltt/branches/poly/lttv/lttv/filter.h @@ -22,11 +22,10 @@ #include #include #include +#include #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 @@ -52,89 +51,195 @@ */ -static 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_STATE, - LTTV_FILTER_EVENT; - + LTTV_FILTER_EVENT, + LTTV_FILTER_NAME, + LTTV_FILTER_CATEGORY, + LTTV_FILTER_TIME, + LTTV_FILTER_TSC, + LTTV_FILTER_PID, + LTTV_FILTER_PPID, + LTTV_FILTER_C_TIME, + LTTV_FILTER_I_TIME, + LTTV_FILTER_P_NAME, + LTTV_FILTER_EX_MODE, + LTTV_FILTER_EX_SUBMODE, + LTTV_FILTER_P_STATUS, + LTTV_FILTER_CPU +} LttvFieldType; + /** - * @enum lttv_expression_op + * @enum LttvExpressionOp */ -typedef enum _lttv_expression_op -{ - 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_expression_op; - -typedef enum _lttv_expression_type +typedef enum _LttvExpressionOp { - LTTV_EXPRESSION, - LTTV_SIMPLE_EXPRESSION -} lttv_expression_type; + 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; -typedef struct _lttv_simple_expression +/** + * @enum LttvTreeElement + * @brief element types for the tree nodes + * + * LttvTreeElement defines the possible + * types of nodes which build the LttvFilterTree. + */ +typedef enum _LttvTreeElement { + 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 { - lttv_expression_op op; char *field_name; +// LttvExpressionOp op; + gboolean (*op)(); char *value; -} lttv_simple_expression; +} 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_NOT = 1<<2, /* 4 */ + LTTV_LOGICAL_XOR = 1<<3 /* 8 */ +} LttvLogicalOp; + +/** + * @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 _LttvFilterTree { + int node; /** value of LttvLogicalOp */ + LttvTreeElement left; + LttvTreeElement right; + union { + struct LttvFilter* t; + LttvSimpleExpression* leaf; + } l_child; + union { + struct LttvFilter* t; + LttvSimpleExpression* leaf; + } r_child; +} LttvFilterTree; + +/** + * @struct lttv_filter + * Contains a binary tree of filtering options along + * with the expression itself. + */ +typedef struct _LttvFilter { + char *expression; + LttvFilterTree *head; +} -//typedef union _tmp { -// struct lttv_expression *e; -// lttv_field_relation *se; -//} tmp; /* -typedef struct _lttv_expression -{ - gboolean or; - gboolean not; - gboolean and; - gboolean xor; - gboolean simple_expression; -// tmp e; -} lttv_expression; -*/ + * General Data Handling functions + */ -typedef union _lttv_expression { - lttv_simple_expression se; - -} lttv_expression; +LttvSimpleExpression* lttv_simple_expression_new(); -typedef struct _lttv_filter_tree { - lttv_expression* node; - struct lttv_filter_tree* r_child; - struct lttv_filter_tree* l_child; -} lttv_filter_tree; +void lttv_filter_tree_add_node(GPtrArray* stack, LttvFilter* subtree, LttvLogicalOp op); -/** - * @struct lttv_filter - * ( will later contain a binary tree of filtering options ) +gboolean parse_field_path(GPtrArray* fp); + +gboolean parse_simple_expression(GString* expression); + +/* + * Logical operators functions */ -typedef struct _lttv_filter { - lttv_filter_tree* tree; -} lttv_filter; -gboolean parse_field_path(GList* fp); +gboolean lttv_apply_op_eq(); -gboolean parse_simple_expression(GString* expression); +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 + */ -/* Compile the filter expression into an efficient data structure */ -lttv_filter *lttv_filter_new(char *expression, LttvTraceState *tfs); +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. */ -gboolean lttv_filter_tracefile(lttv_filter *filter, LttTracefile *tracefile); +gboolean lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile); + +gboolean lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate); -gboolean lttv_filter_event(lttv_filter *filter, LttEvent *event); +gboolean lttv_filter_event(LttvFilter *filter, LttEvent *event); #endif // FILTER_H