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. */
23 #include <lttv/lttv.h>
24 #include <lttv/attribute.h>
25 #include <lttv/hook.h>
26 #include <lttv/option.h>
27 #include <lttv/module.h>
28 #include <lttv/tracecontext.h>
29 #include <lttv/state.h>
30 #include <lttv/stats.h>
31 #include <lttv/filter.h>
32 #include <ltt/trace.h>
34 static LttvTraceset
*traceset
;
48 static gboolean a_stats
;
50 LttvFilter
*a_lttv_filter
;
52 void lttv_trace_option(void *hook_data
)
56 trace
= ltt_trace_open(a_trace
);
57 if(trace
== NULL
) g_critical("cannot open trace %s", a_trace
);
58 lttv_traceset_add(traceset
, lttv_trace_new(trace
));
62 static gboolean
process_traceset(void *hook_data
, void *call_data
)
64 LttvAttributeValue value
;
66 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
68 LttvTracesetStats
*tscs
;
70 LttvTracesetContext
*tc
;
74 g_info("BatchAnalysis begin process traceset");
76 tscs
= g_object_new(LTTV_TRACESET_STATS_TYPE
, NULL
);
77 tc
= &tscs
->parent
.parent
;
79 g_info("BatchAnalysis initialize context");
81 lttv_context_init(tc
, traceset
);
82 lttv_state_add_event_hooks(&tscs
->parent
);
83 if(a_stats
) lttv_stats_add_event_hooks(tscs
);
85 g_assert(lttv_iattribute_find_by_path(attributes
, "filter/expression",
86 LTTV_POINTER
, &value
));
88 a_lttv_filter
= lttv_filter_new();
89 g_debug("Filter string: %s",((GString
*)*(value
.v_pointer
))->str
);
90 lttv_filter_append_expression(a_lttv_filter
,((GString
*)*(value
.v_pointer
))->str
);
92 //lttv_traceset_context_add_hooks(tc,
93 //before_traceset, after_traceset, NULL, before_trace, after_trace,
94 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
95 lttv_process_traceset_begin(tc
,
104 end
.tv_sec
= G_MAXULONG
;
105 end
.tv_nsec
= G_MAXULONG
;
107 g_info("BatchAnalysis process traceset");
109 lttv_process_traceset_seek_time(tc
, start
);
110 lttv_process_traceset_middle(tc
,
115 g_info("BatchAnalysis destroy context");
117 //lttv_traceset_context_remove_hooks(tc,
118 //before_traceset, after_traceset, NULL, before_trace, after_trace,
119 //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event);
120 lttv_process_traceset_end(tc
,
127 lttv_filter_destroy(a_lttv_filter
);
128 lttv_state_remove_event_hooks(&tscs
->parent
);
129 if(a_stats
) lttv_stats_remove_event_hooks(tscs
);
130 lttv_context_fini(tc
);
131 g_object_unref(tscs
);
133 g_info("BatchAnalysis end process traceset");
140 LttvAttributeValue value
;
142 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
144 g_info("Init batchAnalysis.c");
146 lttv_option_add("trace", 't',
147 "add a trace to the trace set to analyse",
148 "pathname of the directory containing the trace",
149 LTTV_OPT_STRING
, &a_trace
, lttv_trace_option
, NULL
);
152 lttv_option_add("stats", 's',
153 "write the traceset and trace statistics",
155 LTTV_OPT_NONE
, &a_stats
, NULL
, NULL
);
158 traceset
= lttv_traceset_new();
160 before_traceset
= lttv_hooks_new();
161 after_traceset
= lttv_hooks_new();
162 before_trace
= lttv_hooks_new();
163 after_trace
= lttv_hooks_new();
164 before_tracefile
= lttv_hooks_new();
165 after_tracefile
= lttv_hooks_new();
166 //before_event = lttv_hooks_new();
167 //after_event = lttv_hooks_new();
168 event_hook
= lttv_hooks_new();
170 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/before",
171 LTTV_POINTER
, &value
));
172 *(value
.v_pointer
) = before_traceset
;
173 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/after",
174 LTTV_POINTER
, &value
));
175 *(value
.v_pointer
) = after_traceset
;
176 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/before",
177 LTTV_POINTER
, &value
));
178 *(value
.v_pointer
) = before_trace
;
179 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/after",
180 LTTV_POINTER
, &value
));
181 *(value
.v_pointer
) = after_trace
;
182 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/before",
183 LTTV_POINTER
, &value
));
184 *(value
.v_pointer
) = before_tracefile
;
185 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/after",
186 LTTV_POINTER
, &value
));
187 *(value
.v_pointer
) = after_tracefile
;
188 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/before",
189 // LTTV_POINTER, &value));
190 //*(value.v_pointer) = before_event;
191 //g_assert(lttv_iattribute_find_by_path(attributes, "hooks/event/after",
192 // LTTV_POINTER, &value));
193 //*(value.v_pointer) = after_event;
194 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event",
195 LTTV_POINTER
, &value
));
196 *(value
.v_pointer
) = event_hook
;
198 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
199 LTTV_POINTER
, &value
));
200 g_assert((main_hooks
= *(value
.v_pointer
)) != NULL
);
201 lttv_hooks_add(main_hooks
, process_traceset
, NULL
, LTTV_PRIO_DEFAULT
);
205 static void destroy()
211 g_info("Destroy batchAnalysis.c");
213 lttv_option_remove("trace");
214 lttv_option_remove("stats");
216 lttv_hooks_destroy(before_traceset
);
217 lttv_hooks_destroy(after_traceset
);
218 lttv_hooks_destroy(before_trace
);
219 lttv_hooks_destroy(after_trace
);
220 lttv_hooks_destroy(before_tracefile
);
221 lttv_hooks_destroy(after_tracefile
);
222 //lttv_hooks_destroy(before_event);
223 //lttv_hooks_destroy(after_event);
224 lttv_hooks_destroy(event_hook
);
225 lttv_hooks_remove_data(main_hooks
, process_traceset
, NULL
);
227 nb
= lttv_traceset_number(traceset
);
228 for(i
= 0 ; i
< nb
; i
++) {
229 trace
= lttv_traceset_get(traceset
, i
);
230 ltt_trace_close(lttv_trace(trace
));
231 /* This will be done by lttv_traceset_destroy */
232 //lttv_trace_destroy(trace);
235 lttv_traceset_destroy(traceset
);
239 LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \
240 "Run through a trace calling all the registered hooks", \
241 init
, destroy
, "state", "stats", "option","textFilter")
This page took 0.035155 seconds and 5 git commands to generate.