Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add the Storage::read_async and Storage::write_async methods
[simgrid.git] / src / instr / instr_platform.cpp
index fe2f6e8..6a564f9 100644 (file)
@@ -127,9 +127,9 @@ static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_t
     return;
   }
   XBT_DEBUG("Graph extraction for NetZone = %s", netzone->get_cname());
-  if (not netzone->getChildren()->empty()) {
+  if (not netzone->get_children().empty()) {
     // bottom-up recursion
-    for (auto const& nz_son : *netzone->getChildren()) {
+    for (auto const& nz_son : netzone->get_children()) {
       container_t child_container = container->children_.at(nz_son->get_cname());
       recursiveGraphExtraction(nz_son, child_container, filter);
     }
@@ -139,7 +139,7 @@ static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_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>;
 
-  static_cast<simgrid::kernel::routing::NetZoneImpl*>(netzone)->get_graph(graph, nodes, edges);
+  netzone->get_impl()->get_graph(graph, nodes, edges);
   for (auto elm : *edges) {
     xbt_edge_t edge = elm.second;
     linkContainers(simgrid::instr::Container::by_name(static_cast<const char*>(edge->src->data)),
@@ -208,13 +208,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.getSpeed());
+    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");
@@ -228,31 +232,34 @@ 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")
-      ->set_event(surf_get_clock(), host.getCoreCount() * host.get_available_speed());
+      ->get_variable("speed")
+      ->set_event(surf_get_clock(), host.get_core_count() * host.get_available_speed());
 }
 
-static void instr_cpu_action_on_state_change(simgrid::surf::CpuAction* action,
-                                             simgrid::kernel::resource::Action::State /* previous */)
-{
-  simgrid::surf::Cpu* cpu = static_cast<simgrid::surf::Cpu*>(action->get_variable()->get_constraint(0)->get_id());
-  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());
-}
-
-static void instr_link_on_communication_state_change(simgrid::kernel::resource::NetworkAction* action)
+static void instr_action_on_state_change(simgrid::kernel::resource::Action* action,
+                                         simgrid::kernel::resource::Action::State /* previous */)
 {
   int n = action->get_variable()->get_number_of_constraint();
 
   for (int i = 0; i < n; i++) {
-    simgrid::kernel::lmm::Constraint* constraint = action->get_variable()->get_constraint(i);
-    simgrid::kernel::resource::LinkImpl* link = static_cast<simgrid::kernel::resource::LinkImpl*>(constraint->get_id());
     double value = action->get_variable()->get_value() * action->get_variable()->get_constraint_weight(i);
-    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());
+    /* 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", "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)
+      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())
@@ -294,6 +301,15 @@ static void instr_actor_on_creation(simgrid::s4u::ActorPtr actor)
   state->add_entity_value("task_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);
+
+  std::string container_name = instr_pid(actor.get());
+  actor->on_exit(
+      [container_name](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(container_name)->remove_from_parent();
+      },
+      actor->get_impl());
 }
 
 static long long int counter = 0;
@@ -344,13 +360,13 @@ void instr_define_callbacks()
     simgrid::s4u::Host::on_speed_change.connect(instr_host_on_speed_change);
     simgrid::s4u::Link::on_creation.connect(instr_link_on_creation);
     simgrid::s4u::Link::on_bandwidth_change.connect(instr_link_on_bandwidth_change);
-    simgrid::s4u::NetZone::onSeal.connect([](simgrid::s4u::NetZone& /*netzone*/) { currentContainer.pop_back(); });
-    simgrid::kernel::routing::NetPoint::onCreation.connect(instr_netpoint_on_creation);
+    simgrid::s4u::NetZone::on_seal.connect([](simgrid::s4u::NetZone& /*netzone*/) { currentContainer.pop_back(); });
+    simgrid::kernel::routing::NetPoint::on_creation.connect(instr_netpoint_on_creation);
   }
-  simgrid::s4u::NetZone::onCreation.connect(instr_netzone_on_creation);
+  simgrid::s4u::NetZone::on_creation.connect(instr_netzone_on_creation);
 
-  simgrid::surf::CpuAction::onStateChange.connect(instr_cpu_action_on_state_change);
-  simgrid::s4u::Link::on_communication_state_change.connect(instr_link_on_communication_state_change);
+  simgrid::surf::CpuAction::on_state_change.connect(instr_action_on_state_change);
+  simgrid::s4u::Link::on_communication_state_change.connect(instr_action_on_state_change);
 
   if (TRACE_actor_is_enabled()) {
     simgrid::s4u::Actor::on_creation.connect(instr_actor_on_creation);
@@ -459,15 +475,15 @@ static void recursiveXBTGraphExtraction(xbt_graph_t graph, std::map<std::string,
                                         std::map<std::string, xbt_edge_t>* edges, sg_netzone_t netzone,
                                         container_t container)
 {
-  if (not netzone->getChildren()->empty()) {
+  if (not netzone->get_children().empty()) {
     // bottom-up recursion
-    for (auto const& netzone_child : *netzone->getChildren()) {
+    for (auto const& netzone_child : netzone->get_children()) {
       container_t child_container = container->children_.at(netzone_child->get_cname());
       recursiveXBTGraphExtraction(graph, nodes, edges, netzone_child, child_container);
     }
   }
 
-  static_cast<simgrid::kernel::routing::NetZoneImpl*>(netzone)->get_graph(graph, nodes, edges);
+  netzone->get_impl()->get_graph(graph, nodes, edges);
 }
 
 xbt_graph_t instr_routing_platform_graph()