1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
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;
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.
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,
22 #include <lttv/traceset.h>
23 #include <lttv/tracecontext.h>
24 #include <lttv/state.h>
25 #include <lttv/module.h>
27 #include <ltt/event.h>
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
36 The grammar for filters is:
40 expression = "(" expression ")" | "!" expression |
41 expression "&&" expression | expression "||" expression |
44 simpleExpression = fieldPath op value
46 fieldPath = fieldComponent [ "." fieldPath ]
48 fieldComponent = name [ "[" integer "]" ]
50 value = integer | double | string
55 * @enum LttvStructType
56 * @brief The lttv structures
58 * the LttvStructType enumerates
59 * the possible structures for the
62 enum _LttvStructType
{
65 LTTV_FILTER_TRACEFILE
,
72 * @brief Possible fields for the structures
74 * the LttvFieldType enum consists on
75 * all the hardcoded structures and
76 * their appropriate fields on which
77 * filters can be applied.
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
,
97 // LTTV_FILTER_CATEGORY,
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,
112 * @enum LttvExpressionOp
114 typedef enum _LttvExpressionOp
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 */
125 * @enum LttvTreeElement
126 * @brief element types for the tree nodes
128 * LttvTreeElement defines the possible
129 * types of nodes which build the LttvFilterTree.
131 typedef enum _LttvTreeElement
{
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 */
138 * @enum LttvSimpleExpression
139 * @brief simple expression structure
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
149 typedef struct _LttvSimpleExpression
154 // LttvExpressionOp op;
155 gboolean (*op
)(gpointer
,char*);
157 } LttvSimpleExpression
;
160 * @enum LttvLogicalOp
161 * @brief logical operators
163 * Contains the possible values taken
164 * by logical operator used to link
165 * simple expression. Values are
166 * AND, OR, XOR or NOT
168 typedef enum _LttvLogicalOp
{
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 */
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
182 typedef struct _LttvFilterTree
{
183 int node
; /** value of LttvLogicalOp */
184 LttvTreeElement left
;
185 LttvTreeElement right
;
187 struct LttvFilter
* t
;
188 LttvSimpleExpression
* leaf
;
191 struct LttvFilter
* t
;
192 LttvSimpleExpression
* leaf
;
197 * @struct lttv_filter
198 * Contains a binary tree of filtering options along
199 * with the expression itself.
201 typedef struct _LttvFilter
{
203 LttvFilterTree
*head
;
207 * General Data Handling functions
210 LttvSimpleExpression
* lttv_simple_expression_new();
212 void lttv_filter_tree_add_node(GPtrArray
* stack
, LttvFilterTree
* subtree
, LttvLogicalOp op
);
214 gboolean
parse_field_path(GPtrArray
* fp
, LttvSimpleExpression
* se
);
216 gboolean
assign_operator(LttvSimpleExpression
* se
, LttvExpressionOp op
);
221 * Logical operators functions
224 gboolean
lttv_apply_op_eq_uint64(gpointer v1
, char* v2
);
225 gboolean
lttv_apply_op_eq_uint32(gpointer v1
, char* v2
);
226 gboolean
lttv_apply_op_eq_uint16(gpointer v1
, char* v2
);
227 gboolean
lttv_apply_op_eq_double(gpointer v1
, char* v2
);
228 gboolean
lttv_apply_op_eq_string(gpointer v1
, char* v2
);
230 gboolean
lttv_apply_op_ne_uint64(gpointer v1
, char* v2
);
231 gboolean
lttv_apply_op_ne_uint32(gpointer v1
, char* v2
);
232 gboolean
lttv_apply_op_ne_uint16(gpointer v1
, char* v2
);
233 gboolean
lttv_apply_op_ne_double(gpointer v1
, char* v2
);
234 gboolean
lttv_apply_op_ne_string(gpointer v1
, char* v2
);
236 gboolean
lttv_apply_op_lt_uint64(gpointer v1
, char* v2
);
237 gboolean
lttv_apply_op_lt_uint32(gpointer v1
, char* v2
);
238 gboolean
lttv_apply_op_lt_uint16(gpointer v1
, char* v2
);
239 gboolean
lttv_apply_op_lt_double(gpointer v1
, char* v2
);
241 gboolean
lttv_apply_op_le_uint64(gpointer v1
, char* v2
);
242 gboolean
lttv_apply_op_le_uint32(gpointer v1
, char* v2
);
243 gboolean
lttv_apply_op_le_uint16(gpointer v1
, char* v2
);
244 gboolean
lttv_apply_op_le_double(gpointer v1
, char* v2
);
246 gboolean
lttv_apply_op_gt_uint64(gpointer v1
, char* v2
);
247 gboolean
lttv_apply_op_gt_uint32(gpointer v1
, char* v2
);
248 gboolean
lttv_apply_op_gt_uint16(gpointer v1
, char* v2
);
249 gboolean
lttv_apply_op_gt_double(gpointer v1
, char* v2
);
251 gboolean
lttv_apply_op_ge_uint64(gpointer v1
, char* v2
);
252 gboolean
lttv_apply_op_ge_uint32(gpointer v1
, char* v2
);
253 gboolean
lttv_apply_op_ge_uint16(gpointer v1
, char* v2
);
254 gboolean
lttv_apply_op_ge_double(gpointer v1
, char* v2
);
260 LttvFilterTree
* lttv_filter_tree_clone(LttvFilterTree
* tree
);
262 LttvFilter
* lttv_filter_clone(LttvFilter
* filter
);
265 * Constructors/Destructors
269 LttvFilter
*lttv_filter_new();
271 gboolean
lttv_filter_update(LttvFilter
* filter
);
273 void lttv_filter_destroy(LttvFilter
* filter
);
275 void lttv_filter_append_expression(LttvFilter
* filter
, char *expression
);
277 void lttv_filter_clear_expression(LttvFilter
* filter
);
280 LttvFilterTree
* lttv_filter_tree_new();
282 void lttv_filter_tree_destroy(LttvFilterTree
* tree
);
284 gboolean
lttv_filter_tree_parse(
287 LttTracefile
* tracefile
,
289 LttvProcessState
* state
);
294 * These hook functions will be the one called when filtering
295 * an event, a trace, a state, etc.
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. */
301 gboolean
lttv_filter_tracefile(LttvFilter
*filter
, LttTracefile
*tracefile
);
303 gboolean
lttv_filter_tracestate(LttvFilter
*filter
, LttvTraceState
*tracestate
);
305 gboolean
lttv_filter_event(LttvFilter
*filter
, LttEvent
*event
);
310 void lttv_print_tree(LttvFilterTree
* t
);