* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/plugins/energy.h"
+#include "simgrid/plugins/load.h"
#include "simgrid/simix.hpp"
#include "src/plugins/vm/VirtualMachineImpl.hpp"
#include "src/surf/cpu_interface.hpp"
host.extension_set(new HostEnergy(&host));
}
-static void onActionStateChange(simgrid::surf::CpuAction* action, simgrid::surf::Action::State previous)
+static void onActionStateChange(simgrid::surf::CpuAction* action, simgrid::kernel::resource::Action::State previous)
{
for (simgrid::surf::Cpu* const& cpu : action->cpus()) {
simgrid::s4u::Host* host = cpu->getHost();
static void onSimulationEnd()
{
- sg_host_t* host_list = sg_host_list();
- int host_count = sg_host_count();
+ std::vector<simgrid::s4u::Host*> hosts = simgrid::s4u::Engine::getInstance()->getAllHosts();
+
double total_energy = 0.0; // Total energy consumption (whole platform)
double used_hosts_energy = 0.0; // Energy consumed by hosts that computed something
- for (int i = 0; i < host_count; i++) {
- if (dynamic_cast<simgrid::s4u::VirtualMachine*>(host_list[i]) == nullptr) { // Ignore virtual machines
+ for (size_t i = 0; i < hosts.size(); i++) {
+ if (dynamic_cast<simgrid::s4u::VirtualMachine*>(hosts[i]) == nullptr) { // Ignore virtual machines
- bool host_was_used = (host_list[i]->extension<HostEnergy>()->last_updated != 0);
- double energy = host_list[i]->extension<HostEnergy>()->getConsumedEnergy();
+ bool host_was_used = (sg_host_get_computed_flops(hosts[i]) != 0);
+ double energy = hosts[i]->extension<HostEnergy>()->getConsumedEnergy();
total_energy += energy;
if (host_was_used)
used_hosts_energy += energy;
}
XBT_INFO("Total energy consumption: %f Joules (used hosts: %f Joules; unused/idle hosts: %f)",
total_energy, used_hosts_energy, total_energy - used_hosts_energy);
- xbt_free(host_list);
}
/* **************************** Public interface *************************** */
if (HostEnergy::EXTENSION_ID.valid())
return;
+ sg_host_load_plugin_init();
+
HostEnergy::EXTENSION_ID = simgrid::s4u::Host::extension_create<HostEnergy>();
simgrid::s4u::Host::onCreation.connect(&onCreation);
void sg_host_energy_update_all()
{
simgrid::simix::kernelImmediate([]() {
- std::vector<simgrid::s4u::Host*> list;
- simgrid::s4u::Engine::getInstance()->getHostList(&list);
+ std::vector<simgrid::s4u::Host*> list = simgrid::s4u::Engine::getInstance()->getAllHosts();
for (auto const& host : list)
if (dynamic_cast<simgrid::s4u::VirtualMachine*>(host) == nullptr) // Ignore virtual machines
host->extension<HostEnergy>()->update();