+struct cleanup_state_struct {
+ LttvTraceState *ts;
+ LttTime current_time;
+};
+
+//static void lttv_stats_cleanup_process_state(LttvTraceState *ts,
+// LttvProcessState *process, LttTime current_time)
+static void lttv_stats_cleanup_process_state(gpointer key, gpointer value,
+ gpointer user_data)
+{
+ struct cleanup_state_struct *cleanup_closure =
+ (struct cleanup_state_struct *)user_data;
+ LttvTraceState *ts = cleanup_closure->ts;
+ LttvProcessState *process = (LttvProcessState *)value;
+ LttTime current_time = cleanup_closure->current_time;
+ LttvTracefileStats **tfs = (LttvTracefileStats **)
+ &g_array_index(ts->parent.tracefiles, LttvTracefileContext*,
+ process->cpu);
+ int cleanup_empty = 0;
+ LttTime nested_delta = ltt_time_zero;
+
+ /* FIXME : ok, this is a hack. The time is infinite here :( */
+ //LttTime save_time = (*tfs)->parent.parent.timestamp;
+ //LttTime start, end;
+ //ltt_trace_time_span_get(ts->parent.t, &start, &end);
+ //(*tfs)->parent.parent.timestamp = end;
+
+ do {
+ if(ltt_time_compare(process->state->cum_cpu_time, ltt_time_zero) != 0) {
+ find_event_tree(*tfs, process->pid_time,
+ process->cpu,
+ process->current_function,
+ process->state->t, process->state->n, &((*tfs)->current_events_tree),
+ &((*tfs)->current_event_types_tree));
+ /* Call mode_end only if not at end of trace */
+ if(ltt_time_compare(current_time, ltt_time_infinite) != 0)
+ mode_end(*tfs);
+ nested_delta = process->state->cum_cpu_time;
+ }
+ cleanup_empty = lttv_state_pop_state_cleanup(process,
+ (LttvTracefileState *)*tfs);
+ process->state->cum_cpu_time = ltt_time_add(process->state->cum_cpu_time,
+ nested_delta);
+
+ } while(cleanup_empty != 1);
+
+ //(*tfs)->parent.parent.timestamp = save_time;
+}
+
+/* For each cpu, for each of their stacked states,
+ * perform sum of needed values. */
+static void lttv_stats_cleanup_state(LttvTraceStats *tcs, LttTime current_time)
+{
+ LttvTraceState *ts = (LttvTraceState *)tcs;
+ struct cleanup_state_struct cleanup_closure;
+#if 0
+ guint nb_cpus, i;
+
+ nb_cpus = ltt_trace_get_num_cpu(ts->parent.t);
+
+ for(i=0; i<nb_cpus; i++) {
+ lttv_stats_cleanup_process_state(ts, ts->running_process[i], current_time);
+ }
+#endif //0
+ cleanup_closure.ts = ts;
+ cleanup_closure.current_time = current_time;
+ g_hash_table_foreach(ts->processes, lttv_stats_cleanup_process_state,
+ &cleanup_closure);
+}