From 67185374330d2c4bf274fce222c937e838df5b03 Mon Sep 17 00:00:00 2001 From: Henri Casanova Date: Wed, 16 Sep 2020 16:59:42 -1000 Subject: [PATCH] (#200) Implemented non-redundant energy time-stamps --- src/wrench/simulation/SimulationOutput.cpp | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/wrench/simulation/SimulationOutput.cpp b/src/wrench/simulation/SimulationOutput.cpp index 1c9a67b972..337305e972 100644 --- a/src/wrench/simulation/SimulationOutput.cpp +++ b/src/wrench/simulation/SimulationOutput.cpp @@ -1812,9 +1812,33 @@ namespace wrench { * @param joules: consumption in joules */ void SimulationOutput::addTimestampEnergyConsumption(std::string hostname, double joules) { - if (this->isEnabled()) { - this->addTimestamp(new SimulationTimestampEnergyConsumption(hostname, joules)); + static std::unordered_map> last_two_timestamps; + + if (not this->isEnabled()) { + return; } + + auto new_timestamp = new SimulationTimestampEnergyConsumption(hostname,joules); + + // If less thant 2 time-stamp for that host, just record and add + if (last_two_timestamps[hostname].size() < 2) { + last_two_timestamps[hostname].push_back(new_timestamp); + this->addTimestamp(new_timestamp); + return; + } + + // Otherwise, check whether we can merge + bool can_merge = DBL_EQUAL(last_two_timestamps[hostname].at(0)->getConsumption(), last_two_timestamps[hostname].at(1)->getConsumption()) and + DBL_EQUAL(last_two_timestamps[hostname].at(1)->getConsumption(), new_timestamp->getConsumption()); + + if (can_merge) { + last_two_timestamps[hostname].at(1)->setDate(new_timestamp->getDate()); + } else { + last_two_timestamps[hostname][0] = last_two_timestamps[hostname][1]; + last_two_timestamps[hostname][1] = new_timestamp; + this->addTimestamp(new_timestamp); + } + } /**