-/* Copyright (c) 2010-2018. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2010-2019. 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. */
host.extension<HostLoad>()->update();
}
-/* This callback is called when an action (computation, idle, ...) terminates */
-static void on_action_state_change(simgrid::surf::CpuAction* action, simgrid::kernel::resource::Action::State /*previous*/)
-{
- for (simgrid::surf::Cpu* const& cpu : action->cpus()) {
- simgrid::s4u::Host* host = cpu->get_host();
-
- if (dynamic_cast<simgrid::s4u::VirtualMachine*>(host)) // Ignore virtual machines
- return;
-
- if (host != nullptr) {
- host->extension<HostLoad>()->update();
- }
- }
-}
-
/* **************************** Public interface *************************** */
/** @brief Initializes the HostLoad plugin
simgrid::kernel::activity::ExecImpl::on_creation.connect([](simgrid::kernel::activity::ExecImplPtr activity){
if (activity->host_ != nullptr) { // We only run on one host
simgrid::s4u::Host* host = activity->host_;
- if (dynamic_cast<simgrid::s4u::VirtualMachine*>(activity->host_))
- host = dynamic_cast<simgrid::s4u::VirtualMachine*>(activity->host_)->get_pm();
+ simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host);
+ if (vm != nullptr)
+ host = vm->get_pm();
host->extension<HostLoad>()->add_activity(activity);
host->extension<HostLoad>()->update(); // If the system was idle until now, we need to update *before*
simgrid::kernel::activity::ExecImpl::on_completion.connect([](simgrid::kernel::activity::ExecImplPtr activity){
if (activity->host_ != nullptr) { // We only run on one host
simgrid::s4u::Host* host = activity->host_;
- if (dynamic_cast<simgrid::s4u::VirtualMachine*>(activity->host_))
- host = dynamic_cast<simgrid::s4u::VirtualMachine*>(activity->host_)->get_pm();
+ simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host);
+ if (vm != nullptr)
+ host = vm->get_pm();
host->extension<HostLoad>()->update();
}