X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5014a33c445bb3b94e34453892aebccc0251e783..d9966aa66acc63c0417fbeae8e3ff12bccb0cdb0:/src/surf/plugins/host_energy.cpp diff --git a/src/surf/plugins/host_energy.cpp b/src/surf/plugins/host_energy.cpp index 171f6b7dcc..81b4c9b559 100644 --- a/src/surf/plugins/host_energy.cpp +++ b/src/surf/plugins/host_energy.cpp @@ -389,7 +389,7 @@ static void onCreation(simgrid::s4u::Host& host) 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(); @@ -432,15 +432,15 @@ static void onHostDestruction(simgrid::s4u::Host& host) static void onSimulationEnd() { - sg_host_t* host_list = sg_host_list(); - int host_count = sg_host_count(); + std::vector 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(host_list[i]) == nullptr) { // Ignore virtual machines + for (size_t i = 0; i < hosts.size(); i++) { + if (dynamic_cast(hosts[i]) == nullptr) { // Ignore virtual machines - bool host_was_used = (sg_host_get_computed_flops(host_list[i]) != 0); - double energy = host_list[i]->extension()->getConsumedEnergy(); + bool host_was_used = (sg_host_get_computed_flops(hosts[i]) != 0); + double energy = hosts[i]->extension()->getConsumedEnergy(); total_energy += energy; if (host_was_used) used_hosts_energy += energy; @@ -448,7 +448,6 @@ static void onSimulationEnd() } 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 *************************** */ @@ -484,8 +483,7 @@ void sg_host_energy_plugin_init() void sg_host_energy_update_all() { simgrid::simix::kernelImmediate([]() { - std::vector list; - simgrid::s4u::Engine::getInstance()->getHostList(&list); + std::vector list = simgrid::s4u::Engine::getInstance()->getAllHosts(); for (auto const& host : list) if (dynamic_cast(host) == nullptr) // Ignore virtual machines host->extension()->update();