9c312311 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
852f16bb |
2 | * Copyright (C) 2003-2005 Michel Dagenais and Simon Bouvier-Zappa |
9c312311 |
3 | * |
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; |
7 | * |
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. |
12 | * |
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, |
16 | * MA 02111-1307, USA. |
17 | */ |
18 | |
48f6f3c2 |
19 | #ifndef FILTER_H |
20 | #define FILTER_H |
21 | |
7e7af7f2 |
22 | /*! \file lttv/lttv/filter.h |
23 | * \brief Defines the core filter of application |
24 | * |
25 | * A filter expression consists in nested AND, OR and NOT expressions |
26 | * involving boolean relation (>, >=, =, !=, <, <=) between event fields and |
27 | * specific values. It is compiled into an efficient data structure which |
28 | * is used in functions to check if a given event or tracefile satisfies the |
29 | * filter. |
30 | * |
31 | * The grammar for filters is: |
32 | * |
33 | * filter = expression |
34 | * |
35 | * expression = "(" expression ")" | "!" expression | |
36 | * expression "&&" expression | expression "||" expression | |
37 | * simpleExpression |
38 | * |
39 | * simpleExpression = fieldPath op value |
40 | * |
41 | * fieldPath = fieldComponent [ "." fieldPath ] |
42 | * |
43 | * fieldComponent = name [ "[" integer "]" ] |
44 | * |
45 | * value = integer | double | string |
46 | */ |
47 | |
48 | |
31452f49 |
49 | #include <lttv/traceset.h> |
a4c292d4 |
50 | #include <lttv/tracecontext.h> |
51 | #include <lttv/state.h> |
91ad3f0a |
52 | #include <lttv/module.h> |
a4c292d4 |
53 | #include <ltt/ltt.h> |
7145a073 |
54 | #include <ltt/time.h> |
a4c292d4 |
55 | #include <ltt/event.h> |
56 | |
e00d6a24 |
57 | /* structures prototypes */ |
58 | typedef enum _LttvStructType LttvStructType; |
59 | typedef enum _LttvFieldType LttvFieldType; |
60 | typedef enum _LttvExpressionOp LttvExpressionOp; |
61 | typedef enum _LttvTreeElement LttvTreeElement; |
62 | typedef enum _LttvLogicalOp LttvLogicalOp; |
63 | |
64 | typedef union _LttvFieldValue LttvFieldValue; |
65 | |
66 | typedef struct _LttvSimpleExpression LttvSimpleExpression; |
67 | typedef struct _LttvFilterTree LttvFilterTree; |
68 | typedef struct _LttvFilter LttvFilter; |
69 | |
70 | |
80f9611a |
71 | /** |
7e7af7f2 |
72 | * @enum _LttvStructType |
80f9611a |
73 | * @brief The lttv structures |
74 | * |
75 | * the LttvStructType enumerates |
76 | * the possible structures for the |
77 | * lttv core filter |
78 | */ |
79 | enum _LttvStructType { |
7e7af7f2 |
80 | LTTV_FILTER_TRACE, /**< trace (LttTrace) */ |
81 | LTTV_FILTER_TRACESET, /**< traceset */ |
82 | LTTV_FILTER_TRACEFILE, /**< tracefile (LttTracefile) */ |
83 | LTTV_FILTER_EVENT, /**< event (LttEvent) */ |
84 | LTTV_FILTER_STATE /**< state (LttvProcessState) */ |
e00d6a24 |
85 | }; |
80f9611a |
86 | |
150f0d33 |
87 | /** |
7e7af7f2 |
88 | * @enum _LttvFieldType |
80f9611a |
89 | * @brief Possible fields for the structures |
150f0d33 |
90 | * |
91 | * the LttvFieldType enum consists on |
92 | * all the hardcoded structures and |
93 | * their appropriate fields on which |
94 | * filters can be applied. |
95 | */ |
96 | enum _LttvFieldType { |
7e7af7f2 |
97 | LTTV_FILTER_TRACE_NAME, /**< trace.name (char*) */ |
98 | LTTV_FILTER_TRACEFILE_NAME, /**< tracefile.name (char*) */ |
99 | LTTV_FILTER_STATE_PID, /**< state.pid (guint) */ |
100 | LTTV_FILTER_STATE_PPID, /**< state.ppid (guint) */ |
101 | LTTV_FILTER_STATE_CT, /**< state.creation_time (double) */ |
102 | LTTV_FILTER_STATE_IT, /**< state.insertion_time (double) */ |
103 | LTTV_FILTER_STATE_P_NAME, /**< state.process_name (char*) */ |
104 | LTTV_FILTER_STATE_EX_MODE, /**< state.execution_mode (LttvExecutionMode) */ |
105 | LTTV_FILTER_STATE_EX_SUBMODE, /**< state.execution_submode (LttvExecutionSubmode) */ |
106 | LTTV_FILTER_STATE_P_STATUS, /**< state.process_status (LttvProcessStatus) */ |
107 | LTTV_FILTER_STATE_CPU, /**< state.cpu (?last_cpu?) */ |
108 | LTTV_FILTER_EVENT_NAME, /**< event.name (char*) */ |
109 | LTTV_FILTER_EVENT_CATEGORY, /**< FIXME: not implemented */ |
110 | LTTV_FILTER_EVENT_TIME, /**< event.time (double) */ |
111 | LTTV_FILTER_EVENT_TSC, /**< event.tsc (double) */ |
112 | LTTV_FILTER_EVENT_FIELD, /**< dynamic field, specified in core.xml */ |
113 | LTTV_FILTER_UNDEFINED /**< undefined field */ |
e00d6a24 |
114 | }; |
91ad3f0a |
115 | |
84a333d6 |
116 | /** |
7e7af7f2 |
117 | * @enum _LttvExpressionOp |
56e29124 |
118 | * @brief Contains possible operators |
119 | * |
120 | * This enumeration defines the |
121 | * possible operator used to compare |
122 | * right and left member in simple |
123 | * expression |
84a333d6 |
124 | */ |
e00d6a24 |
125 | enum _LttvExpressionOp |
84a333d6 |
126 | { |
7e7af7f2 |
127 | LTTV_FIELD_EQ, /**< equal */ |
128 | LTTV_FIELD_NE, /**< not equal */ |
129 | LTTV_FIELD_LT, /**< lower than */ |
130 | LTTV_FIELD_LE, /**< lower or equal */ |
131 | LTTV_FIELD_GT, /**< greater than */ |
132 | LTTV_FIELD_GE /**< greater or equal */ |
e00d6a24 |
133 | }; |
84a333d6 |
134 | |
56e29124 |
135 | /** |
7e7af7f2 |
136 | * @union _LttvFieldValue |
56e29124 |
137 | * @brief Contains possible field values |
7e7af7f2 |
138 | * |
56e29124 |
139 | * This particular union defines the |
140 | * possible set of values taken by the |
141 | * right member of a simple expression. |
142 | * It is used for comparison whithin the |
143 | * 'operators' functions |
144 | */ |
e00d6a24 |
145 | union _LttvFieldValue { |
7e7af7f2 |
146 | guint64 v_uint64; /**< unsigned int of 64 bytes */ |
147 | guint32 v_uint32; /**< unsigned int of 32 bytes */ |
148 | guint16 v_uint16; /**< unsigned int of 16 bytes */ |
149 | double v_double; /**< double */ |
150 | char* v_string; /**< string */ |
151 | LttTime v_ltttime; /**< LttTime */ |
e00d6a24 |
152 | }; |
56e29124 |
153 | |
150f0d33 |
154 | /** |
7e7af7f2 |
155 | * @enum _LttvTreeElement |
150f0d33 |
156 | * @brief element types for the tree nodes |
157 | * |
158 | * LttvTreeElement defines the possible |
159 | * types of nodes which build the LttvFilterTree. |
2ea36caf |
160 | */ |
e00d6a24 |
161 | enum _LttvTreeElement { |
7e7af7f2 |
162 | LTTV_TREE_IDLE, /**< this node does nothing */ |
163 | LTTV_TREE_NODE, /**< this node contains a logical operator */ |
164 | LTTV_TREE_LEAF /**< this node is a leaf and contains a simple expression */ |
e00d6a24 |
165 | }; |
f4e9dd16 |
166 | |
56e29124 |
167 | |
150f0d33 |
168 | /** |
7e7af7f2 |
169 | * @struct _LttvSimpleExpression |
150f0d33 |
170 | * @brief simple expression structure |
171 | * |
172 | * An LttvSimpleExpression is the base |
173 | * of all filtering operations. It also |
174 | * populates the leaves of the |
175 | * LttvFilterTree. Each expression |
176 | * consists basically in a structure |
177 | * field, an operator and a specific |
178 | * value. |
179 | */ |
e00d6a24 |
180 | struct _LttvSimpleExpression |
84a333d6 |
181 | { |
7e7af7f2 |
182 | gint field; /**< left member of simple expression */ |
183 | gint offset; /**< offset used for dynamic fields */ |
184 | gboolean (*op)(gpointer,LttvFieldValue); /**< operator of simple expression */ |
185 | LttvFieldValue value; /**< right member of simple expression */ |
e00d6a24 |
186 | }; |
84a333d6 |
187 | |
150f0d33 |
188 | /** |
7e7af7f2 |
189 | * @enum _LttvLogicalOp |
150f0d33 |
190 | * @brief logical operators |
191 | * |
192 | * Contains the possible values taken |
193 | * by logical operator used to link |
194 | * simple expression. Values are |
195 | * AND, OR, XOR or NOT |
196 | */ |
e00d6a24 |
197 | enum _LttvLogicalOp { |
7e7af7f2 |
198 | LTTV_LOGICAL_OR = 1, /**< OR (1) */ |
199 | LTTV_LOGICAL_AND = 1<<1, /**< AND (2) */ |
200 | LTTV_LOGICAL_NOT = 1<<2, /**< NOT (4) */ |
201 | LTTV_LOGICAL_XOR = 1<<3 /**< XOR (8) */ |
e00d6a24 |
202 | }; |
1a7fa682 |
203 | |
150f0d33 |
204 | /** |
7e7af7f2 |
205 | * @struct _LttvFilterTree |
206 | * @brief The filtering tree |
207 | * |
150f0d33 |
208 | * The filtering tree is used to represent the |
209 | * expression string in its entire hierarchy |
210 | * composed of simple expressions and logical |
211 | * operators |
2ea36caf |
212 | */ |
e00d6a24 |
213 | struct _LttvFilterTree { |
7e7af7f2 |
214 | int node; /**< value of LttvLogicalOp */ |
215 | LttvTreeElement left; /**< nature of left branch (node/leaf) */ |
216 | LttvTreeElement right; /**< nature of right branch (node/leaf) */ |
f4e9dd16 |
217 | union { |
7e7af7f2 |
218 | LttvFilterTree* t; |
219 | LttvSimpleExpression* leaf; |
220 | } l_child; /**< left branch of tree */ |
f4e9dd16 |
221 | union { |
7e7af7f2 |
222 | LttvFilterTree* t; |
223 | LttvSimpleExpression* leaf; |
224 | } r_child; /**< right branch of tree */ |
e00d6a24 |
225 | }; |
84a333d6 |
226 | |
31452f49 |
227 | /** |
7e7af7f2 |
228 | * @struct _LttvFilter |
229 | * @brief The filter |
230 | * |
150f0d33 |
231 | * Contains a binary tree of filtering options along |
232 | * with the expression itself. |
31452f49 |
233 | */ |
e00d6a24 |
234 | struct _LttvFilter { |
7e7af7f2 |
235 | char *expression; /**< filtering expression string */ |
236 | LttvFilterTree *head; /**< tree associated to expression */ |
e00d6a24 |
237 | }; |
84a333d6 |
238 | |
56e29124 |
239 | /* |
240 | * Simple Expression |
241 | */ |
242 | LttvSimpleExpression* lttv_simple_expression_new(); |
243 | |
7e7af7f2 |
244 | gboolean lttv_simple_expression_assign_field(GPtrArray* fp, LttvSimpleExpression* se); |
91ad3f0a |
245 | |
56e29124 |
246 | gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression* se, LttvExpressionOp op); |
bb87caa7 |
247 | |
9ab5ebd7 |
248 | gboolean lttv_simple_expression_assign_value(LttvSimpleExpression* se, char* value); |
249 | |
56e29124 |
250 | void lttv_simple_expression_destroy(LttvSimpleExpression* se); |
5f185a2b |
251 | |
5f185a2b |
252 | |
150f0d33 |
253 | /* |
254 | * Logical operators functions |
255 | */ |
256 | |
4d9ff942 |
257 | gboolean lttv_apply_op_eq_uint64(const gpointer v1, LttvFieldValue v2); |
258 | gboolean lttv_apply_op_eq_uint32(const gpointer v1, LttvFieldValue v2); |
259 | gboolean lttv_apply_op_eq_uint16(const gpointer v1, LttvFieldValue v2); |
260 | gboolean lttv_apply_op_eq_double(const gpointer v1, LttvFieldValue v2); |
261 | gboolean lttv_apply_op_eq_string(const gpointer v1, LttvFieldValue v2); |
c6832b57 |
262 | gboolean lttv_apply_op_eq_quark(const gpointer v1, LttvFieldValue v2); |
4d9ff942 |
263 | gboolean lttv_apply_op_eq_ltttime(const gpointer v1, LttvFieldValue v2); |
264 | |
265 | gboolean lttv_apply_op_ne_uint64(const gpointer v1, LttvFieldValue v2); |
266 | gboolean lttv_apply_op_ne_uint32(const gpointer v1, LttvFieldValue v2); |
267 | gboolean lttv_apply_op_ne_uint16(const gpointer v1, LttvFieldValue v2); |
268 | gboolean lttv_apply_op_ne_double(const gpointer v1, LttvFieldValue v2); |
269 | gboolean lttv_apply_op_ne_string(const gpointer v1, LttvFieldValue v2); |
c6832b57 |
270 | gboolean lttv_apply_op_ne_quark(const gpointer v1, LttvFieldValue v2); |
4d9ff942 |
271 | gboolean lttv_apply_op_ne_ltttime(const gpointer v1, LttvFieldValue v2); |
272 | |
273 | gboolean lttv_apply_op_lt_uint64(const gpointer v1, LttvFieldValue v2); |
274 | gboolean lttv_apply_op_lt_uint32(const gpointer v1, LttvFieldValue v2); |
275 | gboolean lttv_apply_op_lt_uint16(const gpointer v1, LttvFieldValue v2); |
276 | gboolean lttv_apply_op_lt_double(const gpointer v1, LttvFieldValue v2); |
277 | gboolean lttv_apply_op_lt_ltttime(const gpointer v1, LttvFieldValue v2); |
278 | |
279 | gboolean lttv_apply_op_le_uint64(const gpointer v1, LttvFieldValue v2); |
280 | gboolean lttv_apply_op_le_uint32(const gpointer v1, LttvFieldValue v2); |
281 | gboolean lttv_apply_op_le_uint16(const gpointer v1, LttvFieldValue v2); |
282 | gboolean lttv_apply_op_le_double(const gpointer v1, LttvFieldValue v2); |
283 | gboolean lttv_apply_op_le_ltttime(const gpointer v1, LttvFieldValue v2); |
284 | |
285 | gboolean lttv_apply_op_gt_uint64(const gpointer v1, LttvFieldValue v2); |
286 | gboolean lttv_apply_op_gt_uint32(const gpointer v1, LttvFieldValue v2); |
287 | gboolean lttv_apply_op_gt_uint16(const gpointer v1, LttvFieldValue v2); |
288 | gboolean lttv_apply_op_gt_double(const gpointer v1, LttvFieldValue v2); |
289 | gboolean lttv_apply_op_gt_ltttime(const gpointer v1, LttvFieldValue v2); |
290 | |
291 | gboolean lttv_apply_op_ge_uint64(const gpointer v1, LttvFieldValue v2); |
292 | gboolean lttv_apply_op_ge_uint32(const gpointer v1, LttvFieldValue v2); |
293 | gboolean lttv_apply_op_ge_uint16(const gpointer v1, LttvFieldValue v2); |
294 | gboolean lttv_apply_op_ge_double(const gpointer v1, LttvFieldValue v2); |
295 | gboolean lttv_apply_op_ge_ltttime(const gpointer v1, LttvFieldValue v2); |
150f0d33 |
296 | |
297 | /* |
298 | * Cloning |
299 | */ |
300 | |
4d9ff942 |
301 | LttvFilterTree* lttv_filter_tree_clone(const LttvFilterTree* tree); |
150f0d33 |
302 | |
4d9ff942 |
303 | LttvFilter* lttv_filter_clone(const LttvFilter* filter); |
150f0d33 |
304 | |
56e29124 |
305 | /* |
306 | * LttvFilter |
150f0d33 |
307 | */ |
5f185a2b |
308 | LttvFilter *lttv_filter_new(); |
309 | |
310 | gboolean lttv_filter_update(LttvFilter* filter); |
48f6f3c2 |
311 | |
2ea36caf |
312 | void lttv_filter_destroy(LttvFilter* filter); |
1da1525d |
313 | |
56e29124 |
314 | gboolean lttv_filter_append_expression(LttvFilter* filter, char *expression); |
80f9611a |
315 | |
316 | void lttv_filter_clear_expression(LttvFilter* filter); |
317 | |
56e29124 |
318 | /* |
319 | * LttvFilterTree |
320 | */ |
150f0d33 |
321 | LttvFilterTree* lttv_filter_tree_new(); |
322 | |
323 | void lttv_filter_tree_destroy(LttvFilterTree* tree); |
324 | |
80f9611a |
325 | gboolean lttv_filter_tree_parse( |
4d9ff942 |
326 | const LttvFilterTree* t, |
327 | const LttEvent* event, |
328 | const LttTracefile* tracefile, |
329 | const LttTrace* trace, |
330 | const LttvProcessState* state, |
331 | const LttvTracefileContext* context); |
332 | |
333 | gboolean lttv_filter_tree_parse_branch( |
334 | const LttvSimpleExpression* se, |
335 | const LttEvent* event, |
336 | const LttTracefile* tracefile, |
337 | const LttTrace* trace, |
338 | const LttvProcessState* state, |
339 | const LttvTracefileContext* context); |
48f6f3c2 |
340 | |
80f9611a |
341 | /* |
342 | * Debug functions |
343 | */ |
4d9ff942 |
344 | void lttv_print_tree(const LttvFilterTree* t); |
80f9611a |
345 | |
48f6f3c2 |
346 | #endif // FILTER_H |
347 | |