#include "simgrid/plugins/energy.h"
#include "simgrid/s4u/Engine.hpp"
#include "src/surf/network_interface.hpp"
+#include "src/surf/surf_interface.hpp"
#include "surf/surf.hpp"
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
+SIMGRID_REGISTER_PLUGIN(link_energy, "Link energy consumption.", &sg_link_energy_plugin_init)
+
/** @addtogroup SURF_plugin_energy
/* min_power corresponds to the idle power (link load = 0) */
/* max_power is the power consumed at 100% link load */
- char* idleMsg = bprintf("Invalid idle power value for link%s", this->link_->get_cname());
- char* busyMsg = bprintf("Invalid busy power value for %s", this->link_->get_cname());
+ try {
+ idle_ = std::stod(current_power_values.front());
+ } catch (std::invalid_argument& ia) {
+ throw std::invalid_argument(std::string("Invalid idle power value for link ") + this->link_->get_cname());
+ }
- idle_ = xbt_str_parse_double((current_power_values.at(0)).c_str(), idleMsg);
- busy_ = xbt_str_parse_double((current_power_values.at(1)).c_str(), busyMsg);
+ try {
+ busy_ = std::stod(current_power_values.back());
+ } catch (std::invalid_argument& ia) {
+ throw std::invalid_argument(std::string("Invalid busy power value for link ") + this->link_->get_cname());
+ }
- xbt_free(idleMsg);
- xbt_free(busyMsg);
update();
}
}
link.extension<LinkEnergy>()->get_consumed_energy());
});
- simgrid::s4u::Link::on_communication_state_change.connect([](simgrid::kernel::resource::NetworkAction* action) {
- for (simgrid::kernel::resource::LinkImpl* link : action->links()) {
- if (link != nullptr)
- link->piface_.extension<LinkEnergy>()->update();
- }
- });
+ simgrid::s4u::Link::on_communication_state_change.connect(
+ [](simgrid::kernel::resource::NetworkAction* action, simgrid::kernel::resource::Action::State /* previous */) {
+ for (simgrid::kernel::resource::LinkImpl* link : action->links()) {
+ if (link != nullptr)
+ link->piface_.extension<LinkEnergy>()->update();
+ }
+ });
simgrid::s4u::Link::on_communicate.connect(&on_communicate);
simgrid::s4u::on_simulation_end.connect(&on_simulation_end);