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>
28 #include <ltt/event.h>
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
55 /* structures prototypes */
56 typedef enum _LttvStructType LttvStructType
;
57 typedef enum _LttvFieldType LttvFieldType
;
58 typedef enum _LttvExpressionOp LttvExpressionOp
;
59 typedef enum _LttvTreeElement LttvTreeElement
;
60 typedef enum _LttvLogicalOp LttvLogicalOp
;
62 typedef union _LttvFieldValue LttvFieldValue
;
64 typedef struct _LttvSimpleExpression LttvSimpleExpression
;
65 typedef struct _LttvFilterTree LttvFilterTree
;
66 typedef struct _LttvFilter LttvFilter
;
70 * @enum LttvStructType
71 * @brief The lttv structures
73 * the LttvStructType enumerates
74 * the possible structures for the
77 enum _LttvStructType
{
80 LTTV_FILTER_TRACEFILE
,
87 * @brief Possible fields for the structures
89 * the LttvFieldType enum consists on
90 * all the hardcoded structures and
91 * their appropriate fields on which
92 * filters can be applied.
95 LTTV_FILTER_TRACE_NAME
, /** trace.name (char*) */
96 LTTV_FILTER_TRACEFILE_NAME
, /** tracefile.name (char*) */
97 LTTV_FILTER_STATE_PID
, /** state.pid (guint) */
98 LTTV_FILTER_STATE_PPID
, /** state.ppid (guint) */
99 LTTV_FILTER_STATE_CT
, /** state.creation_time (double) */
100 LTTV_FILTER_STATE_IT
, /** state.insertion_time (double) */
101 LTTV_FILTER_STATE_P_NAME
, /** state.process_name (char*) */
102 LTTV_FILTER_STATE_EX_MODE
, /** state.execution_mode (LttvExecutionMode) */
103 LTTV_FILTER_STATE_EX_SUBMODE
, /** state.execution_submode (LttvExecutionSubmode) */
104 LTTV_FILTER_STATE_P_STATUS
, /** state.process_status (LttvProcessStatus) */
105 LTTV_FILTER_STATE_CPU
, /** state.cpu (?last_cpu?) */
106 LTTV_FILTER_EVENT_NAME
, /** event.name (char*) */
107 LTTV_FILTER_EVENT_CATEGORY
, /** FIXME: not implemented */
108 LTTV_FILTER_EVENT_TIME
, /** event.time (double) */
109 LTTV_FILTER_EVENT_TSC
, /** event.tsc (double) */
110 LTTV_FILTER_EVENT_FIELD
,
111 LTTV_FILTER_UNDEFINED
/** undefined field */
115 * @enum LttvExpressionOp
116 * @brief Contains possible operators
118 * This enumeration defines the
119 * possible operator used to compare
120 * right and left member in simple
123 enum _LttvExpressionOp
125 LTTV_FIELD_EQ
, /** equal */
126 LTTV_FIELD_NE
, /** not equal */
127 LTTV_FIELD_LT
, /** lower than */
128 LTTV_FIELD_LE
, /** lower or equal */
129 LTTV_FIELD_GT
, /** greater than */
130 LTTV_FIELD_GE
/** greater or equal */
134 * @union LttvFieldValue
136 * @brief Contains possible field values
137 * This particular union defines the
138 * possible set of values taken by the
139 * right member of a simple expression.
140 * It is used for comparison whithin the
141 * 'operators' functions
143 union _LttvFieldValue
{
153 * @enum LttvTreeElement
154 * @brief element types for the tree nodes
156 * LttvTreeElement defines the possible
157 * types of nodes which build the LttvFilterTree.
159 enum _LttvTreeElement
{
160 LTTV_TREE_IDLE
, /** this node does nothing */
161 LTTV_TREE_NODE
, /** this node contains a logical operator */
162 LTTV_TREE_LEAF
/** this node is a leaf and contains a simple expression */
167 * @struct LttvSimpleExpression
168 * @brief simple expression structure
170 * An LttvSimpleExpression is the base
171 * of all filtering operations. It also
172 * populates the leaves of the
173 * LttvFilterTree. Each expression
174 * consists basically in a structure
175 * field, an operator and a specific
178 struct _LttvSimpleExpression
180 gint field
; /** left member of simple expression */
181 gint offset
; /** offset used for dynamic fields */
182 gboolean (*op
)(gpointer
,LttvFieldValue
); /** operator of simple expression */
184 LttvFieldValue value
; /** right member of simple expression */
188 * @enum LttvLogicalOp
189 * @brief logical operators
191 * Contains the possible values taken
192 * by logical operator used to link
193 * simple expression. Values are
194 * AND, OR, XOR or NOT
196 enum _LttvLogicalOp
{
197 LTTV_LOGICAL_OR
= 1, /** OR (1) */
198 LTTV_LOGICAL_AND
= 1<<1, /** AND (2) */
199 LTTV_LOGICAL_NOT
= 1<<2, /** NOT (4) */
200 LTTV_LOGICAL_XOR
= 1<<3 /** XOR (8) */
204 * @struct LttvFilterTree
205 * The filtering tree is used to represent the
206 * expression string in its entire hierarchy
207 * composed of simple expressions and logical
210 struct _LttvFilterTree
{
211 int node
; /** value of LttvLogicalOp */
212 LttvTreeElement left
;
213 LttvTreeElement right
;
216 LttvSimpleExpression
* leaf
;
220 LttvSimpleExpression
* leaf
;
225 * @struct lttv_filter
226 * Contains a binary tree of filtering options along
227 * with the expression itself.
231 LttvFilterTree
*head
;
237 LttvSimpleExpression
* lttv_simple_expression_new();
239 gboolean
lttv_simple_expression_add_field(GPtrArray
* fp
, LttvSimpleExpression
* se
);
241 gboolean
lttv_simple_expression_assign_operator(LttvSimpleExpression
* se
, LttvExpressionOp op
);
243 gboolean
lttv_simple_expression_assign_value(LttvSimpleExpression
* se
, char* value
);
245 void lttv_simple_expression_destroy(LttvSimpleExpression
* se
);
249 * Logical operators functions
252 gboolean
lttv_apply_op_eq_uint64(const gpointer v1
, LttvFieldValue v2
);
253 gboolean
lttv_apply_op_eq_uint32(const gpointer v1
, LttvFieldValue v2
);
254 gboolean
lttv_apply_op_eq_uint16(const gpointer v1
, LttvFieldValue v2
);
255 gboolean
lttv_apply_op_eq_double(const gpointer v1
, LttvFieldValue v2
);
256 gboolean
lttv_apply_op_eq_string(const gpointer v1
, LttvFieldValue v2
);
257 gboolean
lttv_apply_op_eq_ltttime(const gpointer v1
, LttvFieldValue v2
);
259 gboolean
lttv_apply_op_ne_uint64(const gpointer v1
, LttvFieldValue v2
);
260 gboolean
lttv_apply_op_ne_uint32(const gpointer v1
, LttvFieldValue v2
);
261 gboolean
lttv_apply_op_ne_uint16(const gpointer v1
, LttvFieldValue v2
);
262 gboolean
lttv_apply_op_ne_double(const gpointer v1
, LttvFieldValue v2
);
263 gboolean
lttv_apply_op_ne_string(const gpointer v1
, LttvFieldValue v2
);
264 gboolean
lttv_apply_op_ne_ltttime(const gpointer v1
, LttvFieldValue v2
);
266 gboolean
lttv_apply_op_lt_uint64(const gpointer v1
, LttvFieldValue v2
);
267 gboolean
lttv_apply_op_lt_uint32(const gpointer v1
, LttvFieldValue v2
);
268 gboolean
lttv_apply_op_lt_uint16(const gpointer v1
, LttvFieldValue v2
);
269 gboolean
lttv_apply_op_lt_double(const gpointer v1
, LttvFieldValue v2
);
270 gboolean
lttv_apply_op_lt_ltttime(const gpointer v1
, LttvFieldValue v2
);
272 gboolean
lttv_apply_op_le_uint64(const gpointer v1
, LttvFieldValue v2
);
273 gboolean
lttv_apply_op_le_uint32(const gpointer v1
, LttvFieldValue v2
);
274 gboolean
lttv_apply_op_le_uint16(const gpointer v1
, LttvFieldValue v2
);
275 gboolean
lttv_apply_op_le_double(const gpointer v1
, LttvFieldValue v2
);
276 gboolean
lttv_apply_op_le_ltttime(const gpointer v1
, LttvFieldValue v2
);
278 gboolean
lttv_apply_op_gt_uint64(const gpointer v1
, LttvFieldValue v2
);
279 gboolean
lttv_apply_op_gt_uint32(const gpointer v1
, LttvFieldValue v2
);
280 gboolean
lttv_apply_op_gt_uint16(const gpointer v1
, LttvFieldValue v2
);
281 gboolean
lttv_apply_op_gt_double(const gpointer v1
, LttvFieldValue v2
);
282 gboolean
lttv_apply_op_gt_ltttime(const gpointer v1
, LttvFieldValue v2
);
284 gboolean
lttv_apply_op_ge_uint64(const gpointer v1
, LttvFieldValue v2
);
285 gboolean
lttv_apply_op_ge_uint32(const gpointer v1
, LttvFieldValue v2
);
286 gboolean
lttv_apply_op_ge_uint16(const gpointer v1
, LttvFieldValue v2
);
287 gboolean
lttv_apply_op_ge_double(const gpointer v1
, LttvFieldValue v2
);
288 gboolean
lttv_apply_op_ge_ltttime(const gpointer v1
, LttvFieldValue v2
);
294 LttvFilterTree
* lttv_filter_tree_clone(const LttvFilterTree
* tree
);
296 LttvFilter
* lttv_filter_clone(const LttvFilter
* filter
);
301 LttvFilter
*lttv_filter_new();
303 gboolean
lttv_filter_update(LttvFilter
* filter
);
305 void lttv_filter_destroy(LttvFilter
* filter
);
307 gboolean
lttv_filter_append_expression(LttvFilter
* filter
, char *expression
);
309 void lttv_filter_clear_expression(LttvFilter
* filter
);
314 LttvFilterTree
* lttv_filter_tree_new();
316 void lttv_filter_tree_destroy(LttvFilterTree
* tree
);
318 gboolean
lttv_filter_tree_parse(
319 const LttvFilterTree
* t
,
320 const LttEvent
* event
,
321 const LttTracefile
* tracefile
,
322 const LttTrace
* trace
,
323 const LttvProcessState
* state
,
324 const LttvTracefileContext
* context
);
326 gboolean
lttv_filter_tree_parse_branch(
327 const LttvSimpleExpression
* se
,
328 const LttEvent
* event
,
329 const LttTracefile
* tracefile
,
330 const LttTrace
* trace
,
331 const LttvProcessState
* state
,
332 const LttvTracefileContext
* context
);
337 void lttv_print_tree(const LttvFilterTree
* t
);