Skip to content

Commit

Permalink
Additional fix
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhjp01 committed May 7, 2024
1 parent 2ff7de3 commit 55ce42e
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/cosim/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,32 @@ class real_time_timer::impl
time_point& currentSimulationTime,
const cosim::duration& elapsedRealTime)
{
const auto elapsedSimTime =
tick_period_match_ ? currentSimulationTime - rtSimulationStartTime_ : std::chrono::duration_cast<cosim::duration>(currentSimulationTime - rtSimulationStartTime_);

metrics_->rolling_average_real_time_factor = elapsedSimTime.count() / (1.0 * elapsedRealTime.count());
const auto elapsedSimTime = currentSimulationTime - rtSimulationStartTime_;
if (tick_period_match_) {
metrics_->rolling_average_real_time_factor = elapsedSimTime.count() / (1.0 * elapsedRealTime.count());
} else {
metrics_->rolling_average_real_time_factor =
std::chrono::duration_cast<cosim::duration>(elapsedSimTime).count() / (1.0 * std::chrono::duration_cast<cosim::duration>(elapsedRealTime).count());
}
rtStartTime_ = currentTime;
rtSimulationStartTime_ = currentSimulationTime;
rtCounter_ = 0L;
}

void update_real_time_factor(Time::time_point currentTime, time_point currentSimulationTime)
{
const auto relativeSimTime =
tick_period_match_ ? currentSimulationTime - simulationStartTime_ : std::chrono::duration_cast<cosim::duration>(currentSimulationTime - simulationStartTime_);
const auto relativeRealTime =
tick_period_match_ ? currentTime - startTime_ : std::chrono::duration_cast<cosim::duration>(currentTime - startTime_);

metrics_->total_average_real_time_factor = relativeSimTime.count() / (1.0 * relativeRealTime.count());
const auto relativeSimTime = currentSimulationTime - simulationStartTime_;
const auto relativeRealTime = currentTime - startTime_;

if (tick_period_match_) {
metrics_->total_average_real_time_factor = relativeSimTime.count() / (1.0 * relativeRealTime.count());
} else {
metrics_->total_average_real_time_factor =
std::chrono::duration_cast<cosim::duration>(relativeSimTime).count() / (1.0 * std::chrono::duration_cast<cosim::duration>(relativeRealTime).count());
}

if (sampling_period_to_monitor_.has_value()) {
const auto elapsedRealTime =
tick_period_match_ ? currentTime - rtStartTime_ : std::chrono::duration_cast<cosim::duration>(currentTime - rtStartTime_);
const auto elapsedRealTime = currentTime - rtStartTime_;

if (elapsedRealTime > sampling_period_to_monitor_.value()) {
update_rolling_average_real_time_factor(currentTime, currentSimulationTime, elapsedRealTime);
Expand Down

0 comments on commit 55ce42e

Please sign in to comment.