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