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