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, |
42 | *before_event, |
43 | *after_event, |
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 | { |
b445142a |
62 | LttvTracesetStats *tscs; |
63 | |
64 | LttvTracesetContext *tc; |
48f6f3c2 |
65 | |
dc877563 |
66 | LttTime start, end; |
48f6f3c2 |
67 | |
b445142a |
68 | g_info("BatchAnalysis begin process traceset"); |
69 | |
70 | tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); |
71 | tc = &tscs->parent.parent; |
72 | |
73 | g_info("BatchAnalysis initialize context"); |
48f6f3c2 |
74 | |
b445142a |
75 | lttv_context_init(tc, traceset); |
76 | lttv_state_add_event_hooks(&tscs->parent); |
77 | if(a_stats) lttv_stats_add_event_hooks(tscs); |
78 | |
79 | lttv_traceset_context_add_hooks(tc, |
ffd54a90 |
80 | before_traceset, after_traceset, NULL, before_trace, after_trace, |
81 | NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); |
48f6f3c2 |
82 | |
dc877563 |
83 | start.tv_sec = 0; |
84 | start.tv_nsec = 0; |
85 | end.tv_sec = G_MAXULONG; |
86 | end.tv_nsec = G_MAXULONG; |
48f6f3c2 |
87 | |
b445142a |
88 | g_info("BatchAnalysis process traceset"); |
89 | |
308711e5 |
90 | lttv_process_traceset_seek_time(tc, start); |
91 | lttv_process_traceset(tc, end, G_MAXULONG); |
b445142a |
92 | |
93 | g_info("BatchAnalysis destroy context"); |
94 | |
95 | lttv_traceset_context_remove_hooks(tc, |
ffd54a90 |
96 | before_traceset, after_traceset, NULL, before_trace, after_trace, |
97 | NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); |
b445142a |
98 | lttv_state_remove_event_hooks(&tscs->parent); |
99 | if(a_stats) lttv_stats_remove_event_hooks(tscs); |
100 | lttv_context_fini(tc); |
101 | g_object_unref(tscs); |
48f6f3c2 |
102 | |
b445142a |
103 | g_info("BatchAnalysis end process traceset"); |
48f6f3c2 |
104 | } |
105 | |
106 | |
08b1c66e |
107 | static void init() |
48f6f3c2 |
108 | { |
ffd54a90 |
109 | LttvAttributeValue value; |
dc877563 |
110 | |
ffd54a90 |
111 | LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); |
dc877563 |
112 | |
b445142a |
113 | g_info("Init batchAnalysis.c"); |
114 | |
dc877563 |
115 | lttv_option_add("trace", 't', |
116 | "add a trace to the trace set to analyse", |
117 | "pathname of the directory containing the trace", |
ffd54a90 |
118 | LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); |
dc877563 |
119 | |
b445142a |
120 | a_stats = FALSE; |
121 | lttv_option_add("stats", 's', |
122 | "write the traceset and trace statistics", |
123 | "", |
124 | LTTV_OPT_NONE, &a_stats, NULL, NULL); |
125 | |
126 | |
dc877563 |
127 | traceset = lttv_traceset_new(); |
128 | |
129 | before_traceset = lttv_hooks_new(); |
130 | after_traceset = lttv_hooks_new(); |
131 | before_trace = lttv_hooks_new(); |
132 | after_trace = lttv_hooks_new(); |
133 | before_tracefile = lttv_hooks_new(); |
134 | after_tracefile = lttv_hooks_new(); |
135 | before_event = lttv_hooks_new(); |
136 | after_event = lttv_hooks_new(); |
137 | |
138 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before", |
139 | LTTV_POINTER, &value)); |
ffd54a90 |
140 | *(value.v_pointer) = before_traceset; |
dc877563 |
141 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after", |
142 | LTTV_POINTER, &value)); |
ffd54a90 |
143 | *(value.v_pointer) = after_traceset; |
dc877563 |
144 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before", |
145 | LTTV_POINTER, &value)); |
ffd54a90 |
146 | *(value.v_pointer) = before_trace; |
dc877563 |
147 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after", |
148 | LTTV_POINTER, &value)); |
ffd54a90 |
149 | *(value.v_pointer) = after_trace; |
dc877563 |
150 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before", |
151 | LTTV_POINTER, &value)); |
ffd54a90 |
152 | *(value.v_pointer) = before_tracefile; |
dc877563 |
153 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after", |
154 | LTTV_POINTER, &value)); |
ffd54a90 |
155 | *(value.v_pointer) = after_tracefile; |
dc877563 |
156 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before", |
157 | LTTV_POINTER, &value)); |
ffd54a90 |
158 | *(value.v_pointer) = before_event; |
dc877563 |
159 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after", |
160 | LTTV_POINTER, &value)); |
ffd54a90 |
161 | *(value.v_pointer) = after_event; |
dc877563 |
162 | |
163 | g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before", |
164 | LTTV_POINTER, &value)); |
ffd54a90 |
165 | g_assert((main_hooks = *(value.v_pointer)) != NULL); |
dc877563 |
166 | lttv_hooks_add(main_hooks, process_traceset, NULL); |
48f6f3c2 |
167 | } |
168 | |
169 | |
08b1c66e |
170 | static void destroy() |
48f6f3c2 |
171 | { |
dc877563 |
172 | guint i, nb; |
48f6f3c2 |
173 | |
308711e5 |
174 | LttvTrace *trace; |
175 | |
b445142a |
176 | g_info("Destroy batchAnalysis.c"); |
177 | |
dc877563 |
178 | lttv_option_remove("trace"); |
b445142a |
179 | lttv_option_remove("stats"); |
48f6f3c2 |
180 | |
dc877563 |
181 | lttv_hooks_destroy(before_traceset); |
182 | lttv_hooks_destroy(after_traceset); |
183 | lttv_hooks_destroy(before_trace); |
184 | lttv_hooks_destroy(after_trace); |
185 | lttv_hooks_destroy(before_tracefile); |
186 | lttv_hooks_destroy(after_tracefile); |
187 | lttv_hooks_destroy(before_event); |
188 | lttv_hooks_destroy(after_event); |
311e7f46 |
189 | lttv_hooks_remove_data(main_hooks, process_traceset, NULL); |
48f6f3c2 |
190 | |
dc877563 |
191 | nb = lttv_traceset_number(traceset); |
ffd54a90 |
192 | for(i = 0 ; i < nb ; i++) { |
308711e5 |
193 | trace = lttv_traceset_get(traceset, i); |
194 | ltt_trace_close(lttv_trace(trace)); |
195 | lttv_trace_destroy(trace); |
dc877563 |
196 | } |
c6bc9cb9 |
197 | |
198 | lttv_traceset_destroy(traceset); |
dc877563 |
199 | } |
48f6f3c2 |
200 | |
08b1c66e |
201 | |
202 | LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \ |
203 | "Run through a trace calling all the registered hooks", \ |
204 | init, destroy, "state", "stats", "option") |