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