X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3c3db4bc680e606d91d4006265d7bcf9174df050..d234466c6c9a92df8e2f787dabecd0791c51f3af:/src/instr/instr_paje.c diff --git a/src/instr/instr_paje.c b/src/instr/instr_paje.c index 3812aa7e53..e6edfda1f3 100644 --- a/src/instr/instr_paje.c +++ b/src/instr/instr_paje.c @@ -8,363 +8,304 @@ #ifdef HAVE_TRACING -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje, instr, "Paje tracing event system"); - -static FILE *tracing_file = NULL; - -static int pajeDefineContainerTypeId = 0; -static int pajeDefineStateTypeId = 1; -static int pajeDefineEntityValueId = 2; -static int pajeDefineEventTypeId = 3; -static int pajeDefineLinkTypeId = 4; -static int pajeCreateContainerId = 5; -static int pajeSetStateId = 6; -#define UNUSED007 7 -static int pajePopStateId = 8; -static int pajeDestroyContainerId = 9; -#define UNUSED006 10 -#define UNUSED003 11 -static int pajeStartLinkId = 12; -static int pajeEndLinkId = 13; -#define UNUSED000 14 -#define UNUSED004 15 -#define UNUSED008 16 -#define UNUSED009 17 -#define UNUSED005 18 -static int pajePushStateId = 19; -#define UNUSED001 20 -static int pajeDefineVariableTypeWithColorId = 21; -static int pajeSetVariableId = 22; -static int pajeAddVariableId = 23; -static int pajeSubVariableId = 24; -static int pajeDefineVariableTypeId = 25; -static int pajeStartLinkWithVolumeId = 26; -static int pajeNewEventId = 27; - -#define TRACE_LINE_SIZE 1000 - -void TRACE_paje_start(void) -{ - char *filename = TRACE_get_filename(); - tracing_file = fopen(filename, "w"); - xbt_assert1 (tracing_file != NULL, "Tracefile %s could not be opened for writing.", filename); - - DEBUG1("Filename %s is open for writing", filename); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje, instr, "Paje tracing event system (data structures)"); - /* output header */ - TRACE_paje_create_header(); -} +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 TRACE_paje_end(void) +void instr_paje_init (container_t root) { - fclose(tracing_file); - char *filename = TRACE_get_filename(); - DEBUG1("Filename %s is closed", filename); + allContainers = xbt_dict_new (); + trivaNodeTypes = xbt_dict_new (); + trivaEdgeTypes = xbt_dict_new (); + rootContainer = root; } -void TRACE_paje_create_header(void) +static long long int newTypeId () { - DEBUG0 ("Define paje header"); - fprintf(tracing_file, "\ -%%EventDef PajeDefineContainerType %d \n\ -%% Alias string \n\ -%% ContainerType string \n\ -%% Name string \n\ -%%EndEventDef \n\ -%%EventDef PajeDefineStateType %d \n\ -%% Alias string \n\ -%% ContainerType string \n\ -%% Name string \n\ -%%EndEventDef \n\ -%%EventDef PajeDefineEntityValue %d \n\ -%% Alias string \n\ -%% EntityType string \n\ -%% Name string \n\ -%%EndEventDef \n\ -%%EventDef PajeDefineEventType %d \n\ -%% Alias string \n\ -%% EntityType string \n\ -%% Name string \n\ -%%EndEventDef \n\ -%%EventDef PajeDefineLinkType %d \n\ -%% Alias string \n\ -%% ContainerType string \n\ -%% SourceContainerType string \n\ -%% DestContainerType string \n\ -%% Name string \n\ -%%EndEventDef \n\ -%%EventDef PajeCreateContainer %d \n\ -%% Time date \n\ -%% Alias string \n\ -%% Type string \n\ -%% Container string \n\ -%% Name string \n\ -%%EndEventDef \n\ -%%EventDef PajeDestroyContainer %d \n\ -%% Time date \n\ -%% Type string \n\ -%% Container string \n\ -%%EndEventDef \n\ -%%EventDef PajeSetState %d \n\ -%% Time date \n\ -%% EntityType string \n\ -%% Container string \n\ -%% Value string \n\ -%%EndEventDef\n\ -%%EventDef PajePopState %d \n\ -%% Time date \n\ -%% EntityType string \n\ -%% Container string \n\ -%%EndEventDef\n\ -%%EventDef PajeStartLink %d \n\ -%% Time date \n\ -%% EntityType string \n\ -%% Container string \n\ -%% Value string \n\ -%% SourceContainer string \n\ -%% Key string \n\ -%%EndEventDef\n\ -%%EventDef PajeEndLink %d \n\ -%% Time date \n\ -%% EntityType string \n\ -%% Container string \n\ -%% Value string \n\ -%% DestContainer string \n\ -%% Key string \n\ -%%EndEventDef\n\ -%%EventDef PajePushState %d \n\ -%% Time date \n\ -%% EntityType string \n\ -%% Container string \n\ -%% Value string \n\ -%%EndEventDef\n\ -%%EventDef PajeSetVariable %d \n\ -%% Time date \n\ -%% EntityType string \n\ -%% Container string \n\ -%% Value string \n\ -%%EndEventDef\n\ -%%EventDef PajeAddVariable %d \n\ -%% Time date \n\ -%% EntityType string \n\ -%% Container string \n\ -%% Value string \n\ -%%EndEventDef\n\ -%%EventDef PajeSubVariable %d \n\ -%% Time date \n\ -%% EntityType string \n\ -%% Container string \n\ -%% Value string \n\ -%%EndEventDef\n\ -%%EventDef PajeDefineVariableType %d \n\ -%% Alias string \n\ -%% ContainerType string \n\ -%% Name string \n\ -%%EndEventDef \n\ -%%EventDef PajeDefineVariableType %d \n\ -%% Alias string \n\ -%% ContainerType string \n\ -%% Name string \n\ -%% Color color \n\ -%%EndEventDef \n\ -%%EventDef PajeStartLink %d \n\ -%% Time date \n\ -%% EntityType string \n\ -%% Container string \n\ -%% Value string \n\ -%% SourceContainer string \n\ -%% Key string \n\ -%% Volume string \n\ -%%EndEventDef\n\ -%%EventDef PajeNewEvent %d \n\ -%% Time date \n\ -%% EntityType string \n\ -%% Container string \n\ -%% Value string \n\ -%%EndEventDef\n", pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId, pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId, pajeDestroyContainerId, pajeSetStateId, pajePopStateId, pajeStartLinkId, pajeEndLinkId, pajePushStateId, pajeSetVariableId, pajeAddVariableId, pajeSubVariableId, pajeDefineVariableTypeId, pajeDefineVariableTypeWithColorId, pajeStartLinkWithVolumeId, pajeNewEventId); + static long long int counter = 0; + return counter++; } -/* internal to this file */ -static void __pajeCreateContainer(char *output, int len, int eventid, - double time, const char *alias, - const char *type, const char *container, - const char *name) +static type_t newType (const char *typename, const char *key, const char *color, e_entity_types kind, type_t father) { - snprintf(output, len, "%d %lf %s %s %s %s", eventid, time, - alias, type, container, name); + 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 void __pajeSetState(char *output, int len, int eventid, double time, - const char *entityType, const char *container, - const char *value) +type_t getRootType () { - snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType, - container, value); + return rootType; } -static void __pajeSetVariable(char *output, int len, int eventid, - double time, const char *entityType, - const char *container, const char *value) +type_t getContainerType (const char *typename, type_t father) { - snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType, - container, value); + 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; } -static void __pajeStartLink(char *output, int len, int eventid, - double time, const char *entityType, - const char *container, const char *value, - const char *sourceContainer, const char *key) +type_t getEventType (const char *typename, const char *color, type_t father) { - snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType, - container, value, sourceContainer, key); + 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; } -/* internal do the instrumentation module */ -void pajeDefineContainerType(const char *alias, const char *containerType, - const char *name) +type_t getVariableType (const char *typename, const char *color, type_t father) { - fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias, - containerType, name); + 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; } -void pajeDefineStateType(const char *alias, const char *containerType, - const char *name) +char *getVariableTypeIdByName (const char *name, type_t father) { - fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias, - containerType, name); + 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; } -void pajeDefineEventType(const char *alias, const char *containerType, - const char *name) +type_t getLinkType (const char *typename, type_t father, type_t source, type_t dest) { - fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias, - containerType, name); + 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; } -void pajeDefineLinkType(const char *alias, const char *containerType, - const char *sourceContainerType, - const char *destContainerType, const char *name) +type_t getStateType (const char *typename, type_t father) { - fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias, - containerType, sourceContainerType, destContainerType, name); + 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); + } + return ret; } -void pajeCreateContainer(double time, const char *alias, const char *type, - const char *container, const char *name) -{ - char line[TRACE_LINE_SIZE]; - __pajeCreateContainer(line, TRACE_LINE_SIZE, pajeCreateContainerId, time, - alias, type, container, name); - fprintf(tracing_file, "%s\n", line); -} -void pajeDestroyContainer(double time, const char *type, - const char *container) +static long long int newContainedId () { - fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time, - type, container); + static long long counter = 0; + return counter++; } -void pajeSetState(double time, const char *entityType, - const char *container, const char *value) +container_t newContainer (const char *name, e_container_types kind, container_t father) { - char line[TRACE_LINE_SIZE]; - __pajeSetState(line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType, - container, value); - fprintf(tracing_file, "%s\n", line); + long long int counter = newContainedId(); + char id_str[INSTR_DEFAULT_STR_SIZE]; + snprintf (id_str, INSTR_DEFAULT_STR_SIZE, "%lld", counter); + + container_t new = xbt_new0(s_container_t, 1); + new->name = xbt_strdup (name); // name of the container + new->id = xbt_strdup (id_str); // id (or alias) of the container + new->father = father; + // level depends on level of father + if (new->father){ + new->level = new->father->level+1; + }else{ + new->level = 0; + } + // type definition (method depends on kind of this new container) + new->kind = kind; + if (new->kind == INSTR_AS){ + //if this container is of an AS, its type name depends on its level + 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); + }else{ + new->type = getContainerType ("0", NULL); + } + }else{ + //otherwise, the name is its kind + 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; + } + } + new->children = xbt_dict_new(); + 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 NODE types for triva configuration + xbt_dict_set (trivaNodeTypes, new->type->name, xbt_strdup("1"), xbt_free); + } + return new; } -void pajePushState(double time, const char *entityType, - const char *container, const char *value) +static container_t recursiveGetContainer (const char *name, container_t root) { - char line[TRACE_LINE_SIZE]; - __pajeSetState(line, TRACE_LINE_SIZE, pajePushStateId, time, entityType, - container, value); - fprintf(tracing_file, "%s\n", line); + 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; + } + return NULL; } -void pajePopState(double time, const char *entityType, - const char *container) +container_t getContainer (const char *name) { - fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType, - container); + return recursiveGetContainer(name, rootContainer); } -void pajeStartLink(double time, const char *entityType, - const char *container, const char *value, - const char *sourceContainer, const char *key) +container_t getContainerByName (const char *name) { - char line[TRACE_LINE_SIZE]; - __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType, - container, value, sourceContainer, key); - fprintf(tracing_file, "%s\n", line); + return (container_t)xbt_dict_get (allContainers, name); } -void pajeStartLinkWithVolume(double time, const char *entityType, - const char *container, const char *value, - const char *sourceContainer, const char *key, - double volume) +char *getContainerIdByName (const char *name) { - char line[TRACE_LINE_SIZE]; - __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkWithVolumeId, time, - entityType, container, value, sourceContainer, key); - fprintf(tracing_file, "%s %f\n", line, volume); + return getContainerByName(name)->id; } -void pajeEndLink(double time, const char *entityType, - const char *container, const char *value, - const char *destContainer, const char *key) +container_t getRootContainer () { - fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time, - entityType, container, value, destContainer, key); + return rootContainer; } -void pajeDefineVariableType(const char *alias, const char *containerType, - const char *name) +static type_t recursiveGetType (const char *name, type_t root) { - fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias, - containerType, name); + 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; + } + return NULL; } -void pajeDefineVariableTypeWithColor(const char *alias, const char *containerType, - const char *name, const char *color) +type_t getType (const char *name) { - fprintf(tracing_file, "%d %s %s %s \"%s\"\n", pajeDefineVariableTypeWithColorId, alias, - containerType, name, color); + return recursiveGetType (name, rootType); } -void pajeSetVariable(double time, const char *entityType, - const char *container, const char *value) +void destroyContainer (container_t container) { - char line[TRACE_LINE_SIZE]; - __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSetVariableId, time, - entityType, container, value); - fprintf(tracing_file, "%s\n", line); + //remove me from my father + if (container->father){ + xbt_dict_remove(container->father->children, container->name); + } + + //trace my destruction + new_pajeDestroyContainer(container); + + //free + xbt_free (container->name); + xbt_free (container->id); + xbt_free (container->children); + xbt_free (container); + container = NULL; } -void pajeAddVariable(double time, const char *entityType, - const char *container, const char *value) +static void recursiveDestroyContainer (container_t container) { - char line[TRACE_LINE_SIZE]; - __pajeSetVariable(line, TRACE_LINE_SIZE, pajeAddVariableId, time, - entityType, container, value); - fprintf(tracing_file, "%s\n", line); + 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); } -void pajeSubVariable(double time, const char *entityType, - const char *container, const char *value) +static void recursiveDestroyType (type_t type) { - char line[TRACE_LINE_SIZE]; - __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSubVariableId, time, - entityType, container, value); - fprintf(tracing_file, "%s\n", line); + xbt_dict_cursor_t cursor = NULL; + type_t child; + char *child_name; + xbt_dict_foreach(type->children, cursor, child_name, child) { + recursiveDestroyType (child); + } + xbt_free (type->name); + xbt_free (type->id); + xbt_free (type->children); + xbt_free (type); + type = NULL; } -void pajeNewEvent(double time, const char *entityType, - const char *container, const char *value) +void destroyAllContainers () { - fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time, - entityType, container, value); + if (getRootContainer()) recursiveDestroyContainer (getRootContainer()); + if (getRootType()) recursiveDestroyType (getRootType()); + rootContainer = NULL; + rootType = NULL; } + #endif /* HAVE_TRACING */