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