Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the amount of implicit include directories
[simgrid.git] / src / surf / instr_routing.c
index 2a5e64e..fbb9117 100644 (file)
@@ -1,21 +1,16 @@
-/* Copyright (c) 2010. The SimGrid Team.
+/* Copyright (c) 2010, 2012-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 * under the terms of the license (GNU LGPL) which comes with this package. */
+ * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "instr/instr_private.h"
-#include "mc/mc.h"
+#include "src/instr/instr_private.h"
 
-#ifdef HAVE_TRACING
-#include "surf/surf_private.h"
-#include "surf/network_private.h"
+#include "src/surf/surf_private.h"
 #include "xbt/graph.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_routing, instr, "Tracing platform hierarchy");
 
-extern xbt_dict_t defined_types; /* from instr_interface.c */
-
 static int platform_created = 0;            /* indicate whether the platform file has been traced */
 static xbt_dynar_t currentContainer = NULL; /* push and pop, used only in creation */
 
@@ -119,9 +114,6 @@ static void linkContainers (container_t src, container_t dst, xbt_dict_t filter)
   //create the link
   static long long counter = 0;
 
-  if(MC_is_active())
-    MC_ignore_data_bss(&counter, sizeof(counter));
-
   char key[INSTR_DEFAULT_STR_SIZE];
   snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
   new_pajeStartLink(SIMIX_get_clock(), father, link_type, src, "topology", key);
@@ -130,89 +122,40 @@ static void linkContainers (container_t src, container_t dst, xbt_dict_t filter)
   XBT_DEBUG ("  linkContainers %s <-> %s", src->name, dst->name);
 }
 
-static int graph_extraction_filter_out (container_t c1, container_t c2)
-{
-  if (c1->kind == INSTR_LINK ||
-      c1->kind == INSTR_SMPI ||
-      c1->kind == INSTR_MSG_PROCESS ||
-      c1->kind == INSTR_MSG_TASK ||
-      c1->kind == INSTR_MSG_VM ||
-      (c2 && strcmp (c1->name, c2->name) == 0))
-    return 1;
-  else
-    return 0;
-}
-
 static void recursiveGraphExtraction (AS_t rc, container_t container, xbt_dict_t filter)
 {
   if (!TRACE_platform_topology()){
-    XBT_DEBUG("Graph extracing disable by user.");
+    XBT_DEBUG("Graph extraction disabled by user.");
     return;
   }
-  XBT_DEBUG ("Graph extraction for routing_component = %s", rc->name);
-  if (!xbt_dict_is_empty(rc->routing_sons)){
+  XBT_DEBUG ("Graph extraction for routing_component = %s", surf_AS_get_name(rc));
+  if (!xbt_dict_is_empty(surf_AS_get_routing_sons(rc))){
     xbt_dict_cursor_t cursor = NULL;
     AS_t rc_son;
     char *child_name;
     //bottom-up recursion
-    xbt_dict_foreach(rc->routing_sons, cursor, child_name, rc_son) {
-      container_t child_container = xbt_dict_get (container->children, rc_son->name);
+    xbt_dict_foreach(surf_AS_get_routing_sons(rc), cursor, child_name, rc_son) {
+      container_t child_container = xbt_dict_get (container->children, surf_AS_get_name(rc_son));
       recursiveGraphExtraction (rc_son, child_container, filter);
     }
   }
 
-  //let's get routes
-  xbt_dict_cursor_t cursor1 = NULL, cursor2 = NULL;
-  container_t child1, child2;
-  const char *child1_name, *child2_name;
-  xbt_dict_foreach(container->children, cursor1, child1_name, child1) {
-    if (graph_extraction_filter_out (child1, NULL)) continue;
-
-    xbt_dict_foreach(container->children, cursor2, child2_name, child2) {
-      if (graph_extraction_filter_out (child2, child1)) continue;
-      XBT_DEBUG ("get_route from %s to %s", child1_name, child2_name);
-
-      //if child1 is not child2
-      if (strcmp (child1_name, child2_name) == 0) continue;
-
-      //get the route
-      sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1);
-      route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
-      rc->get_route_and_latency(rc, child1->net_elm, child2->net_elm,
-                                route, NULL);
-
-      //user might want to extract a graph using routes with only one link
-      //see --cfg=tracing/onelink_only:1 or --help-tracing for details
-      if (TRACE_onelink_only() && xbt_dynar_length (route->link_list) > 1){
-        generic_free_route(route);
-        continue;
-      }
+  {
+    xbt_graph_t graph = xbt_graph_new_graph (0, NULL);
+    xbt_dict_t nodes = xbt_dict_new_homogeneous(NULL);
+    xbt_dict_t edges = xbt_dict_new_homogeneous(NULL);
+    xbt_edge_t edge = NULL;
 
-      //traverse the route connecting the containers
-      unsigned int cpt;
-      void *link;
-      container_t current, previous;
-      if (route->gw_src){
-        previous = PJ_container_get(route->gw_src->name);
-      }else{
-        previous = child1;
-      }
+    xbt_dict_cursor_t cursor = NULL;
+    char *edge_name;
 
-      xbt_dynar_foreach (route->link_list, cpt, link) {
-        //FIXME (TODO): Should have a cleaner way to get the link name
-        char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
-        current = PJ_container_get(link_name);
-        linkContainers(previous, current, filter);
-        previous = current;
-      }
-      if (route->gw_dst){
-        current = PJ_container_get(route->gw_dst->name);
-      }else{
-        current = child2;
-      }
-      linkContainers(previous, current, filter);
-      generic_free_route(route);
+    surf_AS_get_graph(rc, graph, nodes, edges);
+    xbt_dict_foreach(edges,cursor,edge_name,edge) {
+        linkContainers(PJ_container_get(edge->src->data), PJ_container_get(edge->dst->data), filter);
     }
+    xbt_dict_free (&nodes);
+    xbt_dict_free (&edges);
+    xbt_graph_free_graph(graph, xbt_free_f, xbt_free_f, NULL);
   }
 }
 
@@ -286,7 +229,7 @@ static void instr_routing_parse_start_link (sg_platf_link_cbarg_t link)
 
     container_t new = PJ_container_new (link_name, INSTR_LINK, father);
 
-    if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()){
+    if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (! TRACE_disable_link())) {
       type_t bandwidth = PJ_type_get_or_null ("bandwidth", new->type);
       if (bandwidth == NULL){
         bandwidth = PJ_type_variable_new ("bandwidth", NULL, new->type);
@@ -301,7 +244,7 @@ static void instr_routing_parse_start_link (sg_platf_link_cbarg_t link)
     if (TRACE_uncategorized()){
       type_t bandwidth_used = PJ_type_get_or_null ("bandwidth_used", new->type);
       if (bandwidth_used == NULL){
-        bandwidth_used = PJ_type_variable_new ("bandwidth_used", "0.5 0.5 0.5", new->type);
+        PJ_type_variable_new ("bandwidth_used", "0.5 0.5 0.5", new->type);
       }
     }
   }
@@ -314,17 +257,20 @@ 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 = PJ_container_new (host->id, INSTR_HOST, father);
 
-  if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) {
+  if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (! TRACE_disable_power())) {
     type_t power = PJ_type_get_or_null ("power", new->type);
     if (power == NULL){
       power = PJ_type_variable_new ("power", NULL, new->type);
     }
-    new_pajeSetVariable (0, new, power, host->power_peak);
+
+    double current_power_state;
+    xbt_dynar_get_cpy(host->power_peak, host->pstate, &current_power_state);
+    new_pajeSetVariable (0, new, power, current_power_state);
   }
   if (TRACE_uncategorized()){
     type_t power_used = PJ_type_get_or_null ("power_used", new->type);
     if (power_used == NULL){
-      power_used = PJ_type_variable_new ("power_used", "0.5 0.5 0.5", new->type);
+      PJ_type_variable_new ("power_used", "0.5 0.5 0.5", new->type);
     }
   }
 
@@ -379,9 +325,9 @@ static void instr_routing_parse_end_platform ()
 {
   xbt_dynar_free(&currentContainer);
   currentContainer = NULL;
-  xbt_dict_t filter = xbt_dict_new_homogeneous(xbt_free);
+  xbt_dict_t filter = xbt_dict_new_homogeneous(xbt_free_f);
   XBT_DEBUG ("Starting graph extraction.");
-  recursiveGraphExtraction (routing_platf->root, PJ_container_get_root(), filter);
+  recursiveGraphExtraction (surf_platf_get_root(routing_platf), PJ_container_get_root(), filter);
   XBT_DEBUG ("Graph extraction finished.");
   xbt_dict_free(&filter);
   platform_created = 1;
@@ -498,107 +444,21 @@ int instr_platform_traced ()
 #define GRAPHICATOR_SUPPORT_FUNCTIONS
 
 
-static xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes)
-{
-  xbt_node_t ret = xbt_dict_get_or_null (nodes, name);
-  if (ret) return ret;
-
-  ret = xbt_graph_new_node (graph, xbt_strdup(name));
-  xbt_dict_set (nodes, name, ret, NULL);
-  return ret;
-}
-
-static xbt_edge_t new_xbt_graph_edge (xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges)
-{
-  xbt_edge_t ret;
-
-  const char *sn = instr_node_name (s);
-  const char *dn = instr_node_name (d);
-  int len = strlen(sn)+strlen(dn)+1;
-  char *name = (char*)xbt_malloc(len * sizeof(char));
-
-
-  snprintf (name, len, "%s%s", sn, dn);
-  ret = xbt_dict_get_or_null (edges, name);
-  if (ret == NULL){
-    snprintf (name, len, "%s%s", dn, sn);
-    ret = xbt_dict_get_or_null (edges, name);
-  }
-
-  if (ret == NULL){
-    ret = xbt_graph_new_edge(graph, s, d, NULL);
-    xbt_dict_set (edges, name, ret, NULL);
-  }
-  free (name);
-  return ret;
-}
-
 static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges,
     AS_t rc, container_t container)
 {
-  if (!xbt_dict_is_empty(rc->routing_sons)){
+  if (!xbt_dict_is_empty(surf_AS_get_routing_sons(rc))){
     xbt_dict_cursor_t cursor = NULL;
     AS_t rc_son;
     char *child_name;
     //bottom-up recursion
-    xbt_dict_foreach(rc->routing_sons, cursor, child_name, rc_son) {
-      container_t child_container = xbt_dict_get (container->children, rc_son->name);
+    xbt_dict_foreach(surf_AS_get_routing_sons(rc), cursor, child_name, rc_son) {
+      container_t child_container = xbt_dict_get (container->children, surf_AS_get_name(rc_son));
       recursiveXBTGraphExtraction (graph, nodes, edges, rc_son, child_container);
     }
   }
 
-  //let's get routes
-  xbt_dict_cursor_t cursor1 = NULL, cursor2 = NULL;
-  container_t child1, child2;
-  const char *child1_name, *child2_name;
-  xbt_dict_foreach(container->children, cursor1, child1_name, child1) {
-    //if child1 is not a link, a smpi node, a msg process, a msg vm or a msg task
-    if (child1->kind == INSTR_LINK || child1->kind == INSTR_SMPI || child1->kind == INSTR_MSG_PROCESS || child1->kind == INSTR_MSG_VM || child1->kind == INSTR_MSG_TASK) continue;
-
-    xbt_dict_foreach(container->children, cursor2, child2_name, child2) {
-      //if child2 is not a link, a smpi node, a msg process or a msg task
-      if (child2->kind == INSTR_LINK || child2->kind == INSTR_SMPI || child2->kind == INSTR_MSG_PROCESS || child2->kind == INSTR_MSG_VM || child2->kind == INSTR_MSG_TASK) continue;
-
-      //if child1 is not child2
-      if (strcmp (child1_name, child2_name) == 0) continue;
-
-      //get the route
-      sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1);
-      route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
-      rc->get_route_and_latency(rc, child1->net_elm, child2->net_elm,
-                                route, NULL);
-
-      //user might want to extract a graph using routes with only one link
-      //see --cfg=tracing/onelink_only:1 or --help-tracing for details
-      if (TRACE_onelink_only() && xbt_dynar_length (route->link_list) > 1) continue;
-
-      //traverse the route connecting the containers
-      unsigned int cpt;
-      void *link;
-      xbt_node_t current, previous;
-      if (route->gw_src){
-        previous = new_xbt_graph_node(graph, route->gw_src->name, nodes);
-      }else{
-        previous = new_xbt_graph_node(graph, child1_name, nodes);
-      }
-
-      xbt_dynar_foreach (route->link_list, cpt, link) {
-        char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
-        current = new_xbt_graph_node(graph, link_name, nodes);
-        new_xbt_graph_edge (graph, previous, current, edges);
-        //previous -> current
-        previous = current;
-      }
-      if (route->gw_dst){
-        current = new_xbt_graph_node(graph, route->gw_dst->name, nodes);
-      }else{
-        current = new_xbt_graph_node(graph, child2_name, nodes);
-      }
-      new_xbt_graph_edge (graph, previous, current, edges);
-      generic_free_route(route);
-    }
-  }
-
+  surf_AS_get_graph(rc, graph, nodes, edges);
 }
 
 xbt_graph_t instr_routing_platform_graph (void)
@@ -606,7 +466,7 @@ xbt_graph_t instr_routing_platform_graph (void)
   xbt_graph_t ret = xbt_graph_new_graph (0, NULL);
   xbt_dict_t nodes = xbt_dict_new_homogeneous(NULL);
   xbt_dict_t edges = xbt_dict_new_homogeneous(NULL);
-  recursiveXBTGraphExtraction (ret, nodes, edges, routing_platf->root, PJ_container_get_root());
+  recursiveXBTGraphExtraction (ret, nodes, edges, surf_platf_get_root(routing_platf), PJ_container_get_root());
   xbt_dict_free (&nodes);
   xbt_dict_free (&edges);
   return ret;
@@ -648,6 +508,3 @@ void instr_routing_platform_graph_export_graphviz (xbt_graph_t g, const char *fi
   fclose(file);
 
 }
-
-#endif /* HAVE_TRACING */
-