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