global traces works, interaction with mainwindow seems ok
[lttv.git] / ltt / branches / poly / lttv / lttv / tracecontext.h
CommitLineData
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
68typedef struct _LttvTracesetContext LttvTracesetContext;
69typedef struct _LttvTracesetContextClass LttvTracesetContextClass;
70
71typedef struct _LttvTraceContext LttvTraceContext;
72typedef struct _LttvTraceContextClass LttvTraceContextClass;
73
74typedef struct _LttvTracefileContext LttvTracefileContext;
75typedef struct _LttvTracefileContextClass LttvTracefileContextClass;
76
8697a616 77typedef struct _LttvTracesetContextPosition LttvTracesetContextPosition;
78typedef struct _LttvTraceContextPosition LttvTraceContextPosition;
79
dc877563 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
dc877563 87struct _LttvTracesetContext {
88 GObject parent;
89
90 LttvTraceset *ts;
dc877563 91 LttvTraceContext **traces;
92 LttvAttribute *a;
308711e5 93 LttvAttribute *ts_a;
8697a616 94 TimeInterval time_span;
2a2fa4f0 95 GTree *pqueue;
dc877563 96};
97
98struct _LttvTracesetContextClass {
99 GObjectClass parent;
100
101 void (*init) (LttvTracesetContext *self, LttvTraceset *ts);
102 void (*fini) (LttvTracesetContext *self);
103 LttvTracesetContext* (*new_traceset_context) (LttvTracesetContext *self);
104 LttvTraceContext* (*new_trace_context) (LttvTracesetContext *self);
105 LttvTracefileContext* (*new_tracefile_context) (LttvTracesetContext *self);
106};
107
108GType lttv_traceset_context_get_type (void);
109
110void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts);
111
112void lttv_context_fini(LttvTracesetContext *self);
113
114LttvTracesetContext *
115lttv_context_new_traceset_context(LttvTracesetContext *self);
116
117LttvTraceContext *
118lttv_context_new_trace_context(LttvTracesetContext *self);
119
120LttvTracefileContext *
121lttv_context_new_tracefile_context(LttvTracesetContext *self);
122
123
124#define LTTV_TRACE_CONTEXT_TYPE (lttv_trace_context_get_type ())
125#define LTTV_TRACE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContext))
126#define LTTV_TRACE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass))
127#define LTTV_IS_TRACE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACE_CONTEXT_TYPE))
128#define LTTV_IS_TRACE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACE_CONTEXT_TYPE))
129#define LTTV_TRACE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACE_CONTEXT_TYPE, LttvTraceContextClass))
130
dc877563 131struct _LttvTraceContext {
132 GObject parent;
133
134 LttvTracesetContext *ts_context;
135 guint index; /* in ts_context->traces */
ffd54a90 136 LttTrace *t;
308711e5 137 LttvTrace *vt;
dbb7bb09 138 LttvTracefileContext **tracefiles;
dc877563 139 LttvAttribute *a;
308711e5 140 LttvAttribute *t_a;
dc877563 141};
142
143struct _LttvTraceContextClass {
144 GObjectClass parent;
145};
146
147GType lttv_trace_context_get_type (void);
148
149#define LTTV_TRACEFILE_CONTEXT_TYPE (lttv_tracefile_context_get_type ())
150#define LTTV_TRACEFILE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContext))
151#define LTTV_TRACEFILE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass))
152#define LTTV_IS_TRACEFILE_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LTTV_TRACEFILE_CONTEXT_TYPE))
153#define LTTV_IS_TRACEFILE_CONTEXT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), LTTV_TRACEFILE_CONTEXT_TYPE))
154#define LTTV_TRACEFILE_CONTEXT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), LTTV_TRACEFILE_CONTEXT_TYPE, LttvTracefileContextClass))
155
dc877563 156struct _LttvTracefileContext {
157 GObject parent;
158
159 LttvTraceContext *t_context;
160 gboolean control;
dbb7bb09 161 guint index; /* in ts_context->tracefiles */
ffd54a90 162 LttTracefile *tf;
ffd54a90 163 LttEvent *e;
8697a616 164 LttvHooks *event;
165 LttvHooksById *event_by_id;
ffd54a90 166 LttTime timestamp;
dc877563 167 LttvAttribute *a;
168};
169
170struct _LttvTracefileContextClass {
171 GObjectClass parent;
172};
173
174GType lttv_tracefile_context_get_type (void);
175
2a2fa4f0 176/* Run through the events in a traceset in sorted order calling all the
177 hooks appropriately. It starts at the current time and runs until end or
178 nb_events are processed. */
179
308711e5 180void lttv_process_traceset(LttvTracesetContext *self, LttTime end,
2a2fa4f0 181 unsigned nb_events);
182
8697a616 183/* Process traceset can also be done in smaller pieces calling begin,
184 * then seek and middle repeatedly, and end. The middle function return the
185 * number of events processed. It will be smaller than nb_events if the end time
186 * or end position is reached. */
2a2fa4f0 187
2a2fa4f0 188
8697a616 189void lttv_process_traceset_begin(LttvTracesetContext *self,
190 LttvHooks *before_traceset,
191 LttvHooks *before_trace,
192 LttvHooks *before_tracefile,
193 LttvHooks *event,
194 LttvHooksById *event_by_id);
195
2a2fa4f0 196
8697a616 197guint lttv_process_traceset_middle(LttvTracesetContext *self,
198 LttTime end,
b8eccacd 199 guint nb_events,
8697a616 200 const LttvTracesetContextPosition *end_position);
201
202void lttv_process_traceset_end(LttvTracesetContext *self,
203 LttvHooks *after_traceset,
204 LttvHooks *after_trace,
205 LttvHooks *after_tracefile,
206 LttvHooks *event,
207 LttvHooksById *event_by_id);
2a2fa4f0 208
308711e5 209
210void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start);
211
8697a616 212gboolean lttv_process_traceset_seek_position(LttvTracesetContext *self,
213 const LttvTracesetContextPosition *pos);
214
308711e5 215void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start);
dc877563 216
217void lttv_traceset_context_add_hooks(LttvTracesetContext *self,
8697a616 218 LttvHooks *before_traceset,
dc877563 219 LttvHooks *before_trace,
ffd54a90 220 LttvHooks *before_tracefile,
8697a616 221 LttvHooks *event,
222 LttvHooksById *event_by_id);
dc877563 223
224void lttv_traceset_context_remove_hooks(LttvTracesetContext *self,
dc877563 225 LttvHooks *after_traceset,
dc877563 226 LttvHooks *after_trace,
ffd54a90 227 LttvHooks *after_tracefile,
8697a616 228 LttvHooks *event,
229 LttvHooksById *event_by_id);
dc877563 230
a8c0f09d 231void lttv_trace_context_add_hooks(LttvTraceContext *self,
8697a616 232 LttvHooks *before_trace,
233 LttvHooks *before_tracefile,
234 LttvHooks *event,
235 LttvHooksById *event_by_id);
a8c0f09d 236
237void lttv_trace_context_remove_hooks(LttvTraceContext *self,
8697a616 238 LttvHooks *after_trace,
239 LttvHooks *after_tracefile,
240 LttvHooks *event,
241 LttvHooksById *event_by_id);
a8c0f09d 242
243void lttv_tracefile_context_add_hooks(LttvTracefileContext *self,
8697a616 244 LttvHooks *before_tracefile,
245 LttvHooks *event,
246 LttvHooksById *event_by_id);
247
a8c0f09d 248
249void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self,
8697a616 250 LttvHooks *after_tracefile,
251 LttvHooks *event,
252 LttvHooksById *event_by_id);
253
a8c0f09d 254
255void lttv_tracefile_context_add_hooks_by_id(LttvTracefileContext *self,
256 unsigned i,
8697a616 257 LttvHooks *event_by_id);
a8c0f09d 258
259void lttv_tracefile_context_remove_hooks_by_id(LttvTracefileContext *self,
260 unsigned i);
261
b445142a 262typedef struct _LttvTraceHook {
263 LttvHook h;
264 guint id;
265 LttField *f1;
266 LttField *f2;
267 LttField *f3;
268} LttvTraceHook;
269
270
271/* Search in the trace for the id of the named event type within the named
272 facility. Then, find the three (if non null) named fields. All that
273 information is then used to fill the LttvTraceHook structure. This
274 is useful to find the specific id for an event within a trace, for
275 registering a hook using this structure as event data;
276 it already contains the (up to three) needed fields handles. */
277
278void lttv_trace_find_hook(LttTrace *t, char *facility, char *event_type,
279 char *field1, char *field2, char *field3, LttvHook h, LttvTraceHook *th);
280
8697a616 281
2d262115 282LttvTracefileContext *lttv_traceset_context_get_current_tfc(
283 LttvTracesetContext *self);
284
8697a616 285void lttv_traceset_context_position_save(const LttvTracesetContext *self,
286 LttvTracesetContextPosition *pos);
287
288void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos);
289
290gint lttv_traceset_context_pos_pos_compare(
291 const LttvTracesetContextPosition *pos1,
292 const LttvTracesetContextPosition *pos2);
293
294gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self,
295 const LttvTracesetContextPosition *pos);
296
297gint lttv_traceset_context_pos_pos_compare(const LttvTracesetContextPosition *a,
298 const LttvTracesetContextPosition *b);
2d262115 299LttTime lttv_traceset_context_position_get_time(
300 const LttvTracesetContextPosition *pos);
dc877563 301#endif // PROCESSTRACE_H
This page took 0.039011 seconds and 4 git commands to generate.