Began to work on the guifilter module
[lttv.git] / ltt / branches / poly / lttv / lttv / filter.c
CommitLineData
9c312311 1/* This file is part of the Linux Trace Toolkit viewer
0769c82f 2 * Copyright (C) 2003-2005 Michel Dagenais
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
31452f49 19/*
48f6f3c2 20 consist in AND, OR and NOT nested expressions, forming a tree with
21 simple relations as leaves. The simple relations test is a field
22 in an event is equal, not equal, smaller, smaller or equal, larger, or
a4c292d4 23 larger or equal to a specified value.
24*/
48f6f3c2 25
0769c82f 26/*
27 * YET TO BE ANSWERED
91ad3f0a 28 * - nothing for now
0769c82f 29 */
30
31452f49 31#include <lttv/filter.h>
32
31452f49 33/*
a4c292d4 34 read_token
48f6f3c2 35
a4c292d4 36 read_expression
37 ( read expr )
38 simple expr [ op expr ]
48f6f3c2 39
a4c292d4 40 read_simple_expression
41 read_field_path [ rel value ]
48f6f3c2 42
a4c292d4 43 read_field_path
44 read_field_component [. field path]
48f6f3c2 45
a4c292d4 46 read_field_component
47 name [ \[ value \] ]
48f6f3c2 48
a4c292d4 49 data struct:
50 and/or(left/right)
51 not(child)
52 op(left/right)
53 path(component...) -> field
31452f49 54*/
55
1a7fa682 56GQuark
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
1a7fa682 76
0769c82f 77/**
78 * Parse through filtering field hierarchy as specified
79 * by user. This function compares each value to
80 * predetermined quarks
81 * @param fp The field path list
82 * @return success/failure of operation
83 */
84gboolean
85parse_field_path(GList* fp) {
86
87 GString* f = g_list_first(fp)->data;
88
91ad3f0a 89 if(g_quark_try_string(f->str) == LTTV_FILTER_EVENT) {
90// parse_subfield(fp, LTTV_FILTER_EVENT);
91
92 } else if(g_quark_try_string(f->str) == LTTV_FILTER_TRACEFILE) {
93
94 } else if(g_quark_try_string(f->str) == LTTV_FILTER_TRACE) {
95
96 } else if(g_quark_try_string(f->str) == LTTV_FILTER_STATE) {
97
98 } else {
99 g_warning("Unrecognized field in filter string");
100 return FALSE;
0769c82f 101 }
91ad3f0a 102 return TRUE;
0769c82f 103}
104
31452f49 105/**
84a333d6 106 * Add an filtering option to the current tree
107 * @param expression Current expression to parse
108 * @return success/failure of operation
109 */
110gboolean
111parse_simple_expression(GString* expression) {
112
113 unsigned i;
114
a4c292d4 115
0769c82f 116
a4c292d4 117
84a333d6 118}
119
120/**
121 * Creates a new lttv_filter
31452f49 122 * @param expression filtering options string
123 * @param t pointer to the current LttvTrace
84a333d6 124 * @return the current lttv_filter or NULL if error
31452f49 125 */
91ad3f0a 126lttv_filter_t*
0769c82f 127lttv_filter_new(char *expression, LttvTraceState *tcs) {
a4c292d4 128
0769c82f 129 g_print("filter::lttv_filter_new()\n"); /* debug */
a4c292d4 130
a4c292d4 131 unsigned
132 i,
91ad3f0a 133 p_nesting=0, /* parenthesis nesting value */
a4c292d4 134 b=0; /* current breakpoint in expression string */
31452f49 135
a4c292d4 136 /* temporary values */
0769c82f 137 GString *a_field_component = g_string_new("");
138 GList *a_field_path = NULL;
a4c292d4 139 lttv_simple_expression a_simple_expression;
0769c82f 140
a4c292d4 141 /*
142 * 1. parse expression
143 * 2. construct binary tree
144 * 3. return corresponding filter
145 */
146
147 /*
148 * Binary tree memory allocation
149 * - based upon a preliminary block size
150 */
91ad3f0a 151// gulong size = (strlen(expression)/AVERAGE_EXPRESSION_LENGTH)*MAX_FACTOR;
152// tree = g_malloc(size*sizeof(lttv_filter_tree));
a4c292d4 153
154 /*
155 * Parse entire expression and construct
156 * the binary tree. There are two steps
157 * in browsing that string
158 * 1. finding boolean ops ( &,|,^,! ) and parenthesis
159 * 2. finding simple expressions
0769c82f 160 * - field path ( separated by dots )
a4c292d4 161 * - op ( >, <, =, >=, <=, !=)
0769c82f 162 * - value ( integer, string ... )
163 * To spare computing time, the whole
164 * string is parsed in this loop for a
165 * O(n) complexity order.
a4c292d4 166 */
a4c292d4 167 for(i=0;i<strlen(expression);i++) {
0769c82f 168 g_print("%s\n",a_field_component->str);
a4c292d4 169 switch(expression[i]) {
170 /*
171 * logical operators
172 */
173 case '&': /* and */
174 case '|': /* or */
175 case '^': /* xor */
0769c82f 176 g_list_append( a_field_path, a_field_component );
177 a_field_component = g_string_new("");
a4c292d4 178 break;
179 case '!': /* not, or not equal (math op) */
180 if(expression[i+1] == '=') { /* != */
181 a_simple_expression.op = LTTV_FIELD_NE;
182 i++;
183 } else { /* ! */
0769c82f 184 g_print("%s\n",a_field_component);
1a7fa682 185 a_field_component = g_string_new("");
a4c292d4 186 }
187 break;
188 case '(': /* start of parenthesis */
91ad3f0a 189 case '[':
190 case '{':
191 p_nesting++; /* incrementing parenthesis nesting value */
a4c292d4 192 break;
193 case ')': /* end of parenthesis */
91ad3f0a 194 case ']':
195 case '}':
196 p_nesting--; /* decrementing parenthesis nesting value */
a4c292d4 197 break;
198
199 /*
200 * mathematic operators
201 */
202 case '<': /* lower, lower or equal */
203 if(expression[i+1] == '=') { /* <= */
204 i++;
205 a_simple_expression.op = LTTV_FIELD_LE;
206 } else a_simple_expression.op = LTTV_FIELD_LT;
207 break;
208 case '>': /* higher, higher or equal */
209 if(expression[i+1] == '=') { /* >= */
210 i++;
211 a_simple_expression.op = LTTV_FIELD_GE;
212 } else a_simple_expression.op = LTTV_FIELD_GT;
213 break;
214 case '=': /* equal */
215 a_simple_expression.op = LTTV_FIELD_EQ;
216 break;
0769c82f 217 /*
218 * Field concatening caracter
219 */
220 case '.': /* dot */
221 g_list_append( a_field_path, a_field_component );
222 a_field_component = g_string_new("");
223 break;
a4c292d4 224 default: /* concatening current string */
1a7fa682 225 g_string_append_c(a_field_component,expression[i]);
a4c292d4 226 }
227 }
228
229
230
91ad3f0a 231 if( p_nesting>0 ) {
a4c292d4 232 g_warning("Wrong filtering options, the string\n\"%s\"\n\
233 is not valid due to parenthesis incorrect use",expression);
234 return NULL;
235 }
31452f49 236}
237
84a333d6 238/**
239 * Apply the filter to a specific trace
240 * @param filter the current filter applied
241 * @param tracefile the trace to apply the filter to
242 * @return success/failure of operation
243 */
31452f49 244gboolean
91ad3f0a 245lttv_filter_tracefile(lttv_filter_t *filter, LttTracefile *tracefile) {
0769c82f 246
247
248
249 /* test */
250/* int i, nb;
251 char *f_name, *e_name;
31452f49 252
0769c82f 253 char* field = "cpu";
254
255 LttvTraceHook h;
256
257 LttEventType *et;
258
259 LttType *t;
260
261 GString *fe_name = g_string_new("");
262
263 nb = ltt_trace_eventtype_number(tcs->parent.t);
264 g_print("NB:%i\n",nb);
265 for(i = 0 ; i < nb ; i++) {
266 et = ltt_trace_eventtype_get(tcs->parent.t, i);
267 e_name = ltt_eventtype_name(et);
268 f_name = ltt_facility_name(ltt_eventtype_facility(et));
269 g_string_printf(fe_name, "%s.%s", f_name, e_name);
270 g_print("facility:%s and event:%s\n",f_name,e_name);
271 }
272 */
31452f49 273}
274
1a7fa682 275gboolean
91ad3f0a 276lttv_filter_tracestate(lttv_filter_t *filter, LttvTraceState *tracestate) {
341aa948 277
278}
1a7fa682 279
84a333d6 280/**
281 * Apply the filter to a specific event
282 * @param filter the current filter applied
283 * @param event the event to apply the filter to
284 * @return success/failure of operation
285 */
31452f49 286gboolean
91ad3f0a 287lttv_filter_event(lttv_filter_t *filter, LttEvent *event) {
31452f49 288
289}
1a7fa682 290
91ad3f0a 291/**
292 * Initializes the filter module and specific values
293 */
1a7fa682 294static void module_init()
295{
91ad3f0a 296
297 /*
298 * Quarks initialization
299 * for hardcoded filtering options
300 *
301 * TODO: traceset has no yet been defined
302 */
303
304 /* top fields */
305 LTTV_FILTER_EVENT = g_quark_from_string("event");
306 LTTV_FILTER_TRACE = g_quark_from_string("trace");
307 LTTV_FILTER_TRACESET = g_quark_from_string("traceset");
308 LTTV_FILTER_STATE = g_quark_from_string("state");
309 LTTV_FILTER_TRACEFILE = g_quark_from_string("tracefile");
1a7fa682 310
91ad3f0a 311 /* event.name, tracefile.name, trace.name */
312 LTTV_FILTER_NAME = g_quark_from_string("name");
313
314 /* event sub fields */
315 LTTV_FILTER_CATEGORY = g_quark_from_string("category");
316 LTTV_FILTER_TIME = g_quark_from_string("time");
317 LTTV_FILTER_TSC = g_quark_from_string("tsc");
318
319 /* state sub fields */
320 LTTV_FILTER_PID = g_quark_from_string("pid");
321 LTTV_FILTER_PPID = g_quark_from_string("ppid");
322 LTTV_FILTER_C_TIME = g_quark_from_string("creation_time");
323 LTTV_FILTER_I_TIME = g_quark_from_string("insertion_time");
324 LTTV_FILTER_P_NAME = g_quark_from_string("process_name");
325 LTTV_FILTER_EX_MODE = g_quark_from_string("execution_mode");
326 LTTV_FILTER_EX_SUBMODE = g_quark_from_string("execution_submode");
327 LTTV_FILTER_P_STATUS = g_quark_from_string("process_status");
328 LTTV_FILTER_CPU = g_quark_from_string("cpu");
329
1a7fa682 330}
331
91ad3f0a 332/**
333 * Destroys the filter module and specific values
334 */
1a7fa682 335static void module_destroy()
336{
337}
338
339
91ad3f0a 340LTTV_MODULE("filter", "Filters traceset and events", \
341 "Filters traceset and events specifically to user input", \
1a7fa682 342 module_init, module_destroy)
343
344
345
This page took 0.05067 seconds and 4 git commands to generate.