Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] new field id to make the final trace file smaller
[simgrid.git] / src / instr / instr_routing.c
index 2516095..037c934 100644 (file)
@@ -8,6 +8,7 @@
 
 #ifdef HAVE_TRACING
 #include "surf/surf_private.h"
+#include "surf/network_private.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_routing, instr, "Tracing platform hierarchy");
 
@@ -22,7 +23,8 @@ typedef enum {
 
 typedef struct s_container *container_t;
 typedef struct s_container {
-  char *name;     /* Unique id of this container */
+  char *name;     /* Unique name of this container */
+  char *id;       /* Unique id of this container */
   char *type;     /* Type of this container */
   char *typename; /* Type name of this container */
   int level;      /* Level in the hierarchy, root level is 0 */
@@ -106,11 +108,21 @@ void instr_routing_define_callbacks ()
   surfxml_add_callback(ETag_surfxml_platform_cb_list, &instr_routing_parse_end_platform);
 }
 
+static long long int newContainedId ()
+{
+  static long long counter = 0;
+  return counter++;
+}
 
 static container_t newContainer (const char *name, const char *type, e_container_types kind)
 {
+  long long int counter = newContainedId();
+  char id_str[INSTR_DEFAULT_STR_SIZE];
+  snprintf (id_str, INSTR_DEFAULT_STR_SIZE, "%lld", counter);
+
   container_t newContainer = xbt_new0(s_container_t, 1);
   newContainer->name = xbt_strdup (name);
+  newContainer->id = xbt_strdup (id_str);
   newContainer->father = xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
   newContainer->level = newContainer->father->level+1;
   newContainer->type = xbt_strdup (type);
@@ -126,7 +138,7 @@ static container_t newContainer (const char *name, const char *type, e_container
   xbt_dict_set(newContainer->father->children, newContainer->name, newContainer, NULL);
 
   newContainerType (newContainer->type, newContainer->father->type, newContainer->typename);
-  pajeCreateContainer (0, newContainer->name, newContainer->type, newContainer->father->name, newContainer->name);
+  pajeCreateContainer (0, newContainer->id, newContainer->type, newContainer->father->id, newContainer->name);
 
   return newContainer;
 }
@@ -140,15 +152,114 @@ static void recursiveDestroyContainer (container_t container)
     recursiveDestroyContainer (child);
   }
 
-  pajeDestroyContainer(SIMIX_get_clock(), container->type, container->name);
+  pajeDestroyContainer(SIMIX_get_clock(), container->type, container->id);
 
   xbt_free (container->name);
+  xbt_free (container->id);
   xbt_free (container->type);
   xbt_free (container->children);
   xbt_free (container);
   container = NULL;
 }
 
+static void linkContainers (container_t container, const char *a1, const char *a2)
+{
+  //ignore loopback
+  if (strcmp (a1, "__loopback__") == 0 || strcmp (a2, "__loopback__") == 0)
+    return;
+
+  char *a1_id = ((container_t)xbt_dict_get (allContainers, a1))->id;
+  char *a1_type = ((container_t)xbt_dict_get (allContainers, a1))->type;
+  char *a1_typename = ((container_t)xbt_dict_get (allContainers, a1))->typename;
+
+  char *a2_id = ((container_t)xbt_dict_get (allContainers, a2))->id;
+  char *a2_type = ((container_t)xbt_dict_get (allContainers, a2))->type;
+  char *a2_typename = ((container_t)xbt_dict_get (allContainers, a2))->typename;
+
+  //declare type
+  char new_link_type[INSTR_DEFAULT_STR_SIZE], new_link_typename[INSTR_DEFAULT_STR_SIZE];
+  snprintf (new_link_type, INSTR_DEFAULT_STR_SIZE, "%s-%s", a1_type, a2_type);
+  snprintf (new_link_typename, INSTR_DEFAULT_STR_SIZE, "%s-%s", a1_typename, a2_typename);
+  newLinkType (new_link_type, container->type, a1_type, a2_type, new_link_typename);
+
+  //create the link
+  static long long counter = 0;
+  char key[INSTR_DEFAULT_STR_SIZE];
+  snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
+  pajeStartLink(SIMIX_get_clock(), new_link_type, container->id, "G", a1_id, key);
+  pajeEndLink(SIMIX_get_clock(), new_link_type, container->id, "G", a2_id, key);
+}
+
+static void recursiveGraphExtraction (container_t container)
+{
+  if (xbt_dict_length(container->children)){
+    xbt_dict_cursor_t cursor = NULL;
+    container_t child;
+    char *child_name;
+    //bottom-up recursion
+    xbt_dict_foreach(container->children, cursor, child_name, child) {
+      recursiveGraphExtraction (child);
+    }
+
+    //let's get routes
+    xbt_dict_cursor_t cursor1 = NULL, cursor2 = NULL;
+    container_t child1, child2;
+    const char *child_name1, *child_name2;
+
+    xbt_dict_foreach(container->children, cursor1, child_name1, child1) {
+      xbt_dict_foreach(container->children, cursor2, child_name2, child2) {
+        if ((child1->kind == INSTR_HOST || child1->kind == INSTR_ROUTER) &&
+            (child2->kind == INSTR_HOST  || child2->kind == INSTR_ROUTER)){
+
+          //getting route
+          xbt_dynar_t route;
+          xbt_ex_t exception;
+          TRY {
+            route = global_routing->get_route (child_name1, child_name2);
+          }CATCH(exception) {
+            //no route between them, that's possible
+            continue;
+          }
+
+          //link the route members
+          unsigned int cpt;
+          void *link;
+          char *previous_entity_name = (char*)child_name1;
+          xbt_dynar_foreach (route, cpt, link) {
+            char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
+            linkContainers (container, previous_entity_name, link_name);
+            previous_entity_name = link_name;
+          }
+          linkContainers (container, previous_entity_name, child_name2);
+        }else if (child1->kind == INSTR_AS &&
+                  child2->kind == INSTR_AS &&
+                  strcmp(child_name1, child_name2) != 0){
+
+          //getting route
+          routing_component_t root = global_routing->root;
+          route_extended_t route;
+          xbt_ex_t exception;
+          TRY {
+            route = root->get_route (root, child_name1, child_name2);
+          }CATCH(exception) {
+            //no route between them, that's possible
+            continue;
+          }
+          unsigned int cpt;
+          void *link;
+          char *previous_entity_name = route->src_gateway;
+          xbt_dynar_foreach (route->generic_route.link_list, cpt, link) {
+            char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
+            linkContainers (container, previous_entity_name, link_name);
+            previous_entity_name = link_name;
+          }
+          linkContainers (container, previous_entity_name, route->dst_gateway);
+        }
+      }
+    }
+  }
+}
+
 /*
  * Callbacks
  */
@@ -157,6 +268,7 @@ static void instr_routing_parse_start_AS ()
   if (rootContainer == NULL){
     rootContainer = xbt_new0(s_container_t, 1);
     rootContainer->name = xbt_strdup ("0");
+    rootContainer->id = xbt_strdup (rootContainer->name);
     rootContainer->type = xbt_strdup ("0");
     rootContainer->typename = xbt_strdup ("0");
     rootContainer->level = 0;
@@ -172,8 +284,13 @@ static void instr_routing_parse_start_AS ()
     links_types = xbt_dict_new ();
   }
 
+  long long int counter = newContainedId();
+  char id_str[INSTR_DEFAULT_STR_SIZE];
+  snprintf (id_str, INSTR_DEFAULT_STR_SIZE, "%lld", counter);
+
   container_t newContainer = xbt_new0(s_container_t, 1);
   newContainer->name = xbt_strdup (A_surfxml_AS_id);
+  newContainer->id = xbt_strdup (id_str);
   newContainer->father = xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
   newContainer->level = newContainer->father->level+1;
   newContainer->type = instr_AS_type (newContainer->level);
@@ -184,7 +301,7 @@ static void instr_routing_parse_start_AS ()
 
   //trace
   newContainerType (newContainer->type, newContainer->father->type, newContainer->type);
-  pajeCreateContainer (0, newContainer->name, newContainer->type, newContainer->father->name, newContainer->name);
+  pajeCreateContainer (0, newContainer->id, newContainer->type, newContainer->father->id, newContainer->name);
 
   //push
   xbt_dynar_push (currentContainer, newContainer);
@@ -208,8 +325,8 @@ static void instr_routing_parse_start_link ()
   snprintf (latency_type, INSTR_DEFAULT_STR_SIZE, "latency-%s", type);
   newVariableType (bandwidth_type, type, "bandwidth", NULL);
   newVariableType (latency_type, type, "latency", NULL);
-  pajeSetVariable(0, bandwidth_type, new->name, A_surfxml_link_bandwidth);
-  pajeSetVariable(0, latency_type, new->name, A_surfxml_link_latency);
+  pajeSetVariable(0, bandwidth_type, new->id, A_surfxml_link_bandwidth);
+  pajeSetVariable(0, latency_type, new->id, A_surfxml_link_latency);
 
   if (TRACE_uncategorized()){
     //bandwidth_used
@@ -240,7 +357,7 @@ static void instr_routing_parse_start_host ()
   char power_type[INSTR_DEFAULT_STR_SIZE];
   snprintf (power_type, INSTR_DEFAULT_STR_SIZE, "power-%s", type);
   newVariableType (power_type, type, "power", NULL);
-  pajeSetVariable(0, power_type, new->name, A_surfxml_host_power);
+  pajeSetVariable(0, power_type, new->id, A_surfxml_host_power);
 
   if (TRACE_uncategorized()){
     //power_used
@@ -278,6 +395,7 @@ static void instr_routing_parse_end_router ()
 static void instr_routing_parse_end_platform ()
 {
   currentContainer = NULL;
+  recursiveGraphExtraction (rootContainer);
 }
 
 /*
@@ -302,6 +420,11 @@ char *instr_host_type (const char *name)
   return ((container_t)xbt_dict_get (allContainers, name))->type;
 }
 
+char *instr_id (const char *name)
+{
+  return ((container_t)xbt_dict_get (allContainers, name))->id;
+}
+
 void instr_destroy_platform ()
 {
   if (rootContainer) recursiveDestroyContainer (rootContainer);