+ if (TRACE_needs_platform()){
+ xbt_dynar_pop_ptr (currentContainer);
+ }
+}
+
+static void instr_routing_parse_start_link (sg_platf_link_cbarg_t link)
+{
+ container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
+
+ double bandwidth_value = link->bandwidth;
+ double latency_value = link->latency;
+ xbt_dynar_t links_to_create = xbt_dynar_new (sizeof(char*), &xbt_free_ref);
+
+ if (link->policy == SURF_LINK_FULLDUPLEX){
+ char *up = bprintf("%s_UP", link->id);
+ char *down = bprintf("%s_DOWN", link->id);
+ xbt_dynar_push_as (links_to_create, char*, xbt_strdup(up));
+ xbt_dynar_push_as (links_to_create, char*, xbt_strdup(down));
+ free (up);
+ free (down);
+ }else{
+ xbt_dynar_push_as (links_to_create, char*, strdup(link->id));
+ }
+
+ char *link_name = NULL;
+ unsigned int i;
+ xbt_dynar_foreach (links_to_create, i, link_name){
+
+ container_t new = newContainer (link_name, INSTR_LINK, father);
+
+ if (TRACE_categorized() || TRACE_uncategorized()){
+ type_t bandwidth = getVariableType ("bandwidth", NULL, new->type);
+ type_t latency = getVariableType ("latency", NULL, new->type);
+ new_pajeSetVariable (0, new, bandwidth, bandwidth_value);
+ new_pajeSetVariable (0, new, latency, latency_value);
+ }
+ if (TRACE_uncategorized()){
+ getVariableType ("bandwidth_used", "0.5 0.5 0.5", new->type);
+ }
+ }
+
+ xbt_dynar_free (&links_to_create);
+}
+
+static void instr_routing_parse_start_host (sg_platf_host_cbarg_t host)
+{
+ container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
+ container_t new = newContainer (host->id, INSTR_HOST, father);
+
+ if (TRACE_categorized() || TRACE_uncategorized()) {
+ type_t power = getVariableType ("power", NULL, new->type);
+ new_pajeSetVariable (0, new, power, host->power_peak);
+ }
+ if (TRACE_uncategorized()){
+ getVariableType ("power_used", "0.5 0.5 0.5", new->type);
+ }
+
+ if (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped()){
+ type_t mpi = getContainerType("MPI", new->type);
+ getStateType ("MPI_STATE", mpi);
+ getLinkType ("MPI_LINK", getRootType(), mpi, mpi);
+ }
+
+ if (TRACE_msg_process_is_enabled()) {
+ type_t msg_process = getContainerType("MSG_PROCESS", new->type);
+ type_t state = getStateType ("MSG_PROCESS_STATE", msg_process);
+ getValue ("executing", "0 1 0", state);
+ getValue ("suspend", "1 0 1", state);
+ getValue ("sleep", "1 1 0", state);
+ getValue ("receive", "1 0 0", state);
+ getValue ("send", "0 0 1", state);
+ getValue ("task_execute", "0 1 1", state);
+ getLinkType ("MSG_PROCESS_LINK", getRootType(), msg_process, msg_process);
+ getLinkType ("MSG_PROCESS_TASK_LINK", getRootType(), msg_process, msg_process);
+ }
+
+ if (TRACE_msg_task_is_enabled()) {
+ type_t msg_task = getContainerType ("MSG_TASK", new->type);
+ type_t state = getStateType ("MSG_TASK_STATE", msg_task);
+ getValue ("MSG_task_execute", "0 1 0", state);
+ getValue ("created", "1 1 0", state);
+ getLinkType ("MSG_TASK_LINK", getRootType(), msg_task, msg_task);
+ }
+}
+
+static void instr_routing_parse_start_router (sg_platf_router_cbarg_t router)
+{
+ container_t father = *(container_t*)xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
+ newContainer (router->id, INSTR_ROUTER, father);
+}
+
+static void instr_routing_parse_end_platform ()
+{
+ xbt_dynar_free(¤tContainer);
+ currentContainer = NULL;
+ xbt_dict_t filter = xbt_dict_new ();
+ recursiveGraphExtraction (global_routing->root, getRootContainer(), filter);
+ xbt_dict_free(&filter);
+ platform_created = 1;
+ TRACE_paje_dump_buffer(1);
+}
+
+void instr_routing_define_callbacks ()
+{
+ if (!TRACE_is_enabled()) return;
+ //always need the call backs to ASes (we need only the root AS),
+ //to create the rootContainer and the rootType properly
+ sg_platf_AS_begin_add_cb(instr_routing_parse_start_AS);
+ sg_platf_AS_end_add_cb(instr_routing_parse_end_AS);
+ if (!TRACE_needs_platform()) return;
+ sg_platf_link_add_cb(instr_routing_parse_start_link);
+ sg_platf_host_add_cb(instr_routing_parse_start_host);
+ sg_platf_router_add_cb(instr_routing_parse_start_router);
+
+ sg_platf_postparse_add_cb(instr_routing_parse_end_platform);
+}
+
+/*
+ * user categories support
+ */
+static void recursiveNewVariableType (const char *new_typename, const char *color, type_t root)
+{
+ if (!strcmp (root->name, "HOST")){
+ char tnstr[INSTR_DEFAULT_STR_SIZE];
+ snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "p%s", new_typename);
+ getVariableType(tnstr, color, root);
+ }
+ if (!strcmp (root->name, "LINK")){
+ char tnstr[INSTR_DEFAULT_STR_SIZE];
+ snprintf (tnstr, INSTR_DEFAULT_STR_SIZE, "b%s", new_typename);
+ getVariableType(tnstr, color, root);
+ }
+ xbt_dict_cursor_t cursor = NULL;
+ type_t child_type;
+ char *name;
+ xbt_dict_foreach(root->children, cursor, name, child_type) {
+ recursiveNewVariableType (new_typename, color, child_type);
+ }
+}
+
+void instr_new_variable_type (const char *new_typename, const char *color)
+{
+ recursiveNewVariableType (new_typename, color, getRootType());
+}
+
+static void recursiveNewUserVariableType (const char *father_type, const char *new_typename, const char *color, type_t root)
+{
+ if (!strcmp (root->name, father_type)){
+ getVariableType(new_typename, color, root);
+ }
+ xbt_dict_cursor_t cursor = NULL;
+ type_t child_type;
+ char *name;
+ xbt_dict_foreach(root->children, cursor, name, child_type) {
+ recursiveNewUserVariableType (father_type, new_typename, color, child_type);
+ }
+}
+
+void instr_new_user_variable_type (const char *father_type, const char *new_typename, const char *color)
+{
+ recursiveNewUserVariableType (father_type, new_typename, color, getRootType());