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