UTF8 fix
[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
73050a5f 50LttvFilter *a_lttv_filter;
1da1525d 51
dc877563 52void lttv_trace_option(void *hook_data)
53{
54 LttTrace *trace;
55
56 trace = ltt_trace_open(a_trace);
57 if(trace == NULL) g_critical("cannot open trace %s", a_trace);
308711e5 58 lttv_traceset_add(traceset, lttv_trace_new(trace));
dc877563 59}
60
61
ffd54a90 62static gboolean process_traceset(void *hook_data, void *call_data)
48f6f3c2 63{
73050a5f 64 LttvAttributeValue value;
65
66 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
67
b445142a 68 LttvTracesetStats *tscs;
69
70 LttvTracesetContext *tc;
48f6f3c2 71
dc877563 72 LttTime start, end;
48f6f3c2 73
b445142a 74 g_info("BatchAnalysis begin process traceset");
75
76 tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL);
77 tc = &tscs->parent.parent;
78
79 g_info("BatchAnalysis initialize context");
48f6f3c2 80
b445142a 81 lttv_context_init(tc, traceset);
82 lttv_state_add_event_hooks(&tscs->parent);
83 if(a_stats) lttv_stats_add_event_hooks(tscs);
84
73050a5f 85 g_assert(lttv_iattribute_find_by_path(attributes, "filter/expression",
86 LTTV_POINTER, &value));
87
cec3d7b0 88 a_lttv_filter = lttv_filter_new();
73050a5f 89 g_debug("Filter string: %s",((GString*)*(value.v_pointer))->str);
da2e1bfb 90
56e29124 91 g_assert(lttv_filter_append_expression(a_lttv_filter,((GString*)*(value.v_pointer))->str));
1da1525d 92
12c59c3d 93 //lttv_traceset_context_add_hooks(tc,
94 //before_traceset, after_traceset, NULL, before_trace, after_trace,
95 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
96 lttv_process_traceset_begin(tc,
97 before_traceset,
98 before_trace,
99 before_tracefile,
100 event_hook,
101 NULL);
48f6f3c2 102
dc877563 103 start.tv_sec = 0;
104 start.tv_nsec = 0;
105 end.tv_sec = G_MAXULONG;
106 end.tv_nsec = G_MAXULONG;
48f6f3c2 107
b445142a 108 g_info("BatchAnalysis process traceset");
109
308711e5 110 lttv_process_traceset_seek_time(tc, start);
12c59c3d 111 lttv_process_traceset_middle(tc,
112 end,
113 G_MAXULONG,
114 NULL);
b445142a 115
116 g_info("BatchAnalysis destroy context");
117
12c59c3d 118 //lttv_traceset_context_remove_hooks(tc,
119 //before_traceset, after_traceset, NULL, before_trace, after_trace,
120 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
121 lttv_process_traceset_end(tc,
122 after_traceset,
123 after_trace,
124 after_tracefile,
125 event_hook,
126 NULL);
127
1da1525d 128 lttv_filter_destroy(a_lttv_filter);
b445142a 129 lttv_state_remove_event_hooks(&tscs->parent);
130 if(a_stats) lttv_stats_remove_event_hooks(tscs);
131 lttv_context_fini(tc);
132 g_object_unref(tscs);
48f6f3c2 133
b445142a 134 g_info("BatchAnalysis end process traceset");
ba6f11f1 135 return FALSE;
48f6f3c2 136}
137
138
08b1c66e 139static void init()
48f6f3c2 140{
ffd54a90 141 LttvAttributeValue value;
dc877563 142
ffd54a90 143 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
dc877563 144
b445142a 145 g_info("Init batchAnalysis.c");
146
dc877563 147 lttv_option_add("trace", 't',
148 "add a trace to the trace set to analyse",
149 "pathname of the directory containing the trace",
ffd54a90 150 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
dc877563 151
b445142a 152 a_stats = FALSE;
153 lttv_option_add("stats", 's',
154 "write the traceset and trace statistics",
155 "",
156 LTTV_OPT_NONE, &a_stats, NULL, NULL);
157
158
dc877563 159 traceset = lttv_traceset_new();
160
161 before_traceset = lttv_hooks_new();
162 after_traceset = lttv_hooks_new();
163 before_trace = lttv_hooks_new();
164 after_trace = lttv_hooks_new();
165 before_tracefile = lttv_hooks_new();
166 after_tracefile = lttv_hooks_new();
12c59c3d 167 //before_event = lttv_hooks_new();
168 //after_event = lttv_hooks_new();
169 event_hook = lttv_hooks_new();
dc877563 170
171 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/before",
172 LTTV_POINTER, &value));
ffd54a90 173 *(value.v_pointer) = before_traceset;
dc877563 174 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/traceset/after",
175 LTTV_POINTER, &value));
ffd54a90 176 *(value.v_pointer) = after_traceset;
dc877563 177 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/before",
178 LTTV_POINTER, &value));
ffd54a90 179 *(value.v_pointer) = before_trace;
dc877563 180 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/trace/after",
181 LTTV_POINTER, &value));
ffd54a90 182 *(value.v_pointer) = after_trace;
dc877563 183 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/before",
184 LTTV_POINTER, &value));
ffd54a90 185 *(value.v_pointer) = before_tracefile;
dc877563 186 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/tracefile/after",
187 LTTV_POINTER, &value));
ffd54a90 188 *(value.v_pointer) = after_tracefile;
12c59c3d 189 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
190 // LTTV_POINTER, &value));
191 //*(value.v_pointer) = before_event;
192 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
193 // LTTV_POINTER, &value));
194 //*(value.v_pointer) = after_event;
195 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event",
dc877563 196 LTTV_POINTER, &value));
12c59c3d 197 *(value.v_pointer) = event_hook;
dc877563 198
199 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
200 LTTV_POINTER, &value));
ffd54a90 201 g_assert((main_hooks = *(value.v_pointer)) != NULL);
12c59c3d 202 lttv_hooks_add(main_hooks, process_traceset, NULL, LTTV_PRIO_DEFAULT);
48f6f3c2 203}
204
205
08b1c66e 206static void destroy()
48f6f3c2 207{
dc877563 208 guint i, nb;
48f6f3c2 209
308711e5 210 LttvTrace *trace;
211
b445142a 212 g_info("Destroy batchAnalysis.c");
213
dc877563 214 lttv_option_remove("trace");
b445142a 215 lttv_option_remove("stats");
48f6f3c2 216
dc877563 217 lttv_hooks_destroy(before_traceset);
218 lttv_hooks_destroy(after_traceset);
219 lttv_hooks_destroy(before_trace);
220 lttv_hooks_destroy(after_trace);
221 lttv_hooks_destroy(before_tracefile);
222 lttv_hooks_destroy(after_tracefile);
12c59c3d 223 //lttv_hooks_destroy(before_event);
224 //lttv_hooks_destroy(after_event);
225 lttv_hooks_destroy(event_hook);
311e7f46 226 lttv_hooks_remove_data(main_hooks, process_traceset, NULL);
48f6f3c2 227
dc877563 228 nb = lttv_traceset_number(traceset);
ffd54a90 229 for(i = 0 ; i < nb ; i++) {
308711e5 230 trace = lttv_traceset_get(traceset, i);
231 ltt_trace_close(lttv_trace(trace));
3d974afb 232 /* This will be done by lttv_traceset_destroy */
233 //lttv_trace_destroy(trace);
dc877563 234 }
c6bc9cb9 235
236 lttv_traceset_destroy(traceset);
dc877563 237}
48f6f3c2 238
08b1c66e 239
240LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \
241 "Run through a trace calling all the registered hooks", \
cec3d7b0 242 init, destroy, "state", "stats", "option","textFilter")
This page took 0.043092 seconds and 4 git commands to generate.