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