+ simgrid::s4u::Exec::on_start_cb([](simgrid::s4u::Exec const& activity) {
+ if (activity.get_host_number() == 1) { // We only run on one host
+ simgrid::s4u::Host* host = activity.get_host();
+ const simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host);
+ if (vm != nullptr)
+ host = vm->get_pm();
+ xbt_assert(host != nullptr);
+ host->extension<HostLoad>()->add_activity(static_cast<simgrid::kernel::activity::ExecImpl*>(activity.get_impl()));
+ host->extension<HostLoad>()->update(); // If the system was idle until now, we need to update *before*
+ // this computation starts running so we can keep track of the
+ // idle time. (Communication operations don't trigger this hook!)
+ }
+ else { // This runs on multiple hosts
+ XBT_WARN("HostLoad plugin currently does not support executions on several hosts");
+ }
+ });
+ simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity const& activity) {
+ const auto* exec = dynamic_cast<simgrid::s4u::Exec const*>(&activity);
+ if (exec == nullptr) // Only Execs are concerned here
+ return;
+ if (exec->get_host_number() == 1) { // We only run on one host
+ simgrid::s4u::Host* host = exec->get_host();
+ const simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host);
+ if (vm != nullptr)
+ host = vm->get_pm();
+ xbt_assert(host != nullptr);
+ host->extension<HostLoad>()->update();
+ } else { // This runs on multiple hosts
+ XBT_WARN("HostLoad plugin currently does not support executions on several hosts");
+ }
+ });
+ simgrid::s4u::Host::on_state_change_cb(&on_host_change);
+ simgrid::s4u::Host::on_speed_change_cb(&on_host_change);