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 | |
4e4d11b3 |
19 | #ifdef HAVE_CONFIG_H |
20 | #include <config.h> |
21 | #endif |
22 | |
00e74b69 |
23 | #include <string.h> |
d8f124de |
24 | #include <lttv/tracecontext.h> |
ffd54a90 |
25 | #include <ltt/event.h> |
b445142a |
26 | #include <ltt/facility.h> |
a5dcde2f |
27 | #include <ltt/trace.h> |
28 | #include <ltt/type.h> |
33e44b82 |
29 | #include <lttv/filter.h> |
27304273 |
30 | #include <errno.h> |
dc877563 |
31 | |
0bd2f89c |
32 | #define min(a,b) (((a)<(b))?(a):(b)) |
8697a616 |
33 | |
34 | |
27304273 |
35 | gint compare_tracefile(gconstpointer a, gconstpointer b) |
8697a616 |
36 | { |
cf94ff67 |
37 | gint comparison = 0; |
8697a616 |
38 | |
00e74b69 |
39 | const LttvTracefileContext *trace_a = (const LttvTracefileContext *)a; |
00e74b69 |
40 | const LttvTracefileContext *trace_b = (const LttvTracefileContext *)b; |
8697a616 |
41 | |
1d1df11d |
42 | if(likely(trace_a != trace_b)) { |
8fe3c6b6 |
43 | comparison = ltt_time_compare(trace_a->timestamp, trace_b->timestamp); |
1d1df11d |
44 | if(unlikely(comparison == 0)) { |
a855f059 |
45 | if(trace_a->index < trace_b->index) comparison = -1; |
46 | else if(trace_a->index > trace_b->index) comparison = 1; |
47 | else if(trace_a->t_context->index < trace_b->t_context->index) |
48 | comparison = -1; |
49 | else if(trace_a->t_context->index > trace_b->t_context->index) |
50 | comparison = 1; |
51 | } |
cf94ff67 |
52 | } |
cf94ff67 |
53 | return comparison; |
8697a616 |
54 | } |
55 | |
9ba3aaaf |
56 | typedef struct _LttvTracefileContextPosition { |
57 | LttEventPosition *event; |
58 | LttvTracefileContext *tfc; |
59 | gboolean used; /* Tells if the tfc is at end of traceset position */ |
60 | } LttvTracefileContextPosition; |
61 | |
62 | |
8697a616 |
63 | struct _LttvTracesetContextPosition { |
9ba3aaaf |
64 | GArray *tfcp; /* Array of LttvTracefileContextPosition */ |
18c87975 |
65 | LttTime timestamp; /* Current time at the saved position */ |
66 | /* If ltt_time_infinite : no position is |
67 | * set, else, a position is set (may be end |
68 | * of trace, with ep->len == 0) */ |
8697a616 |
69 | }; |
70 | |
ffd54a90 |
71 | void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts) |
dc877563 |
72 | { |
ffd54a90 |
73 | LTTV_TRACESET_CONTEXT_GET_CLASS(self)->init(self, ts); |
dc877563 |
74 | } |
75 | |
76 | |
77 | void lttv_context_fini(LttvTracesetContext *self) |
78 | { |
79 | LTTV_TRACESET_CONTEXT_GET_CLASS(self)->fini(self); |
80 | } |
81 | |
82 | |
83 | LttvTracesetContext * |
84 | lttv_context_new_traceset_context(LttvTracesetContext *self) |
85 | { |
86 | return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_traceset_context(self); |
87 | } |
88 | |
89 | |
90 | |
91 | |
92 | LttvTraceContext * |
93 | lttv_context_new_trace_context(LttvTracesetContext *self) |
94 | { |
95 | return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self); |
96 | } |
97 | |
98 | |
99 | LttvTracefileContext * |
100 | lttv_context_new_tracefile_context(LttvTracesetContext *self) |
101 | { |
c6bc9cb9 |
102 | return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self); |
dc877563 |
103 | } |
104 | |
f7afe191 |
105 | /**************************************************************************** |
106 | * lttv_traceset_context_compute_time_span |
107 | * |
8697a616 |
108 | * Keep the time span is sync with on the fly addition and removal of traces |
f7afe191 |
109 | * in a trace set. It must be called each time a trace is added/removed from |
110 | * the traceset. It could be more efficient to call it only once a bunch |
111 | * of traces are loaded, but the calculation is not long, so it's not |
112 | * critical. |
113 | * |
114 | * Author : Xang Xiu Yang |
f7afe191 |
115 | ***************************************************************************/ |
116 | static void lttv_traceset_context_compute_time_span( |
117 | LttvTracesetContext *self, |
33f7a12c |
118 | TimeInterval *time_span) |
f7afe191 |
119 | { |
120 | LttvTraceset * traceset = self->ts; |
121 | int numTraces = lttv_traceset_number(traceset); |
122 | int i; |
123 | LttTime s, e; |
124 | LttvTraceContext *tc; |
125 | LttTrace * trace; |
126 | |
33f7a12c |
127 | time_span->start_time.tv_sec = 0; |
128 | time_span->start_time.tv_nsec = 0; |
129 | time_span->end_time.tv_sec = 0; |
130 | time_span->end_time.tv_nsec = 0; |
912be9a5 |
131 | |
f7afe191 |
132 | for(i=0; i<numTraces;i++){ |
133 | tc = self->traces[i]; |
134 | trace = tc->t; |
135 | |
136 | ltt_trace_time_span_get(trace, &s, &e); |
14aecf75 |
137 | tc->time_span.start_time = s; |
138 | tc->time_span.end_time = e; |
f7afe191 |
139 | |
140 | if(i==0){ |
33f7a12c |
141 | time_span->start_time = s; |
142 | time_span->end_time = e; |
f7afe191 |
143 | }else{ |
33f7a12c |
144 | if(s.tv_sec < time_span->start_time.tv_sec |
145 | || (s.tv_sec == time_span->start_time.tv_sec |
146 | && s.tv_nsec < time_span->start_time.tv_nsec)) |
147 | time_span->start_time = s; |
148 | if(e.tv_sec > time_span->end_time.tv_sec |
149 | || (e.tv_sec == time_span->end_time.tv_sec |
150 | && e.tv_nsec > time_span->end_time.tv_nsec)) |
151 | time_span->end_time = e; |
f7afe191 |
152 | } |
153 | } |
154 | } |
155 | |
eed2ef37 |
156 | static void init_tracefile_context(LttTracefile *tracefile, |
157 | LttvTraceContext *tc) |
158 | { |
159 | LttvTracefileContext *tfc; |
160 | LttvTracesetContext *tsc = tc->ts_context; |
161 | |
162 | tfc = LTTV_TRACESET_CONTEXT_GET_CLASS(tsc)->new_tracefile_context(tsc); |
163 | |
164 | tfc->index = tc->tracefiles->len; |
165 | tc->tracefiles = g_array_append_val(tc->tracefiles, tfc); |
166 | |
167 | tfc->tf = tracefile; |
168 | |
169 | tfc->t_context = tc; |
170 | tfc->event = lttv_hooks_new(); |
171 | tfc->event_by_id = lttv_hooks_by_id_new(); |
172 | tfc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
173 | } |
174 | |
dc877563 |
175 | |
176 | static void |
177 | init(LttvTracesetContext *self, LttvTraceset *ts) |
178 | { |
327a4314 |
179 | guint i, nb_trace; |
dc877563 |
180 | |
181 | LttvTraceContext *tc; |
182 | |
3865ea09 |
183 | GData **tracefiles_groups; |
dc877563 |
184 | |
eed2ef37 |
185 | struct compute_tracefile_group_args args; |
308711e5 |
186 | |
dc877563 |
187 | nb_trace = lttv_traceset_number(ts); |
188 | self->ts = ts; |
ffd54a90 |
189 | self->traces = g_new(LttvTraceContext *, nb_trace); |
ffd54a90 |
190 | self->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
308711e5 |
191 | self->ts_a = lttv_traceset_attribute(ts); |
dc877563 |
192 | for(i = 0 ; i < nb_trace ; i++) { |
ffd54a90 |
193 | tc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self); |
dc877563 |
194 | self->traces[i] = tc; |
195 | |
196 | tc->ts_context = self; |
197 | tc->index = i; |
308711e5 |
198 | tc->vt = lttv_traceset_get(ts, i); |
199 | tc->t = lttv_trace(tc->vt); |
ffd54a90 |
200 | tc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
308711e5 |
201 | tc->t_a = lttv_trace_attribute(tc->vt); |
3865ea09 |
202 | tc->tracefiles = g_array_sized_new(FALSE, TRUE, |
203 | sizeof(LttvTracefileContext*), 10); |
eed2ef37 |
204 | |
205 | tracefiles_groups = ltt_trace_get_tracefiles_groups(tc->t); |
e45551ac |
206 | if(tracefiles_groups != NULL) { |
207 | args.func = (ForEachTraceFileFunc)init_tracefile_context; |
208 | args.func_args = tc; |
eed2ef37 |
209 | |
e45551ac |
210 | g_datalist_foreach(tracefiles_groups, |
211 | (GDataForeachFunc)compute_tracefile_group, |
212 | &args); |
213 | } |
eed2ef37 |
214 | |
215 | #if 0 |
dc877563 |
216 | nb_control = ltt_trace_control_tracefile_number(tc->t); |
217 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); |
218 | nb_tracefile = nb_control + nb_per_cpu; |
dbb7bb09 |
219 | tc->tracefiles = g_new(LttvTracefileContext *, nb_tracefile); |
dc877563 |
220 | |
221 | for(j = 0 ; j < nb_tracefile ; j++) { |
ffd54a90 |
222 | tfc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self); |
dbb7bb09 |
223 | tc->tracefiles[j] = tfc; |
224 | tfc->index = j; |
225 | |
dc877563 |
226 | if(j < nb_control) { |
dc877563 |
227 | tfc->control = TRUE; |
ffd54a90 |
228 | tfc->tf = ltt_trace_control_tracefile_get(tc->t, j); |
dc877563 |
229 | } |
230 | else { |
dc877563 |
231 | tfc->control = FALSE; |
ffd54a90 |
232 | tfc->tf = ltt_trace_per_cpu_tracefile_get(tc->t, j - nb_control); |
dc877563 |
233 | } |
eed2ef37 |
234 | |
dc877563 |
235 | tfc->t_context = tc; |
d3e01c7a |
236 | tfc->e = ltt_event_new(); |
8697a616 |
237 | tfc->event = lttv_hooks_new(); |
238 | tfc->event_by_id = lttv_hooks_by_id_new(); |
ffd54a90 |
239 | tfc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
dc877563 |
240 | } |
eed2ef37 |
241 | #endif //0 |
242 | |
dc877563 |
243 | } |
9ba3aaaf |
244 | self->sync_position = lttv_traceset_context_position_new(self); |
2d262115 |
245 | self->pqueue = g_tree_new(compare_tracefile); |
eed2ef37 |
246 | lttv_process_traceset_seek_time(self, ltt_time_zero); |
33f7a12c |
247 | lttv_traceset_context_compute_time_span(self, &self->time_span); |
8697a616 |
248 | |
dc877563 |
249 | } |
250 | |
251 | |
252 | void fini(LttvTracesetContext *self) |
253 | { |
dbb7bb09 |
254 | guint i, j, nb_trace, nb_tracefile; |
dc877563 |
255 | |
256 | LttvTraceContext *tc; |
257 | |
1986f254 |
258 | LttvTracefileContext **tfc; |
dc877563 |
259 | |
ffd54a90 |
260 | LttvTraceset *ts = self->ts; |
dc877563 |
261 | |
8697a616 |
262 | g_tree_destroy(self->pqueue); |
2061e03d |
263 | g_object_unref(self->a); |
18c87975 |
264 | lttv_traceset_context_position_destroy(self->sync_position); |
dc877563 |
265 | |
266 | nb_trace = lttv_traceset_number(ts); |
267 | |
268 | for(i = 0 ; i < nb_trace ; i++) { |
269 | tc = self->traces[i]; |
270 | |
ffd54a90 |
271 | g_object_unref(tc->a); |
dc877563 |
272 | |
eed2ef37 |
273 | nb_tracefile = tc->tracefiles->len; |
dc877563 |
274 | |
275 | for(j = 0 ; j < nb_tracefile ; j++) { |
1986f254 |
276 | tfc = &g_array_index(tc->tracefiles, LttvTracefileContext*, j); |
277 | lttv_hooks_destroy((*tfc)->event); |
278 | lttv_hooks_by_id_destroy((*tfc)->event_by_id); |
279 | g_object_unref((*tfc)->a); |
280 | g_object_unref(*tfc); |
dc877563 |
281 | } |
eed2ef37 |
282 | g_array_free(tc->tracefiles, TRUE); |
dc877563 |
283 | g_object_unref(tc); |
284 | } |
285 | g_free(self->traces); |
286 | } |
287 | |
288 | |
289 | void lttv_traceset_context_add_hooks(LttvTracesetContext *self, |
8697a616 |
290 | LttvHooks *before_traceset, |
dc877563 |
291 | LttvHooks *before_trace, |
ffd54a90 |
292 | LttvHooks *before_tracefile, |
8697a616 |
293 | LttvHooks *event, |
294 | LttvHooksById *event_by_id) |
dc877563 |
295 | { |
296 | LttvTraceset *ts = self->ts; |
297 | |
8697a616 |
298 | guint i, nb_trace; |
dc877563 |
299 | |
300 | LttvTraceContext *tc; |
301 | |
8697a616 |
302 | lttv_hooks_call(before_traceset, self); |
dc877563 |
303 | |
dc877563 |
304 | nb_trace = lttv_traceset_number(ts); |
305 | |
306 | for(i = 0 ; i < nb_trace ; i++) { |
307 | tc = self->traces[i]; |
8697a616 |
308 | lttv_trace_context_add_hooks(tc, |
309 | before_trace, |
310 | before_tracefile, |
311 | event, |
312 | event_by_id); |
dc877563 |
313 | } |
314 | } |
315 | |
316 | |
317 | void lttv_traceset_context_remove_hooks(LttvTracesetContext *self, |
dc877563 |
318 | LttvHooks *after_traceset, |
dc877563 |
319 | LttvHooks *after_trace, |
ffd54a90 |
320 | LttvHooks *after_tracefile, |
8697a616 |
321 | LttvHooks *event, |
322 | LttvHooksById *event_by_id) |
dc877563 |
323 | { |
8697a616 |
324 | |
dc877563 |
325 | LttvTraceset *ts = self->ts; |
326 | |
8697a616 |
327 | guint i, nb_trace; |
dc877563 |
328 | |
329 | LttvTraceContext *tc; |
330 | |
dc877563 |
331 | nb_trace = lttv_traceset_number(ts); |
332 | |
333 | for(i = 0 ; i < nb_trace ; i++) { |
334 | tc = self->traces[i]; |
8697a616 |
335 | lttv_trace_context_remove_hooks(tc, |
336 | after_trace, |
337 | after_tracefile, |
338 | event, |
339 | event_by_id); |
dc877563 |
340 | } |
8697a616 |
341 | |
342 | lttv_hooks_call(after_traceset, self); |
343 | |
344 | |
dc877563 |
345 | } |
346 | |
8697a616 |
347 | void lttv_trace_context_add_hooks(LttvTraceContext *self, |
348 | LttvHooks *before_trace, |
349 | LttvHooks *before_tracefile, |
350 | LttvHooks *event, |
351 | LttvHooksById *event_by_id) |
a8c0f09d |
352 | { |
8697a616 |
353 | guint i, nb_tracefile; |
354 | |
1986f254 |
355 | LttvTracefileContext **tfc; |
8697a616 |
356 | |
357 | lttv_hooks_call(before_trace, self); |
eed2ef37 |
358 | |
359 | nb_tracefile = self->tracefiles->len; |
8697a616 |
360 | |
361 | for(i = 0 ; i < nb_tracefile ; i++) { |
1986f254 |
362 | tfc = &g_array_index(self->tracefiles, LttvTracefileContext*, i); |
363 | lttv_tracefile_context_add_hooks(*tfc, |
8697a616 |
364 | before_tracefile, |
365 | event, |
366 | event_by_id); |
367 | } |
a8c0f09d |
368 | } |
369 | |
8697a616 |
370 | |
371 | |
372 | void lttv_trace_context_remove_hooks(LttvTraceContext *self, |
373 | LttvHooks *after_trace, |
374 | LttvHooks *after_tracefile, |
375 | LttvHooks *event, |
376 | LttvHooksById *event_by_id) |
a8c0f09d |
377 | { |
8697a616 |
378 | guint i, nb_tracefile; |
379 | |
1986f254 |
380 | LttvTracefileContext **tfc; |
8697a616 |
381 | |
eed2ef37 |
382 | nb_tracefile = self->tracefiles->len; |
8697a616 |
383 | |
384 | for(i = 0 ; i < nb_tracefile ; i++) { |
1986f254 |
385 | tfc = &g_array_index(self->tracefiles, LttvTracefileContext*, i); |
386 | lttv_tracefile_context_remove_hooks(*tfc, |
8697a616 |
387 | after_tracefile, |
388 | event, |
389 | event_by_id); |
390 | } |
391 | |
392 | lttv_hooks_call(after_trace, self); |
a8c0f09d |
393 | } |
394 | |
8697a616 |
395 | void lttv_tracefile_context_add_hooks(LttvTracefileContext *self, |
396 | LttvHooks *before_tracefile, |
397 | LttvHooks *event, |
398 | LttvHooksById *event_by_id) |
a8c0f09d |
399 | { |
9d239bd9 |
400 | guint i, index; |
8697a616 |
401 | |
402 | LttvHooks *hook; |
403 | |
404 | lttv_hooks_call(before_tracefile, self); |
405 | lttv_hooks_add_list(self->event, event); |
9d239bd9 |
406 | if(event_by_id != NULL) { |
407 | for(i = 0; i < event_by_id->array->len; i++) { |
408 | index = g_array_index(event_by_id->array, guint, i); |
409 | hook = lttv_hooks_by_id_find(self->event_by_id, index); |
410 | lttv_hooks_add_list(hook, lttv_hooks_by_id_get(event_by_id, index)); |
8697a616 |
411 | } |
9d239bd9 |
412 | } |
a8c0f09d |
413 | } |
414 | |
8697a616 |
415 | void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self, |
416 | LttvHooks *after_tracefile, |
417 | LttvHooks *event, |
418 | LttvHooksById *event_by_id) |
a8c0f09d |
419 | { |
9d239bd9 |
420 | guint i, index; |
8697a616 |
421 | |
422 | LttvHooks *hook; |
423 | |
8697a616 |
424 | lttv_hooks_remove_list(self->event, event); |
9d239bd9 |
425 | if(event_by_id != NULL) { |
426 | for(i = 0; i < event_by_id->array->len; i++) { |
427 | index = g_array_index(event_by_id->array, guint, i); |
428 | hook = lttv_hooks_by_id_get(self->event_by_id, index); |
41a9e0c3 |
429 | if(hook != NULL) |
9d239bd9 |
430 | lttv_hooks_remove_list(hook, lttv_hooks_by_id_get(event_by_id, index)); |
8697a616 |
431 | } |
9d239bd9 |
432 | } |
8697a616 |
433 | |
434 | lttv_hooks_call(after_tracefile, self); |
a8c0f09d |
435 | } |
436 | |
8697a616 |
437 | |
438 | |
a8c0f09d |
439 | void lttv_tracefile_context_add_hooks_by_id(LttvTracefileContext *tfc, |
440 | unsigned i, |
8697a616 |
441 | LttvHooks *event_by_id) |
a8c0f09d |
442 | { |
443 | LttvHooks * h; |
8697a616 |
444 | h = lttv_hooks_by_id_find(tfc->event_by_id, i); |
445 | lttv_hooks_add_list(h, event_by_id); |
a8c0f09d |
446 | } |
447 | |
448 | void lttv_tracefile_context_remove_hooks_by_id(LttvTracefileContext *tfc, |
449 | unsigned i) |
450 | { |
8697a616 |
451 | lttv_hooks_by_id_remove(tfc->event_by_id, i); |
a8c0f09d |
452 | } |
dc877563 |
453 | |
ba576a78 |
454 | static LttvTracesetContext * |
dc877563 |
455 | new_traceset_context(LttvTracesetContext *self) |
456 | { |
ffd54a90 |
457 | return g_object_new(LTTV_TRACESET_CONTEXT_TYPE, NULL); |
dc877563 |
458 | } |
459 | |
460 | |
ba576a78 |
461 | static LttvTraceContext * |
dc877563 |
462 | new_trace_context(LttvTracesetContext *self) |
463 | { |
ffd54a90 |
464 | return g_object_new(LTTV_TRACE_CONTEXT_TYPE, NULL); |
dc877563 |
465 | } |
466 | |
467 | |
ba576a78 |
468 | static LttvTracefileContext * |
dc877563 |
469 | new_tracefile_context(LttvTracesetContext *self) |
470 | { |
ffd54a90 |
471 | return g_object_new(LTTV_TRACEFILE_CONTEXT_TYPE, NULL); |
dc877563 |
472 | } |
473 | |
474 | |
475 | static void |
476 | traceset_context_instance_init (GTypeInstance *instance, gpointer g_class) |
477 | { |
478 | /* Be careful of anything which would not work well with shallow copies */ |
479 | } |
480 | |
481 | |
482 | static void |
483 | traceset_context_finalize (LttvTracesetContext *self) |
484 | { |
b445142a |
485 | G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACESET_CONTEXT_TYPE))) |
486 | ->finalize(G_OBJECT(self)); |
dc877563 |
487 | } |
488 | |
489 | |
490 | static void |
491 | traceset_context_class_init (LttvTracesetContextClass *klass) |
492 | { |
493 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
494 | |
ffd54a90 |
495 | gobject_class->finalize = (void (*)(GObject *self))traceset_context_finalize; |
dc877563 |
496 | klass->init = init; |
497 | klass->fini = fini; |
498 | klass->new_traceset_context = new_traceset_context; |
499 | klass->new_trace_context = new_trace_context; |
500 | klass->new_tracefile_context = new_tracefile_context; |
501 | } |
502 | |
503 | |
504 | GType |
ffd54a90 |
505 | lttv_traceset_context_get_type(void) |
dc877563 |
506 | { |
507 | static GType type = 0; |
508 | if (type == 0) { |
509 | static const GTypeInfo info = { |
ffd54a90 |
510 | sizeof (LttvTracesetContextClass), |
dc877563 |
511 | NULL, /* base_init */ |
512 | NULL, /* base_finalize */ |
ffd54a90 |
513 | (GClassInitFunc) traceset_context_class_init, /* class_init */ |
dc877563 |
514 | NULL, /* class_finalize */ |
515 | NULL, /* class_data */ |
ffd54a90 |
516 | sizeof (LttvTracesetContext), |
dc877563 |
517 | 0, /* n_preallocs */ |
00e74b69 |
518 | (GInstanceInitFunc) traceset_context_instance_init, /* instance_init */ |
519 | NULL /* Value handling */ |
dc877563 |
520 | }; |
521 | |
ffd54a90 |
522 | type = g_type_register_static (G_TYPE_OBJECT, "LttvTracesetContextType", |
dc877563 |
523 | &info, 0); |
524 | } |
525 | return type; |
526 | } |
527 | |
528 | |
529 | static void |
530 | trace_context_instance_init (GTypeInstance *instance, gpointer g_class) |
531 | { |
532 | /* Be careful of anything which would not work well with shallow copies */ |
533 | } |
534 | |
535 | |
536 | static void |
537 | trace_context_finalize (LttvTraceContext *self) |
538 | { |
b445142a |
539 | G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACE_CONTEXT_TYPE)))-> |
540 | finalize(G_OBJECT(self)); |
dc877563 |
541 | } |
542 | |
543 | |
544 | static void |
545 | trace_context_class_init (LttvTraceContextClass *klass) |
546 | { |
547 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
548 | |
ffd54a90 |
549 | gobject_class->finalize = (void (*)(GObject *self)) trace_context_finalize; |
dc877563 |
550 | } |
551 | |
552 | |
553 | GType |
ffd54a90 |
554 | lttv_trace_context_get_type(void) |
dc877563 |
555 | { |
556 | static GType type = 0; |
557 | if (type == 0) { |
558 | static const GTypeInfo info = { |
ffd54a90 |
559 | sizeof (LttvTraceContextClass), |
dc877563 |
560 | NULL, /* base_init */ |
561 | NULL, /* base_finalize */ |
ffd54a90 |
562 | (GClassInitFunc) trace_context_class_init, /* class_init */ |
dc877563 |
563 | NULL, /* class_finalize */ |
564 | NULL, /* class_data */ |
c6bc9cb9 |
565 | sizeof (LttvTraceContext), |
dc877563 |
566 | 0, /* n_preallocs */ |
00e74b69 |
567 | (GInstanceInitFunc) trace_context_instance_init, /* instance_init */ |
568 | NULL /* Value handling */ |
dc877563 |
569 | }; |
570 | |
ffd54a90 |
571 | type = g_type_register_static (G_TYPE_OBJECT, "LttvTraceContextType", |
dc877563 |
572 | &info, 0); |
573 | } |
574 | return type; |
575 | } |
576 | |
577 | |
578 | static void |
579 | tracefile_context_instance_init (GTypeInstance *instance, gpointer g_class) |
580 | { |
581 | /* Be careful of anything which would not work well with shallow copies */ |
582 | } |
583 | |
584 | |
585 | static void |
586 | tracefile_context_finalize (LttvTracefileContext *self) |
587 | { |
b445142a |
588 | G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACEFILE_CONTEXT_TYPE))) |
589 | ->finalize(G_OBJECT(self)); |
dc877563 |
590 | } |
591 | |
592 | |
593 | static void |
594 | tracefile_context_class_init (LttvTracefileContextClass *klass) |
595 | { |
596 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
597 | |
ffd54a90 |
598 | gobject_class->finalize = (void (*)(GObject *self))tracefile_context_finalize; |
599 | } |
600 | |
601 | |
602 | GType |
603 | lttv_tracefile_context_get_type(void) |
604 | { |
605 | static GType type = 0; |
606 | if (type == 0) { |
607 | static const GTypeInfo info = { |
608 | sizeof (LttvTracefileContextClass), |
609 | NULL, /* base_init */ |
610 | NULL, /* base_finalize */ |
611 | (GClassInitFunc) tracefile_context_class_init, /* class_init */ |
612 | NULL, /* class_finalize */ |
613 | NULL, /* class_data */ |
614 | sizeof (LttvTracefileContext), |
615 | 0, /* n_preallocs */ |
00e74b69 |
616 | (GInstanceInitFunc) tracefile_context_instance_init, /* instance_init */ |
617 | NULL /* Value handling */ |
ffd54a90 |
618 | }; |
619 | |
620 | type = g_type_register_static (G_TYPE_OBJECT, "LttvTracefileContextType", |
621 | &info, 0); |
622 | } |
623 | return type; |
dc877563 |
624 | } |
625 | |
626 | |
dc877563 |
627 | |
6843100a |
628 | static gboolean get_first(gpointer key, gpointer value, gpointer user_data) { |
77199e93 |
629 | g_assert(key == value); |
dc877563 |
630 | *((LttvTracefileContext **)user_data) = (LttvTracefileContext *)value; |
631 | return TRUE; |
632 | } |
633 | |
e7f5e89d |
634 | #ifdef DEBUG |
635 | // Test to see if pqueue is traversed in the right order. |
636 | static LttTime test_time; |
637 | |
698e81c2 |
638 | static gboolean test_tree(gpointer key, gpointer value, gpointer user_data) { |
639 | |
77199e93 |
640 | LttvTracefileContext *tfc = (LttvTracefileContext *)key; |
641 | |
642 | g_debug("Tracefile name %s, time %lu.%lu, tfi %u, ti %u", |
643 | g_quark_to_string(ltt_tracefile_name(tfc->tf)), |
644 | tfc->timestamp.tv_sec, tfc->timestamp.tv_nsec, |
645 | tfc->index, tfc->t_context->index); |
e7f5e89d |
646 | |
647 | if(user_data != NULL) { |
648 | if(((LttvTracefileContext *)user_data) == (LttvTracefileContext *)value) { |
649 | g_assert(compare_tracefile(user_data, value) == 0); |
650 | } else |
651 | g_assert(compare_tracefile(user_data, value) != 0); |
652 | } |
653 | g_assert(ltt_time_compare(test_time, tfc->timestamp) <= 0); |
654 | test_time.tv_sec = tfc->timestamp.tv_sec; |
655 | test_time.tv_nsec = tfc->timestamp.tv_nsec; |
77199e93 |
656 | |
77199e93 |
657 | |
658 | //g_assert(((LttvTracefileContext *)user_data) != (LttvTracefileContext *)value); |
698e81c2 |
659 | return FALSE; |
660 | } |
e7f5e89d |
661 | #endif //DEBUG |
698e81c2 |
662 | |
663 | |
dc877563 |
664 | |
8697a616 |
665 | void lttv_process_traceset_begin(LttvTracesetContext *self, |
666 | LttvHooks *before_traceset, |
667 | LttvHooks *before_trace, |
668 | LttvHooks *before_tracefile, |
669 | LttvHooks *event, |
670 | LttvHooksById *event_by_id) |
671 | { |
dc877563 |
672 | |
8697a616 |
673 | /* simply add hooks in context. _before hooks are called by add_hooks. */ |
674 | /* It calls all before_traceset, before_trace, and before_tracefile hooks. */ |
675 | lttv_traceset_context_add_hooks(self, |
676 | before_traceset, |
677 | before_trace, |
678 | before_tracefile, |
679 | event, |
680 | event_by_id); |
681 | |
2a2fa4f0 |
682 | } |
683 | |
36d36c9f |
684 | enum read_state { LAST_NONE, LAST_OK, LAST_EMPTY }; |
685 | |
8697a616 |
686 | /* Note : a _middle must be preceded from a _seek or another middle */ |
687 | guint lttv_process_traceset_middle(LttvTracesetContext *self, |
688 | LttTime end, |
b8eccacd |
689 | guint nb_events, |
8697a616 |
690 | const LttvTracesetContextPosition *end_position) |
2a2fa4f0 |
691 | { |
692 | GTree *pqueue = self->pqueue; |
693 | |
698e81c2 |
694 | guint fac_id, ev_id, id; |
2a2fa4f0 |
695 | |
2a2fa4f0 |
696 | LttvTracefileContext *tfc; |
697 | |
eed2ef37 |
698 | LttEvent *e; |
699 | |
2a2fa4f0 |
700 | unsigned count = 0; |
701 | |
36d36c9f |
702 | guint read_ret; |
703 | |
704 | enum read_state last_read_state = LAST_NONE; |
698e81c2 |
705 | |
a54f091a |
706 | gboolean last_ret = FALSE; /* return value of the last hook list called */ |
707 | |
dc877563 |
708 | /* Get the next event from the pqueue, call its hooks, |
709 | reinsert in the pqueue the following event from the same tracefile |
710 | unless the tracefile is finished or the event is later than the |
8697a616 |
711 | end time. */ |
dc877563 |
712 | |
ffd54a90 |
713 | while(TRUE) { |
dc877563 |
714 | tfc = NULL; |
715 | g_tree_foreach(pqueue, get_first, &tfc); |
33f7a12c |
716 | /* End of traceset : tfc is NULL */ |
1d1df11d |
717 | if(unlikely(tfc == NULL)) |
a43d67ba |
718 | { |
a43d67ba |
719 | return count; |
720 | } |
dc877563 |
721 | |
8697a616 |
722 | /* Have we reached : |
723 | * - the maximum number of events specified? |
724 | * - the end position ? |
725 | * - the end time ? |
726 | * then the read is finished. We leave the queue in the same state and |
727 | * break the loop. |
728 | */ |
729 | |
1d1df11d |
730 | if(unlikely(last_ret == TRUE || |
d052ffc3 |
731 | ((count >= nb_events) && (nb_events != G_MAXULONG)) || |
8b0bbe19 |
732 | (end_position!=NULL&<tv_traceset_context_ctx_pos_compare(self, |
733 | end_position) == 0)|| |
1d1df11d |
734 | ltt_time_compare(end, tfc->timestamp) <= 0)) |
a43d67ba |
735 | { |
a43d67ba |
736 | return count; |
737 | } |
36d36c9f |
738 | |
308711e5 |
739 | /* Get the tracefile with an event for the smallest time found. If two |
740 | or more tracefiles have events for the same time, hope that lookup |
741 | and remove are consistent. */ |
1986f254 |
742 | |
743 | #ifdef DEBUG |
e7f5e89d |
744 | test_time.tv_sec = 0; |
745 | test_time.tv_nsec = 0; |
77199e93 |
746 | g_debug("test tree before remove"); |
747 | g_tree_foreach(pqueue, test_tree, tfc); |
1986f254 |
748 | #endif //DEBUG |
f95bc830 |
749 | g_tree_remove(pqueue, tfc); |
698e81c2 |
750 | |
1986f254 |
751 | #ifdef DEBUG |
e7f5e89d |
752 | test_time.tv_sec = 0; |
753 | test_time.tv_nsec = 0; |
77199e93 |
754 | g_debug("test tree after remove"); |
698e81c2 |
755 | g_tree_foreach(pqueue, test_tree, tfc); |
1986f254 |
756 | #endif //DEBUG |
77199e93 |
757 | |
eed2ef37 |
758 | e = ltt_tracefile_get_event(tfc->tf); |
dc877563 |
759 | |
36d36c9f |
760 | if(last_read_state != LAST_EMPTY) { |
761 | /* Only call hooks if the last read has given an event or if we are at the |
762 | * first pass (not if last read returned end of tracefile) */ |
763 | count++; |
764 | |
765 | fac_id = ltt_event_facility_id(e); |
766 | ev_id = ltt_event_eventtype_id(e); |
767 | id = GET_HOOK_ID(fac_id, ev_id); |
768 | last_ret = lttv_hooks_call_merge(tfc->event, tfc, |
769 | lttv_hooks_by_id_get(tfc->event_by_id, id), tfc); |
770 | } |
771 | |
698e81c2 |
772 | read_ret = ltt_tracefile_read(tfc->tf); |
773 | |
774 | if(likely(!read_ret)) { |
3054461a |
775 | //g_debug("An event is ready"); |
eed2ef37 |
776 | tfc->timestamp = ltt_event_time(e); |
e7f5e89d |
777 | g_assert(ltt_time_compare(tfc->timestamp, ltt_time_infinite) != 0); |
33f7a12c |
778 | g_tree_insert(pqueue, tfc, tfc); |
e7f5e89d |
779 | #ifdef DEBUG |
780 | test_time.tv_sec = 0; |
781 | test_time.tv_nsec = 0; |
782 | g_debug("test tree after event ready"); |
783 | g_tree_foreach(pqueue, test_tree, NULL); |
784 | #endif //DEBUG |
785 | |
36d36c9f |
786 | last_read_state = LAST_OK; |
698e81c2 |
787 | } else { |
1986f254 |
788 | tfc->timestamp = ltt_time_infinite; |
789 | |
36d36c9f |
790 | if(read_ret == ERANGE) { |
791 | last_read_state = LAST_EMPTY; |
698e81c2 |
792 | g_debug("End of trace"); |
36d36c9f |
793 | } else |
698e81c2 |
794 | g_error("Error happened in lttv_process_traceset_middle"); |
dc877563 |
795 | } |
796 | } |
2a2fa4f0 |
797 | } |
798 | |
799 | |
8697a616 |
800 | void lttv_process_traceset_end(LttvTracesetContext *self, |
801 | LttvHooks *after_traceset, |
802 | LttvHooks *after_trace, |
803 | LttvHooks *after_tracefile, |
804 | LttvHooks *event, |
805 | LttvHooksById *event_by_id) |
2a2fa4f0 |
806 | { |
8697a616 |
807 | /* Remove hooks from context. _after hooks are called by remove_hooks. */ |
808 | /* It calls all after_traceset, after_trace, and after_tracefile hooks. */ |
809 | lttv_traceset_context_remove_hooks(self, |
810 | after_traceset, |
811 | after_trace, |
812 | after_tracefile, |
813 | event, |
814 | event_by_id); |
815 | } |
2a2fa4f0 |
816 | |
27304273 |
817 | /* Subtile modification : |
818 | * if tracefile has no event at or after the time requested, it is not put in |
348c6ba8 |
819 | * the queue, as the next read would fail. |
820 | * |
821 | * Don't forget to empty the traceset pqueue before calling this. |
822 | */ |
8697a616 |
823 | void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start) |
824 | { |
825 | guint i, nb_tracefile; |
2a2fa4f0 |
826 | |
eed2ef37 |
827 | gint ret; |
828 | |
1986f254 |
829 | LttvTracefileContext **tfc; |
2a2fa4f0 |
830 | |
eed2ef37 |
831 | nb_tracefile = self->tracefiles->len; |
dc877563 |
832 | |
e7f5e89d |
833 | GTree *pqueue = self->ts_context->pqueue; |
834 | |
8697a616 |
835 | for(i = 0 ; i < nb_tracefile ; i++) { |
1986f254 |
836 | tfc = &g_array_index(self->tracefiles, LttvTracefileContext*, i); |
77199e93 |
837 | |
e7f5e89d |
838 | //g_tree_remove(pqueue, *tfc); |
77199e93 |
839 | |
1986f254 |
840 | ret = ltt_tracefile_seek_time((*tfc)->tf, start); |
27304273 |
841 | if(ret == EPERM) g_error("error in lttv_process_trace_seek_time seek"); |
27304273 |
842 | |
843 | if(ret == 0) { /* not ERANGE especially */ |
1986f254 |
844 | (*tfc)->timestamp = ltt_event_time(ltt_tracefile_get_event((*tfc)->tf)); |
e7f5e89d |
845 | g_assert(ltt_time_compare((*tfc)->timestamp, ltt_time_infinite) != 0); |
1986f254 |
846 | g_tree_insert(pqueue, (*tfc), (*tfc)); |
847 | } else { |
848 | (*tfc)->timestamp = ltt_time_infinite; |
27304273 |
849 | } |
8697a616 |
850 | } |
e7f5e89d |
851 | #ifdef DEBUG |
852 | test_time.tv_sec = 0; |
853 | test_time.tv_nsec = 0; |
854 | g_debug("test tree after seek_time"); |
855 | g_tree_foreach(pqueue, test_tree, NULL); |
856 | #endif //DEBUG |
857 | |
858 | |
859 | |
8697a616 |
860 | } |
dc877563 |
861 | |
2a2fa4f0 |
862 | |
8697a616 |
863 | void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start) |
864 | { |
865 | guint i, nb_trace; |
2a2fa4f0 |
866 | |
8697a616 |
867 | LttvTraceContext *tc; |
2a2fa4f0 |
868 | |
348c6ba8 |
869 | g_tree_destroy(self->pqueue); |
870 | self->pqueue = g_tree_new(compare_tracefile); |
871 | |
8697a616 |
872 | nb_trace = lttv_traceset_number(self->ts); |
873 | for(i = 0 ; i < nb_trace ; i++) { |
874 | tc = self->traces[i]; |
875 | lttv_process_trace_seek_time(tc, start); |
876 | } |
dc877563 |
877 | } |
b445142a |
878 | |
308711e5 |
879 | |
8697a616 |
880 | gboolean lttv_process_traceset_seek_position(LttvTracesetContext *self, |
881 | const LttvTracesetContextPosition *pos) |
308711e5 |
882 | { |
27304273 |
883 | guint i; |
8697a616 |
884 | |
18c87975 |
885 | /* If a position is set, seek the traceset to this position */ |
886 | if(ltt_time_compare(pos->timestamp, ltt_time_infinite) != 0) { |
887 | g_tree_destroy(self->pqueue); |
888 | self->pqueue = g_tree_new(compare_tracefile); |
889 | |
9ba3aaaf |
890 | for(i=0;i<pos->tfcp->len; i++) { |
891 | LttvTracefileContextPosition *tfcp = |
892 | &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); |
893 | |
894 | |
895 | if(tfcp->used == TRUE) { |
896 | if(ltt_tracefile_seek_position(tfcp->tfc->tf, tfcp->event) != 0) |
18c87975 |
897 | return 1; |
9ba3aaaf |
898 | tfcp->tfc->timestamp = |
899 | ltt_event_time(ltt_tracefile_get_event(tfcp->tfc->tf)); |
900 | g_assert(ltt_time_compare(tfcp->tfc->timestamp, |
901 | ltt_time_infinite) != 0); |
902 | g_tree_insert(self->pqueue, tfcp->tfc, tfcp->tfc); |
903 | |
18c87975 |
904 | } else { |
9ba3aaaf |
905 | tfcp->tfc->timestamp = ltt_time_infinite; |
18c87975 |
906 | } |
1986f254 |
907 | } |
308711e5 |
908 | } |
e7f5e89d |
909 | #ifdef DEBUG |
910 | test_time.tv_sec = 0; |
911 | test_time.tv_nsec = 0; |
912 | g_debug("test tree after seek_position"); |
913 | g_tree_foreach(self->pqueue, test_tree, NULL); |
914 | #endif //DEBUG |
915 | |
916 | |
917 | |
2c82c4dc |
918 | return 0; |
308711e5 |
919 | } |
920 | |
921 | |
8697a616 |
922 | |
b445142a |
923 | static LttField * |
eed2ef37 |
924 | find_field(LttEventType *et, const GQuark field) |
b445142a |
925 | { |
926 | LttType *t; |
927 | |
928 | LttField *f; |
929 | |
930 | guint i, nb; |
931 | |
eed2ef37 |
932 | GQuark name; |
b445142a |
933 | |
eed2ef37 |
934 | /* Field is unset */ |
935 | if(field == 0) return NULL; |
936 | |
b445142a |
937 | f = ltt_eventtype_field(et); |
938 | t = ltt_eventtype_type(et); |
939 | g_assert(ltt_type_class(t) == LTT_STRUCT); |
940 | nb = ltt_type_member_number(t); |
941 | for(i = 0 ; i < nb ; i++) { |
942 | ltt_type_member_type(t, i, &name); |
eed2ef37 |
943 | if(name == field) break; |
b445142a |
944 | } |
945 | g_assert(i < nb); |
946 | return ltt_field_member(f, i); |
947 | } |
948 | |
eed2ef37 |
949 | LttvTraceHookByFacility *lttv_trace_hook_get_fac(LttvTraceHook *th, |
950 | guint facility_id) |
951 | { |
952 | return &g_array_index(th->fac_index, LttvTraceHookByFacility, facility_id); |
953 | } |
954 | |
955 | /* Get the first facility corresponding to the name. As the types must be |
956 | * compatible, it is relevant to use the field name and sizes of the first |
957 | * facility to create data structures and assume the data will be compatible |
958 | * thorough the trace */ |
959 | LttvTraceHookByFacility *lttv_trace_hook_get_first(LttvTraceHook *th) |
960 | { |
961 | g_assert(th->fac_list->len > 0); |
962 | return g_array_index(th->fac_list, LttvTraceHookByFacility*, 0); |
963 | } |
964 | |
b445142a |
965 | |
eed2ef37 |
966 | /* Returns 0 on success, -1 if fails. */ |
967 | gint |
968 | lttv_trace_find_hook(LttTrace *t, GQuark facility, GQuark event, |
2c82c4dc |
969 | GQuark field1, GQuark field2, GQuark field3, LttvHook h, gpointer hook_data, |
970 | LttvTraceHook *th) |
b445142a |
971 | { |
972 | LttFacility *f; |
973 | |
eed2ef37 |
974 | LttEventType *et, *first_et; |
975 | |
976 | GArray *facilities; |
977 | |
d052ffc3 |
978 | guint i, fac_id, ev_id; |
b445142a |
979 | |
eed2ef37 |
980 | LttvTraceHookByFacility *thf, *first_thf; |
b445142a |
981 | |
eed2ef37 |
982 | facilities = ltt_trace_facility_get_by_name(t, facility); |
021eeb41 |
983 | |
eed2ef37 |
984 | if(unlikely(facilities == NULL)) goto facility_error; |
985 | |
986 | th->fac_index = g_array_sized_new(FALSE, TRUE, |
987 | sizeof(LttvTraceHookByFacility), |
988 | NUM_FACILITIES); |
989 | th->fac_index = g_array_set_size(th->fac_index, NUM_FACILITIES); |
b445142a |
990 | |
eed2ef37 |
991 | th->fac_list = g_array_sized_new(FALSE, TRUE, |
992 | sizeof(LttvTraceHookByFacility*), |
993 | facilities->len); |
994 | th->fac_list = g_array_set_size(th->fac_list, facilities->len); |
995 | |
996 | fac_id = g_array_index(facilities, guint, 0); |
997 | f = ltt_trace_get_facility_by_num(t, fac_id); |
998 | |
cb03932a |
999 | et = ltt_facility_eventtype_get_by_name(f, event); |
eed2ef37 |
1000 | if(unlikely(et == NULL)) goto event_error; |
1001 | |
1002 | thf = &g_array_index(th->fac_index, LttvTraceHookByFacility, fac_id); |
1986f254 |
1003 | g_array_index(th->fac_list, LttvTraceHookByFacility*, 0) = thf; |
9d239bd9 |
1004 | |
d052ffc3 |
1005 | ev_id = ltt_eventtype_id(et); |
1006 | |
eed2ef37 |
1007 | thf->h = h; |
d052ffc3 |
1008 | thf->id = GET_HOOK_ID(fac_id, ev_id); |
eed2ef37 |
1009 | thf->f1 = find_field(et, field1); |
1010 | thf->f2 = find_field(et, field2); |
1011 | thf->f3 = find_field(et, field3); |
2c82c4dc |
1012 | thf->hook_data = hook_data; |
eed2ef37 |
1013 | |
1014 | first_thf = thf; |
826f1ab2 |
1015 | first_et = et; |
eed2ef37 |
1016 | |
1017 | /* Check for type compatibility too */ |
1018 | for(i=1;i<facilities->len;i++) { |
1019 | fac_id = g_array_index(facilities, guint, i); |
1020 | f = ltt_trace_get_facility_by_num(t, fac_id); |
1021 | |
f4b88a7d |
1022 | et = ltt_facility_eventtype_get_by_name(f, event); |
eed2ef37 |
1023 | if(unlikely(et == NULL)) goto event_error; |
1024 | |
1025 | thf = &g_array_index(th->fac_index, LttvTraceHookByFacility, fac_id); |
1986f254 |
1026 | g_array_index(th->fac_list, LttvTraceHookByFacility*, i) = thf; |
d052ffc3 |
1027 | ev_id = ltt_eventtype_id(et); |
eed2ef37 |
1028 | thf->h = h; |
d052ffc3 |
1029 | thf->id = GET_HOOK_ID(fac_id, ev_id); |
eed2ef37 |
1030 | thf->f1 = find_field(et, field1); |
1031 | if(check_fields_compatibility(first_et, et, |
1032 | first_thf->f1, thf->f1)) |
1033 | goto type_error; |
1034 | |
1035 | thf->f2 = find_field(et, field2); |
1036 | if(check_fields_compatibility(first_et, et, |
1037 | first_thf->f2, thf->f2)) |
1038 | goto type_error; |
1039 | |
1040 | thf->f3 = find_field(et, field3); |
1041 | if(check_fields_compatibility(first_et, et, |
1042 | first_thf->f3, thf->f3)) |
1043 | goto type_error; |
2c82c4dc |
1044 | thf->hook_data = hook_data; |
eed2ef37 |
1045 | } |
1046 | |
1047 | return 0; |
1048 | |
1049 | type_error: |
1050 | goto free; |
1051 | event_error: |
f4b88a7d |
1052 | g_error("Event type does not exist for event %s", |
1053 | g_quark_to_string(event)); |
eed2ef37 |
1054 | goto free; |
1055 | facility_error: |
1056 | g_error("No %s facility", g_quark_to_string(facility)); |
1057 | goto free; |
1058 | free: |
1059 | g_array_free(th->fac_index, TRUE); |
1060 | g_array_free(th->fac_list, TRUE); |
1061 | th->fac_index = NULL; |
1062 | th->fac_list = NULL; |
1063 | return -1; |
1064 | } |
1065 | |
1066 | void lttv_trace_hook_destroy(LttvTraceHook *th) |
1067 | { |
1068 | g_array_free(th->fac_index, TRUE); |
1069 | g_array_free(th->fac_list, TRUE); |
b445142a |
1070 | } |
1071 | |
1072 | |
9ba3aaaf |
1073 | |
1074 | |
1075 | LttvTracesetContextPosition *lttv_traceset_context_position_new( |
1076 | const LttvTracesetContext *self) |
5e2c04a2 |
1077 | { |
9ba3aaaf |
1078 | guint num_traces = lttv_traceset_number(self->ts); |
1079 | guint tf_count = 0; |
1080 | guint i; |
1081 | |
1082 | for(i=0; i<num_traces;i++) { |
1083 | GArray * tracefiles = self->traces[i]->tracefiles; |
1084 | guint j; |
1085 | guint num_tracefiles = tracefiles->len; |
1086 | for(j=0;j<num_tracefiles;j++) |
1087 | tf_count++; |
1088 | } |
1089 | LttvTracesetContextPosition *pos = |
1090 | g_new(LttvTracesetContextPosition, 1); |
1091 | pos->tfcp = g_array_sized_new(FALSE, TRUE, |
1092 | sizeof(LttvTracefileContextPosition), |
1093 | tf_count); |
1094 | g_array_set_size(pos->tfcp, tf_count); |
1095 | for(i=0;i<pos->tfcp->len;i++) { |
1096 | LttvTracefileContextPosition *tfcp = |
1097 | &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); |
1098 | tfcp->event = ltt_event_position_new(); |
1099 | } |
1100 | |
27304273 |
1101 | pos->timestamp = ltt_time_infinite; |
1102 | return pos; |
5e2c04a2 |
1103 | } |
1104 | |
3054461a |
1105 | /* Save all positions, the ones with infinite time will have NULL |
1986f254 |
1106 | * ep. */ |
9ba3aaaf |
1107 | /* note : a position must be destroyed when a trace is added/removed from a |
1108 | * traceset */ |
27304273 |
1109 | void lttv_traceset_context_position_save(const LttvTracesetContext *self, |
1110 | LttvTracesetContextPosition *pos) |
1111 | { |
1986f254 |
1112 | guint i; |
1113 | guint num_traces = lttv_traceset_number(self->ts); |
9ba3aaaf |
1114 | guint tf_count = 0; |
728d0c3e |
1115 | |
0bd2f89c |
1116 | pos->timestamp = ltt_time_infinite; |
728d0c3e |
1117 | |
1986f254 |
1118 | for(i=0; i<num_traces;i++) { |
1119 | GArray * tracefiles = self->traces[i]->tracefiles; |
1120 | guint j; |
1121 | guint num_tracefiles = tracefiles->len; |
1122 | |
1123 | for(j=0;j<num_tracefiles;j++) { |
9ba3aaaf |
1124 | g_assert(tf_count < pos->tfcp->len); |
1986f254 |
1125 | LttvTracefileContext **tfc = &g_array_index(tracefiles, |
1126 | LttvTracefileContext*, j); |
9ba3aaaf |
1127 | LttvTracefileContextPosition *tfcp = |
1128 | &g_array_index(pos->tfcp, LttvTracefileContextPosition, tf_count); |
1986f254 |
1129 | |
9ba3aaaf |
1130 | tfcp->tfc = *tfc; |
1986f254 |
1131 | |
1132 | if(ltt_time_compare((*tfc)->timestamp, ltt_time_infinite) != 0) { |
9ba3aaaf |
1133 | LttEvent *event = ltt_tracefile_get_event((*tfc)->tf); |
1134 | ltt_event_position(event, tfcp->event); |
1986f254 |
1135 | if(ltt_time_compare((*tfc)->timestamp, pos->timestamp) < 0) |
1136 | pos->timestamp = (*tfc)->timestamp; |
9ba3aaaf |
1137 | tfcp->used = TRUE; |
1986f254 |
1138 | } else { |
9ba3aaaf |
1139 | tfcp->used = FALSE; |
1986f254 |
1140 | } |
9ba3aaaf |
1141 | |
1142 | //g_array_append_val(pos->tfc, *tfc); |
1143 | //g_array_append_val(pos->ep, ep); |
1144 | tf_count++; |
1986f254 |
1145 | } |
1146 | |
1147 | } |
8697a616 |
1148 | } |
1149 | |
1150 | void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos) |
1151 | { |
27304273 |
1152 | int i; |
1986f254 |
1153 | |
9ba3aaaf |
1154 | for(i=0;i<pos->tfcp->len;i++) { |
1155 | LttvTracefileContextPosition *tfcp = |
1156 | &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); |
1157 | g_free(tfcp->event); |
1158 | tfcp->event = NULL; |
1159 | tfcp->used = FALSE; |
1986f254 |
1160 | } |
9ba3aaaf |
1161 | g_array_free(pos->tfcp, TRUE); |
27304273 |
1162 | g_free(pos); |
8697a616 |
1163 | } |
1164 | |
5e2c04a2 |
1165 | void lttv_traceset_context_position_copy(LttvTracesetContextPosition *dest, |
1166 | const LttvTracesetContextPosition *src) |
1167 | { |
27304273 |
1168 | int i; |
9ba3aaaf |
1169 | LttvTracefileContextPosition *src_tfcp, *dest_tfcp; |
5e2c04a2 |
1170 | |
9ba3aaaf |
1171 | g_assert(src->tfcp->len == src->tfcp->len); |
27304273 |
1172 | |
9ba3aaaf |
1173 | for(i=0;i<src->tfcp->len;i++) { |
1174 | src_tfcp = |
1175 | &g_array_index(src->tfcp, LttvTracefileContextPosition, i); |
1176 | dest_tfcp = |
1177 | &g_array_index(dest->tfcp, LttvTracefileContextPosition, i); |
1178 | |
1179 | dest_tfcp->used = src_tfcp->used; |
1180 | dest_tfcp->tfc = src_tfcp->tfc; |
1181 | |
1182 | if(src_tfcp->used) { |
1986f254 |
1183 | ltt_event_position_copy( |
9ba3aaaf |
1184 | dest_tfcp->event, |
1185 | src_tfcp->event); |
1186 | } |
5e2c04a2 |
1187 | } |
5e2c04a2 |
1188 | dest->timestamp = src->timestamp; |
1189 | } |
1190 | |
8697a616 |
1191 | gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self, |
1192 | const LttvTracesetContextPosition *pos) |
1193 | { |
27304273 |
1194 | int i; |
826f1ab2 |
1195 | int ret = 0; |
2c82c4dc |
1196 | |
9ba3aaaf |
1197 | if(pos->tfcp->len == 0) { |
2c82c4dc |
1198 | if(lttv_traceset_number(self->ts) == 0) return 0; |
1199 | else return 1; |
1200 | } |
1201 | if(lttv_traceset_number(self->ts) == 0) |
1202 | return -1; |
1203 | |
9ba3aaaf |
1204 | for(i=0;i<pos->tfcp->len;i++) { |
1205 | LttvTracefileContextPosition *tfcp = |
1206 | &g_array_index(pos->tfcp, LttvTracefileContextPosition, i); |
1986f254 |
1207 | |
9ba3aaaf |
1208 | if(tfcp->used == FALSE) { |
1209 | if(ltt_time_compare(tfcp->tfc->timestamp, ltt_time_infinite) < 0) { |
1986f254 |
1210 | ret = -1; |
1211 | } |
1212 | } else { |
9ba3aaaf |
1213 | if(ltt_time_compare(tfcp->tfc->timestamp, ltt_time_infinite) == 0) { |
1986f254 |
1214 | ret = 1; |
1215 | } else { |
9ba3aaaf |
1216 | LttEvent *event = ltt_tracefile_get_event(tfcp->tfc->tf); |
8697a616 |
1217 | |
1986f254 |
1218 | ret = ltt_event_position_compare((LttEventPosition*)event, |
9ba3aaaf |
1219 | tfcp->event); |
1986f254 |
1220 | } |
1221 | } |
27304273 |
1222 | if(ret != 0) return ret; |
8697a616 |
1223 | |
8697a616 |
1224 | } |
1225 | return 0; |
1226 | } |
1227 | |
1228 | |
1229 | gint lttv_traceset_context_pos_pos_compare( |
1230 | const LttvTracesetContextPosition *pos1, |
1231 | const LttvTracesetContextPosition *pos2) |
1232 | { |
27304273 |
1233 | int i, j; |
1234 | int ret; |
8697a616 |
1235 | |
9ba3aaaf |
1236 | if(pos1->tfcp->len == 0) { |
1237 | if(pos2->tfcp->len == 0) return 0; |
2c82c4dc |
1238 | else return 1; |
1239 | } |
9ba3aaaf |
1240 | if(pos2->tfcp->len == 0) |
2c82c4dc |
1241 | return -1; |
1242 | |
9ba3aaaf |
1243 | for(i=0;i<pos1->tfcp->len;i++) { |
1244 | LttvTracefileContextPosition *tfcp1 = |
1245 | &g_array_index(pos1->tfcp, LttvTracefileContextPosition, i); |
27304273 |
1246 | |
9ba3aaaf |
1247 | if(tfcp1->used == TRUE) { |
1248 | for(j=0;j<pos2->tfcp->len;j++) { |
1249 | LttvTracefileContextPosition *tfcp2 = |
1250 | &g_array_index(pos2->tfcp, LttvTracefileContextPosition, j); |
1251 | |
1252 | if(tfcp1->tfc == tfcp2->tfc) { |
1253 | if(tfcp2->used == TRUE) |
1254 | ret = ltt_event_position_compare(tfcp1->event, tfcp2->event); |
1986f254 |
1255 | else |
1256 | ret = -1; |
1257 | |
1258 | if(ret != 0) return ret; |
1259 | } |
1260 | } |
9ba3aaaf |
1261 | |
1986f254 |
1262 | } else { |
9ba3aaaf |
1263 | for(j=0;j<pos2->tfcp->len;j++) { |
1264 | LttvTracefileContextPosition *tfcp2 = |
1265 | &g_array_index(pos2->tfcp, LttvTracefileContextPosition, j); |
1266 | |
1267 | if(tfcp1->tfc == tfcp2->tfc) |
1268 | if(tfcp2->used == TRUE) ret = 1; |
1269 | if(ret != 0) return ret; |
27304273 |
1270 | } |
8697a616 |
1271 | } |
1272 | } |
1273 | return 0; |
1274 | } |
1275 | |
1276 | |
2d262115 |
1277 | LttTime lttv_traceset_context_position_get_time( |
1278 | const LttvTracesetContextPosition *pos) |
1279 | { |
1280 | return pos->timestamp; |
1281 | } |
1282 | |
1283 | |
1284 | LttvTracefileContext *lttv_traceset_context_get_current_tfc(LttvTracesetContext *self) |
1285 | { |
1286 | GTree *pqueue = self->pqueue; |
b56b5fec |
1287 | LttvTracefileContext *tfc = NULL; |
2d262115 |
1288 | |
1289 | g_tree_foreach(pqueue, get_first, &tfc); |
1290 | |
1291 | return tfc; |
1292 | } |
18c87975 |
1293 | |
2c82c4dc |
1294 | /* lttv_process_traceset_synchronize_tracefiles |
1295 | * |
1296 | * Use the sync_position field of the trace set context to synchronize each |
1297 | * tracefile with the previously saved position. |
1298 | * |
1299 | * If no previous position has been saved, it simply does nothing. |
1300 | */ |
1301 | void lttv_process_traceset_synchronize_tracefiles(LttvTracesetContext *tsc) |
1302 | { |
1303 | g_assert(lttv_process_traceset_seek_position(tsc, tsc->sync_position) == 0); |
1304 | } |
1305 | |
1306 | |
1307 | |
1308 | |
1309 | void lttv_process_traceset_get_sync_data(LttvTracesetContext *tsc) |
1310 | { |
1311 | lttv_traceset_context_position_save(tsc, tsc->sync_position); |
1312 | } |
1313 | |
0bd2f89c |
1314 | struct seek_back_data { |
1315 | guint first_event; /* Index of the first event in the array : we will always |
1316 | overwrite at this position : this is a circular array. |
1317 | */ |
1318 | guint events_found; |
33e44b82 |
1319 | guint n; /* number of events requested */ |
0bd2f89c |
1320 | GPtrArray *array; /* array of LttvTracesetContextPositions pointers */ |
33e44b82 |
1321 | LttvFilter *filter; |
0bd2f89c |
1322 | }; |
1323 | |
1324 | static gint seek_back_event_hook(void *hook_data, void* call_data) |
1325 | { |
1326 | struct seek_back_data *sd = (struct seek_back_data*)hook_data; |
1327 | LttvTracefileContext *tfc = (LttvTracefileContext*)call_data; |
1328 | LttvTracesetContext *tsc = tfc->t_context->ts_context; |
1329 | LttvTracesetContextPosition *pos; |
33e44b82 |
1330 | |
1331 | if(sd->filter != NULL) { |
1332 | if(!lttv_filter_tree_parse(sd->filter->head, |
1333 | ltt_tracefile_get_event(tfc->tf), |
1334 | tfc->tf, |
1335 | tfc->t_context->t, |
1336 | tfc)) |
1337 | return FALSE; |
0bd2f89c |
1338 | } |
33e44b82 |
1339 | |
1340 | pos = (LttvTracesetContextPosition*)g_ptr_array_index (sd->array, |
1341 | sd->first_event); |
0bd2f89c |
1342 | |
1343 | lttv_traceset_context_position_save(tsc, pos); |
1344 | |
1345 | if(sd->first_event >= sd->array->len - 1) sd->first_event = 0; |
1346 | else sd->first_event++; |
1347 | |
33e44b82 |
1348 | sd->events_found = min(sd->n, sd->events_found + 1); |
0bd2f89c |
1349 | |
1350 | return FALSE; |
1351 | } |
1352 | |
0bd2f89c |
1353 | /* Seek back n events back from the current position. |
1354 | * |
1355 | * Parameters : |
1356 | * @self The trace set context |
1357 | * @n number of events to jump over |
9ba3aaaf |
1358 | * @first_offset The initial offset value used. |
33e44b82 |
1359 | * never put first_offset at ltt_time_zero. |
1360 | * @time_seeker Function pointer of the function to use to seek time : |
1361 | * either lttv_process_traceset_seek_time |
1362 | * or lttv_state_traceset_seek_time_closest |
1363 | * @filter The filter to call. |
0bd2f89c |
1364 | * |
1365 | * Return value : the number of events found (might be lower than the number |
1366 | * requested if beginning of traceset is reached). |
1367 | * |
1368 | * The first search will go back first_offset and try to find the last n events |
1369 | * matching the filter. If there are not enough, it will try to go back from the |
1370 | * new trace point from first_offset*2, and so on, until beginning of trace or n |
1371 | * events are found. |
1372 | * |
1373 | * Note : this function does not take in account the LttvFilter : use the |
1374 | * similar function found in state.c instead. |
1375 | * |
1376 | * Note2 : the caller must make sure that the LttvTracesetContext does not |
1377 | * contain any hook, as process_traceset_middle is used in this routine. |
1378 | */ |
1379 | guint lttv_process_traceset_seek_n_backward(LttvTracesetContext *self, |
33e44b82 |
1380 | guint n, LttTime first_offset, |
1381 | seek_time_fct time_seeker, |
1382 | LttvFilter *filter) |
0bd2f89c |
1383 | { |
33e44b82 |
1384 | if(lttv_traceset_number(self->ts) == 0) return 0; |
1385 | g_assert(ltt_time_compare(first_offset, ltt_time_zero) != 0); |
1386 | |
0bd2f89c |
1387 | guint i; |
1388 | LttvTracesetContextPosition *next_iter_end_pos = |
9ba3aaaf |
1389 | lttv_traceset_context_position_new(self); |
1390 | LttvTracesetContextPosition *end_pos = |
1391 | lttv_traceset_context_position_new(self); |
1392 | LttvTracesetContextPosition *saved_pos = |
1393 | lttv_traceset_context_position_new(self); |
0bd2f89c |
1394 | LttTime time; |
1395 | LttTime time_offset; |
1396 | struct seek_back_data sd; |
1397 | LttvHooks *hooks = lttv_hooks_new(); |
1398 | |
1399 | sd.first_event = 0; |
1400 | sd.events_found = 0; |
1401 | sd.array = g_ptr_array_sized_new(n); |
33e44b82 |
1402 | sd.filter = filter; |
1403 | sd.n = n; |
0bd2f89c |
1404 | g_ptr_array_set_size(sd.array, n); |
1405 | for(i=0;i<n;i++) { |
9ba3aaaf |
1406 | g_ptr_array_index (sd.array, i) = lttv_traceset_context_position_new(self); |
0bd2f89c |
1407 | } |
33e44b82 |
1408 | |
0bd2f89c |
1409 | lttv_traceset_context_position_save(self, next_iter_end_pos); |
33e44b82 |
1410 | lttv_traceset_context_position_save(self, saved_pos); |
0bd2f89c |
1411 | /* Get the current time from which we will offset */ |
1412 | time = lttv_traceset_context_position_get_time(next_iter_end_pos); |
1413 | /* the position saved might be end of traceset... */ |
1414 | if(ltt_time_compare(time, self->time_span.end_time) > 0) { |
1415 | time = self->time_span.end_time; |
1416 | } |
1417 | time_offset = first_offset; |
1418 | |
1419 | lttv_hooks_add(hooks, seek_back_event_hook, &sd, LTTV_PRIO_DEFAULT); |
1420 | |
1421 | lttv_process_traceset_begin(self, NULL, NULL, NULL, hooks, NULL); |
1422 | |
1423 | while(1) { |
1424 | /* stop criteria : - n events found |
1425 | * - time < beginning of trace */ |
1426 | if(ltt_time_compare(time, self->time_span.start_time) < 0) break; |
0bd2f89c |
1427 | |
1428 | lttv_traceset_context_position_copy(end_pos, next_iter_end_pos); |
1429 | |
1430 | /* We must seek the traceset back to time - time_offset */ |
1431 | /* this time becomes the new reference time */ |
1432 | time = ltt_time_sub(time, time_offset); |
1433 | |
33e44b82 |
1434 | time_seeker(self, time); |
0bd2f89c |
1435 | lttv_traceset_context_position_save(self, next_iter_end_pos); |
33e44b82 |
1436 | /* Resync the time in case of a seek_closest */ |
1437 | time = lttv_traceset_context_position_get_time(next_iter_end_pos); |
1438 | if(ltt_time_compare(time, self->time_span.end_time) > 0) { |
1439 | time = self->time_span.end_time; |
1440 | } |
0bd2f89c |
1441 | |
1442 | /* Process the traceset, calling a hook which adds events |
1443 | * to the array, overwriting the tail. It changes first_event and |
1444 | * events_found too. */ |
1445 | /* We would like to have a clean context here : no other hook than our's */ |
1446 | |
1447 | lttv_process_traceset_middle(self, ltt_time_infinite, |
1448 | G_MAXUINT, end_pos); |
1449 | |
33e44b82 |
1450 | if(sd.events_found < n) { |
1451 | if(sd.first_event > 0) { |
1452 | /* Save the first position */ |
1453 | LttvTracesetContextPosition *pos = |
1454 | (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, 0); |
1455 | lttv_traceset_context_position_copy(saved_pos, pos); |
1456 | } |
1457 | g_assert(n-sd.events_found <= sd.array->len); |
1458 | /* Change array size to n - events_found */ |
1459 | for(i=n-sd.events_found;i<sd.array->len;i++) { |
1460 | LttvTracesetContextPosition *pos = |
1461 | (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, i); |
1462 | lttv_traceset_context_position_destroy(pos); |
1463 | } |
1464 | g_ptr_array_set_size(sd.array, n-sd.events_found); |
1465 | sd.first_event = 0; |
1466 | |
1467 | } else break; /* Second end criterion : n events found */ |
1468 | |
0bd2f89c |
1469 | time_offset = ltt_time_mul(time_offset, BACKWARD_SEEK_MUL); |
1470 | } |
1471 | |
1472 | lttv_traceset_context_position_destroy(end_pos); |
1473 | lttv_traceset_context_position_destroy(next_iter_end_pos); |
1474 | |
1475 | lttv_process_traceset_end(self, NULL, NULL, NULL, hooks, NULL); |
1476 | |
33e44b82 |
1477 | if(sd.events_found >= n) { |
0bd2f89c |
1478 | /* Seek the traceset to the first event in the circular array */ |
1479 | LttvTracesetContextPosition *pos = |
1480 | (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, |
1481 | sd.first_event); |
1482 | g_assert(lttv_process_traceset_seek_position(self, pos) == 0); |
33e44b82 |
1483 | } else { |
1484 | /* Will seek to the last saved position : in the worst case, it will be the |
1485 | * original position (if events_found is 0) */ |
1486 | g_assert(lttv_process_traceset_seek_position(self, saved_pos) == 0); |
0bd2f89c |
1487 | } |
1488 | |
33e44b82 |
1489 | for(i=0;i<sd.array->len;i++) { |
0bd2f89c |
1490 | LttvTracesetContextPosition *pos = |
1491 | (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, i); |
1492 | lttv_traceset_context_position_destroy(pos); |
1493 | } |
1494 | g_ptr_array_free(sd.array, TRUE); |
1495 | |
1496 | lttv_hooks_destroy(hooks); |
1497 | |
33e44b82 |
1498 | lttv_traceset_context_position_destroy(saved_pos); |
1499 | |
0bd2f89c |
1500 | return sd.events_found; |
1501 | } |
1502 | |
1503 | |
1504 | struct seek_forward_data { |
1505 | guint event_count; /* event counter */ |
1506 | guint n; /* requested number of events to jump over */ |
33e44b82 |
1507 | LttvFilter *filter; |
0bd2f89c |
1508 | }; |
1509 | |
1510 | static gint seek_forward_event_hook(void *hook_data, void* call_data) |
1511 | { |
1512 | struct seek_forward_data *sd = (struct seek_forward_data*)hook_data; |
33e44b82 |
1513 | LttvTracefileContext *tfc = (LttvTracefileContext*)call_data; |
0bd2f89c |
1514 | |
33e44b82 |
1515 | if(sd->filter != NULL) { |
1516 | if(!lttv_filter_tree_parse(sd->filter->head, |
1517 | ltt_tracefile_get_event(tfc->tf), |
1518 | tfc->tf, |
1519 | tfc->t_context->t, |
1520 | tfc)) |
1521 | return FALSE; |
1522 | } |
1523 | |
0bd2f89c |
1524 | sd->event_count++; |
1525 | |
1526 | if(sd->event_count >= sd->n) |
1527 | return TRUE; |
1528 | else |
1529 | return FALSE; |
1530 | } |
1531 | |
1532 | /* Seek back n events forward from the current position |
1533 | * |
1534 | * Parameters : |
33e44b82 |
1535 | * @self the trace set context |
1536 | * @n number of events to jump over |
1537 | * @filter filter to call. |
0bd2f89c |
1538 | * |
1539 | * returns : the number of events jumped over (may be less than requested if end |
1540 | * of traceset reached) */ |
1541 | guint lttv_process_traceset_seek_n_forward(LttvTracesetContext *self, |
33e44b82 |
1542 | guint n, LttvFilter *filter) |
0bd2f89c |
1543 | { |
1544 | struct seek_forward_data sd; |
1545 | sd.event_count = 0; |
1546 | sd.n = n; |
33e44b82 |
1547 | sd.filter = filter; |
0bd2f89c |
1548 | LttvHooks *hooks = lttv_hooks_new(); |
1549 | |
1550 | lttv_hooks_add(hooks, seek_forward_event_hook, &sd, LTTV_PRIO_DEFAULT); |
1551 | |
1552 | lttv_process_traceset_begin(self, NULL, NULL, NULL, hooks, NULL); |
1553 | |
1554 | /* it will end on the end of traceset, or the fact that the |
1555 | * hook returns TRUE. |
1556 | */ |
1557 | lttv_process_traceset_middle(self, ltt_time_infinite, |
1558 | G_MAXUINT, NULL); |
1559 | |
1560 | /* Here, our position is either the end of traceset, or the exact position |
1561 | * after n events : leave it like this. */ |
1562 | |
1563 | lttv_process_traceset_end(self, NULL, NULL, NULL, hooks, NULL); |
1564 | |
1565 | lttv_hooks_destroy(hooks); |
1566 | |
1567 | return sd.event_count; |
1568 | } |
1569 | |
1570 | |