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 char * testval
= 0x88888;
70 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
72 LttvTracesetStats
*tscs
;
74 LttvTracesetContext
*tc
;
78 g_info("BatchAnalysis begin process traceset");
80 tscs
= g_object_new(LTTV_TRACESET_STATS_TYPE
, NULL
);
81 tc
= &tscs
->parent
.parent
;
83 g_info("BatchAnalysis initialize context");
85 lttv_context_init(tc
, traceset
);
86 lttv_state_add_event_hooks(&tscs
->parent
);
87 if(a_stats
) lttv_stats_add_event_hooks(tscs
);
89 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
90 LTTV_POINTER
, &value_expression
));
92 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/lttv_filter",
93 LTTV_POINTER
, &value_filter
));
95 *(value_filter
.v_pointer
) = lttv_filter_new();
96 //g_debug("Filter string: %s",((GString*)*(value_expression.v_pointer))->str);
98 lttv_filter_append_expression(*(value_filter
.v_pointer
),((GString
*)*(value_expression
.v_pointer
))->str
);
100 //lttv_traceset_context_add_hooks(tc,
101 //before_traceset, after_traceset, NULL, before_trace, after_trace,
102 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
103 lttv_process_traceset_begin(tc
,
112 end
.tv_sec
= G_MAXULONG
;
113 end
.tv_nsec
= G_MAXULONG
;
115 g_info("BatchAnalysis process traceset");
117 lttv_process_traceset_seek_time(tc
, start
);
118 lttv_process_traceset_middle(tc
,
124 //lttv_traceset_context_remove_hooks(tc,
125 //before_traceset, after_traceset, NULL, before_trace, after_trace,
126 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
127 lttv_process_traceset_end(tc
,
134 g_info("BatchAnalysis destroy context");
136 lttv_filter_destroy(*(value_filter
.v_pointer
));
137 lttv_state_remove_event_hooks(&tscs
->parent
);
138 if(a_stats
) lttv_stats_remove_event_hooks(tscs
);
139 lttv_context_fini(tc
);
140 g_object_unref(tscs
);
142 g_info("BatchAnalysis end process traceset");
149 LttvAttributeValue value
;
151 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
153 g_info("Init batchAnalysis.c");
155 lttv_option_add("trace", 't',
156 "add a trace to the trace set to analyse",
157 "pathname of the directory containing the trace",
158 LTTV_OPT_STRING
, &a_trace
, lttv_trace_option
, NULL
);
161 lttv_option_add("stats", 's',
162 "write the traceset and trace statistics",
164 LTTV_OPT_NONE
, &a_stats
, NULL
, NULL
);
167 traceset
= lttv_traceset_new();
169 before_traceset
= lttv_hooks_new();
170 after_traceset
= lttv_hooks_new();
171 before_trace
= lttv_hooks_new();
172 after_trace
= lttv_hooks_new();
173 before_tracefile
= lttv_hooks_new();
174 after_tracefile
= lttv_hooks_new();
175 //before_event = lttv_hooks_new();
176 //after_event = lttv_hooks_new();
177 event_hook
= lttv_hooks_new();
179 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/before",
180 LTTV_POINTER
, &value
));
181 *(value
.v_pointer
) = before_traceset
;
182 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/after",
183 LTTV_POINTER
, &value
));
184 *(value
.v_pointer
) = after_traceset
;
185 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/before",
186 LTTV_POINTER
, &value
));
187 *(value
.v_pointer
) = before_trace
;
188 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/after",
189 LTTV_POINTER
, &value
));
190 *(value
.v_pointer
) = after_trace
;
191 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/before",
192 LTTV_POINTER
, &value
));
193 *(value
.v_pointer
) = before_tracefile
;
194 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/after",
195 LTTV_POINTER
, &value
));
196 *(value
.v_pointer
) = after_tracefile
;
197 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
198 // LTTV_POINTER, &value));
199 //*(value.v_pointer) = before_event;
200 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
201 // LTTV_POINTER, &value));
202 //*(value.v_pointer) = after_event;
203 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event",
204 LTTV_POINTER
, &value
));
205 *(value
.v_pointer
) = event_hook
;
207 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
208 LTTV_POINTER
, &value
));
209 g_assert((main_hooks
= *(value
.v_pointer
)) != NULL
);
210 lttv_hooks_add(main_hooks
, process_traceset
, NULL
, LTTV_PRIO_DEFAULT
);
213 static void destroy()
219 g_info("Destroy batchAnalysis.c");
221 lttv_option_remove("trace");
222 lttv_option_remove("stats");
224 lttv_hooks_destroy(before_traceset
);
225 lttv_hooks_destroy(after_traceset
);
226 lttv_hooks_destroy(before_trace
);
227 lttv_hooks_destroy(after_trace
);
228 lttv_hooks_destroy(before_tracefile
);
229 lttv_hooks_destroy(after_tracefile
);
230 //lttv_hooks_destroy(before_event);
231 //lttv_hooks_destroy(after_event);
232 lttv_hooks_destroy(event_hook
);
233 lttv_hooks_remove_data(main_hooks
, process_traceset
, NULL
);
235 nb
= lttv_traceset_number(traceset
);
236 for(i
= 0 ; i
< nb
; i
++) {
237 trace
= lttv_traceset_get(traceset
, i
);
238 ltt_trace_close(lttv_trace(trace
));
239 /* This will be done by lttv_traceset_destroy */
240 //lttv_trace_destroy(trace);
243 lttv_traceset_destroy(traceset
);
246 LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \
247 "Run through a trace calling all the registered hooks", \
248 init
, destroy
, "state", "stats", "option","textFilter")