core filter, lttvwindow, batchanalysis
[lttv.git] / ltt / branches / poly / lttv / modules / text / batchAnalysis.c
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
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>
26 #include <lttv/option.h>
27 #include <lttv/module.h>
28 #include <lttv/tracecontext.h>
29 #include <lttv/state.h>
30 #include <lttv/stats.h>
31 #include <lttv/filter.h>
32 #include <ltt/trace.h>
33
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,
43 *event_hook,
44 *main_hooks;
45
46 static char *a_trace;
47
48 static gboolean a_stats;
49
50 static LttvFilter *a_lttv_filter;
51
52 extern GString *a_filter_string;
53
54 void lttv_trace_option(void *hook_data)
55 {
56 LttTrace *trace;
57
58 trace = ltt_trace_open(a_trace);
59 if(trace == NULL) g_critical("cannot open trace %s", a_trace);
60 lttv_traceset_add(traceset, lttv_trace_new(trace));
61 }
62
63
64 static gboolean process_traceset(void *hook_data, void *call_data)
65 {
66 LttvTracesetStats *tscs;
67
68 LttvTracesetContext *tc;
69
70 LttTime start, end;
71
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");
78
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
83 a_lttv_filter = lttv_filter_new(a_filter_string,(LttvTraceState*)tscs);
84
85 //lttv_traceset_context_add_hooks(tc,
86 //before_traceset, after_traceset, NULL, before_trace, after_trace,
87 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
88 lttv_process_traceset_begin(tc,
89 before_traceset,
90 before_trace,
91 before_tracefile,
92 event_hook,
93 NULL);
94
95 start.tv_sec = 0;
96 start.tv_nsec = 0;
97 end.tv_sec = G_MAXULONG;
98 end.tv_nsec = G_MAXULONG;
99
100 g_info("BatchAnalysis process traceset");
101
102 lttv_process_traceset_seek_time(tc, start);
103 lttv_process_traceset_middle(tc,
104 end,
105 G_MAXULONG,
106 NULL);
107
108 g_info("BatchAnalysis destroy context");
109
110 //lttv_traceset_context_remove_hooks(tc,
111 //before_traceset, after_traceset, NULL, before_trace, after_trace,
112 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
113 lttv_process_traceset_end(tc,
114 after_traceset,
115 after_trace,
116 after_tracefile,
117 event_hook,
118 NULL);
119
120 lttv_filter_destroy(a_lttv_filter);
121 lttv_state_remove_event_hooks(&tscs->parent);
122 if(a_stats) lttv_stats_remove_event_hooks(tscs);
123 lttv_context_fini(tc);
124 g_object_unref(tscs);
125
126 g_info("BatchAnalysis end process traceset");
127 return FALSE;
128 }
129
130
131 static void init()
132 {
133 LttvAttributeValue value;
134
135 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
136
137 g_info("Init batchAnalysis.c");
138
139 lttv_option_add("trace", 't',
140 "add a trace to the trace set to analyse",
141 "pathname of the directory containing the trace",
142 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
143
144 a_stats = FALSE;
145 lttv_option_add("stats", 's',
146 "write the traceset and trace statistics",
147 "",
148 LTTV_OPT_NONE, &a_stats, NULL, NULL);
149
150
151 traceset = lttv_traceset_new();
152
153 before_traceset = lttv_hooks_new();
154 after_traceset = lttv_hooks_new();
155 before_trace = lttv_hooks_new();
156 after_trace = lttv_hooks_new();
157 before_tracefile = lttv_hooks_new();
158 after_tracefile = lttv_hooks_new();
159 //before_event = lttv_hooks_new();
160 //after_event = lttv_hooks_new();
161 event_hook = lttv_hooks_new();
162
163 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
164 LTTV_POINTER, &value));
165 *(value.v_pointer) = before_traceset;
166 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
167 LTTV_POINTER, &value));
168 *(value.v_pointer) = after_traceset;
169 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
170 LTTV_POINTER, &value));
171 *(value.v_pointer) = before_trace;
172 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
173 LTTV_POINTER, &value));
174 *(value.v_pointer) = after_trace;
175 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
176 LTTV_POINTER, &value));
177 *(value.v_pointer) = before_tracefile;
178 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
179 LTTV_POINTER, &value));
180 *(value.v_pointer) = after_tracefile;
181 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
182 // LTTV_POINTER, &value));
183 //*(value.v_pointer) = before_event;
184 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
185 // LTTV_POINTER, &value));
186 //*(value.v_pointer) = after_event;
187 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event",
188 LTTV_POINTER, &value));
189 *(value.v_pointer) = event_hook;
190
191 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
192 LTTV_POINTER, &value));
193 g_assert((main_hooks = *(value.v_pointer)) != NULL);
194 lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT);
195 }
196
197
198 static void destroy()
199 {
200 guint i, nb;
201
202 LttvTrace *trace;
203
204 g_info("Destroy batchAnalysis.c");
205
206 lttv_option_remove("trace");
207 lttv_option_remove("stats");
208
209 lttv_hooks_destroy(before_traceset);
210 lttv_hooks_destroy(after_traceset);
211 lttv_hooks_destroy(before_trace);
212 lttv_hooks_destroy(after_trace);
213 lttv_hooks_destroy(before_tracefile);
214 lttv_hooks_destroy(after_tracefile);
215 //lttv_hooks_destroy(before_event);
216 //lttv_hooks_destroy(after_event);
217 lttv_hooks_destroy(event_hook);
218 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
219
220 nb = lttv_traceset_number(traceset);
221 for(i = 0 ; i < nb ; i++) {
222 trace = lttv_traceset_get(traceset, i);
223 ltt_trace_close(lttv_trace(trace));
224 /* This will be done by lttv_traceset_destroy */
225 //lttv_trace_destroy(trace);
226 }
227
228 lttv_traceset_destroy(traceset);
229 }
230
231
232 LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \
233 "Run through a trace calling all the registered hooks", \
234 init, destroy, "state", "stats", "option","filter")
This page took 0.034253 seconds and 4 git commands to generate.