Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid unnecessary copy by using a 'const' reference (sonar).
[simgrid.git] / src / instr / instr_platform.cpp
index 4f7288a..f08514b 100644 (file)
@@ -38,22 +38,16 @@ static simgrid::instr::Container* lowestCommonAncestor(const simgrid::instr::Con
 
   // create an array with all ancestors of a1
   std::vector<simgrid::instr::Container*> ancestors_a1;
-  simgrid::instr::Container* p = a1->father_;
-  while (p) {
+  for (auto* p = a1->father_; p != nullptr; p = p->father_)
     ancestors_a1.push_back(p);
-    p = p->father_;
-  }
 
   // create an array with all ancestors of a2
   std::vector<simgrid::instr::Container*> ancestors_a2;
-  p = a2->father_;
-  while (p) {
+  for (auto* p = a2->father_; p != nullptr; p = p->father_)
     ancestors_a2.push_back(p);
-    p = p->father_;
-  }
 
   // find the lowest ancestor
-  p     = nullptr;
+  simgrid::instr::Container* p = nullptr;
   int i = static_cast<int>(ancestors_a1.size()) - 1;
   int j = static_cast<int>(ancestors_a2.size()) - 1;
   while (i >= 0 && j >= 0) {
@@ -137,17 +131,15 @@ static void recursiveGraphExtraction(const simgrid::s4u::NetZone* netzone, simgr
   }
 
   auto* graph = xbt_graph_new_graph(0, nullptr);
-  auto* nodes = new std::map<std::string, xbt_node_t>();
-  auto* edges = new std::map<std::string, xbt_edge_t>();
+  std::map<std::string, xbt_node_t> nodes;
+  std::map<std::string, xbt_edge_t> edges;
 
-  netzone->get_impl()->get_graph(graph, nodes, edges);
-  for (auto elm : *edges) {
+  netzone->get_impl()->get_graph(graph, &nodes, &edges);
+  for (auto const& elm : edges) {
     const xbt_edge* edge = elm.second;
     linkContainers(simgrid::instr::Container::by_name(static_cast<const char*>(edge->src->data)),
                    simgrid::instr::Container::by_name(static_cast<const char*>(edge->dst->data)), filter);
   }
-  delete nodes;
-  delete edges;
   xbt_graph_free_graph(graph, xbt_free_f, xbt_free_f, nullptr);
 }
 
@@ -225,9 +217,9 @@ namespace instr {
 void platform_graph_export_graphviz(const std::string& output_filename)
 {
   auto* g     = xbt_graph_new_graph(0, nullptr);
-  auto* nodes = new std::map<std::string, xbt_node_t>();
-  auto* edges = new std::map<std::string, xbt_edge_t>();
-  s4u::Engine::get_instance()->get_netzone_root()->extract_xbt_graph(g, nodes, edges);
+  std::map<std::string, xbt_node_t> nodes;
+  std::map<std::string, xbt_edge_t> edges;
+  s4u::Engine::get_instance()->get_netzone_root()->extract_xbt_graph(g, &nodes, &edges);
 
   std::ofstream fs;
   fs.open(output_filename, std::ofstream::out);
@@ -243,10 +235,10 @@ void platform_graph_export_graphviz(const std::string& output_filename)
   fs << "  node [shape=box, style=filled]" << std::endl;
   fs << "  node [width=.3, height=.3, style=filled, color=skyblue]" << std::endl << std::endl;
 
-  for (auto const& elm : *nodes)
+  for (auto const& elm : nodes)
     fs << "  \"" << elm.first << "\";" << std::endl;
 
-  for (auto const& elm : *edges) {
+  for (auto const& elm : edges) {
     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)
@@ -258,8 +250,6 @@ void platform_graph_export_graphviz(const std::string& output_filename)
   fs.close();
 
   xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
-  delete nodes;
-  delete edges;
 }
 
 /* Callbacks */
@@ -276,7 +266,6 @@ static void on_netzone_creation(s4u::NetZone const& netzone)
       if (not TRACE_smpi_is_grouped())
         mpi->by_name_or_create<StateType>("MPI_STATE");
       root->type_->by_name_or_create("MPI_LINK", mpi, mpi);
-      // TODO See if we can move this to the LoadBalancer plugin
       root->type_->by_name_or_create("MIGRATE_LINK", mpi, mpi);
       mpi->by_name_or_create<StateType>("MIGRATE_STATE");
     }
@@ -336,7 +325,6 @@ static void on_host_creation(s4u::Host const& host)
   if (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped()) {
     auto* mpi = container->type_->by_name_or_create<ContainerType>("MPI");
     mpi->by_name_or_create<StateType>("MPI_STATE");
-    // TODO See if we can move this to the LoadBalancer plugin
     root->type_->by_name_or_create("MIGRATE_LINK", mpi, mpi);
     mpi->by_name_or_create<StateType>("MIGRATE_STATE");
   }
@@ -368,11 +356,10 @@ static void on_action_state_change(kernel::resource::Action const& action,
 static void on_platform_created()
 {
   currentContainer.clear();
-  auto* filter = new std::set<std::string>();
+  std::set<std::string> filter;
   XBT_DEBUG("Starting graph extraction.");
-  recursiveGraphExtraction(s4u::Engine::get_instance()->get_netzone_root(), Container::get_root(), filter);
+  recursiveGraphExtraction(s4u::Engine::get_instance()->get_netzone_root(), Container::get_root(), &filter);
   XBT_DEBUG("Graph extraction finished.");
-  delete filter;
   dump_buffer(true);
 }