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