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