X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2d208a737e63d5fbbd8a7fc8a3d94f867610a85b..5972326eb1013c4071d7af0c8959d6fbf793ef78:/src/instr/instr_paje.c diff --git a/src/instr/instr_paje.c b/src/instr/instr_paje.c index 678d1d0f0d..86eeadf1c6 100644 --- a/src/instr/instr_paje.c +++ b/src/instr/instr_paje.c @@ -16,18 +16,71 @@ static xbt_dict_t allContainers = NULL; /* all created containers indexed by xbt_dict_t trivaNodeTypes = NULL; /* all link types defined */ xbt_dict_t trivaEdgeTypes = NULL; /* all host types defined */ -void instr_paje_init (container_t root) +void instr_paje_init (void) +{ + allContainers = xbt_dict_new_homogeneous(NULL); + trivaNodeTypes = xbt_dict_new_homogeneous(xbt_free); + trivaEdgeTypes = xbt_dict_new_homogeneous(xbt_free); +} + +void instr_paje_set_root (container_t root) { - allContainers = xbt_dict_new (); - trivaNodeTypes = xbt_dict_new (); - trivaEdgeTypes = xbt_dict_new (); rootContainer = root; } -static long long int newTypeId () +void instr_paje_free (void) +{ + xbt_dict_free (&allContainers); + xbt_dict_free (&trivaNodeTypes); + xbt_dict_free (&trivaEdgeTypes); +} + +static long long int new_type_id (void) +{ + static long long int type_id = 0; + return type_id++; +} + +static void destroyValue (void *value) { - static long long int counter = 0; - return counter++; + xbt_free(((val_t)value)->name); + xbt_free(((val_t)value)->color); + xbt_free(((val_t)value)->id); + xbt_free(value); +} + +static val_t newValue (const char *valuename, const char *color, type_t father) +{ + val_t ret = xbt_new0(s_val_t, 1); + ret->name = xbt_strdup (valuename); + ret->father = father; + ret->color = xbt_strdup (color); + + char str_id[INSTR_DEFAULT_STR_SIZE]; + snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", new_type_id()); + ret->id = xbt_strdup (str_id); + + xbt_dict_set (father->values, valuename, ret, NULL); + XBT_DEBUG("new value %s, child of %s", ret->name, ret->father->name); + return ret; +} + +val_t getValue (const char *valuename, const char *color, type_t father) +{ + if (father->kind == TYPE_VARIABLE) return NULL; //Variables can't have different values + + val_t ret = (val_t)xbt_dict_get_or_null (father->values, valuename); + if (ret == NULL){ + ret = newValue (valuename, color, father); + XBT_DEBUG("EntityValue %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id); + new_pajeDefineEntityValue(ret); + } + return ret; +} + +val_t getValueByName (const char *valuename, type_t father) +{ + return getValue (valuename, NULL, father); } static type_t newType (const char *typename, const char *key, const char *color, e_entity_types kind, type_t father) @@ -36,17 +89,17 @@ static type_t newType (const char *typename, const char *key, const char *color, ret->name = xbt_strdup (typename); ret->father = father; ret->kind = kind; - ret->children = xbt_dict_new (); + ret->children = xbt_dict_new_homogeneous(NULL); + ret->values = xbt_dict_new_homogeneous(NULL); ret->color = xbt_strdup (color); - long long int id = newTypeId(); char str_id[INSTR_DEFAULT_STR_SIZE]; - snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", id); + snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", new_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); + XBT_DEBUG("new type %s, child of %s", typename, father->name); } return ret; } @@ -84,7 +137,7 @@ type_t getEventType (const char *typename, const char *color, type_t 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); + XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id); new_pajeDefineEventType(ret); } return ret; @@ -100,7 +153,7 @@ type_t getVariableType (const char *typename, const char *color, type_t 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); + XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id); new_pajeDefineVariableType (ret); } return ret; @@ -124,7 +177,7 @@ type_t getLinkType (const char *typename, type_t father, type_t source, type_t d type_t ret = xbt_dict_get_or_null (father->children, key); if (ret == NULL){ 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); + XBT_DEBUG("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; @@ -135,24 +188,17 @@ 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, NULL, TYPE_STATE, father); - DEBUG4("StateType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id); + XBT_DEBUG("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 @@ -161,7 +207,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); + XBT_DEBUG("new container %s, child of %s", name, father->name); }else{ new->level = 0; } @@ -188,7 +234,7 @@ container_t newContainer (const char *name, e_container_types kind, container_t default: xbt_die ("Congratulations, you have found a bug on newContainer function of instr_routing.c"); break; } } - new->children = xbt_dict_new(); + new->children = xbt_dict_new_homogeneous(NULL); if (new->father){ xbt_dict_set(new->father->children, new->name, new, NULL); new_pajeCreateContainer (new); @@ -199,13 +245,14 @@ container_t newContainer (const char *name, e_container_types kind, container_t xbt_dict_set (allContainers, new->name, new, NULL); //register NODE types for triva configuration - xbt_dict_set (trivaNodeTypes, new->type->name, xbt_strdup("1"), xbt_free); + xbt_dict_set (trivaNodeTypes, new->type->name, xbt_strdup("1"), NULL); } return new; } static container_t recursiveGetContainer (const char *name, container_t root) { + if (name == NULL || root == NULL) return NULL; if (strcmp (root->name, name) == 0) return root; xbt_dict_cursor_t cursor = NULL; @@ -220,9 +267,19 @@ static container_t recursiveGetContainer (const char *name, container_t root) container_t getContainer (const char *name) { + if (name == NULL) return NULL; return recursiveGetContainer(name, rootContainer); } +int knownContainerWithName (const char *name) +{ + if (xbt_dict_get_or_null (allContainers, name)){ + return 1; + }else{ + return 0; + } +} + container_t getContainerByName (const char *name) { return (container_t)xbt_dict_get (allContainers, name); @@ -245,45 +302,65 @@ static type_t recursiveGetType (const char *name, type_t root) xbt_dict_cursor_t cursor = NULL; type_t child; char *child_name; + type_t ret = NULL; xbt_dict_foreach(root->children, cursor, child_name, child) { - type_t ret = recursiveGetType(name, child); - if (ret) return ret; + type_t found = recursiveGetType(name, child); + if (found){ + if (ret == NULL){ + ret = found; + }else{ + XBT_CRITICAL("[tracing] found two types with the same name"); + } + } } - return NULL; + return ret; } -type_t getType (const char *name) +type_t getType (const char *name, type_t father) { - return recursiveGetType (name, rootType); + return recursiveGetType (name, father); } -void destroyContainer (container_t container) +void removeContainerFromParent (container_t child) { - //remove me from my father - if (container->father){ - xbt_dict_remove(container->father->children, container->name); + container_t parent = child->father; + if (parent){ + XBT_DEBUG("removeChildContainer (%s) FromContainer (%s) ", + child->name, + parent->name); + xbt_dict_remove (parent->children, child->name); } +} - DEBUG1("destroy container %s", container->name); - - //trace my destruction - new_pajeDestroyContainer(container); +void destroyContainer (container_t container) +{ + XBT_DEBUG("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(); + TRACE_paje_dump_buffer(1); + + //trace my destruction + if (!TRACE_disable_destroy()){ + //do not trace the container destruction if user requests + new_pajeDestroyContainer(container); + } + + //remove it from allContainers data structure + xbt_dict_remove (allContainers, container->name); //free xbt_free (container->name); xbt_free (container->id); - xbt_free (container->children); + xbt_dict_free (&container->children); xbt_free (container); container = NULL; } static void recursiveDestroyContainer (container_t container) { + XBT_DEBUG("recursiveDestroyContainer %s", container->name); xbt_dict_cursor_t cursor = NULL; container_t child; char *child_name; @@ -295,6 +372,7 @@ static void recursiveDestroyContainer (container_t container) static void recursiveDestroyType (type_t type) { + XBT_DEBUG("recursiveDestroyType %s", type->name); xbt_dict_cursor_t cursor = NULL; type_t child; char *child_name; @@ -303,7 +381,14 @@ static void recursiveDestroyType (type_t type) } xbt_free (type->name); xbt_free (type->id); - xbt_free (type->children); + xbt_free (type->color); + xbt_dict_free (&type->children); + val_t value; + char *value_name; + xbt_dict_foreach(type->values, cursor, value_name, value) { + destroyValue (value); + } + xbt_dict_free (&type->values); xbt_free (type); type = NULL; }