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