delphyne
InteractiveSimulationStats Class Reference

Detailed Description

A class that keeps statistics on a interactive simulation session An interactive session is usually composed of one or more simulation runs, depending on the interactions with the external world.

As an example consider the following scenario, where the simulation step is of 1ms:

  • An interactive simulation starts at a 1.0 real-time rate and is paused after 5 secs.
  • Some time T1 goes by.
  • The real-time rate is changed to 2.0 and a request to execute 2000 steps is placed, each step taking 1ms sim time.
  • Some time T2 goes by.
  • The real-time rate is changed to 0.5 and the simulation is unpaused.
  • The simulation is stopped after 10 secs.

For this case, the interactive simulation statistics would be composed of three runs:

  • A 5 sec (both simulation time and real time) run, with 5000 steps.
  • A 2 sec simulation time, 1 sec real time run, with 2000 steps.
  • A 5 sec simulation time, 10 sec real time run, with 5000 steps.

Hence the total numbers would be:

  • 12 secs sim time
  • 16 secs real time
  • 12000 steps

Note that T1 and T2 are not considered, as during those time the simulation was idle.

#include <src/backend/interactive_simulation_stats.h>

Public Member Functions

 DELPHYNE_NO_COPY_NO_MOVE_NO_ASSIGN (InteractiveSimulationStats)
 
 InteractiveSimulationStats ()=default
 
void NewRunStartingAt (double start_simtime, double expected_realtime_rate)
 Creates a new simulation run, starting at start_simtime More...
 
void NewRunStartingAt (double start_simtime, double expected_realtime_rate, const TimePoint &start_realtime)
 Creates a new simulation run, starting at start_simtime More...
 
TimePoint StepExecuted (double simtime)
 Records that a step was executed by the simulator and records it as part of the current simulation run. More...
 
void RealtimeStepExecuted (const TimePoint &realtime)
 Sets the time when the step is completed and records it as part of the current simulation run. More...
 
void RealtimeStepExecuted ()
 Sets the time when the step is completed and records it as part of the current simulation run. More...
 
SimulationRunStats GetCurrentRunStats () const
 Returns a copy of the current running simulation stats. More...
 
double TotalElapsedSimtime () const
 Returns the sum of the elapsed simulation time of all the simulation runs. More...
 
double TotalElapsedRealtime () const
 Returns the sum of the elapsed real time of all the simulation runs. More...
 
int TotalExecutedSteps () const
 Returns the sum of the executed steps of all the simulation runs. More...
 
int TotalRuns () const
 Returns the number of simulation runs. More...
 
double get_current_realtime_rate () const
 Returns the current real-time rate by doing a weighted cumulative sum. More...
 

Constructor & Destructor Documentation

◆ InteractiveSimulationStats()

Member Function Documentation

◆ DELPHYNE_NO_COPY_NO_MOVE_NO_ASSIGN()

DELPHYNE_NO_COPY_NO_MOVE_NO_ASSIGN ( InteractiveSimulationStats  )

◆ get_current_realtime_rate()

double get_current_realtime_rate ( ) const

Returns the current real-time rate by doing a weighted cumulative sum.

We use this method instead of just dividing total_elapsed_simtime_ by total_elapsed_simtime_ because that would require a long time to adjust to real-time rate changes. As an example of this behavior consider an interactive simulation configured with a 1ms simulation step. Assuming that it starts with a simulation run of 100 seconds at 1.0 real-time, ff we then change the real-time rate to 0.1, after the first execution step we would have:

  • Total elapsed simulation time: 100s + 0.001s = 100.001s
  • Total elapsed real time: 100s + 0.01s = 100.01s whose real-time rate would yield 0.99991. If we take this further and let the second run execute for 100s (i.e. 10,000 steps) we would get:
  • Total elapsed simulation time: 110s
  • Total elapsed real time: 200s whose real-time rate would yield 0.55, which is still far away from the 0.1 configured step.

In contrast, by using a weighted cumulative sum to compute the real-time rate, the latest steps are given more importance in the computation, allowing the rate to quickly update to configuration changes. Continuing with the above example and using a 0.5 weighing factor, in only 15 steps the real-time rate drops to ~0.102, closely matching our 0.1 configured factor.

◆ GetCurrentRunStats()

SimulationRunStats GetCurrentRunStats ( ) const

Returns a copy of the current running simulation stats.

See also
SimulationRunStats

◆ NewRunStartingAt() [1/2]

void NewRunStartingAt ( double  start_simtime,
double  expected_realtime_rate 
)

Creates a new simulation run, starting at start_simtime

Parameters
[in]start_simtimeThe time the simulation started, given by the simulator clock.
[in]expected_realtime_rateThe desired real time based in the simulation runner configuration.

◆ NewRunStartingAt() [2/2]

void NewRunStartingAt ( double  start_simtime,
double  expected_realtime_rate,
const TimePoint start_realtime 
)

Creates a new simulation run, starting at start_simtime

Parameters
[in]start_simtimeThe time the simulation started, given by the simulator clock.
[in]expected_realtime_rateThe desired real time based in the simulation runner configuration.
[in]start_realtimeThe time the simulation started, given by the real-time clock.

◆ RealtimeStepExecuted() [1/2]

void RealtimeStepExecuted ( )

Sets the time when the step is completed and records it as part of the current simulation run.

◆ RealtimeStepExecuted() [2/2]

void RealtimeStepExecuted ( const TimePoint realtime)

Sets the time when the step is completed and records it as part of the current simulation run.

Parameters
[in]realtimeThe time the step took to execute, given by the wall clock.

◆ StepExecuted()

TimePoint StepExecuted ( double  simtime)

Records that a step was executed by the simulator and records it as part of the current simulation run.

Assumes that the realtime counterpart is the current time.

Parameters
[in]simtimeThe time the step was executed, in seconds, given by the simulator clock.

◆ TotalElapsedRealtime()

double TotalElapsedRealtime ( ) const

Returns the sum of the elapsed real time of all the simulation runs.

◆ TotalElapsedSimtime()

double TotalElapsedSimtime ( ) const

Returns the sum of the elapsed simulation time of all the simulation runs.

◆ TotalExecutedSteps()

int TotalExecutedSteps ( ) const

Returns the sum of the executed steps of all the simulation runs.

◆ TotalRuns()

int TotalRuns ( ) const

Returns the number of simulation runs.


The documentation for this class was generated from the following files: