explain hook call return value useage
[lttv.git] / ltt / branches / poly / lttv / lttv / tracecontext.c
CommitLineData
9c312311 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
dc877563 19
d8f124de 20#include <lttv/tracecontext.h>
ffd54a90 21#include <ltt/event.h>
b445142a 22#include <ltt/facility.h>
a5dcde2f 23#include <ltt/trace.h>
24#include <ltt/type.h>
dc877563 25
8697a616 26
27
28
29gint compare_tracefile(gconstpointer a, gconstpointer b)
30{
31 gint comparison;
32
33 LttvTracefileContext *trace_a = (LttvTracefileContext *)a;
34
35 LttvTracefileContext *trace_b = (LttvTracefileContext *)b;
36
37 if(trace_a == trace_b) return 0;
38 comparison = ltt_time_compare(trace_a->timestamp, trace_b->timestamp);
39 if(comparison != 0) return comparison;
40 if(trace_a->index < trace_b->index) return -1;
41 else if(trace_a->index > trace_b->index) return 1;
42 if(trace_a->t_context->index < trace_b->t_context->index) return -1;
43 else if(trace_a->t_context->index > trace_b->t_context->index) return 1;
44 g_assert(FALSE);
45}
46
47struct _LttvTraceContextPosition {
48 LttEventPosition **tf_pos; /* Position in each trace */
49 guint nb_tracefile; /* Number of tracefiles (check) */
50};
51
52struct _LttvTracesetContextPosition {
53 LttvTraceContextPosition *t_pos; /* Position in each trace */
54 guint nb_trace; /* Number of traces (check) */
55};
56
ffd54a90 57void lttv_context_init(LttvTracesetContext *self, LttvTraceset *ts)
dc877563 58{
ffd54a90 59 LTTV_TRACESET_CONTEXT_GET_CLASS(self)->init(self, ts);
dc877563 60}
61
62
63void lttv_context_fini(LttvTracesetContext *self)
64{
65 LTTV_TRACESET_CONTEXT_GET_CLASS(self)->fini(self);
66}
67
68
69LttvTracesetContext *
70lttv_context_new_traceset_context(LttvTracesetContext *self)
71{
72 return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_traceset_context(self);
73}
74
75
76
77
78LttvTraceContext *
79lttv_context_new_trace_context(LttvTracesetContext *self)
80{
81 return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self);
82}
83
84
85LttvTracefileContext *
86lttv_context_new_tracefile_context(LttvTracesetContext *self)
87{
c6bc9cb9 88 return LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self);
dc877563 89}
90
f7afe191 91/****************************************************************************
92 * lttv_traceset_context_compute_time_span
93 *
8697a616 94 * Keep the time span is sync with on the fly addition and removal of traces
f7afe191 95 * in a trace set. It must be called each time a trace is added/removed from
96 * the traceset. It could be more efficient to call it only once a bunch
97 * of traces are loaded, but the calculation is not long, so it's not
98 * critical.
99 *
100 * Author : Xang Xiu Yang
f7afe191 101 ***************************************************************************/
102static void lttv_traceset_context_compute_time_span(
103 LttvTracesetContext *self,
8697a616 104 TimeInterval time_span)
f7afe191 105{
106 LttvTraceset * traceset = self->ts;
107 int numTraces = lttv_traceset_number(traceset);
108 int i;
109 LttTime s, e;
110 LttvTraceContext *tc;
111 LttTrace * trace;
112
8697a616 113 time_span.startTime.tv_sec = 0;
114 time_span.startTime.tv_nsec = 0;
115 time_span.endTime.tv_sec = 0;
116 time_span.endTime.tv_nsec = 0;
912be9a5 117
f7afe191 118 for(i=0; i<numTraces;i++){
119 tc = self->traces[i];
120 trace = tc->t;
121
122 ltt_trace_time_span_get(trace, &s, &e);
123
124 if(i==0){
8697a616 125 time_span.startTime = s;
126 time_span.endTime = e;
f7afe191 127 }else{
8697a616 128 if(s.tv_sec < time_span.startTime.tv_sec
129 || (s.tv_sec == time_span.startTime.tv_sec
130 && s.tv_nsec < time_span.startTime.tv_nsec))
131 time_span.startTime = s;
132 if(e.tv_sec > time_span.endTime.tv_sec
133 || (e.tv_sec == time_span.endTime.tv_sec
134 && e.tv_nsec > time_span.endTime.tv_nsec))
135 time_span.endTime = e;
f7afe191 136 }
137 }
138}
139
dc877563 140
141static void
142init(LttvTracesetContext *self, LttvTraceset *ts)
143{
144 guint i, j, nb_trace, nb_control, nb_per_cpu, nb_tracefile;
145
146 LttvTraceContext *tc;
147
148 LttvTracefileContext *tfc;
149
308711e5 150 LttTime null_time = {0, 0};
151
dc877563 152 nb_trace = lttv_traceset_number(ts);
153 self->ts = ts;
ffd54a90 154 self->traces = g_new(LttvTraceContext *, nb_trace);
ffd54a90 155 self->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
308711e5 156 self->ts_a = lttv_traceset_attribute(ts);
dc877563 157 for(i = 0 ; i < nb_trace ; i++) {
ffd54a90 158 tc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_trace_context(self);
dc877563 159 self->traces[i] = tc;
160
161 tc->ts_context = self;
162 tc->index = i;
308711e5 163 tc->vt = lttv_traceset_get(ts, i);
164 tc->t = lttv_trace(tc->vt);
ffd54a90 165 tc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
308711e5 166 tc->t_a = lttv_trace_attribute(tc->vt);
dc877563 167 nb_control = ltt_trace_control_tracefile_number(tc->t);
168 nb_per_cpu = ltt_trace_per_cpu_tracefile_number(tc->t);
169 nb_tracefile = nb_control + nb_per_cpu;
dbb7bb09 170 tc->tracefiles = g_new(LttvTracefileContext *, nb_tracefile);
dc877563 171
172 for(j = 0 ; j < nb_tracefile ; j++) {
ffd54a90 173 tfc = LTTV_TRACESET_CONTEXT_GET_CLASS(self)->new_tracefile_context(self);
dbb7bb09 174 tc->tracefiles[j] = tfc;
175 tfc->index = j;
176
dc877563 177 if(j < nb_control) {
dc877563 178 tfc->control = TRUE;
ffd54a90 179 tfc->tf = ltt_trace_control_tracefile_get(tc->t, j);
dc877563 180 }
181 else {
dc877563 182 tfc->control = FALSE;
ffd54a90 183 tfc->tf = ltt_trace_per_cpu_tracefile_get(tc->t, j - nb_control);
dc877563 184 }
185 tfc->t_context = tc;
8697a616 186 tfc->event = lttv_hooks_new();
187 tfc->event_by_id = lttv_hooks_by_id_new();
ffd54a90 188 tfc->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
dc877563 189 }
190 }
308711e5 191 lttv_process_traceset_seek_time(self, null_time);
8697a616 192 lttv_traceset_context_compute_time_span(self, self->time_span);
a43d67ba 193 self->e = NULL;
8697a616 194
195 self->pqueue = g_tree_new(compare_tracefile);
dc877563 196}
197
198
199void fini(LttvTracesetContext *self)
200{
dbb7bb09 201 guint i, j, nb_trace, nb_tracefile;
dc877563 202
203 LttvTraceContext *tc;
204
205 LttvTracefileContext *tfc;
206
ffd54a90 207 LttvTraceset *ts = self->ts;
dc877563 208
f7afe191 209 //FIXME : segfault
8697a616 210
211 g_tree_destroy(self->pqueue);
2061e03d 212 g_object_unref(self->a);
dc877563 213
214 nb_trace = lttv_traceset_number(ts);
215
216 for(i = 0 ; i < nb_trace ; i++) {
217 tc = self->traces[i];
218
ffd54a90 219 g_object_unref(tc->a);
dc877563 220
dbb7bb09 221 nb_tracefile = ltt_trace_control_tracefile_number(tc->t) +
222 ltt_trace_per_cpu_tracefile_number(tc->t);
dc877563 223
224 for(j = 0 ; j < nb_tracefile ; j++) {
dbb7bb09 225 tfc = tc->tracefiles[j];
8697a616 226 lttv_hooks_destroy(tfc->event);
227 lttv_hooks_by_id_destroy(tfc->event_by_id);
ffd54a90 228 g_object_unref(tfc->a);
dc877563 229 g_object_unref(tfc);
230 }
dbb7bb09 231 g_free(tc->tracefiles);
dc877563 232 g_object_unref(tc);
233 }
234 g_free(self->traces);
235}
236
237
238void lttv_traceset_context_add_hooks(LttvTracesetContext *self,
8697a616 239 LttvHooks *before_traceset,
dc877563 240 LttvHooks *before_trace,
ffd54a90 241 LttvHooks *before_tracefile,
8697a616 242 LttvHooks *event,
243 LttvHooksById *event_by_id)
dc877563 244{
245 LttvTraceset *ts = self->ts;
246
8697a616 247 guint i, nb_trace;
dc877563 248
249 LttvTraceContext *tc;
250
8697a616 251 lttv_hooks_call(before_traceset, self);
dc877563 252
dc877563 253 nb_trace = lttv_traceset_number(ts);
254
255 for(i = 0 ; i < nb_trace ; i++) {
256 tc = self->traces[i];
8697a616 257 lttv_trace_context_add_hooks(tc,
258 before_trace,
259 before_tracefile,
260 event,
261 event_by_id);
dc877563 262 }
263}
264
265
266void lttv_traceset_context_remove_hooks(LttvTracesetContext *self,
dc877563 267 LttvHooks *after_traceset,
dc877563 268 LttvHooks *after_trace,
ffd54a90 269 LttvHooks *after_tracefile,
8697a616 270 LttvHooks *event,
271 LttvHooksById *event_by_id)
dc877563 272{
8697a616 273
dc877563 274 LttvTraceset *ts = self->ts;
275
8697a616 276 guint i, nb_trace;
dc877563 277
278 LttvTraceContext *tc;
279
dc877563 280 nb_trace = lttv_traceset_number(ts);
281
282 for(i = 0 ; i < nb_trace ; i++) {
283 tc = self->traces[i];
8697a616 284 lttv_trace_context_remove_hooks(tc,
285 after_trace,
286 after_tracefile,
287 event,
288 event_by_id);
dc877563 289 }
8697a616 290
291 lttv_hooks_call(after_traceset, self);
292
293
dc877563 294}
295
8697a616 296void lttv_trace_context_add_hooks(LttvTraceContext *self,
297 LttvHooks *before_trace,
298 LttvHooks *before_tracefile,
299 LttvHooks *event,
300 LttvHooksById *event_by_id)
a8c0f09d 301{
8697a616 302 guint i, nb_tracefile;
303
304 LttvTracefileContext *tfc;
305
306 lttv_hooks_call(before_trace, self);
307 nb_tracefile = ltt_trace_control_tracefile_number(self->t) +
308 ltt_trace_per_cpu_tracefile_number(self->t);
309
310 for(i = 0 ; i < nb_tracefile ; i++) {
311 tfc = self->tracefiles[i];
312 lttv_tracefile_context_add_hooks(tfc,
313 before_tracefile,
314 event,
315 event_by_id);
316 }
a8c0f09d 317}
318
8697a616 319
320
321void lttv_trace_context_remove_hooks(LttvTraceContext *self,
322 LttvHooks *after_trace,
323 LttvHooks *after_tracefile,
324 LttvHooks *event,
325 LttvHooksById *event_by_id)
a8c0f09d 326{
8697a616 327 guint i, nb_tracefile;
328
329 LttvTracefileContext *tfc;
330
331 nb_tracefile = ltt_trace_control_tracefile_number(self->t) +
332 ltt_trace_per_cpu_tracefile_number(self->t);
333
334 for(i = 0 ; i < nb_tracefile ; i++) {
335 tfc = self->tracefiles[i];
336 lttv_tracefile_context_remove_hooks(tfc,
337 after_tracefile,
338 event,
339 event_by_id);
340 }
341
342 lttv_hooks_call(after_trace, self);
a8c0f09d 343}
344
8697a616 345void lttv_tracefile_context_add_hooks(LttvTracefileContext *self,
346 LttvHooks *before_tracefile,
347 LttvHooks *event,
348 LttvHooksById *event_by_id)
a8c0f09d 349{
8697a616 350 guint i;
351
352 LttvHooks *hook;
353
354 lttv_hooks_call(before_tracefile, self);
355 lttv_hooks_add_list(self->event, event);
356 if(event_by_id != NULL)
357 for(i = 0; i < lttv_hooks_by_id_max_id(event_by_id); i++) {
358 hook = lttv_hooks_by_id_get(self->event_by_id, i);
359 if(hook != NULL)
360 lttv_hooks_remove_list(hook, lttv_hooks_by_id_get(event_by_id, i));
361 }
362
a8c0f09d 363}
364
8697a616 365void lttv_tracefile_context_remove_hooks(LttvTracefileContext *self,
366 LttvHooks *after_tracefile,
367 LttvHooks *event,
368 LttvHooksById *event_by_id)
a8c0f09d 369{
8697a616 370 guint i;
371
372 LttvHooks *hook;
373
374
375 lttv_hooks_remove_list(self->event, event);
376 if(event_by_id != NULL)
377 for(i = 0; i < lttv_hooks_by_id_max_id(event_by_id); i++) {
378 hook = lttv_hooks_by_id_find(self->event_by_id, i);
379 lttv_hooks_add_list(hook, lttv_hooks_by_id_get(event_by_id, i));
380 }
381
382 lttv_hooks_call(after_tracefile, self);
a8c0f09d 383}
384
8697a616 385
386
a8c0f09d 387void lttv_tracefile_context_add_hooks_by_id(LttvTracefileContext *tfc,
388 unsigned i,
8697a616 389 LttvHooks *event_by_id)
a8c0f09d 390{
391 LttvHooks * h;
8697a616 392 h = lttv_hooks_by_id_find(tfc->event_by_id, i);
393 lttv_hooks_add_list(h, event_by_id);
a8c0f09d 394}
395
396void lttv_tracefile_context_remove_hooks_by_id(LttvTracefileContext *tfc,
397 unsigned i)
398{
8697a616 399 lttv_hooks_by_id_remove(tfc->event_by_id, i);
a8c0f09d 400}
dc877563 401
ba576a78 402static LttvTracesetContext *
dc877563 403new_traceset_context(LttvTracesetContext *self)
404{
ffd54a90 405 return g_object_new(LTTV_TRACESET_CONTEXT_TYPE, NULL);
dc877563 406}
407
408
ba576a78 409static LttvTraceContext *
dc877563 410new_trace_context(LttvTracesetContext *self)
411{
ffd54a90 412 return g_object_new(LTTV_TRACE_CONTEXT_TYPE, NULL);
dc877563 413}
414
415
ba576a78 416static LttvTracefileContext *
dc877563 417new_tracefile_context(LttvTracesetContext *self)
418{
ffd54a90 419 return g_object_new(LTTV_TRACEFILE_CONTEXT_TYPE, NULL);
dc877563 420}
421
422
423static void
424traceset_context_instance_init (GTypeInstance *instance, gpointer g_class)
425{
426 /* Be careful of anything which would not work well with shallow copies */
427}
428
429
430static void
431traceset_context_finalize (LttvTracesetContext *self)
432{
b445142a 433 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACESET_CONTEXT_TYPE)))
434 ->finalize(G_OBJECT(self));
dc877563 435}
436
437
438static void
439traceset_context_class_init (LttvTracesetContextClass *klass)
440{
441 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
442
ffd54a90 443 gobject_class->finalize = (void (*)(GObject *self))traceset_context_finalize;
dc877563 444 klass->init = init;
445 klass->fini = fini;
446 klass->new_traceset_context = new_traceset_context;
447 klass->new_trace_context = new_trace_context;
448 klass->new_tracefile_context = new_tracefile_context;
449}
450
451
452GType
ffd54a90 453lttv_traceset_context_get_type(void)
dc877563 454{
455 static GType type = 0;
456 if (type == 0) {
457 static const GTypeInfo info = {
ffd54a90 458 sizeof (LttvTracesetContextClass),
dc877563 459 NULL, /* base_init */
460 NULL, /* base_finalize */
ffd54a90 461 (GClassInitFunc) traceset_context_class_init, /* class_init */
dc877563 462 NULL, /* class_finalize */
463 NULL, /* class_data */
ffd54a90 464 sizeof (LttvTracesetContext),
dc877563 465 0, /* n_preallocs */
ffd54a90 466 (GInstanceInitFunc) traceset_context_instance_init /* instance_init */
dc877563 467 };
468
ffd54a90 469 type = g_type_register_static (G_TYPE_OBJECT, "LttvTracesetContextType",
dc877563 470 &info, 0);
471 }
472 return type;
473}
474
475
476static void
477trace_context_instance_init (GTypeInstance *instance, gpointer g_class)
478{
479 /* Be careful of anything which would not work well with shallow copies */
480}
481
482
483static void
484trace_context_finalize (LttvTraceContext *self)
485{
b445142a 486 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACE_CONTEXT_TYPE)))->
487 finalize(G_OBJECT(self));
dc877563 488}
489
490
491static void
492trace_context_class_init (LttvTraceContextClass *klass)
493{
494 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
495
ffd54a90 496 gobject_class->finalize = (void (*)(GObject *self)) trace_context_finalize;
dc877563 497}
498
499
500GType
ffd54a90 501lttv_trace_context_get_type(void)
dc877563 502{
503 static GType type = 0;
504 if (type == 0) {
505 static const GTypeInfo info = {
ffd54a90 506 sizeof (LttvTraceContextClass),
dc877563 507 NULL, /* base_init */
508 NULL, /* base_finalize */
ffd54a90 509 (GClassInitFunc) trace_context_class_init, /* class_init */
dc877563 510 NULL, /* class_finalize */
511 NULL, /* class_data */
c6bc9cb9 512 sizeof (LttvTraceContext),
dc877563 513 0, /* n_preallocs */
ffd54a90 514 (GInstanceInitFunc) trace_context_instance_init /* instance_init */
dc877563 515 };
516
ffd54a90 517 type = g_type_register_static (G_TYPE_OBJECT, "LttvTraceContextType",
dc877563 518 &info, 0);
519 }
520 return type;
521}
522
523
524static void
525tracefile_context_instance_init (GTypeInstance *instance, gpointer g_class)
526{
527 /* Be careful of anything which would not work well with shallow copies */
528}
529
530
531static void
532tracefile_context_finalize (LttvTracefileContext *self)
533{
b445142a 534 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACEFILE_CONTEXT_TYPE)))
535 ->finalize(G_OBJECT(self));
dc877563 536}
537
538
539static void
540tracefile_context_class_init (LttvTracefileContextClass *klass)
541{
542 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
543
ffd54a90 544 gobject_class->finalize = (void (*)(GObject *self))tracefile_context_finalize;
545}
546
547
548GType
549lttv_tracefile_context_get_type(void)
550{
551 static GType type = 0;
552 if (type == 0) {
553 static const GTypeInfo info = {
554 sizeof (LttvTracefileContextClass),
555 NULL, /* base_init */
556 NULL, /* base_finalize */
557 (GClassInitFunc) tracefile_context_class_init, /* class_init */
558 NULL, /* class_finalize */
559 NULL, /* class_data */
560 sizeof (LttvTracefileContext),
561 0, /* n_preallocs */
562 (GInstanceInitFunc) tracefile_context_instance_init /* instance_init */
563 };
564
565 type = g_type_register_static (G_TYPE_OBJECT, "LttvTracefileContextType",
566 &info, 0);
567 }
568 return type;
dc877563 569}
570
571
dc877563 572
573gboolean get_first(gpointer key, gpointer value, gpointer user_data) {
574 *((LttvTracefileContext **)user_data) = (LttvTracefileContext *)value;
575 return TRUE;
576}
577
578
dc877563 579
8697a616 580void lttv_process_traceset_begin(LttvTracesetContext *self,
581 LttvHooks *before_traceset,
582 LttvHooks *before_trace,
583 LttvHooks *before_tracefile,
584 LttvHooks *event,
585 LttvHooksById *event_by_id)
586{
dc877563 587
8697a616 588 /* simply add hooks in context. _before hooks are called by add_hooks. */
589 /* It calls all before_traceset, before_trace, and before_tracefile hooks. */
590 lttv_traceset_context_add_hooks(self,
591 before_traceset,
592 before_trace,
593 before_tracefile,
594 event,
595 event_by_id);
596
2a2fa4f0 597}
598
8697a616 599/* Note : a _middle must be preceded from a _seek or another middle */
600guint lttv_process_traceset_middle(LttvTracesetContext *self,
601 LttTime end,
602 unsigned nb_events,
603 const LttvTracesetContextPosition *end_position)
2a2fa4f0 604{
605 GTree *pqueue = self->pqueue;
606
607 guint id;
608
2a2fa4f0 609 LttvTracefileContext *tfc;
610
611 LttEvent *event;
612
613 unsigned count = 0;
614
dc877563 615 /* Get the next event from the pqueue, call its hooks,
616 reinsert in the pqueue the following event from the same tracefile
617 unless the tracefile is finished or the event is later than the
8697a616 618 end time. */
dc877563 619
ffd54a90 620 while(TRUE) {
dc877563 621 tfc = NULL;
622 g_tree_foreach(pqueue, get_first, &tfc);
a43d67ba 623 if(tfc == NULL)
624 {
625 self->e = event;
626 return count;
627 }
dc877563 628
8697a616 629 /* Have we reached :
630 * - the maximum number of events specified?
631 * - the end position ?
632 * - the end time ?
633 * then the read is finished. We leave the queue in the same state and
634 * break the loop.
635 */
636
637 if(count >= nb_events ||
638 lttv_traceset_context_ctx_pos_compare(self,
639 end_position) >= 0 ||
640 ltt_time_compare(tfc->timestamp, end) >= 0)
a43d67ba 641 {
642 self->e = event;
643 return count;
644 }
2a2fa4f0 645
308711e5 646 /* Get the tracefile with an event for the smallest time found. If two
647 or more tracefiles have events for the same time, hope that lookup
648 and remove are consistent. */
270e7cc5 649
f95bc830 650 g_tree_remove(pqueue, tfc);
2a2fa4f0 651 count++;
dc877563 652
8697a616 653 id = ltt_event_eventtype_id(tfc->e);
654 lttv_hooks_call_merge(tfc->event, tfc,
655 lttv_hooks_by_id_get(tfc->event_by_id, id), tfc);
dc877563 656
657 event = ltt_tracefile_read(tfc->tf);
658 if(event != NULL) {
659 tfc->e = event;
ffd54a90 660 tfc->timestamp = ltt_event_time(event);
270e7cc5 661 if(tfc->timestamp.tv_sec < end.tv_sec ||
8697a616 662 (tfc->timestamp.tv_sec == end.tv_sec &&
663 tfc->timestamp.tv_nsec <= end.tv_nsec))
664 g_tree_insert(pqueue, tfc, tfc);
dc877563 665 }
666 }
2a2fa4f0 667}
668
669
8697a616 670void lttv_process_traceset_end(LttvTracesetContext *self,
671 LttvHooks *after_traceset,
672 LttvHooks *after_trace,
673 LttvHooks *after_tracefile,
674 LttvHooks *event,
675 LttvHooksById *event_by_id)
2a2fa4f0 676{
8697a616 677 /* Remove hooks from context. _after hooks are called by remove_hooks. */
678 /* It calls all after_traceset, after_trace, and after_tracefile hooks. */
679 lttv_traceset_context_remove_hooks(self,
680 after_traceset,
681 after_trace,
682 after_tracefile,
683 event,
684 event_by_id);
685}
2a2fa4f0 686
8697a616 687void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start)
688{
689 guint i, nb_tracefile;
2a2fa4f0 690
691 LttvTracefileContext *tfc;
692
8697a616 693 LttEvent *event;
dc877563 694
8697a616 695 nb_tracefile = ltt_trace_control_tracefile_number(self->t) +
696 ltt_trace_per_cpu_tracefile_number(self->t);
dc877563 697
8697a616 698 for(i = 0 ; i < nb_tracefile ; i++) {
699 tfc = self->tracefiles[i];
700 ltt_tracefile_seek_time(tfc->tf, start);
701 event = ltt_tracefile_read(tfc->tf);
702 tfc->e = event;
703 if(event != NULL) {
704 tfc->timestamp = ltt_event_time(event);
705 g_tree_insert(self->ts_context->pqueue, tfc, tfc);
706 }
707 }
708}
dc877563 709
2a2fa4f0 710
8697a616 711void lttv_process_traceset_seek_time(LttvTracesetContext *self, LttTime start)
712{
713 guint i, nb_trace;
2a2fa4f0 714
8697a616 715 LttvTraceContext *tc;
2a2fa4f0 716
8697a616 717 LttvTracefileContext *tfc;
dc877563 718
8697a616 719 /* Empty the pqueue */
dc877563 720
2a2fa4f0 721 while(TRUE){
722 tfc = NULL;
723 g_tree_foreach(self->pqueue, get_first, &tfc);
724 if(tfc == NULL) break;
725 g_tree_remove(self->pqueue, &(tfc->timestamp));
726 }
2a2fa4f0 727
8697a616 728 nb_trace = lttv_traceset_number(self->ts);
729 for(i = 0 ; i < nb_trace ; i++) {
730 tc = self->traces[i];
731 lttv_process_trace_seek_time(tc, start);
732 }
dc877563 733}
b445142a 734
308711e5 735
8697a616 736gboolean lttv_process_trace_seek_position(LttvTraceContext *self,
737 const LttvTraceContextPosition *pos)
308711e5 738{
dbb7bb09 739 guint i, nb_tracefile;
308711e5 740
741 LttvTracefileContext *tfc;
742
743 LttEvent *event;
744
dbb7bb09 745 nb_tracefile = ltt_trace_control_tracefile_number(self->t) +
746 ltt_trace_per_cpu_tracefile_number(self->t);
308711e5 747
8697a616 748 if(nb_tracefile != pos->nb_tracefile)
749 return FALSE; /* Error */
750
dbb7bb09 751 for(i = 0 ; i < nb_tracefile ; i++) {
752 tfc = self->tracefiles[i];
8697a616 753 ltt_tracefile_seek_position(tfc->tf, pos->tf_pos[i]);
308711e5 754 event = ltt_tracefile_read(tfc->tf);
755 tfc->e = event;
8697a616 756 if(event != NULL) {
757 tfc->timestamp = ltt_event_time(event);
758 g_tree_insert(self->ts_context->pqueue, tfc, tfc);
759 }
308711e5 760 }
8697a616 761
762 return TRUE;
308711e5 763}
764
765
8697a616 766
767gboolean lttv_process_traceset_seek_position(LttvTracesetContext *self,
768 const LttvTracesetContextPosition *pos)
308711e5 769{
770 guint i, nb_trace;
8697a616 771 gboolean sum_ret = TRUE;
308711e5 772
773 LttvTraceContext *tc;
774
8697a616 775 LttvTracefileContext *tfc;
776
308711e5 777 nb_trace = lttv_traceset_number(self->ts);
8697a616 778
779 if(nb_trace != pos->nb_trace)
780 return FALSE; /* Error */
781
782 /* Empty the pqueue */
783
784 while(TRUE){
785 tfc = NULL;
786 g_tree_foreach(self->pqueue, get_first, &tfc);
787 if(tfc == NULL) break;
788 g_tree_remove(self->pqueue, &(tfc->timestamp));
789 }
790
308711e5 791 for(i = 0 ; i < nb_trace ; i++) {
792 tc = self->traces[i];
8697a616 793 sum_ret = sum_ret && lttv_process_trace_seek_position(tc, &pos->t_pos[i]);
308711e5 794 }
8697a616 795
796 return sum_ret;
308711e5 797}
798
799
8697a616 800
b445142a 801static LttField *
802find_field(LttEventType *et, const char *field)
803{
804 LttType *t;
805
806 LttField *f;
807
808 guint i, nb;
809
810 char *name;
811
812 if(field == NULL) return NULL;
813
814 f = ltt_eventtype_field(et);
815 t = ltt_eventtype_type(et);
816 g_assert(ltt_type_class(t) == LTT_STRUCT);
817 nb = ltt_type_member_number(t);
818 for(i = 0 ; i < nb ; i++) {
819 ltt_type_member_type(t, i, &name);
820 if(strcmp(name, field) == 0) break;
821 }
822 g_assert(i < nb);
823 return ltt_field_member(f, i);
824}
825
826
827void
828lttv_trace_find_hook(LttTrace *t, char *facility, char *event_type,
829 char *field1, char *field2, char *field3, LttvHook h, LttvTraceHook *th)
830{
831 LttFacility *f;
832
833 LttEventType *et;
834
835 guint nb, pos, i;
836
837 char *name;
838
839 nb = ltt_trace_facility_find(t, facility, &pos);
840 if(nb < 1) g_error("No %s facility", facility);
841 f = ltt_trace_facility_get(t, pos);
842 et = ltt_facility_eventtype_get_by_name(f, event_type);
843 if(et == NULL) g_error("Event %s does not exist", event_type);
844
845 th->h = h;
846 th->id = ltt_eventtype_id(et);
847 th->f1 = find_field(et, field1);
848 th->f2 = find_field(et, field2);
849 th->f3 = find_field(et, field3);
850}
851
852
8697a616 853void lttv_traceset_context_position_save(const LttvTracesetContext *self,
854 LttvTracesetContextPosition *pos)
855{
856 guint nb_trace, nb_tracefile;
857 guint iter_trace, iter_tracefile;
858
859 LttvTraceContext *tc;
860
861 LttvTracefileContext *tfc;
862
863 LttEvent *event;
864
865 pos->nb_trace = nb_trace = lttv_traceset_number(self->ts);
866 pos->t_pos = g_new(LttvTraceContextPosition, nb_trace);
867
868 for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
869 tc = self->traces[iter_trace];
870 pos->t_pos[iter_trace].nb_tracefile = nb_tracefile =
871 ltt_trace_control_tracefile_number(tc->t) +
872 ltt_trace_per_cpu_tracefile_number(tc->t);
873
874 pos->t_pos[iter_trace].tf_pos = g_new(LttEventPosition*, nb_tracefile);
875 for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) {
876 pos->t_pos[iter_trace].tf_pos[iter_tracefile]
877 = ltt_event_position_new();
878 tfc = tc->tracefiles[iter_tracefile];
879 event = tfc->e;
880 ltt_event_position(event,
881 pos->t_pos[iter_trace].tf_pos[iter_tracefile]);
882 }
883 }
884}
885
886void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos)
887{
888 guint nb_trace, nb_tracefile;
889 guint iter_trace, iter_tracefile;
890
891 nb_trace = pos->nb_trace;
892
893 for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
894 for(iter_tracefile = 0; iter_tracefile <
895 pos->t_pos[iter_trace].nb_tracefile;
896 iter_tracefile++) {
897
898 g_free(pos->t_pos[iter_trace].tf_pos[iter_tracefile]);
899 }
900 g_free(pos->t_pos[iter_trace].tf_pos);
901 }
902 g_free(pos->t_pos);
903
904}
905
906gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self,
907 const LttvTracesetContextPosition *pos)
908{
909 guint nb_trace, nb_tracefile;
910 guint iter_trace, iter_tracefile;
911 gint ret;
912
913 LttvTraceContext *tc;
914
915 LttvTracefileContext *tfc;
916
917 LttEvent *event;
918
919 nb_trace = lttv_traceset_number(self->ts);
920
921 if(pos->nb_trace != nb_trace)
922 g_error("lttv_traceset_context_ctx_pos_compare : nb_trace does not match.");
923
924 for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
925 tc = self->traces[iter_trace];
926 nb_tracefile = ltt_trace_control_tracefile_number(tc->t) +
927 ltt_trace_per_cpu_tracefile_number(tc->t);
928
929 if(pos->t_pos[iter_trace].nb_tracefile != nb_tracefile)
930 g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match.");
931
932 for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) {
933 tfc = tc->tracefiles[iter_tracefile];
934 event = tfc->e;
935 if(
936 ret =
937 ltt_event_event_position_compare(event,
938 pos->t_pos[iter_trace].tf_pos[iter_tracefile])
939 != 0)
940 return ret;
941 }
942 }
943 return 0;
944}
945
946
947gint lttv_traceset_context_pos_pos_compare(
948 const LttvTracesetContextPosition *pos1,
949 const LttvTracesetContextPosition *pos2)
950{
951 guint nb_trace, nb_tracefile;
952 guint iter_trace, iter_tracefile;
953
954 gint ret;
955
956 nb_trace = pos1->nb_trace;
957 if(nb_trace != pos2->nb_trace)
958 g_error("lttv_traceset_context_pos_pos_compare : nb_trace does not match.");
959
960 for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
961
962 nb_tracefile = pos1->t_pos[iter_trace].nb_tracefile;
963 if(nb_tracefile != pos2->t_pos[iter_trace].nb_tracefile)
964 g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match.");
965
966 for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) {
967 if(ret =
968 ltt_event_position_compare(
969 pos1->t_pos[iter_trace].tf_pos[iter_tracefile],
970 pos2->t_pos[iter_trace].tf_pos[iter_tracefile])
971 != 0)
972 return ret;
973 }
974 }
975 return 0;
976}
977
978
This page took 0.067346 seconds and 4 git commands to generate.