dc877563 |
1 | |
2 | #include <lttv/processTrace.h> |
ffd54a90 |
3 | #include <ltt/event.h> |
b445142a |
4 | #include <ltt/facility.h> |
dc877563 |
5 | |
ffd54a90 |
6 | void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts) |
dc877563 |
7 | { |
ffd54a90 |
8 | LTTV_TRACESET_CONTEXT_GET_CLASS(self)->init(self, ts); |
dc877563 |
9 | } |
10 | |
11 | |
12 | void lttv_context_fini(LttvTracesetContext *self) |
13 | { |
14 | LTTV_TRACESET_CONTEXT_GET_CLASS(self)->fini(self); |
15 | } |
16 | |
17 | |
18 | LttvTracesetContext * |
19 | lttv_context_new_traceset_context(LttvTracesetContext *self) |
20 | { |
21 | return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_traceset_context(self); |
22 | } |
23 | |
24 | |
25 | |
26 | |
27 | LttvTraceContext * |
28 | lttv_context_new_trace_context(LttvTracesetContext *self) |
29 | { |
30 | return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self); |
31 | } |
32 | |
33 | |
34 | LttvTracefileContext * |
35 | lttv_context_new_tracefile_context(LttvTracesetContext *self) |
36 | { |
c6bc9cb9 |
37 | return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self); |
dc877563 |
38 | } |
39 | |
f7afe191 |
40 | /**************************************************************************** |
41 | * lttv_traceset_context_compute_time_span |
42 | * |
43 | * Keep the Time_Span is sync with on the fly addition and removal of traces |
44 | * in a trace set. It must be called each time a trace is added/removed from |
45 | * the traceset. It could be more efficient to call it only once a bunch |
46 | * of traces are loaded, but the calculation is not long, so it's not |
47 | * critical. |
48 | * |
49 | * Author : Xang Xiu Yang |
50 | * Imported from gtkTraceSet.c by Mathieu Desnoyers |
51 | ***************************************************************************/ |
52 | static void lttv_traceset_context_compute_time_span( |
53 | LttvTracesetContext *self, |
54 | TimeInterval *Time_Span) |
55 | { |
56 | LttvTraceset * traceset = self->ts; |
57 | int numTraces = lttv_traceset_number(traceset); |
58 | int i; |
59 | LttTime s, e; |
60 | LttvTraceContext *tc; |
61 | LttTrace * trace; |
62 | |
63 | for(i=0; i<numTraces;i++){ |
64 | tc = self->traces[i]; |
65 | trace = tc->t; |
66 | |
67 | ltt_trace_time_span_get(trace, &s, &e); |
68 | |
69 | if(i==0){ |
70 | Time_Span->startTime = s; |
71 | Time_Span->endTime = e; |
72 | }else{ |
73 | if(s.tv_sec < Time_Span->startTime.tv_sec || |
74 | (s.tv_sec == Time_Span->startTime.tv_sec |
75 | && s.tv_nsec < Time_Span->startTime.tv_nsec)) |
76 | Time_Span->startTime = s; |
77 | if(e.tv_sec > Time_Span->endTime.tv_sec || |
78 | (e.tv_sec == Time_Span->endTime.tv_sec && |
79 | e.tv_nsec > Time_Span->endTime.tv_nsec)) |
80 | Time_Span->endTime = e; |
81 | } |
82 | } |
83 | } |
84 | |
dc877563 |
85 | |
86 | static void |
87 | init(LttvTracesetContext *self, LttvTraceset *ts) |
88 | { |
89 | guint i, j, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
90 | |
91 | LttvTraceContext *tc; |
92 | |
93 | LttvTracefileContext *tfc; |
94 | |
95 | nb_trace = lttv_traceset_number(ts); |
96 | self->ts = ts; |
ffd54a90 |
97 | self->traces = g_new(LttvTraceContext *, nb_trace); |
dc877563 |
98 | self->before = lttv_hooks_new(); |
99 | self->after = lttv_hooks_new(); |
ffd54a90 |
100 | self->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
dc877563 |
101 | for(i = 0 ; i < nb_trace ; i++) { |
ffd54a90 |
102 | tc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self); |
dc877563 |
103 | self->traces[i] = tc; |
104 | |
105 | tc->ts_context = self; |
106 | tc->index = i; |
107 | tc->t = lttv_traceset_get(ts, i); |
108 | tc->check = lttv_hooks_new(); |
109 | tc->before = lttv_hooks_new(); |
110 | tc->after = lttv_hooks_new(); |
ffd54a90 |
111 | tc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
dc877563 |
112 | nb_control = ltt_trace_control_tracefile_number(tc->t); |
113 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); |
114 | nb_tracefile = nb_control + nb_per_cpu; |
ffd54a90 |
115 | tc->control_tracefiles = g_new(LttvTracefileContext *, nb_control); |
116 | tc->per_cpu_tracefiles = g_new(LttvTracefileContext *, nb_per_cpu); |
dc877563 |
117 | |
118 | for(j = 0 ; j < nb_tracefile ; j++) { |
ffd54a90 |
119 | tfc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self); |
dc877563 |
120 | if(j < nb_control) { |
121 | tc->control_tracefiles[j] = tfc; |
122 | tfc->control = TRUE; |
123 | tfc->index = j; |
ffd54a90 |
124 | tfc->tf = ltt_trace_control_tracefile_get(tc->t, j); |
dc877563 |
125 | } |
126 | else { |
127 | tc->per_cpu_tracefiles[j - nb_control] = tfc; |
128 | tfc->control = FALSE; |
129 | tfc->index = j - nb_control; |
ffd54a90 |
130 | tfc->tf = ltt_trace_per_cpu_tracefile_get(tc->t, j - nb_control); |
dc877563 |
131 | } |
132 | tfc->t_context = tc; |
133 | tfc->check = lttv_hooks_new(); |
134 | tfc->before = lttv_hooks_new(); |
135 | tfc->after = lttv_hooks_new(); |
136 | tfc->check_event = lttv_hooks_new(); |
137 | tfc->before_event = lttv_hooks_new(); |
138 | tfc->before_event_by_id = lttv_hooks_by_id_new(); |
139 | tfc->after_event = lttv_hooks_new(); |
140 | tfc->after_event_by_id = lttv_hooks_by_id_new(); |
ffd54a90 |
141 | tfc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
dc877563 |
142 | } |
143 | } |
f7afe191 |
144 | self->Time_Span = g_new(TimeInterval,1); |
145 | lttv_traceset_context_compute_time_span(self, self->Time_Span); |
dc877563 |
146 | } |
147 | |
148 | |
149 | void fini(LttvTracesetContext *self) |
150 | { |
151 | guint i, j, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
152 | |
153 | LttvTraceContext *tc; |
154 | |
155 | LttvTracefileContext *tfc; |
156 | |
ffd54a90 |
157 | LttvTraceset *ts = self->ts; |
dc877563 |
158 | |
f7afe191 |
159 | g_free(self->Time_Span); |
160 | |
dc877563 |
161 | lttv_hooks_destroy(self->before); |
162 | lttv_hooks_destroy(self->after); |
f7afe191 |
163 | //FIXME : segfault |
164 | // g_object_unref(self->a); |
dc877563 |
165 | |
166 | nb_trace = lttv_traceset_number(ts); |
167 | |
168 | for(i = 0 ; i < nb_trace ; i++) { |
169 | tc = self->traces[i]; |
170 | |
171 | lttv_hooks_destroy(tc->check); |
172 | lttv_hooks_destroy(tc->before); |
173 | lttv_hooks_destroy(tc->after); |
ffd54a90 |
174 | g_object_unref(tc->a); |
dc877563 |
175 | |
176 | nb_control = ltt_trace_control_tracefile_number(tc->t); |
177 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); |
178 | nb_tracefile = nb_control + nb_per_cpu; |
179 | |
180 | for(j = 0 ; j < nb_tracefile ; j++) { |
181 | if(j < nb_control) tfc = tc->control_tracefiles[j]; |
182 | else tfc = tc->per_cpu_tracefiles[j - nb_control]; |
183 | |
184 | lttv_hooks_destroy(tfc->check); |
185 | lttv_hooks_destroy(tfc->before); |
186 | lttv_hooks_destroy(tfc->after); |
187 | lttv_hooks_destroy(tfc->check_event); |
188 | lttv_hooks_destroy(tfc->before_event); |
189 | lttv_hooks_by_id_destroy(tfc->before_event_by_id); |
190 | lttv_hooks_destroy(tfc->after_event); |
191 | lttv_hooks_by_id_destroy(tfc->after_event_by_id); |
ffd54a90 |
192 | g_object_unref(tfc->a); |
dc877563 |
193 | g_object_unref(tfc); |
194 | } |
195 | g_free(tc->control_tracefiles); |
196 | g_free(tc->per_cpu_tracefiles); |
197 | g_object_unref(tc); |
198 | } |
199 | g_free(self->traces); |
200 | } |
201 | |
202 | |
203 | void lttv_traceset_context_add_hooks(LttvTracesetContext *self, |
204 | LttvHooks *before_traceset, |
205 | LttvHooks *after_traceset, |
206 | LttvHooks *check_trace, |
207 | LttvHooks *before_trace, |
208 | LttvHooks *after_trace, |
ffd54a90 |
209 | LttvHooks *check_tracefile, |
210 | LttvHooks *before_tracefile, |
211 | LttvHooks *after_tracefile, |
dc877563 |
212 | LttvHooks *check_event, |
213 | LttvHooks *before_event, |
214 | LttvHooks *after_event) |
215 | { |
216 | LttvTraceset *ts = self->ts; |
217 | |
218 | guint i, j, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
219 | |
220 | LttvTraceContext *tc; |
221 | |
222 | LttvTracefileContext *tfc; |
223 | |
224 | void *hook_data; |
225 | |
226 | lttv_hooks_add_list(self->before, before_traceset); |
227 | lttv_hooks_add_list(self->after, after_traceset); |
228 | nb_trace = lttv_traceset_number(ts); |
229 | |
230 | for(i = 0 ; i < nb_trace ; i++) { |
231 | tc = self->traces[i]; |
232 | lttv_hooks_add_list(tc->check, check_trace); |
233 | lttv_hooks_add_list(tc->before, before_trace); |
234 | lttv_hooks_add_list(tc->after, after_trace); |
235 | nb_control = ltt_trace_control_tracefile_number(tc->t); |
d83f6739 |
236 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); |
dc877563 |
237 | nb_tracefile = nb_control + nb_per_cpu; |
238 | |
239 | for(j = 0 ; j < nb_tracefile ; j++) { |
240 | if(j < nb_control) { |
241 | tfc = tc->control_tracefiles[j]; |
242 | } |
243 | else { |
d83f6739 |
244 | tfc = tc->per_cpu_tracefiles[j-nb_control]; |
dc877563 |
245 | } |
246 | lttv_hooks_add_list(tfc->check, check_tracefile); |
247 | lttv_hooks_add_list(tfc->before, before_tracefile); |
248 | lttv_hooks_add_list(tfc->after, after_tracefile); |
249 | lttv_hooks_add_list(tfc->check_event, check_event); |
250 | lttv_hooks_add_list(tfc->before_event, before_event); |
251 | lttv_hooks_add_list(tfc->after_event, after_event); |
252 | } |
253 | } |
254 | } |
255 | |
256 | |
257 | void lttv_traceset_context_remove_hooks(LttvTracesetContext *self, |
258 | LttvHooks *before_traceset, |
259 | LttvHooks *after_traceset, |
260 | LttvHooks *check_trace, |
261 | LttvHooks *before_trace, |
262 | LttvHooks *after_trace, |
ffd54a90 |
263 | LttvHooks *check_tracefile, |
264 | LttvHooks *before_tracefile, |
265 | LttvHooks *after_tracefile, |
dc877563 |
266 | LttvHooks *check_event, |
267 | LttvHooks *before_event, |
268 | LttvHooks *after_event) |
269 | { |
270 | LttvTraceset *ts = self->ts; |
271 | |
272 | guint i, j, nb_trace, nb_control, nb_per_cpu, nb_tracefile; |
273 | |
274 | LttvTraceContext *tc; |
275 | |
276 | LttvTracefileContext *tfc; |
277 | |
278 | void *hook_data; |
279 | |
280 | lttv_hooks_remove_list(self->before, before_traceset); |
281 | lttv_hooks_remove_list(self->after, after_traceset); |
282 | nb_trace = lttv_traceset_number(ts); |
283 | |
284 | for(i = 0 ; i < nb_trace ; i++) { |
285 | tc = self->traces[i]; |
286 | lttv_hooks_remove_list(tc->check, check_trace); |
287 | lttv_hooks_remove_list(tc->before, before_trace); |
288 | lttv_hooks_remove_list(tc->after, after_trace); |
289 | nb_control = ltt_trace_control_tracefile_number(tc->t); |
d83f6739 |
290 | nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t); |
dc877563 |
291 | nb_tracefile = nb_control + nb_per_cpu; |
292 | |
293 | for(j = 0 ; j < nb_tracefile ; j++) { |
294 | if(j < nb_control) { |
295 | tfc = tc->control_tracefiles[j]; |
296 | } |
297 | else { |
d83f6739 |
298 | tfc = tc->per_cpu_tracefiles[j-nb_control]; |
dc877563 |
299 | } |
300 | lttv_hooks_remove_list(tfc->check, check_tracefile); |
301 | lttv_hooks_remove_list(tfc->before, before_tracefile); |
302 | lttv_hooks_remove_list(tfc->after, after_tracefile); |
303 | lttv_hooks_remove_list(tfc->check_event, check_event); |
304 | lttv_hooks_remove_list(tfc->before_event, before_event); |
305 | lttv_hooks_remove_list(tfc->after_event, after_event); |
306 | } |
307 | } |
308 | } |
309 | |
310 | |
ba576a78 |
311 | static LttvTracesetContext * |
dc877563 |
312 | new_traceset_context(LttvTracesetContext *self) |
313 | { |
ffd54a90 |
314 | return g_object_new(LTTV_TRACESET_CONTEXT_TYPE, NULL); |
dc877563 |
315 | } |
316 | |
317 | |
ba576a78 |
318 | static LttvTraceContext * |
dc877563 |
319 | new_trace_context(LttvTracesetContext *self) |
320 | { |
ffd54a90 |
321 | return g_object_new(LTTV_TRACE_CONTEXT_TYPE, NULL); |
dc877563 |
322 | } |
323 | |
324 | |
ba576a78 |
325 | static LttvTracefileContext * |
dc877563 |
326 | new_tracefile_context(LttvTracesetContext *self) |
327 | { |
ffd54a90 |
328 | return g_object_new(LTTV_TRACEFILE_CONTEXT_TYPE, NULL); |
dc877563 |
329 | } |
330 | |
331 | |
332 | static void |
333 | traceset_context_instance_init (GTypeInstance *instance, gpointer g_class) |
334 | { |
335 | /* Be careful of anything which would not work well with shallow copies */ |
336 | } |
337 | |
338 | |
339 | static void |
340 | traceset_context_finalize (LttvTracesetContext *self) |
341 | { |
b445142a |
342 | G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACESET_CONTEXT_TYPE))) |
343 | ->finalize(G_OBJECT(self)); |
dc877563 |
344 | } |
345 | |
346 | |
347 | static void |
348 | traceset_context_class_init (LttvTracesetContextClass *klass) |
349 | { |
350 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
351 | |
ffd54a90 |
352 | gobject_class->finalize = (void (*)(GObject *self))traceset_context_finalize; |
dc877563 |
353 | klass->init = init; |
354 | klass->fini = fini; |
355 | klass->new_traceset_context = new_traceset_context; |
356 | klass->new_trace_context = new_trace_context; |
357 | klass->new_tracefile_context = new_tracefile_context; |
358 | } |
359 | |
360 | |
361 | GType |
ffd54a90 |
362 | lttv_traceset_context_get_type(void) |
dc877563 |
363 | { |
364 | static GType type = 0; |
365 | if (type == 0) { |
366 | static const GTypeInfo info = { |
ffd54a90 |
367 | sizeof (LttvTracesetContextClass), |
dc877563 |
368 | NULL, /* base_init */ |
369 | NULL, /* base_finalize */ |
ffd54a90 |
370 | (GClassInitFunc) traceset_context_class_init, /* class_init */ |
dc877563 |
371 | NULL, /* class_finalize */ |
372 | NULL, /* class_data */ |
ffd54a90 |
373 | sizeof (LttvTracesetContext), |
dc877563 |
374 | 0, /* n_preallocs */ |
ffd54a90 |
375 | (GInstanceInitFunc) traceset_context_instance_init /* instance_init */ |
dc877563 |
376 | }; |
377 | |
ffd54a90 |
378 | type = g_type_register_static (G_TYPE_OBJECT, "LttvTracesetContextType", |
dc877563 |
379 | &info, 0); |
380 | } |
381 | return type; |
382 | } |
383 | |
384 | |
385 | static void |
386 | trace_context_instance_init (GTypeInstance *instance, gpointer g_class) |
387 | { |
388 | /* Be careful of anything which would not work well with shallow copies */ |
389 | } |
390 | |
391 | |
392 | static void |
393 | trace_context_finalize (LttvTraceContext *self) |
394 | { |
b445142a |
395 | G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACE_CONTEXT_TYPE)))-> |
396 | finalize(G_OBJECT(self)); |
dc877563 |
397 | } |
398 | |
399 | |
400 | static void |
401 | trace_context_class_init (LttvTraceContextClass *klass) |
402 | { |
403 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
404 | |
ffd54a90 |
405 | gobject_class->finalize = (void (*)(GObject *self)) trace_context_finalize; |
dc877563 |
406 | } |
407 | |
408 | |
409 | GType |
ffd54a90 |
410 | lttv_trace_context_get_type(void) |
dc877563 |
411 | { |
412 | static GType type = 0; |
413 | if (type == 0) { |
414 | static const GTypeInfo info = { |
ffd54a90 |
415 | sizeof (LttvTraceContextClass), |
dc877563 |
416 | NULL, /* base_init */ |
417 | NULL, /* base_finalize */ |
ffd54a90 |
418 | (GClassInitFunc) trace_context_class_init, /* class_init */ |
dc877563 |
419 | NULL, /* class_finalize */ |
420 | NULL, /* class_data */ |
c6bc9cb9 |
421 | sizeof (LttvTraceContext), |
dc877563 |
422 | 0, /* n_preallocs */ |
ffd54a90 |
423 | (GInstanceInitFunc) trace_context_instance_init /* instance_init */ |
dc877563 |
424 | }; |
425 | |
ffd54a90 |
426 | type = g_type_register_static (G_TYPE_OBJECT, "LttvTraceContextType", |
dc877563 |
427 | &info, 0); |
428 | } |
429 | return type; |
430 | } |
431 | |
432 | |
433 | static void |
434 | tracefile_context_instance_init (GTypeInstance *instance, gpointer g_class) |
435 | { |
436 | /* Be careful of anything which would not work well with shallow copies */ |
437 | } |
438 | |
439 | |
440 | static void |
441 | tracefile_context_finalize (LttvTracefileContext *self) |
442 | { |
b445142a |
443 | G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACEFILE_CONTEXT_TYPE))) |
444 | ->finalize(G_OBJECT(self)); |
dc877563 |
445 | } |
446 | |
447 | |
448 | static void |
449 | tracefile_context_class_init (LttvTracefileContextClass *klass) |
450 | { |
451 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
452 | |
ffd54a90 |
453 | gobject_class->finalize = (void (*)(GObject *self))tracefile_context_finalize; |
454 | } |
455 | |
456 | |
457 | GType |
458 | lttv_tracefile_context_get_type(void) |
459 | { |
460 | static GType type = 0; |
461 | if (type == 0) { |
462 | static const GTypeInfo info = { |
463 | sizeof (LttvTracefileContextClass), |
464 | NULL, /* base_init */ |
465 | NULL, /* base_finalize */ |
466 | (GClassInitFunc) tracefile_context_class_init, /* class_init */ |
467 | NULL, /* class_finalize */ |
468 | NULL, /* class_data */ |
469 | sizeof (LttvTracefileContext), |
470 | 0, /* n_preallocs */ |
471 | (GInstanceInitFunc) tracefile_context_instance_init /* instance_init */ |
472 | }; |
473 | |
474 | type = g_type_register_static (G_TYPE_OBJECT, "LttvTracefileContextType", |
475 | &info, 0); |
476 | } |
477 | return type; |
dc877563 |
478 | } |
479 | |
480 | |
ffd54a90 |
481 | gint compare_tracefile(gconstpointer a, gconstpointer b) |
dc877563 |
482 | { |
ffd54a90 |
483 | if(((LttvTime *)a)->tv_sec > ((LttvTime *)b)->tv_sec) return 1; |
484 | if(((LttvTime *)a)->tv_sec < ((LttvTime *)b)->tv_sec) return -1; |
485 | if(((LttvTime *)a)->tv_nsec > ((LttvTime *)b)->tv_nsec) return 1; |
486 | if(((LttvTime *)a)->tv_nsec < ((LttvTime *)b)->tv_nsec) return -1; |
dc877563 |
487 | return 0; |
488 | } |
489 | |
490 | |
491 | gboolean get_first(gpointer key, gpointer value, gpointer user_data) { |
492 | *((LttvTracefileContext **)user_data) = (LttvTracefileContext *)value; |
493 | return TRUE; |
494 | } |
495 | |
496 | |
ffd54a90 |
497 | void lttv_process_trace(LttTime start, LttTime end, LttvTraceset *traceset, |
270e7cc5 |
498 | LttvTracesetContext *context, unsigned maxNumEvents) |
dc877563 |
499 | { |
500 | GPtrArray *traces = g_ptr_array_new(); |
501 | |
502 | GPtrArray *tracefiles = g_ptr_array_new(); |
503 | |
504 | GTree *pqueue = g_tree_new(compare_tracefile); |
505 | |
ffd54a90 |
506 | guint i, j, nbi, nbj, id, nb_control, nb_cpu; |
dc877563 |
507 | |
508 | LttTrace *trace; |
509 | |
510 | LttvTraceContext *tc; |
511 | |
512 | LttTracefile *tracefile; |
513 | |
514 | LttvTracefileContext *tfc; |
515 | |
516 | LttEvent *event; |
270e7cc5 |
517 | unsigned count = 0; |
518 | LttTime preTimestamp; |
dc877563 |
519 | |
520 | /* Call all before_traceset, before_trace, and before_tracefile hooks. |
521 | For all qualifying tracefiles, seek to the start time, create a context, |
522 | read one event and insert in the pqueue based on the event time. */ |
523 | |
524 | lttv_hooks_call(context->before, context); |
cbe7c836 |
525 | nbi = lttv_traceset_number(traceset); |
526 | // nbi = ltt_trace_set_number(traceset); |
dc877563 |
527 | |
528 | for(i = 0 ; i < nbi ; i++) { |
529 | tc = context->traces[i]; |
530 | trace = tc->t; |
531 | |
532 | if(!lttv_hooks_call_check(tc->check, tc)) { |
533 | g_ptr_array_add(traces, tc); |
534 | lttv_hooks_call(tc->before, tc); |
535 | nb_control = ltt_trace_control_tracefile_number(trace); |
536 | nb_cpu = ltt_trace_per_cpu_tracefile_number(trace); |
537 | nbj = nb_control + nb_cpu; |
538 | |
539 | for(j = 0 ; j < nbj ; j++) { |
540 | if(j < nb_control) { |
541 | tfc = tc->control_tracefiles[j]; |
542 | } |
543 | else { |
544 | tfc = tc->per_cpu_tracefiles[j - nb_control]; |
545 | } |
546 | |
547 | tracefile = tfc->tf; |
548 | |
549 | if(!lttv_hooks_call_check(tfc->check, tfc)) { |
550 | g_ptr_array_add(tracefiles, tfc); |
551 | lttv_hooks_call(tfc->before, tfc); |
552 | |
553 | ltt_tracefile_seek_time(tracefile, start); |
554 | event = ltt_tracefile_read(tracefile); |
555 | tfc->e = event; |
556 | |
557 | if(event != NULL) { |
ffd54a90 |
558 | tfc->timestamp = ltt_event_time(event); |
559 | g_tree_insert(pqueue, &(tfc->timestamp), tfc); |
dc877563 |
560 | } |
561 | } |
562 | } |
563 | } |
564 | } |
565 | |
566 | /* Get the next event from the pqueue, call its hooks, |
567 | reinsert in the pqueue the following event from the same tracefile |
568 | unless the tracefile is finished or the event is later than the |
569 | start time. */ |
570 | |
ffd54a90 |
571 | while(TRUE) { |
dc877563 |
572 | tfc = NULL; |
573 | g_tree_foreach(pqueue, get_first, &tfc); |
574 | if(tfc == NULL) break; |
575 | |
576 | /* Get the tracefile with an event for the smallest time found. If two |
577 | or more tracefiles have events for the same time, hope that lookup |
578 | and remove are consistent. */ |
579 | |
270e7cc5 |
580 | count++; |
581 | if(count > maxNumEvents){ |
582 | if(tfc->timestamp.tv_sec == preTimestamp.tv_sec && |
583 | tfc->timestamp.tv_nsec == preTimestamp.tv_nsec) { |
584 | count--; |
585 | }else{ |
586 | while(TRUE){ |
587 | tfc = NULL; |
588 | g_tree_foreach(pqueue, get_first, &tfc); |
589 | if(tfc == NULL) break; |
590 | g_tree_remove(pqueue, &(tfc->timestamp)); |
591 | } |
592 | break; |
593 | } |
594 | } |
595 | preTimestamp = tfc->timestamp; |
596 | |
ffd54a90 |
597 | tfc = g_tree_lookup(pqueue, &(tfc->timestamp)); |
598 | g_tree_remove(pqueue, &(tfc->timestamp)); |
dc877563 |
599 | |
b445142a |
600 | if(!lttv_hooks_call(tfc->check_event, tfc)) { |
cbe7c836 |
601 | id = ltt_event_eventtype_id(tfc->e); |
dc877563 |
602 | lttv_hooks_call(tfc->before_event, tfc); |
603 | lttv_hooks_call(lttv_hooks_by_id_get(tfc->before_event_by_id, id), tfc); |
b445142a |
604 | lttv_hooks_call(tfc->after_event, tfc); |
dc877563 |
605 | lttv_hooks_call(lttv_hooks_by_id_get(tfc->after_event_by_id, id), tfc); |
606 | } |
607 | |
608 | event = ltt_tracefile_read(tfc->tf); |
609 | if(event != NULL) { |
610 | tfc->e = event; |
ffd54a90 |
611 | tfc->timestamp = ltt_event_time(event); |
270e7cc5 |
612 | if(tfc->timestamp.tv_sec < end.tv_sec || |
613 | (tfc->timestamp.tv_sec == end.tv_sec && tfc->timestamp.tv_nsec <= end.tv_nsec)) |
614 | g_tree_insert(pqueue, &(tfc->timestamp), tfc); |
dc877563 |
615 | } |
616 | } |
617 | |
618 | /* Call all the after_tracefile, after_trace and after_traceset hooks. */ |
619 | |
620 | for(i = 0, j = 0 ; i < traces->len ; i++) { |
621 | tc = traces->pdata[i]; |
622 | while(j < tracefiles->len) { |
623 | tfc = tracefiles->pdata[j]; |
624 | |
625 | if(tfc->t_context == tc) { |
626 | lttv_hooks_call(tfc->after, tfc); |
627 | j++; |
628 | } |
629 | else break; |
630 | } |
631 | lttv_hooks_call(tc->after, tc); |
632 | } |
633 | |
634 | g_assert(j == tracefiles->len); |
ffd54a90 |
635 | lttv_hooks_call(context->after, context); |
dc877563 |
636 | |
637 | /* Free the traces, tracefiles and pqueue */ |
638 | |
639 | g_ptr_array_free(tracefiles, TRUE); |
640 | g_ptr_array_free(traces, TRUE); |
ffd54a90 |
641 | g_tree_destroy(pqueue); |
dc877563 |
642 | } |
b445142a |
643 | |
644 | static LttField * |
645 | find_field(LttEventType *et, const char *field) |
646 | { |
647 | LttType *t; |
648 | |
649 | LttField *f; |
650 | |
651 | guint i, nb; |
652 | |
653 | char *name; |
654 | |
655 | if(field == NULL) return NULL; |
656 | |
657 | f = ltt_eventtype_field(et); |
658 | t = ltt_eventtype_type(et); |
659 | g_assert(ltt_type_class(t) == LTT_STRUCT); |
660 | nb = ltt_type_member_number(t); |
661 | for(i = 0 ; i < nb ; i++) { |
662 | ltt_type_member_type(t, i, &name); |
663 | if(strcmp(name, field) == 0) break; |
664 | } |
665 | g_assert(i < nb); |
666 | return ltt_field_member(f, i); |
667 | } |
668 | |
669 | |
670 | void |
671 | lttv_trace_find_hook(LttTrace *t, char *facility, char *event_type, |
672 | char *field1, char *field2, char *field3, LttvHook h, LttvTraceHook *th) |
673 | { |
674 | LttFacility *f; |
675 | |
676 | LttEventType *et; |
677 | |
678 | guint nb, pos, i; |
679 | |
680 | char *name; |
681 | |
682 | nb = ltt_trace_facility_find(t, facility, &pos); |
683 | if(nb < 1) g_error("No %s facility", facility); |
684 | f = ltt_trace_facility_get(t, pos); |
685 | et = ltt_facility_eventtype_get_by_name(f, event_type); |
686 | if(et == NULL) g_error("Event %s does not exist", event_type); |
687 | |
688 | th->h = h; |
689 | th->id = ltt_eventtype_id(et); |
690 | th->f1 = find_field(et, field1); |
691 | th->f2 = find_field(et, field2); |
692 | th->f3 = find_field(et, field3); |
693 | } |
694 | |
695 | |