Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
new function to check if a tracing container exists
[simgrid.git] / src / instr / instr_resource_utilization.c
index d68cb87..e8273e3 100644 (file)
@@ -8,6 +8,8 @@
 
 #ifdef HAVE_TRACING
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_resource, instr, "tracing (un)-categorized resource utilization");
+
 //to check if variables were previously set to 0, otherwise paje won't simulate them
 static xbt_dict_t platform_variables;   /* host or link name -> array of categories */
 
@@ -37,8 +39,9 @@ static void __TRACE_surf_check_variable_set_to_zero(double now,
     xbt_dynar_t array = xbt_dynar_new(sizeof(char *), xbt_free);
     char *var_cpy = xbt_strdup(variable);
     xbt_dynar_push(array, &var_cpy);
-    if (IS_TRACING_PLATFORM)
-      pajeSetVariable(now, variable, resource, "0");
+    container_t container = getContainerByName (resource);
+    type_t type = getVariableType (variable, NULL, container->type);
+    new_pajeSetVariable (now, container, type, 0);
     xbt_dict_set(platform_variables, resource, array,
                  xbt_dynar_free_voidp);
   } else {
@@ -54,8 +57,11 @@ static void __TRACE_surf_check_variable_set_to_zero(double now,
     if (flag == 0) {
       char *var_cpy = xbt_strdup(variable);
       xbt_dynar_push(array, &var_cpy);
-      if (IS_TRACING_PLATFORM)
-        pajeSetVariable(now, variable, resource, "0");
+      if (TRACE_categorized ()){
+        container_t container = getContainerByName (resource);
+        type_t type = getVariableType (variable, NULL, container->type);
+        new_pajeSetVariable (now, container, type, 0);
+      }
     }
   }
   /* end of check */
@@ -79,15 +85,14 @@ static void __TRACE_A_event(smx_action_t action, double now, double delta,
                             const char *variable, const char *resource,
                             double value)
 {
-  if (!IS_TRACING_PLATFORM)
-    return;
-
   char valuestr[100];
   snprintf(valuestr, 100, "%f", value);
 
   __TRACE_surf_check_variable_set_to_zero(now, variable, resource);
-  pajeAddVariable(now, variable, resource, valuestr);
-  pajeSubVariable(now + delta, variable, resource, valuestr);
+  container_t container = getContainerByName (resource);
+  type_t type = getVariableType (variable, NULL, container->type);
+  new_pajeAddVariable(now, container, type, value);
+  new_pajeSubVariable(now + delta, container, type, value);
 }
 
 static void __TRACE_A_end(smx_action_t action)
@@ -104,9 +109,6 @@ static void __TRACE_B_alloc(void)
 
 static void __TRACE_B_release(void)
 {
-  if (!IS_TRACING_PLATFORM)
-    return;
-
   char *key, *time;
   xbt_dict_cursor_t cursor = NULL;
   xbt_dict_foreach(method_b_dict, cursor, key, time) {
@@ -118,7 +120,9 @@ static void __TRACE_B_release(void)
       char key_value[INSTR_DEFAULT_STR_SIZE];
       snprintf (key_value, INSTR_DEFAULT_STR_SIZE, "%s %s value", resource, variable);
       char *value = xbt_dict_get_or_null (method_b_dict, key_value);
-      pajeSubVariable(atof(time), variable, resource, value);
+      container_t container = getContainerByName (resource);
+      type_t type = getVariableType (variable, NULL, container->type);
+      new_pajeSubVariable(atof(time), container, type, atof(value));
     }
   }
   xbt_dict_free(&method_b_dict);
@@ -132,9 +136,6 @@ static void __TRACE_B_event(smx_action_t action, double now, double delta,
                             const char *variable, const char *resource,
                             double value)
 {
-  if (!IS_TRACING_PLATFORM)
-    return;
-
   char key_time[INSTR_DEFAULT_STR_SIZE];
   char key_value[INSTR_DEFAULT_STR_SIZE];
   char nowstr[INSTR_DEFAULT_STR_SIZE];
@@ -151,7 +152,9 @@ static void __TRACE_B_event(smx_action_t action, double now, double delta,
   char *lastvaluestr = xbt_dict_get_or_null(method_b_dict, key_value);
   if (lasttimestr == NULL){
     __TRACE_surf_check_variable_set_to_zero(now, variable, resource);
-    pajeAddVariable(now, variable, resource, valuestr);
+    container_t container = getContainerByName (resource);
+    type_t type = getVariableType (variable, NULL, container->type);
+    new_pajeAddVariable(now, container, type, value);
     xbt_dict_set(method_b_dict, key_time, xbt_strdup(nowdeltastr), xbt_free);
     xbt_dict_set(method_b_dict, key_value, xbt_strdup(valuestr), xbt_free);
   }else{
@@ -164,13 +167,17 @@ static void __TRACE_B_event(smx_action_t action, double now, double delta,
         //perfect, just go on
       }else{
         //time changed, have to update
-        pajeSubVariable(lasttime, variable, resource, lastvaluestr);
-        pajeAddVariable(now, variable, resource, valuestr);
+        container_t container = getContainerByName (resource);
+        type_t type = getVariableType (variable, NULL, container->type);
+        new_pajeSubVariable(lasttime, container, type, lastvalue);
+        new_pajeAddVariable(now, container, type, value);
       }
     }else{
       //value changed, have to update
-      pajeSubVariable(lasttime, variable, resource, lastvaluestr);
-      pajeAddVariable(now, variable, resource, valuestr);
+      container_t container = getContainerByName (resource);
+      type_t type = getVariableType (variable, NULL, container->type);
+      new_pajeSubVariable(lasttime, container, type, lastvalue);
+      new_pajeAddVariable(now, container, type, value);
     }
     xbt_dict_set(method_b_dict, key_time, xbt_strdup(nowdeltastr), xbt_free);
     xbt_dict_set(method_b_dict, key_value, xbt_strdup(valuestr), xbt_free);
@@ -259,12 +266,12 @@ static void __TRACE_C_end(smx_action_t action)
       continue;
     __TRACE_surf_check_variable_set_to_zero(start_time, variable,
                                             resource);
-    char value_str[100];
     if (end_time - start_time != 0) {
-      snprintf(value_str, 100, "%f",
-               atof(action_dict_value) / (end_time - start_time));
-      pajeAddVariable(start_time, variable, resource, value_str);
-      pajeSubVariable(end_time, variable, resource, value_str);
+      container_t container = getContainerByName (resource);
+      type_t type = getVariableType (variable, NULL, container->type);
+      double val = atof(action_dict_value) / (end_time - start_time);
+      new_pajeSubVariable(start_time, container, type, val);
+      new_pajeAddVariable(end_time, container, type, val);
     }
   }
   xbt_dict_remove(method_c_dict, key);
@@ -274,7 +281,7 @@ static void __TRACE_C_end(smx_action_t action)
 /*
  * TRACE_surf_link_set_utilization: entry point from SimGrid
  */
-void TRACE_surf_link_set_utilization(void *link, smx_action_t smx_action,
+void TRACE_surf_link_set_utilization(const char *resource, smx_action_t smx_action,
                                      surf_action_t surf_action,
                                      double value, double now,
                                      double delta)
@@ -284,34 +291,38 @@ void TRACE_surf_link_set_utilization(void *link, smx_action_t smx_action,
   if (!value)
     return;
   //only trace link utilization if link is known by tracing mechanism
-  if (!TRACE_surf_link_is_traced(link))
+  if (!knownContainerWithName(resource))
     return;
   if (!value)
     return;
 
-  char resource[100];
-  snprintf(resource, 100, "%p", link);
-
   //trace uncategorized link utilization
   if (TRACE_uncategorized()){
-    TRACE_surf_resource_utilization_event(smx_action, now, delta,
-                                        "bandwidth_used", resource, value);
+    XBT_DEBUG("UNCAT LINK [%f - %f] %s bandwidth_used %f", now, now+delta, resource, value);
+    container_t container = getContainerByName (resource);
+    type_t type = getVariableType("bandwidth_used", NULL, container->type);
+    TRACE_surf_resource_utilization_event(smx_action, now, delta, type->name, container->name, value);
   }
 
   //trace categorized utilization
-  if (!IS_TRACED(surf_action))
-    return;
-  char type[100];
-  snprintf(type, 100, "b%s", surf_action->category);
-  TRACE_surf_resource_utilization_event(smx_action, now, delta, type,
-                                        resource, value);
+  if (TRACE_categorized()){
+    if (!surf_action->category)
+      return;
+    //variable of this category starts by 'b', because we have a link here
+    char category_type[INSTR_DEFAULT_STR_SIZE];
+    snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "b%s", surf_action->category);
+    XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
+    container_t container = getContainerByName (resource);
+    type_t type = getVariableType(category_type, NULL, container->type);
+    TRACE_surf_resource_utilization_event(smx_action, now, delta, type->name, container->name, value);
+  }
   return;
 }
 
 /*
  * TRACE_surf_host_set_utilization: entry point from SimGrid
  */
-void TRACE_surf_host_set_utilization(const char *name,
+void TRACE_surf_host_set_utilization(const char *resource,
                                      smx_action_t smx_action,
                                      surf_action_t surf_action,
                                      double value, double now,
@@ -319,22 +330,32 @@ void TRACE_surf_host_set_utilization(const char *name,
 {
   if (!TRACE_is_active())
     return;
+  //only trace host utilization if host is known by tracing mechanism
+  if (!knownContainerWithName(resource))
+    return;
   if (!value)
     return;
 
   //trace uncategorized host utilization
   if (TRACE_uncategorized()){
-    TRACE_surf_resource_utilization_event(smx_action, now, delta,
-                                        "power_used", name, value);
+    XBT_DEBUG("UNCAT HOST [%f - %f] %s power_used %f", now, now+delta, resource, value);
+    container_t container = getContainerByName (resource);
+    type_t type = getVariableType("power_used", NULL, container->type);
+    TRACE_surf_resource_utilization_event(smx_action, now, delta, type->name, container->name, value);
   }
 
   //trace categorized utilization
-  if (!IS_TRACED(surf_action))
-    return;
-  char type[100];
-  snprintf(type, 100, "p%s", surf_action->category);
-  TRACE_surf_resource_utilization_event(smx_action, now, delta, type, name,
-                                        value);
+  if (TRACE_categorized()){
+    if (!surf_action->category)
+      return;
+    //variable of this category starts by 'p', because we have a host here
+    char category_type[INSTR_DEFAULT_STR_SIZE];
+    snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "p%s", surf_action->category);
+    XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
+    container_t container = getContainerByName (resource);
+    type_t type = getVariableType(category_type, NULL, container->type);
+    TRACE_surf_resource_utilization_event(smx_action, now, delta, type->name, container->name, value);
+  }
   return;
 }
 
@@ -345,6 +366,7 @@ void TRACE_surf_resource_utilization_start(smx_action_t action)
 {
   if (!TRACE_is_active())
     return;
+  XBT_DEBUG("START %p", action);
   TRACE_method_start(action);
 }
 
@@ -356,6 +378,7 @@ void TRACE_surf_resource_utilization_event(smx_action_t action, double now,
 {
   if (!TRACE_is_active())
     return;
+  XBT_DEBUG("EVENT %p [%f - %f] %s %s %f", action, now, now+delta, resource, variable, value);
   TRACE_method_event(action, now, delta, variable, resource, value);
 }
 
@@ -364,6 +387,7 @@ void TRACE_surf_resource_utilization_end(smx_action_t action)
   if (!TRACE_is_active())
     return;
   TRACE_method_end(action);
+  XBT_DEBUG("END %p", action);
 }
 
 void TRACE_surf_resource_utilization_release()