Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] return NULL instead of launching exception if a container does not exists
[simgrid.git] / src / instr / instr_paje.c
index 39f1510..7bc4bbf 100644 (file)
@@ -24,27 +24,23 @@ void instr_paje_init (container_t root)
   rootContainer = root;
 }
 
-static long long int newTypeId ()
-{
-  static long long int counter = 0;
-  return counter++;
-}
-
-static type_t newType (const char *typename, const char *key, e_entity_types kind, type_t father)
+static type_t newType (const char *typename, const char *key, const char *color, e_entity_types kind, type_t father)
 {
   type_t ret = xbt_new0(s_type_t, 1);
   ret->name = xbt_strdup (typename);
   ret->father = father;
   ret->kind = kind;
   ret->children = xbt_dict_new ();
+  ret->color = xbt_strdup (color);
 
-  long long int id = newTypeId();
+  static long long int type_id = 0;
   char str_id[INSTR_DEFAULT_STR_SIZE];
-  snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", id);
+  snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", type_id++);
   ret->id = xbt_strdup (str_id);
 
   if (father != NULL){
     xbt_dict_set (father->children, key, ret, NULL);
+    DEBUG2("new type %s, child of %s", typename, father->name);
   }
   return ret;
 }
@@ -58,14 +54,14 @@ type_t getContainerType (const char *typename, type_t father)
 {
   type_t ret;
   if (father == NULL){
-    ret = newType (typename, typename, TYPE_CONTAINER, father);
+    ret = newType (typename, typename, NULL, TYPE_CONTAINER, father);
     if (father) new_pajeDefineContainerType (ret);
     rootType = ret;
   }else{
     //check if my father type already has my typename
     ret = (type_t)xbt_dict_get_or_null (father->children, typename);
     if (ret == NULL){
-      ret = newType (typename, typename, TYPE_CONTAINER, father);
+      ret = newType (typename, typename, NULL, TYPE_CONTAINER, father);
       new_pajeDefineContainerType (ret);
     }
   }
@@ -76,9 +72,13 @@ type_t getEventType (const char *typename, const char *color, type_t father)
 {
   type_t ret = xbt_dict_get_or_null (father->children, typename);
   if (ret == NULL){
-    ret = newType (typename, typename, TYPE_EVENT, father);
-    ret->color = xbt_strdup (color);
-    //INFO4("EventType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
+    char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
+    if (!color){
+      ret = newType (typename, typename, white, TYPE_EVENT, father);
+    }else{
+      ret = newType (typename, typename, color, TYPE_EVENT, father);
+    }
+    DEBUG4("EventType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
     new_pajeDefineEventType(ret);
   }
   return ret;
@@ -88,9 +88,13 @@ type_t getVariableType (const char *typename, const char *color, type_t father)
 {
   type_t ret = xbt_dict_get_or_null (father->children, typename);
   if (ret == NULL){
-    ret = newType (typename, typename, TYPE_VARIABLE, father);
-    ret->color = xbt_strdup (color);
-    //INFO4("VariableType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
+    char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
+    if (!color){
+      ret = newType (typename, typename, white, TYPE_VARIABLE, father);
+    }else{
+      ret = newType (typename, typename, color, TYPE_VARIABLE, father);
+    }
+    DEBUG4("VariableType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
     new_pajeDefineVariableType (ret);
   }
   return ret;
@@ -113,8 +117,8 @@ type_t getLinkType (const char *typename, type_t father, type_t source, type_t d
   snprintf (key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", typename, source->id, dest->id);
   type_t ret = xbt_dict_get_or_null (father->children, key);
   if (ret == NULL){
-    ret = newType (typename, key, TYPE_LINK, father);
-    //INFO8("LinkType %s(%s), child of %s(%s)  %s(%s)->%s(%s)", ret->name, ret->id, father->name, father->id, source->name, source->id, dest->name, dest->id);
+    ret = newType (typename, key, NULL, TYPE_LINK, father);
+    DEBUG8("LinkType %s(%s), child of %s(%s)  %s(%s)->%s(%s)", ret->name, ret->id, father->name, father->id, source->name, source->id, dest->name, dest->id);
     new_pajeDefineLinkType(ret, source, dest);
   }
   return ret;
@@ -124,25 +128,18 @@ type_t getStateType (const char *typename, type_t father)
 {
   type_t ret = xbt_dict_get_or_null (father->children, typename);
   if (ret == NULL){
-    ret = newType (typename, typename, TYPE_STATE, father);
-    //INFO4("StateType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
+    ret = newType (typename, typename, NULL, TYPE_STATE, father);
+    DEBUG4("StateType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
     new_pajeDefineStateType(ret);
   }
   return ret;
 }
 
-
-static long long int newContainedId ()
-{
-  static long long counter = 0;
-  return counter++;
-}
-
 container_t newContainer (const char *name, e_container_types kind, container_t father)
 {
-  long long int counter = newContainedId();
+  static long long int container_id = 0;
   char id_str[INSTR_DEFAULT_STR_SIZE];
-  snprintf (id_str, INSTR_DEFAULT_STR_SIZE, "%lld", counter);
+  snprintf (id_str, INSTR_DEFAULT_STR_SIZE, "%lld", container_id++);
 
   container_t new = xbt_new0(s_container_t, 1);
   new->name = xbt_strdup (name); // name of the container
@@ -151,6 +148,7 @@ container_t newContainer (const char *name, e_container_types kind, container_t
   // level depends on level of father
   if (new->father){
     new->level = new->father->level+1;
+    DEBUG2("new container %s, child of %s", name, father->name);
   }else{
     new->level = 0;
   }
@@ -214,7 +212,7 @@ container_t getContainer (const char *name)
 
 container_t getContainerByName (const char *name)
 {
-  return (container_t)xbt_dict_get (allContainers, name);
+  return (container_t)xbt_dict_get_or_null (allContainers, name);
 }
 
 char *getContainerIdByName (const char *name)
@@ -253,6 +251,13 @@ void destroyContainer (container_t container)
     xbt_dict_remove(container->father->children, container->name);
   }
 
+  DEBUG1("destroy container %s", container->name);
+
+  //obligation to dump previous events because they might
+  //reference the container that is about to be destroyed
+  TRACE_last_timestamp_to_dump = surf_get_clock();
+  TRACE_paje_dump_buffer(1);
+
   //trace my destruction
   new_pajeDestroyContainer(container);