Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] protecting the declaration of multiple types with the same name
[simgrid.git] / src / instr / instr_variables.c
index 40dfcf0..608186b 100644 (file)
 
 #ifdef HAVE_TRACING
 
-extern routing_global_t global_routing;
-
-void TRACE_user_link_variable(double time, const char *src,
-                              const char *dst, const char *variable,
+void TRACE_user_link_variable(double time, const char *resource,
+                              const char *variable,
                               double value, const char *what)
 {
-  if (!IS_TRACING || !IS_TRACING_PLATFORM)
+  if (!TRACE_is_active())
     return;
 
+  xbt_assert1 (instr_platform_traced(),
+      "%s must be called after environment creation", __FUNCTION__);
+
   char valuestr[100];
   snprintf(valuestr, 100, "%g", value);
 
   if (strcmp(what, "declare") == 0) {
-    pajeDefineVariableType(variable, "LINK", variable);
-    return;
-  }
-
-  if (!global_routing)
-    return;
-
-  xbt_dynar_t route = global_routing->get_route(src, dst);
-  unsigned int i;
-  void *link_ptr;
-  xbt_dynar_foreach(route, i, link_ptr) {
-    char resource[100];
-    snprintf(resource, 100, "%p", link_ptr);
-
+    instr_new_user_link_variable_type (variable, NULL);
+  } else{
+    char *variable_id = instr_variable_type(variable, resource);
+    char *resource_id = instr_resource_type(resource);
     if (strcmp(what, "set") == 0) {
-      pajeSetVariable(time, variable, resource, valuestr);
+      pajeSetVariable(time, variable_id, resource_id, valuestr);
     } else if (strcmp(what, "add") == 0) {
-      pajeAddVariable(time, variable, resource, valuestr);
+      pajeAddVariable(time, variable_id, resource_id, valuestr);
     } else if (strcmp(what, "sub") == 0) {
-      pajeSubVariable(time, variable, resource, valuestr);
+      pajeSubVariable(time, variable_id, resource_id, valuestr);
     }
   }
 }
@@ -50,21 +41,29 @@ void TRACE_user_link_variable(double time, const char *src,
 void TRACE_user_host_variable(double time, const char *variable,
                               double value, const char *what)
 {
-  char valuestr[100];
-  if (!IS_TRACING || !IS_TRACING_PLATFORM)
+  if (!TRACE_is_active())
     return;
 
+  xbt_assert1 (instr_platform_traced(),
+      "%s must be called after environment creation", __FUNCTION__);
+
+  char valuestr[100];
   snprintf(valuestr, 100, "%g", value);
 
   if (strcmp(what, "declare") == 0) {
-    pajeDefineVariableType(variable, "HOST", variable);
-  } else if (strcmp(what, "set") == 0) {
-    pajeSetVariable(time, variable, MSG_host_self()->name, valuestr);
-  } else if (strcmp(what, "add") == 0) {
-    pajeAddVariable(time, variable, MSG_host_self()->name, valuestr);
-  } else if (strcmp(what, "sub") == 0) {
-    pajeSubVariable(time, variable, MSG_host_self()->name, valuestr);
+    instr_new_user_host_variable_type (variable, NULL);
+  } else{
+    char *host_name = MSG_host_self()->name;
+    char *variable_id = instr_variable_type(variable, host_name);
+    char *resource_id = instr_resource_type(host_name);
+    if (strcmp(what, "set") == 0) {
+      pajeSetVariable(time, variable_id, resource_id, valuestr);
+    } else if (strcmp(what, "add") == 0) {
+      pajeAddVariable(time, variable_id, resource_id, valuestr);
+    } else if (strcmp(what, "sub") == 0) {
+      pajeSubVariable(time, variable_id, resource_id, valuestr);
+    }
   }
 }
 
-#endif                          /* HAVE_TRACING */
+#endif /* HAVE_TRACING */