Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MSG_VM => VM in instr
[simgrid.git] / src / instr / instr_platform.cpp
index b7b6375..293ae81 100644 (file)
@@ -7,8 +7,10 @@
 
 #include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/Actor.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/VirtualMachine.hpp"
 #include "src/surf/network_interface.hpp"
 #include "src/surf/xml/platf_private.hpp"
 #include "surf/surf.hpp"
@@ -131,7 +133,7 @@ static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_t
     }
   }
 
-  xbt_graph_t graph = xbt_graph_new_graph(0, nullptr);
+  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>;
 
@@ -227,30 +229,6 @@ static void instr_host_on_creation(simgrid::s4u::Host& host)
     root->type_->getOrCreateLinkType("MIGRATE_LINK", mpi, mpi);
     mpi->getOrCreateStateType("MIGRATE_STATE");
   }
-
-  if (TRACE_actor_is_enabled()) {
-    simgrid::instr::ContainerType* actor = container->type_->getOrCreateContainerType("ACTOR");
-    simgrid::instr::StateType* state     = actor->getOrCreateStateType("ACTOR_STATE");
-    state->addEntityValue("suspend", "1 0 1");
-    state->addEntityValue("sleep", "1 1 0");
-    state->addEntityValue("receive", "1 0 0");
-    state->addEntityValue("send", "0 0 1");
-    state->addEntityValue("task_execute", "0 1 1");
-    root->type_->getOrCreateLinkType("ACTOR_LINK", actor, actor);
-    root->type_->getOrCreateLinkType("ACTOR_TASK_LINK", actor, actor);
-  }
-
-  if (TRACE_vm_is_enabled()) {
-    simgrid::instr::ContainerType* msg_vm = container->type_->getOrCreateContainerType("MSG_VM");
-    simgrid::instr::StateType* state      = msg_vm->getOrCreateStateType("MSG_VM_STATE");
-    state->addEntityValue("suspend", "1 0 1");
-    state->addEntityValue("sleep", "1 1 0");
-    state->addEntityValue("receive", "1 0 0");
-    state->addEntityValue("send", "0 0 1");
-    state->addEntityValue("task_execute", "0 1 1");
-    root->type_->getOrCreateLinkType("MSG_VM_LINK", msg_vm, msg_vm);
-    root->type_->getOrCreateLinkType("MSG_VM_ACTOR_LINK", msg_vm, msg_vm);
-  }
 }
 
 static void instr_netpoint_on_creation(simgrid::kernel::routing::NetPoint* netpoint)
@@ -264,13 +242,103 @@ static void instr_on_platform_created()
   currentContainer.clear();
   std::set<std::string>* filter = new std::set<std::string>;
   XBT_DEBUG("Starting graph extraction.");
-  recursiveGraphExtraction(simgrid::s4u::Engine::getInstance()->getNetRoot(), simgrid::instr::Container::getRoot(),
+  recursiveGraphExtraction(simgrid::s4u::Engine::get_instance()->getNetRoot(), simgrid::instr::Container::getRoot(),
                            filter);
   XBT_DEBUG("Graph extraction finished.");
   delete filter;
   TRACE_paje_dump_buffer(true);
 }
 
+static void instr_actor_on_creation(simgrid::s4u::ActorPtr actor)
+{
+  container_t root      = simgrid::instr::Container::getRoot();
+  container_t container = simgrid::instr::Container::byName(actor->get_host()->get_name());
+
+  container->createChild(instr_pid(actor.get()), "ACTOR");
+  simgrid::instr::ContainerType* actor_type = container->type_->getOrCreateContainerType("ACTOR");
+  simgrid::instr::StateType* state          = actor_type->getOrCreateStateType("ACTOR_STATE");
+  state->addEntityValue("suspend", "1 0 1");
+  state->addEntityValue("sleep", "1 1 0");
+  state->addEntityValue("receive", "1 0 0");
+  state->addEntityValue("send", "0 0 1");
+  state->addEntityValue("task_execute", "0 1 1");
+  root->type_->getOrCreateLinkType("ACTOR_LINK", actor_type, actor_type);
+  root->type_->getOrCreateLinkType("ACTOR_TASK_LINK", actor_type, actor_type);
+}
+
+static void instr_actor_on_suspend(simgrid::s4u::ActorPtr actor)
+{
+  simgrid::instr::Container::byName(instr_pid(actor.get()))->getState("ACTOR_STATE")->pushEvent("suspend");
+}
+
+static void instr_actor_on_resume(simgrid::s4u::ActorPtr actor)
+{
+  simgrid::instr::Container::byName(instr_pid(actor.get()))->getState("ACTOR_STATE")->popEvent();
+}
+
+static long long int counter = 0;
+
+static void instr_actor_on_migration_start(simgrid::s4u::ActorPtr actor)
+{
+  // start link
+  container_t container = simgrid::instr::Container::byName(instr_pid(actor.get()));
+  simgrid::instr::Container::getRoot()->getLink("ACTOR_LINK")->startEvent(container, "M", std::to_string(counter));
+
+  // destroy existing container of this process
+  container->removeFromParent();
+}
+
+static void instr_actor_on_migration_end(simgrid::s4u::ActorPtr actor)
+{
+  // create new container on the new_host location
+  simgrid::instr::Container::byName(actor->get_host()->get_name())->createChild(instr_pid(actor.get()), "ACTOR");
+  // end link
+  simgrid::instr::Container::getRoot()
+      ->getLink("ACTOR_LINK")
+      ->endEvent(simgrid::instr::Container::byName(instr_pid(actor.get())), "M", std::to_string(counter));
+  counter++;
+}
+
+static void instr_vm_on_creation(simgrid::s4u::Host& host)
+{
+  container_t container                 = new simgrid::instr::HostContainer(host, currentContainer.back());
+  container_t root                      = simgrid::instr::Container::getRoot();
+  simgrid::instr::ContainerType* msg_vm = container->type_->getOrCreateContainerType("VM");
+  simgrid::instr::StateType* state      = msg_vm->getOrCreateStateType("VM_STATE");
+  state->addEntityValue("suspend", "1 0 1");
+  state->addEntityValue("sleep", "1 1 0");
+  state->addEntityValue("receive", "1 0 0");
+  state->addEntityValue("send", "0 0 1");
+  state->addEntityValue("task_execute", "0 1 1");
+  root->type_->getOrCreateLinkType("VM_LINK", msg_vm, msg_vm);
+  root->type_->getOrCreateLinkType("VM_ACTOR_LINK", msg_vm, msg_vm);
+}
+
+static void instr_vm_on_start(simgrid::s4u::VirtualMachine& vm)
+{
+  simgrid::instr::Container::byName(vm.get_name())->getState("VM_STATE")->pushEvent("start");
+}
+
+static void instr_vm_on_started(simgrid::s4u::VirtualMachine& vm)
+{
+  simgrid::instr::Container::byName(vm.get_name())->getState("VM_STATE")->popEvent();
+}
+
+static void instr_vm_on_suspend(simgrid::s4u::VirtualMachine& vm)
+{
+  simgrid::instr::Container::byName(vm.get_name())->getState("VM_STATE")->pushEvent("suspend");
+}
+
+static void instr_vm_on_resume(simgrid::s4u::VirtualMachine& vm)
+{
+  simgrid::instr::Container::byName(vm.get_name())->getState("VM_STATE")->popEvent();
+}
+
+static void instr_vm_on_destruction(simgrid::s4u::Host& host)
+{
+  simgrid::instr::Container::byName(host.get_name())->removeFromParent();
+}
+
 void instr_define_callbacks()
 {
   // always need the callbacks to zones (we need only the root zone), to create the rootContainer and the rootType
@@ -283,13 +351,30 @@ void instr_define_callbacks()
   simgrid::s4u::NetZone::onCreation.connect(instr_netzone_on_creation);
   simgrid::s4u::NetZone::onSeal.connect(instr_netzone_on_seal);
   simgrid::kernel::routing::NetPoint::onCreation.connect(instr_netpoint_on_creation);
+
+  if (TRACE_actor_is_enabled()) {
+    simgrid::s4u::Actor::on_creation.connect(instr_actor_on_creation);
+    simgrid::s4u::Actor::on_suspend.connect(instr_actor_on_suspend);
+    simgrid::s4u::Actor::on_resume.connect(instr_actor_on_resume);
+    simgrid::s4u::Actor::on_migration_start.connect(instr_actor_on_migration_start);
+    simgrid::s4u::Actor::on_migration_end.connect(instr_actor_on_migration_end);
+  }
+
+  if (TRACE_vm_is_enabled()) {
+    simgrid::s4u::Host::onCreation.connect(instr_vm_on_creation);
+    simgrid::s4u::VirtualMachine::on_start.connect(instr_vm_on_start);
+    simgrid::s4u::VirtualMachine::on_started.connect(instr_vm_on_started);
+    simgrid::s4u::VirtualMachine::on_suspend.connect(instr_vm_on_suspend);
+    simgrid::s4u::VirtualMachine::on_resume.connect(instr_vm_on_resume);
+    simgrid::s4u::Host::onDestruction.connect(instr_vm_on_destruction);
+  }
 }
 /*
  * user categories support
  */
 static void recursiveNewVariableType(std::string new_typename, std::string color, simgrid::instr::Type* root)
 {
-  if (root->get_name() == "HOST" || root->get_name() == "MSG_VM")
+  if (root->get_name() == "HOST" || root->get_name() == "VM")
     root->getOrCreateVariableType(std::string("p") + new_typename, color);
 
   if (root->get_name() == "LINK")
@@ -368,10 +453,10 @@ 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);
+  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>;
-  recursiveXBTGraphExtraction(ret, nodes, edges, simgrid::s4u::Engine::getInstance()->getNetRoot(),
+  recursiveXBTGraphExtraction(ret, nodes, edges, simgrid::s4u::Engine::get_instance()->getNetRoot(),
                               simgrid::instr::Container::getRoot());
   delete nodes;
   delete edges;