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