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 | |
29 | #define AVERAGE_EXPRESSION_LENGTH 6 |
30 | #define MAX_FACTOR 1.5 |
31452f49 |
31 | |
48f6f3c2 |
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 | |
1a7fa682 |
56 | extern GQuark |
0769c82f |
57 | LTTV_FILTER_TRACE, |
58 | LTTV_FILTER_TRACESET, |
59 | LTTV_FILTER_TRACEFILE, |
60 | LTTV_FILTER_STATE, |
91ad3f0a |
61 | LTTV_FILTER_EVENT, |
62 | LTTV_FILTER_NAME, |
63 | LTTV_FILTER_CATEGORY, |
64 | LTTV_FILTER_TIME, |
65 | LTTV_FILTER_TSC, |
66 | LTTV_FILTER_PID, |
67 | LTTV_FILTER_PPID, |
68 | LTTV_FILTER_C_TIME, |
69 | LTTV_FILTER_I_TIME, |
70 | LTTV_FILTER_P_NAME, |
71 | LTTV_FILTER_EX_MODE, |
72 | LTTV_FILTER_EX_SUBMODE, |
73 | LTTV_FILTER_P_STATUS, |
74 | LTTV_FILTER_CPU; |
75 | |
84a333d6 |
76 | /** |
77 | * @enum lttv_expression_op |
78 | */ |
2ea36caf |
79 | typedef enum _LttvExpressionOp |
84a333d6 |
80 | { |
81 | LTTV_FIELD_EQ, /** equal */ |
82 | LTTV_FIELD_NE, /** not equal */ |
83 | LTTV_FIELD_LT, /** lower than */ |
84 | LTTV_FIELD_LE, /** lower or equal */ |
85 | LTTV_FIELD_GT, /** greater than */ |
86 | LTTV_FIELD_GE /** greater or equal */ |
2ea36caf |
87 | } LttvExpressionOp; |
84a333d6 |
88 | |
2ea36caf |
89 | /* |
90 | * FIXME: Unused enum ? |
91 | */ |
92 | typedef enum _LttvExpressionType |
84a333d6 |
93 | { |
94 | LTTV_EXPRESSION, |
f4e9dd16 |
95 | LTTV_SIMPLE_EXPRESSION, |
96 | LTTV_EXPRESSION_OP, |
97 | LTTV_UNDEFINED_EXPRESSION |
2ea36caf |
98 | } LttvExpressionType; |
84a333d6 |
99 | |
2ea36caf |
100 | typedef enum _LttvTreeElement { |
2a734d8e |
101 | LTTV_TREE_IDLE, |
f4e9dd16 |
102 | LTTV_TREE_NODE, |
103 | LTTV_TREE_LEAF |
2ea36caf |
104 | } LttvTreeElement; |
f4e9dd16 |
105 | |
2ea36caf |
106 | typedef struct _LttvSimpleExpression |
84a333d6 |
107 | { |
84a333d6 |
108 | char *field_name; |
2ea36caf |
109 | LttvExpressionOp op; |
84a333d6 |
110 | char *value; |
2ea36caf |
111 | } LttvSimpleExpression; |
84a333d6 |
112 | |
2ea36caf |
113 | typedef enum _LttvLogicalOp { |
f4e9dd16 |
114 | LTTV_LOGICAL_OR = 1, /* 1 */ |
115 | LTTV_LOGICAL_AND = 1<<1, /* 2 */ |
116 | LTTV_LOGICAL_NOT = 1<<2, /* 4 */ |
117 | LTTV_LOGICAL_XOR = 1<<3 /* 8 */ |
2ea36caf |
118 | } LttvLogicalOp; |
1a7fa682 |
119 | |
a4c292d4 |
120 | /* |
1a7fa682 |
121 | * Ah .. that's my tree |
122 | */ |
f4e9dd16 |
123 | //typedef struct _lttv_expression |
124 | //{ |
1a7fa682 |
125 | // gboolean simple_expression; |
f4e9dd16 |
126 | // int op; |
127 | // lttv_expression_type type; |
128 | // union { |
129 | // struct lttv_expression *e; |
130 | // lttv_field_relation *se; /* --> simple expression */ |
131 | // } e; |
132 | //} lttv_expression; |
133 | |
2ea36caf |
134 | /* |
135 | * FIXME: Unused struct |
136 | */ |
137 | typedef struct _LttvExpression { |
138 | LttvExpressionType type; |
1a7fa682 |
139 | union { |
2ea36caf |
140 | LttvSimpleExpression *se; |
f4e9dd16 |
141 | int op; |
1a7fa682 |
142 | } e; |
2ea36caf |
143 | } LttvExpression; |
1a7fa682 |
144 | |
2ea36caf |
145 | typedef struct _LttvFilter { |
0cdc2470 |
146 | // lttv_expression* node; |
2ea36caf |
147 | int node; /** value of LttvLogicalOp */ |
148 | LttvTreeElement left; |
149 | LttvTreeElement right; |
f4e9dd16 |
150 | union { |
2ea36caf |
151 | struct LttvFilter* t; |
152 | LttvSimpleExpression* leaf; |
f4e9dd16 |
153 | } l_child; |
154 | union { |
2ea36caf |
155 | struct LttvFilter* t; |
156 | LttvSimpleExpression* leaf; |
f4e9dd16 |
157 | } r_child; |
2ea36caf |
158 | } LttvFilter; |
84a333d6 |
159 | |
31452f49 |
160 | /** |
161 | * @struct lttv_filter |
162 | * ( will later contain a binary tree of filtering options ) |
163 | */ |
2ea36caf |
164 | //typedef struct _lttv_filter_t { |
165 | // lttv_filter_tree* tree; |
166 | //} lttv_filter_t; |
84a333d6 |
167 | |
0769c82f |
168 | |
2ea36caf |
169 | LttvSimpleExpression* lttv_simple_expression_new(); |
0cdc2470 |
170 | |
2ea36caf |
171 | LttvFilter* lttv_filter_tree_new(); |
f4e9dd16 |
172 | |
2ea36caf |
173 | void lttv_filter_tree_destroy(LttvFilter* tree); |
f4e9dd16 |
174 | |
2ea36caf |
175 | LttvFilter* lttv_filter_clone(LttvFilter* tree); |
bcacff8e |
176 | |
2ea36caf |
177 | void lttv_filter_tree_add_node(GPtrArray* stack, LttvFilter* subtree, LttvLogicalOp op); |
0cdc2470 |
178 | |
f4e9dd16 |
179 | /* Parse field path contained in list */ |
180 | gboolean parse_field_path(GPtrArray* fp); |
91ad3f0a |
181 | |
84a333d6 |
182 | gboolean parse_simple_expression(GString* expression); |
48f6f3c2 |
183 | |
48f6f3c2 |
184 | /* Compile the filter expression into an efficient data structure */ |
2ea36caf |
185 | LttvFilter *lttv_filter_new(char *expression, LttvTraceState *tfs); |
48f6f3c2 |
186 | |
2ea36caf |
187 | void lttv_filter_destroy(LttvFilter* filter); |
1da1525d |
188 | |
48f6f3c2 |
189 | /* Check if the tracefile or event satisfies the filter. The arguments are |
190 | declared as void * to allow these functions to be used as hooks. */ |
191 | |
2ea36caf |
192 | gboolean lttv_filter_tracefile(LttvFilter *filter, LttTracefile *tracefile); |
48f6f3c2 |
193 | |
2ea36caf |
194 | gboolean lttv_filter_tracestate(LttvFilter *filter, LttvTraceState *tracestate); |
1a7fa682 |
195 | |
2ea36caf |
196 | gboolean lttv_filter_event(LttvFilter *filter, LttEvent *event); |
48f6f3c2 |
197 | |
198 | #endif // FILTER_H |
199 | |