Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a cmake flag to not compile MSG at all
[simgrid.git] / src / instr / instr_platform.cpp
index a19c699..fc6fde1 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2020. 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. */
@@ -24,12 +24,17 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_routing, instr, "Tracing platform hierarch
 
 static std::vector<simgrid::instr::NetZoneContainer*> currentContainer; /* push and pop, used only in creation */
 
-static const char* instr_node_name(xbt_node_t node)
+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(container_t a1, container_t a2)
+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)
   if (a1->father_ == a2->father_)
@@ -57,7 +62,7 @@ static container_t lowestCommonAncestor(container_t a1, container_t a2)
   int j = ancestors_a2.size() - 1;
   while (i >= 0 && j >= 0) {
     container_t a1p = ancestors_a1.at(i);
-    container_t a2p = ancestors_a2.at(j);
+    const simgrid::instr::Container* a2p = ancestors_a2.at(j);
     if (a1p == a2p) {
       p = a1p;
     } else {
@@ -106,9 +111,6 @@ static void linkContainers(container_t src, container_t dst, std::set<std::strin
   simgrid::instr::LinkType* link = father->type_->by_name_or_create(link_typename, src->type_, dst->type_);
   link->set_calling_container(father);
 
-  // register EDGE types for triva configuration
-  trivaEdgeTypes.insert(link->get_name());
-
   // create the link
   static long long counter = 0;
 
@@ -121,7 +123,7 @@ static void linkContainers(container_t src, container_t dst, std::set<std::strin
   XBT_DEBUG("  linkContainers %s <-> %s", src->get_cname(), dst->get_cname());
 }
 
-static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_t container,
+static void recursiveGraphExtraction(const simgrid::s4u::NetZone* netzone, container_t container,
                                      std::set<std::string>* filter)
 {
   if (not TRACE_platform_topology()) {
@@ -138,12 +140,12 @@ static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_t
   }
 
   xbt_graph_t graph                        = 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>;
+  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>();
 
   netzone->get_impl()->get_graph(graph, nodes, edges);
   for (auto elm : *edges) {
-    xbt_edge_t edge = elm.second;
+    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);
   }
@@ -207,8 +209,8 @@ static void instr_link_on_creation(simgrid::s4u::Link const& link)
 
 static void instr_host_on_creation(simgrid::s4u::Host const& host)
 {
-  container_t container = new simgrid::instr::HostContainer(host, currentContainer.back());
-  container_t root      = simgrid::instr::Container::get_root();
+  simgrid::instr::Container* container  = new simgrid::instr::HostContainer(host, currentContainer.back());
+  const simgrid::instr::Container* root = simgrid::instr::Container::get_root();
 
   if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (not TRACE_disable_speed())) {
     simgrid::instr::VariableType* speed = container->type_->by_name_or_create("speed", "");
@@ -247,15 +249,14 @@ static void instr_action_on_state_change(simgrid::kernel::resource::Action const
   for (int i = 0; i < n; i++) {
     double value = action.get_variable()->get_value() * action.get_variable()->get_constraint_weight(i);
     /* Beware of composite actions: ptasks put links and cpus together. Extra pb: we cannot dynamic_cast from void* */
-    simgrid::kernel::resource::Resource* resource =
-        static_cast<simgrid::kernel::resource::Resource*>(action.get_variable()->get_constraint(i)->get_id());
-    simgrid::kernel::resource::Cpu* cpu = dynamic_cast<simgrid::kernel::resource::Cpu*>(resource);
+    simgrid::kernel::resource::Resource* resource = action.get_variable()->get_constraint(i)->get_id();
+    const simgrid::kernel::resource::Cpu* cpu     = dynamic_cast<simgrid::kernel::resource::Cpu*>(resource);
 
     if (cpu != nullptr)
       TRACE_surf_resource_set_utilization("HOST", "speed_used", cpu->get_cname(), action.get_category(), value,
                                           action.get_last_update(), SIMIX_get_clock() - action.get_last_update());
 
-    simgrid::kernel::resource::LinkImpl* link = dynamic_cast<simgrid::kernel::resource::LinkImpl*>(resource);
+    const simgrid::kernel::resource::LinkImpl* link = dynamic_cast<simgrid::kernel::resource::LinkImpl*>(resource);
 
     if (link != nullptr)
       TRACE_surf_resource_set_utilization("LINK", "bandwidth_used", link->get_cname(), action.get_category(), value,
@@ -279,7 +280,7 @@ static void instr_netpoint_on_creation(simgrid::kernel::routing::NetPoint const&
 static void instr_on_platform_created()
 {
   currentContainer.clear();
-  std::set<std::string>* filter = new std::set<std::string>;
+  std::set<std::string>* filter = new std::set<std::string>();
   XBT_DEBUG("Starting graph extraction.");
   recursiveGraphExtraction(simgrid::s4u::Engine::get_instance()->get_netzone_root(),
                            simgrid::instr::Container::get_root(), filter);
@@ -290,8 +291,8 @@ static void instr_on_platform_created()
 
 static void instr_actor_on_creation(simgrid::s4u::Actor const& actor)
 {
-  container_t root      = simgrid::instr::Container::get_root();
-  container_t container = simgrid::instr::Container::by_name(actor.get_host()->get_name());
+  const simgrid::instr::Container* root = simgrid::instr::Container::get_root();
+  simgrid::instr::Container* container  = simgrid::instr::Container::by_name(actor.get_host()->get_name());
 
   container->create_child(instr_pid(actor), "ACTOR");
   simgrid::instr::ContainerType* actor_type =
@@ -313,33 +314,28 @@ static void instr_actor_on_creation(simgrid::s4u::Actor const& actor)
   });
 }
 
-static long long int counter = 0;
-
-static void instr_actor_on_migration_start(simgrid::s4u::Actor const& actor)
+static void instr_actor_on_host_change(simgrid::s4u::Actor const& actor,
+                                       simgrid::s4u::Host const& /*previous_location*/)
 {
-  // start link
+  static long long int counter = 0;
   container_t container = simgrid::instr::Container::by_name(instr_pid(actor));
-  simgrid::instr::Container::get_root()->get_link("ACTOR_LINK")->start_event(container, "M", std::to_string(counter));
+  simgrid::instr::LinkType* link = simgrid::instr::Container::get_root()->get_link("ACTOR_LINK");
 
+  // start link
+  link->start_event(container, "M", std::to_string(counter));
   // destroy existing container of this process
   container->remove_from_parent();
-}
-
-static void instr_actor_on_migration_end(simgrid::s4u::Actor const& actor)
-{
   // create new container on the new_host location
   simgrid::instr::Container::by_name(actor.get_host()->get_name())->create_child(instr_pid(actor), "ACTOR");
   // end link
-  simgrid::instr::Container::get_root()
-      ->get_link("ACTOR_LINK")
-      ->end_event(simgrid::instr::Container::by_name(instr_pid(actor)), "M", std::to_string(counter));
+  link->end_event(simgrid::instr::Container::by_name(instr_pid(actor)), "M", std::to_string(counter));
   counter++;
 }
 
 static void instr_vm_on_creation(simgrid::s4u::Host const& host)
 {
-  container_t container             = new simgrid::instr::HostContainer(host, currentContainer.back());
-  container_t root                  = simgrid::instr::Container::get_root();
+  const simgrid::instr::Container* container = new simgrid::instr::HostContainer(host, currentContainer.back());
+  const simgrid::instr::Container* root      = simgrid::instr::Container::get_root();
   simgrid::instr::ContainerType* vm = container->type_->by_name_or_create<simgrid::instr::ContainerType>("VM");
   simgrid::instr::StateType* state  = vm->by_name_or_create<simgrid::instr::StateType>("VM_STATE");
   state->add_entity_value("suspend", "1 0 1");
@@ -356,7 +352,7 @@ void instr_define_callbacks()
   // always need the callbacks to zones (we need only the root zone), to create the rootContainer and the rootType
   // properly
   if (TRACE_needs_platform()) {
-    simgrid::s4u::on_platform_created.connect(instr_on_platform_created);
+    simgrid::s4u::Engine::on_platform_created.connect(instr_on_platform_created);
     simgrid::s4u::Host::on_creation.connect(instr_host_on_creation);
     simgrid::s4u::Host::on_speed_change.connect(instr_host_on_speed_change);
     simgrid::s4u::Link::on_creation.connect(instr_link_on_creation);
@@ -389,10 +385,10 @@ void instr_define_callbacks()
     simgrid::s4u::Actor::on_wake_up.connect([](simgrid::s4u::Actor const& actor) {
       simgrid::instr::Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->pop_event();
     });
-    simgrid::s4u::Exec::on_start.connect([](simgrid::s4u::Actor const& actor) {
+    simgrid::s4u::Exec::on_start.connect([](simgrid::s4u::Actor const& actor, simgrid::s4u::Exec const&) {
       simgrid::instr::Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->push_event("execute");
     });
-    simgrid::s4u::Exec::on_completion.connect([](simgrid::s4u::Actor const& actor) {
+    simgrid::s4u::Exec::on_completion.connect([](simgrid::s4u::Actor const& actor, simgrid::s4u::Exec const&) {
       simgrid::instr::Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->pop_event();
     });
     simgrid::s4u::Comm::on_sender_start.connect([](simgrid::s4u::Actor const& actor) {
@@ -404,8 +400,7 @@ void instr_define_callbacks()
     simgrid::s4u::Comm::on_completion.connect([](simgrid::s4u::Actor const& actor) {
       simgrid::instr::Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->pop_event();
     });
-    simgrid::s4u::Actor::on_migration_start.connect(instr_actor_on_migration_start);
-    simgrid::s4u::Actor::on_migration_end.connect(instr_actor_on_migration_end);
+    simgrid::s4u::Actor::on_host_change.connect(instr_actor_on_host_change);
   }
 
   if (TRACE_vm_is_enabled()) {
@@ -439,8 +434,8 @@ static void recursiveNewVariableType(const std::string& new_typename, const std:
   if (root->get_name() == "LINK")
     root->by_name_or_create(std::string("b") + new_typename, color);
 
-  for (auto elm : root->children_) {
-    recursiveNewVariableType(new_typename, color, elm.second);
+  for (auto const& elm : root->children_) {
+    recursiveNewVariableType(new_typename, color, elm.second.get());
   }
 }
 
@@ -455,8 +450,8 @@ static void recursiveNewUserVariableType(const std::string& father_type, const s
   if (root->get_name() == father_type) {
     root->by_name_or_create(new_typename, color);
   }
-  for (auto elm : root->children_)
-    recursiveNewUserVariableType(father_type, new_typename, color, elm.second);
+  for (auto const& elm : root->children_)
+    recursiveNewUserVariableType(father_type, new_typename, color, elm.second.get());
 }
 
 void instr_new_user_variable_type(const std::string& father_type, const std::string& new_typename,
@@ -471,8 +466,8 @@ static void recursiveNewUserStateType(const std::string& father_type, const std:
   if (root->get_name() == father_type)
     root->by_name_or_create<simgrid::instr::StateType>(new_typename);
 
-  for (auto elm : root->children_)
-    recursiveNewUserStateType(father_type, new_typename, elm.second);
+  for (auto const& elm : root->children_)
+    recursiveNewUserStateType(father_type, new_typename, elm.second.get());
 }
 
 void instr_new_user_state_type(const std::string& father_type, const std::string& new_typename)
@@ -486,8 +481,8 @@ static void recursiveNewValueForUserStateType(const std::string& type_name, cons
   if (root->get_name() == type_name)
     static_cast<simgrid::instr::StateType*>(root)->add_entity_value(val, color);
 
-  for (auto elm : root->children_)
-    recursiveNewValueForUserStateType(type_name, val, color, elm.second);
+  for (auto const& elm : root->children_)
+    recursiveNewValueForUserStateType(type_name, val, color, elm.second.get());
 }
 
 void instr_new_value_for_user_state_type(const std::string& type_name, const char* value, const std::string& color)
@@ -497,8 +492,8 @@ void instr_new_value_for_user_state_type(const std::string& type_name, const cha
 
 #define GRAPHICATOR_SUPPORT_FUNCTIONS
 
-static void recursiveXBTGraphExtraction(xbt_graph_t graph, std::map<std::string, xbt_node_t>* nodes,
-                                        std::map<std::string, xbt_edge_t>* edges, sg_netzone_t netzone,
+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,
                                         container_t container)
 {
   if (not netzone->get_children().empty()) {
@@ -515,8 +510,8 @@ static void recursiveXBTGraphExtraction(xbt_graph_t graph, std::map<std::string,
 xbt_graph_t instr_routing_platform_graph()
 {
   xbt_graph_t ret                          = 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>;
+  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(ret, nodes, edges, simgrid::s4u::Engine::get_instance()->get_netzone_root(),
                               simgrid::instr::Container::get_root());
   delete nodes;
@@ -524,7 +519,7 @@ xbt_graph_t instr_routing_platform_graph()
   return ret;
 }
 
-void instr_routing_platform_graph_export_graphviz(xbt_graph_t g, const char* filename)
+void instr_routing_platform_graph_export_graphviz(const s_xbt_graph_t* g, const char* filename)
 {
   unsigned int cursor = 0;
   xbt_node_t node     = nullptr;