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