-/* Copyright (c) 2017-2018. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2017-2019. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
void LinkEnergy::update()
{
+ if (!inited_)
+ init_watts_range_list();
+
double power = get_power();
double now = surf_get_clock();
total_energy_ += power * (now - last_updated_);
void LinkEnergy::init_watts_range_list()
{
-
if (inited_)
return;
inited_ = true;
} catch (std::invalid_argument& ia) {
throw std::invalid_argument(std::string("Invalid busy power value for link ") + this->link_->get_cname());
}
-
- update();
}
}
simgrid::s4u::Link::on_state_change.connect([](simgrid::s4u::Link& link) { link.extension<LinkEnergy>()->update(); });
simgrid::s4u::Link::on_destruction.connect([](simgrid::s4u::Link& link) {
- if (strcmp(link.get_cname(), "__loopback__"))
+ if (link.get_name() != "__loopback__")
XBT_INFO("Energy consumption of link '%s': %f Joules", link.get_cname(),
link.extension<LinkEnergy>()->get_consumed_energy());
});