Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
the extraction of the graph is a NetZone method
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sun, 29 Mar 2020 17:20:39 +0000 (19:20 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sun, 29 Mar 2020 17:54:31 +0000 (19:54 +0200)
include/simgrid/s4u/NetZone.hpp
src/instr/instr_platform.cpp
src/s4u/s4u_Netzone.cpp

index 741fa71..537ab6e 100644 (file)
@@ -7,8 +7,10 @@
 #define SIMGRID_S4U_NETZONE_HPP
 
 #include <simgrid/forward.h>
+#include <xbt/graph.h>
 #include <xbt/signal.hpp>
 
+#include <map>
 #include <string>
 #include <unordered_map>
 #include <utility>
@@ -53,6 +55,8 @@ public:
   void set_property(const std::string& key, const std::string& value);
 
   std::vector<NetZone*> get_children() const;
+  void extract_xbt_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t>* nodes,
+                         std::map<std::string, xbt_edge_t>* edges);
 
   /* Add content to the netzone, at parsing time. It should be sealed afterward. */
   int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
index f273438..8de841b 100644 (file)
@@ -29,11 +29,6 @@ std::string instr_pid(simgrid::s4u::Actor const& proc)
   return std::string(proc.get_name()) + "-" + std::to_string(proc.get_pid());
 }
 
-static const char* instr_node_name(const s_xbt_node_t* node)
-{
-  return static_cast<char*>(xbt_graph_node_get_data(node));
-}
-
 static container_t lowestCommonAncestor(const simgrid::instr::Container* a1, const simgrid::instr::Container* a2)
 {
   // this is only an optimization (since most of a1 and a2 share the same parent)
@@ -222,16 +217,6 @@ void instr_new_value_for_user_state_type(const std::string& type_name, const cha
   recursiveNewValueForUserStateType(type_name, value, color, simgrid::instr::Container::get_root()->type_);
 }
 
-static void recursiveXBTGraphExtraction(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t>* nodes,
-                                        std::map<std::string, xbt_edge_t>* edges, const_sg_netzone_t netzone)
-{
-  // bottom-up recursion
-  for (auto const& netzone_child : netzone->get_children())
-    recursiveXBTGraphExtraction(graph, nodes, edges, netzone_child);
-
-  netzone->get_impl()->get_graph(graph, nodes, edges);
-}
-
 namespace simgrid {
 namespace instr {
 
@@ -240,7 +225,7 @@ void platform_graph_export_graphviz(const std::string& output_filename)
   xbt_graph_t g                            = xbt_graph_new_graph(0, nullptr);
   std::map<std::string, xbt_node_t>* nodes = new std::map<std::string, xbt_node_t>();
   std::map<std::string, xbt_edge_t>* edges = new std::map<std::string, xbt_edge_t>();
-  recursiveXBTGraphExtraction(g, nodes, edges, s4u::Engine::get_instance()->get_netzone_root());
+  s4u::Engine::get_instance()->get_netzone_root()->extract_xbt_graph(g, nodes, edges);
 
   std::ofstream fs;
   fs.open(output_filename, std::ofstream::out);
@@ -257,11 +242,11 @@ void platform_graph_export_graphviz(const std::string& output_filename)
   fs << "  node [width=.3, height=.3, style=filled, color=skyblue]" << std::endl << std::endl;
 
   for (auto const& elm : *nodes)
-    fs << "  \"" << instr_node_name(elm.second) << "\";" << std::endl;
+    fs << "  \"" << elm.first << "\";" << std::endl;
 
   for (auto const& elm : *edges) {
-    const char* src_s = instr_node_name(elm.second->src);
-    const char* dst_s = instr_node_name(elm.second->dst);
+    const char* src_s = static_cast<char*>(elm.second->src->data);
+    const char* dst_s = static_cast<char*>(elm.second->dst->data);
     if (g->directed)
       fs << "  \"" << src_s << "\" -> \"" << dst_s << "\";" << std::endl;
     else
index 4fab50a..6109f66 100644 (file)
@@ -89,6 +89,15 @@ void NetZone::add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::
 {
   pimpl_->add_bypass_route(src, dst, gw_src, gw_dst, link_list, symmetrical);
 }
+
+void NetZone::extract_xbt_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t>* nodes,
+                                std::map<std::string, xbt_edge_t>* edges)
+{
+  for (auto const& child : get_children())
+    child->extract_xbt_graph(graph, nodes, edges);
+
+  pimpl_->get_graph(graph, nodes, edges);
+}
 } // namespace s4u
 } // namespace simgrid