10 #ifndef WRENCH_SIMULATIONTRACE_H
11 #define WRENCH_SIMULATIONTRACE_H
19 #include "wrench/simulation/SimulationTimestamp.h"
29 class GenericSimulationTrace {
32 virtual ~GenericSimulationTrace() {}
48 template <
class T>
class SimulationTrace :
public GenericSimulationTrace {
58 void addTimestamp(SimulationTimestamp<T> *timestamp) {
59 this->trace.push_back(timestamp);
69 std::vector<SimulationTimestamp<T> *> getTrace() {
76 ~SimulationTrace<T>() {
77 for (
auto ×tamp : this->trace) {
84 std::vector<SimulationTimestamp<T> *> trace;
92 class SimulationTrace<SimulationTimestampPstateSet> :
public GenericSimulationTrace {
99 void addTimestamp(SimulationTimestamp<SimulationTimestampPstateSet> *new_timestamp) {
100 auto hostname = new_timestamp->getContent()->getHostname();
102 auto hostname_search = latest_timestamps_by_host.find(hostname);
103 if (hostname_search == latest_timestamps_by_host.end()) {
105 this->trace.push_back(new_timestamp);
106 this->latest_timestamps_by_host[hostname] = this->trace.size() - 1;
109 SimulationTimestamp<SimulationTimestampPstateSet> *& latest_timestamp = this->trace[this->latest_timestamps_by_host[hostname]];
114 if (std::fabs(new_timestamp->getDate() - latest_timestamp->getDate()) < DBL_EPSILON) {
115 std::swap(new_timestamp, latest_timestamp);
120 delete new_timestamp;
122 if (new_timestamp->getDate() > latest_timestamp->getDate()) {
123 this->trace.push_back(new_timestamp);
124 this->latest_timestamps_by_host[hostname] = this->trace.size() - 1;
126 throw std::runtime_error(
127 "SimulationTrace<SimulationTimestampPstateSet>::addTimestamp() timestamps out of order");
137 std::vector<SimulationTimestamp<SimulationTimestampPstateSet> *> getTrace() {
144 ~SimulationTrace<SimulationTimestampPstateSet>() {
145 for (
auto ×tamp: this->trace) {
151 std::map<std::string, size_t> latest_timestamps_by_host;
152 std::vector<SimulationTimestamp<SimulationTimestampPstateSet> *> trace;
162 #endif //WRENCH_SIMULATIONTRACE_H