Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
xbt_strbuff to std::string in cpp files
[simgrid.git] / src / surf / plugins / host_load.cpp
index 54761f1..623ae67 100644 (file)
@@ -35,12 +35,14 @@ public:
 
   double getCurrentLoad();
   double getComputedFlops();
+  double getAverageLoad();
   void update();
   void reset();
 
 private:
   simgrid::s4u::Host* host = nullptr;
   double last_updated      = 0;
+  double last_reset        = 0;
   double current_flops     = 0;
   double computed_flops    = 0;
 };
@@ -48,7 +50,10 @@ private:
 simgrid::xbt::Extension<simgrid::s4u::Host, HostLoad> HostLoad::EXTENSION_ID;
 
 HostLoad::HostLoad(simgrid::s4u::Host* ptr)
-    : host(ptr), last_updated(surf_get_clock()), current_flops(lmm_constraint_get_usage(host->pimpl_cpu->constraint()))
+    : host(ptr)
+    , last_updated(surf_get_clock())
+    , last_reset(surf_get_clock())
+    , current_flops(lmm_constraint_get_usage(host->pimpl_cpu->constraint()))
 {
 }
 
@@ -73,6 +78,11 @@ double HostLoad::getCurrentLoad()
   return current_flops / (host->speed() * host->coreCount());
 }
 
+double HostLoad::getAverageLoad()
+{
+  return getComputedFlops() / (host->speed() * host->coreCount() * (surf_get_clock() - last_reset));
+}
+
 double HostLoad::getComputedFlops()
 {
   update();
@@ -86,6 +96,7 @@ double HostLoad::getComputedFlops()
 void HostLoad::reset()
 {
   last_updated   = surf_get_clock();
+  last_reset     = surf_get_clock();
   computed_flops = 0;
 }
 }
@@ -118,12 +129,11 @@ static void onActionStateChange(simgrid::surf::CpuAction* action, simgrid::surf:
   for (simgrid::surf::Cpu* cpu : action->cpus()) {
     simgrid::s4u::Host* host = cpu->getHost();
 
-    if (host == nullptr)
-      continue;
-
-    // Get the host_load extension for the relevant host
-    HostLoad* host_load = host->extension<HostLoad>();
-    host_load->update();
+    if (host != nullptr) {
+      // Get the host_load extension for the relevant host
+      HostLoad* host_load = host->extension<HostLoad>();
+      host_load->update();
+    }
   }
 }