* the time passed in parameter.
*
* If the time parameter is outside the tracefile time span, seek to the first
- * or the last event of the tracefile.
+ * event or if after, return ERANGE.
*
* If the time parameter is before the first event, we have to seek specially to
* there.
*
- * If the time is after the end of the trace, get the last event.
+ * If the time is after the end of the trace, return ERANGE.
*
* Do a binary search to find the right block, then a sequential search in the
* block to find the event.
* you will jump over an event if you do.
*
* Return value : 0 : no error, the tf->event can be used
+ * ERANGE : time if after the last event of the trace
* otherwise : this is an error.
*
* */
* go to the first event. */
if(ltt_time_compare(time, tf->buffer.begin.timestamp) <= 0) {
ret = ltt_tracefile_read(tf);
+ if(ret == ERANGE) goto range;
+ else if (ret) goto fail;
goto found; /* There is either no event in the trace or the event points
to the first event in the trace */
}
goto fail;
}
- /* If the time is after the end of the trace, get the last event. */
- if(ltt_time_compare(time, tf->buffer.end.timestamp) >= 0) {
- /* While the ltt_tracefile_read doesn't return ERANGE or EPERM,
- * continue reading.
- */
- while(1) {
- ret = ltt_tracefile_read(tf);
- if(ret == ERANGE) goto found; /* ERANGE or EPERM */
- else if(ret) goto fail;
- }
+ /* If the time is after the end of the trace, return ERANGE. */
+ if(ltt_time_compare(time, tf->buffer.end.timestamp) > 0) {
+ goto range;
}
/* Binary search the block */
* (or in the next buffer first event) */
while(1) {
ret = ltt_tracefile_read(tf);
- if(ret == ERANGE) goto found; /* ERANGE or EPERM */
+ if(ret == ERANGE) goto range; /* ERANGE or EPERM */
else if(ret) goto fail;
if(ltt_time_compare(time, tf->event.event_time) >= 0)
break;
}
- } if(ltt_time_compare(time, tf->buffer.begin.timestamp) < 0) {
+ } else if(ltt_time_compare(time, tf->buffer.begin.timestamp) < 0) {
/* go to lower part */
high = block_num;
} else if(ltt_time_compare(time, tf->buffer.end.timestamp) > 0) {
} else {/* The event is right in the buffer!
(or in the next buffer first event) */
while(1) {
- ltt_tracefile_read(tf);
- if(ret == ERANGE) goto found; /* ERANGE or EPERM */
+ ret = ltt_tracefile_read(tf);
+ if(ret == ERANGE) goto range; /* ERANGE or EPERM */
else if(ret) goto fail;
if(ltt_time_compare(time, tf->event.event_time) >= 0)
found:
return 0;
+range:
+ return ERANGE;
/* Error handling */
fail:
g_quark_to_string(tf->name));
goto event_type_error;
}
+
+ if(event_type->root_field)
+ size = get_field_type_size(tf, event_type,
+ 0, 0, event_type->root_field, tf->event.data);
+ else
+ size = 0;
- size = get_field_type_size(tf, event_type,
- 0, 0, event_type->root_field, tf->event.data);
g_debug("Event root field : f.e %hhu.%hhu size %lu", tf->event.facility_id,
tf->event.event_id, size);
}
field->child[0]);
field->fixed_size = FIELD_VARIABLE;
field->field_size = 0;
+ *fixed_root = FIELD_VARIABLE;
+ *fixed_parent = FIELD_VARIABLE;
break;
case LTT_STRING:
field->fixed_size = FIELD_VARIABLE;
field->field_size = 0;
+ *fixed_root = FIELD_VARIABLE;
+ *fixed_parent = FIELD_VARIABLE;
break;
case LTT_ARRAY:
local_fixed_root = FIELD_VARIABLE;
&local_fixed_root, &local_fixed_parent,
field->child[0]);
field->fixed_size = field->child[0]->fixed_size;
- if(field->fixed_size == FIELD_FIXED)
+ if(field->fixed_size == FIELD_FIXED) {
field->field_size = type->element_number * field->child[0]->field_size;
- else
+ } else {
field->field_size = 0;
+ *fixed_root = FIELD_VARIABLE;
+ *fixed_parent = FIELD_VARIABLE;
+ }
break;
case LTT_STRUCT:
current_root_offset = field->offset_root;
#include <ltt/facility.h>
#include <ltt/trace.h>
#include <ltt/type.h>
+#include <errno.h>
-static gint compare_tracefile(gconstpointer a, gconstpointer b)
+gint compare_tracefile(gconstpointer a, gconstpointer b)
{
gint comparison = 0;
return comparison;
}
-struct _LttvTraceContextPosition {
- LttEventPosition **tf_pos; /* Position in each tracefile */
- guint nb_tracefile; /* Number of tracefiles (check) */
-};
-
struct _LttvTracesetContextPosition {
- LttvTraceContextPosition *t_pos; /* Position in each trace */
- guint nb_trace; /* Number of traces (check) */
+ GArray *ep; /* Array of LttEventPosition */
+ GArray *tfc; /* Array of corresponding
+ TracefileContext* */
LttTime timestamp; /* Current time at the saved position */
};
}
-/* Put all the tracefiles at the tracefile context position */
-void lttv_process_traceset_synchronize_tracefiles(LttvTracesetContext *self)
-{
- guint iter_trace, nb_trace;
-
- LttvTraceContext *tc;
-
- nb_trace = lttv_traceset_number(self->ts);
-
- for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
- tc = self->traces[iter_trace];
- {
- /* each trace */
- guint iter_tf, nb_tracefile;
-
- LttvTracefileContext *tfc;
-
- nb_tracefile = tc->tracefiles->len;
-
- for(iter_tf = 0 ; iter_tf < nb_tracefile ; iter_tf++) {
- tfc = g_array_index(tc->tracefiles, LttvTracefileContext*, iter_tf);
- {
- /* each tracefile */
- //ltt_tracefile_copy(tfc->tf_sync_data, tfc->tf);
- LttEventPosition *ep = ltt_event_position_new();
-
- ltt_event_position(ltt_tracefile_get_event(tfc->tf), ep);
-
- ltt_tracefile_seek_position(tfc->tf, ep);
- g_free(ep);
- }
- }
- }
- }
-}
-
-
-
void lttv_process_traceset_begin(LttvTracesetContext *self,
LttvHooks *before_traceset,
LttvHooks *before_trace,
event_by_id);
}
+/* Subtile modification :
+ * if tracefile has no event at or after the time requested, it is not put in
+ * the queue, as the next read would fail. */
void lttv_process_trace_seek_time(LttvTraceContext *self, LttTime start)
{
guint i, nb_tracefile;
for(i = 0 ; i < nb_tracefile ; i++) {
tfc = g_array_index(self->tracefiles, LttvTracefileContext*, i);
ret = ltt_tracefile_seek_time(tfc->tf, start);
- if(ret) g_error("error in lttv_process_trace_seek_time seek");
+ if(ret == EPERM) g_error("error in lttv_process_trace_seek_time seek");
g_tree_remove(pqueue, tfc);
- tfc->timestamp = ltt_event_time(ltt_tracefile_get_event(tfc->tf));
- g_tree_insert(pqueue, tfc, tfc);
+
+ if(ret == 0) { /* not ERANGE especially */
+ tfc->timestamp = ltt_event_time(ltt_tracefile_get_event(tfc->tf));
+ g_tree_insert(pqueue, tfc, tfc);
+ }
}
}
}
-gboolean lttv_process_tracefile_seek_position(LttvTracefileContext *self,
- const LttEventPosition *pos)
-{
- LttvTracefileContext *tfc = self;
-
- GTree *pqueue = self->t_context->ts_context->pqueue;
-
- ltt_tracefile_seek_position(tfc->tf, pos);
- g_tree_remove(pqueue, tfc);
- tfc->timestamp = ltt_event_time(ltt_tracefile_get_event(tfc->tf));
- g_tree_insert(pqueue, tfc, tfc);
-
- return TRUE;
-}
-
-gboolean lttv_process_trace_seek_position(LttvTraceContext *self,
- const LttvTraceContextPosition *pos)
-{
- guint i, nb_tracefile;
-
- LttvTracefileContext *tfc;
-
- nb_tracefile = self->tracefiles->len;
-
- if(nb_tracefile != pos->nb_tracefile)
- return FALSE; /* Error */
-
- for(i = 0 ; i < nb_tracefile ; i++) {
- tfc = g_array_index(self->tracefiles, LttvTracefileContext*, i);
- lttv_process_tracefile_seek_position(tfc, pos->tf_pos[i]);
- }
-
- return TRUE;
-}
-
-
-
gboolean lttv_process_traceset_seek_position(LttvTracesetContext *self,
const LttvTracesetContextPosition *pos)
{
- guint i, nb_trace;
- gboolean sum_ret = TRUE;
-
+ guint i;
LttvTraceContext *tc;
+ LttvTracefileContext *tfc;
- nb_trace = lttv_traceset_number(self->ts);
+ g_tree_destroy(self->pqueue);
+ self->pqueue = g_tree_new(compare_tracefile);
- if(nb_trace != pos->nb_trace)
- return FALSE; /* Error */
-
- for(i = 0 ; i < nb_trace ; i++) {
- tc = self->traces[i];
- sum_ret = sum_ret && lttv_process_trace_seek_position(tc, &pos->t_pos[i]);
+ for(i=0;i<pos->ep->len; i++) {
+ LttEventPosition *ep = g_array_index(pos->ep, LttEventPosition*, i);
+ LttvTracefileContext *tfc =
+ g_array_index(pos->tfc, LttvTracefileContext*, i);
+ g_assert(ltt_tracefile_seek_position(tfc->tf, ep) == 0);
+ tfc->timestamp = ltt_event_time(ltt_tracefile_get_event(tfc->tf));
+ g_tree_insert(self->pqueue, tfc, tfc);
}
-
- return sum_ret;
+ return TRUE;
}
LttvTracesetContextPosition *lttv_traceset_context_position_new()
{
- return g_new(LttvTracesetContextPosition,1);
+ LttvTracesetContextPosition *pos = g_new(LttvTracesetContextPosition,1);
+ pos->ep = g_array_sized_new(FALSE, TRUE, sizeof(LttEventPosition*),
+ 10);
+ pos->tfc = g_array_sized_new(FALSE, TRUE, sizeof(LttvTracefileContext*),
+ 10);
+ pos->timestamp = ltt_time_infinite;
+ return pos;
}
-
-void lttv_traceset_context_position_save(const LttvTracesetContext *self,
- LttvTracesetContextPosition *pos)
+gboolean traverse_get_tfc(gpointer key, gpointer value, gpointer data)
{
- guint nb_trace, nb_tracefile;
- guint iter_trace, iter_tracefile;
-
- LttvTraceContext *tc;
-
- LttvTracefileContext *tfc;
+ LttvTracefileContext *tfc = (LttvTracefileContext *)value;
+ LttvTracesetContextPosition *pos = (LttvTracesetContextPosition *)data;
- LttEvent *event;
+ LttEvent *event = ltt_tracefile_get_event(tfc->tf);
+ LttEventPosition *ep = ltt_event_position_new();
+
+ ltt_event_position(event, ep);
- LttTime timestamp = self->time_span.end_time;
+ g_array_append_val(pos->ep, ep);
+ g_array_append_val(pos->tfc, tfc);
- pos->nb_trace = nb_trace = lttv_traceset_number(self->ts);
- pos->t_pos = g_new(LttvTraceContextPosition, nb_trace);
+ if(ltt_time_compare(tfc->timestamp, pos->timestamp) < 0)
+ pos->timestamp = tfc->timestamp;
- for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
- tc = self->traces[iter_trace];
+ return 0;
+}
- nb_tracefile = tc->tracefiles->len;
- pos->t_pos[iter_trace].nb_tracefile = nb_tracefile;
-
- pos->t_pos[iter_trace].tf_pos = g_new(LttEventPosition*, nb_tracefile);
- for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) {
- tfc = g_array_index(tc->tracefiles, LttvTracefileContext*,
- iter_tracefile);
- event = ltt_tracefile_get_event(tfc->tf);
- if(event!=NULL) {
- pos->t_pos[iter_trace].tf_pos[iter_tracefile]
- = ltt_event_position_new();
- ltt_event_position(event,
- pos->t_pos[iter_trace].tf_pos[iter_tracefile]);
- } else {
- pos->t_pos[iter_trace].tf_pos[iter_tracefile] = NULL;
- }
- if(ltt_time_compare(tfc->timestamp, timestamp) < 0)
- timestamp = tfc->timestamp;
- }
- }
- pos->timestamp = timestamp;
+/* Subtile modification :
+ * only save the tracefiles that are loaded in the pqueue */
+void lttv_traceset_context_position_save(const LttvTracesetContext *self,
+ LttvTracesetContextPosition *pos)
+{
+ g_tree_foreach(self->pqueue, traverse_get_tfc, pos);
}
void lttv_traceset_context_position_destroy(LttvTracesetContextPosition *pos)
{
- guint nb_trace;
- guint iter_trace, iter_tracefile;
-
- nb_trace = pos->nb_trace;
-
- for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
- for(iter_tracefile = 0; iter_tracefile <
- pos->t_pos[iter_trace].nb_tracefile;
- iter_tracefile++) {
- if(pos->t_pos[iter_trace].tf_pos[iter_tracefile] != NULL)
- g_free(pos->t_pos[iter_trace].tf_pos[iter_tracefile]);
- }
- g_free(pos->t_pos[iter_trace].tf_pos);
- }
- g_free(pos->t_pos);
-
+ int i;
+ for(i=0;i<pos->ep->len;i++)
+ g_free(g_array_index(pos->ep, LttEventPosition*, i));
+ g_array_free(pos->ep, TRUE);
+ g_array_free(pos->tfc, TRUE);
+ g_free(pos);
}
void lttv_traceset_context_position_copy(LttvTracesetContextPosition *dest,
const LttvTracesetContextPosition *src)
{
- guint nb_trace, nb_tracefile;
- guint iter_trace, iter_tracefile;
+ int i;
- nb_trace = dest->nb_trace = src->nb_trace;
- dest->t_pos = g_new(LttvTraceContextPosition, nb_trace);
-
- for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
-
- nb_tracefile = src->t_pos[iter_trace].nb_tracefile;
-
- dest->t_pos[iter_trace].nb_tracefile = nb_tracefile;
-
- dest->t_pos[iter_trace].tf_pos = g_new(LttEventPosition*, nb_tracefile);
-
- for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) {
- dest->t_pos[iter_trace].tf_pos[iter_tracefile] =
- ltt_event_position_new();
- if(src->t_pos[iter_trace].tf_pos[iter_tracefile] != NULL)
- ltt_event_position_copy(
- dest->t_pos[iter_trace].tf_pos[iter_tracefile],
- src->t_pos[iter_trace].tf_pos[iter_tracefile]);
- else
- dest->t_pos[iter_trace].tf_pos[iter_tracefile] = NULL;
- }
+ g_array_set_size(dest->ep, src->ep->len);
+ g_array_set_size(dest->tfc, src->tfc->len);
+
+ for(i=0;i<src->ep->len;i++) {
+ g_array_index(dest->ep, LttEventPosition*, i) = ltt_event_position_new();
+ ltt_event_position_copy(
+ g_array_index(dest->ep, LttEventPosition*, i),
+ g_array_index(src->ep, LttEventPosition*, i));
+ }
+ for(i=0;i<src->tfc->len;i++) {
+ g_array_index(dest->tfc, LttvTracefileContext*, i) =
+ g_array_index(src->tfc, LttvTracefileContext*, i);
}
-
dest->timestamp = src->timestamp;
}
gint lttv_traceset_context_ctx_pos_compare(const LttvTracesetContext *self,
const LttvTracesetContextPosition *pos)
{
- guint nb_trace, nb_tracefile;
- guint iter_trace, iter_tracefile;
- gint ret;
-
- LttvTraceContext *tc;
-
- LttvTracefileContext *tfc;
+ int i;
+ int ret;
- LttEvent *event;
+ for(i=0;i<pos->ep->len;i++) {
+ LttEventPosition *ep = g_array_index(pos->ep, LttEventPosition*, i);
+ LttvTracefileContext *tfc =
+ g_array_index(pos->tfc, LttvTracefileContext*, i);
- nb_trace = lttv_traceset_number(self->ts);
+ LttEvent *event = ltt_tracefile_get_event(tfc->tf);
- if(unlikely(pos->nb_trace != nb_trace))
- g_error("lttv_traceset_context_ctx_pos_compare : nb_trace does not match.");
-
- for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
- tc = self->traces[iter_trace];
- nb_tracefile = tc->tracefiles->len;
+ ret = ltt_event_position_compare((LttEventPosition*)event,
+ ep);
+ if(ret != 0) return ret;
- if(unlikely(pos->t_pos[iter_trace].nb_tracefile != nb_tracefile))
- g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match.");
-
- for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) {
- tfc = g_array_index(tc->tracefiles, LttvTracefileContext*,
- iter_tracefile);
- event = ltt_tracefile_get_event(tfc->tf);
- ret = ltt_event_position_compare((LttEventPosition*)event,
- pos->t_pos[iter_trace].tf_pos[iter_tracefile]);
- if(ret != 0)
- return ret;
- }
}
return 0;
}
const LttvTracesetContextPosition *pos1,
const LttvTracesetContextPosition *pos2)
{
- guint nb_trace, nb_tracefile;
- guint iter_trace, iter_tracefile;
+ int i, j;
+ int ret;
- gint ret;
-
- nb_trace = pos1->nb_trace;
- if(unlikely(nb_trace != pos2->nb_trace))
- g_error("lttv_traceset_context_pos_pos_compare : nb_trace does not match.");
-
- for(iter_trace = 0 ; iter_trace < nb_trace ; iter_trace++) {
-
- nb_tracefile = pos1->t_pos[iter_trace].nb_tracefile;
- if(unlikely(nb_tracefile != pos2->t_pos[iter_trace].nb_tracefile))
- g_error("lttv_traceset_context_ctx_pos_compare : nb_tracefile does not match.");
+ for(i=0;i<pos1->ep->len;i++) {
+ LttEventPosition *ep1 = g_array_index(pos1->ep, LttEventPosition*, i);
+ LttTracefile *tf1 = ltt_event_position_tracefile(ep1);
+
+ for(j=0;j<pos2->ep->len;j++) {
+ LttEventPosition *ep2 = g_array_index(pos2->ep, LttEventPosition*, j);
+ LttTracefile *tf2 = ltt_event_position_tracefile(ep2);
- for(iter_tracefile = 0; iter_tracefile < nb_tracefile; iter_tracefile++) {
- ret = ltt_event_position_compare(
- pos1->t_pos[iter_trace].tf_pos[iter_tracefile],
- pos2->t_pos[iter_trace].tf_pos[iter_tracefile]);
- if(ret != 0)
- return ret;
+ if(tf1 == tf2) {
+ ret = ltt_event_position_compare(ep1, ep2);
+ if(ret != 0) return ret;
+ }
}
}
return 0;
+
}