control flow background request desactivated
[lttv.git] / ltt / branches / poly / lttv / lttv / tracecontext.h
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
19 #ifndef PROCESSTRACE_H
20 #define PROCESSTRACE_H
21
22 #include <lttv/traceset.h>
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
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
77 typedef struct _LttvTracesetContextPosition LttvTracesetContextPosition;
78 typedef struct _LttvTraceContextPosition LttvTraceContextPosition;
79
80 #define LTTV_TRACESET_CONTEXT_TYPE (lttv_traceset_context_get_type ())
81 #define LTTV_TRACESET_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContext))
82 #define LTTV_TRACESET_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContextClass))
83 #define LTTV_IS_TRACESET_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACESET_CONTEXT_TYPE))
84 #define LTTV_IS_TRACESET_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACESET_CONTEXT_TYPE))
85 #define LTTV_TRACESET_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACESET_CONTEXT_TYPE, LttvTracesetContextClass))
86
87 struct _LttvTracesetContext {
88 GObject parent;
89
90 LttvTraceset *ts;
91 LttvTraceContext **traces;
92 LttvAttribute *a;
93 LttvAttribute *ts_a;
94 TimeInterval time_span;
95 GTree *pqueue;
96
97 LttvTracesetContextPosition *sync_position; /* position at which to sync the
98 trace context */
99 };
100
101 struct _LttvTracesetContextClass {
102 GObjectClass parent;
103
104 void (*init) (LttvTracesetContext *self, LttvTraceset *ts);
105 void (*fini) (LttvTracesetContext *self);
106 LttvTracesetContext* (*new_traceset_context) (LttvTracesetContext *self);
107 LttvTraceContext* (*new_trace_context) (LttvTracesetContext *self);
108 LttvTracefileContext* (*new_tracefile_context) (LttvTracesetContext *self);
109 };
110
111 GType lttv_traceset_context_get_type (void);
112
113 void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts);
114
115 void lttv_context_fini(LttvTracesetContext *self);
116
117 LttvTracesetContext *
118 lttv_context_new_traceset_context(LttvTracesetContext *self);
119
120 LttvTraceContext *
121 lttv_context_new_trace_context(LttvTracesetContext *self);
122
123 LttvTracefileContext *
124 lttv_context_new_tracefile_context(LttvTracesetContext *self);
125
126
127 #define LTTV_TRACE_CONTEXT_TYPE (lttv_trace_context_get_type ())
128 #define LTTV_TRACE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContext))
129 #define LTTV_TRACE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass))
130 #define LTTV_IS_TRACE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_CONTEXT_TYPE))
131 #define LTTV_IS_TRACE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_CONTEXT_TYPE))
132 #define LTTV_TRACE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass))
133
134 struct _LttvTraceContext {
135 GObject parent;
136
137 LttvTracesetContext *ts_context;
138 guint index; /* in ts_context->traces */
139 LttTrace *t;
140 LttvTrace *vt;
141 //LttvTracefileContext **tracefiles;
142 GArray *tracefiles;
143 LttvAttribute *a;
144 LttvAttribute *t_a;
145 };
146
147 struct _LttvTraceContextClass {
148 GObjectClass parent;
149 };
150
151 GType lttv_trace_context_get_type (void);
152
153 #define LTTV_TRACEFILE_CONTEXT_TYPE (lttv_tracefile_context_get_type ())
154 #define LTTV_TRACEFILE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContext))
155 #define LTTV_TRACEFILE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass))
156 #define LTTV_IS_TRACEFILE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_CONTEXT_TYPE))
157 #define LTTV_IS_TRACEFILE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_CONTEXT_TYPE))
158 #define LTTV_TRACEFILE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass))
159
160 struct _LttvTracefileContext {
161 GObject parent;
162
163 LttvTraceContext *t_context;
164 // gboolean control;
165 guint index; /* in ts_context->tracefiles */
166 LttTracefile *tf;
167 // LttEvent *e;
168 LttvHooks *event;
169 LttvHooksById *event_by_id;
170 LttTime timestamp;
171 LttvAttribute *a;
172 };
173
174 struct _LttvTracefileContextClass {
175 GObjectClass parent;
176 };
177
178 GType lttv_tracefile_context_get_type (void);
179
180 /* Run through the events in a traceset in sorted order calling all the
181 hooks appropriately. It starts at the current time and runs until end or
182 nb_events are processed. */
183
184 void lttv_process_traceset(LttvTracesetContext *self, LttTime end,
185 unsigned nb_events);
186
187 /* Process traceset can also be done in smaller pieces calling begin,
188 * then seek and middle repeatedly, and end. The middle function return the
189 * number of events processed. It will be smaller than nb_events if the end time
190 * or end position is reached. */
191
192
193 void lttv_process_traceset_begin(LttvTracesetContext *self,
194 LttvHooks *before_traceset,
195 LttvHooks *before_trace,
196 LttvHooks *before_tracefile,
197 LttvHooks *event,
198 LttvHooksById *event_by_id);
199
200
201 guint lttv_process_traceset_middle(LttvTracesetContext *self,
202 LttTime end,
203 guint nb_events,
204 const LttvTracesetContextPosition *end_position);
205
206 void lttv_process_traceset_end(LttvTracesetContext *self,
207 LttvHooks *after_traceset,
208 LttvHooks *after_trace,
209 LttvHooks *after_tracefile,
210 LttvHooks *event,
211 LttvHooksById *event_by_id);
212
213
214 void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start);
215
216 gboolean lttv_process_traceset_seek_position(LttvTracesetContext *self,
217 const LttvTracesetContextPosition *pos);
218
219 void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start);
220
221 void lttv_traceset_context_add_hooks(LttvTracesetContext *self,
222 LttvHooks *before_traceset,
223 LttvHooks *before_trace,
224 LttvHooks *before_tracefile,
225 LttvHooks *event,
226 LttvHooksById *event_by_id);
227
228 void lttv_traceset_context_remove_hooks(LttvTracesetContext *self,
229 LttvHooks *after_traceset,
230 LttvHooks *after_trace,
231 LttvHooks *after_tracefile,
232 LttvHooks *event,
233 LttvHooksById *event_by_id);
234
235 void lttv_trace_context_add_hooks(LttvTraceContext *self,
236 LttvHooks *before_trace,
237 LttvHooks *before_tracefile,
238 LttvHooks *event,
239 LttvHooksById *event_by_id);
240
241 void lttv_trace_context_remove_hooks(LttvTraceContext *self,
242 LttvHooks *after_trace,
243 LttvHooks *after_tracefile,
244 LttvHooks *event,
245 LttvHooksById *event_by_id);
246
247 void lttv_tracefile_context_add_hooks(LttvTracefileContext *self,
248 LttvHooks *before_tracefile,
249 LttvHooks *event,
250 LttvHooksById *event_by_id);
251
252
253 void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self,
254 LttvHooks *after_tracefile,
255 LttvHooks *event,
256 LttvHooksById *event_by_id);
257
258
259 void lttv_tracefile_context_add_hooks_by_id(LttvTracefileContext *self,
260 unsigned i,
261 LttvHooks *event_by_id);
262
263 void lttv_tracefile_context_remove_hooks_by_id(LttvTracefileContext *self,
264 unsigned i);
265
266 /* A LttvTraceHook has two arrays of LttvTraceHookByFacility,
267 * indexed by facility ID and a simple array used to walk all the hooks */
268 typedef struct _LttvTraceHook {
269 GArray *fac_index;
270 GArray *fac_list;
271 } LttvTraceHook;
272
273 typedef struct _LttvTraceHookByFacility {
274 LttvHook h;
275 guint id;
276 LttField *f1;
277 LttField *f2;
278 LttField *f3;
279 gpointer hook_data;
280 } LttvTraceHookByFacility;
281
282
283 /* Get the first facility corresponding to the name. As the types must be
284 * compatible, it is relevant to use the field name and sizes of the first
285 * facility to create data structures and assume the data will be compatible
286 * thorough the trace */
287 LttvTraceHookByFacility *lttv_trace_hook_get_first(LttvTraceHook *th);
288
289 LttvTraceHookByFacility *lttv_trace_hook_get_fac(
290 LttvTraceHook *th, guint facility_id);
291
292 void lttv_trace_hook_destroy(LttvTraceHook *th);
293
294 /* Search in the trace for the id of the named event type within the named
295 facility. Then, find the three (if non null) named fields. All that
296 information is then used to fill the LttvTraceHook structure. This
297 is useful to find the specific id for an event within a trace, for
298 registering a hook using this structure as event data;
299 it already contains the (up to three) needed fields handles. */
300
301 gint lttv_trace_find_hook(LttTrace *t, GQuark facility, GQuark event_type,
302 GQuark field1, GQuark field2, GQuark field3, LttvHook h,
303 gpointer hook_data, LttvTraceHook *th);
304
305 LttvTracefileContext *lttv_traceset_context_get_current_tfc(
306 LttvTracesetContext *self);
307
308
309 LttvTracesetContextPosition *lttv_traceset_context_position_new();
310
311 void lttv_traceset_context_position_save(const LttvTracesetContext *self,
312 LttvTracesetContextPosition *pos);
313
314 void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos);
315
316 void lttv_traceset_context_position_copy(LttvTracesetContextPosition *dest,
317 const LttvTracesetContextPosition *src);
318
319 gint lttv_traceset_context_pos_pos_compare(
320 const LttvTracesetContextPosition *pos1,
321 const LttvTracesetContextPosition *pos2);
322
323 gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self,
324 const LttvTracesetContextPosition *pos2);
325
326 LttTime lttv_traceset_context_position_get_time(
327 const LttvTracesetContextPosition *pos);
328
329 gint compare_tracefile(gconstpointer a, gconstpointer b);
330
331
332 /* Synchronisation helpers : save/restore synchronization between ltt traces and
333 * a traceset context. */
334 void lttv_process_traceset_synchronize_tracefiles(LttvTracesetContext *tsc);
335
336 void lttv_process_traceset_get_sync_data(LttvTracesetContext *tsc);
337
338 #endif // PROCESSTRACE_H
This page took 0.035751 seconds and 4 git commands to generate.