Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'factor_in_actions' into 'master'
[simgrid.git] / src / instr / instr_platform.cpp
index 287d531..6db1c3b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2021. 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. */
@@ -75,9 +75,7 @@ static void linkContainers(simgrid::instr::Container* src, simgrid::instr::Conta
 
   // find common father
   simgrid::instr::Container* father = lowestCommonAncestor(src, dst);
-  if (not father) {
-    xbt_die("common father unknown, this is a tracing problem");
-  }
+  xbt_assert(father, "common father unknown, this is a tracing problem");
 
   // check if we already register this pair (we only need one direction)
   std::string aux1 = src->get_name() + dst->get_name();
@@ -122,12 +120,11 @@ static void recursiveGraphExtraction(const simgrid::s4u::NetZone* netzone, simgr
     return;
   }
   XBT_DEBUG("Graph extraction for NetZone = %s", netzone->get_cname());
-  if (not netzone->get_children().empty()) {
-    // bottom-up recursion
-    for (auto const& nz_son : netzone->get_children()) {
-      simgrid::instr::Container* child_container = container->children_.at(nz_son->get_name());
-      recursiveGraphExtraction(nz_son, child_container, filter);
-    }
+
+  // bottom-up recursion
+  for (auto const& nz_son : netzone->get_children()) {
+    simgrid::instr::Container* child_container = container->children_.at(nz_son->get_name());
+    recursiveGraphExtraction(nz_son, child_container, filter);
   }
 
   auto* graph = xbt_graph_new_graph(0, nullptr);
@@ -306,6 +303,9 @@ static void on_link_creation(s4u::Link const& link)
 
 static void on_host_creation(s4u::Host const& host)
 {
+  if (Container::by_name_or_null(host.get_name())) // This host already exists, do nothing
+    return;
+
   Container* container  = new HostContainer(host, currentContainer.back());
   const Container* root = Container::get_root();
 
@@ -336,20 +336,20 @@ static void on_action_state_change(kernel::resource::Action const& action,
   auto n = static_cast<unsigned>(action.get_variable()->get_number_of_constraint());
 
   for (unsigned i = 0; i < n; i++) {
-    double value = action.get_variable()->get_value() * action.get_variable()->get_constraint_weight(i);
+    double value = action.get_rate() * 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* */
     kernel::resource::Resource* resource = action.get_variable()->get_constraint(i)->get_id();
-    const kernel::resource::Cpu* cpu     = dynamic_cast<kernel::resource::Cpu*>(resource);
+    const kernel::resource::CpuImpl* cpu = dynamic_cast<kernel::resource::CpuImpl*>(resource);
 
     if (cpu != nullptr)
       resource_set_utilization("HOST", "speed_used", cpu->get_cname(), action.get_category(), value,
-                               action.get_last_update(), SIMIX_get_clock() - action.get_last_update());
+                               action.get_last_update(), simgrid_get_clock() - action.get_last_update());
 
     const kernel::resource::LinkImpl* link = dynamic_cast<kernel::resource::LinkImpl*>(resource);
 
     if (link != nullptr)
       resource_set_utilization("LINK", "bandwidth_used", link->get_cname(), action.get_category(), value,
-                               action.get_last_update(), SIMIX_get_clock() - action.get_last_update());
+                               action.get_last_update(), simgrid_get_clock() - action.get_last_update());
   }
 }
 
@@ -465,31 +465,33 @@ void define_callbacks()
     });
     s4u::Actor::on_wake_up.connect(
         [](s4u::Actor const& actor) { Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->pop_event(); });
-    s4u::Exec::on_start.connect([](simgrid::s4u::Actor const& actor, s4u::Exec const&) {
-      Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->push_event("execute");
+    s4u::Exec::on_start.connect([](s4u::Exec const&) {
+      Container::by_name(instr_pid(*s4u::Actor::self()))->get_state("ACTOR_STATE")->push_event("execute");
     });
-    s4u::Exec::on_completion.connect([](s4u::Actor const& actor, s4u::Exec const&) {
-      Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->pop_event();
+    s4u::Exec::on_completion.connect([](s4u::Exec const&) {
+      Container::by_name(instr_pid(*s4u::Actor::self()))->get_state("ACTOR_STATE")->pop_event();
     });
-    s4u::Comm::on_sender_start.connect([](s4u::Actor const& actor) {
-      Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->push_event("send");
+    s4u::Comm::on_start.connect([](s4u::Comm const&, bool is_sender) {
+      Container::by_name(instr_pid(*s4u::Actor::self()))
+          ->get_state("ACTOR_STATE")
+          ->push_event(is_sender ? "send" : "receive");
     });
-    s4u::Comm::on_receiver_start.connect([](s4u::Actor const& actor) {
-      Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->push_event("receive");
+    s4u::Comm::on_completion.connect([](s4u::Comm const&) {
+      Container::by_name(instr_pid(*s4u::Actor::self()))->get_state("ACTOR_STATE")->pop_event();
     });
-    s4u::Comm::on_completion.connect(
-        [](s4u::Actor const& actor) { Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->pop_event(); });
     s4u::Actor::on_host_change.connect(on_actor_host_change);
   }
 
   if (TRACE_smpi_is_enabled() && TRACE_smpi_is_computing()) {
-    s4u::Exec::on_start.connect([](simgrid::s4u::Actor const& actor, s4u::Exec const& exec) {
-      Container::by_name(std::string("rank-") + std::to_string(actor.get_pid()))
+    s4u::Exec::on_start.connect([](s4u::Exec const& exec) {
+      Container::by_name(std::string("rank-") + std::to_string(s4u::Actor::self()->get_pid()))
           ->get_state("MPI_STATE")
           ->push_event("computing", new CpuTIData("compute", exec.get_cost()));
     });
-    s4u::Exec::on_completion.connect([](s4u::Actor const& actor, s4u::Exec const&) {
-      Container::by_name(std::string("rank-") + std::to_string(actor.get_pid()))->get_state("MPI_STATE")->pop_event();
+    s4u::Exec::on_completion.connect([](s4u::Exec const&) {
+      Container::by_name(std::string("rank-") + std::to_string(s4u::Actor::self()->get_pid()))
+          ->get_state("MPI_STATE")
+          ->pop_event();
     });
   }