Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Sanitize the prototype of Actor::on_exit() callbacks
[simgrid.git] / src / instr / instr_platform.cpp
index 695fcb9..4bc1e2c 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2018. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2019. 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. */
@@ -8,7 +8,9 @@
 #include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/kernel/routing/NetZoneImpl.hpp"
 #include "simgrid/s4u/Actor.hpp"
+#include "simgrid/s4u/Comm.hpp"
 #include "simgrid/s4u/Engine.hpp"
+#include "simgrid/s4u/Exec.hpp"
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/s4u/VirtualMachine.hpp"
 #include "src/surf/cpu_interface.hpp"
@@ -130,7 +132,7 @@ static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_t
   if (not netzone->get_children().empty()) {
     // bottom-up recursion
     for (auto const& nz_son : netzone->get_children()) {
-      container_t child_container = container->children_.at(nz_son->get_cname());
+      container_t child_container = container->children_.at(nz_son->get_name());
       recursiveGraphExtraction(nz_son, child_container, filter);
     }
   }
@@ -158,6 +160,7 @@ static void instr_netzone_on_creation(simgrid::s4u::NetZone& netzone)
   std::string id = netzone.get_name();
   if (simgrid::instr::Container::get_root() == nullptr) {
     simgrid::instr::NetZoneContainer* root = new simgrid::instr::NetZoneContainer(id, 0, nullptr);
+    xbt_assert(simgrid::instr::Container::get_root() == root);
 
     if (TRACE_smpi_is_enabled()) {
       simgrid::instr::ContainerType* mpi = root->type_->by_name_or_create<simgrid::instr::ContainerType>("MPI");
@@ -208,13 +211,17 @@ static void instr_host_on_creation(simgrid::s4u::Host& host)
   container_t root      = simgrid::instr::Container::get_root();
 
   if ((TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) && (not TRACE_disable_speed())) {
-    simgrid::instr::VariableType* power = container->type_->by_name_or_create("power", "");
-    power->set_calling_container(container);
-    power->set_event(0, host.get_speed());
+    simgrid::instr::VariableType* speed = container->type_->by_name_or_create("speed", "");
+    speed->set_calling_container(container);
+    speed->set_event(0, host.get_speed());
+
+    simgrid::instr::VariableType* cores = container->type_->by_name_or_create("core_count", "");
+    cores->set_calling_container(container);
+    cores->set_event(0, host.get_core_count());
   }
 
   if (TRACE_uncategorized())
-    container->type_->by_name_or_create("power_used", "0.5 0.5 0.5");
+    container->type_->by_name_or_create("speed_used", "0.5 0.5 0.5");
 
   if (TRACE_smpi_is_enabled() && TRACE_smpi_is_grouped()) {
     simgrid::instr::ContainerType* mpi = container->type_->by_name_or_create<simgrid::instr::ContainerType>("MPI");
@@ -227,8 +234,8 @@ static void instr_host_on_creation(simgrid::s4u::Host& host)
 
 static void instr_host_on_speed_change(simgrid::s4u::Host& host)
 {
-  simgrid::instr::Container::by_name(host.get_cname())
-      ->get_variable("power")
+  simgrid::instr::Container::by_name(host.get_name())
+      ->get_variable("speed")
       ->set_event(surf_get_clock(), host.get_core_count() * host.get_available_speed());
 }
 
@@ -238,28 +245,27 @@ static void instr_action_on_state_change(simgrid::kernel::resource::Action* acti
   int n = action->get_variable()->get_number_of_constraint();
 
   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::surf::Cpu* cpu = dynamic_cast<simgrid::surf::Cpu*>(resource);
 
     if (cpu != nullptr)
-      TRACE_surf_resource_set_utilization("HOST", "power_used", cpu->get_cname(), action->get_category(),
-                                          action->get_variable()->get_value(), action->get_last_update(),
-                                          SIMIX_get_clock() - action->get_last_update());
+      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);
 
-    if (link != nullptr) {
-      double value = action->get_variable()->get_value() * action->get_variable()->get_constraint_weight(i);
+    if (link != nullptr)
       TRACE_surf_resource_set_utilization("LINK", "bandwidth_used", link->get_cname(), action->get_category(), value,
                                           action->get_last_update(), SIMIX_get_clock() - action->get_last_update());
-    }
   }
 }
 
 static void instr_link_on_bandwidth_change(simgrid::s4u::Link& link)
 {
-  simgrid::instr::Container::by_name(link.get_cname())
+  simgrid::instr::Container::by_name(link.get_name())
       ->get_variable("bandwidth")
       ->set_event(surf_get_clock(), sg_bandwidth_factor * link.get_bandwidth());
 }
@@ -267,7 +273,7 @@ static void instr_link_on_bandwidth_change(simgrid::s4u::Link& link)
 static void instr_netpoint_on_creation(simgrid::kernel::routing::NetPoint* netpoint)
 {
   if (netpoint->is_router())
-    new simgrid::instr::RouterContainer(netpoint->get_cname(), currentContainer.back());
+    new simgrid::instr::RouterContainer(netpoint->get_name(), currentContainer.back());
 }
 
 static void instr_on_platform_created()
@@ -295,17 +301,16 @@ static void instr_actor_on_creation(simgrid::s4u::ActorPtr actor)
   state->add_entity_value("sleep", "1 1 0");
   state->add_entity_value("receive", "1 0 0");
   state->add_entity_value("send", "0 0 1");
-  state->add_entity_value("task_execute", "0 1 1");
+  state->add_entity_value("execute", "0 1 1");
   root->type_->by_name_or_create("ACTOR_LINK", actor_type, actor_type);
   root->type_->by_name_or_create("ACTOR_TASK_LINK", actor_type, actor_type);
 
-  actor->on_exit(
-      [](int status, void* actor) {
-        if (status == SMX_EXIT_FAILURE)
-          // kill means that this actor no longer exists, let's destroy it
-          simgrid::instr::Container::by_name(instr_pid(static_cast<simgrid::s4u::Actor*>(actor)))->remove_from_parent();
-      },
-      actor->get_impl());
+  std::string container_name = instr_pid(actor.get());
+  actor->on_exit([container_name](bool failed) {
+    if (failed)
+      // kill means that this actor no longer exists, let's destroy it
+      simgrid::instr::Container::by_name(container_name)->remove_from_parent();
+  });
 }
 
 static long long int counter = 0;
@@ -341,7 +346,7 @@ static void instr_vm_on_creation(simgrid::s4u::Host& host)
   state->add_entity_value("sleep", "1 1 0");
   state->add_entity_value("receive", "1 0 0");
   state->add_entity_value("send", "0 0 1");
-  state->add_entity_value("task_execute", "0 1 1");
+  state->add_entity_value("execute", "0 1 1");
   root->type_->by_name_or_create("VM_LINK", vm, vm);
   root->type_->by_name_or_create("VM_ACTOR_LINK", vm, vm);
 }
@@ -366,6 +371,11 @@ void instr_define_callbacks()
 
   if (TRACE_actor_is_enabled()) {
     simgrid::s4u::Actor::on_creation.connect(instr_actor_on_creation);
+    simgrid::s4u::Actor::on_destruction.connect([](simgrid::s4u::ActorPtr actor) {
+      auto container = simgrid::instr::Container::by_name_or_null(instr_pid(actor.get()));
+      if (container != nullptr)
+        container->remove_from_parent();
+    });
     simgrid::s4u::Actor::on_suspend.connect([](simgrid::s4u::ActorPtr actor) {
       simgrid::instr::Container::by_name(instr_pid(actor.get()))->get_state("ACTOR_STATE")->push_event("suspend");
     });
@@ -378,6 +388,21 @@ void instr_define_callbacks()
     simgrid::s4u::Actor::on_wake_up.connect([](simgrid::s4u::ActorPtr actor) {
       simgrid::instr::Container::by_name(instr_pid(actor.get()))->get_state("ACTOR_STATE")->pop_event();
     });
+    simgrid::s4u::Exec::on_start.connect([](simgrid::s4u::ActorPtr actor) {
+      simgrid::instr::Container::by_name(instr_pid(actor.get()))->get_state("ACTOR_STATE")->push_event("execute");
+    });
+    simgrid::s4u::Exec::on_completion.connect([](simgrid::s4u::ActorPtr actor) {
+      simgrid::instr::Container::by_name(instr_pid(actor.get()))->get_state("ACTOR_STATE")->pop_event();
+    });
+    simgrid::s4u::Comm::on_sender_start.connect([](simgrid::s4u::ActorPtr actor) {
+      simgrid::instr::Container::by_name(instr_pid(actor.get()))->get_state("ACTOR_STATE")->push_event("send");
+    });
+    simgrid::s4u::Comm::on_receiver_start.connect([](simgrid::s4u::ActorPtr actor) {
+      simgrid::instr::Container::by_name(instr_pid(actor.get()))->get_state("ACTOR_STATE")->push_event("receive");
+    });
+    simgrid::s4u::Comm::on_completion.connect([](simgrid::s4u::ActorPtr actor) {
+      simgrid::instr::Container::by_name(instr_pid(actor.get()))->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);
   }
@@ -403,7 +428,8 @@ void instr_define_callbacks()
 /*
  * user categories support
  */
-static void recursiveNewVariableType(std::string new_typename, std::string color, simgrid::instr::Type* root)
+static void recursiveNewVariableType(const std::string& new_typename, const std::string& color,
+                                     simgrid::instr::Type* root)
 {
   if (root->get_name() == "HOST" || root->get_name() == "VM")
     root->by_name_or_create(std::string("p") + new_typename, color);
@@ -416,13 +442,13 @@ static void recursiveNewVariableType(std::string new_typename, std::string color
   }
 }
 
-void instr_new_variable_type(std::string new_typename, std::string color)
+void instr_new_variable_type(const std::string& new_typename, const std::string& color)
 {
   recursiveNewVariableType(new_typename, color, simgrid::instr::Container::get_root()->type_);
 }
 
-static void recursiveNewUserVariableType(std::string father_type, std::string new_typename, std::string color,
-                                         simgrid::instr::Type* root)
+static void recursiveNewUserVariableType(const std::string& father_type, const std::string& new_typename,
+                                         const std::string& color, simgrid::instr::Type* root)
 {
   if (root->get_name() == father_type) {
     root->by_name_or_create(new_typename, color);
@@ -431,12 +457,14 @@ static void recursiveNewUserVariableType(std::string father_type, std::string ne
     recursiveNewUserVariableType(father_type, new_typename, color, elm.second);
 }
 
-void instr_new_user_variable_type(std::string father_type, std::string new_typename, std::string color)
+void instr_new_user_variable_type(const std::string& father_type, const std::string& new_typename,
+                                  const std::string& color)
 {
   recursiveNewUserVariableType(father_type, new_typename, color, simgrid::instr::Container::get_root()->type_);
 }
 
-static void recursiveNewUserStateType(std::string father_type, std::string new_typename, simgrid::instr::Type* root)
+static void recursiveNewUserStateType(const std::string& father_type, const std::string& new_typename,
+                                      simgrid::instr::Type* root)
 {
   if (root->get_name() == father_type)
     root->by_name_or_create<simgrid::instr::StateType>(new_typename);
@@ -445,12 +473,12 @@ static void recursiveNewUserStateType(std::string father_type, std::string new_t
     recursiveNewUserStateType(father_type, new_typename, elm.second);
 }
 
-void instr_new_user_state_type(std::string father_type, std::string new_typename)
+void instr_new_user_state_type(const std::string& father_type, const std::string& new_typename)
 {
   recursiveNewUserStateType(father_type, new_typename, simgrid::instr::Container::get_root()->type_);
 }
 
-static void recursiveNewValueForUserStateType(std::string type_name, const char* val, std::string color,
+static void recursiveNewValueForUserStateType(const std::string& type_name, const char* val, const std::string& color,
                                               simgrid::instr::Type* root)
 {
   if (root->get_name() == type_name)
@@ -460,7 +488,7 @@ static void recursiveNewValueForUserStateType(std::string type_name, const char*
     recursiveNewValueForUserStateType(type_name, val, color, elm.second);
 }
 
-void instr_new_value_for_user_state_type(std::string type_name, const char* value, std::string color)
+void instr_new_value_for_user_state_type(const std::string& type_name, const char* value, const std::string& color)
 {
   recursiveNewValueForUserStateType(type_name, value, color, simgrid::instr::Container::get_root()->type_);
 }
@@ -474,7 +502,7 @@ static void recursiveXBTGraphExtraction(xbt_graph_t graph, std::map<std::string,
   if (not netzone->get_children().empty()) {
     // bottom-up recursion
     for (auto const& netzone_child : netzone->get_children()) {
-      container_t child_container = container->children_.at(netzone_child->get_cname());
+      container_t child_container = container->children_.at(netzone_child->get_name());
       recursiveXBTGraphExtraction(graph, nodes, edges, netzone_child, child_container);
     }
   }