Disable sync/ completely, build OK
[lttv.git] / lttv / modules / text / batchAnalysis.c
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
19 /* This module inserts a hook in the program main loop. This hook processes
20 all the events in the main tracefile. */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <glib.h>
27 #include <lttv/lttv.h>
28 #include <lttv/attribute.h>
29 #include <lttv/hook.h>
30 #include <lttv/option.h>
31 #include <lttv/module.h>
32 #include <lttv/tracecontext.h>
33 #include <lttv/state.h>
34 #include <lttv/stats.h>
35 #include <lttv/filter.h>
36 #include <ltt/trace.h>
37 #include <lttv/sync/sync_chain_lttv.h>
38
39 static LttvTraceset *traceset;
40
41 static LttvHooks
42 *before_traceset,
43 *after_traceset,
44 *before_trace,
45 *after_trace,
46 *before_tracefile,
47 *after_tracefile,
48 *event_hook,
49 *main_hooks;
50
51 static char *a_trace;
52
53 static gboolean a_stats;
54
55 void lttv_trace_option(void *hook_data)
56 {
57 LttTrace *trace;
58
59 trace = ltt_trace_open(a_trace);
60 if(trace == NULL) g_critical("cannot open trace %s", a_trace);
61 lttv_traceset_add(traceset, lttv_trace_new(trace));
62 }
63
64
65 static gboolean process_traceset(void *hook_data, void *call_data)
66 {
67 LttvAttributeValue value_expression, value_filter;
68
69 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
70
71 LttvTracesetStats *tscs;
72
73 LttvTracesetState *tss;
74
75 LttvTracesetContext *tc;
76
77 LttTime start, end;
78 gboolean retval;
79
80 g_info("BatchAnalysis begin process traceset");
81
82 if (a_stats) {
83 tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
84 tss = &tscs->parent;
85 } else {
86 tss = g_object_new(LTTV_TRACESET_STATE_TYPE, NULL);
87 }
88 tc = &tss->parent;
89
90 g_info("BatchAnalysis initialize context");
91
92 lttv_context_init(tc, traceset);
93
94 /* Disabled by Mathieu, does not build on x86_64 */
95 /* syncTraceset(tc); */
96
97 lttv_state_add_event_hooks(tc);
98 if(a_stats) lttv_stats_add_event_hooks(tscs);
99
100 retval= lttv_iattribute_find_by_path(attributes, "filter/expression",
101 LTTV_POINTER, &value_expression);
102 g_assert(retval);
103
104 retval= lttv_iattribute_find_by_path(attributes, "filter/lttv_filter",
105 LTTV_POINTER, &value_filter);
106 g_assert(retval);
107
108 /* Repeat the search for the first element, the second search might have
109 * moved the first element (by creating the second element)
110 */
111 retval= lttv_iattribute_find_by_path(attributes, "filter/expression",
112 LTTV_POINTER, &value_expression);
113 g_assert(retval);
114
115 *(value_filter.v_pointer) = lttv_filter_new();
116 //g_debug("Filter string: %s",((GString*)*(value_expression.v_pointer))->str);
117
118 lttv_filter_append_expression(*(value_filter.v_pointer),((GString*)*(value_expression.v_pointer))->str);
119
120 //lttv_traceset_context_add_hooks(tc,
121 //before_traceset, after_traceset, NULL, before_trace, after_trace,
122 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
123 lttv_process_traceset_begin(tc,
124 before_traceset,
125 before_trace,
126 before_tracefile,
127 event_hook,
128 NULL);
129
130 start.tv_sec = 0;
131 start.tv_nsec = 0;
132 end.tv_sec = G_MAXULONG;
133 end.tv_nsec = G_MAXULONG;
134
135 g_info("BatchAnalysis process traceset");
136
137 lttv_process_traceset_seek_time(tc, start);
138 lttv_process_traceset_middle(tc,
139 end,
140 G_MAXULONG,
141 NULL);
142
143
144 //lttv_traceset_context_remove_hooks(tc,
145 //before_traceset, after_traceset, NULL, before_trace, after_trace,
146 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
147 lttv_process_traceset_end(tc,
148 after_traceset,
149 after_trace,
150 after_tracefile,
151 event_hook,
152 NULL);
153
154 g_info("BatchAnalysis destroy context");
155
156 lttv_filter_destroy(*(value_filter.v_pointer));
157 lttv_state_remove_event_hooks(tss);
158 if(a_stats) lttv_stats_remove_event_hooks(tscs);
159 lttv_context_fini(tc);
160 if (a_stats)
161 g_object_unref(tscs);
162 else
163 g_object_unref(tss);
164
165 g_info("BatchAnalysis end process traceset");
166 return FALSE;
167 }
168
169
170 static void init()
171 {
172 LttvAttributeValue value;
173
174 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
175 gboolean retval;
176
177 g_info("Init batchAnalysis.c");
178
179 lttv_option_add("trace", 't',
180 "add a trace to the trace set to analyse",
181 "pathname of the directory containing the trace",
182 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
183
184 a_stats = FALSE;
185 lttv_option_add("stats", 's',
186 "write the traceset and trace statistics",
187 "",
188 LTTV_OPT_NONE, &a_stats, NULL, NULL);
189
190
191 traceset = lttv_traceset_new();
192
193 before_traceset = lttv_hooks_new();
194 after_traceset = lttv_hooks_new();
195 before_trace = lttv_hooks_new();
196 after_trace = lttv_hooks_new();
197 before_tracefile = lttv_hooks_new();
198 after_tracefile = lttv_hooks_new();
199 //before_event = lttv_hooks_new();
200 //after_event = lttv_hooks_new();
201 event_hook = lttv_hooks_new();
202
203 retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
204 LTTV_POINTER, &value);
205 g_assert(retval);
206 *(value.v_pointer) = before_traceset;
207 retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
208 LTTV_POINTER, &value);
209 g_assert(retval);
210 *(value.v_pointer) = after_traceset;
211 retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
212 LTTV_POINTER, &value);
213 g_assert(retval);
214 *(value.v_pointer) = before_trace;
215 retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
216 LTTV_POINTER, &value);
217 g_assert(retval);
218 *(value.v_pointer) = after_trace;
219 retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
220 LTTV_POINTER, &value);
221 g_assert(retval);
222 *(value.v_pointer) = before_tracefile;
223 retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
224 LTTV_POINTER, &value);
225 g_assert(retval);
226 *(value.v_pointer) = after_tracefile;
227 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
228 // LTTV_POINTER, &value));
229 //*(value.v_pointer) = before_event;
230 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
231 // LTTV_POINTER, &value));
232 //*(value.v_pointer) = after_event;
233 retval= lttv_iattribute_find_by_path(attributes, "hooks/event",
234 LTTV_POINTER, &value);
235 g_assert(retval);
236 *(value.v_pointer) = event_hook;
237
238 retval= lttv_iattribute_find_by_path(attributes, "hooks/main/before",
239 LTTV_POINTER, &value);
240 g_assert(retval);
241 g_assert((main_hooks = *(value.v_pointer)) != NULL);
242 lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT);
243 }
244
245 static void destroy()
246 {
247 guint i, nb;
248
249 LttvTrace *trace;
250
251 g_info("Destroy batchAnalysis.c");
252
253 lttv_option_remove("trace");
254 lttv_option_remove("stats");
255
256 lttv_hooks_destroy(before_traceset);
257 lttv_hooks_destroy(after_traceset);
258 lttv_hooks_destroy(before_trace);
259 lttv_hooks_destroy(after_trace);
260 lttv_hooks_destroy(before_tracefile);
261 lttv_hooks_destroy(after_tracefile);
262 //lttv_hooks_destroy(before_event);
263 //lttv_hooks_destroy(after_event);
264 lttv_hooks_destroy(event_hook);
265 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
266
267 nb = lttv_traceset_number(traceset);
268 for(i = 0 ; i < nb ; i++) {
269 trace = lttv_traceset_get(traceset, i);
270 ltt_trace_close(lttv_trace(trace));
271 /* This will be done by lttv_traceset_destroy */
272 //lttv_trace_destroy(trace);
273 }
274
275 lttv_traceset_destroy(traceset);
276 }
277
278 LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \
279 "Run through a trace calling all the registered hooks", \
280 /* init, destroy, "state", "stats", "option","textFilter", "sync") */
281 init, destroy, "state", "stats", "option","textFilter")
This page took 0.034875 seconds and 4 git commands to generate.