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