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