Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
better example on monitoring s4u::Exec activities
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 9 Dec 2017 20:10:28 +0000 (21:10 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 9 Dec 2017 20:10:28 +0000 (21:10 +0100)
examples/s4u/exec-monitor/s4u-exec-monitor.cpp
examples/s4u/exec-monitor/s4u-exec-monitor.tesh

index 2af13c3..fb08720 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2014-2015, 2017. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2017. 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. */
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
 
-simgrid::s4u::ExecPtr activity;
-
-static void executor()
+static void monitor(simgrid::s4u::ExecPtr activity)
 {
-  const char* actor_name = simgrid::s4u::this_actor::getCname();
-  const char* host_name  = simgrid::s4u::Host::current()->getCname();
-
-  double clock_begin = simgrid::s4u::Engine::getClock();
-  XBT_INFO("%s:%s task 1 created %g", host_name, actor_name, clock_begin);
-  activity = simgrid::s4u::Actor::self()->exec_async(1e9);
-  activity->wait();
-  double clock_end = simgrid::s4u::Engine::getClock();
-
-  XBT_INFO("%s:%s task 1 executed %g", host_name, actor_name, clock_end - clock_begin);
-
-  activity = nullptr;
-
-  simgrid::s4u::this_actor::sleep_for(1);
-
-  clock_begin = simgrid::s4u::Engine::getClock();
-  XBT_INFO("%s:%s task 2 created %g", host_name, actor_name, clock_begin);
-  activity = simgrid::s4u::Actor::self()->exec_async(1e10);
-  activity->wait();
-  clock_end = simgrid::s4u::Engine::getClock();
-
-  XBT_INFO("%s:%s task 2 executed %g", host_name, actor_name, clock_end - clock_begin);
+  while (activity->getRemains() > 0) { // FIXME: use a test() here once that function is implemented
+    XBT_INFO("activity remaining duration: %g (%.0f%%)", activity->getRemains(), 100 * activity->getRemainingRatio());
+    simgrid::s4u::this_actor::sleep_for(5);
+  }
+  XBT_INFO("My task is over.");
 }
 
-static void monitor()
+static void executor()
 {
-  simgrid::s4u::Actor::createActor("compute", simgrid::s4u::Host::by_name("Fafard"), executor);
-
-  while (simgrid::s4u::Engine::getClock() < 100) {
-    if (activity)
-      XBT_INFO("activity remaining duration: %g", activity->getRemains());
-    simgrid::s4u::this_actor::sleep_for(1);
-  }
-
-  simgrid::s4u::this_actor::sleep_for(10000);
+  XBT_INFO("Create one monitored task, and wait for it");
+  simgrid::s4u::ExecPtr activity = simgrid::s4u::Actor::self()->exec_async(1e9);
+  simgrid::s4u::Actor::createActor("monitor 1", simgrid::s4u::Host::by_name("Tremblay"), monitor, activity);
+  activity->wait(); // This blocks until the activity is over
+  XBT_INFO("The monitored task is over. Let's start 3 of them now.");
+  simgrid::s4u::Actor::createActor("monitor 2", simgrid::s4u::Host::by_name("Jupiter"), monitor,
+                                   simgrid::s4u::Actor::self()->exec_async(1e9));
+  simgrid::s4u::Actor::createActor("monitor 3", simgrid::s4u::Host::by_name("Ginette"), monitor,
+                                   simgrid::s4u::Actor::self()->exec_async(1e9));
+  simgrid::s4u::Actor::createActor("monitor 4", simgrid::s4u::Host::by_name("Bourassa"), monitor,
+                                   simgrid::s4u::Actor::self()->exec_async(1e9));
+  XBT_INFO("All activities are started; finish now");
+  // Waiting execution activities is not mandatory: they go to completion once started
+
+  // No memory is leaked here: activities are automatically refcounted, thanks to C++ smart pointers
 }
 
 int main(int argc, char* argv[])
 {
   simgrid::s4u::Engine e(&argc, argv);
-  e.loadPlatform(argv[1]); /* - Load the platform description */
+  e.loadPlatform(argv[1]);
 
-  simgrid::s4u::Actor::createActor("master_", simgrid::s4u::Host::by_name("Fafard"), monitor);
+  simgrid::s4u::Actor::createActor("executor", simgrid::s4u::Host::by_name("Fafard"), executor);
 
   e.run();
 
-  XBT_INFO("Simulation time %g", e.getClock());
-
   return 0;
 }
index dcc5630..0aff0bd 100644 (file)
 #! ./tesh
 
-p Testing a vm with two successive tasks
+p Start several asynchronous tasks and monitor them
 
 $ $SG_TEST_EXENV ${bindir:=.}/s4u-exec-monitor$EXEEXT ${platfdir}/small_platform.xml
-> [VM0:compute:(2) 0.000000] [s4u_test/INFO] VM0:compute task 1 created 0
-> [Fafard:master_:(1) 1.000000] [s4u_test/INFO] activity remaining duration: 9.23704e+08
-> [Fafard:master_:(1) 2.000000] [s4u_test/INFO] activity remaining duration: 8.47408e+08
-> [Fafard:master_:(1) 3.000000] [s4u_test/INFO] activity remaining duration: 7.71112e+08
-> [Fafard:master_:(1) 4.000000] [s4u_test/INFO] activity remaining duration: 6.94816e+08
-> [Fafard:master_:(1) 5.000000] [s4u_test/INFO] activity remaining duration: 6.1852e+08
-> [Fafard:master_:(1) 6.000000] [s4u_test/INFO] activity remaining duration: 5.42224e+08
-> [Fafard:master_:(1) 7.000000] [s4u_test/INFO] activity remaining duration: 4.65928e+08
-> [Fafard:master_:(1) 8.000000] [s4u_test/INFO] activity remaining duration: 3.89632e+08
-> [Fafard:master_:(1) 9.000000] [s4u_test/INFO] activity remaining duration: 3.13336e+08
-> [Fafard:master_:(1) 10.000000] [s4u_test/INFO] activity remaining duration: 2.3704e+08
-> [Fafard:master_:(1) 11.000000] [s4u_test/INFO] activity remaining duration: 1.60744e+08
-> [Fafard:master_:(1) 12.000000] [s4u_test/INFO] activity remaining duration: 8.4448e+07
-> [Fafard:master_:(1) 13.000000] [s4u_test/INFO] activity remaining duration: 8.152e+06
-> [VM0:compute:(2) 13.106847] [s4u_test/INFO] VM0:compute task 1 executed 13.1068
-> [VM0:compute:(2) 14.106847] [s4u_test/INFO] VM0:compute task 2 created 14.1068
-> [Fafard:master_:(1) 15.000000] [s4u_test/INFO] activity remaining duration: 9.93186e+09
-> [Fafard:master_:(1) 16.000000] [s4u_test/INFO] activity remaining duration: 9.85556e+09
-> [Fafard:master_:(1) 17.000000] [s4u_test/INFO] activity remaining duration: 9.77926e+09
-> [Fafard:master_:(1) 18.000000] [s4u_test/INFO] activity remaining duration: 9.70297e+09
-> [Fafard:master_:(1) 19.000000] [s4u_test/INFO] activity remaining duration: 9.62667e+09
-> [Fafard:master_:(1) 20.000000] [s4u_test/INFO] activity remaining duration: 9.55038e+09
-> [Fafard:master_:(1) 21.000000] [s4u_test/INFO] activity remaining duration: 9.47408e+09
-> [Fafard:master_:(1) 22.000000] [s4u_test/INFO] activity remaining duration: 9.39778e+09
-> [Fafard:master_:(1) 23.000000] [s4u_test/INFO] activity remaining duration: 9.32149e+09
-> [Fafard:master_:(1) 24.000000] [s4u_test/INFO] activity remaining duration: 9.24519e+09
-> [Fafard:master_:(1) 25.000000] [s4u_test/INFO] activity remaining duration: 9.1689e+09
-> [Fafard:master_:(1) 26.000000] [s4u_test/INFO] activity remaining duration: 9.0926e+09
-> [Fafard:master_:(1) 27.000000] [s4u_test/INFO] activity remaining duration: 9.0163e+09
-> [Fafard:master_:(1) 28.000000] [s4u_test/INFO] activity remaining duration: 8.94001e+09
-> [Fafard:master_:(1) 29.000000] [s4u_test/INFO] activity remaining duration: 8.86371e+09
-> [Fafard:master_:(1) 30.000000] [s4u_test/INFO] activity remaining duration: 8.78742e+09
-> [Fafard:master_:(1) 31.000000] [s4u_test/INFO] activity remaining duration: 8.71112e+09
-> [Fafard:master_:(1) 32.000000] [s4u_test/INFO] activity remaining duration: 8.63482e+09
-> [Fafard:master_:(1) 33.000000] [s4u_test/INFO] activity remaining duration: 8.55853e+09
-> [Fafard:master_:(1) 34.000000] [s4u_test/INFO] activity remaining duration: 8.48223e+09
-> [Fafard:master_:(1) 35.000000] [s4u_test/INFO] activity remaining duration: 8.40594e+09
-> [Fafard:master_:(1) 36.000000] [s4u_test/INFO] activity remaining duration: 8.32964e+09
-> [Fafard:master_:(1) 37.000000] [s4u_test/INFO] activity remaining duration: 8.25334e+09
-> [Fafard:master_:(1) 38.000000] [s4u_test/INFO] activity remaining duration: 8.17705e+09
-> [Fafard:master_:(1) 39.000000] [s4u_test/INFO] activity remaining duration: 8.10075e+09
-> [Fafard:master_:(1) 40.000000] [s4u_test/INFO] activity remaining duration: 8.02446e+09
-> [Fafard:master_:(1) 41.000000] [s4u_test/INFO] activity remaining duration: 7.94816e+09
-> [Fafard:master_:(1) 42.000000] [s4u_test/INFO] activity remaining duration: 7.87186e+09
-> [Fafard:master_:(1) 43.000000] [s4u_test/INFO] activity remaining duration: 7.79557e+09
-> [Fafard:master_:(1) 44.000000] [s4u_test/INFO] activity remaining duration: 7.71927e+09
-> [Fafard:master_:(1) 45.000000] [s4u_test/INFO] activity remaining duration: 7.64298e+09
-> [Fafard:master_:(1) 46.000000] [s4u_test/INFO] activity remaining duration: 7.56668e+09
-> [Fafard:master_:(1) 47.000000] [s4u_test/INFO] activity remaining duration: 7.49038e+09
-> [Fafard:master_:(1) 48.000000] [s4u_test/INFO] activity remaining duration: 7.41409e+09
-> [Fafard:master_:(1) 49.000000] [s4u_test/INFO] activity remaining duration: 7.33779e+09
-> [Fafard:master_:(1) 50.000000] [s4u_test/INFO] activity remaining duration: 7.2615e+09
-> [Fafard:master_:(1) 51.000000] [s4u_test/INFO] activity remaining duration: 7.1852e+09
-> [Fafard:master_:(1) 52.000000] [s4u_test/INFO] activity remaining duration: 7.1089e+09
-> [Fafard:master_:(1) 53.000000] [s4u_test/INFO] activity remaining duration: 7.03261e+09
-> [Fafard:master_:(1) 54.000000] [s4u_test/INFO] activity remaining duration: 6.95631e+09
-> [Fafard:master_:(1) 55.000000] [s4u_test/INFO] activity remaining duration: 6.88002e+09
-> [Fafard:master_:(1) 56.000000] [s4u_test/INFO] activity remaining duration: 6.80372e+09
-> [Fafard:master_:(1) 57.000000] [s4u_test/INFO] activity remaining duration: 6.72742e+09
-> [Fafard:master_:(1) 58.000000] [s4u_test/INFO] activity remaining duration: 6.65113e+09
-> [Fafard:master_:(1) 59.000000] [s4u_test/INFO] activity remaining duration: 6.57483e+09
-> [Fafard:master_:(1) 60.000000] [s4u_test/INFO] activity remaining duration: 6.49854e+09
-> [Fafard:master_:(1) 61.000000] [s4u_test/INFO] activity remaining duration: 6.42224e+09
-> [Fafard:master_:(1) 62.000000] [s4u_test/INFO] activity remaining duration: 6.34594e+09
-> [Fafard:master_:(1) 63.000000] [s4u_test/INFO] activity remaining duration: 6.26965e+09
-> [Fafard:master_:(1) 64.000000] [s4u_test/INFO] activity remaining duration: 6.19335e+09
-> [Fafard:master_:(1) 65.000000] [s4u_test/INFO] activity remaining duration: 6.11706e+09
-> [Fafard:master_:(1) 66.000000] [s4u_test/INFO] activity remaining duration: 6.04076e+09
-> [Fafard:master_:(1) 67.000000] [s4u_test/INFO] activity remaining duration: 5.96446e+09
-> [Fafard:master_:(1) 68.000000] [s4u_test/INFO] activity remaining duration: 5.88817e+09
-> [Fafard:master_:(1) 69.000000] [s4u_test/INFO] activity remaining duration: 5.81187e+09
-> [Fafard:master_:(1) 70.000000] [s4u_test/INFO] activity remaining duration: 5.73558e+09
-> [Fafard:master_:(1) 71.000000] [s4u_test/INFO] activity remaining duration: 5.65928e+09
-> [Fafard:master_:(1) 72.000000] [s4u_test/INFO] activity remaining duration: 5.58298e+09
-> [Fafard:master_:(1) 73.000000] [s4u_test/INFO] activity remaining duration: 5.50669e+09
-> [Fafard:master_:(1) 74.000000] [s4u_test/INFO] activity remaining duration: 5.43039e+09
-> [Fafard:master_:(1) 75.000000] [s4u_test/INFO] activity remaining duration: 5.3541e+09
-> [Fafard:master_:(1) 76.000000] [s4u_test/INFO] activity remaining duration: 5.2778e+09
-> [Fafard:master_:(1) 77.000000] [s4u_test/INFO] activity remaining duration: 5.2015e+09
-> [Fafard:master_:(1) 78.000000] [s4u_test/INFO] activity remaining duration: 5.12521e+09
-> [Fafard:master_:(1) 79.000000] [s4u_test/INFO] activity remaining duration: 5.04891e+09
-> [Fafard:master_:(1) 80.000000] [s4u_test/INFO] activity remaining duration: 4.97262e+09
-> [Fafard:master_:(1) 81.000000] [s4u_test/INFO] activity remaining duration: 4.89632e+09
-> [Fafard:master_:(1) 82.000000] [s4u_test/INFO] activity remaining duration: 4.82002e+09
-> [Fafard:master_:(1) 83.000000] [s4u_test/INFO] activity remaining duration: 4.74373e+09
-> [Fafard:master_:(1) 84.000000] [s4u_test/INFO] activity remaining duration: 4.66743e+09
-> [Fafard:master_:(1) 85.000000] [s4u_test/INFO] activity remaining duration: 4.59114e+09
-> [Fafard:master_:(1) 86.000000] [s4u_test/INFO] activity remaining duration: 4.51484e+09
-> [Fafard:master_:(1) 87.000000] [s4u_test/INFO] activity remaining duration: 4.43854e+09
-> [Fafard:master_:(1) 88.000000] [s4u_test/INFO] activity remaining duration: 4.36225e+09
-> [Fafard:master_:(1) 89.000000] [s4u_test/INFO] activity remaining duration: 4.28595e+09
-> [Fafard:master_:(1) 90.000000] [s4u_test/INFO] activity remaining duration: 4.20966e+09
-> [Fafard:master_:(1) 91.000000] [s4u_test/INFO] activity remaining duration: 4.13336e+09
-> [Fafard:master_:(1) 92.000000] [s4u_test/INFO] activity remaining duration: 4.05706e+09
-> [Fafard:master_:(1) 93.000000] [s4u_test/INFO] activity remaining duration: 3.98077e+09
-> [Fafard:master_:(1) 94.000000] [s4u_test/INFO] activity remaining duration: 3.90447e+09
-> [Fafard:master_:(1) 95.000000] [s4u_test/INFO] activity remaining duration: 3.82818e+09
-> [Fafard:master_:(1) 96.000000] [s4u_test/INFO] activity remaining duration: 3.75188e+09
-> [Fafard:master_:(1) 97.000000] [s4u_test/INFO] activity remaining duration: 3.67558e+09
-> [Fafard:master_:(1) 98.000000] [s4u_test/INFO] activity remaining duration: 3.59929e+09
-> [Fafard:master_:(1) 99.000000] [s4u_test/INFO] activity remaining duration: 3.52299e+09
-> [VM0:compute:(2) 145.175317] [s4u_test/INFO] VM0:compute task 2 executed 131.068
-> [10100.000000] [s4u_test/INFO] Simulation time 10100
+> [Fafard:executor:(1) 0.000000] [s4u_test/INFO] Create one monitored task, and wait for it
+> [Tremblay:monitor 1:(2) 0.000000] [s4u_test/INFO] activity remaining duration: 1e+09 (100%)
+> [Tremblay:monitor 1:(2) 5.000000] [s4u_test/INFO] activity remaining duration: 6.1852e+08 (62%)
+> [Tremblay:monitor 1:(2) 10.000000] [s4u_test/INFO] activity remaining duration: 2.3704e+08 (24%)
+> [Fafard:executor:(1) 13.106847] [s4u_test/INFO] The monitored task is over. Let's start 3 of them now.
+> [Jupiter:monitor 2:(3) 13.106847] [s4u_test/INFO] activity remaining duration: 1e+09 (100%)
+> [Fafard:executor:(1) 13.106847] [s4u_test/INFO] All activities are started; finish now
+> [Ginette:monitor 3:(4) 13.106847] [s4u_test/INFO] activity remaining duration: 1e+09 (100%)
+> [Bourassa:monitor 4:(5) 13.106847] [s4u_test/INFO] activity remaining duration: 1e+09 (100%)
+> [Tremblay:monitor 1:(2) 15.000000] [s4u_test/INFO] My task is over.
+> [Bourassa:monitor 4:(5) 18.106847] [s4u_test/INFO] activity remaining duration: 8.7284e+08 (87%)
+> [Ginette:monitor 3:(4) 18.106847] [s4u_test/INFO] activity remaining duration: 8.7284e+08 (87%)
+> [Jupiter:monitor 2:(3) 18.106847] [s4u_test/INFO] activity remaining duration: 8.7284e+08 (87%)
+> [Jupiter:monitor 2:(3) 23.106847] [s4u_test/INFO] activity remaining duration: 7.4568e+08 (75%)
+> [Ginette:monitor 3:(4) 23.106847] [s4u_test/INFO] activity remaining duration: 7.4568e+08 (75%)
+> [Bourassa:monitor 4:(5) 23.106847] [s4u_test/INFO] activity remaining duration: 7.4568e+08 (75%)
+> [Bourassa:monitor 4:(5) 28.106847] [s4u_test/INFO] activity remaining duration: 6.1852e+08 (62%)
+> [Ginette:monitor 3:(4) 28.106847] [s4u_test/INFO] activity remaining duration: 6.1852e+08 (62%)
+> [Jupiter:monitor 2:(3) 28.106847] [s4u_test/INFO] activity remaining duration: 6.1852e+08 (62%)
+> [Jupiter:monitor 2:(3) 33.106847] [s4u_test/INFO] activity remaining duration: 4.9136e+08 (49%)
+> [Ginette:monitor 3:(4) 33.106847] [s4u_test/INFO] activity remaining duration: 4.9136e+08 (49%)
+> [Bourassa:monitor 4:(5) 33.106847] [s4u_test/INFO] activity remaining duration: 4.9136e+08 (49%)
+> [Bourassa:monitor 4:(5) 38.106847] [s4u_test/INFO] activity remaining duration: 3.642e+08 (36%)
+> [Ginette:monitor 3:(4) 38.106847] [s4u_test/INFO] activity remaining duration: 3.642e+08 (36%)
+> [Jupiter:monitor 2:(3) 38.106847] [s4u_test/INFO] activity remaining duration: 3.642e+08 (36%)
+> [Jupiter:monitor 2:(3) 43.106847] [s4u_test/INFO] activity remaining duration: 2.3704e+08 (24%)
+> [Ginette:monitor 3:(4) 43.106847] [s4u_test/INFO] activity remaining duration: 2.3704e+08 (24%)
+> [Bourassa:monitor 4:(5) 43.106847] [s4u_test/INFO] activity remaining duration: 2.3704e+08 (24%)
+> [Bourassa:monitor 4:(5) 48.106847] [s4u_test/INFO] activity remaining duration: 1.0988e+08 (11%)
+> [Ginette:monitor 3:(4) 48.106847] [s4u_test/INFO] activity remaining duration: 1.0988e+08 (11%)
+> [Jupiter:monitor 2:(3) 48.106847] [s4u_test/INFO] activity remaining duration: 1.0988e+08 (11%)
+> [Jupiter:monitor 2:(3) 53.106847] [s4u_test/INFO] My task is over.
+> [Ginette:monitor 3:(4) 53.106847] [s4u_test/INFO] My task is over.
+> [Bourassa:monitor 4:(5) 53.106847] [s4u_test/INFO] My task is over.