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