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