Be more specific in the no SEEK_LAST fallback
[lttv.git] / lttv / lttv / traceset.c
index b10564c5dce8d040a7fafb44bfb2d97ec8f9981e..7e86c5b764b8e2c0e1f0787f6826b2e99c23932a 100644 (file)
@@ -68,7 +68,11 @@ LttvTraceset *lttv_traceset_new(void)
        ts->event_hooks = lttv_hooks_new();
 
        ts->state_trace_handle_index = g_ptr_array_new();
+       ts->has_precomputed_states = FALSE;
 
+       ts->time_span.start_time = ltt_time_zero;
+        ts->time_span.end_time = ltt_time_zero;
+       lttv_traceset_get_time_span_real(ts);
        return ts;
 }
 
@@ -421,7 +425,7 @@ guint lttv_trace_get_num_cpu(LttvTrace *t)
        return 24;
 }
 
-LttvTracesetPosition *lttv_traceset_create_position(LttvTraceset *traceset)
+LttvTracesetPosition *lttv_traceset_create_current_position(LttvTraceset *traceset)
 {
        LttvTracesetPosition *traceset_pos;
        
@@ -434,7 +438,9 @@ LttvTracesetPosition *lttv_traceset_create_position(LttvTraceset *traceset)
 
        traceset_pos->iter = traceset->iter;
        traceset_pos->bt_pos = bt_iter_get_pos(bt_ctf_get_iter(traceset->iter));
-       
+        traceset_pos->timestamp = G_MAXUINT64;
+        traceset_pos->cpu_id = INT_MAX;
+        
        return traceset_pos;
 }
 
@@ -451,10 +457,11 @@ LttvTracesetPosition *lttv_traceset_create_time_position(LttvTraceset *traceset,
         }
         
         traceset_pos->iter = traceset->iter;
-        traceset_pos->bt_pos = bt_iter_create_time_pos(
+        traceset_pos->bt_pos = bt_iter_create_time_pos( 
                                         bt_ctf_get_iter(traceset_pos->iter),
                                         ltt_time_to_uint64(timestamp));
-         
+        traceset_pos->timestamp = G_MAXUINT64;
+        traceset_pos->cpu_id = INT_MAX;
         return traceset_pos;
 }
 
@@ -496,6 +503,8 @@ guint64 lttv_traceset_get_timestamp_first_event(LttvTraceset *ts)
         LttvTracesetPosition begin_position;
         struct bt_iter_pos pos;
         begin_position.bt_pos = &pos;
+        begin_position.timestamp = G_MAXUINT64;
+        begin_position.cpu_id = INT_MAX;
        
          /* Assign iterator to the beginning of the traces */  
         begin_position.bt_pos->type = BT_SEEK_BEGIN;
@@ -504,6 +513,21 @@ guint64 lttv_traceset_get_timestamp_first_event(LttvTraceset *ts)
         return lttv_traceset_position_get_timestamp(&begin_position);  
 }
 
+guint64 lttv_traceset_get_timestamp_last_event(LttvTraceset *ts)
+{
+       LttvTracesetPosition last_position;
+       struct bt_iter_pos pos;
+       last_position.bt_pos = &pos;
+       last_position.timestamp = G_MAXUINT64;
+       last_position.cpu_id = INT_MAX;
+#ifdef BABEL_HAS_SEEK_LAST     
+       /* Assign iterator to the last event of the traces */  
+       last_position.bt_pos->type = BT_SEEK_LAST;
+       last_position.iter = ts->iter;
+#endif
+       return lttv_traceset_position_get_timestamp(&last_position);
+}
+
 /*
  * lttv_traceset_get_timestamp_begin : returns the  minimum timestamp of 
  * all the traces in the traceset.
@@ -526,7 +550,8 @@ guint64 lttv_traceset_get_timestamp_begin(LttvTraceset *traceset)
                 {
                         currentTrace = g_ptr_array_index(traceset->traces,i);
                         timestamp_cur = bt_trace_handle_get_timestamp_begin(bt_ctx,
-                                                                        currentTrace->id);
+                                                                       currentTrace->id,
+                                                                       BT_CLOCK_REAL);
                         if(timestamp_cur < timestamp_min)
                                 timestamp_min = timestamp_cur;
                 }
@@ -558,7 +583,8 @@ guint64 lttv_traceset_get_timestamp_end(LttvTraceset *traceset)
                {
                        currentTrace = g_ptr_array_index(traceset->traces,i);
                        timestamp_cur = bt_trace_handle_get_timestamp_end(bt_ctx,
-                                                                         currentTrace->id);
+                                                                       currentTrace->id,
+                                                                       BT_CLOCK_REAL);
                        if(timestamp_cur > timestamp_max){
                                timestamp_max = timestamp_cur;
                        }
@@ -568,28 +594,41 @@ guint64 lttv_traceset_get_timestamp_end(LttvTraceset *traceset)
 }
 /*
  * lttv_traceset_get_time_span_real : return a TimeInterval representing the
- * minimum timestamp dans le maximum timestamp of the traceset.
+ * minimum timestamp and the maximum timestamp of the traceset.
  * 
  */
 TimeInterval lttv_traceset_get_time_span_real(LttvTraceset *ts)
 {
-        TimeInterval time_span;
-        time_span.start_time =ltt_time_from_uint64(lttv_traceset_get_timestamp_first_event(ts));
-        time_span.end_time = ltt_time_from_uint64(lttv_traceset_get_timestamp_end(ts));
-        return time_span;
+
+
+       if(ltt_time_compare(ts->time_span.start_time, 
+                               ltt_time_zero) == 0 && ts->traces->len > 0){
+               ts->time_span.start_time = ltt_time_from_uint64(
+                               lttv_traceset_get_timestamp_first_event(ts));
+#ifdef BABEL_HAS_SEEK_LAST     
+               ts->time_span.end_time = ltt_time_from_uint64(
+                                       lttv_traceset_get_timestamp_end(ts));
+#else
+               ts->time_span.end_time = lttv_traceset_get_time_span(ts).end_time;      
+#endif
+       }
+        return ts->time_span;
 }
 
 /*
  * lttv_traceset_get_time_span : return a TimeInterval representing the
- * minimum timestamp dans le maximum timestamp of the traceset.
+ * minimum timestamp and the maximum timestamp of the traceset.
  * 
  */
 TimeInterval lttv_traceset_get_time_span(LttvTraceset *ts)
 {
-        TimeInterval time_span;
-        time_span.start_time =ltt_time_from_uint64(lttv_traceset_get_timestamp_begin(ts));
-        time_span.end_time = ltt_time_from_uint64(lttv_traceset_get_timestamp_end(ts));
-        return time_span;
+       if(ltt_time_compare(ts->time_span.start_time, ltt_time_zero) == 0){
+               ts->time_span.start_time =ltt_time_from_uint64(
+                                       lttv_traceset_get_timestamp_begin(ts));
+               ts->time_span.end_time = ltt_time_from_uint64(
+                                       lttv_traceset_get_timestamp_end(ts));
+       }
+        return ts->time_span;
 }
 
 const char *lttv_traceset_get_name_from_event(LttvEvent *event)
@@ -597,24 +636,53 @@ const char *lttv_traceset_get_name_from_event(LttvEvent *event)
        return bt_ctf_event_name(event->bt_event);
 }
 
-guint64 lttv_traceset_position_get_timestamp(const LttvTracesetPosition *pos)
-{ 
-        guint64 timestamp = 0;
-       /*We save the current iterator,so we can reassign it after the seek*/
-        LttvTracesetPosition previous_pos;
-        previous_pos.iter = pos->iter;
-        previous_pos.bt_pos = bt_iter_get_pos(bt_ctf_get_iter(pos->iter));
+int set_values_position(const LttvTracesetPosition *pos)
+{
+       LttvTracesetPosition previous_pos;
+       previous_pos.iter = pos->iter;
+       previous_pos.bt_pos = bt_iter_get_pos(bt_ctf_get_iter(pos->iter));
        /* Seek to the new desired position */
-        lttv_traceset_seek_to_position(pos);
+       lttv_traceset_seek_to_position(pos);
        /*Read the event*/
-        struct bt_ctf_event *event = bt_ctf_iter_read_event(pos->iter);
-        
+       struct bt_ctf_event *event = bt_ctf_iter_read_event(pos->iter);
+
        if(event != NULL){
-               timestamp = bt_ctf_get_timestamp_raw(event); 
+               ((LttvTracesetPosition *)pos)->timestamp = bt_ctf_get_timestamp(event); 
+               
+               LttvEvent lttv_event;
+               lttv_event.bt_event = event;
+               ((LttvTracesetPosition *)pos)->cpu_id = lttv_traceset_get_cpuid_from_event(&lttv_event);
        }
-        /* Reassign the previously saved position */
-        lttv_traceset_seek_to_position(&previous_pos);
-       return timestamp;
+       else {
+               /* The event is null */
+               return 0;
+       }
+
+       /* Reassign the previously saved position */
+       lttv_traceset_seek_to_position(&previous_pos);
+       /*We must desallocate because the function bt_iter_get_pos() does a g_new */
+       bt_iter_free_pos(previous_pos.bt_pos);
+       return 1;
+}
+
+guint64 lttv_traceset_position_get_timestamp(const LttvTracesetPosition *pos)
+{ 
+        if(pos->timestamp == G_MAXUINT64){
+                if(set_values_position(pos) == 0){
+                       return 0;
+               }
+        }
+        
+        return pos->timestamp;
+}
+
+int lttv_traceset_position_get_cpuid(const LttvTracesetPosition *pos){
+        if(pos->cpu_id == INT_MAX ){
+                 if(set_values_position(pos) == 0){
+                       return 0;
+               }
+        }
+        return pos->cpu_id;
 }
 
 LttTime  lttv_traceset_position_get_time(const LttvTracesetPosition *pos)
@@ -622,6 +690,8 @@ LttTime  lttv_traceset_position_get_time(const LttvTracesetPosition *pos)
         return ltt_time_from_uint64(lttv_traceset_position_get_timestamp(pos));
 }
 
+
+
 int lttv_traceset_position_compare(const LttvTracesetPosition *pos1, const LttvTracesetPosition *pos2)
 {
 #warning " TODO :Rename for lttv_traceset_position_equals && Must return COMPARAISON OF THE 2 POSITION && verify if it is the best way to compare position"
@@ -631,21 +701,13 @@ int lttv_traceset_position_compare(const LttvTracesetPosition *pos1, const LttvT
         
         guint64 timeStampPos1,timeStampPos2;
         guint cpuId1, cpuId2;
-        LttvEvent event1, event2;
-        int ret;
         
         timeStampPos1 = lttv_traceset_position_get_timestamp(pos1);
         timeStampPos2 = lttv_traceset_position_get_timestamp(pos2);
         
-        event1.bt_event = bt_ctf_iter_read_event(pos1->iter);
-        event2.bt_event = bt_ctf_iter_read_event(pos2->iter);
         
-        if(event1.bt_event == NULL || event2.bt_event == NULL){
-                return -1;
-       }
-
-        cpuId1 = lttv_traceset_get_cpuid_from_event(&event1);
-        cpuId2 = lttv_traceset_get_cpuid_from_event(&event2);
+        cpuId1 = lttv_traceset_position_get_cpuid(pos1);
+        cpuId2 = lttv_traceset_position_get_cpuid(pos2);
        
         if(timeStampPos1 == timeStampPos2 && cpuId1 == cpuId2){
                 return 0;
@@ -654,3 +716,35 @@ int lttv_traceset_position_compare(const LttvTracesetPosition *pos1, const LttvT
                 return 1;
        }
 }
+
+int lttv_traceset_position_time_compare(const LttvTracesetPosition *pos1, 
+                                       const LttvTracesetPosition *pos2)
+{
+        guint64 timeStampPos1,timeStampPos2;
+
+       timeStampPos1 = lttv_traceset_position_get_timestamp(pos1);
+        timeStampPos2 = lttv_traceset_position_get_timestamp(pos2);
+        
+       return timeStampPos1 - timeStampPos2;
+}
+int lttv_traceset_position_compare_current(const LttvTraceset *ts, 
+                                          const LttvTracesetPosition *pos)
+{
+       int result = 0;
+       LttvTracesetPosition *curPos = lttv_traceset_create_current_position(ts);
+
+       result = lttv_traceset_position_compare(curPos,pos);
+
+       lttv_traceset_destroy_position(curPos);
+
+       return result;
+}
+
+LttTime lttv_traceset_get_current_time(const LttvTraceset *ts)
+{
+       LttvTracesetPosition *curPos = lttv_traceset_create_current_position(ts);
+       guint64 currentTimestamp = lttv_traceset_position_get_timestamp(curPos);
+       lttv_traceset_destroy_position(curPos);
+
+        return ltt_time_from_uint64(currentTimestamp);
+}
This page took 0.025988 seconds and 4 git commands to generate.