1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
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;
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.
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,
19 /* This module inserts a hook in the program main loop. This hook processes
20 all the events in the main tracefile. */
28 #include <lttv/lttv.h>
29 #include <lttv/attribute.h>
30 #include <lttv/hook.h>
31 #include <lttv/option.h>
32 #include <lttv/module.h>
33 #include <lttv/traceset-process.h>
34 #include <lttv/state.h>
36 #include <lttv/stats.h>
37 #include <lttv/filter.h>
39 #include <ltt/trace.h>
40 #ifdef BABEL_CLEANUP_SYNC
41 #include <lttv/sync/sync_chain_lttv.h>
43 #include <babeltrace/context.h>
45 static LttvTraceset
*traceset
;
57 static char *trace_path
;
59 static gboolean a_stats
;
60 static gboolean a_live
;
61 static int a_live_update_period
;
63 #define DEFAULT_LIVE_UPDATE_PERIOD 1
65 void lttv_trace_option(void *hook_data
)
68 //trace_collection *trace;
69 //format *fmt = bt_lookup_format(g_quark_from_static_string("ctf"));
72 //trace = ltt_trace_open_live(a_trace);
75 //trace = bt_add_trace(a_trace,"ctf");
77 if(trace == NULL) g_critical("cannot open trace %s", a_trace);
78 lttv_traceset_add(traceset, lttv_trace_new(trace));*/
80 if(lttv_traceset_add_path(traceset
, trace_path
) < 0) {
81 printf("Cannot add trace %s", trace_path
);
86 static gboolean
process_traceset(void *hook_data
, void *call_data
)
88 LttvAttributeValue value_expression
, value_filter
;
90 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
93 LttvTracesetStats
*tscs
= NULL
;
95 LttvTracesetState
*tss
;
97 LttvTracesetContext
*tc
;
102 g_info("BatchAnalysis begin process traceset");
105 tscs
= g_object_new(LTTV_TRACESET_STATS_TYPE
, NULL
);
108 tss
= g_object_new(LTTV_TRACESET_STATE_TYPE
, NULL
);
112 g_info("BatchAnalysis initialize context");
114 lttv_context_init(tc
, traceset
);
119 lttv_state_add_event_hooks(tss
);
120 if(a_stats
) lttv_stats_add_event_hooks(tscs
);
123 retval
= lttv_iattribute_find_by_path(attributes
, "filter/expression",
124 LTTV_POINTER
, &value_expression
);
127 retval
= lttv_iattribute_find_by_path(attributes
, "filter/lttv_filter",
128 LTTV_POINTER
, &value_filter
);
131 /* Repeat the search for the first element, the second search might have
132 * moved the first element (by creating the second element)
134 retval
= lttv_iattribute_find_by_path(attributes
, "filter/expression",
135 LTTV_POINTER
, &value_expression
);
138 *(value_filter
.v_pointer
) = lttv_filter_new();
139 //g_debug("Filter string: %s",((GString*)*(value_expression.v_pointer))->str);
141 lttv_filter_append_expression(*(value_filter
.v_pointer
),((GString
*)*(value_expression
.v_pointer
))->str
);
143 //lttv_traceset_context_add_hooks(tc,
144 //before_traceset, after_traceset, NULL, before_trace, after_trace,
145 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
147 lttv_state_add_event_hooks(traceset
);
148 lttv_process_traceset_begin(traceset
,
155 end
.tv_sec
= G_MAXULONG
;
156 end
.tv_nsec
= G_MAXULONG
;
158 g_info("BatchAnalysis process traceset");
160 lttv_process_traceset_seek_time(traceset
, start
);
161 /* Read as long a we do not reach the end (0) */
163 unsigned int updated_count
;
165 count
= lttv_process_traceset_middle(traceset
,
171 updated_count
= lttv_process_traceset_update(tc
);
174 sleep(a_live_update_period
);
182 //lttv_traceset_context_remove_hooks(tc,
183 //before_traceset, after_traceset, NULL, before_trace, after_trace,
184 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
185 lttv_process_traceset_end(traceset
,
190 g_info("BatchAnalysis destroy context");
192 lttv_filter_destroy(*(value_filter
.v_pointer
));
194 lttv_state_remove_event_hooks(tss
);
195 if(a_stats
) lttv_stats_remove_event_hooks(tscs
);
197 lttv_context_fini(tc
);
199 g_object_unref(tscs
);
203 g_info("BatchAnalysis end process traceset");
210 LttvAttributeValue value
;
212 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
215 g_info("Init batchAnalysis.c");
217 lttv_option_add("trace", 't',
218 "add a trace to the trace set to analyse",
219 "pathname of the directory containing the trace",
220 LTTV_OPT_STRING
, &trace_path
, lttv_trace_option
, NULL
);
223 lttv_option_add("stats", 's',
224 "write the traceset and trace statistics",
226 LTTV_OPT_NONE
, &a_stats
, NULL
, NULL
);
229 lttv_option_add("live", 0,
230 "define if the traceset is receiving live informations",
232 LTTV_OPT_NONE
, &a_live
, NULL
, NULL
);
234 a_live_update_period
= DEFAULT_LIVE_UPDATE_PERIOD
;
235 lttv_option_add("live-period", 0,
236 "period to update a live trace",
239 &a_live_update_period
,
243 traceset
= lttv_traceset_new();
245 before_traceset
= lttv_hooks_new();
246 after_traceset
= lttv_hooks_new();
247 before_trace
= lttv_hooks_new();
248 after_trace
= lttv_hooks_new();
249 before_tracefile
= lttv_hooks_new();
250 after_tracefile
= lttv_hooks_new();
251 //before_event = lttv_hooks_new();
252 //after_event = lttv_hooks_new();
253 event_hook
= lttv_hooks_new();
255 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/traceset/before",
256 LTTV_POINTER
, &value
);
258 *(value
.v_pointer
) = before_traceset
;
259 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/traceset/after",
260 LTTV_POINTER
, &value
);
262 *(value
.v_pointer
) = after_traceset
;
263 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/trace/before",
264 LTTV_POINTER
, &value
);
266 *(value
.v_pointer
) = before_trace
;
267 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/trace/after",
268 LTTV_POINTER
, &value
);
270 *(value
.v_pointer
) = after_trace
;
271 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/before",
272 LTTV_POINTER
, &value
);
274 *(value
.v_pointer
) = before_tracefile
;
275 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/after",
276 LTTV_POINTER
, &value
);
278 *(value
.v_pointer
) = after_tracefile
;
279 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
280 // LTTV_POINTER, &value));
281 //*(value.v_pointer) = before_event;
282 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
283 // LTTV_POINTER, &value));
284 //*(value.v_pointer) = after_event;
285 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/event",
286 LTTV_POINTER
, &value
);
288 *(value
.v_pointer
) = event_hook
;
290 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
291 LTTV_POINTER
, &value
);
293 g_assert((main_hooks
= *(value
.v_pointer
)) != NULL
);
294 lttv_hooks_add(main_hooks
, process_traceset
, NULL
, LTTV_PRIO_DEFAULT
);
297 static void destroy()
305 g_info("Destroy batchAnalysis.c");
307 lttv_option_remove("trace");
308 lttv_option_remove("stats");
309 lttv_option_remove("live");
310 lttv_option_remove("live-period");
312 lttv_hooks_destroy(before_traceset
);
313 lttv_hooks_destroy(after_traceset
);
314 lttv_hooks_destroy(before_trace
);
315 lttv_hooks_destroy(after_trace
);
316 lttv_hooks_destroy(before_tracefile
);
317 lttv_hooks_destroy(after_tracefile
);
318 //lttv_hooks_destroy(before_event);
319 //lttv_hooks_destroy(after_event);
320 lttv_hooks_destroy(event_hook
);
321 lttv_hooks_remove_data(main_hooks
, process_traceset
, NULL
);
324 nb
= lttv_traceset_number(traceset
);
325 for(i
= 0 ; i
< nb
; i
++) {
326 trace
= lttv_traceset_get(traceset
, i
);
327 ltt_trace_close(lttv_trace(trace
));
328 lttv_trace_destroy(trace
);
331 lttv_traceset_destroy(traceset
);
334 LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \
335 "Run through a trace calling all the registered hooks", \
336 init
, destroy
, "state", "option")
337 //TODO ybrosseau 2012-05-15 reenable textFilter, stats, sync