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,
24 #include <lttv/tracecontext.h>
25 #include <ltt/event.h>
26 #include <ltt/facility.h>
27 #include <ltt/trace.h>
33 static gint
compare_tracefile(gconstpointer a
, gconstpointer b
)
37 const LttvTracefileContext
*trace_a
= (const LttvTracefileContext
*)a
;
38 const LttvTracefileContext
*trace_b
= (const LttvTracefileContext
*)b
;
40 if(likely(trace_a
!= trace_b
)) {
41 comparison
= ltt_time_compare(trace_a
->timestamp
, trace_b
->timestamp
);
42 if(unlikely(comparison
== 0)) {
43 if(trace_a
->index
< trace_b
->index
) comparison
= -1;
44 else if(trace_a
->index
> trace_b
->index
) comparison
= 1;
45 else if(trace_a
->t_context
->index
< trace_b
->t_context
->index
)
47 else if(trace_a
->t_context
->index
> trace_b
->t_context
->index
)
54 struct _LttvTraceContextPosition
{
55 LttEventPosition
**tf_pos
; /* Position in each tracefile */
56 guint nb_tracefile
; /* Number of tracefiles (check) */
59 struct _LttvTracesetContextPosition
{
60 LttvTraceContextPosition
*t_pos
; /* Position in each trace */
61 guint nb_trace
; /* Number of traces (check) */
62 LttTime timestamp
; /* Current time at the saved position */
65 void lttv_context_init(LttvTracesetContext
*self
, LttvTraceset
*ts
)
67 LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->init(self
, ts
);
71 void lttv_context_fini(LttvTracesetContext
*self
)
73 LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->fini(self
);
78 lttv_context_new_traceset_context(LttvTracesetContext
*self
)
80 return LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->new_traceset_context(self
);
87 lttv_context_new_trace_context(LttvTracesetContext
*self
)
89 return LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->new_trace_context(self
);
93 LttvTracefileContext
*
94 lttv_context_new_tracefile_context(LttvTracesetContext
*self
)
96 return LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->new_tracefile_context(self
);
99 /****************************************************************************
100 * lttv_traceset_context_compute_time_span
102 * Keep the time span is sync with on the fly addition and removal of traces
103 * in a trace set. It must be called each time a trace is added/removed from
104 * the traceset. It could be more efficient to call it only once a bunch
105 * of traces are loaded, but the calculation is not long, so it's not
108 * Author : Xang Xiu Yang
109 ***************************************************************************/
110 static void lttv_traceset_context_compute_time_span(
111 LttvTracesetContext
*self
,
112 TimeInterval
*time_span
)
114 LttvTraceset
* traceset
= self
->ts
;
115 int numTraces
= lttv_traceset_number(traceset
);
118 LttvTraceContext
*tc
;
121 time_span
->start_time
.tv_sec
= 0;
122 time_span
->start_time
.tv_nsec
= 0;
123 time_span
->end_time
.tv_sec
= 0;
124 time_span
->end_time
.tv_nsec
= 0;
126 for(i
=0; i
<numTraces
;i
++){
127 tc
= self
->traces
[i
];
130 ltt_trace_time_span_get(trace
, &s
, &e
);
133 time_span
->start_time
= s
;
134 time_span
->end_time
= e
;
136 if(s
.tv_sec
< time_span
->start_time
.tv_sec
137 || (s
.tv_sec
== time_span
->start_time
.tv_sec
138 && s
.tv_nsec
< time_span
->start_time
.tv_nsec
))
139 time_span
->start_time
= s
;
140 if(e
.tv_sec
> time_span
->end_time
.tv_sec
141 || (e
.tv_sec
== time_span
->end_time
.tv_sec
142 && e
.tv_nsec
> time_span
->end_time
.tv_nsec
))
143 time_span
->end_time
= e
;
148 static void init_tracefile_context(LttTracefile
*tracefile
,
149 LttvTraceContext
*tc
)
151 LttvTracefileContext
*tfc
;
152 LttvTracesetContext
*tsc
= tc
->ts_context
;
154 tfc
= LTTV_TRACESET_CONTEXT_GET_CLASS(tsc
)->new_tracefile_context(tsc
);
156 tfc
->index
= tc
->tracefiles
->len
;
157 tc
->tracefiles
= g_array_append_val(tc
->tracefiles
, tfc
);
162 tfc
->event
= lttv_hooks_new();
163 tfc
->event_by_id
= lttv_hooks_by_id_new();
164 tfc
->a
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
169 init(LttvTracesetContext
*self
, LttvTraceset
*ts
)
171 guint i
, j
, nb_trace
, nb_control
, nb_per_cpu
, nb_tracefile
;
173 LttvTraceContext
*tc
;
175 GData
*tracefiles_groups
;
177 struct compute_tracefile_group_args args
;
179 nb_trace
= lttv_traceset_number(ts
);
181 self
->traces
= g_new(LttvTraceContext
*, nb_trace
);
182 self
->a
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
183 self
->ts_a
= lttv_traceset_attribute(ts
);
184 for(i
= 0 ; i
< nb_trace
; i
++) {
185 tc
= LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->new_trace_context(self
);
186 self
->traces
[i
] = tc
;
188 tc
->ts_context
= self
;
190 tc
->vt
= lttv_traceset_get(ts
, i
);
191 tc
->t
= lttv_trace(tc
->vt
);
192 tc
->a
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
193 tc
->t_a
= lttv_trace_attribute(tc
->vt
);
195 tracefiles_groups
= ltt_trace_get_tracefiles_groups(tc
->t
);
197 args
.func
= (ForEachTraceFileFunc
)init_tracefile_context
;
200 g_datalist_foreach(&tracefiles_groups
,
201 (GDataForeachFunc
)compute_tracefile_group
,
205 nb_control
= ltt_trace_control_tracefile_number(tc
->t
);
206 nb_per_cpu
= ltt_trace_per_cpu_tracefile_number(tc
->t
);
207 nb_tracefile
= nb_control
+ nb_per_cpu
;
208 tc
->tracefiles
= g_new(LttvTracefileContext
*, nb_tracefile
);
210 for(j
= 0 ; j
< nb_tracefile
; j
++) {
211 tfc
= LTTV_TRACESET_CONTEXT_GET_CLASS(self
)->new_tracefile_context(self
);
212 tc
->tracefiles
[j
] = tfc
;
217 tfc
->tf
= ltt_trace_control_tracefile_get(tc
->t
, j
);
220 tfc
->control
= FALSE
;
221 tfc
->tf
= ltt_trace_per_cpu_tracefile_get(tc
->t
, j
- nb_control
);
225 tfc
->e
= ltt_event_new();
226 tfc
->event
= lttv_hooks_new();
227 tfc
->event_by_id
= lttv_hooks_by_id_new();
228 tfc
->a
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
233 self
->pqueue
= g_tree_new(compare_tracefile
);
234 lttv_process_traceset_seek_time(self
, ltt_time_zero
);
235 lttv_traceset_context_compute_time_span(self
, &self
->time_span
);
240 void fini(LttvTracesetContext
*self
)
242 guint i
, j
, nb_trace
, nb_tracefile
;
244 LttvTraceContext
*tc
;
246 LttvTracefileContext
*tfc
;
248 LttvTraceset
*ts
= self
->ts
;
252 g_tree_destroy(self
->pqueue
);
253 g_object_unref(self
->a
);
255 nb_trace
= lttv_traceset_number(ts
);
257 for(i
= 0 ; i
< nb_trace
; i
++) {
258 tc
= self
->traces
[i
];
260 g_object_unref(tc
->a
);
262 nb_tracefile
= tc
->tracefiles
->len
;
264 for(j
= 0 ; j
< nb_tracefile
; j
++) {
265 tfc
= &g_array_index(tc
->tracefiles
, LttvTracefileContext
, j
);
266 lttv_hooks_destroy(tfc
->event
);
267 lttv_hooks_by_id_destroy(tfc
->event_by_id
);
268 g_object_unref(tfc
->a
);
271 g_array_free(tc
->tracefiles
, TRUE
);
274 g_free(self
->traces
);
278 void lttv_traceset_context_add_hooks(LttvTracesetContext
*self
,
279 LttvHooks
*before_traceset
,
280 LttvHooks
*before_trace
,
281 LttvHooks
*before_tracefile
,
283 LttvHooksById
*event_by_id
)
285 LttvTraceset
*ts
= self
->ts
;
289 LttvTraceContext
*tc
;
291 lttv_hooks_call(before_traceset
, self
);
293 nb_trace
= lttv_traceset_number(ts
);
295 for(i
= 0 ; i
< nb_trace
; i
++) {
296 tc
= self
->traces
[i
];
297 lttv_trace_context_add_hooks(tc
,
306 void lttv_traceset_context_remove_hooks(LttvTracesetContext
*self
,
307 LttvHooks
*after_traceset
,
308 LttvHooks
*after_trace
,
309 LttvHooks
*after_tracefile
,
311 LttvHooksById
*event_by_id
)
314 LttvTraceset
*ts
= self
->ts
;
318 LttvTraceContext
*tc
;
320 nb_trace
= lttv_traceset_number(ts
);
322 for(i
= 0 ; i
< nb_trace
; i
++) {
323 tc
= self
->traces
[i
];
324 lttv_trace_context_remove_hooks(tc
,
331 lttv_hooks_call(after_traceset
, self
);
336 void lttv_trace_context_add_hooks(LttvTraceContext
*self
,
337 LttvHooks
*before_trace
,
338 LttvHooks
*before_tracefile
,
340 LttvHooksById
*event_by_id
)
342 guint i
, nb_tracefile
;
344 LttvTracefileContext
*tfc
;
346 lttv_hooks_call(before_trace
, self
);
348 nb_tracefile
= self
->tracefiles
->len
;
350 for(i
= 0 ; i
< nb_tracefile
; i
++) {
351 tfc
= &g_array_index(self
->tracefiles
, LttvTracefileContext
, i
);
352 lttv_tracefile_context_add_hooks(tfc
,
361 void lttv_trace_context_remove_hooks(LttvTraceContext
*self
,
362 LttvHooks
*after_trace
,
363 LttvHooks
*after_tracefile
,
365 LttvHooksById
*event_by_id
)
367 guint i
, nb_tracefile
;
369 LttvTracefileContext
*tfc
;
371 nb_tracefile
= self
->tracefiles
->len
;
373 for(i
= 0 ; i
< nb_tracefile
; i
++) {
374 tfc
= &g_array_index(self
->tracefiles
, LttvTracefileContext
, i
);
375 lttv_tracefile_context_remove_hooks(tfc
,
381 lttv_hooks_call(after_trace
, self
);
384 void lttv_tracefile_context_add_hooks(LttvTracefileContext
*self
,
385 LttvHooks
*before_tracefile
,
387 LttvHooksById
*event_by_id
)
393 lttv_hooks_call(before_tracefile
, self
);
394 lttv_hooks_add_list(self
->event
, event
);
395 if(event_by_id
!= NULL
)
396 for(i
= 0; i
< lttv_hooks_by_id_max_id(event_by_id
); i
++) {
397 hook
= lttv_hooks_by_id_find(self
->event_by_id
, i
);
398 lttv_hooks_add_list(hook
, lttv_hooks_by_id_get(event_by_id
, i
));
403 void lttv_tracefile_context_remove_hooks(LttvTracefileContext
*self
,
404 LttvHooks
*after_tracefile
,
406 LttvHooksById
*event_by_id
)
413 lttv_hooks_remove_list(self
->event
, event
);
414 if(event_by_id
!= NULL
)
415 for(i
= 0; i
< lttv_hooks_by_id_max_id(event_by_id
); i
++) {
416 hook
= lttv_hooks_by_id_get(self
->event_by_id
, i
);
418 lttv_hooks_remove_list(hook
, lttv_hooks_by_id_get(event_by_id
, i
));
421 lttv_hooks_call(after_tracefile
, self
);
426 void lttv_tracefile_context_add_hooks_by_id(LttvTracefileContext
*tfc
,
428 LttvHooks
*event_by_id
)
431 h
= lttv_hooks_by_id_find(tfc
->event_by_id
, i
);
432 lttv_hooks_add_list(h
, event_by_id
);
435 void lttv_tracefile_context_remove_hooks_by_id(LttvTracefileContext
*tfc
,
438 lttv_hooks_by_id_remove(tfc
->event_by_id
, i
);
441 static LttvTracesetContext
*
442 new_traceset_context(LttvTracesetContext
*self
)
444 return g_object_new(LTTV_TRACESET_CONTEXT_TYPE
, NULL
);
448 static LttvTraceContext
*
449 new_trace_context(LttvTracesetContext
*self
)
451 return g_object_new(LTTV_TRACE_CONTEXT_TYPE
, NULL
);
455 static LttvTracefileContext
*
456 new_tracefile_context(LttvTracesetContext
*self
)
458 return g_object_new(LTTV_TRACEFILE_CONTEXT_TYPE
, NULL
);
463 traceset_context_instance_init (GTypeInstance
*instance
, gpointer g_class
)
465 /* Be careful of anything which would not work well with shallow copies */
470 traceset_context_finalize (LttvTracesetContext
*self
)
472 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACESET_CONTEXT_TYPE
)))
473 ->finalize(G_OBJECT(self
));
478 traceset_context_class_init (LttvTracesetContextClass
*klass
)
480 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
482 gobject_class
->finalize
= (void (*)(GObject
*self
))traceset_context_finalize
;
485 klass
->new_traceset_context
= new_traceset_context
;
486 klass
->new_trace_context
= new_trace_context
;
487 klass
->new_tracefile_context
= new_tracefile_context
;
492 lttv_traceset_context_get_type(void)
494 static GType type
= 0;
496 static const GTypeInfo info
= {
497 sizeof (LttvTracesetContextClass
),
498 NULL
, /* base_init */
499 NULL
, /* base_finalize */
500 (GClassInitFunc
) traceset_context_class_init
, /* class_init */
501 NULL
, /* class_finalize */
502 NULL
, /* class_data */
503 sizeof (LttvTracesetContext
),
505 (GInstanceInitFunc
) traceset_context_instance_init
, /* instance_init */
506 NULL
/* Value handling */
509 type
= g_type_register_static (G_TYPE_OBJECT
, "LttvTracesetContextType",
517 trace_context_instance_init (GTypeInstance
*instance
, gpointer g_class
)
519 /* Be careful of anything which would not work well with shallow copies */
524 trace_context_finalize (LttvTraceContext
*self
)
526 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACE_CONTEXT_TYPE
)))->
527 finalize(G_OBJECT(self
));
532 trace_context_class_init (LttvTraceContextClass
*klass
)
534 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
536 gobject_class
->finalize
= (void (*)(GObject
*self
)) trace_context_finalize
;
541 lttv_trace_context_get_type(void)
543 static GType type
= 0;
545 static const GTypeInfo info
= {
546 sizeof (LttvTraceContextClass
),
547 NULL
, /* base_init */
548 NULL
, /* base_finalize */
549 (GClassInitFunc
) trace_context_class_init
, /* class_init */
550 NULL
, /* class_finalize */
551 NULL
, /* class_data */
552 sizeof (LttvTraceContext
),
554 (GInstanceInitFunc
) trace_context_instance_init
, /* instance_init */
555 NULL
/* Value handling */
558 type
= g_type_register_static (G_TYPE_OBJECT
, "LttvTraceContextType",
566 tracefile_context_instance_init (GTypeInstance
*instance
, gpointer g_class
)
568 /* Be careful of anything which would not work well with shallow copies */
573 tracefile_context_finalize (LttvTracefileContext
*self
)
575 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(LTTV_TRACEFILE_CONTEXT_TYPE
)))
576 ->finalize(G_OBJECT(self
));
581 tracefile_context_class_init (LttvTracefileContextClass
*klass
)
583 GObjectClass
*gobject_class
= G_OBJECT_CLASS(klass
);
585 gobject_class
->finalize
= (void (*)(GObject
*self
))tracefile_context_finalize
;
590 lttv_tracefile_context_get_type(void)
592 static GType type
= 0;
594 static const GTypeInfo info
= {
595 sizeof (LttvTracefileContextClass
),
596 NULL
, /* base_init */
597 NULL
, /* base_finalize */
598 (GClassInitFunc
) tracefile_context_class_init
, /* class_init */
599 NULL
, /* class_finalize */
600 NULL
, /* class_data */
601 sizeof (LttvTracefileContext
),
603 (GInstanceInitFunc
) tracefile_context_instance_init
, /* instance_init */
604 NULL
/* Value handling */
607 type
= g_type_register_static (G_TYPE_OBJECT
, "LttvTracefileContextType",
615 static gboolean
get_first(gpointer key
, gpointer value
, gpointer user_data
) {
616 *((LttvTracefileContext
**)user_data
) = (LttvTracefileContext
*)value
;
621 /* Put all the tracefiles at the tracefile context position */
622 void lttv_process_traceset_synchronize_tracefiles(LttvTracesetContext
*self
)
624 guint iter_trace
, nb_trace
;
626 LttvTraceContext
*tc
;
628 nb_trace
= lttv_traceset_number(self
->ts
);
630 for(iter_trace
= 0 ; iter_trace
< nb_trace
; iter_trace
++) {
631 tc
= self
->traces
[iter_trace
];
634 guint iter_tf
, nb_tracefile
;
636 LttvTracefileContext
*tfc
;
638 nb_tracefile
= tc
->tracefiles
->len
;
640 for(iter_tf
= 0 ; iter_tf
< nb_tracefile
; iter_tf
++) {
641 tfc
= &g_array_index(tc
->tracefiles
, LttvTracefileContext
, iter_tf
);
644 //ltt_tracefile_copy(tfc->tf_sync_data, tfc->tf);
645 LttEventPosition
*ep
= ltt_event_position_new();
647 ltt_event_position(ltt_tracefile_get_event(tfc
->tf
), ep
);
649 ltt_tracefile_seek_position(tfc
->tf
, ep
);
659 void lttv_process_traceset_begin(LttvTracesetContext
*self
,
660 LttvHooks
*before_traceset
,
661 LttvHooks
*before_trace
,
662 LttvHooks
*before_tracefile
,
664 LttvHooksById
*event_by_id
)
667 /* simply add hooks in context. _before hooks are called by add_hooks. */
668 /* It calls all before_traceset, before_trace, and before_tracefile hooks. */
669 lttv_traceset_context_add_hooks(self
,
678 /* Note : a _middle must be preceded from a _seek or another middle */
679 guint
lttv_process_traceset_middle(LttvTracesetContext
*self
,
682 const LttvTracesetContextPosition
*end_position
)
684 GTree
*pqueue
= self
->pqueue
;
688 LttvTracefileContext
*tfc
;
694 gboolean last_ret
= FALSE
; /* return value of the last hook list called */
696 /* Get the next event from the pqueue, call its hooks,
697 reinsert in the pqueue the following event from the same tracefile
698 unless the tracefile is finished or the event is later than the
703 g_tree_foreach(pqueue
, get_first
, &tfc
);
704 /* End of traceset : tfc is NULL */
705 if(unlikely(tfc
== NULL
))
711 * - the maximum number of events specified?
712 * - the end position ?
714 * then the read is finished. We leave the queue in the same state and
718 if(unlikely(last_ret
== TRUE
||
719 count
>= nb_events
||
720 (end_position
!=NULL
&<tv_traceset_context_ctx_pos_compare(self
,
721 end_position
) == 0)||
722 ltt_time_compare(end
, tfc
->timestamp
) <= 0))
727 /* Get the tracefile with an event for the smallest time found. If two
728 or more tracefiles have events for the same time, hope that lookup
729 and remove are consistent. */
731 g_tree_remove(pqueue
, tfc
);
734 e
= ltt_tracefile_get_event(tfc
->tf
);
735 id
= ltt_event_eventtype_id(e
);
736 last_ret
= lttv_hooks_call_merge(tfc
->event
, tfc
,
737 lttv_hooks_by_id_get(tfc
->event_by_id
, id
), tfc
);
739 if(likely(!ltt_tracefile_read(tfc
->tf
))) {
740 tfc
->timestamp
= ltt_event_time(e
);
741 g_tree_insert(pqueue
, tfc
, tfc
);
747 void lttv_process_traceset_end(LttvTracesetContext
*self
,
748 LttvHooks
*after_traceset
,
749 LttvHooks
*after_trace
,
750 LttvHooks
*after_tracefile
,
752 LttvHooksById
*event_by_id
)
754 /* Remove hooks from context. _after hooks are called by remove_hooks. */
755 /* It calls all after_traceset, after_trace, and after_tracefile hooks. */
756 lttv_traceset_context_remove_hooks(self
,
764 void lttv_process_trace_seek_time(LttvTraceContext
*self
, LttTime start
)
766 guint i
, nb_tracefile
;
770 LttvTracefileContext
*tfc
;
772 GTree
*pqueue
= self
->ts_context
->pqueue
;
774 nb_tracefile
= self
->tracefiles
->len
;
776 for(i
= 0 ; i
< nb_tracefile
; i
++) {
777 tfc
= &g_array_index(self
->tracefiles
, LttvTracefileContext
, i
);
778 ret
= ltt_tracefile_seek_time(tfc
->tf
, start
);
779 if(ret
) g_error("error in lttv_process_trace_seek_time seek");
780 g_tree_remove(pqueue
, tfc
);
781 tfc
->timestamp
= ltt_event_time(ltt_tracefile_get_event(tfc
->tf
));
782 g_tree_insert(pqueue
, tfc
, tfc
);
787 void lttv_process_traceset_seek_time(LttvTracesetContext
*self
, LttTime start
)
791 LttvTraceContext
*tc
;
793 nb_trace
= lttv_traceset_number(self
->ts
);
794 for(i
= 0 ; i
< nb_trace
; i
++) {
795 tc
= self
->traces
[i
];
796 lttv_process_trace_seek_time(tc
, start
);
801 gboolean
lttv_process_tracefile_seek_position(LttvTracefileContext
*self
,
802 const LttEventPosition
*pos
)
804 LttvTracefileContext
*tfc
= self
;
806 GTree
*pqueue
= self
->t_context
->ts_context
->pqueue
;
808 ltt_tracefile_seek_position(tfc
->tf
, pos
);
809 g_tree_remove(pqueue
, tfc
);
810 tfc
->timestamp
= ltt_event_time(ltt_tracefile_get_event(tfc
->tf
));
811 g_tree_insert(pqueue
, tfc
, tfc
);
816 gboolean
lttv_process_trace_seek_position(LttvTraceContext
*self
,
817 const LttvTraceContextPosition
*pos
)
819 guint i
, nb_tracefile
;
821 LttvTracefileContext
*tfc
;
823 nb_tracefile
= self
->tracefiles
->len
;
825 if(nb_tracefile
!= pos
->nb_tracefile
)
826 return FALSE
; /* Error */
828 for(i
= 0 ; i
< nb_tracefile
; i
++) {
829 tfc
= &g_array_index(self
->tracefiles
, LttvTracefileContext
, i
);
830 lttv_process_tracefile_seek_position(tfc
, pos
->tf_pos
[i
]);
838 gboolean
lttv_process_traceset_seek_position(LttvTracesetContext
*self
,
839 const LttvTracesetContextPosition
*pos
)
842 gboolean sum_ret
= TRUE
;
844 LttvTraceContext
*tc
;
846 nb_trace
= lttv_traceset_number(self
->ts
);
848 if(nb_trace
!= pos
->nb_trace
)
849 return FALSE
; /* Error */
851 for(i
= 0 ; i
< nb_trace
; i
++) {
852 tc
= self
->traces
[i
];
853 sum_ret
= sum_ret
&& lttv_process_trace_seek_position(tc
, &pos
->t_pos
[i
]);
862 find_field(LttEventType
*et
, const GQuark field
)
873 if(field
== 0) return NULL
;
875 f
= ltt_eventtype_field(et
);
876 t
= ltt_eventtype_type(et
);
877 g_assert(ltt_type_class(t
) == LTT_STRUCT
);
878 nb
= ltt_type_member_number(t
);
879 for(i
= 0 ; i
< nb
; i
++) {
880 ltt_type_member_type(t
, i
, &name
);
881 if(name
== field
) break;
884 return ltt_field_member(f
, i
);
887 LttvTraceHookByFacility
*lttv_trace_hook_get_fac(LttvTraceHook
*th
,
890 return &g_array_index(th
->fac_index
, LttvTraceHookByFacility
, facility_id
);
893 /* Get the first facility corresponding to the name. As the types must be
894 * compatible, it is relevant to use the field name and sizes of the first
895 * facility to create data structures and assume the data will be compatible
896 * thorough the trace */
897 LttvTraceHookByFacility
*lttv_trace_hook_get_first(LttvTraceHook
*th
)
899 g_assert(th
->fac_list
->len
> 0);
900 return g_array_index(th
->fac_list
, LttvTraceHookByFacility
*, 0);
904 /* Returns 0 on success, -1 if fails. */
906 lttv_trace_find_hook(LttTrace
*t
, GQuark facility
, GQuark event
,
907 GQuark field1
, GQuark field2
, GQuark field3
, LttvHook h
, LttvTraceHook
*th
)
911 LttEventType
*et
, *first_et
;
917 LttvTraceHookByFacility
*thf
, *first_thf
;
919 facilities
= ltt_trace_facility_get_by_name(t
, facility
);
921 if(unlikely(facilities
== NULL
)) goto facility_error
;
923 th
->fac_index
= g_array_sized_new(FALSE
, TRUE
,
924 sizeof(LttvTraceHookByFacility
),
926 th
->fac_index
= g_array_set_size(th
->fac_index
, NUM_FACILITIES
);
928 th
->fac_list
= g_array_sized_new(FALSE
, TRUE
,
929 sizeof(LttvTraceHookByFacility
*),
931 th
->fac_list
= g_array_set_size(th
->fac_list
, facilities
->len
);
933 fac_id
= g_array_index(facilities
, guint
, 0);
934 f
= ltt_trace_get_facility_by_num(t
, fac_id
);
936 et
= ltt_facility_eventtype_get_by_name(f
, ltt_eventtype_name(et
));
937 if(unlikely(et
== NULL
)) goto event_error
;
939 thf
= &g_array_index(th
->fac_index
, LttvTraceHookByFacility
, fac_id
);
940 g_array_index(th
->fac_list
, LttvTraceHookByFacility
*, 0)
943 thf
->id
= ltt_eventtype_id(et
);
944 thf
->f1
= find_field(et
, field1
);
945 thf
->f2
= find_field(et
, field2
);
946 thf
->f3
= find_field(et
, field3
);
950 /* Check for type compatibility too */
951 for(i
=1;i
<facilities
->len
;i
++) {
952 fac_id
= g_array_index(facilities
, guint
, i
);
953 f
= ltt_trace_get_facility_by_num(t
, fac_id
);
955 et
= ltt_facility_eventtype_get_by_name(f
, ltt_eventtype_name(et
));
956 if(unlikely(et
== NULL
)) goto event_error
;
958 thf
= &g_array_index(th
->fac_index
, LttvTraceHookByFacility
, fac_id
);
959 g_array_index(th
->fac_list
, LttvTraceHookByFacility
*, i
)
962 thf
->id
= ltt_eventtype_id(et
);
963 thf
->f1
= find_field(et
, field1
);
964 if(check_fields_compatibility(first_et
, et
,
965 first_thf
->f1
, thf
->f1
))
968 thf
->f2
= find_field(et
, field2
);
969 if(check_fields_compatibility(first_et
, et
,
970 first_thf
->f2
, thf
->f2
))
973 thf
->f3
= find_field(et
, field3
);
974 if(check_fields_compatibility(first_et
, et
,
975 first_thf
->f3
, thf
->f3
))
984 g_error("Event type %s does not exist",
985 g_quark_to_string(ltt_eventtype_name(et
)));
988 g_error("No %s facility", g_quark_to_string(facility
));
991 g_array_free(th
->fac_index
, TRUE
);
992 g_array_free(th
->fac_list
, TRUE
);
993 th
->fac_index
= NULL
;
998 void lttv_trace_hook_destroy(LttvTraceHook
*th
)
1000 g_array_free(th
->fac_index
, TRUE
);
1001 g_array_free(th
->fac_list
, TRUE
);
1005 LttvTracesetContextPosition
*lttv_traceset_context_position_new()
1007 return g_new(LttvTracesetContextPosition
,1);
1011 void lttv_traceset_context_position_save(const LttvTracesetContext
*self
,
1012 LttvTracesetContextPosition
*pos
)
1014 guint nb_trace
, nb_tracefile
;
1015 guint iter_trace
, iter_tracefile
;
1017 LttvTraceContext
*tc
;
1019 LttvTracefileContext
*tfc
;
1023 LttTime timestamp
= self
->time_span
.end_time
;
1025 pos
->nb_trace
= nb_trace
= lttv_traceset_number(self
->ts
);
1026 pos
->t_pos
= g_new(LttvTraceContextPosition
, nb_trace
);
1028 for(iter_trace
= 0 ; iter_trace
< nb_trace
; iter_trace
++) {
1029 tc
= self
->traces
[iter_trace
];
1031 nb_tracefile
= tc
->tracefiles
->len
;
1032 pos
->t_pos
[iter_trace
].nb_tracefile
= nb_tracefile
;
1034 pos
->t_pos
[iter_trace
].tf_pos
= g_new(LttEventPosition
*, nb_tracefile
);
1035 for(iter_tracefile
= 0; iter_tracefile
< nb_tracefile
; iter_tracefile
++) {
1036 tfc
= &g_array_index(tc
->tracefiles
, LttvTracefileContext
,
1038 event
= ltt_tracefile_get_event(tfc
->tf
);
1040 pos
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
]
1041 = ltt_event_position_new();
1042 ltt_event_position(event
,
1043 pos
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
]);
1045 pos
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
] = NULL
;
1047 if(ltt_time_compare(tfc
->timestamp
, timestamp
) < 0)
1048 timestamp
= tfc
->timestamp
;
1051 pos
->timestamp
= timestamp
;
1054 void lttv_traceset_context_position_destroy(LttvTracesetContextPosition
*pos
)
1057 guint iter_trace
, iter_tracefile
;
1059 nb_trace
= pos
->nb_trace
;
1061 for(iter_trace
= 0 ; iter_trace
< nb_trace
; iter_trace
++) {
1062 for(iter_tracefile
= 0; iter_tracefile
<
1063 pos
->t_pos
[iter_trace
].nb_tracefile
;
1065 if(pos
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
] != NULL
)
1066 g_free(pos
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
]);
1068 g_free(pos
->t_pos
[iter_trace
].tf_pos
);
1074 void lttv_traceset_context_position_copy(LttvTracesetContextPosition
*dest
,
1075 const LttvTracesetContextPosition
*src
)
1077 guint nb_trace
, nb_tracefile
;
1078 guint iter_trace
, iter_tracefile
;
1080 nb_trace
= dest
->nb_trace
= src
->nb_trace
;
1081 dest
->t_pos
= g_new(LttvTraceContextPosition
, nb_trace
);
1083 for(iter_trace
= 0 ; iter_trace
< nb_trace
; iter_trace
++) {
1085 nb_tracefile
= src
->t_pos
[iter_trace
].nb_tracefile
;
1087 dest
->t_pos
[iter_trace
].nb_tracefile
= nb_tracefile
;
1089 dest
->t_pos
[iter_trace
].tf_pos
= g_new(LttEventPosition
*, nb_tracefile
);
1091 for(iter_tracefile
= 0; iter_tracefile
< nb_tracefile
; iter_tracefile
++) {
1092 dest
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
] =
1093 ltt_event_position_new();
1094 if(src
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
] != NULL
)
1095 ltt_event_position_copy(
1096 dest
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
],
1097 src
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
]);
1099 dest
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
] = NULL
;
1103 dest
->timestamp
= src
->timestamp
;
1106 gint
lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext
*self
,
1107 const LttvTracesetContextPosition
*pos
)
1109 guint nb_trace
, nb_tracefile
;
1110 guint iter_trace
, iter_tracefile
;
1113 LttvTraceContext
*tc
;
1115 LttvTracefileContext
*tfc
;
1119 nb_trace
= lttv_traceset_number(self
->ts
);
1121 if(unlikely(pos
->nb_trace
!= nb_trace
))
1122 g_error("lttv_traceset_context_ctx_pos_compare : nb_trace does not match.");
1124 for(iter_trace
= 0 ; iter_trace
< nb_trace
; iter_trace
++) {
1125 tc
= self
->traces
[iter_trace
];
1126 nb_tracefile
= tc
->tracefiles
->len
;
1128 if(unlikely(pos
->t_pos
[iter_trace
].nb_tracefile
!= nb_tracefile
))
1129 g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match.");
1131 for(iter_tracefile
= 0; iter_tracefile
< nb_tracefile
; iter_tracefile
++) {
1132 tfc
= &g_array_index(tc
->tracefiles
, LttvTracefileContext
,
1134 event
= ltt_tracefile_get_event(tfc
->tf
);
1135 ret
= ltt_event_position_compare((LttEventPosition
*)event
,
1136 pos
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
]);
1145 gint
lttv_traceset_context_pos_pos_compare(
1146 const LttvTracesetContextPosition
*pos1
,
1147 const LttvTracesetContextPosition
*pos2
)
1149 guint nb_trace
, nb_tracefile
;
1150 guint iter_trace
, iter_tracefile
;
1154 nb_trace
= pos1
->nb_trace
;
1155 if(unlikely(nb_trace
!= pos2
->nb_trace
))
1156 g_error("lttv_traceset_context_pos_pos_compare : nb_trace does not match.");
1158 for(iter_trace
= 0 ; iter_trace
< nb_trace
; iter_trace
++) {
1160 nb_tracefile
= pos1
->t_pos
[iter_trace
].nb_tracefile
;
1161 if(unlikely(nb_tracefile
!= pos2
->t_pos
[iter_trace
].nb_tracefile
))
1162 g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match.");
1164 for(iter_tracefile
= 0; iter_tracefile
< nb_tracefile
; iter_tracefile
++) {
1165 ret
= ltt_event_position_compare(
1166 pos1
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
],
1167 pos2
->t_pos
[iter_trace
].tf_pos
[iter_tracefile
]);
1176 LttTime
lttv_traceset_context_position_get_time(
1177 const LttvTracesetContextPosition
*pos
)
1179 return pos
->timestamp
;
1183 LttvTracefileContext
*lttv_traceset_context_get_current_tfc(LttvTracesetContext
*self
)
1185 GTree
*pqueue
= self
->pqueue
;
1186 LttvTracefileContext
*tfc
= NULL
;
1188 g_tree_foreach(pqueue
, get_first
, &tfc
);