Fix tar.gz build by removing legacy include to ltt directory
[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>
3667f07d 27#include <unistd.h>
48f6f3c2 28#include <lttv/lttv.h>
29#include <lttv/attribute.h>
30#include <lttv/hook.h>
ffd54a90 31#include <lttv/option.h>
996acd92 32#include <lttv/module.h>
7a4bdb54 33#include <lttv/traceset-process.h>
dc877563 34#include <lttv/state.h>
7a4bdb54 35#ifdef BABEL_CLEANUP
b445142a 36#include <lttv/stats.h>
1da1525d 37#include <lttv/filter.h>
7a4bdb54 38#endif
7a4bdb54 39#ifdef BABEL_CLEANUP_SYNC
2f076594 40#include <lttv/sync/sync_chain_lttv.h>
7a4bdb54 41#endif
922581a4
YB
42#include <babeltrace/context.h>
43
dc877563 44static LttvTraceset *traceset;
45
46static LttvHooks
47 *before_traceset,
48 *after_traceset,
49 *before_trace,
50 *after_trace,
51 *before_tracefile,
52 *after_tracefile,
12c59c3d 53 *event_hook,
dc877563 54 *main_hooks;
55
2bc1bcfb 56static char *trace_path;
dc877563 57
b445142a 58static gboolean a_stats;
3667f07d
YB
59static gboolean a_live;
60static int a_live_update_period;
61
62#define DEFAULT_LIVE_UPDATE_PERIOD 1
dc877563 63
64void lttv_trace_option(void *hook_data)
65{
922581a4
YB
66 //LttTrace *trace;
67 //trace_collection *trace;
68 //format *fmt = bt_lookup_format(g_quark_from_static_string("ctf"));
69 /*
3667f07d 70 if(a_live) {
922581a4 71 //trace = ltt_trace_open_live(a_trace);
3667f07d 72 } else {
922581a4
YB
73 bt_create_context();
74 //trace = bt_add_trace(a_trace,"ctf");
3667f07d 75 }
dc877563 76 if(trace == NULL) g_critical("cannot open trace %s", a_trace);
922581a4 77 lttv_traceset_add(traceset, lttv_trace_new(trace));*/
2bc1bcfb 78
79 if(lttv_traceset_add_path(traceset, trace_path) < 0) {
3685e022 80 g_error("Cannot add trace %s", trace_path);
2bc1bcfb 81 }
dc877563 82}
83
84
ffd54a90 85static gboolean process_traceset(void *hook_data, void *call_data)
48f6f3c2 86{
8bf54995 87 LttvAttributeValue value_expression, value_filter;
73050a5f 88
89 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
90
7a4bdb54 91#ifdef BABEL_CLEANUP
c7cb53d7 92 LttvTracesetStats *tscs = NULL;
b445142a 93
b221eaef 94 LttvTracesetState *tss;
95
b445142a 96 LttvTracesetContext *tc;
7a4bdb54 97#endif
dc877563 98 LttTime start, end;
8f318283 99 gboolean retval;
48f6f3c2 100
b445142a 101 g_info("BatchAnalysis begin process traceset");
7a4bdb54 102#ifdef BABEL_CLEANUP
b221eaef 103 if (a_stats) {
104 tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
105 tss = &tscs->parent;
106 } else {
107 tss = g_object_new(LTTV_TRACESET_STATE_TYPE, NULL);
108 }
109 tc = &tss->parent;
b445142a 110
111 g_info("BatchAnalysis initialize context");
48f6f3c2 112
b445142a 113 lttv_context_init(tc, traceset);
800dfee0 114
7a4bdb54 115
665fdbb7 116 syncTraceset(tc);
800dfee0 117
c7cb53d7 118 lttv_state_add_event_hooks(tss);
b445142a 119 if(a_stats) lttv_stats_add_event_hooks(tscs);
7a4bdb54 120
b445142a 121
8f318283
BP
122 retval= lttv_iattribute_find_by_path(attributes, "filter/expression",
123 LTTV_POINTER, &value_expression);
124 g_assert(retval);
8bf54995 125
8f318283
BP
126 retval= lttv_iattribute_find_by_path(attributes, "filter/lttv_filter",
127 LTTV_POINTER, &value_filter);
128 g_assert(retval);
73050a5f 129
b399ad0e
BP
130 /* Repeat the search for the first element, the second search might have
131 * moved the first element (by creating the second element)
132 */
133 retval= lttv_iattribute_find_by_path(attributes, "filter/expression",
134 LTTV_POINTER, &value_expression);
135 g_assert(retval);
136
8bf54995 137 *(value_filter.v_pointer) = lttv_filter_new();
32aa92c2 138 //g_debug("Filter string: %s",((GString*)*(value_expression.v_pointer))->str);
4ec0c904 139
0bc23ba9 140 lttv_filter_append_expression(*(value_filter.v_pointer),((GString*)*(value_expression.v_pointer))->str);
7a4bdb54 141#endif
12c59c3d 142 //lttv_traceset_context_add_hooks(tc,
143 //before_traceset, after_traceset, NULL, before_trace, after_trace,
144 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
7a4bdb54
YB
145
146 lttv_state_add_event_hooks(traceset);
147 lttv_process_traceset_begin(traceset,
12c59c3d 148 before_traceset,
149 before_trace,
7a4bdb54 150 event_hook);
48f6f3c2 151
dc877563 152 start.tv_sec = 0;
153 start.tv_nsec = 0;
154 end.tv_sec = G_MAXULONG;
155 end.tv_nsec = G_MAXULONG;
48f6f3c2 156
b445142a 157 g_info("BatchAnalysis process traceset");
922581a4 158
7a4bdb54 159 lttv_process_traceset_seek_time(traceset, start);
3667f07d
YB
160 /* Read as long a we do not reach the end (0) */
161 unsigned int count;
162 unsigned int updated_count;
163 do {
7a4bdb54 164 count = lttv_process_traceset_middle(traceset,
3667f07d
YB
165 end,
166 G_MAXULONG,
167 NULL);
168
2bc1bcfb 169#ifdef BABEL_CLEANUP
170 updated_count = lttv_process_traceset_update(tc);
171#endif
3667f07d
YB
172
173 sleep(a_live_update_period);
2bc1bcfb 174 } while(count != 0
175#ifdef BABEL_CLEANUP
176 || updated_count > 0
177#endif
178 );
b445142a 179
b445142a 180
12c59c3d 181 //lttv_traceset_context_remove_hooks(tc,
182 //before_traceset, after_traceset, NULL, before_trace, after_trace,
183 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
7a4bdb54 184 lttv_process_traceset_end(traceset,
12c59c3d 185 after_traceset,
186 after_trace,
7a4bdb54 187 event_hook);
12c59c3d 188
d730b5c8 189 g_info("BatchAnalysis destroy context");
2bc1bcfb 190#ifdef BABEL_CLEANUP
7a4bdb54
YB
191 lttv_filter_destroy(*(value_filter.v_pointer));
192
b221eaef 193 lttv_state_remove_event_hooks(tss);
b445142a 194 if(a_stats) lttv_stats_remove_event_hooks(tscs);
7a4bdb54 195
b445142a 196 lttv_context_fini(tc);
b221eaef 197 if (a_stats)
198 g_object_unref(tscs);
199 else
200 g_object_unref(tss);
7a4bdb54 201#endif
b445142a 202 g_info("BatchAnalysis end process traceset");
ba6f11f1 203 return FALSE;
48f6f3c2 204}
205
206
08b1c66e 207static void init()
48f6f3c2 208{
ffd54a90 209 LttvAttributeValue value;
dc877563 210
ffd54a90 211 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
8f318283 212 gboolean retval;
dc877563 213
b445142a 214 g_info("Init batchAnalysis.c");
215
dc877563 216 lttv_option_add("trace", 't',
217 "add a trace to the trace set to analyse",
218 "pathname of the directory containing the trace",
2bc1bcfb 219 LTTV_OPT_STRING, &trace_path, lttv_trace_option, NULL);
dc877563 220
b445142a 221 a_stats = FALSE;
222 lttv_option_add("stats", 's',
223 "write the traceset and trace statistics",
224 "",
225 LTTV_OPT_NONE, &a_stats, NULL, NULL);
226
3667f07d
YB
227 a_live = FALSE;
228 lttv_option_add("live", 0,
229 "define if the traceset is receiving live informations",
230 "",
231 LTTV_OPT_NONE, &a_live, NULL, NULL);
232
233 a_live_update_period = DEFAULT_LIVE_UPDATE_PERIOD;
234 lttv_option_add("live-period", 0,
235 "period to update a live trace",
236 "in seconds",
237 LTTV_OPT_INT,
238 &a_live_update_period,
239 NULL, NULL);
240
b445142a 241
dc877563 242 traceset = lttv_traceset_new();
243
244 before_traceset = lttv_hooks_new();
245 after_traceset = lttv_hooks_new();
246 before_trace = lttv_hooks_new();
247 after_trace = lttv_hooks_new();
248 before_tracefile = lttv_hooks_new();
249 after_tracefile = lttv_hooks_new();
12c59c3d 250 //before_event = lttv_hooks_new();
251 //after_event = lttv_hooks_new();
252 event_hook = lttv_hooks_new();
dc877563 253
8f318283
BP
254 retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
255 LTTV_POINTER, &value);
256 g_assert(retval);
ffd54a90 257 *(value.v_pointer) = before_traceset;
8f318283
BP
258 retval= lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
259 LTTV_POINTER, &value);
260 g_assert(retval);
ffd54a90 261 *(value.v_pointer) = after_traceset;
8f318283
BP
262 retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
263 LTTV_POINTER, &value);
264 g_assert(retval);
ffd54a90 265 *(value.v_pointer) = before_trace;
8f318283
BP
266 retval= lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
267 LTTV_POINTER, &value);
268 g_assert(retval);
ffd54a90 269 *(value.v_pointer) = after_trace;
8f318283
BP
270 retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
271 LTTV_POINTER, &value);
272 g_assert(retval);
ffd54a90 273 *(value.v_pointer) = before_tracefile;
8f318283
BP
274 retval= lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
275 LTTV_POINTER, &value);
276 g_assert(retval);
ffd54a90 277 *(value.v_pointer) = after_tracefile;
12c59c3d 278 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
279 // LTTV_POINTER, &value));
280 //*(value.v_pointer) = before_event;
281 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
282 // LTTV_POINTER, &value));
283 //*(value.v_pointer) = after_event;
8f318283
BP
284 retval= lttv_iattribute_find_by_path(attributes, "hooks/event",
285 LTTV_POINTER, &value);
286 g_assert(retval);
12c59c3d 287 *(value.v_pointer) = event_hook;
dc877563 288
8f318283
BP
289 retval= lttv_iattribute_find_by_path(attributes, "hooks/main/before",
290 LTTV_POINTER, &value);
291 g_assert(retval);
ffd54a90 292 g_assert((main_hooks = *(value.v_pointer)) != NULL);
12c59c3d 293 lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT);
48f6f3c2 294}
295
08b1c66e 296static void destroy()
48f6f3c2 297{
2bc1bcfb 298#ifdef BABEL_CLEANUP
dc877563 299 guint i, nb;
48f6f3c2 300
308711e5 301 LttvTrace *trace;
2bc1bcfb 302#endif
308711e5 303
b445142a 304 g_info("Destroy batchAnalysis.c");
305
dc877563 306 lttv_option_remove("trace");
b445142a 307 lttv_option_remove("stats");
3667f07d
YB
308 lttv_option_remove("live");
309 lttv_option_remove("live-period");
48f6f3c2 310
dc877563 311 lttv_hooks_destroy(before_traceset);
312 lttv_hooks_destroy(after_traceset);
313 lttv_hooks_destroy(before_trace);
314 lttv_hooks_destroy(after_trace);
315 lttv_hooks_destroy(before_tracefile);
316 lttv_hooks_destroy(after_tracefile);
12c59c3d 317 //lttv_hooks_destroy(before_event);
318 //lttv_hooks_destroy(after_event);
319 lttv_hooks_destroy(event_hook);
311e7f46 320 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
48f6f3c2 321
2bc1bcfb 322#ifdef BABEL_CLEANUP
dc877563 323 nb = lttv_traceset_number(traceset);
ffd54a90 324 for(i = 0 ; i < nb ; i++) {
308711e5 325 trace = lttv_traceset_get(traceset, i);
326 ltt_trace_close(lttv_trace(trace));
2bc1bcfb 327 lttv_trace_destroy(trace);
dc877563 328 }
2bc1bcfb 329#endif
c6bc9cb9 330 lttv_traceset_destroy(traceset);
dc877563 331}
48f6f3c2 332
08b1c66e 333LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \
334 "Run through a trace calling all the registered hooks", \
7a4bdb54
YB
335 init, destroy, "state", "option")
336//TODO ybrosseau 2012-05-15 reenable textFilter, stats, sync
This page took 0.086476 seconds and 4 git commands to generate.