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 | |
dc877563 |
19 | #ifndef PROCESSTRACE_H |
20 | #define PROCESSTRACE_H |
21 | |
ffd54a90 |
22 | #include <lttv/traceset.h> |
dc877563 |
23 | #include <lttv/attribute.h> |
24 | #include <lttv/hook.h> |
25 | #include <ltt/ltt.h> |
26 | |
27 | /* This is the generic part of trace processing. All events within a |
28 | certain time interval are accessed and processing hooks are called for |
29 | each. The events are examined in monotonically increasing time to more |
30 | closely follow the traced system behavior. |
31 | |
32 | Hooks are called at several different places during the processing: |
33 | before traceset, after traceset, check trace, before trace, after trace, |
34 | check tracefile, before tracefile, after tracefile, |
35 | check_event, before_event, before_event_by_id, |
36 | after_event, after_event_by_id. |
37 | |
38 | In each case the "check" hooks are called first to determine if further |
39 | processing of the trace, tracefile or event is wanted. Then, the before |
40 | hooks and the after hooks are called. The before hooks for a traceset |
41 | are called before those for the contained traces, which are called before |
42 | those for the contained tracefiles. The after hooks are called in reverse |
43 | order. The event hooks are called after all the before_tracefile hooks |
44 | and before all the after_tracefile hooks. |
45 | |
46 | The hooks receive two arguments, the hook_data and call_data. The hook_data |
47 | is specified when the hook is registered and typically links to the |
48 | object registering the hook (e.g. a graphical events viewer). The call_data |
49 | must contain all the context related to the call. The traceset hooks receive |
50 | the LttvTracesetContext provided by the caller. The trace hooks receive |
51 | the LttvTraceContext from the traces array in the LttvTracesetContext. |
52 | The tracefile and event hooks receive the LttvTracefileContext from |
53 | the tracefiles array in the LttvTraceContext. The LttEvent and LttTime |
54 | fields in the tracefile context are set to the current event and current |
55 | event time before calling the event hooks. No other context field is |
56 | modified. |
57 | |
58 | The contexts in the traces and tracefiles arrays must be allocated by |
59 | the caller, either before the call or during the before hooks of the |
60 | enclosing traceset or trace. The order in the traces array must |
61 | correspond to the lttv_traceset_get function. The order in the tracefiles |
62 | arrays must correspond to the ltt_trace_control_tracefile_get and |
63 | ltt_trace_per_cpu_tracefile_get functions. The traceset, trace and |
64 | tracefile contexts may be subtyped as needed. Indeed, both the contexts |
65 | and the hooks are defined by the caller. */ |
66 | |
ffd54a90 |
67 | |
68 | typedef struct _LttvTracesetContext LttvTracesetContext; |
69 | typedef struct _LttvTracesetContextClass LttvTracesetContextClass; |
70 | |
71 | typedef struct _LttvTraceContext LttvTraceContext; |
72 | typedef struct _LttvTraceContextClass LttvTraceContextClass; |
73 | |
74 | typedef struct _LttvTracefileContext LttvTracefileContext; |
75 | typedef struct _LttvTracefileContextClass LttvTracefileContextClass; |
76 | |
8697a616 |
77 | typedef struct _LttvTracesetContextPosition LttvTracesetContextPosition; |
78 | typedef struct _LttvTraceContextPosition LttvTraceContextPosition; |
79 | |
33e44b82 |
80 | #ifndef LTTVFILTER_TYPE_DEFINED |
81 | typedef struct _LttvFilter LttvFilter; |
82 | #define LTTVFILTER_TYPE_DEFINED |
83 | #endif |
84 | |
dc877563 |
85 | #define LTTV_TRACESET_CONTEXT_TYPE (lttv_traceset_context_get_type ()) |
86 | #define LTTV_TRACESET_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContext)) |
87 | #define LTTV_TRACESET_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContextClass)) |
88 | #define LTTV_IS_TRACESET_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACESET_CONTEXT_TYPE)) |
89 | #define LTTV_IS_TRACESET_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_CONTEXT_TYPE)) |
90 | #define LTTV_TRACESET_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContextClass)) |
91 | |
dc877563 |
92 | struct _LttvTracesetContext { |
93 | GObject parent; |
94 | |
95 | LttvTraceset *ts; |
dc877563 |
96 | LttvTraceContext **traces; |
97 | LttvAttribute *a; |
308711e5 |
98 | LttvAttribute *ts_a; |
8697a616 |
99 | TimeInterval time_span; |
2a2fa4f0 |
100 | GTree *pqueue; |
2c82c4dc |
101 | |
18c87975 |
102 | LttvTracesetContextPosition *sync_position; /* position at which to sync the |
103 | trace context */ |
dc877563 |
104 | }; |
105 | |
106 | struct _LttvTracesetContextClass { |
107 | GObjectClass parent; |
108 | |
109 | void (*init) (LttvTracesetContext *self, LttvTraceset *ts); |
110 | void (*fini) (LttvTracesetContext *self); |
111 | LttvTracesetContext* (*new_traceset_context) (LttvTracesetContext *self); |
112 | LttvTraceContext* (*new_trace_context) (LttvTracesetContext *self); |
113 | LttvTracefileContext* (*new_tracefile_context) (LttvTracesetContext *self); |
114 | }; |
115 | |
116 | GType lttv_traceset_context_get_type (void); |
117 | |
118 | void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts); |
119 | |
120 | void lttv_context_fini(LttvTracesetContext *self); |
121 | |
122 | LttvTracesetContext * |
123 | lttv_context_new_traceset_context(LttvTracesetContext *self); |
124 | |
125 | LttvTraceContext * |
126 | lttv_context_new_trace_context(LttvTracesetContext *self); |
127 | |
128 | LttvTracefileContext * |
129 | lttv_context_new_tracefile_context(LttvTracesetContext *self); |
130 | |
131 | |
132 | #define LTTV_TRACE_CONTEXT_TYPE (lttv_trace_context_get_type ()) |
133 | #define LTTV_TRACE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContext)) |
134 | #define LTTV_TRACE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass)) |
135 | #define LTTV_IS_TRACE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_CONTEXT_TYPE)) |
136 | #define LTTV_IS_TRACE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_CONTEXT_TYPE)) |
137 | #define LTTV_TRACE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass)) |
138 | |
dc877563 |
139 | struct _LttvTraceContext { |
140 | GObject parent; |
141 | |
142 | LttvTracesetContext *ts_context; |
143 | guint index; /* in ts_context->traces */ |
ffd54a90 |
144 | LttTrace *t; |
308711e5 |
145 | LttvTrace *vt; |
eed2ef37 |
146 | //LttvTracefileContext **tracefiles; |
147 | GArray *tracefiles; |
dc877563 |
148 | LttvAttribute *a; |
308711e5 |
149 | LttvAttribute *t_a; |
dc877563 |
150 | }; |
151 | |
152 | struct _LttvTraceContextClass { |
153 | GObjectClass parent; |
154 | }; |
155 | |
156 | GType lttv_trace_context_get_type (void); |
157 | |
158 | #define LTTV_TRACEFILE_CONTEXT_TYPE (lttv_tracefile_context_get_type ()) |
159 | #define LTTV_TRACEFILE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContext)) |
160 | #define LTTV_TRACEFILE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass)) |
161 | #define LTTV_IS_TRACEFILE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_CONTEXT_TYPE)) |
162 | #define LTTV_IS_TRACEFILE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_CONTEXT_TYPE)) |
163 | #define LTTV_TRACEFILE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass)) |
164 | |
dc877563 |
165 | struct _LttvTracefileContext { |
166 | GObject parent; |
167 | |
168 | LttvTraceContext *t_context; |
eed2ef37 |
169 | // gboolean control; |
dbb7bb09 |
170 | guint index; /* in ts_context->tracefiles */ |
ffd54a90 |
171 | LttTracefile *tf; |
eed2ef37 |
172 | // LttEvent *e; |
8697a616 |
173 | LttvHooks *event; |
174 | LttvHooksById *event_by_id; |
ffd54a90 |
175 | LttTime timestamp; |
dc877563 |
176 | LttvAttribute *a; |
177 | }; |
178 | |
179 | struct _LttvTracefileContextClass { |
180 | GObjectClass parent; |
181 | }; |
182 | |
183 | GType lttv_tracefile_context_get_type (void); |
184 | |
2a2fa4f0 |
185 | /* Run through the events in a traceset in sorted order calling all the |
186 | hooks appropriately. It starts at the current time and runs until end or |
187 | nb_events are processed. */ |
188 | |
308711e5 |
189 | void lttv_process_traceset(LttvTracesetContext *self, LttTime end, |
2a2fa4f0 |
190 | unsigned nb_events); |
191 | |
8697a616 |
192 | /* Process traceset can also be done in smaller pieces calling begin, |
193 | * then seek and middle repeatedly, and end. The middle function return the |
194 | * number of events processed. It will be smaller than nb_events if the end time |
195 | * or end position is reached. */ |
2a2fa4f0 |
196 | |
2a2fa4f0 |
197 | |
8697a616 |
198 | void lttv_process_traceset_begin(LttvTracesetContext *self, |
199 | LttvHooks *before_traceset, |
200 | LttvHooks *before_trace, |
201 | LttvHooks *before_tracefile, |
202 | LttvHooks *event, |
203 | LttvHooksById *event_by_id); |
204 | |
2a2fa4f0 |
205 | |
8697a616 |
206 | guint lttv_process_traceset_middle(LttvTracesetContext *self, |
207 | LttTime end, |
b8eccacd |
208 | guint nb_events, |
8697a616 |
209 | const LttvTracesetContextPosition *end_position); |
210 | |
211 | void lttv_process_traceset_end(LttvTracesetContext *self, |
212 | LttvHooks *after_traceset, |
213 | LttvHooks *after_trace, |
214 | LttvHooks *after_tracefile, |
215 | LttvHooks *event, |
216 | LttvHooksById *event_by_id); |
2a2fa4f0 |
217 | |
308711e5 |
218 | |
219 | void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start); |
220 | |
8697a616 |
221 | gboolean lttv_process_traceset_seek_position(LttvTracesetContext *self, |
222 | const LttvTracesetContextPosition *pos); |
223 | |
308711e5 |
224 | void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start); |
dc877563 |
225 | |
226 | void lttv_traceset_context_add_hooks(LttvTracesetContext *self, |
8697a616 |
227 | LttvHooks *before_traceset, |
dc877563 |
228 | LttvHooks *before_trace, |
ffd54a90 |
229 | LttvHooks *before_tracefile, |
8697a616 |
230 | LttvHooks *event, |
231 | LttvHooksById *event_by_id); |
dc877563 |
232 | |
233 | void lttv_traceset_context_remove_hooks(LttvTracesetContext *self, |
dc877563 |
234 | LttvHooks *after_traceset, |
dc877563 |
235 | LttvHooks *after_trace, |
ffd54a90 |
236 | LttvHooks *after_tracefile, |
8697a616 |
237 | LttvHooks *event, |
238 | LttvHooksById *event_by_id); |
dc877563 |
239 | |
a8c0f09d |
240 | void lttv_trace_context_add_hooks(LttvTraceContext *self, |
8697a616 |
241 | LttvHooks *before_trace, |
242 | LttvHooks *before_tracefile, |
243 | LttvHooks *event, |
244 | LttvHooksById *event_by_id); |
a8c0f09d |
245 | |
246 | void lttv_trace_context_remove_hooks(LttvTraceContext *self, |
8697a616 |
247 | LttvHooks *after_trace, |
248 | LttvHooks *after_tracefile, |
249 | LttvHooks *event, |
250 | LttvHooksById *event_by_id); |
a8c0f09d |
251 | |
252 | void lttv_tracefile_context_add_hooks(LttvTracefileContext *self, |
8697a616 |
253 | LttvHooks *before_tracefile, |
254 | LttvHooks *event, |
255 | LttvHooksById *event_by_id); |
256 | |
a8c0f09d |
257 | |
258 | void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self, |
8697a616 |
259 | LttvHooks *after_tracefile, |
260 | LttvHooks *event, |
261 | LttvHooksById *event_by_id); |
262 | |
a8c0f09d |
263 | |
264 | void lttv_tracefile_context_add_hooks_by_id(LttvTracefileContext *self, |
265 | unsigned i, |
8697a616 |
266 | LttvHooks *event_by_id); |
a8c0f09d |
267 | |
268 | void lttv_tracefile_context_remove_hooks_by_id(LttvTracefileContext *self, |
269 | unsigned i); |
270 | |
eed2ef37 |
271 | /* A LttvTraceHook has two arrays of LttvTraceHookByFacility, |
272 | * indexed by facility ID and a simple array used to walk all the hooks */ |
b445142a |
273 | typedef struct _LttvTraceHook { |
eed2ef37 |
274 | GArray *fac_index; |
275 | GArray *fac_list; |
276 | } LttvTraceHook; |
277 | |
278 | typedef struct _LttvTraceHookByFacility { |
b445142a |
279 | LttvHook h; |
280 | guint id; |
281 | LttField *f1; |
282 | LttField *f2; |
283 | LttField *f3; |
2c82c4dc |
284 | gpointer hook_data; |
eed2ef37 |
285 | } LttvTraceHookByFacility; |
286 | |
287 | |
288 | /* Get the first facility corresponding to the name. As the types must be |
289 | * compatible, it is relevant to use the field name and sizes of the first |
290 | * facility to create data structures and assume the data will be compatible |
291 | * thorough the trace */ |
292 | LttvTraceHookByFacility *lttv_trace_hook_get_first(LttvTraceHook *th); |
293 | |
294 | LttvTraceHookByFacility *lttv_trace_hook_get_fac( |
295 | LttvTraceHook *th, guint facility_id); |
b445142a |
296 | |
eed2ef37 |
297 | void lttv_trace_hook_destroy(LttvTraceHook *th); |
b445142a |
298 | |
299 | /* Search in the trace for the id of the named event type within the named |
300 | facility. Then, find the three (if non null) named fields. All that |
301 | information is then used to fill the LttvTraceHook structure. This |
302 | is useful to find the specific id for an event within a trace, for |
303 | registering a hook using this structure as event data; |
304 | it already contains the (up to three) needed fields handles. */ |
305 | |
eed2ef37 |
306 | gint lttv_trace_find_hook(LttTrace *t, GQuark facility, GQuark event_type, |
2c82c4dc |
307 | GQuark field1, GQuark field2, GQuark field3, LttvHook h, |
308 | gpointer hook_data, LttvTraceHook *th); |
b445142a |
309 | |
2d262115 |
310 | LttvTracefileContext *lttv_traceset_context_get_current_tfc( |
311 | LttvTracesetContext *self); |
312 | |
8b0bbe19 |
313 | |
314 | LttvTracesetContextPosition *lttv_traceset_context_position_new(); |
5e2c04a2 |
315 | |
8697a616 |
316 | void lttv_traceset_context_position_save(const LttvTracesetContext *self, |
317 | LttvTracesetContextPosition *pos); |
318 | |
319 | void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos); |
320 | |
5e2c04a2 |
321 | void lttv_traceset_context_position_copy(LttvTracesetContextPosition *dest, |
322 | const LttvTracesetContextPosition *src); |
323 | |
8697a616 |
324 | gint lttv_traceset_context_pos_pos_compare( |
8b0bbe19 |
325 | const LttvTracesetContextPosition *pos1, |
326 | const LttvTracesetContextPosition *pos2); |
8697a616 |
327 | |
328 | gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self, |
8b0bbe19 |
329 | const LttvTracesetContextPosition *pos2); |
8697a616 |
330 | |
2d262115 |
331 | LttTime lttv_traceset_context_position_get_time( |
8b0bbe19 |
332 | const LttvTracesetContextPosition *pos); |
333 | |
27304273 |
334 | gint compare_tracefile(gconstpointer a, gconstpointer b); |
8b0bbe19 |
335 | |
2c82c4dc |
336 | |
337 | /* Synchronisation helpers : save/restore synchronization between ltt traces and |
338 | * a traceset context. */ |
18c87975 |
339 | void lttv_process_traceset_synchronize_tracefiles(LttvTracesetContext *tsc); |
2c82c4dc |
340 | |
18c87975 |
341 | void lttv_process_traceset_get_sync_data(LttvTracesetContext *tsc); |
2c82c4dc |
342 | |
0bd2f89c |
343 | /* Seek n events forward and backward (without filtering) : only use these where |
344 | * necessary : the seek backward is costy. */ |
345 | |
346 | #define BACKWARD_SEEK_MUL 2 /* Multiplication factor of time_offset between |
347 | backward seek iterations */ |
348 | |
33e44b82 |
349 | static const LttTime seek_back_default_offset = { 0, 100000 }; |
350 | |
0bd2f89c |
351 | guint lttv_process_traceset_seek_n_forward(LttvTracesetContext *self, |
33e44b82 |
352 | guint n, |
353 | LttvFilter *filter); |
354 | typedef void (*seek_time_fct)(LttvTracesetContext *self, LttTime start); |
0bd2f89c |
355 | |
33e44b82 |
356 | /* If first_offset is ltt_time_zero, it will choose a default value */ |
0bd2f89c |
357 | guint lttv_process_traceset_seek_n_backward(LttvTracesetContext *self, |
33e44b82 |
358 | guint n, |
359 | LttTime first_offset, |
360 | seek_time_fct, |
361 | LttvFilter *filter); |
362 | |
0bd2f89c |
363 | |
dc877563 |
364 | #endif // PROCESSTRACE_H |