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,
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
23 larger or equal to a specified value.
26 #include <lttv/filter.h>
33 simple expr [ op expr ]
35 read_simple_expression
36 read_field_path [ rel value ]
39 read_field_component [. field path]
48 path(component...) -> field
52 * Add an filtering option to the current tree
53 * @param expression Current expression to parse
54 * @return success/failure of operation
57 parse_simple_expression(GString
* expression
) {
66 * Creates a new lttv_filter
67 * @param expression filtering options string
68 * @param t pointer to the current LttvTrace
69 * @return the current lttv_filter or NULL if error
72 lttv_filter_new(char *expression
, LttvTraceState
*tfs
) {
78 // LttField* a_ltt_field = NULL;
79 // a_ltt_field = find_field(NULL,field);
81 // g_print("%s\n",a_ltt_field->field_type->type_name);
87 p
=0, /* parenthesis nesting value */
88 b
=0; /* current breakpoint in expression string */
92 /* temporary values */
93 GString
*current_option
= g_string_new("");
94 lttv_simple_expression a_simple_expression
;
96 g_print("filter::lttv_filter_new()\n"); /* debug */
100 * 2. construct binary tree
101 * 3. return corresponding filter
105 * Binary tree memory allocation
106 * - based upon a preliminary block size
108 gulong size
= (strlen(expression
)/AVERAGE_EXPRESSION_LENGTH
)*MAX_FACTOR
;
109 tree
= g_malloc(size
*sizeof(lttv_filter_tree
));
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
118 * - op ( >, <, =, >=, <=, !=)
122 for(i
=0;i
<strlen(expression
);i
++) {
123 g_print("%s\n",current_option
->str
);
124 switch(expression
[i
]) {
131 current_option
= g_string_new("");
133 case '!': /* not, or not equal (math op) */
134 if(expression
[i
+1] == '=') { /* != */
135 a_simple_expression
.op
= LTTV_FIELD_NE
;
138 g_print("%s\n",current_option
);
139 current_option
= g_string_new("");
142 case '(': /* start of parenthesis */
143 p
++; /* incrementing parenthesis nesting value */
145 case ')': /* end of parenthesis */
146 p
--; /* decrementing parenthesis nesting value */
150 * mathematic operators
152 case '<': /* lower, lower or equal */
153 if(expression
[i
+1] == '=') { /* <= */
155 a_simple_expression
.op
= LTTV_FIELD_LE
;
156 } else a_simple_expression
.op
= LTTV_FIELD_LT
;
158 case '>': /* higher, higher or equal */
159 if(expression
[i
+1] == '=') { /* >= */
161 a_simple_expression
.op
= LTTV_FIELD_GE
;
162 } else a_simple_expression
.op
= LTTV_FIELD_GT
;
164 case '=': /* equal */
165 a_simple_expression
.op
= LTTV_FIELD_EQ
;
167 default: /* concatening current string */
168 g_string_append_c(current_option
,expression
[i
]);
175 g_warning("Wrong filtering options, the string\n\"%s\"\n\
176 is not valid due to parenthesis incorrect use",expression
);
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
188 lttv_filter_tracefile(lttv_filter
*filter
, LttvTrace
*tracefile
) {
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
199 lttv_filter_event(lttv_filter
*filter
, LttEvent
*event
) {