work on core filter
[lttv.git] / ltt / branches / poly / lttv / lttv / filter.c
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
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
31452f49 26#include <lttv/filter.h>
27
31452f49 28/*
a4c292d4 29 read_token
48f6f3c2 30
a4c292d4 31 read_expression
32 ( read expr )
33 simple expr [ op expr ]
48f6f3c2 34
a4c292d4 35 read_simple_expression
36 read_field_path [ rel value ]
48f6f3c2 37
a4c292d4 38 read_field_path
39 read_field_component [. field path]
48f6f3c2 40
a4c292d4 41 read_field_component
42 name [ \[ value \] ]
48f6f3c2 43
a4c292d4 44 data struct:
45 and/or(left/right)
46 not(child)
47 op(left/right)
48 path(component...) -> field
31452f49 49*/
50
51/**
84a333d6 52 * Add an filtering option to the current tree
53 * @param expression Current expression to parse
54 * @return success/failure of operation
55 */
56gboolean
57parse_simple_expression(GString* expression) {
58
59 unsigned i;
60
a4c292d4 61
62
84a333d6 63}
64
65/**
66 * Creates a new lttv_filter
31452f49 67 * @param expression filtering options string
68 * @param t pointer to the current LttvTrace
84a333d6 69 * @return the current lttv_filter or NULL if error
31452f49 70 */
71lttv_filter*
a4c292d4 72lttv_filter_new(char *expression, LttvTraceState *tfs) {
73
74 /* test */
75 char* field = "cpu";
76 LttEventType *et;
77
78 // LttField* a_ltt_field = NULL;
79 // a_ltt_field = find_field(NULL,field);
80
81 // g_print("%s\n",a_ltt_field->field_type->type_name);
82
83 return NULL;
84
85 unsigned
86 i,
87 p=0, /* parenthesis nesting value */
88 b=0; /* current breakpoint in expression string */
31452f49 89
a4c292d4 90 gpointer tree = NULL;
91
92 /* temporary values */
93 GString *current_option = g_string_new("");
94 lttv_simple_expression a_simple_expression;
95
96 g_print("filter::lttv_filter_new()\n"); /* debug */
97
98 /*
99 * 1. parse expression
100 * 2. construct binary tree
101 * 3. return corresponding filter
102 */
103
104 /*
105 * Binary tree memory allocation
106 * - based upon a preliminary block size
107 */
108 gulong size = (strlen(expression)/AVERAGE_EXPRESSION_LENGTH)*MAX_FACTOR;
109 tree = g_malloc(size*sizeof(lttv_filter_tree));
110
111 /*
112 * Parse entire expression and construct
113 * the binary tree. There are two steps
114 * in browsing that string
115 * 1. finding boolean ops ( &,|,^,! ) and parenthesis
116 * 2. finding simple expressions
117 * - field path
118 * - op ( >, <, =, >=, <=, !=)
119 * - value
120 */
121
122 for(i=0;i<strlen(expression);i++) {
123 g_print("%s\n",current_option->str);
124 switch(expression[i]) {
125 /*
126 * logical operators
127 */
128 case '&': /* and */
129 case '|': /* or */
130 case '^': /* xor */
131 current_option = g_string_new("");
132 break;
133 case '!': /* not, or not equal (math op) */
134 if(expression[i+1] == '=') { /* != */
135 a_simple_expression.op = LTTV_FIELD_NE;
136 i++;
137 } else { /* ! */
138 g_print("%s\n",current_option);
139 current_option = g_string_new("");
140 }
141 break;
142 case '(': /* start of parenthesis */
143 p++; /* incrementing parenthesis nesting value */
144 break;
145 case ')': /* end of parenthesis */
146 p--; /* decrementing parenthesis nesting value */
147 break;
148
149 /*
150 * mathematic operators
151 */
152 case '<': /* lower, lower or equal */
153 if(expression[i+1] == '=') { /* <= */
154 i++;
155 a_simple_expression.op = LTTV_FIELD_LE;
156 } else a_simple_expression.op = LTTV_FIELD_LT;
157 break;
158 case '>': /* higher, higher or equal */
159 if(expression[i+1] == '=') { /* >= */
160 i++;
161 a_simple_expression.op = LTTV_FIELD_GE;
162 } else a_simple_expression.op = LTTV_FIELD_GT;
163 break;
164 case '=': /* equal */
165 a_simple_expression.op = LTTV_FIELD_EQ;
166 break;
167 default: /* concatening current string */
168 g_string_append_c(current_option,expression[i]);
169 }
170 }
171
172
173
174 if( p>0 ) {
175 g_warning("Wrong filtering options, the string\n\"%s\"\n\
176 is not valid due to parenthesis incorrect use",expression);
177 return NULL;
178 }
31452f49 179}
180
84a333d6 181/**
182 * Apply the filter to a specific trace
183 * @param filter the current filter applied
184 * @param tracefile the trace to apply the filter to
185 * @return success/failure of operation
186 */
31452f49 187gboolean
a4c292d4 188lttv_filter_tracefile(lttv_filter *filter, LttvTrace *tracefile) {
31452f49 189
190}
191
84a333d6 192/**
193 * Apply the filter to a specific event
194 * @param filter the current filter applied
195 * @param event the event to apply the filter to
196 * @return success/failure of operation
197 */
31452f49 198gboolean
a4c292d4 199lttv_filter_event(lttv_filter *filter, LttEvent *event) {
31452f49 200
201}
This page took 0.038234 seconds and 4 git commands to generate.