Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] assertions to point out errors on tracing
[simgrid.git] / src / instr / instr_paje.c
index 161436d..9bb9f8a 100644 (file)
@@ -8,6 +8,10 @@
 
 #ifdef HAVE_TRACING
 
+#define INSTR_PAJE_ASSERT(str) {xbt_assert1(str!=NULL&&strlen(str)>0, "'%s' is NULL or length is zero", #str);}
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje, instr, "Paje tracing event system");
+
 static FILE *tracing_file = NULL;
 
 static int pajeDefineContainerTypeId = 0;
@@ -30,7 +34,7 @@ static int pajeEndLinkId = 13;
 #define UNUSED009 17
 #define UNUSED005 18
 static int pajePushStateId = 19;
-#define UNUSED001 20
+static int pajeDefineEventTypeWithColorId = 20;
 static int pajeDefineVariableTypeWithColorId = 21;
 static int pajeSetVariableId = 22;
 static int pajeAddVariableId = 23;
@@ -45,10 +49,9 @@ void TRACE_paje_start(void)
 {
   char *filename = TRACE_get_filename();
   tracing_file = fopen(filename, "w");
-  if (!tracing_file) {
-    THROW1(tracing_error, TRACE_ERROR_FILE_OPEN,
-           "Tracefile %s could not be opened for writing.", filename);
-  }
+  xbt_assert1 (tracing_file != NULL, "Tracefile %s could not be opened for writing.", filename);
+
+  DEBUG1("Filename %s is open for writing", filename);
 
   /* output header */
   TRACE_paje_create_header();
@@ -57,10 +60,13 @@ void TRACE_paje_start(void)
 void TRACE_paje_end(void)
 {
   fclose(tracing_file);
+  char *filename = TRACE_get_filename();
+  DEBUG1("Filename %s is closed", filename);
 }
 
 void TRACE_paje_create_header(void)
 {
+  DEBUG0 ("Define paje header");
   fprintf(tracing_file, "\
 %%EventDef PajeDefineContainerType %d \n\
 %%       Alias string \n\
@@ -81,6 +87,12 @@ void TRACE_paje_create_header(void)
 %%       Alias string \n\
 %%       EntityType string \n\
 %%       Name string \n\
+%%       Color color \n\
+%%EndEventDef \n\
+%%EventDef PajeDefineEventType %d \n\
+%%       Alias string \n\
+%%       EntityType string \n\
+%%       Name string \n\
 %%EndEventDef \n\
 %%EventDef PajeDefineLinkType %d \n\
 %%       Alias string \n\
@@ -177,7 +189,7 @@ void TRACE_paje_create_header(void)
 %%       EntityType string \n\
 %%       Container string \n\
 %%       Value string \n\
-%%EndEventDef\n", pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId, pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId, pajeDestroyContainerId, pajeSetStateId, pajePopStateId, pajeStartLinkId, pajeEndLinkId, pajePushStateId, pajeSetVariableId, pajeAddVariableId, pajeSubVariableId, pajeDefineVariableTypeId, pajeDefineVariableTypeWithColorId, pajeStartLinkWithVolumeId, pajeNewEventId);
+%%EndEventDef\n", pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId, pajeDefineEventTypeWithColorId, pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId, pajeDestroyContainerId, pajeSetStateId, pajePopStateId, pajeStartLinkId, pajeEndLinkId, pajePushStateId, pajeSetVariableId, pajeAddVariableId, pajeSubVariableId, pajeDefineVariableTypeId, pajeDefineVariableTypeWithColorId, pajeStartLinkWithVolumeId, pajeNewEventId);
 }
 
 /* internal to this file */
@@ -186,24 +198,39 @@ static void __pajeCreateContainer(char *output, int len, int eventid,
                                   const char *type, const char *container,
                                   const char *name)
 {
-  snprintf(output, len, "%d %lf %s %s %s %s", eventid, time,
+  if (time == 0){
+    snprintf(output, len, "%d 0 %s %s %s %s", eventid,
+           alias, type, container, name);
+  }else{
+    snprintf(output, len, "%d %lf %s %s %s %s", eventid, time,
            alias, type, container, name);
+  }
 }
 
 static void __pajeSetState(char *output, int len, int eventid, double time,
                            const char *entityType, const char *container,
                            const char *value)
 {
-  snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
+  if (time == 0){
+    snprintf(output, len, "%d 0 %s %s %s", eventid, entityType,
+           container, value);
+  }else{
+    snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
            container, value);
+  }
 }
 
 static void __pajeSetVariable(char *output, int len, int eventid,
                               double time, const char *entityType,
                               const char *container, const char *value)
 {
-  snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
+  if (time == 0){
+    snprintf(output, len, "%d 0 %s %s %s", eventid, entityType,
            container, value);
+  }else{
+    snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
+           container, value);
+  }
 }
 
 static void __pajeStartLink(char *output, int len, int eventid,
@@ -211,14 +238,23 @@ static void __pajeStartLink(char *output, int len, int eventid,
                             const char *container, const char *value,
                             const char *sourceContainer, const char *key)
 {
-  snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType,
+  if (time == 0){
+    snprintf(output, len, "%d 0 %s %s %s %s %s", eventid, entityType,
+           container, value, sourceContainer, key);
+  }else{
+    snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType,
            container, value, sourceContainer, key);
+  }
 }
 
 /* internal do the instrumentation module */
 void pajeDefineContainerType(const char *alias, const char *containerType,
                              const char *name)
 {
+  INSTR_PAJE_ASSERT(alias);
+  INSTR_PAJE_ASSERT(containerType);
+  INSTR_PAJE_ASSERT(name);
+
   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias,
           containerType, name);
 }
@@ -226,13 +262,33 @@ void pajeDefineContainerType(const char *alias, const char *containerType,
 void pajeDefineStateType(const char *alias, const char *containerType,
                          const char *name)
 {
+  INSTR_PAJE_ASSERT(alias);
+  INSTR_PAJE_ASSERT(containerType);
+  INSTR_PAJE_ASSERT(name);
+
   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias,
           containerType, name);
 }
 
+void pajeDefineEventTypeWithColor(const char *alias, const char *containerType,
+                         const char *name, const char *color)
+{
+  INSTR_PAJE_ASSERT(alias);
+  INSTR_PAJE_ASSERT(containerType);
+  INSTR_PAJE_ASSERT(name);
+  INSTR_PAJE_ASSERT(name);
+
+  fprintf(tracing_file, "%d %s %s %s %s\n", pajeDefineEventTypeWithColorId, alias,
+          containerType, name, color);
+}
+
 void pajeDefineEventType(const char *alias, const char *containerType,
                          const char *name)
 {
+  INSTR_PAJE_ASSERT(alias);
+  INSTR_PAJE_ASSERT(containerType);
+  INSTR_PAJE_ASSERT(name);
+
   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias,
           containerType, name);
 }
@@ -241,6 +297,12 @@ void pajeDefineLinkType(const char *alias, const char *containerType,
                         const char *sourceContainerType,
                         const char *destContainerType, const char *name)
 {
+  INSTR_PAJE_ASSERT(alias);
+  INSTR_PAJE_ASSERT(containerType);
+  INSTR_PAJE_ASSERT(sourceContainerType);
+  INSTR_PAJE_ASSERT(destContainerType);
+  INSTR_PAJE_ASSERT(name);
+
   fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias,
           containerType, sourceContainerType, destContainerType, name);
 }
@@ -248,6 +310,11 @@ void pajeDefineLinkType(const char *alias, const char *containerType,
 void pajeCreateContainer(double time, const char *alias, const char *type,
                          const char *container, const char *name)
 {
+  INSTR_PAJE_ASSERT(alias);
+  INSTR_PAJE_ASSERT(type);
+  INSTR_PAJE_ASSERT(container);
+  INSTR_PAJE_ASSERT(name);
+
   char line[TRACE_LINE_SIZE];
   __pajeCreateContainer(line, TRACE_LINE_SIZE, pajeCreateContainerId, time,
                         alias, type, container, name);
@@ -257,13 +324,25 @@ void pajeCreateContainer(double time, const char *alias, const char *type,
 void pajeDestroyContainer(double time, const char *type,
                           const char *container)
 {
-  fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time,
+  INSTR_PAJE_ASSERT(type);
+  INSTR_PAJE_ASSERT(container);
+
+  if (time == 0){
+    fprintf(tracing_file, "%d 0 %s %s\n", pajeDestroyContainerId,
+          type, container);
+  }else{
+    fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time,
           type, container);
+  }
 }
 
 void pajeSetState(double time, const char *entityType,
                   const char *container, const char *value)
 {
+  INSTR_PAJE_ASSERT(entityType);
+  INSTR_PAJE_ASSERT(container);
+  INSTR_PAJE_ASSERT(value);
+
   char line[TRACE_LINE_SIZE];
   __pajeSetState(line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType,
                  container, value);
@@ -273,6 +352,10 @@ void pajeSetState(double time, const char *entityType,
 void pajePushState(double time, const char *entityType,
                    const char *container, const char *value)
 {
+  INSTR_PAJE_ASSERT(entityType);
+  INSTR_PAJE_ASSERT(container);
+  INSTR_PAJE_ASSERT(value);
+
   char line[TRACE_LINE_SIZE];
   __pajeSetState(line, TRACE_LINE_SIZE, pajePushStateId, time, entityType,
                  container, value);
@@ -282,6 +365,9 @@ void pajePushState(double time, const char *entityType,
 void pajePopState(double time, const char *entityType,
                   const char *container)
 {
+  INSTR_PAJE_ASSERT(entityType);
+  INSTR_PAJE_ASSERT(container);
+
   fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType,
           container);
 }
@@ -290,6 +376,12 @@ void pajeStartLink(double time, const char *entityType,
                    const char *container, const char *value,
                    const char *sourceContainer, const char *key)
 {
+  INSTR_PAJE_ASSERT(entityType);
+  INSTR_PAJE_ASSERT(container);
+  INSTR_PAJE_ASSERT(value);
+  INSTR_PAJE_ASSERT(sourceContainer);
+  INSTR_PAJE_ASSERT(key);
+
   char line[TRACE_LINE_SIZE];
   __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType,
                   container, value, sourceContainer, key);
@@ -301,6 +393,12 @@ void pajeStartLinkWithVolume(double time, const char *entityType,
                              const char *sourceContainer, const char *key,
                              double volume)
 {
+  INSTR_PAJE_ASSERT(entityType);
+  INSTR_PAJE_ASSERT(container);
+  INSTR_PAJE_ASSERT(value);
+  INSTR_PAJE_ASSERT(sourceContainer);
+  INSTR_PAJE_ASSERT(key);
+
   char line[TRACE_LINE_SIZE];
   __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkWithVolumeId, time,
                   entityType, container, value, sourceContainer, key);
@@ -311,13 +409,28 @@ void pajeEndLink(double time, const char *entityType,
                  const char *container, const char *value,
                  const char *destContainer, const char *key)
 {
-  fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time,
+  INSTR_PAJE_ASSERT(entityType);
+  INSTR_PAJE_ASSERT(container);
+  INSTR_PAJE_ASSERT(value);
+  INSTR_PAJE_ASSERT(destContainer);
+  INSTR_PAJE_ASSERT(key);
+
+  if (time == 0){
+    fprintf(tracing_file, "%d 0 %s %s %s %s %s\n", pajeEndLinkId,
+            entityType, container, value, destContainer, key);
+  }else {
+    fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time,
           entityType, container, value, destContainer, key);
+  }
 }
 
 void pajeDefineVariableType(const char *alias, const char *containerType,
                             const char *name)
 {
+  INSTR_PAJE_ASSERT(alias);
+  INSTR_PAJE_ASSERT(containerType);
+  INSTR_PAJE_ASSERT(name);
+
   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias,
           containerType, name);
 }
@@ -325,6 +438,11 @@ void pajeDefineVariableType(const char *alias, const char *containerType,
 void pajeDefineVariableTypeWithColor(const char *alias, const char *containerType,
                             const char *name, const char *color)
 {
+  INSTR_PAJE_ASSERT(alias);
+  INSTR_PAJE_ASSERT(containerType);
+  INSTR_PAJE_ASSERT(name);
+  INSTR_PAJE_ASSERT(color);
+
   fprintf(tracing_file, "%d %s %s %s \"%s\"\n", pajeDefineVariableTypeWithColorId, alias,
           containerType, name, color);
 }
@@ -332,6 +450,10 @@ void pajeDefineVariableTypeWithColor(const char *alias, const char *containerTyp
 void pajeSetVariable(double time, const char *entityType,
                      const char *container, const char *value)
 {
+  INSTR_PAJE_ASSERT(entityType);
+  INSTR_PAJE_ASSERT(container);
+  INSTR_PAJE_ASSERT(value);
+
   char line[TRACE_LINE_SIZE];
   __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSetVariableId, time,
                     entityType, container, value);
@@ -341,6 +463,10 @@ void pajeSetVariable(double time, const char *entityType,
 void pajeAddVariable(double time, const char *entityType,
                      const char *container, const char *value)
 {
+  INSTR_PAJE_ASSERT(entityType);
+  INSTR_PAJE_ASSERT(container);
+  INSTR_PAJE_ASSERT(value);
+
   char line[TRACE_LINE_SIZE];
   __pajeSetVariable(line, TRACE_LINE_SIZE, pajeAddVariableId, time,
                     entityType, container, value);
@@ -350,6 +476,10 @@ void pajeAddVariable(double time, const char *entityType,
 void pajeSubVariable(double time, const char *entityType,
                      const char *container, const char *value)
 {
+  INSTR_PAJE_ASSERT(entityType);
+  INSTR_PAJE_ASSERT(container);
+  INSTR_PAJE_ASSERT(value);
+
   char line[TRACE_LINE_SIZE];
   __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSubVariableId, time,
                     entityType, container, value);
@@ -359,8 +489,17 @@ void pajeSubVariable(double time, const char *entityType,
 void pajeNewEvent(double time, const char *entityType,
                   const char *container, const char *value)
 {
-  fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time,
+  INSTR_PAJE_ASSERT(entityType);
+  INSTR_PAJE_ASSERT(container);
+  INSTR_PAJE_ASSERT(value);
+
+  if (time == 0){
+    fprintf(tracing_file, "%d 0 %s %s %s\n", pajeNewEventId,
           entityType, container, value);
+  }else{
+    fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time,
+          entityType, container, value);
+  }
 }
 
 #endif /* HAVE_TRACING */