filter core:
[lttv.git] / ltt / branches / poly / lttv / lttv / filter.h
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
19 #ifndef FILTER_H
20 #define FILTER_H
21
22 #include <lttv/traceset.h>
23 #include <lttv/tracecontext.h>
24 #include <lttv/state.h>
25 #include <lttv/module.h>
26 #include <ltt/ltt.h>
27 #include <ltt/event.h>
28
29
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
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 {
64 LTTV_FILTER_TRACE,
65 LTTV_FILTER_TRACESET,
66 LTTV_FILTER_TRACEFILE,
67 LTTV_FILTER_STATE,
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,
81 LTTV_FILTER_CPU
82 } LttvFieldType;
83
84 /**
85 * @enum LttvExpressionOp
86 */
87 typedef enum _LttvExpressionOp
88 {
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 */
95 } LttvExpressionOp;
96
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.
103 */
104 typedef enum _LttvTreeElement {
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 */
108 } LttvTreeElement;
109
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 */
122 typedef struct _LttvSimpleExpression
123 {
124 char *field_name;
125 // LttvExpressionOp op;
126 gboolean (*op)();
127 char *value;
128 } LttvSimpleExpression;
129
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 */
139 typedef enum _LttvLogicalOp {
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 */
144 } LttvLogicalOp;
145
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
152 */
153 typedef struct _LttvFilterTree {
154 int node; /** value of LttvLogicalOp */
155 LttvTreeElement left;
156 LttvTreeElement right;
157 union {
158 struct LttvFilter* t;
159 LttvSimpleExpression* leaf;
160 } l_child;
161 union {
162 struct LttvFilter* t;
163 LttvSimpleExpression* leaf;
164 } r_child;
165 } LttvFilterTree;
166
167 /**
168 * @struct lttv_filter
169 * Contains a binary tree of filtering options along
170 * with the expression itself.
171 */
172 typedef struct _LttvFilter {
173 char *expression;
174 LttvFilterTree *head;
175 } LttvFilter;
176
177 /*
178 * General Data Handling functions
179 */
180
181 LttvSimpleExpression* lttv_simple_expression_new();
182
183 void lttv_filter_tree_add_node(GPtrArray* stack, LttvFilterTree* subtree, LttvLogicalOp op);
184
185 gboolean parse_field_path(GPtrArray* fp, LttvSimpleExpression* se);
186
187 gboolean parse_simple_expression(GString* expression);
188
189 /*
190 * Logical operators functions
191 */
192
193 gboolean lttv_apply_op_eq_uint64(guint64 v1, guint64 v2);
194 gboolean lttv_apply_op_eq_uint32(guint32 v1, guint32 v2);
195 gboolean lttv_apply_op_eq_uint16(guint16 v1, guint16 v2);
196 gboolean lttv_apply_op_eq_double(double v1, double v2);
197 gboolean lttv_apply_op_eq_string(char* v1, char* v2);
198
199 gboolean lttv_apply_op_ne_uint64(guint64 v1, guint64 v2);
200 gboolean lttv_apply_op_ne_uint32(guint32 v1, guint32 v2);
201 gboolean lttv_apply_op_ne_uint16(guint16 v1, guint16 v2);
202 gboolean lttv_apply_op_ne_double(double v1, double v2);
203 gboolean lttv_apply_op_ne_string(char* v1, char* v2);
204
205 gboolean lttv_apply_op_lt_uint64(guint64 v1, guint64 v2);
206 gboolean lttv_apply_op_lt_uint32(guint32 v1, guint32 v2);
207 gboolean lttv_apply_op_lt_uint16(guint16 v1, guint16 v2);
208 gboolean lttv_apply_op_lt_double(double v1, double v2);
209
210 gboolean lttv_apply_op_le_uint64(guint64 v1, guint64 v2);
211 gboolean lttv_apply_op_le_uint32(guint32 v1, guint32 v2);
212 gboolean lttv_apply_op_le_uint16(guint16 v1, guint16 v2);
213 gboolean lttv_apply_op_le_double(double v1, double v2);
214
215 gboolean lttv_apply_op_gt_uint64(guint64 v1, guint64 v2);
216 gboolean lttv_apply_op_gt_uint32(guint32 v1, guint32 v2);
217 gboolean lttv_apply_op_gt_uint16(guint16 v1, guint16 v2);
218 gboolean lttv_apply_op_gt_double(double v1, double v2);
219
220 gboolean lttv_apply_op_ge_uint64(guint64 v1, guint64 v2);
221 gboolean lttv_apply_op_ge_uint32(guint32 v1, guint32 v2);
222 gboolean lttv_apply_op_ge_uint16(guint16 v1, guint16 v2);
223 gboolean lttv_apply_op_ge_double(double v1, double v2);
224
225 /*
226 * Cloning
227 */
228
229 LttvFilterTree* lttv_filter_tree_clone(LttvFilterTree* tree);
230
231 LttvFilter* lttv_filter_clone(LttvFilter* filter);
232
233 /*
234 * Constructors/Destructors
235 */
236
237 /* LttvFilter */
238 LttvFilter *lttv_filter_new(char *expression, LttvTraceState *tfs);
239
240 void lttv_filter_destroy(LttvFilter* filter);
241
242 /* LttvFilterTree */
243 LttvFilterTree* lttv_filter_tree_new();
244
245 void lttv_filter_tree_destroy(LttvFilterTree* tree);
246
247
248 /*
249 * Hook functions
250 *
251 * These hook functions will be the one called when filtering
252 * an event, a trace, a state, etc.
253 */
254
255 /* Check if the tracefile or event satisfies the filter. The arguments are
256 declared as void * to allow these functions to be used as hooks. */
257
258 gboolean lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile);
259
260 gboolean lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate);
261
262 gboolean lttv_filter_event(LttvFilter *filter, LttEvent *event);
263
264 #endif // FILTER_H
265
This page took 0.034798 seconds and 4 git commands to generate.