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