- XBT_DEBUG(
- "[update_energy of %s] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> %.2f J",
- host->cname(), start_time, finish_time, host->pimpl_cpu->speed_.peak, previous_energy, energy_this_step);
+ double instantaneous_consumption;
+ if (this->pstate == -1) // The host was off at the beginning of this time interval
+ instantaneous_consumption = this->watts_off;
+ else
+ instantaneous_consumption = this->getCurrentWattsValue(cpu_load);
+
+ double energy_this_step = instantaneous_consumption * (finish_time - start_time);
+
+ // TODO Trace: Trace energy_this_step from start_time to finish_time in host->name()
+
+ this->total_energy = previous_energy + energy_this_step;
+ this->last_updated = finish_time;
+
+ XBT_DEBUG("[update_energy of %s] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> "
+ "%.2f J",
+ host->cname(), start_time, finish_time, host->pimpl_cpu->speed_.peak, previous_energy, energy_this_step);
+ }
+
+ /* Save data for the upcoming time interval: whether it's on/off and the pstate if it's on */
+ this->pstate = host->isOn() ? host->pstate() : -1;