filter core:
[lttv.git] / ltt / branches / poly / lttv / lttv / filter.h
... / ...
CommitLineData
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/time.h>
28#include <ltt/event.h>
29
30
31/*
32 A filter expression consists in nested AND, OR and NOT expressions
33 involving boolean relation (>, >=, =, !=, <, <=) between event fields and
34 specific values. It is compiled into an efficient data structure which
35 is used in functions to check if a given event or tracefile satisfies the
36 filter.
37
38 The grammar for filters is:
39
40 filter = expression
41
42 expression = "(" expression ")" | "!" expression |
43 expression "&&" expression | expression "||" expression |
44 simpleExpression
45
46 simpleExpression = fieldPath op value
47
48 fieldPath = fieldComponent [ "." fieldPath ]
49
50 fieldComponent = name [ "[" integer "]" ]
51
52 value = integer | double | string
53*/
54
55/* structures prototypes */
56typedef enum _LttvStructType LttvStructType;
57typedef enum _LttvFieldType LttvFieldType;
58typedef enum _LttvExpressionOp LttvExpressionOp;
59typedef enum _LttvTreeElement LttvTreeElement;
60typedef enum _LttvLogicalOp LttvLogicalOp;
61
62typedef union _LttvFieldValue LttvFieldValue;
63
64typedef struct _LttvSimpleExpression LttvSimpleExpression;
65typedef struct _LttvFilterTree LttvFilterTree;
66typedef struct _LttvFilter LttvFilter;
67
68
69/**
70 * @enum LttvStructType
71 * @brief The lttv structures
72 *
73 * the LttvStructType enumerates
74 * the possible structures for the
75 * lttv core filter
76 */
77enum _LttvStructType {
78 LTTV_FILTER_TRACE,
79 LTTV_FILTER_TRACESET,
80 LTTV_FILTER_TRACEFILE,
81 LTTV_FILTER_EVENT,
82 LTTV_FILTER_STATE
83};
84
85/**
86 * @enum LttvFieldType
87 * @brief Possible fields for the structures
88 *
89 * the LttvFieldType enum consists on
90 * all the hardcoded structures and
91 * their appropriate fields on which
92 * filters can be applied.
93 */
94enum _LttvFieldType {
95 LTTV_FILTER_TRACE_NAME, /** trace.name (char*) */
96 LTTV_FILTER_TRACEFILE_NAME, /** tracefile.name (char*) */
97 LTTV_FILTER_STATE_PID, /** state.pid (guint) */
98 LTTV_FILTER_STATE_PPID, /** state.ppid (guint) */
99 LTTV_FILTER_STATE_CT, /** state.creation_time (double) */
100 LTTV_FILTER_STATE_IT, /** state.insertion_time (double) */
101 LTTV_FILTER_STATE_P_NAME, /** state.process_name (char*) */
102 LTTV_FILTER_STATE_EX_MODE, /** state.execution_mode (LttvExecutionMode) */
103 LTTV_FILTER_STATE_EX_SUBMODE, /** state.execution_submode (LttvExecutionSubmode) */
104 LTTV_FILTER_STATE_P_STATUS, /** state.process_status (LttvProcessStatus) */
105 LTTV_FILTER_STATE_CPU, /** state.cpu (?last_cpu?) */
106 LTTV_FILTER_EVENT_NAME, /** event.name (char*) */
107 LTTV_FILTER_EVENT_CATEGORY, /** FIXME: not implemented */
108 LTTV_FILTER_EVENT_TIME, /** event.time (double) */
109 LTTV_FILTER_EVENT_TSC, /** event.tsc (double) */
110 LTTV_FILTER_EVENT_FIELD,
111 LTTV_FILTER_UNDEFINED /** undefined field */
112};
113
114/**
115 * @enum LttvExpressionOp
116 * @brief Contains possible operators
117 *
118 * This enumeration defines the
119 * possible operator used to compare
120 * right and left member in simple
121 * expression
122 */
123enum _LttvExpressionOp
124{
125 LTTV_FIELD_EQ, /** equal */
126 LTTV_FIELD_NE, /** not equal */
127 LTTV_FIELD_LT, /** lower than */
128 LTTV_FIELD_LE, /** lower or equal */
129 LTTV_FIELD_GT, /** greater than */
130 LTTV_FIELD_GE /** greater or equal */
131};
132
133/**
134 * @union LttvFieldValue
135 *
136 * @brief Contains possible field values
137 * This particular union defines the
138 * possible set of values taken by the
139 * right member of a simple expression.
140 * It is used for comparison whithin the
141 * 'operators' functions
142 */
143union _LttvFieldValue {
144 guint64 v_uint64;
145 guint32 v_uint32;
146 guint16 v_uint16;
147 double v_double;
148 char* v_string;
149 LttTime v_ltttime;
150};
151
152/**
153 * @enum LttvTreeElement
154 * @brief element types for the tree nodes
155 *
156 * LttvTreeElement defines the possible
157 * types of nodes which build the LttvFilterTree.
158 */
159enum _LttvTreeElement {
160 LTTV_TREE_IDLE, /** this node does nothing */
161 LTTV_TREE_NODE, /** this node contains a logical operator */
162 LTTV_TREE_LEAF /** this node is a leaf and contains a simple expression */
163};
164
165
166/**
167 * @struct LttvSimpleExpression
168 * @brief simple expression structure
169 *
170 * An LttvSimpleExpression is the base
171 * of all filtering operations. It also
172 * populates the leaves of the
173 * LttvFilterTree. Each expression
174 * consists basically in a structure
175 * field, an operator and a specific
176 * value.
177 */
178struct _LttvSimpleExpression
179{
180 gint field; /** left member of simple expression */
181 gint offset; /** offset used for dynamic fields */
182 gboolean (*op)(gpointer,LttvFieldValue); /** operator of simple expression */
183// char *value;
184 LttvFieldValue value; /** right member of simple expression */
185};
186
187/**
188 * @enum LttvLogicalOp
189 * @brief logical operators
190 *
191 * Contains the possible values taken
192 * by logical operator used to link
193 * simple expression. Values are
194 * AND, OR, XOR or NOT
195 */
196enum _LttvLogicalOp {
197 LTTV_LOGICAL_OR = 1, /** OR (1) */
198 LTTV_LOGICAL_AND = 1<<1, /** AND (2) */
199 LTTV_LOGICAL_NOT = 1<<2, /** NOT (4) */
200 LTTV_LOGICAL_XOR = 1<<3 /** XOR (8) */
201};
202
203/**
204 * @struct LttvFilterTree
205 * The filtering tree is used to represent the
206 * expression string in its entire hierarchy
207 * composed of simple expressions and logical
208 * operators
209 */
210struct _LttvFilterTree {
211 int node; /** value of LttvLogicalOp */
212 LttvTreeElement left;
213 LttvTreeElement right;
214 union {
215 LttvFilterTree* t;
216 LttvSimpleExpression* leaf;
217 } l_child;
218 union {
219 LttvFilterTree* t;
220 LttvSimpleExpression* leaf;
221 } r_child;
222};
223
224/**
225 * @struct lttv_filter
226 * Contains a binary tree of filtering options along
227 * with the expression itself.
228 */
229struct _LttvFilter {
230 char *expression;
231 LttvFilterTree *head;
232};
233
234/*
235 * Simple Expression
236 */
237LttvSimpleExpression* lttv_simple_expression_new();
238
239gboolean lttv_simple_expression_add_field(GPtrArray* fp, LttvSimpleExpression* se);
240
241gboolean lttv_simple_expression_assign_operator(LttvSimpleExpression* se, LttvExpressionOp op);
242
243gboolean lttv_simple_expression_assign_value(LttvSimpleExpression* se, char* value);
244
245void lttv_simple_expression_destroy(LttvSimpleExpression* se);
246
247
248/*
249 * Logical operators functions
250 */
251
252gboolean lttv_apply_op_eq_uint64(const gpointer v1, LttvFieldValue v2);
253gboolean lttv_apply_op_eq_uint32(const gpointer v1, LttvFieldValue v2);
254gboolean lttv_apply_op_eq_uint16(const gpointer v1, LttvFieldValue v2);
255gboolean lttv_apply_op_eq_double(const gpointer v1, LttvFieldValue v2);
256gboolean lttv_apply_op_eq_string(const gpointer v1, LttvFieldValue v2);
257gboolean lttv_apply_op_eq_quark(const gpointer v1, LttvFieldValue v2);
258gboolean lttv_apply_op_eq_ltttime(const gpointer v1, LttvFieldValue v2);
259
260gboolean lttv_apply_op_ne_uint64(const gpointer v1, LttvFieldValue v2);
261gboolean lttv_apply_op_ne_uint32(const gpointer v1, LttvFieldValue v2);
262gboolean lttv_apply_op_ne_uint16(const gpointer v1, LttvFieldValue v2);
263gboolean lttv_apply_op_ne_double(const gpointer v1, LttvFieldValue v2);
264gboolean lttv_apply_op_ne_string(const gpointer v1, LttvFieldValue v2);
265gboolean lttv_apply_op_ne_quark(const gpointer v1, LttvFieldValue v2);
266gboolean lttv_apply_op_ne_ltttime(const gpointer v1, LttvFieldValue v2);
267
268gboolean lttv_apply_op_lt_uint64(const gpointer v1, LttvFieldValue v2);
269gboolean lttv_apply_op_lt_uint32(const gpointer v1, LttvFieldValue v2);
270gboolean lttv_apply_op_lt_uint16(const gpointer v1, LttvFieldValue v2);
271gboolean lttv_apply_op_lt_double(const gpointer v1, LttvFieldValue v2);
272gboolean lttv_apply_op_lt_ltttime(const gpointer v1, LttvFieldValue v2);
273
274gboolean lttv_apply_op_le_uint64(const gpointer v1, LttvFieldValue v2);
275gboolean lttv_apply_op_le_uint32(const gpointer v1, LttvFieldValue v2);
276gboolean lttv_apply_op_le_uint16(const gpointer v1, LttvFieldValue v2);
277gboolean lttv_apply_op_le_double(const gpointer v1, LttvFieldValue v2);
278gboolean lttv_apply_op_le_ltttime(const gpointer v1, LttvFieldValue v2);
279
280gboolean lttv_apply_op_gt_uint64(const gpointer v1, LttvFieldValue v2);
281gboolean lttv_apply_op_gt_uint32(const gpointer v1, LttvFieldValue v2);
282gboolean lttv_apply_op_gt_uint16(const gpointer v1, LttvFieldValue v2);
283gboolean lttv_apply_op_gt_double(const gpointer v1, LttvFieldValue v2);
284gboolean lttv_apply_op_gt_ltttime(const gpointer v1, LttvFieldValue v2);
285
286gboolean lttv_apply_op_ge_uint64(const gpointer v1, LttvFieldValue v2);
287gboolean lttv_apply_op_ge_uint32(const gpointer v1, LttvFieldValue v2);
288gboolean lttv_apply_op_ge_uint16(const gpointer v1, LttvFieldValue v2);
289gboolean lttv_apply_op_ge_double(const gpointer v1, LttvFieldValue v2);
290gboolean lttv_apply_op_ge_ltttime(const gpointer v1, LttvFieldValue v2);
291
292/*
293 * Cloning
294 */
295
296LttvFilterTree* lttv_filter_tree_clone(const LttvFilterTree* tree);
297
298LttvFilter* lttv_filter_clone(const LttvFilter* filter);
299
300/*
301 * LttvFilter
302 */
303LttvFilter *lttv_filter_new();
304
305gboolean lttv_filter_update(LttvFilter* filter);
306
307void lttv_filter_destroy(LttvFilter* filter);
308
309gboolean lttv_filter_append_expression(LttvFilter* filter, char *expression);
310
311void lttv_filter_clear_expression(LttvFilter* filter);
312
313/*
314 * LttvFilterTree
315 */
316LttvFilterTree* lttv_filter_tree_new();
317
318void lttv_filter_tree_destroy(LttvFilterTree* tree);
319
320gboolean lttv_filter_tree_parse(
321 const LttvFilterTree* t,
322 const LttEvent* event,
323 const LttTracefile* tracefile,
324 const LttTrace* trace,
325 const LttvProcessState* state,
326 const LttvTracefileContext* context);
327
328gboolean lttv_filter_tree_parse_branch(
329 const LttvSimpleExpression* se,
330 const LttEvent* event,
331 const LttTracefile* tracefile,
332 const LttTrace* trace,
333 const LttvProcessState* state,
334 const LttvTracefileContext* context);
335
336/*
337 * Debug functions
338 */
339void lttv_print_tree(const LttvFilterTree* t);
340
341#endif // FILTER_H
342
This page took 0.022756 seconds and 4 git commands to generate.