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_dynar_t allLinkTypes = NULL; /* all link types defined */
-xbt_dynar_t allHostTypes = NULL; /* all host types defined */
+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 ();
- allLinkTypes = xbt_dynar_new (sizeof(s_type_t), NULL);
- allHostTypes = xbt_dynar_new (sizeof(s_type_t), NULL);
- 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)
-{
- 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 ();
-
- 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;
-}
-
-type_t getRootType ()
-{
- return rootType;
-}
-
-type_t getContainerType (const char *typename, type_t father)
-{
- type_t ret;
- if (father == NULL){
- ret = newType (typename, typename, TYPE_CONTAINER, father);
- if (father) pajeDefineContainerType(ret->id, ret->father->id, ret->name);
- 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);
- pajeDefineContainerType(ret->id, ret->father->id, ret->name);
- }
- }
- return ret;
+ static long long int type_id = 0;
+ return type_id++;
}
-type_t getEventType (const char *typename, const char *color, type_t father)
+void PJ_container_alloc (void)
{
- type_t ret = xbt_dict_get_or_null (father->children, typename);
- if (ret == NULL){
- ret = newType (typename, typename, TYPE_EVENT, father);
- //INFO4("EventType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
- if (color){
- pajeDefineEventTypeWithColor (ret->id, ret->father->id, ret->name, color);
- }else{
- pajeDefineEventType(ret->id, ret->father->id, ret->name);
- }
- }
- return ret;
+ allContainers = xbt_dict_new_homogeneous(NULL);
+ trivaNodeTypes = xbt_dict_new_homogeneous(xbt_free);
+ trivaEdgeTypes = xbt_dict_new_homogeneous(xbt_free);
}
-type_t getVariableType (const char *typename, const char *color, type_t father)
+void PJ_container_release (void)
{
- type_t ret = xbt_dict_get_or_null (father->children, typename);
- if (ret == NULL){
- ret = newType (typename, typename, TYPE_VARIABLE, father);
- //INFO4("VariableType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
- if (color){
- pajeDefineVariableTypeWithColor(ret->id, ret->father->id, ret->name, color);
- }else{
- pajeDefineVariableType(ret->id, ret->father->id, ret->name);
- }
- }
- return ret;
+ xbt_dict_free (&allContainers);
+ xbt_dict_free (&trivaNodeTypes);
+ xbt_dict_free (&trivaEdgeTypes);
}
-type_t getLinkType (const char *typename, type_t father, type_t source, type_t dest)
+void PJ_container_set_root (container_t root)
{
- //FIXME should check using source and dest here and not by the typename (g5k example)
- 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, 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);
- pajeDefineLinkType(ret->id, ret->father->id, source->id, dest->id, ret->name);
- }
- 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, TYPE_STATE, father);
- //INFO4("StateType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
- pajeDefineStateType(ret->id, ret->father->id, ret->name);
+ 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
// 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;
}
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);
- pajeCreateContainer (SIMIX_get_clock(), new->id, new->type->id, new->father->id, new->name);
- }
-
- //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);
+ new_pajeCreateContainer (new);
}
- //register the host container types
- if (new->kind == INSTR_HOST){
- xbt_dynar_push_as (allHostTypes, type_t, new->type);
+ //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 the link container types
- if (new->kind == INSTR_LINK){
- xbt_dynar_push_as(allLinkTypes, type_t, new->type);
+ //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);
+ return ret;
}
-container_t getContainerByName (const char *name)
+container_t PJ_container_get_or_null (const char *name)
{
- return (container_t)xbt_dict_get (allContainers, name);
+ 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
- pajeDestroyContainer(SIMIX_get_clock(), container->type->id, container->id);
+ 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);
+ }
+ PJ_container_free (container);
+}
+
+void PJ_container_free_all ()
+{
+ container_t root = PJ_container_get_root();
+ if (root == NULL){
+ THROWF (tracing_error, 0, "trying to free all containers, but root is NULL");
+ }
+ recursiveDestroyContainer (root);
+ rootContainer = 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 */