-
- (*simgrid::energy::surf_energy)[host] = new HostEnergy(host);
- });
-
- simgrid::surf::Host::onDestruction.connect([](simgrid::surf::Host *host) {
- if (dynamic_cast<simgrid::surf::VirtualMachine*>(host)) // Ignore virtual machines
- return;
-
- std::map<simgrid::surf::Host*, HostEnergy*>::iterator host_energy_it = simgrid::energy::surf_energy->find(host);
- xbt_assert(host_energy_it != simgrid::energy::surf_energy->end(), "The host is not in surf_energy.");
-
- HostEnergy *host_energy = host_energy_it->second;
- update_consumption(host, host_energy);
-
- XBT_INFO("Total energy of host %s: %f Joules", host->getName(), host_energy->getConsumedEnergy());
- host_energy_it->second->unref();
- simgrid::energy::surf_energy->erase(host_energy_it);