1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 #include <lttv/traceset.h>
23 #include <lttv/tracecontext.h>
24 #include <lttv/state.h>
25 #include <lttv/module.h>
27 #include <ltt/event.h>
29 #define AVERAGE_EXPRESSION_LENGTH 6
30 #define MAX_FACTOR 1.5
32 /* A filter expression consists in nested AND, OR and NOT expressions
33 involving boolean relation (>, >=, =, !=, <, <=) between event fields and
34 specific values. It is compiled into an efficient data structure which
35 is used in functions to check if a given event or tracefile satisfies the
38 The grammar for filters is:
42 expression = "(" expression ")" | "!" expression |
43 expression "&&" expression | expression "||" expression |
46 simpleExpression = fieldPath op value
48 fieldPath = fieldComponent [ "." fieldPath ]
50 fieldComponent = name [ "[" integer "]" ]
52 value = integer | double | string
59 LTTV_FILTER_TRACEFILE
,
72 LTTV_FILTER_EX_SUBMODE
,
77 * @enum lttv_expression_op
79 typedef enum _LttvExpressionOp
81 LTTV_FIELD_EQ
, /** equal */
82 LTTV_FIELD_NE
, /** not equal */
83 LTTV_FIELD_LT
, /** lower than */
84 LTTV_FIELD_LE
, /** lower or equal */
85 LTTV_FIELD_GT
, /** greater than */
86 LTTV_FIELD_GE
/** greater or equal */
90 * FIXME: Unused enum ?
92 typedef enum _LttvExpressionType
95 LTTV_SIMPLE_EXPRESSION
,
97 LTTV_UNDEFINED_EXPRESSION
100 typedef enum _LttvTreeElement
{
106 typedef struct _LttvSimpleExpression
111 } LttvSimpleExpression
;
113 typedef enum _LttvLogicalOp
{
114 LTTV_LOGICAL_OR
= 1, /* 1 */
115 LTTV_LOGICAL_AND
= 1<<1, /* 2 */
116 LTTV_LOGICAL_NOT
= 1<<2, /* 4 */
117 LTTV_LOGICAL_XOR
= 1<<3 /* 8 */
121 * Ah .. that's my tree
123 //typedef struct _lttv_expression
125 // gboolean simple_expression;
127 // lttv_expression_type type;
129 // struct lttv_expression *e;
130 // lttv_field_relation *se; /* --> simple expression */
135 * FIXME: Unused struct
137 typedef struct _LttvExpression
{
138 LttvExpressionType type
;
140 LttvSimpleExpression
*se
;
145 typedef struct _LttvFilter
{
146 // lttv_expression* node;
147 int node
; /** value of LttvLogicalOp */
148 LttvTreeElement left
;
149 LttvTreeElement right
;
151 struct LttvFilter
* t
;
152 LttvSimpleExpression
* leaf
;
155 struct LttvFilter
* t
;
156 LttvSimpleExpression
* leaf
;
161 * @struct lttv_filter
162 * ( will later contain a binary tree of filtering options )
164 //typedef struct _lttv_filter_t {
165 // lttv_filter_tree* tree;
169 LttvSimpleExpression
* lttv_simple_expression_new();
171 LttvFilter
* lttv_filter_tree_new();
173 void lttv_filter_tree_destroy(LttvFilter
* tree
);
175 LttvFilter
* lttv_filter_clone(LttvFilter
* tree
);
177 void lttv_filter_tree_add_node(GPtrArray
* stack
, LttvFilter
* subtree
, LttvLogicalOp op
);
179 /* Parse field path contained in list */
180 gboolean
parse_field_path(GPtrArray
* fp
);
182 gboolean
parse_simple_expression(GString
* expression
);
184 /* Compile the filter expression into an efficient data structure */
185 LttvFilter
*lttv_filter_new(char *expression
, LttvTraceState
*tfs
);
187 void lttv_filter_destroy(LttvFilter
* filter
);
189 /* Check if the tracefile or event satisfies the filter. The arguments are
190 declared as void * to allow these functions to be used as hooks. */
192 gboolean
lttv_filter_tracefile(LttvFilter
*filter
, LttTracefile
*tracefile
);
194 gboolean
lttv_filter_tracestate(LttvFilter
*filter
, LttvTraceState
*tracestate
);
196 gboolean
lttv_filter_event(LttvFilter
*filter
, LttEvent
*event
);