-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sampling period for computing the rolling average real time factor #758
Conversation
…ting the rolling average real time factor using the specified period in second.
98fded0
to
60e91b8
Compare
…ding Microsoft.GSL when consuming libcosim.
60e91b8
to
540f0b2
Compare
src/cosim/timer.cpp
Outdated
const duration& elapsedRealTime) | ||
{ | ||
const auto elapsedSimTime = currentSimulationTime - rtSimulationStartTime_; | ||
metrics_->rolling_average_real_time_factor = elapsedSimTime.count() / (1.0 * elapsedRealTime.count()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elapsedSimTime
and elapsedRealTime
are two different std::chrono::duration
types associated with different clocks. The former is associated with Time
, which is an alias for std::chrono::steady_clock
and represents real time, while the latter is associated with cosim::detail::clock
, which is a clock defined to represent simulation time. Therefore, it might be fragile to use their count()
values like this, because it assumes that their tick period is the same.
Two options:
- Insert
std::duration_cast
calls and cast them to a common type with the same tick period. - Insert a compile-time check like
static_assert(decltype(elapsedSimTime)::period == decltype(elapsedRealTime)::period);
I think I prefer the first one if it works, but there may be arguments in favour of the latter too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now that this is old code moved from elsewhere in the file. But then this is a good opportunity to fix it. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added duration_cast
as well as in update_rolling_average_real_time_factor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After adding duration_cast (or some other updates), I see noticeable performance drops. Investigating on it..
The issue was due to my laptop, updated as suggested.
@kyllingstad
Seems the problem was due to my local PC. Will try the original suggestion. |
51e95bf
to
d584596
Compare
05c4ecc
to
2ff7de3
Compare
9801fa2
to
55ce42e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
When the simulation step size is too small, e.g. 0.001, a fixed
cosim::real_time_config.steps_to_monitor
value would not be sufficient to compute the rolling average real time factor because of the following scenario:steps_to_monitor
to a large value (1000) because the default 5 is too small window size to accurately compute RTF.To avoid this problem,
cosim::real_time_config.sampling_period_to_monitor
is introduced. It sets a sampling period in second(s) used in the rolling average real time factor calculation. When the value is greater than zero, the real time factor is computed periodically using the specified time instead of thesteps_to_monitor
value.