Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove all the events that are called and destroyed one time
[simgrid.git] / src / instr / instr_paje_trace.cpp
index 463cadf..5cabc10 100644 (file)
@@ -21,8 +21,6 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr, "tracing event system");
 
-extern s_instr_trace_writer_t active_writer;
-
 static std::stringstream stream;
 FILE *tracing_file = nullptr;
 
@@ -35,10 +33,6 @@ void print_NULL(PajeEvent* event){}
 /* The active set of functions for the selected trace format
  * By default, they all do nothing, hence the print_NULL to avoid segfaults */
 
-s_instr_trace_writer_t active_writer = {&print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL,
-                                        &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL,
-                                        &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL, &print_NULL};
-
 std::vector<PajeEvent*> buffer;
 void buffer_debug(std::vector<PajeEvent*> *buf);
 
@@ -150,7 +144,6 @@ static void insert_into_buffer (PajeEvent* tbi)
     if (e1->timestamp <= tbi->timestamp)
       break;
   }
-  buffer.insert(i.base(), tbi);
   if (i == buffer.rend())
     XBT_DEBUG("%s: inserted at beginning", __FUNCTION__);
   else if (i == buffer.rbegin())
@@ -158,6 +151,7 @@ static void insert_into_buffer (PajeEvent* tbi)
   else
     XBT_DEBUG("%s: inserted at pos= %zd from its end", __FUNCTION__,
         std::distance(buffer.rbegin(),i));
+  buffer.insert(i.base(), tbi);
 
   buffer_debug(&buffer);
 }
@@ -218,50 +212,42 @@ void TRACE_paje_end() {
   XBT_DEBUG("Filename %s is closed", filename);
 }
 
-DefineContainerEvent::DefineContainerEvent(type_t type)
+void DefineContainerEvent(type_t type)
 {
-
-  event_type                            = PAJE_DefineContainerType;
-  timestamp                             = 0;
-  this->type = type;
+  e_event_type event_type                            = PAJE_DefineContainerType;
+  double timestamp                             = 0;
   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
   //print it
-  print ();
-}
-
-void DefineContainerEvent::print() {
   if (instr_fmt_type == instr_fmt_paje) {
-    XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
-    stream << std::fixed << std::setprecision(TRACE_precision());
-    stream << (int)this->event_type;
-    stream << " " << type->id << " " << type->father->id << " " << type->name;
-    print_row();
-  } else if (instr_fmt_type == instr_fmt_TI) {
-    /* Nothing to do */
-  } else {
-    THROW_IMPOSSIBLE;
-  }
+               XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
+               stream << std::fixed << std::setprecision(TRACE_precision());
+               stream << (int)event_type;
+               stream << " " << type->id
+                               << " " << type->father->id
+                               << " " << type->name;
+               print_row();
+       } else if (instr_fmt_type == instr_fmt_TI) {
+               /* Nothing to do */
+       } else {
+               THROW_IMPOSSIBLE;
+       }
+  //--
 }
 
 
 
-DefineVariableTypeEvent::DefineVariableTypeEvent(type_t type)
+void DefineVariableTypeEvent(type_t type)
 {
-  this->event_type                           = PAJE_DefineVariableType;
-  this->timestamp                            = 0;
-  this->type = type;
+  e_event_type event_type                           = PAJE_DefineVariableType;
+  double timestamp                            = 0;
 
   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
 
   //print it
-  print ();
-}
-
-void DefineVariableTypeEvent::print() {
-  if (instr_fmt_type == instr_fmt_paje) {
+if (instr_fmt_type == instr_fmt_paje) {
     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
     stream << std::fixed << std::setprecision(TRACE_precision());
-    stream << (int)this->event_type;
+    stream << (int)event_type;
     stream << " " << type->id << " " << type->father->id << " " << type->name;
     if (type->color)
       stream << " \"" << type->color << "\"";
@@ -273,16 +259,26 @@ void DefineVariableTypeEvent::print() {
   }
 }
 
-DefineStateTypeEvent::DefineStateTypeEvent(type_t type)
+
+void DefineStateTypeEvent(type_t type)
 {
-  this->event_type                        = PAJE_DefineStateType;
-  this->timestamp                         = 0;
-  this->type = type;
+  e_event_type event_type                        = PAJE_DefineStateType;
+  double timestamp                         = 0;
 
   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
 
   //print it
-  print();
+if (instr_fmt_type == instr_fmt_paje) {
+    XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
+    stream << std::fixed << std::setprecision(TRACE_precision());
+    stream << (int)event_type;
+    stream << " " << type->id << " " << type->father->id << " " << type->name;
+    print_row();
+  } else if (instr_fmt_type == instr_fmt_TI) {
+    /* Nothing to do */
+  } else {
+    THROW_IMPOSSIBLE;
+  }
 }
 
 
@@ -299,20 +295,6 @@ DefineEventTypeEvent::DefineEventTypeEvent(type_t type)
 }
 
 
-void DefineStateTypeEvent::print() {
-  if (instr_fmt_type == instr_fmt_paje) {
-    XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
-    stream << std::fixed << std::setprecision(TRACE_precision());
-    stream << (int)this->event_type;
-    stream << " " << type->id << " " << type->father->id << " " << type->name;
-    print_row();
-  } else if (instr_fmt_type == instr_fmt_TI) {
-    /* Nothing to do */
-  } else {
-    THROW_IMPOSSIBLE;
-  }
-}
-
 void DefineEventTypeEvent::print() {
   if (instr_fmt_type == instr_fmt_paje) {
     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
@@ -327,25 +309,18 @@ void DefineEventTypeEvent::print() {
   }
 }
 
-DefineLinkTypeEvent::DefineLinkTypeEvent(type_t type, type_t source, type_t dest)
+void DefineLinkTypeEvent(type_t type, type_t source, type_t dest)
 {
-  this->event_type                         = PAJE_DefineLinkType;
-  this->timestamp                          = 0;
-  this->type   = type;
-  this->source = source;
-  this->dest   = dest;
+  e_event_type event_type                         = PAJE_DefineLinkType;
+  double timestamp                          = 0;
 
   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
 
   //print it
-  print();
-}
-
-void DefineLinkTypeEvent::print() {
-  if (instr_fmt_type == instr_fmt_paje) {
+if (instr_fmt_type == instr_fmt_paje) {
     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
     stream << std::fixed << std::setprecision(TRACE_precision());
-    stream << (int)this->event_type;
+    stream << (int)event_type;
     stream << " " << type->id << " " << type->father->id << " " << source->id << " " << dest->id << " " << type->name;
     print_row();
   } else if (instr_fmt_type == instr_fmt_TI) {
@@ -355,24 +330,18 @@ void DefineLinkTypeEvent::print() {
   }
 }
 
-DefineEntityValueEvent::DefineEntityValueEvent (val_t value)
+void DefineEntityValueEvent (val_t value)
 {
-  this->event_type                           = PAJE_DefineEntityValue;
-  this->timestamp                            = 0;
-  this->value = value;
+  e_event_type event_type                           = PAJE_DefineEntityValue;
+  double timestamp                            = 0;
 
   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event_type);
 
   //print it
-  print();
-}
-
-
-void DefineEntityValueEvent::print() {
-  if (instr_fmt_type == instr_fmt_paje) {
+if (instr_fmt_type == instr_fmt_paje) {
     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
     stream << std::fixed << std::setprecision(TRACE_precision());
-    stream << (int)this->event_type;
+    stream << (int)event_type;
     stream << " " << value->id << " " << value->father->id << " " << value->name;
     if (value->color)
       stream << " \"" << value->color << "\"";
@@ -384,25 +353,26 @@ void DefineEntityValueEvent::print() {
   }
 }
 
-CreateContainerEvent::CreateContainerEvent (container_t container)
-{
-  this->event_type                             = PAJE_CreateContainer;
-  this->timestamp                              = SIMIX_get_clock();
-  this->container = container;
 
-  XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
+void CreateContainerEvent (container_t container)
+{
+  e_event_type event_type                             = PAJE_CreateContainer;
+  double timestamp                              = SIMIX_get_clock();
 
-  print();
-}
+  XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type,timestamp);
 
-void CreateContainerEvent::print() {
-  if (instr_fmt_type == instr_fmt_paje) {
+if (instr_fmt_type == instr_fmt_paje) {
     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
     stream << std::fixed << std::setprecision(TRACE_precision());
-    stream << (int)this->event_type;
-    print_timestamp(this);
-    stream << " " << container->id << " " << container->type->id << " " << container->father->id << " \""
-           << container->name << "\"";
+    stream << (int)event_type;
+    stream << " ";
+  /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
+     if (timestamp < 1e-12)
+         stream << 0;
+      else 
+         stream << timestamp;
+         stream << " " << container->id << " " << container->type->id << " " << container->father->id << " \""
+            << container->name << "\"";
 
     print_row();
   } else if (instr_fmt_type == instr_fmt_TI) {
@@ -437,25 +407,24 @@ void CreateContainerEvent::print() {
   }
 }
 
-DestroyContainerEvent::DestroyContainerEvent (container_t container)
+void DestroyContainerEvent (container_t container)
 {
-  this->event_type                              = PAJE_DestroyContainer;
-  this->timestamp                               = SIMIX_get_clock();
-  this->container = container;
+  e_event_type event_type                              = PAJE_DestroyContainer;
+  double timestamp                               = SIMIX_get_clock();
 
-  XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
+  XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, timestamp);
 
-  print();
-}
-
-void DestroyContainerEvent::print() {
-  if (instr_fmt_type == instr_fmt_paje) {
+if (instr_fmt_type == instr_fmt_paje) {
     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);
     stream << std::fixed << std::setprecision(TRACE_precision());
-    stream << (int)this->event_type;
-    print_timestamp(this);
+    stream << (int)event_type;
+    stream << " ";
+  /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
+    if (timestamp < 1e-12)
+        stream << 0;
+    else 
+        stream << timestamp;
     stream << " " << container->type->id << " " << container->id;
-
     print_row();
   } else if (instr_fmt_type == instr_fmt_TI) {
     if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || xbt_dict_length(tracing_files) == 1) {
@@ -468,6 +437,7 @@ void DestroyContainerEvent::print() {
         }
 }
 
+
 SetVariableEvent::SetVariableEvent (double timestamp, container_t container, type_t type, double value)
 {
   this->event_type                         = PAJE_SetVariable;
@@ -819,6 +789,7 @@ ResetStateEvent::ResetStateEvent (double timestamp, container_t container, type_
   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event_type, this->timestamp);
 
   insert_into_buffer (this);
+       delete [] this;
 }
 
 void ResetStateEvent::print() {
@@ -836,6 +807,11 @@ void ResetStateEvent::print() {
   }
 }
 
+StartLinkEvent::~StartLinkEvent()
+{
+  free(value);
+  free(key);
+}
 StartLinkEvent::StartLinkEvent (double timestamp, container_t container,
     type_t type, container_t sourceContainer, const char *value, const char *key)
   : StartLinkEvent(timestamp, container, type, sourceContainer, value, key, -1)
@@ -895,7 +871,11 @@ EndLinkEvent::EndLinkEvent (double timestamp, container_t container, type_t type
   insert_into_buffer (this);
 }
 
-
+EndLinkEvent::~EndLinkEvent()
+{
+  free(value);
+  free(key);
+}
 void EndLinkEvent::print() {
   if (instr_fmt_type == instr_fmt_paje) {
     XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event_type, TRACE_precision(), timestamp);