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