Commit | Line | Data |
---|---|---|
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> |
7a4bdb54 | 50 | #include <lttv/traceset-process.h> |
a4c292d4 | 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; | |
e00d6a24 | 68 | |
33e44b82 | 69 | #ifndef LTTVFILTER_TYPE_DEFINED |
70 | typedef struct _LttvFilter LttvFilter; | |
71 | #define LTTVFILTER_TYPE_DEFINED | |
72 | #endif | |
e00d6a24 | 73 | |
80f9611a | 74 | /** |
7e7af7f2 | 75 | * @enum _LttvStructType |
80f9611a | 76 | * @brief The lttv structures |
77 | * | |
78 | * the LttvStructType enumerates | |
79 | * the possible structures for the | |
80 | * lttv core filter | |
81 | */ | |
82 | enum _LttvStructType { | |
90e19f82 AM |
83 | LTTV_FILTER_TRACE, /**< trace (LttTrace) */ |
84 | LTTV_FILTER_TRACESET, /**< traceset */ | |
85 | LTTV_FILTER_TRACEFILE, /**< tracefile (LttTracefile) */ | |
86 | LTTV_FILTER_EVENT, /**< event (LttEvent) */ | |
87 | LTTV_FILTER_STATE /**< state (LttvProcessState) */ | |
e00d6a24 | 88 | }; |
80f9611a | 89 | |
150f0d33 | 90 | /** |
7e7af7f2 | 91 | * @enum _LttvFieldType |
80f9611a | 92 | * @brief Possible fields for the structures |
150f0d33 | 93 | * |
94 | * the LttvFieldType enum consists on | |
95 | * all the hardcoded structures and | |
96 | * their appropriate fields on which | |
97 | * filters can be applied. | |
98 | */ | |
99 | enum _LttvFieldType { | |
90e19f82 AM |
100 | LTTV_FILTER_TRACE_NAME, /**< trace.name (char*) */ |
101 | LTTV_FILTER_TRACEFILE_NAME, /**< tracefile.name (char*) */ | |
102 | LTTV_FILTER_STATE_PID, /**< state.pid (guint) */ | |
103 | LTTV_FILTER_STATE_PPID, /**< state.ppid (guint) */ | |
104 | LTTV_FILTER_STATE_CT, /**< state.creation_time (double) */ | |
105 | LTTV_FILTER_STATE_IT, /**< state.insertion_time (double) */ | |
106 | LTTV_FILTER_STATE_P_NAME, /**< state.process_name (char*) */ | |
107 | LTTV_FILTER_STATE_T_BRAND, /**< state.thread_brand (char*) */ | |
108 | LTTV_FILTER_STATE_EX_MODE, /**< state.execution_mode (LttvExecutionMode) */ | |
109 | LTTV_FILTER_STATE_EX_SUBMODE, /**< state.execution_submode (LttvExecutionSubmode) */ | |
110 | LTTV_FILTER_STATE_P_STATUS, /**< state.process_status (LttvProcessStatus) */ | |
111 | LTTV_FILTER_STATE_CPU, /**< state.cpu (?last_cpu?) */ | |
112 | LTTV_FILTER_EVENT_NAME, /**< event.name (char*) */ | |
113 | LTTV_FILTER_EVENT_SUBNAME, /**< event.subname (char*) */ | |
114 | LTTV_FILTER_EVENT_CATEGORY, /**< FIXME: not implemented */ | |
115 | LTTV_FILTER_EVENT_TIME, /**< event.time (double) */ | |
116 | LTTV_FILTER_EVENT_TSC, /**< event.tsc (double) */ | |
117 | LTTV_FILTER_EVENT_TARGET_PID, /**< event.target_pid (guint) */ | |
118 | LTTV_FILTER_EVENT_FIELD, /**< dynamic field, specified in facility */ | |
119 | LTTV_FILTER_UNDEFINED /**< undefined field */ | |
e00d6a24 | 120 | }; |
90e19f82 | 121 | |
84a333d6 | 122 | /** |
571ef1ed | 123 | * @enum _LttvExpressionOp |
56e29124 | 124 | * @brief Contains possible operators |
125 | * | |
126 | * This enumeration defines the | |
127 | * possible operator used to compare | |
128 | * right and left member in simple | |
129 | * expression | |
84a333d6 | 130 | */ |
e00d6a24 | 131 | enum _LttvExpressionOp |
84a333d6 | 132 | { |
90e19f82 AM |
133 | LTTV_FIELD_EQ, /**< equal */ |
134 | LTTV_FIELD_NE, /**< not equal */ | |
135 | LTTV_FIELD_LT, /**< lower than */ | |
136 | LTTV_FIELD_LE, /**< lower or equal */ | |
137 | LTTV_FIELD_GT, /**< greater than */ | |
138 | LTTV_FIELD_GE /**< greater or equal */ | |
e00d6a24 | 139 | }; |
84a333d6 | 140 | |
56e29124 | 141 | /** |
7e7af7f2 | 142 | * @union _LttvFieldValue |
56e29124 | 143 | * @brief Contains possible field values |
7e7af7f2 | 144 | * |
56e29124 | 145 | * This particular union defines the |
146 | * possible set of values taken by the | |
90e19f82 | 147 | * right member of a simple expression. |
56e29124 | 148 | * It is used for comparison whithin the |
149 | * 'operators' functions | |
150 | */ | |
e00d6a24 | 151 | union _LttvFieldValue { |
90e19f82 AM |
152 | GQuark v_quark; /**< GQuark */ |
153 | guint64 v_uint64; /**< unsigned int of 64 bytes */ | |
154 | guint32 v_uint32; /**< unsigned int of 32 bytes */ | |
155 | guint16 v_uint16; /**< unsigned int of 16 bytes */ | |
156 | guint16 v_uint; /**< unsigned int */ | |
157 | double v_double; /**< double */ | |
158 | char* v_string; /**< string */ | |
159 | LttTime v_ltttime; /**< LttTime */ | |
160 | struct { | |
161 | GQuark q[2]; | |
162 | } v_quarks; | |
e00d6a24 | 163 | }; |
56e29124 | 164 | |
150f0d33 | 165 | /** |
7e7af7f2 | 166 | * @enum _LttvTreeElement |
150f0d33 | 167 | * @brief element types for the tree nodes |
168 | * | |
169 | * LttvTreeElement defines the possible | |
90e19f82 | 170 | * types of nodes which build the LttvFilterTree. |
2ea36caf | 171 | */ |
e00d6a24 | 172 | enum _LttvTreeElement { |
90e19f82 AM |
173 | LTTV_TREE_IDLE, /**< this node does nothing */ |
174 | LTTV_TREE_NODE, /**< this node contains a logical operator */ | |
175 | LTTV_TREE_LEAF /**< this node is a leaf and contains a simple expression */ | |
e00d6a24 | 176 | }; |
f4e9dd16 | 177 | |
56e29124 | 178 | |
150f0d33 | 179 | /** |
7e7af7f2 | 180 | * @struct _LttvSimpleExpression |
150f0d33 | 181 | * @brief simple expression structure |
182 | * | |
183 | * An LttvSimpleExpression is the base | |
184 | * of all filtering operations. It also | |
185 | * populates the leaves of the | |
186 | * LttvFilterTree. Each expression | |
187 | * consists basically in a structure | |
188 | * field, an operator and a specific | |
189 | * value. | |
190 | */ | |
e00d6a24 | 191 | struct _LttvSimpleExpression |
84a333d6 | 192 | { |
90e19f82 AM |
193 | gint field; /**< left member of simple expression */ |
194 | gint offset; /**< offset used for dynamic fields */ | |
195 | gboolean (*op)(gpointer,LttvFieldValue); /**< operator of simple expression */ | |
196 | LttvFieldValue value; /**< right member of simple expression */ | |
e00d6a24 | 197 | }; |
84a333d6 | 198 | |
150f0d33 | 199 | /** |
7e7af7f2 | 200 | * @enum _LttvLogicalOp |
150f0d33 | 201 | * @brief logical operators |
202 | * | |
203 | * Contains the possible values taken | |
204 | * by logical operator used to link | |
205 | * simple expression. Values are | |
206 | * AND, OR, XOR or NOT | |
207 | */ | |
e00d6a24 | 208 | enum _LttvLogicalOp { |
90e19f82 AM |
209 | LTTV_LOGICAL_OR = 1, /**< OR (1) */ |
210 | LTTV_LOGICAL_AND = 1<<1, /**< AND (2) */ | |
211 | LTTV_LOGICAL_NOT = 1<<2, /**< NOT (4) */ | |
212 | LTTV_LOGICAL_XOR = 1<<3 /**< XOR (8) */ | |
e00d6a24 | 213 | }; |
1a7fa682 | 214 | |
150f0d33 | 215 | /** |
7e7af7f2 | 216 | * @struct _LttvFilterTree |
217 | * @brief The filtering tree | |
218 | * | |
150f0d33 | 219 | * The filtering tree is used to represent the |
220 | * expression string in its entire hierarchy | |
221 | * composed of simple expressions and logical | |
222 | * operators | |
2ea36caf | 223 | */ |
e00d6a24 | 224 | struct _LttvFilterTree { |
90e19f82 AM |
225 | int node; /**< value of LttvLogicalOp */ |
226 | LttvTreeElement left; /**< nature of left branch (node/leaf) */ | |
227 | LttvTreeElement right; /**< nature of right branch (node/leaf) */ | |
228 | union { | |
229 | LttvFilterTree* t; | |
230 | LttvSimpleExpression* leaf; | |
231 | } l_child; /**< left branch of tree */ | |
232 | union { | |
233 | LttvFilterTree* t; | |
234 | LttvSimpleExpression* leaf; | |
235 | } r_child; /**< right branch of tree */ | |
e00d6a24 | 236 | }; |
84a333d6 | 237 | |
31452f49 | 238 | /** |
7e7af7f2 | 239 | * @struct _LttvFilter |
240 | * @brief The filter | |
241 | * | |
150f0d33 | 242 | * Contains a binary tree of filtering options along |
243 | * with the expression itself. | |
31452f49 | 244 | */ |
e00d6a24 | 245 | struct _LttvFilter { |
90e19f82 AM |
246 | char *expression; /**< filtering expression string */ |
247 | LttvFilterTree *head; /**< tree associated to expression */ | |
e00d6a24 | 248 | }; |
84a333d6 | 249 | |
56e29124 | 250 | /* |
251 | * Simple Expression | |
252 | */ | |
253 | LttvSimpleExpression* lttv_simple_expression_new(); | |
254 | ||
90e19f82 AM |
255 | gboolean lttv_simple_expression_assign_field(GPtrArray* fp, |
256 | LttvSimpleExpression* se); | |
91ad3f0a | 257 | |
90e19f82 AM |
258 | gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression* se, |
259 | LttvExpressionOp op); | |
bb87caa7 | 260 | |
90e19f82 AM |
261 | gboolean lttv_simple_expression_assign_value(LttvSimpleExpression* se, |
262 | char* value); | |
9ab5ebd7 | 263 | |
56e29124 | 264 | void lttv_simple_expression_destroy(LttvSimpleExpression* se); |
5f185a2b | 265 | |
5f185a2b | 266 | |
150f0d33 | 267 | /* |
268 | * Logical operators functions | |
269 | */ | |
270 | ||
2ec11087 | 271 | gboolean lttv_apply_op_eq_uint(const gpointer v1, LttvFieldValue v2); |
4d9ff942 | 272 | gboolean lttv_apply_op_eq_uint64(const gpointer v1, LttvFieldValue v2); |
273 | gboolean lttv_apply_op_eq_uint32(const gpointer v1, LttvFieldValue v2); | |
274 | gboolean lttv_apply_op_eq_uint16(const gpointer v1, LttvFieldValue v2); | |
275 | gboolean lttv_apply_op_eq_double(const gpointer v1, LttvFieldValue v2); | |
276 | gboolean lttv_apply_op_eq_string(const gpointer v1, LttvFieldValue v2); | |
c6832b57 | 277 | gboolean lttv_apply_op_eq_quark(const gpointer v1, LttvFieldValue v2); |
6471e71f | 278 | gboolean lttv_apply_op_eq_quarks(const gpointer v1, LttvFieldValue v2); |
4d9ff942 | 279 | gboolean lttv_apply_op_eq_ltttime(const gpointer v1, LttvFieldValue v2); |
280 | ||
2ec11087 | 281 | gboolean lttv_apply_op_ne_uint(const gpointer v1, LttvFieldValue v2); |
4d9ff942 | 282 | gboolean lttv_apply_op_ne_uint64(const gpointer v1, LttvFieldValue v2); |
283 | gboolean lttv_apply_op_ne_uint32(const gpointer v1, LttvFieldValue v2); | |
284 | gboolean lttv_apply_op_ne_uint16(const gpointer v1, LttvFieldValue v2); | |
285 | gboolean lttv_apply_op_ne_double(const gpointer v1, LttvFieldValue v2); | |
286 | gboolean lttv_apply_op_ne_string(const gpointer v1, LttvFieldValue v2); | |
c6832b57 | 287 | gboolean lttv_apply_op_ne_quark(const gpointer v1, LttvFieldValue v2); |
6471e71f | 288 | gboolean lttv_apply_op_ne_quarks(const gpointer v1, LttvFieldValue v2); |
4d9ff942 | 289 | gboolean lttv_apply_op_ne_ltttime(const gpointer v1, LttvFieldValue v2); |
290 | ||
2ec11087 | 291 | gboolean lttv_apply_op_lt_uint(const gpointer v1, LttvFieldValue v2); |
4d9ff942 | 292 | gboolean lttv_apply_op_lt_uint64(const gpointer v1, LttvFieldValue v2); |
293 | gboolean lttv_apply_op_lt_uint32(const gpointer v1, LttvFieldValue v2); | |
294 | gboolean lttv_apply_op_lt_uint16(const gpointer v1, LttvFieldValue v2); | |
295 | gboolean lttv_apply_op_lt_double(const gpointer v1, LttvFieldValue v2); | |
296 | gboolean lttv_apply_op_lt_ltttime(const gpointer v1, LttvFieldValue v2); | |
297 | ||
2ec11087 | 298 | gboolean lttv_apply_op_le_uint(const gpointer v1, LttvFieldValue v2); |
4d9ff942 | 299 | gboolean lttv_apply_op_le_uint64(const gpointer v1, LttvFieldValue v2); |
300 | gboolean lttv_apply_op_le_uint32(const gpointer v1, LttvFieldValue v2); | |
301 | gboolean lttv_apply_op_le_uint16(const gpointer v1, LttvFieldValue v2); | |
302 | gboolean lttv_apply_op_le_double(const gpointer v1, LttvFieldValue v2); | |
303 | gboolean lttv_apply_op_le_ltttime(const gpointer v1, LttvFieldValue v2); | |
304 | ||
2ec11087 | 305 | gboolean lttv_apply_op_gt_uint(const gpointer v1, LttvFieldValue v2); |
4d9ff942 | 306 | gboolean lttv_apply_op_gt_uint64(const gpointer v1, LttvFieldValue v2); |
307 | gboolean lttv_apply_op_gt_uint32(const gpointer v1, LttvFieldValue v2); | |
308 | gboolean lttv_apply_op_gt_uint16(const gpointer v1, LttvFieldValue v2); | |
309 | gboolean lttv_apply_op_gt_double(const gpointer v1, LttvFieldValue v2); | |
310 | gboolean lttv_apply_op_gt_ltttime(const gpointer v1, LttvFieldValue v2); | |
311 | ||
2ec11087 | 312 | gboolean lttv_apply_op_ge_uint(const gpointer v1, LttvFieldValue v2); |
4d9ff942 | 313 | gboolean lttv_apply_op_ge_uint64(const gpointer v1, LttvFieldValue v2); |
314 | gboolean lttv_apply_op_ge_uint32(const gpointer v1, LttvFieldValue v2); | |
315 | gboolean lttv_apply_op_ge_uint16(const gpointer v1, LttvFieldValue v2); | |
316 | gboolean lttv_apply_op_ge_double(const gpointer v1, LttvFieldValue v2); | |
317 | gboolean lttv_apply_op_ge_ltttime(const gpointer v1, LttvFieldValue v2); | |
150f0d33 | 318 | |
319 | /* | |
320 | * Cloning | |
321 | */ | |
322 | ||
4d9ff942 | 323 | LttvFilterTree* lttv_filter_tree_clone(const LttvFilterTree* tree); |
150f0d33 | 324 | |
4d9ff942 | 325 | LttvFilter* lttv_filter_clone(const LttvFilter* filter); |
150f0d33 | 326 | |
56e29124 | 327 | /* |
328 | * LttvFilter | |
150f0d33 | 329 | */ |
90e19f82 | 330 | LttvFilter* lttv_filter_new(); |
5f185a2b | 331 | |
332 | gboolean lttv_filter_update(LttvFilter* filter); | |
48f6f3c2 | 333 | |
2ea36caf | 334 | void lttv_filter_destroy(LttvFilter* filter); |
1da1525d | 335 | |
90e19f82 AM |
336 | gboolean lttv_filter_append_expression(LttvFilter* filter, |
337 | const char *expression); | |
80f9611a | 338 | |
339 | void lttv_filter_clear_expression(LttvFilter* filter); | |
340 | ||
56e29124 | 341 | /* |
342 | * LttvFilterTree | |
343 | */ | |
150f0d33 | 344 | LttvFilterTree* lttv_filter_tree_new(); |
345 | ||
346 | void lttv_filter_tree_destroy(LttvFilterTree* tree); | |
347 | ||
80f9611a | 348 | gboolean lttv_filter_tree_parse( |
90e19f82 AM |
349 | const LttvFilterTree* t, |
350 | const LttEvent* event, | |
351 | const LttTracefile* tracefile, | |
352 | const LttTrace* trace, | |
90e19f82 | 353 | const LttvProcessState* pstate, |
451aaf27 | 354 | const LttvTrace* tracev); |
4d9ff942 | 355 | |
356 | gboolean lttv_filter_tree_parse_branch( | |
90e19f82 AM |
357 | const LttvSimpleExpression* se, |
358 | const LttEvent* event, | |
359 | const LttTracefile* tracefile, | |
360 | const LttTrace* trace, | |
451aaf27 | 361 | const LttvProcessState* state); |
48f6f3c2 | 362 | |
80f9611a | 363 | /* |
364 | * Debug functions | |
365 | */ | |
72911c5d | 366 | void lttv_print_tree(const LttvFilterTree* t, const int count); |
80f9611a | 367 | |
48f6f3c2 | 368 | #endif // FILTER_H |
369 |