Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] isolating buffer dumping from the simulation, only dump if trace is enabled
[simgrid.git] / src / instr / instr_paje_trace.c
index d2c4026..a8060aa 100644 (file)
@@ -176,6 +176,7 @@ double TRACE_last_timestamp_to_dump = 0;
 //dumps the trace file until the timestamp TRACE_last_timestamp_to_dump
 void TRACE_paje_dump_buffer (int force)
 {
+  if (!TRACE_is_enabled()) return;
   XBT_DEBUG("%s: dump until %f. starts", __FUNCTION__, TRACE_last_timestamp_to_dump);
   if (force){
     paje_event_t event;
@@ -331,37 +332,25 @@ void TRACE_paje_create_header(void)
 /* internal do the instrumentation module */
 static void insert_into_buffer (paje_event_t tbi)
 {
+  if (TRACE_buffer() == 0){
+    tbi->print (tbi);
+    tbi->free (tbi);
+    return;
+  }
   XBT_DEBUG("%s: insert event_type=%d, timestamp=%f, buffersize=%ld)", __FUNCTION__, tbi->event_type, tbi->timestamp, xbt_dynar_length(buffer));
 
   unsigned int i;
-  unsigned long len = xbt_dynar_length(buffer);
-  if (len == 0){
-    xbt_dynar_push (buffer, &tbi);
-    XBT_DEBUG("%s: inserted at beginning", __FUNCTION__);
-  }else{
-    //check if last event has the same timestamp that tbi event
-    paje_event_t e2 = *(paje_event_t*)xbt_dynar_get_ptr (buffer, len-1);
-    if (e2->timestamp == tbi->timestamp){
-      //insert at the end
-      XBT_DEBUG("%s: inserted at end, pos = %ld", __FUNCTION__, len);
-      xbt_dynar_insert_at (buffer, len, &tbi);
-      return;
-    }
-    int inserted = 0;
-    for (i = 0; i < len; i++){
-      paje_event_t e1 = *(paje_event_t*)xbt_dynar_get_ptr(buffer, i);
-      if (e1->timestamp > tbi->timestamp){
-        xbt_dynar_insert_at (buffer, i, &tbi);
-        XBT_DEBUG("%s: inserted at %d", __FUNCTION__, i);
-        inserted = 1;
-        break;
-      }
-    }
-    if (!inserted){
-      xbt_dynar_push (buffer, &tbi);
-      XBT_DEBUG("%s: inserted at end", __FUNCTION__);
-    }
+  for (i = xbt_dynar_length(buffer); i > 0; i--) {
+    paje_event_t e1 = *(paje_event_t*)xbt_dynar_get_ptr(buffer, i - 1);
+    if (e1->timestamp <= tbi->timestamp)
+      break;
   }
+  xbt_dynar_insert_at(buffer, i, &tbi);
+  if (i == 0)
+    XBT_DEBUG("%s: inserted at beginning", __FUNCTION__);
+  else
+    XBT_DEBUG("%s: inserted at%s %d", __FUNCTION__,
+              (i == xbt_dynar_length(buffer) - 1 ? " end, pos =" : ""), i);
 }
 
 static void print_pajeDefineContainerType(paje_event_t event)