+ return FALSE;
+}
+
+/* Seek back n events back from the current position.
+ *
+ * Parameters :
+ * @self The trace set context
+ * @n number of events to jump over
+ * @first_offset The initial offset value used.
+ * never put first_offset at ltt_time_zero.
+ * @time_seeker Function pointer of the function to use to seek time :
+ * either lttv_process_traceset_seek_time
+ * or lttv_state_traceset_seek_time_closest
+ * @filter The filter to call.
+ *
+ * Return value : the number of events found (might be lower than the number
+ * requested if beginning of traceset is reached).
+ *
+ * The first search will go back first_offset and try to find the last n events
+ * matching the filter. If there are not enough, it will try to go back from the
+ * new trace point from first_offset*2, and so on, until beginning of trace or n
+ * events are found.
+ *
+ * Note : this function does not take in account the LttvFilter : use the
+ * similar function found in state.c instead.
+ *
+ * Note2 : the caller must make sure that the LttvTracesetContext does not
+ * contain any hook, as process_traceset_middle is used in this routine.
+ */
+guint lttv_process_traceset_seek_n_backward(LttvTracesetContext *self,
+ guint n, LttTime first_offset,
+ seek_time_fct time_seeker,
+ LttvFilter *filter,
+ check_handler *check,
+ gboolean *stop_flag)
+{
+ if(lttv_traceset_number(self->ts) == 0) return 0;
+ g_assert(ltt_time_compare(first_offset, ltt_time_zero) != 0);
+
+ guint i;
+ LttvTracesetContextPosition *next_iter_end_pos =
+ lttv_traceset_context_position_new(self);
+ LttvTracesetContextPosition *end_pos =
+ lttv_traceset_context_position_new(self);
+ LttvTracesetContextPosition *saved_pos =
+ lttv_traceset_context_position_new(self);
+ LttTime time;
+ LttTime asked_time;
+ LttTime time_offset;
+ struct seek_back_data sd;
+ LttvHooks *hooks = lttv_hooks_new();
+
+ sd.first_event = 0;
+ sd.events_found = 0;
+ sd.array = g_ptr_array_sized_new(n);
+ sd.filter = filter;
+ sd.n = n;
+ sd.check = check;
+ sd.stop_flag = stop_flag;
+ sd.raw_event_count = 0;
+ g_ptr_array_set_size(sd.array, n);
+ for(i=0;i<n;i++) {
+ g_ptr_array_index (sd.array, i) = lttv_traceset_context_position_new(self);
+ }
+
+ lttv_traceset_context_position_save(self, next_iter_end_pos);
+ lttv_traceset_context_position_save(self, saved_pos);
+ /* Get the current time from which we will offset */
+ time = lttv_traceset_context_position_get_time(next_iter_end_pos);
+ /* the position saved might be end of traceset... */
+ if(ltt_time_compare(time, self->time_span.end_time) > 0) {
+ time = self->time_span.end_time;
+ }
+ asked_time = time;
+ time_offset = first_offset;
+
+ lttv_hooks_add(hooks, seek_back_event_hook, &sd, LTTV_PRIO_DEFAULT);
+
+ lttv_process_traceset_begin(self, NULL, NULL, NULL, hooks, NULL);
+
+ while(1) {
+ /* stop criteria : - n events found
+ * - asked_time < beginning of trace */
+ if(ltt_time_compare(asked_time, self->time_span.start_time) < 0) break;
+
+ 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 */
+ time = ltt_time_sub(time, time_offset);
+ 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;
+ }