- lttv_hooks_add(hooks, seek_back_event_hook, &sd, LTTV_PRIO_DEFAULT);
-
- lttv_process_traceset_begin(self, NULL, NULL, NULL, hooks, NULL);
-
- while(1) {
- lttv_traceset_context_position_copy(end_pos, next_iter_end_pos);
-
- /* We must seek the traceset back to time - time_offset */
- /* this time becomes the new reference time */
- if(ltt_time_compare(time, time_offset) > 0)
- time = ltt_time_sub(time, time_offset);
- else
- time = self->time_span.start_time;
- asked_time = time;
-
- time_seeker(self, time);
- lttv_traceset_context_position_save(self, next_iter_end_pos);
- /* Resync the time in case of a seek_closest */
- time = lttv_traceset_context_position_get_time(next_iter_end_pos);
- if(ltt_time_compare(time, self->time_span.end_time) > 0) {
- time = self->time_span.end_time;
- }
-
- /* Process the traceset, calling a hook which adds events
- * to the array, overwriting the tail. It changes first_event and
- * events_found too. */
- /* We would like to have a clean context here : no other hook than our's */
-
- lttv_process_traceset_middle(self, ltt_time_infinite,
- G_MAXUINT, end_pos);
-
- /* stop criteria : - n events found
- * - asked_time < beginning of trace */
- if(sd.events_found < n) {
- if(sd.first_event > 0) {
- /* Save the first position */
- LttvTracesetContextPosition *pos =
- (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, 0);
- lttv_traceset_context_position_copy(saved_pos, pos);
- }
- g_assert(n-sd.events_found <= sd.array->len);
- /* Change array size to n - events_found */
- for(i=n-sd.events_found;i<sd.array->len;i++) {
- LttvTracesetContextPosition *pos =
- (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, i);
- lttv_traceset_context_position_destroy(pos);
- }
- g_ptr_array_set_size(sd.array, n-sd.events_found);
- sd.first_event = 0;
-
- /*
- * Did not fill our event list and started before the beginning of the
- * trace. There is no hope to fill it then.
- * It is OK to compare with trace start time here because we explicitely
- * seeked by time (not by position), so we cannot miss multiple event
- * happening exactly at trace start.
- */
- if(ltt_time_compare(asked_time, self->time_span.start_time) == 0)
- break;
-
- } else break; /* Second end criterion : n events found */
-
- time_offset = ltt_time_mul(time_offset, BACKWARD_SEEK_MUL);
- }
-
- lttv_traceset_context_position_destroy(end_pos);
- lttv_traceset_context_position_destroy(next_iter_end_pos);
-
- lttv_process_traceset_end(self, NULL, NULL, NULL, hooks, NULL);
-
- if(sd.events_found >= n) {
- /* Seek the traceset to the first event in the circular array */
- LttvTracesetContextPosition *pos =
- (LttvTracesetContextPosition*)g_ptr_array_index (sd.array,
- sd.first_event);
- retval= lttv_process_traceset_seek_position(self, pos);
- g_assert_cmpint(retval, ==, 0);
- } else {
- /* Will seek to the last saved position : in the worst case, it will be the
- * original position (if events_found is 0) */
- retval= lttv_process_traceset_seek_position(self, saved_pos);
- g_assert_cmpint(retval, ==, 0);
- }
-
- for(i=0;i<sd.array->len;i++) {
- LttvTracesetContextPosition *pos =
- (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, i);
- lttv_traceset_context_position_destroy(pos);
- }
- g_ptr_array_free(sd.array, TRUE);
-
- lttv_hooks_destroy(hooks);
-
- lttv_traceset_context_position_destroy(saved_pos);
-
- return sd.events_found;
+ lttv_hooks_add(hooks, seek_back_event_hook, &sd, LTTV_PRIO_DEFAULT);
+
+ lttv_process_traceset_begin(self, NULL, NULL, NULL, hooks, NULL);
+
+ while(1) {
+ lttv_traceset_context_position_copy(end_pos, next_iter_end_pos);
+
+ /* We must seek the traceset back to time - time_offset */
+ /* this time becomes the new reference time */
+ if(ltt_time_compare(time, time_offset) > 0)
+ time = ltt_time_sub(time, time_offset);
+ else
+ time = self->time_span.start_time;
+ asked_time = time;
+
+ time_seeker(self, time);
+ lttv_traceset_context_position_save(self, next_iter_end_pos);
+ /* Resync the time in case of a seek_closest */
+ time = lttv_traceset_context_position_get_time(next_iter_end_pos);
+ if(ltt_time_compare(time, self->time_span.end_time) > 0) {
+ time = self->time_span.end_time;
+ }
+
+ /* Process the traceset, calling a hook which adds events
+ * to the array, overwriting the tail. It changes first_event and
+ * events_found too. */
+ /* We would like to have a clean context here : no other hook than our's */
+
+ lttv_process_traceset_middle(self, ltt_time_infinite,
+ G_MAXUINT, end_pos);
+
+ /* stop criteria : - n events found
+ * - asked_time < beginning of trace */
+ if(sd.events_found < n) {
+ if(sd.first_event > 0) {
+ /* Save the first position */
+ LttvTracesetContextPosition *pos =
+ (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, 0);
+ lttv_traceset_context_position_copy(saved_pos, pos);
+ }
+ g_assert(n-sd.events_found <= sd.array->len);
+ /* Change array size to n - events_found */
+ for(i=n-sd.events_found;i<sd.array->len;i++) {
+ LttvTracesetContextPosition *pos =
+ (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, i);
+ lttv_traceset_context_position_destroy(pos);
+ }
+ g_ptr_array_set_size(sd.array, n-sd.events_found);
+ sd.first_event = 0;
+
+ /*
+ * Did not fill our event list and started before the beginning of the
+ * trace. There is no hope to fill it then.
+ * It is OK to compare with trace start time here because we explicitely
+ * seeked by time (not by position), so we cannot miss multiple event
+ * happening exactly at trace start.
+ */
+ if(ltt_time_compare(asked_time, self->time_span.start_time) == 0)
+ break;
+
+ } else break; /* Second end criterion : n events found */
+
+ time_offset = ltt_time_mul(time_offset, BACKWARD_SEEK_MUL);
+ }
+
+ lttv_traceset_context_position_destroy(end_pos);
+ lttv_traceset_context_position_destroy(next_iter_end_pos);
+
+ lttv_process_traceset_end(self, NULL, NULL, NULL, hooks, NULL);
+
+ if(sd.events_found >= n) {
+ /* Seek the traceset to the first event in the circular array */
+ LttvTracesetContextPosition *pos =
+ (LttvTracesetContextPosition*)g_ptr_array_index (sd.array,
+ sd.first_event);
+ retval= lttv_process_traceset_seek_position(self, pos);
+ g_assert_cmpint(retval, ==, 0);
+ } else {
+ /* Will seek to the last saved position : in the worst case, it will be the
+ * original position (if events_found is 0) */
+ retval= lttv_process_traceset_seek_position(self, saved_pos);
+ g_assert_cmpint(retval, ==, 0);
+ }
+
+ for(i=0;i<sd.array->len;i++) {
+ LttvTracesetContextPosition *pos =
+ (LttvTracesetContextPosition*)g_ptr_array_index (sd.array, i);
+ lttv_traceset_context_position_destroy(pos);
+ }
+ g_ptr_array_free(sd.array, TRUE);
+
+ lttv_hooks_destroy(hooks);
+
+ lttv_traceset_context_position_destroy(saved_pos);
+
+ return sd.events_found;