if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
return;
- // TODO Trace: set to zero the energy variable associated to host->getName()
+ // TODO Trace: set to zero the energy variable associated to host->get_name()
host.extension_set(new HostEnergy(&host));
}
});
}
+static void ensure_plugin_inited()
+{
+ if (not HostEnergy::EXTENSION_ID.valid())
+ throw std::logic_error("The Energy plugin is not active. Please call sg_host_energy_plugin_init() before calling "
+ "any function related to that plugin.");
+}
+
/** @ingroup plugin_host_energy
* @brief Returns the total energy consumed by the host so far (in Joules)
*
*/
double sg_host_get_consumed_energy(sg_host_t host)
{
- xbt_assert(HostEnergy::EXTENSION_ID.valid(),
- "The Energy plugin is not active. Please call sg_host_energy_plugin_init() during initialization.");
+ ensure_plugin_inited();
return host->extension<HostEnergy>()->get_consumed_energy();
}
*/
double sg_host_get_idle_consumption(sg_host_t host)
{
- xbt_assert(HostEnergy::EXTENSION_ID.valid(),
- "The Energy plugin is not active. Please call sg_host_energy_plugin_init() during initialization.");
+ ensure_plugin_inited();
return host->extension<HostEnergy>()->get_watt_idle_at(0);
}
*/
double sg_host_get_idle_consumption_at(sg_host_t host, int pstate)
{
- xbt_assert(HostEnergy::EXTENSION_ID.valid(),
- "The Energy plugin is not active. Please call sg_host_energy_plugin_init() during initialization.");
+ ensure_plugin_inited();
return host->extension<HostEnergy>()->get_watt_idle_at(pstate);
}
*/
double sg_host_get_wattmin_at(sg_host_t host, int pstate)
{
- xbt_assert(HostEnergy::EXTENSION_ID.valid(),
- "The Energy plugin is not active. Please call sg_host_energy_plugin_init() during initialization.");
+ ensure_plugin_inited();
return host->extension<HostEnergy>()->get_watt_min_at(pstate);
}
/** @ingroup plugin_host_energy
*/
double sg_host_get_wattmax_at(sg_host_t host, int pstate)
{
- xbt_assert(HostEnergy::EXTENSION_ID.valid(),
- "The Energy plugin is not active. Please call sg_host_energy_plugin_init() during initialization.");
+ ensure_plugin_inited();
return host->extension<HostEnergy>()->get_watt_max_at(pstate);
}
/** @ingroup plugin_host_energy
*/
double sg_host_get_power_range_slope_at(sg_host_t host, int pstate)
{
- xbt_assert(HostEnergy::EXTENSION_ID.valid(),
- "The Energy plugin is not active. Please call sg_host_energy_plugin_init() during initialization.");
+ ensure_plugin_inited();
return host->extension<HostEnergy>()->get_power_range_slope_at(pstate);
}
/** @ingroup plugin_host_energy
*/
double sg_host_get_current_consumption(sg_host_t host)
{
- xbt_assert(HostEnergy::EXTENSION_ID.valid(),
- "The Energy plugin is not active. Please call sg_host_energy_plugin_init() during initialization.");
+ ensure_plugin_inited();
return host->extension<HostEnergy>()->get_current_watts_value();
}