Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] other parts of tracing can also declare types (needed by msg process tracing)
[simgrid.git] / src / instr / instr_paje.c
index d617480..aed13c0 100644 (file)
@@ -8,8 +8,9 @@
 
 #ifdef HAVE_TRACING
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje, instr, "Paje tracing event system");
+
 static FILE *tracing_file = NULL;
-int tracing_active = 0;
 
 static int pajeDefineContainerTypeId = 0;
 static int pajeDefineStateTypeId = 1;
@@ -31,7 +32,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;
@@ -42,23 +43,28 @@ static int pajeNewEventId = 27;
 
 #define TRACE_LINE_SIZE 1000
 
-void TRACE_paje_start(FILE * file)
+void TRACE_paje_start(void)
 {
-  tracing_file = file;
-  tracing_active = 1;
+  char *filename = TRACE_get_filename();
+  tracing_file = fopen(filename, "w");
+  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();
 }
 
-FILE *TRACE_paje_end(void)
+void TRACE_paje_end(void)
 {
-  tracing_active = 0;
-  return tracing_file;
+  fclose(tracing_file);
+  char *filename = TRACE_get_filename();
+  DEBUG1("Filename %s is closed", filename);
 }
 
-
 void TRACE_paje_create_header(void)
 {
-  if (!tracing_active)
-    return;
+  DEBUG0 ("Define paje header");
   fprintf(tracing_file, "\
 %%EventDef PajeDefineContainerType %d \n\
 %%       Alias string \n\
@@ -79,6 +85,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\
@@ -175,7 +187,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 */
@@ -184,24 +196,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,
@@ -209,8 +236,13 @@ 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 */
@@ -228,6 +260,13 @@ void pajeDefineStateType(const char *alias, const char *containerType,
           containerType, name);
 }
 
+void pajeDefineEventTypeWithColor(const char *alias, const char *containerType,
+                         const char *name, const char *color)
+{
+  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)
 {
@@ -255,8 +294,13 @@ 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,
+  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,
@@ -309,8 +353,13 @@ 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,
+  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,
@@ -357,8 +406,13 @@ 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,
+  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
+#endif /* HAVE_TRACING */