1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
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;
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.
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,
20 #include <lttv/tracecontext.h>
21 #include <ltt/event.h>
22 #include <ltt/facility.h>
23 #include <ltt/trace.h>
29 gint
compare_tracefile(gconstpointer a
, gconstpointer b
)
33 LttvTracefileContext
*trace_a
= (LttvTracefileContext
*)a
;
35 LttvTracefileContext
*trace_b
= (LttvTracefileContext
*)b
;
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;
47 struct _LttvTraceContextPosition
{
48 LttEventPosition
**tf_pos
; /* Position in each tracefile */
49 guint nb_tracefile
; /* Number of tracefiles (check) */
52 struct _LttvTracesetContextPosition
{
53 LttvTraceContextPosition
*t_pos
; /* Position in each trace */
54 guint nb_trace
; /* Number of traces (check) */
55 LttTime timestamp
; /* Current time at the saved position */
58 void lttv_context_init(LttvTracesetContext
*self
, LttvTraceset
*ts
)
60 LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->init(self
, ts
);
64 void lttv_context_fini(LttvTracesetContext
*self
)
66 LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->fini(self
);
71 lttv_context_new_traceset_context(LttvTracesetContext
*self
)
73 return LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->new_traceset_context(self
);
80 lttv_context_new_trace_context(LttvTracesetContext
*self
)
82 return LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->new_trace_context(self
);
86 LttvTracefileContext
*
87 lttv_context_new_tracefile_context(LttvTracesetContext
*self
)
89 return LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->new_tracefile_context(self
);
92 /****************************************************************************
93 * lttv_traceset_context_compute_time_span
95 * Keep the time span is sync with on the fly addition and removal of traces
96 * in a trace set. It must be called each time a trace is added/removed from
97 * the traceset. It could be more efficient to call it only once a bunch
98 * of traces are loaded, but the calculation is not long, so it's not
101 * Author : Xang Xiu Yang
102 ***************************************************************************/
103 static void lttv_traceset_context_compute_time_span(
104 LttvTracesetContext
*self
,
105 TimeInterval
*time_span
)
107 LttvTraceset
* traceset
= self
->ts
;
108 int numTraces
= lttv_traceset_number(traceset
);
111 LttvTraceContext
*tc
;
114 time_span
->start_time
.tv_sec
= 0;
115 time_span
->start_time
.tv_nsec
= 0;
116 time_span
->end_time
.tv_sec
= 0;
117 time_span
->end_time
.tv_nsec
= 0;
119 for(i
=0; i
<numTraces
;i
++){
120 tc
= self
->traces
[i
];
123 ltt_trace_time_span_get(trace
, &s
, &e
);
126 time_span
->start_time
= s
;
127 time_span
->end_time
= e
;
129 if(s
.tv_sec
< time_span
->start_time
.tv_sec
130 || (s
.tv_sec
== time_span
->start_time
.tv_sec
131 && s
.tv_nsec
< time_span
->start_time
.tv_nsec
))
132 time_span
->start_time
= s
;
133 if(e
.tv_sec
> time_span
->end_time
.tv_sec
134 || (e
.tv_sec
== time_span
->end_time
.tv_sec
135 && e
.tv_nsec
> time_span
->end_time
.tv_nsec
))
136 time_span
->end_time
= e
;
143 init(LttvTracesetContext
*self
, LttvTraceset
*ts
)
145 guint i
, j
, nb_trace
, nb_control
, nb_per_cpu
, nb_tracefile
;
147 LttvTraceContext
*tc
;
149 LttvTracefileContext
*tfc
;
151 LttTime null_time
= {0, 0};
153 nb_trace
= lttv_traceset_number(ts
);
155 self
->traces
= g_new(LttvTraceContext
*, nb_trace
);
156 self
->a
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
157 self
->ts_a
= lttv_traceset_attribute(ts
);
158 for(i
= 0 ; i
< nb_trace
; i
++) {
159 tc
= LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->new_trace_context(self
);
160 self
->traces
[i
] = tc
;
162 tc
->ts_context
= self
;
164 tc
->vt
= lttv_traceset_get(ts
, i
);
165 tc
->t
= lttv_trace(tc
->vt
);
166 tc
->a
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
167 tc
->t_a
= lttv_trace_attribute(tc
->vt
);
168 nb_control
= ltt_trace_control_tracefile_number(tc
->t
);
169 nb_per_cpu
= ltt_trace_per_cpu_tracefile_number(tc
->t
);
170 nb_tracefile
= nb_control
+ nb_per_cpu
;
171 tc
->tracefiles
= g_new(LttvTracefileContext
*, nb_tracefile
);
173 for(j
= 0 ; j
< nb_tracefile
; j
++) {
174 tfc
= LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->new_tracefile_context(self
);
175 tc
->tracefiles
[j
] = tfc
;
180 tfc
->tf
= ltt_trace_control_tracefile_get(tc
->t
, j
);
183 tfc
->control
= FALSE
;
184 tfc
->tf
= ltt_trace_per_cpu_tracefile_get(tc
->t
, j
- nb_control
);
187 tfc
->event
= lttv_hooks_new();
188 tfc
->event_by_id
= lttv_hooks_by_id_new();
189 tfc
->a
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
192 self
->pqueue
= g_tree_new(compare_tracefile
);
193 lttv_process_traceset_seek_time(self
, null_time
);
194 lttv_traceset_context_compute_time_span(self
, &self
->time_span
);
199 void fini(LttvTracesetContext
*self
)
201 guint i
, j
, nb_trace
, nb_tracefile
;
203 LttvTraceContext
*tc
;
205 LttvTracefileContext
*tfc
;
207 LttvTraceset
*ts
= self
->ts
;
211 g_tree_destroy(self
->pqueue
);
212 g_object_unref(self
->a
);
214 nb_trace
= lttv_traceset_number(ts
);
216 for(i
= 0 ; i
< nb_trace
; i
++) {
217 tc
= self
->traces
[i
];
219 g_object_unref(tc
->a
);
221 nb_tracefile
= ltt_trace_control_tracefile_number(tc
->t
) +
222 ltt_trace_per_cpu_tracefile_number(tc
->t
);
224 for(j
= 0 ; j
< nb_tracefile
; j
++) {
225 tfc
= tc
->tracefiles
[j
];
226 lttv_hooks_destroy(tfc
->event
);
227 lttv_hooks_by_id_destroy(tfc
->event_by_id
);
228 g_object_unref(tfc
->a
);
231 g_free(tc
->tracefiles
);
234 g_free(self
->traces
);
238 void lttv_traceset_context_add_hooks(LttvTracesetContext
*self
,
239 LttvHooks
*before_traceset
,
240 LttvHooks
*before_trace
,
241 LttvHooks
*before_tracefile
,
243 LttvHooksById
*event_by_id
)
245 LttvTraceset
*ts
= self
->ts
;
249 LttvTraceContext
*tc
;
251 lttv_hooks_call(before_traceset
, self
);
253 nb_trace
= lttv_traceset_number(ts
);
255 for(i
= 0 ; i
< nb_trace
; i
++) {
256 tc
= self
->traces
[i
];
257 lttv_trace_context_add_hooks(tc
,
266 void lttv_traceset_context_remove_hooks(LttvTracesetContext
*self
,
267 LttvHooks
*after_traceset
,
268 LttvHooks
*after_trace
,
269 LttvHooks
*after_tracefile
,
271 LttvHooksById
*event_by_id
)
274 LttvTraceset
*ts
= self
->ts
;
278 LttvTraceContext
*tc
;
280 nb_trace
= lttv_traceset_number(ts
);
282 for(i
= 0 ; i
< nb_trace
; i
++) {
283 tc
= self
->traces
[i
];
284 lttv_trace_context_remove_hooks(tc
,
291 lttv_hooks_call(after_traceset
, self
);
296 void lttv_trace_context_add_hooks(LttvTraceContext
*self
,
297 LttvHooks
*before_trace
,
298 LttvHooks
*before_tracefile
,
300 LttvHooksById
*event_by_id
)
302 guint i
, nb_tracefile
;
304 LttvTracefileContext
*tfc
;
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
);
310 for(i
= 0 ; i
< nb_tracefile
; i
++) {
311 tfc
= self
->tracefiles
[i
];
312 lttv_tracefile_context_add_hooks(tfc
,
321 void lttv_trace_context_remove_hooks(LttvTraceContext
*self
,
322 LttvHooks
*after_trace
,
323 LttvHooks
*after_tracefile
,
325 LttvHooksById
*event_by_id
)
327 guint i
, nb_tracefile
;
329 LttvTracefileContext
*tfc
;
331 nb_tracefile
= ltt_trace_control_tracefile_number(self
->t
) +
332 ltt_trace_per_cpu_tracefile_number(self
->t
);
334 for(i
= 0 ; i
< nb_tracefile
; i
++) {
335 tfc
= self
->tracefiles
[i
];
336 lttv_tracefile_context_remove_hooks(tfc
,
342 lttv_hooks_call(after_trace
, self
);
345 void lttv_tracefile_context_add_hooks(LttvTracefileContext
*self
,
346 LttvHooks
*before_tracefile
,
348 LttvHooksById
*event_by_id
)
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
);
360 lttv_hooks_remove_list(hook
, lttv_hooks_by_id_get(event_by_id
, i
));
365 void lttv_tracefile_context_remove_hooks(LttvTracefileContext
*self
,
366 LttvHooks
*after_tracefile
,
368 LttvHooksById
*event_by_id
)
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
));
382 lttv_hooks_call(after_tracefile
, self
);
387 void lttv_tracefile_context_add_hooks_by_id(LttvTracefileContext
*tfc
,
389 LttvHooks
*event_by_id
)
392 h
= lttv_hooks_by_id_find(tfc
->event_by_id
, i
);
393 lttv_hooks_add_list(h
, event_by_id
);
396 void lttv_tracefile_context_remove_hooks_by_id(LttvTracefileContext
*tfc
,
399 lttv_hooks_by_id_remove(tfc
->event_by_id
, i
);
402 static LttvTracesetContext
*
403 new_traceset_context(LttvTracesetContext
*self
)
405 return g_object_new(LTTV_TRACESET_CONTEXT_TYPE
, NULL
);
409 static LttvTraceContext
*
410 new_trace_context(LttvTracesetContext
*self
)
412 return g_object_new(LTTV_TRACE_CONTEXT_TYPE
, NULL
);
416 static LttvTracefileContext
*
417 new_tracefile_context(LttvTracesetContext
*self
)
419 return g_object_new(LTTV_TRACEFILE_CONTEXT_TYPE
, NULL
);
424 traceset_context_instance_init (GTypeInstance
*instance
, gpointer g_class
)
426 /* Be careful of anything which would not work well with shallow copies */
431 traceset_context_finalize (LttvTracesetContext
*self
)
433 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACESET_CONTEXT_TYPE
)))
434 ->finalize(G_OBJECT(self
));
439 traceset_context_class_init (LttvTracesetContextClass
*klass
)
441 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
443 gobject_class
->finalize
= (void (*)(GObject
*self
))traceset_context_finalize
;
446 klass
->new_traceset_context
= new_traceset_context
;
447 klass
->new_trace_context
= new_trace_context
;
448 klass
->new_tracefile_context
= new_tracefile_context
;
453 lttv_traceset_context_get_type(void)
455 static GType type
= 0;
457 static const GTypeInfo info
= {
458 sizeof (LttvTracesetContextClass
),
459 NULL
, /* base_init */
460 NULL
, /* base_finalize */
461 (GClassInitFunc
) traceset_context_class_init
, /* class_init */
462 NULL
, /* class_finalize */
463 NULL
, /* class_data */
464 sizeof (LttvTracesetContext
),
466 (GInstanceInitFunc
) traceset_context_instance_init
/* instance_init */
469 type
= g_type_register_static (G_TYPE_OBJECT
, "LttvTracesetContextType",
477 trace_context_instance_init (GTypeInstance
*instance
, gpointer g_class
)
479 /* Be careful of anything which would not work well with shallow copies */
484 trace_context_finalize (LttvTraceContext
*self
)
486 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACE_CONTEXT_TYPE
)))->
487 finalize(G_OBJECT(self
));
492 trace_context_class_init (LttvTraceContextClass
*klass
)
494 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
496 gobject_class
->finalize
= (void (*)(GObject
*self
)) trace_context_finalize
;
501 lttv_trace_context_get_type(void)
503 static GType type
= 0;
505 static const GTypeInfo info
= {
506 sizeof (LttvTraceContextClass
),
507 NULL
, /* base_init */
508 NULL
, /* base_finalize */
509 (GClassInitFunc
) trace_context_class_init
, /* class_init */
510 NULL
, /* class_finalize */
511 NULL
, /* class_data */
512 sizeof (LttvTraceContext
),
514 (GInstanceInitFunc
) trace_context_instance_init
/* instance_init */
517 type
= g_type_register_static (G_TYPE_OBJECT
, "LttvTraceContextType",
525 tracefile_context_instance_init (GTypeInstance
*instance
, gpointer g_class
)
527 /* Be careful of anything which would not work well with shallow copies */
532 tracefile_context_finalize (LttvTracefileContext
*self
)
534 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACEFILE_CONTEXT_TYPE
)))
535 ->finalize(G_OBJECT(self
));
540 tracefile_context_class_init (LttvTracefileContextClass
*klass
)
542 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
544 gobject_class
->finalize
= (void (*)(GObject
*self
))tracefile_context_finalize
;
549 lttv_tracefile_context_get_type(void)
551 static GType 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
),
562 (GInstanceInitFunc
) tracefile_context_instance_init
/* instance_init */
565 type
= g_type_register_static (G_TYPE_OBJECT
, "LttvTracefileContextType",
573 gboolean
get_first(gpointer key
, gpointer value
, gpointer user_data
) {
574 *((LttvTracefileContext
**)user_data
) = (LttvTracefileContext
*)value
;
580 void lttv_process_traceset_begin(LttvTracesetContext
*self
,
581 LttvHooks
*before_traceset
,
582 LttvHooks
*before_trace
,
583 LttvHooks
*before_tracefile
,
585 LttvHooksById
*event_by_id
)
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
,
599 /* Note : a _middle must be preceded from a _seek or another middle */
600 guint
lttv_process_traceset_middle(LttvTracesetContext
*self
,
603 const LttvTracesetContextPosition
*end_position
)
605 GTree
*pqueue
= self
->pqueue
;
609 LttvTracefileContext
*tfc
;
615 gboolean last_ret
= FALSE
; /* return value of the last hook list called */
617 /* Get the next event from the pqueue, call its hooks,
618 reinsert in the pqueue the following event from the same tracefile
619 unless the tracefile is finished or the event is later than the
624 g_tree_foreach(pqueue
, get_first
, &tfc
);
625 /* End of traceset : tfc is NULL */
632 * - the maximum number of events specified?
633 * - the end position ?
635 * then the read is finished. We leave the queue in the same state and
639 if(last_ret
== TRUE
||
640 count
>= nb_events
||
641 (end_position
!=NULL
)?FALSE
:lttv_traceset_context_ctx_pos_compare(self
,
642 end_position
) >= 0 ||
643 ltt_time_compare(tfc
->timestamp
, end
) >= 0)
648 /* Get the tracefile with an event for the smallest time found. If two
649 or more tracefiles have events for the same time, hope that lookup
650 and remove are consistent. */
652 g_tree_remove(pqueue
, tfc
);
655 id
= ltt_event_eventtype_id(tfc
->e
);
656 last_ret
= lttv_hooks_call_merge(tfc
->event
, tfc
,
657 lttv_hooks_by_id_get(tfc
->event_by_id
, id
), tfc
);
659 event
= ltt_tracefile_read(tfc
->tf
);
662 tfc
->timestamp
= ltt_event_time(event
);
663 g_tree_insert(pqueue
, tfc
, tfc
);
669 void lttv_process_traceset_end(LttvTracesetContext
*self
,
670 LttvHooks
*after_traceset
,
671 LttvHooks
*after_trace
,
672 LttvHooks
*after_tracefile
,
674 LttvHooksById
*event_by_id
)
676 /* Remove hooks from context. _after hooks are called by remove_hooks. */
677 /* It calls all after_traceset, after_trace, and after_tracefile hooks. */
678 lttv_traceset_context_remove_hooks(self
,
686 void lttv_process_trace_seek_time(LttvTraceContext
*self
, LttTime start
)
688 guint i
, nb_tracefile
;
690 LttvTracefileContext
*tfc
;
694 GTree
*pqueue
= self
->ts_context
->pqueue
;
696 nb_tracefile
= ltt_trace_control_tracefile_number(self
->t
) +
697 ltt_trace_per_cpu_tracefile_number(self
->t
);
699 for(i
= 0 ; i
< nb_tracefile
; i
++) {
700 tfc
= self
->tracefiles
[i
];
701 ltt_tracefile_seek_time(tfc
->tf
, start
);
702 g_tree_remove(pqueue
, tfc
);
703 event
= ltt_tracefile_read(tfc
->tf
);
706 tfc
->timestamp
= ltt_event_time(event
);
707 g_tree_insert(pqueue
, tfc
, tfc
);
713 void lttv_process_traceset_seek_time(LttvTracesetContext
*self
, LttTime start
)
717 LttvTraceContext
*tc
;
719 LttvTracefileContext
*tfc
;
721 nb_trace
= lttv_traceset_number(self
->ts
);
722 for(i
= 0 ; i
< nb_trace
; i
++) {
723 tc
= self
->traces
[i
];
724 lttv_process_trace_seek_time(tc
, start
);
729 gboolean
lttv_process_tracefile_seek_position(LttvTracefileContext
*self
,
730 const LttEventPosition
*pos
)
732 LttvTracefileContext
*tfc
= self
;
736 GTree
*pqueue
= self
->t_context
->ts_context
->pqueue
;
738 ltt_tracefile_seek_position(tfc
->tf
, pos
);
739 g_tree_remove(pqueue
, tfc
);
740 event
= ltt_tracefile_read(tfc
->tf
);
743 tfc
->timestamp
= ltt_event_time(event
);
744 g_tree_insert(pqueue
, tfc
, tfc
);
750 gboolean
lttv_process_trace_seek_position(LttvTraceContext
*self
,
751 const LttvTraceContextPosition
*pos
)
753 guint i
, nb_tracefile
;
755 LttvTracefileContext
*tfc
;
759 nb_tracefile
= ltt_trace_control_tracefile_number(self
->t
) +
760 ltt_trace_per_cpu_tracefile_number(self
->t
);
762 if(nb_tracefile
!= pos
->nb_tracefile
)
763 return FALSE
; /* Error */
765 for(i
= 0 ; i
< nb_tracefile
; i
++) {
766 tfc
= self
->tracefiles
[i
];
767 lttv_process_tracefile_seek_position(tfc
, pos
->tf_pos
[i
]);
775 gboolean
lttv_process_traceset_seek_position(LttvTracesetContext
*self
,
776 const LttvTracesetContextPosition
*pos
)
779 gboolean sum_ret
= TRUE
;
781 LttvTraceContext
*tc
;
783 LttvTracefileContext
*tfc
;
785 nb_trace
= lttv_traceset_number(self
->ts
);
787 if(nb_trace
!= pos
->nb_trace
)
788 return FALSE
; /* Error */
790 for(i
= 0 ; i
< nb_trace
; i
++) {
791 tc
= self
->traces
[i
];
792 sum_ret
= sum_ret
&& lttv_process_trace_seek_position(tc
, &pos
->t_pos
[i
]);
801 find_field(LttEventType
*et
, const char *field
)
811 if(field
== NULL
) return NULL
;
813 f
= ltt_eventtype_field(et
);
814 t
= ltt_eventtype_type(et
);
815 g_assert(ltt_type_class(t
) == LTT_STRUCT
);
816 nb
= ltt_type_member_number(t
);
817 for(i
= 0 ; i
< nb
; i
++) {
818 ltt_type_member_type(t
, i
, &name
);
819 if(strcmp(name
, field
) == 0) break;
822 return ltt_field_member(f
, i
);
827 lttv_trace_find_hook(LttTrace
*t
, char *facility
, char *event_type
,
828 char *field1
, char *field2
, char *field3
, LttvHook h
, LttvTraceHook
*th
)
838 nb
= ltt_trace_facility_find(t
, facility
, &pos
);
839 if(nb
< 1) g_error("No %s facility", facility
);
840 f
= ltt_trace_facility_get(t
, pos
);
841 et
= ltt_facility_eventtype_get_by_name(f
, event_type
);
842 if(et
== NULL
) g_error("Event %s does not exist", event_type
);
845 th
->id
= ltt_eventtype_id(et
);
846 th
->f1
= find_field(et
, field1
);
847 th
->f2
= find_field(et
, field2
);
848 th
->f3
= find_field(et
, field3
);
852 void lttv_traceset_context_position_save(const LttvTracesetContext
*self
,
853 LttvTracesetContextPosition
*pos
)
855 guint nb_trace
, nb_tracefile
;
856 guint iter_trace
, iter_tracefile
;
858 LttvTraceContext
*tc
;
860 LttvTracefileContext
*tfc
;
864 LttTime timestamp
= self
->time_span
.end_time
;
866 pos
->nb_trace
= nb_trace
= lttv_traceset_number(self
->ts
);
867 pos
->t_pos
= g_new(LttvTraceContextPosition
, nb_trace
);
869 for(iter_trace
= 0 ; iter_trace
< nb_trace
; iter_trace
++) {
870 tc
= self
->traces
[iter_trace
];
871 pos
->t_pos
[iter_trace
].nb_tracefile
= nb_tracefile
=
872 ltt_trace_control_tracefile_number(tc
->t
) +
873 ltt_trace_per_cpu_tracefile_number(tc
->t
);
875 pos
->t_pos
[iter_trace
].tf_pos
= g_new(LttEventPosition
*, nb_tracefile
);
876 for(iter_tracefile
= 0; iter_tracefile
< nb_tracefile
; iter_tracefile
++) {
877 pos
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
]
878 = ltt_event_position_new();
879 tfc
= tc
->tracefiles
[iter_tracefile
];
881 ltt_event_position(event
,
882 pos
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
]);
883 if(ltt_time_compare(tfc
->timestamp
, timestamp
) < 0)
884 timestamp
= tfc
->timestamp
;
887 pos
->timestamp
= timestamp
;
890 void lttv_traceset_context_position_destroy(LttvTracesetContextPosition
*pos
)
892 guint nb_trace
, nb_tracefile
;
893 guint iter_trace
, iter_tracefile
;
895 nb_trace
= pos
->nb_trace
;
897 for(iter_trace
= 0 ; iter_trace
< nb_trace
; iter_trace
++) {
898 for(iter_tracefile
= 0; iter_tracefile
<
899 pos
->t_pos
[iter_trace
].nb_tracefile
;
902 g_free(pos
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
]);
904 g_free(pos
->t_pos
[iter_trace
].tf_pos
);
910 gint
lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext
*self
,
911 const LttvTracesetContextPosition
*pos
)
913 guint nb_trace
, nb_tracefile
;
914 guint iter_trace
, iter_tracefile
;
917 LttvTraceContext
*tc
;
919 LttvTracefileContext
*tfc
;
923 nb_trace
= lttv_traceset_number(self
->ts
);
925 if(pos
->nb_trace
!= nb_trace
)
926 g_error("lttv_traceset_context_ctx_pos_compare : nb_trace does not match.");
928 for(iter_trace
= 0 ; iter_trace
< nb_trace
; iter_trace
++) {
929 tc
= self
->traces
[iter_trace
];
930 nb_tracefile
= ltt_trace_control_tracefile_number(tc
->t
) +
931 ltt_trace_per_cpu_tracefile_number(tc
->t
);
933 if(pos
->t_pos
[iter_trace
].nb_tracefile
!= nb_tracefile
)
934 g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match.");
936 for(iter_tracefile
= 0; iter_tracefile
< nb_tracefile
; iter_tracefile
++) {
937 tfc
= tc
->tracefiles
[iter_tracefile
];
941 ltt_event_event_position_compare(event
,
942 pos
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
])
951 gint
lttv_traceset_context_pos_pos_compare(
952 const LttvTracesetContextPosition
*pos1
,
953 const LttvTracesetContextPosition
*pos2
)
955 guint nb_trace
, nb_tracefile
;
956 guint iter_trace
, iter_tracefile
;
960 nb_trace
= pos1
->nb_trace
;
961 if(nb_trace
!= pos2
->nb_trace
)
962 g_error("lttv_traceset_context_pos_pos_compare : nb_trace does not match.");
964 for(iter_trace
= 0 ; iter_trace
< nb_trace
; iter_trace
++) {
966 nb_tracefile
= pos1
->t_pos
[iter_trace
].nb_tracefile
;
967 if(nb_tracefile
!= pos2
->t_pos
[iter_trace
].nb_tracefile
)
968 g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match.");
970 for(iter_tracefile
= 0; iter_tracefile
< nb_tracefile
; iter_tracefile
++) {
972 ltt_event_position_compare(
973 pos1
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
],
974 pos2
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
])
983 LttTime
lttv_traceset_context_position_get_time(
984 const LttvTracesetContextPosition
*pos
)
986 return pos
->timestamp
;
990 LttvTracefileContext
*lttv_traceset_context_get_current_tfc(LttvTracesetContext
*self
)
992 GTree
*pqueue
= self
->pqueue
;
993 LttvTracefileContext
*tfc
;
995 g_tree_foreach(pqueue
, get_first
, &tfc
);