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 | |
48f6f3c2 |
30 | /* A filter expression consists in nested AND, OR and NOT expressions |
31 | involving boolean relation (>, >=, =, !=, <, <=) between event fields and |
32 | specific values. It is compiled into an efficient data structure which |
33 | is used in functions to check if a given event or tracefile satisfies the |
34 | filter. |
35 | |
36 | The grammar for filters is: |
37 | |
38 | filter = expression |
39 | |
40 | expression = "(" expression ")" | "!" expression | |
41 | expression "&&" expression | expression "||" expression | |
42 | simpleExpression |
43 | |
44 | simpleExpression = fieldPath op value |
45 | |
46 | fieldPath = fieldComponent [ "." fieldPath ] |
47 | |
48 | fieldComponent = name [ "[" integer "]" ] |
49 | |
50 | value = integer | double | string |
51 | |
52 | */ |
53 | |
150f0d33 |
54 | /** |
55 | * @enum LttvFieldType |
56 | * @brief Structures and their fields |
57 | * |
58 | * the LttvFieldType enum consists on |
59 | * all the hardcoded structures and |
60 | * their appropriate fields on which |
61 | * filters can be applied. |
62 | */ |
63 | enum _LttvFieldType { |
0769c82f |
64 | LTTV_FILTER_TRACE, |
65 | LTTV_FILTER_TRACESET, |
66 | LTTV_FILTER_TRACEFILE, |
67 | LTTV_FILTER_STATE, |
91ad3f0a |
68 | LTTV_FILTER_EVENT, |
389ba50e |
69 | LTTV_FILTER_TRACE_NAME, |
70 | LTTV_FILTER_TRACESET_NAME, |
71 | LTTV_FILTER_TRACEFILE_NAME, |
72 | LTTV_FILTER_STATE_PID, |
73 | LTTV_FILTER_STATE_PPID, |
74 | LTTV_FILTER_STATE_CT, |
75 | LTTV_FILTER_STATE_IT, |
76 | LTTV_FILTER_STATE_P_NAME, |
77 | LTTV_FILTER_STATE_EX_MODE, |
78 | LTTV_FILTER_STATE_EX_SUBMODE, |
79 | LTTV_FILTER_STATE_P_STATUS, |
80 | LTTV_FILTER_STATE_CPU, |
81 | LTTV_FILTER_EVENT_NAME, |
82 | LTTV_FILTER_EVENT_CATEGORY, |
83 | LTTV_FILTER_EVENT_TIME, |
84 | LTTV_FILTER_EVENT_TSC, |
85 | LTTV_FILTER_EVENT_FIELD, |
86 | LTTV_FILTER_UNDEFINED |
87 | // LTTV_FILTER_CATEGORY, |
88 | // LTTV_FILTER_TIME, |
89 | // LTTV_FILTER_TSC, |
90 | // LTTV_FILTER_PID, |
91 | // LTTV_FILTER_PPID, |
92 | // LTTV_FILTER_C_TIME, |
93 | // LTTV_FILTER_I_TIME, |
94 | // LTTV_FILTER_P_NAME, |
95 | // LTTV_FILTER_EX_MODE, |
96 | // LTTV_FILTER_EX_SUBMODE, |
97 | // LTTV_FILTER_P_STATUS, |
98 | // LTTV_FILTER_CPU |
150f0d33 |
99 | } LttvFieldType; |
91ad3f0a |
100 | |
84a333d6 |
101 | /** |
150f0d33 |
102 | * @enum LttvExpressionOp |
84a333d6 |
103 | */ |
2ea36caf |
104 | typedef enum _LttvExpressionOp |
84a333d6 |
105 | { |
150f0d33 |
106 | LTTV_FIELD_EQ, /** equal */ |
107 | LTTV_FIELD_NE, /** not equal */ |
108 | LTTV_FIELD_LT, /** lower than */ |
109 | LTTV_FIELD_LE, /** lower or equal */ |
110 | LTTV_FIELD_GT, /** greater than */ |
111 | LTTV_FIELD_GE /** greater or equal */ |
2ea36caf |
112 | } LttvExpressionOp; |
84a333d6 |
113 | |
150f0d33 |
114 | /** |
115 | * @enum LttvTreeElement |
116 | * @brief element types for the tree nodes |
117 | * |
118 | * LttvTreeElement defines the possible |
119 | * types of nodes which build the LttvFilterTree. |
2ea36caf |
120 | */ |
2ea36caf |
121 | typedef enum _LttvTreeElement { |
150f0d33 |
122 | LTTV_TREE_IDLE, /** this node does nothing */ |
123 | LTTV_TREE_NODE, /** this node contains a logical operator */ |
124 | LTTV_TREE_LEAF /** this node is a leaf and contains a simple expression */ |
2ea36caf |
125 | } LttvTreeElement; |
f4e9dd16 |
126 | |
150f0d33 |
127 | /** |
128 | * @enum LttvSimpleExpression |
129 | * @brief simple expression structure |
130 | * |
131 | * An LttvSimpleExpression is the base |
132 | * of all filtering operations. It also |
133 | * populates the leaves of the |
134 | * LttvFilterTree. Each expression |
135 | * consists basically in a structure |
136 | * field, an operator and a specific |
137 | * value. |
138 | */ |
2ea36caf |
139 | typedef struct _LttvSimpleExpression |
84a333d6 |
140 | { |
389ba50e |
141 | // char *field_name; |
142 | gint field; |
143 | gint offset; |
150f0d33 |
144 | // LttvExpressionOp op; |
145 | gboolean (*op)(); |
84a333d6 |
146 | char *value; |
2ea36caf |
147 | } LttvSimpleExpression; |
84a333d6 |
148 | |
150f0d33 |
149 | /** |
150 | * @enum LttvLogicalOp |
151 | * @brief logical operators |
152 | * |
153 | * Contains the possible values taken |
154 | * by logical operator used to link |
155 | * simple expression. Values are |
156 | * AND, OR, XOR or NOT |
157 | */ |
2ea36caf |
158 | typedef enum _LttvLogicalOp { |
f4e9dd16 |
159 | LTTV_LOGICAL_OR = 1, /* 1 */ |
160 | LTTV_LOGICAL_AND = 1<<1, /* 2 */ |
161 | LTTV_LOGICAL_NOT = 1<<2, /* 4 */ |
162 | LTTV_LOGICAL_XOR = 1<<3 /* 8 */ |
2ea36caf |
163 | } LttvLogicalOp; |
1a7fa682 |
164 | |
150f0d33 |
165 | /** |
166 | * @struct LttvFilterTree |
167 | * The filtering tree is used to represent the |
168 | * expression string in its entire hierarchy |
169 | * composed of simple expressions and logical |
170 | * operators |
2ea36caf |
171 | */ |
150f0d33 |
172 | typedef struct _LttvFilterTree { |
2ea36caf |
173 | int node; /** value of LttvLogicalOp */ |
174 | LttvTreeElement left; |
175 | LttvTreeElement right; |
f4e9dd16 |
176 | union { |
2ea36caf |
177 | struct LttvFilter* t; |
178 | LttvSimpleExpression* leaf; |
f4e9dd16 |
179 | } l_child; |
180 | union { |
2ea36caf |
181 | struct LttvFilter* t; |
182 | LttvSimpleExpression* leaf; |
f4e9dd16 |
183 | } r_child; |
150f0d33 |
184 | } LttvFilterTree; |
84a333d6 |
185 | |
31452f49 |
186 | /** |
187 | * @struct lttv_filter |
150f0d33 |
188 | * Contains a binary tree of filtering options along |
189 | * with the expression itself. |
31452f49 |
190 | */ |
150f0d33 |
191 | typedef struct _LttvFilter { |
192 | char *expression; |
193 | LttvFilterTree *head; |
5b729fcf |
194 | } LttvFilter; |
84a333d6 |
195 | |
150f0d33 |
196 | /* |
197 | * General Data Handling functions |
198 | */ |
0769c82f |
199 | |
2ea36caf |
200 | LttvSimpleExpression* lttv_simple_expression_new(); |
0cdc2470 |
201 | |
5b729fcf |
202 | void lttv_filter_tree_add_node(GPtrArray* stack, LttvFilterTree* subtree, LttvLogicalOp op); |
0cdc2470 |
203 | |
47aa6e58 |
204 | gboolean parse_field_path(GPtrArray* fp, LttvSimpleExpression* se); |
91ad3f0a |
205 | |
84a333d6 |
206 | gboolean parse_simple_expression(GString* expression); |
48f6f3c2 |
207 | |
150f0d33 |
208 | /* |
209 | * Logical operators functions |
210 | */ |
211 | |
47aa6e58 |
212 | gboolean lttv_apply_op_eq_uint64(guint64 v1, guint64 v2); |
213 | gboolean lttv_apply_op_eq_uint32(guint32 v1, guint32 v2); |
214 | gboolean lttv_apply_op_eq_uint16(guint16 v1, guint16 v2); |
215 | gboolean lttv_apply_op_eq_double(double v1, double v2); |
216 | gboolean lttv_apply_op_eq_string(char* v1, char* v2); |
217 | |
218 | gboolean lttv_apply_op_ne_uint64(guint64 v1, guint64 v2); |
219 | gboolean lttv_apply_op_ne_uint32(guint32 v1, guint32 v2); |
220 | gboolean lttv_apply_op_ne_uint16(guint16 v1, guint16 v2); |
221 | gboolean lttv_apply_op_ne_double(double v1, double v2); |
222 | gboolean lttv_apply_op_ne_string(char* v1, char* v2); |
223 | |
224 | gboolean lttv_apply_op_lt_uint64(guint64 v1, guint64 v2); |
225 | gboolean lttv_apply_op_lt_uint32(guint32 v1, guint32 v2); |
226 | gboolean lttv_apply_op_lt_uint16(guint16 v1, guint16 v2); |
227 | gboolean lttv_apply_op_lt_double(double v1, double v2); |
228 | |
229 | gboolean lttv_apply_op_le_uint64(guint64 v1, guint64 v2); |
230 | gboolean lttv_apply_op_le_uint32(guint32 v1, guint32 v2); |
231 | gboolean lttv_apply_op_le_uint16(guint16 v1, guint16 v2); |
232 | gboolean lttv_apply_op_le_double(double v1, double v2); |
233 | |
234 | gboolean lttv_apply_op_gt_uint64(guint64 v1, guint64 v2); |
235 | gboolean lttv_apply_op_gt_uint32(guint32 v1, guint32 v2); |
236 | gboolean lttv_apply_op_gt_uint16(guint16 v1, guint16 v2); |
237 | gboolean lttv_apply_op_gt_double(double v1, double v2); |
238 | |
239 | gboolean lttv_apply_op_ge_uint64(guint64 v1, guint64 v2); |
240 | gboolean lttv_apply_op_ge_uint32(guint32 v1, guint32 v2); |
241 | gboolean lttv_apply_op_ge_uint16(guint16 v1, guint16 v2); |
242 | gboolean lttv_apply_op_ge_double(double v1, double v2); |
150f0d33 |
243 | |
244 | /* |
245 | * Cloning |
246 | */ |
247 | |
248 | LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree* tree); |
249 | |
250 | LttvFilter* lttv_filter_clone(LttvFilter* filter); |
251 | |
252 | /* |
253 | * Constructors/Destructors |
254 | */ |
255 | |
256 | /* LttvFilter */ |
2ea36caf |
257 | LttvFilter *lttv_filter_new(char *expression, LttvTraceState *tfs); |
48f6f3c2 |
258 | |
2ea36caf |
259 | void lttv_filter_destroy(LttvFilter* filter); |
1da1525d |
260 | |
150f0d33 |
261 | /* LttvFilterTree */ |
262 | LttvFilterTree* lttv_filter_tree_new(); |
263 | |
264 | void lttv_filter_tree_destroy(LttvFilterTree* tree); |
265 | |
266 | |
267 | /* |
268 | * Hook functions |
269 | * |
270 | * These hook functions will be the one called when filtering |
271 | * an event, a trace, a state, etc. |
272 | */ |
273 | |
48f6f3c2 |
274 | /* Check if the tracefile or event satisfies the filter. The arguments are |
275 | declared as void * to allow these functions to be used as hooks. */ |
276 | |
2ea36caf |
277 | gboolean lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile); |
48f6f3c2 |
278 | |
2ea36caf |
279 | gboolean lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate); |
1a7fa682 |
280 | |
2ea36caf |
281 | gboolean lttv_filter_event(LttvFilter *filter, LttEvent *event); |
48f6f3c2 |
282 | |
283 | #endif // FILTER_H |
284 | |