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, |
69 | LTTV_FILTER_NAME, |
70 | LTTV_FILTER_CATEGORY, |
71 | LTTV_FILTER_TIME, |
72 | LTTV_FILTER_TSC, |
73 | LTTV_FILTER_PID, |
74 | LTTV_FILTER_PPID, |
75 | LTTV_FILTER_C_TIME, |
76 | LTTV_FILTER_I_TIME, |
77 | LTTV_FILTER_P_NAME, |
78 | LTTV_FILTER_EX_MODE, |
79 | LTTV_FILTER_EX_SUBMODE, |
80 | LTTV_FILTER_P_STATUS, |
150f0d33 |
81 | LTTV_FILTER_CPU |
82 | } LttvFieldType; |
91ad3f0a |
83 | |
84a333d6 |
84 | /** |
150f0d33 |
85 | * @enum LttvExpressionOp |
84a333d6 |
86 | */ |
2ea36caf |
87 | typedef enum _LttvExpressionOp |
84a333d6 |
88 | { |
150f0d33 |
89 | LTTV_FIELD_EQ, /** equal */ |
90 | LTTV_FIELD_NE, /** not equal */ |
91 | LTTV_FIELD_LT, /** lower than */ |
92 | LTTV_FIELD_LE, /** lower or equal */ |
93 | LTTV_FIELD_GT, /** greater than */ |
94 | LTTV_FIELD_GE /** greater or equal */ |
2ea36caf |
95 | } LttvExpressionOp; |
84a333d6 |
96 | |
150f0d33 |
97 | /** |
98 | * @enum LttvTreeElement |
99 | * @brief element types for the tree nodes |
100 | * |
101 | * LttvTreeElement defines the possible |
102 | * types of nodes which build the LttvFilterTree. |
2ea36caf |
103 | */ |
2ea36caf |
104 | typedef enum _LttvTreeElement { |
150f0d33 |
105 | LTTV_TREE_IDLE, /** this node does nothing */ |
106 | LTTV_TREE_NODE, /** this node contains a logical operator */ |
107 | LTTV_TREE_LEAF /** this node is a leaf and contains a simple expression */ |
2ea36caf |
108 | } LttvTreeElement; |
f4e9dd16 |
109 | |
150f0d33 |
110 | /** |
111 | * @enum LttvSimpleExpression |
112 | * @brief simple expression structure |
113 | * |
114 | * An LttvSimpleExpression is the base |
115 | * of all filtering operations. It also |
116 | * populates the leaves of the |
117 | * LttvFilterTree. Each expression |
118 | * consists basically in a structure |
119 | * field, an operator and a specific |
120 | * value. |
121 | */ |
2ea36caf |
122 | typedef struct _LttvSimpleExpression |
84a333d6 |
123 | { |
84a333d6 |
124 | char *field_name; |
150f0d33 |
125 | // LttvExpressionOp op; |
126 | gboolean (*op)(); |
84a333d6 |
127 | char *value; |
2ea36caf |
128 | } LttvSimpleExpression; |
84a333d6 |
129 | |
150f0d33 |
130 | /** |
131 | * @enum LttvLogicalOp |
132 | * @brief logical operators |
133 | * |
134 | * Contains the possible values taken |
135 | * by logical operator used to link |
136 | * simple expression. Values are |
137 | * AND, OR, XOR or NOT |
138 | */ |
2ea36caf |
139 | typedef enum _LttvLogicalOp { |
f4e9dd16 |
140 | LTTV_LOGICAL_OR = 1, /* 1 */ |
141 | LTTV_LOGICAL_AND = 1<<1, /* 2 */ |
142 | LTTV_LOGICAL_NOT = 1<<2, /* 4 */ |
143 | LTTV_LOGICAL_XOR = 1<<3 /* 8 */ |
2ea36caf |
144 | } LttvLogicalOp; |
1a7fa682 |
145 | |
150f0d33 |
146 | /** |
147 | * @struct LttvFilterTree |
148 | * The filtering tree is used to represent the |
149 | * expression string in its entire hierarchy |
150 | * composed of simple expressions and logical |
151 | * operators |
2ea36caf |
152 | */ |
150f0d33 |
153 | typedef struct _LttvFilterTree { |
2ea36caf |
154 | int node; /** value of LttvLogicalOp */ |
155 | LttvTreeElement left; |
156 | LttvTreeElement right; |
f4e9dd16 |
157 | union { |
2ea36caf |
158 | struct LttvFilter* t; |
159 | LttvSimpleExpression* leaf; |
f4e9dd16 |
160 | } l_child; |
161 | union { |
2ea36caf |
162 | struct LttvFilter* t; |
163 | LttvSimpleExpression* leaf; |
f4e9dd16 |
164 | } r_child; |
150f0d33 |
165 | } LttvFilterTree; |
84a333d6 |
166 | |
31452f49 |
167 | /** |
168 | * @struct lttv_filter |
150f0d33 |
169 | * Contains a binary tree of filtering options along |
170 | * with the expression itself. |
31452f49 |
171 | */ |
150f0d33 |
172 | typedef struct _LttvFilter { |
173 | char *expression; |
174 | LttvFilterTree *head; |
175 | } |
84a333d6 |
176 | |
150f0d33 |
177 | /* |
178 | * General Data Handling functions |
179 | */ |
0769c82f |
180 | |
2ea36caf |
181 | LttvSimpleExpression* lttv_simple_expression_new(); |
0cdc2470 |
182 | |
2ea36caf |
183 | void lttv_filter_tree_add_node(GPtrArray* stack, LttvFilter* subtree, LttvLogicalOp op); |
0cdc2470 |
184 | |
f4e9dd16 |
185 | gboolean parse_field_path(GPtrArray* fp); |
91ad3f0a |
186 | |
84a333d6 |
187 | gboolean parse_simple_expression(GString* expression); |
48f6f3c2 |
188 | |
150f0d33 |
189 | /* |
190 | * Logical operators functions |
191 | */ |
192 | |
193 | gboolean lttv_apply_op_eq(); |
194 | |
195 | gboolean lttv_apply_op_ne(); |
196 | |
197 | gboolean lttv_apply_op_lt(); |
198 | |
199 | gboolean lttv_apply_op_le(); |
200 | |
201 | gboolean lttv_apply_op_gt(); |
202 | |
203 | gboolean lttv_apply_op_ge(); |
204 | |
205 | /* |
206 | * Cloning |
207 | */ |
208 | |
209 | LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree* tree); |
210 | |
211 | LttvFilter* lttv_filter_clone(LttvFilter* filter); |
212 | |
213 | /* |
214 | * Constructors/Destructors |
215 | */ |
216 | |
217 | /* LttvFilter */ |
2ea36caf |
218 | LttvFilter *lttv_filter_new(char *expression, LttvTraceState *tfs); |
48f6f3c2 |
219 | |
2ea36caf |
220 | void lttv_filter_destroy(LttvFilter* filter); |
1da1525d |
221 | |
150f0d33 |
222 | /* LttvFilterTree */ |
223 | LttvFilterTree* lttv_filter_tree_new(); |
224 | |
225 | void lttv_filter_tree_destroy(LttvFilterTree* tree); |
226 | |
227 | |
228 | /* |
229 | * Hook functions |
230 | * |
231 | * These hook functions will be the one called when filtering |
232 | * an event, a trace, a state, etc. |
233 | */ |
234 | |
48f6f3c2 |
235 | /* Check if the tracefile or event satisfies the filter. The arguments are |
236 | declared as void * to allow these functions to be used as hooks. */ |
237 | |
2ea36caf |
238 | gboolean lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile); |
48f6f3c2 |
239 | |
2ea36caf |
240 | gboolean lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate); |
1a7fa682 |
241 | |
2ea36caf |
242 | gboolean lttv_filter_event(LttvFilter *filter, LttEvent *event); |
48f6f3c2 |
243 | |
244 | #endif // FILTER_H |
245 | |