Periodically print a status message indicating simulator progress. More...
#include "show-progress.h"
Public Member Functions | |
ShowProgress (const Time interval=Seconds(1), std::ostream &os=std::cout) | |
Constructor. | |
~ShowProgress () | |
Destructor. | |
void | SetInterval (const Time interval) |
Set the target update interval, in wallclock time. | |
void | SetStream (std::ostream &os) |
Set the output stream to show progress on. | |
void | SetTimePrinter (TimePrinter lp) |
Set the TimePrinter function to be used to prepend progress messages with the simulation time. | |
void | SetVerbose (bool verbose) |
Set verbose mode to print real and virtual time intervals. | |
Private Member Functions | |
void | CheckProgress () |
Check on execution progress. | |
void | GiveFeedback (uint64_t nEvents, int64x64_t ratio, int64x64_t speed) |
Show execution progress. | |
void | ScheduleCheckProgress () |
Schedule the next CheckProgress. | |
void | Start () |
Start the elapsed wallclock timestamp and print the start time. | |
void | Stop () |
Stop the elapsed wallclock timestamp and print the total elapsed time. | |
Private Attributes | |
Time | m_elapsed |
Total elapsed wallclock time since last update. | |
EventId | m_event |
The next progress event. | |
uint64_t | m_eventCount |
Simulator event count. | |
Time | m_interval |
The target update interval, in wallclock time. | |
std::ostream * | m_os |
The output stream to use. | |
TimePrinter | m_printer |
The TimePrinter to use. | |
uint64_t | m_repCount |
Number of CheckProgress events. | |
SystemWallClockTimestamp | m_stamp |
Elapsed wallclock time. | |
SystemWallClockMs | m_timer |
Wallclock timer. | |
bool | m_verbose |
Verbose mode flag. | |
Time | m_vtime |
The virtual time interval. | |
Static Private Attributes | |
static const int64x64_t | HYSTERESIS = 1.414 |
Hysteresis factor. | |
static const int64x64_t | MAXGAIN = 2.0 |
Maximum growth factor. | |
Periodically print a status message indicating simulator progress.
Print a status message showing the simulator time and execution speed, relative to wall clock time, as well as the number of events executed each interval of wall clock time.
The output interval is based on wall clock time, rather than simulation time, to avoid too many events for fast simulations, and too long of a reporting interval for very slow simulations.
The target update interval (and output stream) can be configured at construction. The default output stream, if unspecified, is cout.
Example usage:
This generates output similar to the following:
A more extensive example of use is provided in sample-show-progress.cc.
Based on a python version by Gustavo Carneiro gjcar.nosp@m.neir.nosp@m.o@gma.nosp@m.il.c.nosp@m.om, as released here:
https://mailman.isi.edu/pipermail/ns-developers/2009-January/005039.html
Definition at line 82 of file show-progress.h.
Constructor.
[in] | interval | The target wallclock interval to show progress. |
[in] | os | The stream to print on. |
Definition at line 35 of file show-progress.cc.
References NS_LOG_FUNCTION, ScheduleCheckProgress(), and Start().
ns3::ShowProgress::~ShowProgress | ( | ) |
Destructor.
Definition at line 54 of file show-progress.cc.
References Stop().
|
private |
Check on execution progress.
This function is executed periodically, updates the internal state on rate of progress, and decides if it's time to generate output.
We steer m_vtime
to obtain updates approximately every m_interval
in wall clock time. To smooth things out a little we impose a hysteresis band around m_interval
where we don't change m_vtime
. To avoid too rapid movements chasing spikes or dips in execution rate, we bound the change in m_vtime
to a maximum factor.
In mathematical terms, we compute the ratio of elapsed wall clock time compared to the target reporting interval:
Graphically, the windows in ratio value and the corresponding updates to m_vtime
are sketched in this figure:
^ | ratio | vtime update | | | /= MAXGAIN | MAXGAIN -|-------------- /= min (ratio, MAXGAIN) | | /= ratio | HYSTERESIS -|============================================= | | | 1 -| No change | | | 1/ HYSTERESIS -|============================================== | | *= 1 / ratio | 1/ MAXGAIN -|--------------- *= min (1 / ratio, MAXGAIN) | | *= MAXGAIN |
As indicated, when ratio is outside the hysteresis band it amounts to multiplying m_vtime
by the min/max of the ratio with the appropriate MAXGAIN factor.
Finally, some experimentation suggests we further dampen movement between HYSTERESIS and MAXGAIN, so we only apply half the ratio. This reduces "hunting" for a stable update period.
Definition at line 138 of file show-progress.cc.
References ns3::SystemWallClockMs::End(), ns3::Simulator::GetEventCount(), GiveFeedback(), HYSTERESIS, ns3::Time::IsNegative(), m_elapsed, m_eventCount, m_interval, m_repCount, m_timer, m_vtime, MAXGAIN, ns3::MilliSeconds(), NS_LOG_FUNCTION, NS_LOG_LOGIC, and ScheduleCheckProgress().
Referenced by ScheduleCheckProgress().
|
private |
Show execution progress.
This function actually generates output, when directed by CheckProgress().
[in] | nEvents | The actual number of events processed since the last progress output. |
[in] | ratio | The current ratio of elapsed wall clock time to the target update interval. |
[in] | speed | The execution speed relative to wall clock time. |
Definition at line 106 of file show-progress.cc.
References ns3::Time::As(), ns3::int64x64_t::GetDouble(), HYSTERESIS, m_elapsed, m_interval, m_os, m_repCount, m_verbose, m_vtime, and ns3::Time::S.
Referenced by CheckProgress().
|
private |
Schedule the next CheckProgress.
Definition at line 97 of file show-progress.cc.
References CheckProgress(), m_event, m_timer, m_vtime, NS_LOG_FUNCTION, ns3::Simulator::Schedule(), and ns3::SystemWallClockMs::Start().
Referenced by ShowProgress(), and CheckProgress().
void ns3::ShowProgress::SetInterval | ( | const Time | interval | ) |
Set the target update interval, in wallclock time.
[in] | interval | The target wallclock interval to show progress. |
Definition at line 60 of file show-progress.cc.
References ns3::Simulator::Cancel(), m_event, m_interval, m_vtime, NS_LOG_FUNCTION, and Start().
void ns3::ShowProgress::SetStream | ( | std::ostream & | os | ) |
Set the output stream to show progress on.
[in] | os | The output stream; defaults to std::cerr. |
Definition at line 91 of file show-progress.cc.
References m_os.
void ns3::ShowProgress::SetTimePrinter | ( | TimePrinter | lp | ) |
Set the TimePrinter function to be used to prepend progress messages with the simulation time.
The default is DefaultTimePrinter().
[in] | lp | The TimePrinter function. |
Definition at line 77 of file show-progress.cc.
References m_printer, and NS_LOG_FUNCTION.
void ns3::ShowProgress::SetVerbose | ( | bool | verbose | ) |
Set verbose mode to print real and virtual time intervals.
[in] | verbose | true to turn on verbose mode |
Definition at line 84 of file show-progress.cc.
References m_verbose, NS_LOG_FUNCTION, and verbose.
|
private |
Start the elapsed wallclock timestamp and print the start time.
This is triggered by the constructor.
Definition at line 262 of file show-progress.cc.
References m_stamp, ns3::SystemWallClockTimestamp::Stamp(), and ns3::SystemWallClockTimestamp::ToString().
Referenced by ShowProgress(), and SetInterval().
|
private |
Stop the elapsed wallclock timestamp and print the total elapsed time.
This is triggered by the destructor.
Definition at line 269 of file show-progress.cc.
References ns3::SystemWallClockTimestamp::GetInterval(), m_stamp, ns3::SystemWallClockTimestamp::Stamp(), and ns3::SystemWallClockTimestamp::ToString().
Referenced by ~ShowProgress().
|
staticprivate |
Hysteresis factor.
Definition at line 165 of file show-progress.h.
Referenced by CheckProgress(), and GiveFeedback().
|
private |
Total elapsed wallclock time since last update.
Definition at line 174 of file show-progress.h.
Referenced by CheckProgress(), and GiveFeedback().
|
private |
The next progress event.
Definition at line 177 of file show-progress.h.
Referenced by ScheduleCheckProgress(), and SetInterval().
|
private |
Simulator event count.
Definition at line 178 of file show-progress.h.
Referenced by CheckProgress().
|
private |
The target update interval, in wallclock time.
Definition at line 175 of file show-progress.h.
Referenced by CheckProgress(), GiveFeedback(), and SetInterval().
|
private |
The output stream to use.
Definition at line 181 of file show-progress.h.
Referenced by GiveFeedback(), and SetStream().
|
private |
The TimePrinter to use.
Definition at line 180 of file show-progress.h.
Referenced by SetTimePrinter().
|
private |
Number of CheckProgress events.
Definition at line 183 of file show-progress.h.
Referenced by CheckProgress(), and GiveFeedback().
|
private |
Elapsed wallclock time.
Definition at line 173 of file show-progress.h.
|
private |
Wallclock timer.
Definition at line 172 of file show-progress.h.
Referenced by CheckProgress(), and ScheduleCheckProgress().
|
private |
Verbose mode flag.
Definition at line 182 of file show-progress.h.
Referenced by GiveFeedback(), and SetVerbose().
|
private |
The virtual time interval.
Definition at line 176 of file show-progress.h.
Referenced by CheckProgress(), GiveFeedback(), ScheduleCheckProgress(), and SetInterval().
|
staticprivate |
Maximum growth factor.
Definition at line 170 of file show-progress.h.
Referenced by CheckProgress().