Skip to content

Commit

Permalink
(#200) Implemented non-redundant energy time-stamps
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Sep 17, 2020
1 parent 9beb10c commit 6718537
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/wrench/simulation/SimulationOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1812,9 +1812,33 @@ namespace wrench {
* @param joules: consumption in joules
*/
void SimulationOutput::addTimestampEnergyConsumption(std::string hostname, double joules) {
if (this->isEnabled<SimulationTimestampEnergyConsumption>()) {
this->addTimestamp<SimulationTimestampEnergyConsumption>(new SimulationTimestampEnergyConsumption(hostname, joules));
static std::unordered_map<std::string, std::vector<SimulationTimestampEnergyConsumption*>> last_two_timestamps;

if (not this->isEnabled<SimulationTimestampEnergyConsumption>()) {
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<SimulationTimestampEnergyConsumption>(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<SimulationTimestampEnergyConsumption>(new_timestamp);
}

}

/**
Expand Down

0 comments on commit 6718537

Please sign in to comment.