1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
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;
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.
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,
19 /* This module inserts a hook in the program main loop. This hook processes
20 all the events in the main tracefile. */
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>
38 static LttvTraceset
*traceset
;
52 static gboolean a_stats
;
54 void lttv_trace_option(void *hook_data
)
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
));
64 static gboolean
process_traceset(void *hook_data
, void *call_data
)
66 LttvAttributeValue value_expression
, value_filter
;
68 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
70 LttvTracesetStats
*tscs
;
72 LttvTracesetState
*tss
;
74 LttvTracesetContext
*tc
;
79 g_info("BatchAnalysis begin process traceset");
82 tscs
= g_object_new(LTTV_TRACESET_STATS_TYPE
, NULL
);
85 tss
= g_object_new(LTTV_TRACESET_STATE_TYPE
, NULL
);
89 g_info("BatchAnalysis initialize context");
91 lttv_context_init(tc
, traceset
);
92 lttv_state_add_event_hooks(tc
);
93 if(a_stats
) lttv_stats_add_event_hooks(tscs
);
95 retval
= lttv_iattribute_find_by_path(attributes
, "filter/expression",
96 LTTV_POINTER
, &value_expression
);
99 retval
= lttv_iattribute_find_by_path(attributes
, "filter/lttv_filter",
100 LTTV_POINTER
, &value_filter
);
103 /* Repeat the search for the first element, the second search might have
104 * moved the first element (by creating the second element)
106 retval
= lttv_iattribute_find_by_path(attributes
, "filter/expression",
107 LTTV_POINTER
, &value_expression
);
110 *(value_filter
.v_pointer
) = lttv_filter_new();
111 //g_debug("Filter string: %s",((GString*)*(value_expression.v_pointer))->str);
113 lttv_filter_append_expression(*(value_filter
.v_pointer
),((GString
*)*(value_expression
.v_pointer
))->str
);
115 //lttv_traceset_context_add_hooks(tc,
116 //before_traceset, after_traceset, NULL, before_trace, after_trace,
117 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
118 lttv_process_traceset_begin(tc
,
127 end
.tv_sec
= G_MAXULONG
;
128 end
.tv_nsec
= G_MAXULONG
;
130 g_info("BatchAnalysis process traceset");
132 lttv_process_traceset_seek_time(tc
, start
);
133 lttv_process_traceset_middle(tc
,
139 //lttv_traceset_context_remove_hooks(tc,
140 //before_traceset, after_traceset, NULL, before_trace, after_trace,
141 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
142 lttv_process_traceset_end(tc
,
149 g_info("BatchAnalysis destroy context");
151 lttv_filter_destroy(*(value_filter
.v_pointer
));
152 lttv_state_remove_event_hooks(tss
);
153 if(a_stats
) lttv_stats_remove_event_hooks(tscs
);
154 lttv_context_fini(tc
);
156 g_object_unref(tscs
);
160 g_info("BatchAnalysis end process traceset");
167 LttvAttributeValue value
;
169 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
172 g_info("Init batchAnalysis.c");
174 lttv_option_add("trace", 't',
175 "add a trace to the trace set to analyse",
176 "pathname of the directory containing the trace",
177 LTTV_OPT_STRING
, &a_trace
, lttv_trace_option
, NULL
);
180 lttv_option_add("stats", 's',
181 "write the traceset and trace statistics",
183 LTTV_OPT_NONE
, &a_stats
, NULL
, NULL
);
186 traceset
= lttv_traceset_new();
188 before_traceset
= lttv_hooks_new();
189 after_traceset
= lttv_hooks_new();
190 before_trace
= lttv_hooks_new();
191 after_trace
= lttv_hooks_new();
192 before_tracefile
= lttv_hooks_new();
193 after_tracefile
= lttv_hooks_new();
194 //before_event = lttv_hooks_new();
195 //after_event = lttv_hooks_new();
196 event_hook
= lttv_hooks_new();
198 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/traceset/before",
199 LTTV_POINTER
, &value
);
201 *(value
.v_pointer
) = before_traceset
;
202 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/traceset/after",
203 LTTV_POINTER
, &value
);
205 *(value
.v_pointer
) = after_traceset
;
206 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/trace/before",
207 LTTV_POINTER
, &value
);
209 *(value
.v_pointer
) = before_trace
;
210 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/trace/after",
211 LTTV_POINTER
, &value
);
213 *(value
.v_pointer
) = after_trace
;
214 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/before",
215 LTTV_POINTER
, &value
);
217 *(value
.v_pointer
) = before_tracefile
;
218 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/after",
219 LTTV_POINTER
, &value
);
221 *(value
.v_pointer
) = after_tracefile
;
222 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
223 // LTTV_POINTER, &value));
224 //*(value.v_pointer) = before_event;
225 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
226 // LTTV_POINTER, &value));
227 //*(value.v_pointer) = after_event;
228 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/event",
229 LTTV_POINTER
, &value
);
231 *(value
.v_pointer
) = event_hook
;
233 retval
= lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
234 LTTV_POINTER
, &value
);
236 g_assert((main_hooks
= *(value
.v_pointer
)) != NULL
);
237 lttv_hooks_add(main_hooks
, process_traceset
, NULL
, LTTV_PRIO_DEFAULT
);
240 static void destroy()
246 g_info("Destroy batchAnalysis.c");
248 lttv_option_remove("trace");
249 lttv_option_remove("stats");
251 lttv_hooks_destroy(before_traceset
);
252 lttv_hooks_destroy(after_traceset
);
253 lttv_hooks_destroy(before_trace
);
254 lttv_hooks_destroy(after_trace
);
255 lttv_hooks_destroy(before_tracefile
);
256 lttv_hooks_destroy(after_tracefile
);
257 //lttv_hooks_destroy(before_event);
258 //lttv_hooks_destroy(after_event);
259 lttv_hooks_destroy(event_hook
);
260 lttv_hooks_remove_data(main_hooks
, process_traceset
, NULL
);
262 nb
= lttv_traceset_number(traceset
);
263 for(i
= 0 ; i
< nb
; i
++) {
264 trace
= lttv_traceset_get(traceset
, i
);
265 ltt_trace_close(lttv_trace(trace
));
266 /* This will be done by lttv_traceset_destroy */
267 //lttv_trace_destroy(trace);
270 lttv_traceset_destroy(traceset
);
273 LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \
274 "Run through a trace calling all the registered hooks", \
275 init
, destroy
, "state", "stats", "option","textFilter")