X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d8eb62b207b566949a0d9ce649a7b21e226b9168..7415b6acc6794b420f8884de0f73fcb3e020d9c0:/src/plugins/link_energy.cpp diff --git a/src/plugins/link_energy.cpp b/src/plugins/link_energy.cpp index 8bf16970b4..5e27abd95c 100644 --- a/src/plugins/link_energy.cpp +++ b/src/plugins/link_energy.cpp @@ -1,4 +1,4 @@ -/* 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. */ @@ -72,6 +72,9 @@ simgrid::xbt::Extension LinkEnergy::EXTENSION_ID void LinkEnergy::update() { + if (!inited_) + init_watts_range_list(); + double power = get_power(); double now = surf_get_clock(); total_energy_ += power * (now - last_updated_); @@ -80,7 +83,6 @@ void LinkEnergy::update() void LinkEnergy::init_watts_range_list() { - if (inited_) return; inited_ = true; @@ -114,8 +116,6 @@ void LinkEnergy::init_watts_range_list() } catch (std::invalid_argument& ia) { throw std::invalid_argument(std::string("Invalid busy power value for link ") + this->link_->get_cname()); } - - update(); } } @@ -197,7 +197,7 @@ void sg_link_energy_plugin_init() simgrid::s4u::Link::on_state_change.connect([](simgrid::s4u::Link& link) { link.extension()->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()->get_consumed_energy()); });