#ifdef HAVE_TRACING
-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(FILE * file)
+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)
{
- tracing_file = file;
+ allContainers = xbt_dict_new_homogeneous(NULL);
+ trivaNodeTypes = xbt_dict_new_homogeneous(xbt_free);
+ trivaEdgeTypes = xbt_dict_new_homogeneous(xbt_free);
+ rootContainer = root;
}
-FILE *TRACE_paje_end(void)
+static long long int new_type_id (void)
{
- return tracing_file;
+ static long long int type_id = 0;
+ return type_id++;
}
+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;
+}
-void TRACE_paje_create_header(void)
+val_t getValue (const char *valuename, const char *color, type_t father)
{
- if (!TRACE_is_active())
- return;
- 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);
+ 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;
}
-/* 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)
+val_t getValueByName (const char *valuename, type_t father)
{
- snprintf(output, len, "%d %lf %s %s %s %s", eventid, time,
- alias, type, container, name);
+ return getValue (valuename, NULL, father);
}
-static void __pajeSetState(char *output, int len, int eventid, double time,
- const char *entityType, const char *container,
- const char *value)
+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", eventid, time, entityType,
- container, value);
+ 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_homogeneous(NULL);
+ ret->values = xbt_dict_new_homogeneous(NULL);
+ 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);
+
+ if (father != NULL){
+ xbt_dict_set (father->children, key, ret, NULL);
+ XBT_DEBUG("new type %s, child of %s", typename, father->name);
+ }
+ return ret;
}
-static void __pajeSetVariable(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 __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 getContainerType (const char *typename, type_t father)
{
- snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType,
- container, value, sourceContainer, key);
+ 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;
}
-/* internal do the instrumentation module */
-void pajeDefineContainerType(const char *alias, const char *containerType,
- const char *name)
+type_t getEventType (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_EVENT, father);
+ }else{
+ ret = newType (typename, typename, color, TYPE_EVENT, father);
+ }
+ XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
+ new_pajeDefineEventType(ret);
+ }
+ return ret;
}
-void pajeDefineStateType(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", pajeDefineStateTypeId, 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);
+ }
+ XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
+ new_pajeDefineVariableType (ret);
+ }
+ return ret;
}
-void pajeDefineEventType(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", pajeDefineEventTypeId, 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 pajeDefineLinkType(const char *alias, const char *containerType,
- const char *sourceContainerType,
- const char *destContainerType, 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 %s %s\n", pajeDefineLinkTypeId, alias,
- containerType, sourceContainerType, destContainerType, 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);
+ 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;
}
-void pajeCreateContainer(double time, const char *alias, const char *type,
- const char *container, const char *name)
+type_t getStateType (const char *typename, type_t father)
{
- char line[TRACE_LINE_SIZE];
- __pajeCreateContainer(line, TRACE_LINE_SIZE, pajeCreateContainerId, time,
- alias, type, container, name);
- fprintf(tracing_file, "%s\n", line);
+ type_t ret = xbt_dict_get_or_null (father->children, typename);
+ if (ret == NULL){
+ ret = newType (typename, typename, NULL, TYPE_STATE, father);
+ XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->name, ret->id, father->name, father->id);
+ new_pajeDefineStateType(ret);
+ }
+ return ret;
}
-void pajeDestroyContainer(double time, const char *type,
- const char *container)
+container_t newContainer (const char *name, e_container_types kind, container_t father)
{
- fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time,
- type, container);
+ static long long int container_id = 0;
+ char id_str[INSTR_DEFAULT_STR_SIZE];
+ 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
+ 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;
+ XBT_DEBUG("new container %s, child of %s", name, father->name);
+ }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_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 NODE types for triva configuration
+ xbt_dict_set (trivaNodeTypes, new->type->name, xbt_strdup("1"), NULL);
+ }
+ return new;
}
-void pajeSetState(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, pajeSetStateId, time, entityType,
- container, value);
- fprintf(tracing_file, "%s\n", line);
+ if (name == NULL || root == NULL) return NULL;
+ 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 pajePushState(double time, const char *entityType,
- const char *container, const char *value)
+container_t getContainer (const char *name)
{
- char line[TRACE_LINE_SIZE];
- __pajeSetState(line, TRACE_LINE_SIZE, pajePushStateId, time, entityType,
- container, value);
- fprintf(tracing_file, "%s\n", line);
+ if (name == NULL) return NULL;
+ return recursiveGetContainer(name, rootContainer);
}
-void pajePopState(double time, const char *entityType,
- const char *container)
+int knownContainerWithName (const char *name)
{
- fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType,
- container);
+ if (xbt_dict_get_or_null (allContainers, name)){
+ return 1;
+ }else{
+ return 0;
+ }
}
-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, type_t father)
{
- fprintf(tracing_file, "%d %s %s %s \"%s\"\n", pajeDefineVariableTypeWithColorId, alias,
- containerType, name, color);
+ return recursiveGetType (name, father);
}
-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);
+ }
+
+ 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
+ if (!TRACE_disable_destroy()){
+ //do not trace the container destruction if user requests
+ 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->values);
+ 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 */