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