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