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