Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] new callback to end of platform parsing
[simgrid.git] / src / instr / instr_routing.c
index 348a4d3..d01481e 100644 (file)
@@ -7,26 +7,24 @@
 #include "instr/instr_private.h"
 
 #ifdef HAVE_TRACING
-#include "surf/surfxml_parse_private.h"
+#include "surf/surf_private.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_routing, instr, "Tracing platform hierarchy");
 
-extern routing_global_t global_routing; /* from surf/surf_routing.c */
 extern xbt_dict_t defined_types; /* from instr_interface.c */
 
 typedef struct s_container *container_t;
 typedef struct s_container {
-  char *name;
-  char *type;
-  int level;
+  char *name;     /* Unique id of this container */
+  char *type;     /* Type of this container */
+  int level;      /* Level in the hierarchy, root level is 0 */
   struct s_container *father;
   xbt_dict_t children;
 }s_container_t;
 
-static container_t rootContainer = NULL;
-static xbt_dynar_t currentContainer = NULL;
-static xbt_dict_t created_links = NULL;
-static xbt_dict_t created_hosts = NULL;
+static container_t rootContainer = NULL;    /* the root container */
+static xbt_dynar_t currentContainer = NULL; /* push and pop, used only in creation */
+static xbt_dict_t allContainers = NULL;     /* all created containers indexed by name */
 xbt_dict_t hosts_types = NULL;
 xbt_dict_t links_types = NULL;
 
@@ -38,6 +36,7 @@ static void instr_routing_parse_start_host (void);
 static void instr_routing_parse_end_host (void);
 static void instr_routing_parse_start_router (void);
 static void instr_routing_parse_end_router (void);
+static void instr_routing_parse_end_platform (void);
 static char *instr_AS_type (int level);
 
 static char *instr_AS_type (int level)
@@ -76,6 +75,8 @@ static void newVariableType (const char *type, const char *parentType, const cha
 
 void instr_routing_define_callbacks ()
 {
+  if (!TRACE_is_active())
+    return;
   surfxml_add_callback(STag_surfxml_AS_cb_list, &instr_routing_parse_start_AS);
   surfxml_add_callback(ETag_surfxml_AS_cb_list, &instr_routing_parse_end_AS);
   surfxml_add_callback(STag_surfxml_link_cb_list, &instr_routing_parse_start_link);
@@ -84,6 +85,7 @@ void instr_routing_define_callbacks ()
   surfxml_add_callback(ETag_surfxml_host_cb_list, &instr_routing_parse_end_host);
   surfxml_add_callback(STag_surfxml_router_cb_list, &instr_routing_parse_start_router);
   surfxml_add_callback(ETag_surfxml_router_cb_list, &instr_routing_parse_end_router);
+  surfxml_add_callback(ETag_surfxml_platform_cb_list, &instr_routing_parse_end_platform);
 }
 
 
@@ -137,8 +139,7 @@ static void instr_routing_parse_start_AS ()
     currentContainer = xbt_dynar_new (sizeof(s_container_t), NULL);
     xbt_dynar_push (currentContainer, rootContainer);
 
-    created_links = xbt_dict_new ();
-    created_hosts = xbt_dict_new ();
+    allContainers = xbt_dict_new ();
     hosts_types = xbt_dict_new ();
     links_types = xbt_dict_new ();
   }
@@ -188,7 +189,7 @@ static void instr_routing_parse_start_link ()
   }
 
   //register created link on the dictionary
-  xbt_dict_set (created_links, A_surfxml_link_id, new, NULL);
+  xbt_dict_set (allContainers, A_surfxml_link_id, new, NULL);
 
   //register this link type
   xbt_dict_set (links_types, type, xbt_strdup("1"), xbt_free);
@@ -219,7 +220,7 @@ static void instr_routing_parse_start_host ()
   }
 
   //register created host on the dictionary
-  xbt_dict_set (created_hosts, A_surfxml_host_id, new, NULL);
+  xbt_dict_set (allContainers, A_surfxml_host_id, new, NULL);
 
   //register this link type
   xbt_dict_set (hosts_types, type, xbt_strdup("1"), xbt_free);
@@ -234,19 +235,27 @@ static void instr_routing_parse_start_router ()
   container_t father = xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
   char type[INSTR_DEFAULT_STR_SIZE];
   snprintf (type, INSTR_DEFAULT_STR_SIZE, "ROUTER-%s", father->type);
-  newContainer (A_surfxml_router_id, type, "ROUTER");
+  container_t new = newContainer (A_surfxml_router_id, type, "ROUTER");
+
+  //register created host on the dictionary
+  xbt_dict_set (allContainers, A_surfxml_router_id, new, NULL);
 }
 
 static void instr_routing_parse_end_router ()
 {
 }
 
+static void instr_routing_parse_end_platform ()
+{
+  currentContainer = NULL;
+}
+
 /*
  * Support functions
  */
 int instr_link_is_traced (const char *name)
 {
-  if (xbt_dict_get_or_null(created_links, name)) {
+  if (((container_t)xbt_dict_get_or_null (allContainers, name))){
     return 1;
   } else {
     return 0;
@@ -255,28 +264,17 @@ int instr_link_is_traced (const char *name)
 
 char *instr_link_type (const char *name)
 {
-  container_t created_link = xbt_dict_get_or_null(created_links, name);
-  if (created_link){
-    return created_link->type;
-  }else{
-    return NULL;
-  }
+  return ((container_t)xbt_dict_get (allContainers, name))->type;
 }
 
-
 char *instr_host_type (const char *name)
 {
-  container_t created_host = xbt_dict_get_or_null(created_hosts, name);
-  if (created_host){
-    return created_host->type;
-  }else{
-    return NULL;
-  }
+  return ((container_t)xbt_dict_get (allContainers, name))->type;
 }
 
 void instr_destroy_platform ()
 {
-  recursiveDestroyContainer (rootContainer);
+  if (rootContainer) recursiveDestroyContainer (rootContainer);
 }
 
 #endif /* HAVE_TRACING */