Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / src / instr / instr_paje_trace.cpp
index 2cce106..cbdc9f9 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2015. The SimGrid Team.
+/* Copyright (c) 2010-2016. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -6,36 +6,97 @@
 
 #include "src/instr/instr_private.h"
 #include "xbt/virtu.h" /* sg_cmdline */
+#include <sstream>
+#include <iomanip> /** std::setprecision **/
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr_trace, "tracing event system");
 
 extern FILE * tracing_file;
 extern s_instr_trace_writer_t active_writer;
 
-void TRACE_paje_init(void)
-{
-  active_writer.print_DefineContainerType=print_pajeDefineContainerType;
-  active_writer.print_DefineVariableType=print_pajeDefineVariableType;
-  active_writer.print_DefineStateType=print_pajeDefineStateType;
-  active_writer.print_DefineEventType=print_pajeDefineEventType;
-  active_writer.print_DefineLinkType=print_pajeDefineLinkType;
-  active_writer.print_DefineEntityValue=print_pajeDefineEntityValue;
-  active_writer.print_CreateContainer=print_pajeCreateContainer;
-  active_writer.print_DestroyContainer=print_pajeDestroyContainer;
-  active_writer.print_SetVariable=print_pajeSetVariable;
-  active_writer.print_AddVariable=print_pajeAddVariable;
-  active_writer.print_SubVariable=print_pajeSubVariable;
-  active_writer.print_SetState=print_pajeSetState;
-  active_writer.print_PushState=print_pajePushState;
-  active_writer.print_PopState=print_pajePopState;
-  active_writer.print_ResetState=print_pajeResetState;
-  active_writer.print_StartLink=print_pajeStartLink;
-  active_writer.print_EndLink=print_pajeEndLink;
-  active_writer.print_NewEvent=print_pajeNewEvent;
+static std::stringstream stream;
+
+static void print_paje_debug(std::string functionName, paje_event_t event) {
+  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(),
+            event->timestamp);
+}
+
+template<typename T> static void init_stream(paje_event_t event) {
+  stream << std::fixed << std::setprecision(TRACE_precision());
+  stream << (int) event->event_type;
+}
+
+static void print_row() {
+  stream << std::endl;
+  fprintf(tracing_file, "%s", stream.str().c_str());
+  stream.str("");
+  stream.clear();
+}
+
+static void print_timestamp(paje_event_t event) {
+  stream << " ";
+  /* prevent 0.0000 in the trace - this was the behavior before the transition to c++ */
+  if (event->timestamp == 0) 
+    stream << 0;
+  else 
+    stream << event->timestamp;
+}
+
+
+template<typename T> static void print_default_pajeLink_row(paje_event_t& event) {
+  init_stream<T>(event);
+  print_timestamp(event);
+  stream << " " << static_cast<T>(event->data)->type->id
+         << " " << static_cast<T>(event->data)->container->id
+         << " " << static_cast<T>(event->data)->value;
 }
 
-void TRACE_paje_start(void)
-{
+template<typename T> static void print_default_pajeState_row(paje_event_t& event) {
+  init_stream<T>(event);
+  print_timestamp(event);
+  stream << " " << static_cast<T>(event->data)->type->id
+         << " " << static_cast<T>(event->data)->container->id;
+}
+
+template<typename T> static void print_default_pajeType_row(paje_event_t& event) {
+  init_stream<T>(event);
+  stream << " " << static_cast<T>(event->data)->type->id
+         << " " << static_cast<T>(event->data)->type->father->id
+         << " " << static_cast<T>(event->data)->type->name;
+}
+
+template<typename T> static void print_default_pajeVariable_row(paje_event_t& event) {
+  init_stream<T>(event);
+  print_timestamp(event);
+  stream << " " << static_cast<T>(event->data)->type->id
+         << " " << static_cast<T>(event->data)->container->id
+         << " " << static_cast<T>(event->data)->value;
+         
+  print_row();
+}
+
+void TRACE_paje_init(void) {
+  active_writer.print_DefineContainerType = print_pajeDefineContainerType;
+  active_writer.print_DefineVariableType  = print_pajeDefineVariableType;
+  active_writer.print_DefineStateType     = print_pajeDefineStateType;
+  active_writer.print_DefineEventType     = print_pajeDefineEventType;
+  active_writer.print_DefineLinkType      = print_pajeDefineLinkType;
+  active_writer.print_DefineEntityValue   = print_pajeDefineEntityValue;
+  active_writer.print_CreateContainer     = print_pajeCreateContainer;
+  active_writer.print_DestroyContainer    = print_pajeDestroyContainer;
+  active_writer.print_SetVariable         = print_pajeSetVariable;
+  active_writer.print_AddVariable         = print_pajeAddVariable;
+  active_writer.print_SubVariable         = print_pajeSubVariable;
+  active_writer.print_SetState            = print_pajeSetState;
+  active_writer.print_PushState           = print_pajePushState;
+  active_writer.print_PopState            = print_pajePopState;
+  active_writer.print_ResetState          = print_pajeResetState;
+  active_writer.print_StartLink           = print_pajeStartLink;
+  active_writer.print_EndLink             = print_pajeEndLink;
+  active_writer.print_NewEvent            = print_pajeNewEvent;
+}
+
+void TRACE_paje_start(void) {
   char *filename = TRACE_get_filename();
   tracing_file = fopen(filename, "w");
   if (tracing_file == NULL){
@@ -45,7 +106,8 @@ void TRACE_paje_start(void)
   XBT_DEBUG("Filename %s is open for writing", filename);
 
   /* output generator version */
-  fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n", SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
+  fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
+           SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
   fprintf (tracing_file, "#[");
   unsigned int cpt;
   char *str;
@@ -62,384 +124,168 @@ void TRACE_paje_start(void)
 
   /* output header */
   TRACE_header(TRACE_basic(),TRACE_display_sizes());
-
 }
 
-void TRACE_paje_end(void)
-{
+void TRACE_paje_end(void) {
   fclose(tracing_file);
   char *filename = TRACE_get_filename();
   XBT_DEBUG("Filename %s is closed", filename);
 }
 
-
-void print_pajeDefineContainerType(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
-  fprintf(tracing_file, "%d %s %s %s\n",
-      (int)event->event_type,
-      ((defineContainerType_t)event->data)->type->id,
-      ((defineContainerType_t)event->data)->type->father->id,
-      ((defineContainerType_t)event->data)->type->name);
+void print_pajeDefineContainerType(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeType_row<defineContainerType_t>(event);
+  print_row();
 }
 
-void print_pajeDefineVariableType(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
-  fprintf(tracing_file, "%d %s %s %s \"%s\"\n",
-      (int)event->event_type,
-      ((defineVariableType_t)event->data)->type->id,
-      ((defineVariableType_t)event->data)->type->father->id,
-      ((defineVariableType_t)event->data)->type->name,
-      ((defineVariableType_t)event->data)->type->color);
+void print_pajeDefineVariableType(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeType_row<defineVariableType_t>(event);
+  stream << " \"" << static_cast<defineVariableType_t>(event->data)->type->color << "\"";
+  print_row();
 }
 
-void print_pajeDefineStateType(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
-  fprintf(tracing_file, "%d %s %s %s\n",
-      (int)event->event_type,
-      ((defineStateType_t)event->data)->type->id,
-      ((defineStateType_t)event->data)->type->father->id,
-      ((defineStateType_t)event->data)->type->name);
+void print_pajeDefineStateType(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeType_row<defineStateType_t>(event);
+  print_row();
 }
 
-void print_pajeDefineEventType(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
-  fprintf(tracing_file, "%d %s %s %s\n",
-      (int)event->event_type,
-      ((defineEventType_t)event->data)->type->id,
-      ((defineEventType_t)event->data)->type->father->id,
-      ((defineEventType_t)event->data)->type->name);
+void print_pajeDefineEventType(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeType_row<defineEventType_t>(event);
+  print_row();
 }
 
-void print_pajeDefineLinkType(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
-  fprintf(tracing_file, "%d %s %s %s %s %s\n",
-      (int)event->event_type,
-      ((defineLinkType_t)event->data)->type->id,
-      ((defineLinkType_t)event->data)->type->father->id,
-      ((defineLinkType_t)event->data)->source->id,
-      ((defineLinkType_t)event->data)->dest->id,
-      ((defineLinkType_t)event->data)->type->name);
+void print_pajeDefineLinkType(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  init_stream<defineLinkType_t>(event);
+  stream << " " << static_cast<defineLinkType_t>(event->data)->type->id 
+         << " " << static_cast<defineLinkType_t>(event->data)->type->father->id 
+         << " " << static_cast<defineLinkType_t>(event->data)->source->id 
+         << " " << static_cast<defineLinkType_t>(event->data)->dest->id 
+         << " " << static_cast<defineLinkType_t>(event->data)->type->name;
+  print_row();
 }
 
-void print_pajeDefineEntityValue (paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
-  fprintf(tracing_file, "%d %s %s %s \"%s\"\n",
-      (int)event->event_type,
-      ((defineEntityValue_t)event->data)->value->id,
-      ((defineEntityValue_t)event->data)->value->father->id,
-      ((defineEntityValue_t)event->data)->value->name,
-      ((defineEntityValue_t)event->data)->value->color);
+void print_pajeDefineEntityValue (paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  init_stream<defineEntityValue_t>(event);
+  stream << " "   << static_cast<defineEntityValue_t>(event->data)->value->id
+         << " "   << static_cast<defineEntityValue_t>(event->data)->value->father->id
+         << " "   << static_cast<defineEntityValue_t>(event->data)->value->name
+         << " \"" << static_cast<defineEntityValue_t>(event->data)->value->color << "\"";
+  print_row();
 }
 
-void print_pajeCreateContainer(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-  if (event->timestamp == 0){
-    fprintf(tracing_file, "%d 0 %s %s %s \"%s\"\n",
-        (int)event->event_type,
-        ((createContainer_t)event->data)->container->id,
-        ((createContainer_t)event->data)->container->type->id,
-        ((createContainer_t)event->data)->container->father->id,
-        ((createContainer_t)event->data)->container->name);
-  }else{
-    fprintf(tracing_file, "%d %.*f %s %s %s \"%s\"\n",
-        (int)event->event_type,
-        TRACE_precision(),
-        event->timestamp,
-        ((createContainer_t)event->data)->container->id,
-        ((createContainer_t)event->data)->container->type->id,
-        ((createContainer_t)event->data)->container->father->id,
-        ((createContainer_t)event->data)->container->name);
-  }
+void print_pajeCreateContainer(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  init_stream<createContainer_t>(event);
+  print_timestamp(event);
+  stream << " "   << static_cast<createContainer_t>(event->data)->container->id
+         << " "   << static_cast<createContainer_t>(event->data)->container->type->id
+         << " "   << static_cast<createContainer_t>(event->data)->container->father->id
+         << " \"" << static_cast<createContainer_t>(event->data)->container->name << "\"";
+
+  print_row();
 }
 
-void print_pajeDestroyContainer(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-  if (event->timestamp == 0){
-    fprintf(tracing_file, "%d 0 %s %s\n",
-        (int)event->event_type,
-        ((destroyContainer_t)event->data)->container->type->id,
-        ((destroyContainer_t)event->data)->container->id);
-  }else{
-    fprintf(tracing_file, "%d %.*f %s %s\n",
-        (int)event->event_type,
-        TRACE_precision(),
-        event->timestamp,
-        ((destroyContainer_t)event->data)->container->type->id,
-        ((destroyContainer_t)event->data)->container->id);
-  }
+void print_pajeDestroyContainer(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  init_stream<createContainer_t>(event);
+  print_timestamp(event);
+  stream << " "   << static_cast<createContainer_t>(event->data)->container->type->id
+         << " "   << static_cast<createContainer_t>(event->data)->container->id;
+
+  print_row();
 }
 
-void print_pajeSetVariable(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-  if (event->timestamp == 0){
-    fprintf(tracing_file, "%d 0 %s %s %f\n",
-        (int)event->event_type,
-        ((setVariable_t)event->data)->type->id,
-        ((setVariable_t)event->data)->container->id,
-        ((setVariable_t)event->data)->value);
-  }else{
-    fprintf(tracing_file, "%d %.*f %s %s %f\n",
-        (int)event->event_type,
-        TRACE_precision(),
-        event->timestamp,
-        ((setVariable_t)event->data)->type->id,
-        ((setVariable_t)event->data)->container->id,
-        ((setVariable_t)event->data)->value);
-  }
+void print_pajeSetVariable(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeVariable_row<setVariable_t>(event);
 }
 
-void print_pajeAddVariable(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-  if (event->timestamp == 0){
-    fprintf(tracing_file, "%d 0 %s %s %f\n",
-        (int)event->event_type,
-        ((addVariable_t)event->data)->type->id,
-        ((addVariable_t)event->data)->container->id,
-        ((addVariable_t)event->data)->value);
-  }else{
-    fprintf(tracing_file, "%d %.*f %s %s %f\n",
-        (int)event->event_type,
-        TRACE_precision(),
-        event->timestamp,
-        ((addVariable_t)event->data)->type->id,
-        ((addVariable_t)event->data)->container->id,
-        ((addVariable_t)event->data)->value);
-  }
+void print_pajeAddVariable(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeVariable_row<addVariable_t>(event);
 }
 
-void print_pajeSubVariable(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-  if (event->timestamp == 0){
-    fprintf(tracing_file, "%d 0 %s %s %f\n",
-        (int)event->event_type,
-        ((subVariable_t)event->data)->type->id,
-        ((subVariable_t)event->data)->container->id,
-        ((subVariable_t)event->data)->value);
-  }else{
-    fprintf(tracing_file, "%d %.*f %s %s %f\n",
-        (int)event->event_type,
-        TRACE_precision(),
-        event->timestamp,
-        ((subVariable_t)event->data)->type->id,
-        ((subVariable_t)event->data)->container->id,
-        ((subVariable_t)event->data)->value);
-  }
+void print_pajeSubVariable(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeVariable_row<subVariable_t>(event);
 }
 
-void print_pajeSetState(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-  if (event->timestamp == 0){
-    fprintf(tracing_file, "%d 0 %s %s %s\n",
-        (int)event->event_type,
-        ((setState_t)event->data)->type->id,
-        ((setState_t)event->data)->container->id,
-        ((setState_t)event->data)->value->id);
-  }else{
-    fprintf(tracing_file, "%d %.*f %s %s %s\n",
-        (int)event->event_type,
-        TRACE_precision(),
-        event->timestamp,
-        ((setState_t)event->data)->type->id,
-        ((setState_t)event->data)->container->id,
-        ((setState_t)event->data)->value->id);
-  }
+void print_pajeSetState(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+
+  print_default_pajeState_row<setState_t>(event);
+  stream << " " << static_cast<setState_t>(event->data)->value->id;
+  print_row();
 }
 
-void print_pajePushState(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-  if (!TRACE_display_sizes()){
-    if (event->timestamp == 0){
-      fprintf(tracing_file, "%d 0 %s %s %s\n",
-          (int)event->event_type,
-          ((pushState_t)event->data)->type->id,
-          ((pushState_t)event->data)->container->id,
-          ((pushState_t)event->data)->value->id);
-    }else{
-      fprintf(tracing_file, "%d %.*f %s %s %s\n",
-          (int)event->event_type,
-          TRACE_precision(),
-          event->timestamp,
-          ((pushState_t)event->data)->type->id,
-          ((pushState_t)event->data)->container->id,
-          ((pushState_t)event->data)->value->id);
-    }
-  }else{
-    if (event->timestamp == 0){
-      fprintf(tracing_file, "%d 0 %s %s %s ",
-          (int)event->event_type,
-          ((pushState_t)event->data)->type->id,
-          ((pushState_t)event->data)->container->id,
-          ((pushState_t)event->data)->value->id);
-      if(((pushState_t)event->data)->extra !=NULL){
-        fprintf(tracing_file, "%d ", ((instr_extra_data)((pushState_t)event->data)->extra)->send_size);
-      }else{
-        fprintf(tracing_file, "0 ");
-      }
-      fprintf(tracing_file, "\n");
-
-    }else{
-      fprintf(tracing_file, "%d %.*f %s %s %s ",
-          (int)event->event_type,
-          TRACE_precision(),
-          event->timestamp,
-          ((pushState_t)event->data)->type->id,
-          ((pushState_t)event->data)->container->id,
-          ((pushState_t)event->data)->value->id);
-      if(((pushState_t)event->data)->extra !=NULL){
-        fprintf(tracing_file, "%d ", ((instr_extra_data)((pushState_t)event->data)->extra)->send_size);
-      }else{
-        fprintf(tracing_file, "0 ");
-      }
-      fprintf(tracing_file, "\n");
+void print_pajePushState(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeState_row<pushState_t>(event);
+  stream << " " << static_cast<pushState_t>(event->data)->value->id;
 
+  if (TRACE_display_sizes()) {
+    stream << " ";
+    if (static_cast<pushState_t>(event->data)->extra != NULL) {
+      stream << static_cast<instr_extra_data>(static_cast<pushState_t>(event->data)->extra)->send_size;
     }
+    else {
+      stream << 0;
+    }
+  }
+  print_row();
+
+  if (static_cast<pushState_t>(event->data)->extra != NULL) {
+    if (static_cast<instr_extra_data>(static_cast<pushState_t>(event->data)->extra)->sendcounts != NULL)
+      xbt_free(static_cast<instr_extra_data>(static_cast<pushState_t>(event->data)->extra)->sendcounts);
+    if (static_cast<instr_extra_data>(static_cast<pushState_t>(event->data)->extra)->recvcounts != NULL)
+      xbt_free(static_cast<instr_extra_data>(static_cast<pushState_t>(event->data)->extra)->recvcounts);
+    xbt_free(static_cast<pushState_t>(event->data)->extra);
   }
-   if(((pushState_t)event->data)->extra!=NULL){
-     if(((instr_extra_data)((pushState_t)event->data)->extra)->sendcounts!=NULL)
-       xbt_free(((instr_extra_data)((pushState_t)event->data)->extra)->sendcounts);
-     if(((instr_extra_data)((pushState_t)event->data)->extra)->recvcounts!=NULL)
-       xbt_free(((instr_extra_data)((pushState_t)event->data)->extra)->recvcounts);
-     xbt_free(((pushState_t)event->data)->extra);
-   }
 }
 
-void print_pajePopState(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-  if (event->timestamp == 0){
-    fprintf(tracing_file, "%d 0 %s %s\n",
-        (int)event->event_type,
-        ((popState_t)event->data)->type->id,
-        ((popState_t)event->data)->container->id);
-  }else{
-    fprintf(tracing_file, "%d %.*f %s %s\n",
-        (int)event->event_type,
-        TRACE_precision(),
-        event->timestamp,
-        ((popState_t)event->data)->type->id,
-        ((popState_t)event->data)->container->id);
-  }
+void print_pajePopState(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeState_row<popState_t>(event);
+  print_row();
 }
 
-void print_pajeResetState(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-  if (event->timestamp == 0){
-    fprintf(tracing_file, "%d 0 %s %s\n",
-        (int)event->event_type,
-        ((resetState_t)event->data)->type->id,
-        ((resetState_t)event->data)->container->id);
-  }else{
-    fprintf(tracing_file, "%d %.*f %s %s\n",
-        (int)event->event_type,
-        TRACE_precision(),
-        event->timestamp,
-        ((resetState_t)event->data)->type->id,
-        ((resetState_t)event->data)->container->id);
-  }
+void print_pajeResetState(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeState_row<resetState_t>(event);
+  print_row();
 }
 
-void print_pajeStartLink(paje_event_t event)
-{
-  if (!TRACE_display_sizes()){
-    if (event->timestamp == 0){
-      fprintf(tracing_file, "%d 0 %s %s %s %s %s\n",
-          (int)event->event_type,
-          ((startLink_t)event->data)->type->id,
-          ((startLink_t)event->data)->container->id,
-          ((startLink_t)event->data)->value,
-          ((startLink_t)event->data)->sourceContainer->id,
-          ((startLink_t)event->data)->key);
-    }else {
-      fprintf(tracing_file, "%d %.*f %s %s %s %s %s\n",
-          (int)event->event_type,
-          TRACE_precision(),
-          event->timestamp,
-          ((startLink_t)event->data)->type->id,
-          ((startLink_t)event->data)->container->id,
-          ((startLink_t)event->data)->value,
-          ((startLink_t)event->data)->sourceContainer->id,
-          ((startLink_t)event->data)->key);
-    }
-  }else{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-    if (event->timestamp == 0){
-      fprintf(tracing_file, "%d 0 %s %s %s %s %s %d\n",
-          (int)event->event_type,
-          ((startLink_t)event->data)->type->id,
-          ((startLink_t)event->data)->container->id,
-          ((startLink_t)event->data)->value,
-          ((startLink_t)event->data)->sourceContainer->id,
-          ((startLink_t)event->data)->key,
-          ((startLink_t)event->data)->size);
-    }else {
-      fprintf(tracing_file, "%d %.*f %s %s %s %s %s %d\n",
-          (int)event->event_type,
-          TRACE_precision(),
-          event->timestamp,
-          ((startLink_t)event->data)->type->id,
-          ((startLink_t)event->data)->container->id,
-          ((startLink_t)event->data)->value,
-          ((startLink_t)event->data)->sourceContainer->id,
-          ((startLink_t)event->data)->key,
-          ((startLink_t)event->data)->size);
-    }
+void print_pajeStartLink(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeLink_row<startLink_t>(event);
+  stream << " " << static_cast<startLink_t>(event->data)->sourceContainer->id
+         << " " << static_cast<startLink_t>(event->data)->key;
+
+  if (TRACE_display_sizes()) {
+    stream << " " << static_cast<startLink_t>(event->data)->size;
   }
+  print_row();
 }
 
-void print_pajeEndLink(paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-  if (event->timestamp == 0){
-    fprintf(tracing_file, "%d 0 %s %s %s %s %s\n",
-        (int)event->event_type,
-        ((endLink_t)event->data)->type->id,
-        ((endLink_t)event->data)->container->id,
-        ((endLink_t)event->data)->value,
-        ((endLink_t)event->data)->destContainer->id,
-        ((endLink_t)event->data)->key);
-  }else {
-    fprintf(tracing_file, "%d %.*f %s %s %s %s %s\n",
-        (int)event->event_type,
-        TRACE_precision(),
-        event->timestamp,
-        ((endLink_t)event->data)->type->id,
-        ((endLink_t)event->data)->container->id,
-        ((endLink_t)event->data)->value,
-        ((endLink_t)event->data)->destContainer->id,
-        ((endLink_t)event->data)->key);
-  }
+void print_pajeEndLink(paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  print_default_pajeLink_row<startLink_t>(event);
+  stream << " " << static_cast<endLink_t>(event->data)->destContainer->id
+         << " " << static_cast<endLink_t>(event->data)->key;
+  print_row();
 }
 
-void print_pajeNewEvent (paje_event_t event)
-{
-  XBT_DEBUG("%s: event_type=%d, timestamp=%.*f", __FUNCTION__, (int)event->event_type, TRACE_precision(), event->timestamp);
-  if (event->timestamp == 0){
-    fprintf(tracing_file, "%d 0 %s %s %s\n",
-        (int)event->event_type,
-        ((newEvent_t)event->data)->type->id,
-        ((newEvent_t)event->data)->container->id,
-        ((newEvent_t)event->data)->value->id);
-  }else{
-    fprintf(tracing_file, "%d %.*f %s %s %s\n",
-        (int)event->event_type,
-        TRACE_precision(),
-        event->timestamp,
-        ((newEvent_t)event->data)->type->id,
-        ((newEvent_t)event->data)->container->id,
-        ((newEvent_t)event->data)->value->id);
-  }
+void print_pajeNewEvent (paje_event_t event) {
+  print_paje_debug(__FUNCTION__, event);
+  init_stream<newEvent_t>(event);
+  print_timestamp(event);
+  stream << " " << static_cast<newEvent_t>(event->data)->type->id
+         << " " << static_cast<newEvent_t>(event->data)->container->id
+         << " " << static_cast<newEvent_t>(event->data)->value->id;
+  print_row();
 }