1c69df33fc8eedf802c848cdff1c361733dd90ba
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 <ltt/trace.h>
33 static LttvTraceset
*traceset
;
48 static gboolean a_stats
;
50 void lttv_trace_option(void *hook_data
)
54 trace
= ltt_trace_open(a_trace
);
55 if(trace
== NULL
) g_critical("cannot open trace %s", a_trace
);
56 lttv_traceset_add(traceset
, lttv_trace_new(trace
));
60 static gboolean
process_traceset(void *hook_data
, void *call_data
)
62 LttvTracesetStats
*tscs
;
64 LttvTracesetContext
*tc
;
68 g_info("BatchAnalysis begin process traceset");
70 tscs
= g_object_new(LTTV_TRACESET_STATS_TYPE
, NULL
);
71 tc
= &tscs
->parent
.parent
;
73 g_info("BatchAnalysis initialize context");
75 lttv_context_init(tc
, traceset
);
76 lttv_state_add_event_hooks(&tscs
->parent
);
77 if(a_stats
) lttv_stats_add_event_hooks(tscs
);
79 lttv_traceset_context_add_hooks(tc
,
80 before_traceset
, after_traceset
, NULL
, before_trace
, after_trace
,
81 NULL
, before_tracefile
, after_tracefile
, NULL
, before_event
, after_event
);
85 end
.tv_sec
= G_MAXULONG
;
86 end
.tv_nsec
= G_MAXULONG
;
88 g_info("BatchAnalysis process traceset");
90 lttv_process_traceset_seek_time(tc
, start
);
91 lttv_process_traceset(tc
, end
, G_MAXULONG
);
93 g_info("BatchAnalysis destroy context");
95 lttv_traceset_context_remove_hooks(tc
,
96 before_traceset
, after_traceset
, NULL
, before_trace
, after_trace
,
97 NULL
, before_tracefile
, after_tracefile
, NULL
, before_event
, after_event
);
98 lttv_state_remove_event_hooks(&tscs
->parent
);
99 if(a_stats
) lttv_stats_remove_event_hooks(tscs
);
100 lttv_context_fini(tc
);
101 g_object_unref(tscs
);
103 g_info("BatchAnalysis end process traceset");
109 LttvAttributeValue value
;
111 LttvIAttribute
*attributes
= LTTV_IATTRIBUTE(lttv_global_attributes());
113 g_info("Init batchAnalysis.c");
115 lttv_option_add("trace", 't',
116 "add a trace to the trace set to analyse",
117 "pathname of the directory containing the trace",
118 LTTV_OPT_STRING
, &a_trace
, lttv_trace_option
, NULL
);
121 lttv_option_add("stats", 's',
122 "write the traceset and trace statistics",
124 LTTV_OPT_NONE
, &a_stats
, NULL
, NULL
);
127 traceset
= lttv_traceset_new();
129 before_traceset
= lttv_hooks_new();
130 after_traceset
= lttv_hooks_new();
131 before_trace
= lttv_hooks_new();
132 after_trace
= lttv_hooks_new();
133 before_tracefile
= lttv_hooks_new();
134 after_tracefile
= lttv_hooks_new();
135 before_event
= lttv_hooks_new();
136 after_event
= lttv_hooks_new();
138 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/before",
139 LTTV_POINTER
, &value
));
140 *(value
.v_pointer
) = before_traceset
;
141 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/traceset/after",
142 LTTV_POINTER
, &value
));
143 *(value
.v_pointer
) = after_traceset
;
144 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/before",
145 LTTV_POINTER
, &value
));
146 *(value
.v_pointer
) = before_trace
;
147 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/trace/after",
148 LTTV_POINTER
, &value
));
149 *(value
.v_pointer
) = after_trace
;
150 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/before",
151 LTTV_POINTER
, &value
));
152 *(value
.v_pointer
) = before_tracefile
;
153 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/tracefile/after",
154 LTTV_POINTER
, &value
));
155 *(value
.v_pointer
) = after_tracefile
;
156 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event/before",
157 LTTV_POINTER
, &value
));
158 *(value
.v_pointer
) = before_event
;
159 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/event/after",
160 LTTV_POINTER
, &value
));
161 *(value
.v_pointer
) = after_event
;
163 g_assert(lttv_iattribute_find_by_path(attributes
, "hooks/main/before",
164 LTTV_POINTER
, &value
));
165 g_assert((main_hooks
= *(value
.v_pointer
)) != NULL
);
166 lttv_hooks_add(main_hooks
, process_traceset
, NULL
);
170 static void destroy()
176 g_info("Destroy batchAnalysis.c");
178 lttv_option_remove("trace");
179 lttv_option_remove("stats");
181 lttv_hooks_destroy(before_traceset
);
182 lttv_hooks_destroy(after_traceset
);
183 lttv_hooks_destroy(before_trace
);
184 lttv_hooks_destroy(after_trace
);
185 lttv_hooks_destroy(before_tracefile
);
186 lttv_hooks_destroy(after_tracefile
);
187 lttv_hooks_destroy(before_event
);
188 lttv_hooks_destroy(after_event
);
189 lttv_hooks_remove_data(main_hooks
, process_traceset
, NULL
);
191 nb
= lttv_traceset_number(traceset
);
192 for(i
= 0 ; i
< nb
; i
++) {
193 trace
= lttv_traceset_get(traceset
, i
);
194 ltt_trace_close(lttv_trace(trace
));
195 lttv_trace_destroy(trace
);
198 lttv_traceset_destroy(traceset
);
202 LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \
203 "Run through a trace calling all the registered hooks", \
204 init
, destroy
, "state", "stats", "option")
This page took 0.038808 seconds and 4 git commands to generate.