Periodically print a status message indicating simulator progress. More...
#include "show-progress.h"
Public Member Functions | |
ShowProgress (const Time interval=Seconds(1.0), std::ostream &os=std::cout) | |
Constructor. More... | |
void | SetInterval (const Time interval) |
Set the target update interval, in wallclock time. More... | |
void | SetStream (std::ostream &os) |
Set the output stream to show progress on. More... | |
void | SetTimePrinter (TimePrinter lp) |
Set the TimePrinter function to be used to prepend progress messages with the simulation time. More... | |
void | SetVerbose (bool verbose) |
Set verbose mode to print real and virtual time intervals. More... | |
void | Start (void) |
Start the progress timer. More... | |
Private Member Functions | |
void | Feedback (void) |
Show execution progress. More... | |
Private Attributes | |
const int64x64_t | HYSTERESIS = 1.2 |
Hysteresis factor. More... | |
EventId | m_event |
The next progress event. More... | |
uint64_t | m_eventCount |
Simulator event count. More... | |
Time | m_interval |
The target update interval, in wallclock time. More... | |
std::ostream * | m_os |
The output stream to use. More... | |
TimePrinter | m_printer |
The TimePrinter to use. More... | |
uint64_t | m_repCount |
Count of progress lines printed. More... | |
SystemWallClockMs | m_timer |
Wallclock timer. More... | |
bool | m_verbose |
Verbose mode flag. More... | |
Time | m_vtime |
The virtual time interval. More... | |
const int64x64_t | MAXGAIN = 2.0 |
Maximum growth factor. More... | |
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.
The target update rate (and output stream) can be configured at construction.
Example usage:
Based on a python version by Gustavo Carneiro gjcar, as released here: neir o@gma il.c omhttp://mailman.isi.edu/pipermail/ns-developers/2009-January/005201.html
Definition at line 69 of file show-progress.h.
ns3::ShowProgress::ShowProgress | ( | const Time | interval = Seconds (1.0) , |
std::ostream & | os = std::cout |
||
) |
Constructor.
[in] | interval | The target wallclock interval to show progress. |
[in] | os | The stream to print on. |
Definition at line 42 of file show-progress.cc.
References NS_LOG_FUNCTION, and Start().
|
private |
Show execution progress.
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 -|============================================== | | *= ratio | 1/ MAXGAIN -|--------------- *= max (ratio, 1/ MAXGAIN) | | *= 1/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.
Definition at line 100 of file show-progress.cc.
References ns3::Time::As(), ns3::SystemWallClockMs::End(), ns3::int64x64_t::GetDouble(), ns3::Simulator::GetEventCount(), HYSTERESIS, m_eventCount, m_interval, m_os, m_repCount, m_timer, m_verbose, m_vtime, max, MAXGAIN, ns3::MilliSeconds(), min, NS_LOG_FUNCTION, ns3::Time::S, and Start().
Referenced by Start().
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 59 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 85 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 71 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 78 of file show-progress.cc.
References m_verbose, NS_LOG_FUNCTION, and verbose.
void ns3::ShowProgress::Start | ( | void | ) |
Start the progress timer.
Definition at line 91 of file show-progress.cc.
References Feedback(), m_event, m_timer, m_vtime, NS_LOG_FUNCTION, ns3::Simulator::Schedule(), and ns3::SystemWallClockMs::Start().
Referenced by Feedback(), SetInterval(), and ShowProgress().
|
private |
Hysteresis factor.
Definition at line 121 of file show-progress.h.
Referenced by Feedback().
|
private |
The next progress event.
Definition at line 131 of file show-progress.h.
Referenced by SetInterval(), and Start().
|
private |
|
private |
The target update interval, in wallclock time.
Definition at line 129 of file show-progress.h.
Referenced by Feedback(), and SetInterval().
|
private |
The output stream to use.
Definition at line 135 of file show-progress.h.
Referenced by Feedback(), and SetStream().
|
private |
The TimePrinter to use.
Definition at line 134 of file show-progress.h.
Referenced by SetTimePrinter().
|
private |
Count of progress lines printed.
Definition at line 137 of file show-progress.h.
Referenced by Feedback().
|
private |
Wallclock timer.
Definition at line 128 of file show-progress.h.
Referenced by Feedback(), and Start().
|
private |
Verbose mode flag.
Definition at line 136 of file show-progress.h.
Referenced by Feedback(), and SetVerbose().
|
private |
The virtual time interval.
Definition at line 130 of file show-progress.h.
Referenced by Feedback(), SetInterval(), and Start().
|
private |
Maximum growth factor.
Definition at line 126 of file show-progress.h.
Referenced by Feedback().