a58509ee |
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 | |
91ad3f0a |
19 | /* |
20 | * The text filter facility will prompt for user filter option |
21 | * and transmit them to the lttv core |
22 | */ |
a58509ee |
23 | |
24 | #include <lttv/lttv.h> |
25 | #include <lttv/option.h> |
26 | #include <lttv/module.h> |
27 | #include <lttv/hook.h> |
28 | #include <lttv/attribute.h> |
29 | #include <lttv/iattribute.h> |
30 | #include <lttv/stats.h> |
31 | #include <lttv/filter.h> |
32 | #include <ltt/ltt.h> |
33 | #include <ltt/event.h> |
34 | #include <ltt/type.h> |
35 | #include <ltt/trace.h> |
36 | #include <ltt/facility.h> |
37 | #include <stdio.h> |
38 | |
39 | /* Insert the hooks before and after each trace and tracefile, and for each |
40 | event. Print a global header. */ |
41 | |
91ad3f0a |
42 | /* |
43 | * YET TO BE ANSWERED ! |
44 | * - why does this module need dependency with batchAnalysis ? |
45 | */ |
46 | |
47 | static char |
a58509ee |
48 | *a_file_name = NULL, |
91ad3f0a |
49 | *a_string = NULL; |
50 | |
51 | static GString |
a58509ee |
52 | *a_filter_string = NULL; |
53 | |
91ad3f0a |
54 | |
a58509ee |
55 | static LttvHooks |
56 | *before_traceset, |
57 | *event_hook; |
58 | |
59 | static FILE *a_file; |
60 | |
91ad3f0a |
61 | |
a58509ee |
62 | /** |
91ad3f0a |
63 | * filters the file input from user |
a58509ee |
64 | * @param hook_data the hook data |
91ad3f0a |
65 | * @return success/failure of operation |
a58509ee |
66 | */ |
91ad3f0a |
67 | void filter_analyze_file(void *hook_data) { |
68 | |
69 | g_print("textFilter::filter_analyze_file\n"); |
70 | |
71 | /* |
a58509ee |
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 | */ |
91ad3f0a |
76 | a_file = fopen(a_file_name, "r"); |
77 | if(a_file == NULL) { |
78 | g_warning("file %s does not exist", a_file_name); |
79 | return; |
80 | } |
81 | |
82 | char* tmp; |
83 | fscanf(a_file,"%s",tmp); |
84 | |
85 | if(!a_filter_string->len) { |
86 | g_string_append(a_filter_string,tmp); |
87 | } |
88 | else { |
89 | g_string_append(a_filter_string,"&"); /*conjonction between expression*/ |
90 | g_string_append(a_filter_string,tmp); |
91 | } |
92 | |
93 | fclose(a_file); |
94 | } |
95 | |
96 | /** |
97 | * filters the string input from user |
98 | * @param hook_data the hook data |
99 | * @return success/failure of operation |
100 | */ |
101 | void filter_analyze_string(void *hook_data) { |
102 | |
103 | g_print("textFilter::filter_analyze_string\n"); |
18d1226f |
104 | |
105 | a_filter_string = g_string_new(""); |
91ad3f0a |
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 | */ |
18d1226f |
111 | // if(!a_filter_string->len) { |
91ad3f0a |
112 | g_string_append(a_filter_string,a_string); |
18d1226f |
113 | lttv_filter_new(a_filter_string->str,NULL); |
114 | // } |
115 | // else { |
116 | // g_string_append(a_filter_string,"&"); /*conjonction between expression*/ |
117 | // g_string_append(a_filter_string,a_string); |
118 | // } |
91ad3f0a |
119 | |
a58509ee |
120 | } |
121 | |
122 | /** |
123 | * filter to current event depending on the |
124 | * filter options tree |
125 | * @param hook_data the hook data |
126 | * @param call_data the call data |
127 | * @return success/error of operation |
128 | */ |
129 | static gboolean filter_event_content(void *hook_data, void *call_data) { |
130 | |
131 | g_print("textFilter::filter_event_content\n"); /* debug */ |
132 | } |
133 | |
134 | /** |
135 | * initialize the new module |
136 | */ |
137 | static void init() { |
138 | |
91ad3f0a |
139 | g_print("textFilter::init()\n"); /* debug */ |
140 | |
141 | a_filter_string = g_string_new(""); |
142 | |
a58509ee |
143 | LttvAttributeValue value; |
144 | |
145 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
146 | |
147 | g_info("Init textFilter.c"); |
148 | |
91ad3f0a |
149 | a_string = NULL; |
a58509ee |
150 | lttv_option_add("string", 's', |
151 | "filters a string issued by the user on the command line", |
152 | "string", |
91ad3f0a |
153 | LTTV_OPT_STRING, &a_string, filter_analyze_string, NULL); |
1a7fa682 |
154 | // add function to call for option |
155 | |
a58509ee |
156 | a_file_name = NULL; |
157 | lttv_option_add("filename", 'f', |
158 | "browse the filter options contained in specified file", |
159 | "file name", |
91ad3f0a |
160 | LTTV_OPT_STRING, &a_file_name, filter_analyze_file, NULL); |
a58509ee |
161 | |
162 | /* |
163 | * Note to myself ! |
164 | * LttvAttributeValue::v_pointer is a gpointer* --> void** |
165 | * see union LttvAttributeValue for more info |
166 | */ |
167 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event", |
168 | LTTV_POINTER, &value)); |
169 | g_assert((event_hook = *(value.v_pointer)) != NULL); |
170 | lttv_hooks_add(event_hook, filter_event_content, NULL, LTTV_PRIO_DEFAULT); |
171 | |
91ad3f0a |
172 | // g_assert(lttv_iattribute_find_by_path(attributes,"hooks/trace/before", |
173 | // LTTV_POINTER, &value)); |
174 | // g_assert((before_traceset = *(value.v_pointer)) != NULL); |
175 | // lttv_hooks_add(before_traceset, parse_filter_options, NULL, LTTV_PRIO_DEFAULT); |
a58509ee |
176 | |
177 | |
178 | } |
179 | |
180 | /** |
181 | * Destroy the current module |
182 | */ |
183 | static void destroy() { |
184 | g_info("Destroy textFilter"); |
185 | |
186 | lttv_option_remove("string"); |
187 | |
188 | lttv_option_remove("filename"); |
189 | |
190 | lttv_hooks_remove_data(event_hook, filter_event_content, NULL); |
191 | |
91ad3f0a |
192 | // lttv_hooks_remove_data(before_traceset, parse_filter_options, NULL); |
a58509ee |
193 | |
194 | } |
195 | |
196 | |
197 | LTTV_MODULE("textFilter", "Filters traces", \ |
198 | "Filter the trace following commands issued by user input", \ |
91ad3f0a |
199 | init, destroy, "batchAnalysis", "option") |
a58509ee |
200 | |