X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d234466c6c9a92df8e2f787dabecd0791c51f3af..17e2ecb241a23400dab096057ed1fe5cc08cffb1:/src/instr/instr_paje.c diff --git a/src/instr/instr_paje.c b/src/instr/instr_paje.c index e6edfda1f3..dee02034c3 100644 --- a/src/instr/instr_paje.c +++ b/src/instr/instr_paje.c @@ -10,148 +10,45 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje, instr, "Paje tracing event system (data structures)"); -static type_t rootType = NULL; /* the root type */ static container_t rootContainer = NULL; /* the root container */ static xbt_dict_t allContainers = NULL; /* all created containers indexed by name */ 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) +long long int instr_new_paje_id (void) { - allContainers = xbt_dict_new (); - trivaNodeTypes = xbt_dict_new (); - trivaEdgeTypes = xbt_dict_new (); - 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, 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(); - char str_id[INSTR_DEFAULT_STR_SIZE]; - snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", id); - ret->id = xbt_strdup (str_id); - - if (father != NULL){ - xbt_dict_set (father->children, key, ret, NULL); - } - return ret; + static long long int type_id = 0; + return type_id++; } -type_t getRootType () +void PJ_container_alloc (void) { - return rootType; + allContainers = xbt_dict_new_homogeneous(NULL); + trivaNodeTypes = xbt_dict_new_homogeneous(xbt_free); + trivaEdgeTypes = xbt_dict_new_homogeneous(xbt_free); } -type_t getContainerType (const char *typename, type_t father) +void PJ_container_release (void) { - type_t ret; - if (father == NULL){ - 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, NULL, TYPE_CONTAINER, father); - new_pajeDefineContainerType (ret); - } - } - return ret; + xbt_dict_free (&allContainers); + xbt_dict_free (&trivaNodeTypes); + xbt_dict_free (&trivaEdgeTypes); } -type_t getEventType (const char *typename, const char *color, type_t father) +void PJ_container_set_root (container_t root) { - type_t ret = xbt_dict_get_or_null (father->children, typename); - if (ret == NULL){ - 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); - } - //INFO4("EventType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id); - new_pajeDefineEventType(ret); - } - return ret; -} - -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){ - 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); - } - //INFO4("VariableType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id); - new_pajeDefineVariableType (ret); - } - return ret; -} - -char *getVariableTypeIdByName (const char *name, type_t father) -{ - xbt_dict_cursor_t cursor = NULL; - type_t type; - char *key; - xbt_dict_foreach(father->children, cursor, key, type) { - if (strcmp (name, type->name) == 0) return type->id; - } - return NULL; -} - -type_t getLinkType (const char *typename, type_t father, type_t source, type_t dest) -{ - char key[INSTR_DEFAULT_STR_SIZE]; - 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, NULL, 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); - new_pajeDefineLinkType(ret, source, dest); - } - return ret; + rootContainer = root; } -type_t getStateType (const char *typename, type_t father) +container_t PJ_container_new (const char *name, e_container_types kind, container_t father) { - type_t ret = xbt_dict_get_or_null (father->children, typename); - if (ret == NULL){ - ret = newType (typename, typename, NULL, TYPE_STATE, father); - //INFO4("StateType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id); - new_pajeDefineStateType(ret); + if (name == NULL){ + THROWF (tracing_error, 0, "can't create a container with a NULL name"); } - 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 @@ -160,6 +57,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; + XBT_DEBUG("new container %s, child of %s", name, father->name); }else{ new->level = 0; } @@ -170,142 +68,147 @@ container_t newContainer (const char *name, e_container_types kind, container_t char as_typename[INSTR_DEFAULT_STR_SIZE]; snprintf (as_typename, INSTR_DEFAULT_STR_SIZE, "L%d", new->level); if (new->father){ - new->type = getContainerType (as_typename, new->father->type); + new->type = PJ_type_get (as_typename, new->father->type); + if (new->type == NULL){ + new->type = PJ_type_container_new (as_typename, new->father->type); + } }else{ - new->type = getContainerType ("0", NULL); + new->type = PJ_type_container_new ("0", NULL); } }else{ //otherwise, the name is its kind + char typename[INSTR_DEFAULT_STR_SIZE]; switch (new->kind){ - case INSTR_HOST: new->type = getContainerType ("HOST", new->father->type); break; - case INSTR_LINK: new->type = getContainerType ("LINK", new->father->type); break; - case INSTR_ROUTER: new->type = getContainerType ("ROUTER", new->father->type); break; - case INSTR_SMPI: new->type = getContainerType ("MPI", new->father->type); break; - case INSTR_MSG_PROCESS: new->type = getContainerType ("MSG_PROCESS", new->father->type); break; - case INSTR_MSG_TASK: new->type = getContainerType ("MSG_TASK", new->father->type); break; - default: xbt_die ("Congratulations, you have found a bug on newContainer function of instr_routing.c"); break; + case INSTR_HOST: snprintf (typename, INSTR_DEFAULT_STR_SIZE, "HOST"); break; + case INSTR_LINK: snprintf (typename, INSTR_DEFAULT_STR_SIZE, "LINK"); break; + case INSTR_ROUTER: snprintf (typename, INSTR_DEFAULT_STR_SIZE, "ROUTER"); break; + case INSTR_SMPI: snprintf (typename, INSTR_DEFAULT_STR_SIZE, "MPI"); break; + case INSTR_MSG_PROCESS: snprintf (typename, INSTR_DEFAULT_STR_SIZE, "MSG_PROCESS"); break; + case INSTR_MSG_TASK: snprintf (typename, INSTR_DEFAULT_STR_SIZE, "MSG_TASK"); break; + default: THROWF (tracing_error, 0, "new container kind is unknown."); break; + } + type_t type = PJ_type_get (typename, new->father->type); + if (type == NULL){ + new->type = PJ_type_container_new (typename, new->father->type); + }else{ + new->type = type; } } - 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); } - //register hosts, routers, links containers - if (new->kind == INSTR_HOST || new->kind == INSTR_LINK || new->kind == INSTR_ROUTER) { - xbt_dict_set (allContainers, new->name, new, NULL); + //register all kinds by name + if (xbt_dict_get_or_null(allContainers, new->name) != NULL){ + THROWF(tracing_error, 1, "container %s already present in allContainers data structure", new->name); + } + 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); + //register NODE types for triva configuration + if (new->kind == INSTR_HOST || new->kind == INSTR_LINK || new->kind == INSTR_ROUTER) { + xbt_dict_set (trivaNodeTypes, new->type->name, xbt_strdup("1"), NULL); } return new; } -static container_t recursiveGetContainer (const char *name, container_t root) +container_t PJ_container_get (const char *name) { - if (strcmp (root->name, name) == 0) return root; - - xbt_dict_cursor_t cursor = NULL; - container_t child; - char *child_name; - xbt_dict_foreach(root->children, cursor, child_name, child) { - container_t ret = recursiveGetContainer(name, child); - if (ret) return ret; + container_t ret = PJ_container_get_or_null (name); + if (ret == NULL){ + THROWF(tracing_error, 1, "container with name %s not found", name); } - return NULL; -} - -container_t getContainer (const char *name) -{ - return recursiveGetContainer(name, rootContainer); -} - -container_t getContainerByName (const char *name) -{ - return (container_t)xbt_dict_get (allContainers, name); + return ret; } -char *getContainerIdByName (const char *name) +container_t PJ_container_get_or_null (const char *name) { - return getContainerByName(name)->id; + if (name == NULL) return NULL; + container_t ret = xbt_dict_get_or_null (allContainers, name); + if (ret == NULL){ + return NULL; + } + return ret; } -container_t getRootContainer () +container_t PJ_container_get_root () { return rootContainer; } -static type_t recursiveGetType (const char *name, type_t root) +void PJ_container_remove_from_parent (container_t child) { - if (strcmp (root->name, name) == 0) return root; - - xbt_dict_cursor_t cursor = NULL; - type_t child; - char *child_name; - xbt_dict_foreach(root->children, cursor, child_name, child) { - type_t ret = recursiveGetType(name, child); - if (ret) return ret; + if (child == NULL){ + THROWF (tracing_error, 0, "can't remove from parent with a NULL child"); } - return NULL; -} -type_t getType (const char *name) -{ - return recursiveGetType (name, rootType); + container_t parent = child->father; + if (parent){ + XBT_DEBUG("removeChildContainer (%s) FromContainer (%s) ", + child->name, + parent->name); + xbt_dict_remove (parent->children, child->name); + } } -void destroyContainer (container_t container) +void PJ_container_free (container_t container) { - //remove me from my father - if (container->father){ - xbt_dict_remove(container->father->children, container->name); + if (container == NULL){ + THROWF (tracing_error, 0, "trying to free a NULL 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(1); //trace my destruction - new_pajeDestroyContainer(container); + 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) { + if (container == NULL){ + THROWF (tracing_error, 0, "trying to recursively destroy a NULL container"); + } + XBT_DEBUG("recursiveDestroyContainer %s", container->name); xbt_dict_cursor_t cursor = NULL; container_t child; char *child_name; xbt_dict_foreach(container->children, cursor, child_name, child) { recursiveDestroyContainer (child); } - destroyContainer (container); + PJ_container_free (container); } -static void recursiveDestroyType (type_t type) +void PJ_container_free_all () { - xbt_dict_cursor_t cursor = NULL; - type_t child; - char *child_name; - xbt_dict_foreach(type->children, cursor, child_name, child) { - recursiveDestroyType (child); + container_t root = PJ_container_get_root(); + if (root == NULL){ + THROWF (tracing_error, 0, "trying to free all containers, but root is NULL"); } - xbt_free (type->name); - xbt_free (type->id); - xbt_free (type->children); - xbt_free (type); - type = NULL; -} - -void destroyAllContainers () -{ - if (getRootContainer()) recursiveDestroyContainer (getRootContainer()); - if (getRootType()) recursiveDestroyType (getRootType()); + recursiveDestroyContainer (root); rootContainer = NULL; - rootType = NULL; -} + //checks + if (xbt_dict_length(allContainers) != 0){ + THROWF(tracing_error, 0, "some containers still present even after destroying all of them"); + } +} #endif /* HAVE_TRACING */