+ iter = g_slist_next(iter);
+ if(free_data) events_request_free((EventsRequest*)remove_iter->data);
+ list_out = g_slist_remove_link(list_out, remove_iter);
+ } else { // not remove
+ iter = g_slist_next(iter);
+ }
+ }
+ }
+
+ /* 0.1 Lock Traces */
+ {
+ guint iter_trace=0;
+
+ for(iter_trace=0;
+ iter_trace<lttv_traceset_number(tsc->ts);
+ iter_trace++) {
+ LttvTrace *trace_v = lttv_traceset_get(tsc->ts, iter_trace);
+
+ if(lttvwindowtraces_lock(trace_v) != 0) {
+ g_critical("Foreground processing : Unable to get trace lock");
+ return TRUE; /* Cannot get lock, try later */
+ }
+ }
+ }
+
+ /* 0.2 Seek tracefiles positions to context position */
+ //g_assert(lttv_process_traceset_seek_position(tsc, sync_position) == 0);
+ lttv_process_traceset_synchronize_tracefiles(tsc);
+
+
+ /* Events processing algorithm implementation */
+ /* Warning : the gtk_events_pending takes a LOT of cpu time. So what we do
+ * instead is to leave the control to GTK and take it back.
+ */
+ /* A. Servicing loop */
+ //while( (g_slist_length(list_in) != 0 || g_slist_length(list_out) != 0)) {
+ if((g_slist_length(list_in) != 0 || g_slist_length(list_out) != 0)) {
+ /* Servicing */
+ /* 1. If list_in is empty (need a seek) */
+ if( g_slist_length(list_in) == 0 ) {
+
+ /* list in is empty, need a seek */
+ {
+ /* 1.1 Add requests to list_in */
+ GSList *ltime = NULL;
+ GSList *lpos = NULL;
+ GSList *iter = NULL;
+
+ /* 1.1.1 Find all time requests with the lowest start time in list_out
+ * (ltime)
+ */
+ if(g_slist_length(list_out) > 0)
+ ltime = g_slist_append(ltime, g_slist_nth_data(list_out, 0));
+ for(iter=g_slist_nth(list_out,1);iter!=NULL;iter=g_slist_next(iter)) {
+ /* Find all time requests with the lowest start time in list_out */
+ EventsRequest *event_request_ltime = (EventsRequest*)g_slist_nth_data(ltime, 0);
+ EventsRequest *event_request_list_out = (EventsRequest*)iter->data;
+
+ int comp;
+ comp = ltt_time_compare(event_request_ltime->start_time,
+ event_request_list_out->start_time);
+ if(comp == 0)
+ ltime = g_slist_append(ltime, event_request_list_out);
+ else if(comp > 0) {
+ /* Remove all elements from ltime, and add current */
+ while(ltime != NULL)
+ ltime = g_slist_delete_link(ltime, g_slist_nth(ltime, 0));
+ ltime = g_slist_append(ltime, event_request_list_out);
+ }
+ }
+
+ /* 1.1.2 Find all position requests with the lowest position in list_out
+ * (lpos)
+ */
+ if(g_slist_length(list_out) > 0)
+ lpos = g_slist_append(lpos, g_slist_nth_data(list_out, 0));
+ for(iter=g_slist_nth(list_out,1);iter!=NULL;iter=g_slist_next(iter)) {
+ /* Find all position requests with the lowest position in list_out */
+ EventsRequest *event_request_lpos = (EventsRequest*)g_slist_nth_data(lpos, 0);
+ EventsRequest *event_request_list_out = (EventsRequest*)iter->data;
+
+ int comp;
+ if(event_request_lpos->start_position != NULL
+ && event_request_list_out->start_position != NULL)
+ {
+ comp = lttv_traceset_context_pos_pos_compare
+ (event_request_lpos->start_position,
+ event_request_list_out->start_position);
+ } else {
+ comp = -1;
+ }
+ if(comp == 0)
+ lpos = g_slist_append(lpos, event_request_list_out);
+ else if(comp > 0) {
+ /* Remove all elements from lpos, and add current */
+ while(lpos != NULL)
+ lpos = g_slist_delete_link(lpos, g_slist_nth(lpos, 0));
+ lpos = g_slist_append(lpos, event_request_list_out);
+ }
+ }
+
+ {
+ EventsRequest *event_request_lpos = (EventsRequest*)g_slist_nth_data(lpos, 0);
+ EventsRequest *event_request_ltime = (EventsRequest*)g_slist_nth_data(ltime, 0);
+ LttTime lpos_start_time;
+
+ if(event_request_lpos != NULL
+ && event_request_lpos->start_position != NULL) {
+ lpos_start_time = lttv_traceset_context_position_get_time(
+ event_request_lpos->start_position);
+ }
+
+ /* 1.1.3 If lpos.start time < ltime */
+ if(event_request_lpos != NULL
+ && event_request_lpos->start_position != NULL
+ && ltt_time_compare(lpos_start_time,
+ event_request_ltime->start_time)<0) {
+ /* Add lpos to list_in, remove them from list_out */
+ for(iter=lpos;iter!=NULL;iter=g_slist_next(iter)) {
+ /* Add to list_in */
+ EventsRequest *event_request_lpos =
+ (EventsRequest*)iter->data;
+
+ list_in = g_slist_append(list_in, event_request_lpos);
+ /* Remove from list_out */
+ list_out = g_slist_remove(list_out, event_request_lpos);
+ }
+ } else {
+ /* 1.1.4 (lpos.start time >= ltime) */
+ /* Add ltime to list_in, remove them from list_out */
+
+ for(iter=ltime;iter!=NULL;iter=g_slist_next(iter)) {
+ /* Add to list_in */
+ EventsRequest *event_request_ltime =
+ (EventsRequest*)iter->data;
+
+ list_in = g_slist_append(list_in, event_request_ltime);
+ /* Remove from list_out */
+ list_out = g_slist_remove(list_out, event_request_ltime);
+ }
+ }
+ }
+ g_slist_free(lpos);
+ g_slist_free(ltime);
+ }
+
+ /* 1.2 Seek */
+ {
+ tfc = lttv_traceset_context_get_current_tfc(tsc);
+ g_assert(g_slist_length(list_in)>0);
+ EventsRequest *events_request = g_slist_nth_data(list_in, 0);
+ guint seek_count;
+
+ /* 1.2.1 If first request in list_in is a time request */
+ if(events_request->start_position == NULL) {
+ /* - If first req in list_in start time != current time */
+ if(tfc == NULL || ltt_time_compare(events_request->start_time,
+ tfc->timestamp) != 0)
+ /* - Seek to that time */
+ g_debug("SEEK TIME : %lu, %lu", events_request->start_time.tv_sec,
+ events_request->start_time.tv_nsec);
+ //lttv_process_traceset_seek_time(tsc, events_request->start_time);
+ lttv_state_traceset_seek_time_closest(LTTV_TRACESET_STATE(tsc),
+ events_request->start_time);
+
+ /* Process the traceset with only state hooks */
+ seek_count =
+ lttv_process_traceset_middle(tsc,
+ events_request->start_time,
+ G_MAXUINT, NULL);
+#ifdef DEBUG
+ g_assert(seek_count < LTTV_STATE_SAVE_INTERVAL);
+#endif //DEBUG
+
+
+ } else {
+ LttTime pos_time;
+ LttvTracefileContext *tfc =
+ lttv_traceset_context_get_current_tfc(tsc);
+ /* Else, the first request in list_in is a position request */
+ /* If first req in list_in pos != current pos */
+ g_assert(events_request->start_position != NULL);
+ g_debug("SEEK POS time : %lu, %lu",
+ lttv_traceset_context_position_get_time(
+ events_request->start_position).tv_sec,
+ lttv_traceset_context_position_get_time(
+ events_request->start_position).tv_nsec);
+
+ if(tfc) {
+ g_debug("SEEK POS context time : %lu, %lu",
+ tfc->timestamp.tv_sec,
+ tfc->timestamp.tv_nsec);
+ } else {
+ g_debug("SEEK POS context time : %lu, %lu",
+ ltt_time_infinite.tv_sec,
+ ltt_time_infinite.tv_nsec);
+ }
+ g_assert(events_request->start_position != NULL);
+ if(lttv_traceset_context_ctx_pos_compare(tsc,
+ events_request->start_position) != 0) {
+ /* 1.2.2.1 Seek to that position */
+ g_debug("SEEK POSITION");
+ //lttv_process_traceset_seek_position(tsc, events_request->start_position);
+ pos_time = lttv_traceset_context_position_get_time(
+ events_request->start_position);
+
+ lttv_state_traceset_seek_time_closest(LTTV_TRACESET_STATE(tsc),
+ pos_time);
+
+ /* Process the traceset with only state hooks */
+ seek_count =
+ lttv_process_traceset_middle(tsc,
+ ltt_time_infinite,
+ G_MAXUINT,
+ events_request->start_position);
+ g_assert(lttv_traceset_context_ctx_pos_compare(tsc,
+ events_request->start_position) == 0);
+
+
+ }
+ }
+ }
+
+ /* 1.3 Add hooks and call before request for all list_in members */
+ {
+ GSList *iter = NULL;
+
+ for(iter=list_in;iter!=NULL;iter=g_slist_next(iter)) {
+ EventsRequest *events_request = (EventsRequest*)iter->data;
+ /* 1.3.1 If !servicing */
+ if(events_request->servicing == FALSE) {
+ /* - begin request hooks called
+ * - servicing = TRUE
+ */
+ lttv_hooks_call(events_request->before_request, (gpointer)tsc);
+ events_request->servicing = TRUE;
+ }
+ /* 1.3.2 call before chunk
+ * 1.3.3 events hooks added
+ */
+ if(events_request->trace == -1)
+ lttv_process_traceset_begin(tsc,
+ events_request->before_chunk_traceset,
+ events_request->before_chunk_trace,
+ events_request->before_chunk_tracefile,
+ events_request->event,
+ events_request->event_by_id);
+ else {
+ guint nb_trace = lttv_traceset_number(tsc->ts);
+ g_assert((guint)events_request->trace < nb_trace &&
+ events_request->trace > -1);
+ LttvTraceContext *tc = tsc->traces[events_request->trace];
+
+ lttv_hooks_call(events_request->before_chunk_traceset, tsc);
+
+ lttv_trace_context_add_hooks(tc,
+ events_request->before_chunk_trace,
+ events_request->before_chunk_tracefile,
+ events_request->event,
+ events_request->event_by_id);
+ }
+ }
+ }
+ } else {
+ /* 2. Else, list_in is not empty, we continue a read */
+
+ {
+ /* 2.0 For each req of list_in */
+ GSList *iter = list_in;
+
+ while(iter != NULL) {
+
+ EventsRequest *events_request = (EventsRequest *)iter->data;
+
+ /* - Call before chunk
+ * - events hooks added
+ */
+ if(events_request->trace == -1)
+ lttv_process_traceset_begin(tsc,
+ events_request->before_chunk_traceset,
+ events_request->before_chunk_trace,
+ events_request->before_chunk_tracefile,
+ events_request->event,
+ events_request->event_by_id);
+ else {
+ guint nb_trace = lttv_traceset_number(tsc->ts);
+ g_assert((guint)events_request->trace < nb_trace &&
+ events_request->trace > -1);
+ LttvTraceContext *tc = tsc->traces[events_request->trace];
+
+ lttv_hooks_call(events_request->before_chunk_traceset, tsc);
+
+ lttv_trace_context_add_hooks(tc,
+ events_request->before_chunk_trace,
+ events_request->before_chunk_tracefile,
+ events_request->event,
+ events_request->event_by_id);
+ }
+
+ iter = g_slist_next(iter);
+ }
+ }
+
+ {
+ tfc = lttv_traceset_context_get_current_tfc(tsc);
+
+ /* 2.1 For each req of list_out */
+ GSList *iter = list_out;
+
+ while(iter != NULL) {
+
+ gboolean remove = FALSE;
+ gboolean free_data = FALSE;
+ EventsRequest *events_request = (EventsRequest *)iter->data;
+
+ /* if req.start time == current context time
+ * or req.start position == current position*/
+ if( ltt_time_compare(events_request->start_time,
+ tfc->timestamp) == 0
+ ||
+ (events_request->start_position != NULL
+ &&
+ lttv_traceset_context_ctx_pos_compare(tsc,
+ events_request->start_position) == 0)
+ ) {
+ /* - Add to list_in, remove from list_out */
+ list_in = g_slist_append(list_in, events_request);
+ remove = TRUE;
+ free_data = FALSE;
+
+ /* - If !servicing */
+ if(events_request->servicing == FALSE) {
+ /* - begin request hooks called
+ * - servicing = TRUE
+ */
+ lttv_hooks_call(events_request->before_request, (gpointer)tsc);
+ events_request->servicing = TRUE;
+ }
+ /* call before chunk
+ * events hooks added
+ */
+ if(events_request->trace == -1)
+ lttv_process_traceset_begin(tsc,
+ events_request->before_chunk_traceset,
+ events_request->before_chunk_trace,
+ events_request->before_chunk_tracefile,
+ events_request->event,
+ events_request->event_by_id);
+ else {
+ guint nb_trace = lttv_traceset_number(tsc->ts);
+ g_assert((guint)events_request->trace < nb_trace &&
+ events_request->trace > -1);
+ LttvTraceContext *tc = tsc->traces[events_request->trace];
+
+ lttv_hooks_call(events_request->before_chunk_traceset, tsc);
+
+ lttv_trace_context_add_hooks(tc,
+ events_request->before_chunk_trace,
+ events_request->before_chunk_tracefile,
+ events_request->event,
+ events_request->event_by_id);
+ }
+
+
+ }
+
+ /* Go to next */
+ if(remove)
+ {
+ GSList *remove_iter = iter;
+
+ iter = g_slist_next(iter);
+ if(free_data) events_request_free((EventsRequest*)remove_iter->data);
+ list_out = g_slist_remove_link(list_out, remove_iter);
+ } else { // not remove
+ iter = g_slist_next(iter);
+ }
+ }
+ }
+ }
+
+ /* 3. Find end criterions */
+ {
+ /* 3.1 End time */
+ GSList *iter;
+
+ /* 3.1.1 Find lowest end time in list_in */
+ g_assert(g_slist_length(list_in)>0);
+ end_time = ((EventsRequest*)g_slist_nth_data(list_in,0))->end_time;
+
+ for(iter=g_slist_nth(list_in,1);iter!=NULL;iter=g_slist_next(iter)) {
+ EventsRequest *events_request = (EventsRequest*)iter->data;
+
+ if(ltt_time_compare(events_request->end_time,
+ end_time) < 0)
+ end_time = events_request->end_time;
+ }
+
+ /* 3.1.2 Find lowest start time in list_out */
+ for(iter=list_out;iter!=NULL;iter=g_slist_next(iter)) {
+ EventsRequest *events_request = (EventsRequest*)iter->data;
+
+ if(ltt_time_compare(events_request->start_time,
+ end_time) < 0)
+ end_time = events_request->start_time;
+ }
+ }
+
+ {
+ /* 3.2 Number of events */
+
+ /* 3.2.1 Find lowest number of events in list_in */
+ GSList *iter;
+
+ end_nb_events = ((EventsRequest*)g_slist_nth_data(list_in,0))->num_events;
+
+ for(iter=g_slist_nth(list_in,1);iter!=NULL;iter=g_slist_next(iter)) {
+ EventsRequest *events_request = (EventsRequest*)iter->data;
+
+ if(events_request->num_events < end_nb_events)
+ end_nb_events = events_request->num_events;
+ }
+
+ /* 3.2.2 Use min(CHUNK_NUM_EVENTS, min num events in list_in) as
+ * num_events */
+
+ end_nb_events = MIN(CHUNK_NUM_EVENTS, end_nb_events);
+ }
+
+ {
+ /* 3.3 End position */
+
+ /* 3.3.1 Find lowest end position in list_in */
+ GSList *iter;
+
+ end_position =((EventsRequest*)g_slist_nth_data(list_in,0))->end_position;
+
+ for(iter=g_slist_nth(list_in,1);iter!=NULL;iter=g_slist_next(iter)) {
+ EventsRequest *events_request = (EventsRequest*)iter->data;
+
+ if(events_request->end_position != NULL && end_position != NULL &&
+ lttv_traceset_context_pos_pos_compare(events_request->end_position,
+ end_position) <0)
+ end_position = events_request->end_position;
+ }
+ }
+
+ {
+ /* 3.3.2 Find lowest start position in list_out */
+ GSList *iter;
+
+ for(iter=list_out;iter!=NULL;iter=g_slist_next(iter)) {
+ EventsRequest *events_request = (EventsRequest*)iter->data;
+
+ if(events_request->end_position != NULL && end_position != NULL &&
+ lttv_traceset_context_pos_pos_compare(events_request->end_position,
+ end_position) <0)
+ end_position = events_request->end_position;
+ }
+ }
+
+ {
+ /* 4. Call process traceset middle */
+ g_debug("Calling process traceset middle with %p, %lu sec %lu nsec, %u nb ev, %p end pos", tsc, end_time.tv_sec, end_time.tv_nsec, end_nb_events, end_position);
+ count = lttv_process_traceset_middle(tsc, end_time, end_nb_events, end_position);