update compat
[lttv.git] / tags / lttv-0.10.0-pre15-12082008 / lttv / modules / text / textFilter.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2005 Simon Bouvier-Zappa
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
19 /*! \file lttv/modules/text/textFilter.c
20 * \brief Textual prompt for user filtering expression.
21 *
22 * The text filter facility will prompt for user filter option
23 * and transmit them to the lttv core. User can either specify
24 * a filtering string with the command line or/and specify a
25 * file containing filtering expressions.
26 */
27
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31
32 #include <glib.h>
33 #include <lttv/lttv.h>
34 #include <lttv/option.h>
35 #include <lttv/module.h>
36 #include <lttv/hook.h>
37 #include <lttv/attribute.h>
38 #include <lttv/iattribute.h>
39 #include <lttv/stats.h>
40 #include <lttv/filter.h>
41 #include <ltt/ltt.h>
42 #include <ltt/event.h>
43 #include <ltt/trace.h>
44
45 /* Insert the hooks before and after each trace and tracefile, and for each
46 event. Print a global header. */
47
48 /*
49 * TODO
50 * - specify wich hook function will be used to call the core filter
51 */
52
53 static char
54 *a_file_name = NULL,
55 *a_string = NULL;
56
57 static LttvHooks
58 *before_traceset,
59 *event_hook;
60
61 /**
62 * filters the file input from user
63 * @param hook_data the hook data, unused
64 */
65 void filter_analyze_file(void *hook_data) {
66
67 LttvAttributeValue value;
68
69 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
70
71 /*
72 * User may specify filtering options through static file
73 * and/or command line string. From these sources, an
74 * option string is rebuilded and sent to the filter core
75 */
76 if(!g_file_test(a_file_name,G_FILE_TEST_EXISTS)) {
77 g_warning("file %s does not exist", a_file_name);
78 return;
79 }
80
81 char* a_file_content = NULL;
82
83 g_file_get_contents(a_file_name,&a_file_content,NULL,NULL);
84
85 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
86 LTTV_POINTER, &value));
87
88 if(((GString*)*(value.v_pointer))->len != 0)
89 g_string_append_c((GString*)*(value.v_pointer),'&');
90 g_string_append_c((GString*)*(value.v_pointer),'(');
91 g_string_append((GString*)*(value.v_pointer),a_file_content);
92 g_string_append_c((GString*)*(value.v_pointer),')');
93
94 }
95
96 /**
97 * filters the string input from user
98 * @param hook_data the hook data, unused
99 */
100 void filter_analyze_string(void *hook_data) {
101
102 LttvAttributeValue value;
103
104 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
105
106 /*
107 * User may specify filtering options through static file
108 * and/or command line string. From these sources, an
109 * option string is rebuilded and sent to the filter core
110 */
111 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
112 LTTV_POINTER, &value));
113
114 if(((GString*)*(value.v_pointer))->len != 0)
115 g_string_append_c((GString*)*(value.v_pointer),'&');
116 g_string_append_c((GString*)*(value.v_pointer),'(');
117 g_string_append((GString*)*(value.v_pointer),a_string);
118 g_string_append_c((GString*)*(value.v_pointer),')');
119
120 }
121
122 /**
123 * Output all filter commands on console
124 * @param hook_data the hook data
125 */
126 void filter_list_commands(void *hook_data) {
127
128 g_print("[field] [op] [value]\n\n");
129
130 g_print("*** Possible fields ***\n");
131 g_print("event.name (string)\n");
132 g_print("event.facility (string)\n");
133 g_print("event.category (string)\n");
134 g_print("event.time (double)\n");
135 g_print("event.tsc (integer)\n");
136 g_print("event.target_pid (integer)\n");
137 g_print("event.field.facility_name.event_name.field_name.subfield_name (field_type)\n");
138 g_print("tracefile.name (string)\n");
139 g_print("trace.name (string)\n");
140 g_print("state.pid (integer)\n");
141 g_print("state.ppid (integer)\n");
142 g_print("state.creation_time (double)\n");
143 g_print("state.insertion_time (double)\n");
144 g_print("state.process_name (string)\n");
145 g_print("state.thread_brand (string)\n");
146 g_print("state.execution_mode (string)\n");
147 g_print("state.execution_submode (string)\n");
148 g_print("state.process_status (string)\n");
149 g_print("state.cpu (string)\n\n");
150
151 g_print("*** Possible operators ***\n");
152 g_print("equal '='\n");
153 g_print("not equal '!='\n");
154 g_print("greater '>'\n");
155 g_print("greater or equal '>='\n");
156 g_print("lower '<'\n");
157 g_print("lower or equal '<='\n");
158
159 g_print("*** Possible values ***\n");
160 g_print("string, integer, double");
161 }
162
163 /**
164 * initialize the new module
165 */
166 static void init() {
167
168 LttvAttributeValue value;
169
170 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
171
172 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
173 LTTV_POINTER, &value));
174
175 *(value.v_pointer) = g_string_new("");
176
177 g_info("Init textFilter.c");
178
179 a_string = NULL;
180 lttv_option_add("expression", 'e',
181 "filters a string issued by the user on the command line",
182 "string",
183 LTTV_OPT_STRING, &a_string, filter_analyze_string, NULL);
184 // add function to call for option
185
186 a_file_name = NULL;
187 lttv_option_add("filename", 'f',
188 "browse the filter options contained in specified file",
189 "file name",
190 LTTV_OPT_STRING, &a_file_name, filter_analyze_file, NULL);
191
192 lttv_option_add("list", 'l',
193 "list all possible filter commands for module",
194 "list commands",
195 LTTV_OPT_NONE, NULL, filter_list_commands, NULL);
196
197 }
198
199 /**
200 * Destroy the current module
201 */
202 static void destroy() {
203 g_info("Destroy textFilter");
204
205 lttv_option_remove("expression");
206
207 lttv_option_remove("filename");
208
209 lttv_option_remove("list");
210
211 LttvAttributeValue value;
212
213 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
214
215 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
216 LTTV_POINTER, &value));
217
218 g_string_free((GString*)*(value.v_pointer),TRUE);
219
220 }
221
222
223 LTTV_MODULE("textFilter", "Filters traces", \
224 "Filter the trace following commands issued by user input", \
225 init, destroy, "option")
226
This page took 0.033738 seconds and 4 git commands to generate.