> [ 0.000000] (2:receiver@MyHost2) Receiving 1 flows ...
> [ 10.250000] (2:receiver@MyHost2) receiver done.
> [ 10.250000] (1:sender@MyHost1) sender done.
-> [ 10.250000] (0:maestro@) Link 'bus' total consumption: 10.750000
> [ 10.250000] (0:maestro@) Total energy over all links: 10.750000
+> [ 10.250000] (0:maestro@) Energy consumption of link 'bus': 10.750000 Joules
p And now test with 500000 bytes
> [ 0.000000] (2:receiver@MyHost2) Receiving 1 flows ...
> [510.000000] (2:receiver@MyHost2) receiver done.
> [510.000000] (1:sender@MyHost1) sender done.
-> [510.000000] (0:maestro@) Link 'bus' total consumption: 1510.000000
> [510.000000] (0:maestro@) Total energy over all links: 1510.000000
-
+> [510.000000] (0:maestro@) Energy consumption of link 'bus': 1510.000000 Joules
if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
return;
- HostEnergy* host_energy = host.extension<HostEnergy>();
- host_energy->update();
- XBT_INFO("Energy consumption of host %s: %f Joules", host.getCname(), host_energy->getConsumedEnergy());
+ XBT_INFO("Energy consumption of host %s: %f Joules", host.getCname(),
+ host.extension<HostEnergy>()->getConsumedEnergy());
}
static void onSimulationEnd()
~LinkEnergy();
void initWattsRangeList();
- double getTotalEnergy();
+ double getConsumedEnergy();
void update();
private:
return idle_ + dynamic_power;
}
-double LinkEnergy::getTotalEnergy()
+double LinkEnergy::getConsumedEnergy()
{
- update();
+ if (lastUpdated_ < surf_get_clock()) // We need to simcall this as it modifies the environment
+ simgrid::simix::kernelImmediate(std::bind(&LinkEnergy::update, this));
return this->totalEnergy_;
}
}
double total_energy = 0.0; // Total dissipated energy (whole platform)
for (const auto link : links) {
- double link_energy = link->extension<LinkEnergy>()->getTotalEnergy();
- if (strcmp(link->getCname(), "__loopback__"))
- XBT_INFO("Link '%s' total consumption: %f", link->getCname(), link_energy);
+ double link_energy = link->extension<LinkEnergy>()->getConsumedEnergy();
total_energy += link_energy;
}
});
simgrid::s4u::Link::onDestruction.connect([](simgrid::s4u::Link& link) {
- link.extension<LinkEnergy>()->update();
+ if (strcmp(link.getCname(), "__loopback__"))
+ XBT_INFO("Energy consumption of link '%s': %f Joules", link.getCname(),
+ link.extension<LinkEnergy>()->getConsumedEnergy());
});
simgrid::s4u::Link::onCommunicationStateChange.connect([](simgrid::surf::NetworkAction* action) {
simgrid::s4u::onSimulationEnd.connect(&onSimulationEnd);
}
+/** @ingroup plugin_energy
+ * @brief Returns the total energy consumed by the link so far (in Joules)
+ *
+ * Please note that since the consumption is lazily updated, it may require a simcall to update it.
+ * The result is that the actor requesting this value will be interrupted,
+ * the value will be updated in kernel mode before returning the control to the requesting actor.
+ */
+double sg_link_get_consumed_energy(sg_link_t link)
+{
+ return link->extension<LinkEnergy>()->getConsumedEnergy();
+}
SG_END_DECL()