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