A Discrete-Event Network Simulator
API
ns3::ShowProgress Class Reference

Periodically print a status message indicating simulator progress. More...

#include "show-progress.h"

+ Collaboration diagram for ns3::ShowProgress:

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...
 

Detailed Description

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:

int main (int arg, char ** argv)
{
// Create your model
ShowProgress (Seconds (1), std::cerr);
}

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: http://mailman.isi.edu/pipermail/ns-developers/2009-January/005201.html

Definition at line 69 of file show-progress.h.

Constructor & Destructor Documentation

◆ ShowProgress()

ns3::ShowProgress::ShowProgress ( const Time  interval = Seconds (1.0),
std::ostream &  os = std::cout 
)

Constructor.

Parameters
[in]intervalThe target wallclock interval to show progress.
[in]osThe stream to print on.

Definition at line 42 of file show-progress.cc.

References NS_LOG_FUNCTION, and Start().

+ Here is the call graph for this function:

Member Function Documentation

◆ Feedback()

void ns3::ShowProgress::Feedback ( void  )
private

Show execution progress.

Internal: Update algorithm

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:

\[ ratio = \frac{elapsed}{target 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetInterval()

void ns3::ShowProgress::SetInterval ( const Time  interval)

Set the target update interval, in wallclock time.

Parameters
[in]intervalThe 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().

+ Here is the call graph for this function:

◆ SetStream()

void ns3::ShowProgress::SetStream ( std::ostream &  os)

Set the output stream to show progress on.

Parameters
[in]osThe output stream; defaults to std::cerr.

Definition at line 85 of file show-progress.cc.

References m_os.

◆ SetTimePrinter()

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().

Parameters
[in]lpThe TimePrinter function.

Definition at line 71 of file show-progress.cc.

References m_printer, and NS_LOG_FUNCTION.

◆ SetVerbose()

void ns3::ShowProgress::SetVerbose ( bool  verbose)

Set verbose mode to print real and virtual time intervals.

Parameters
[in]verbosetrue to turn on verbose mode

Definition at line 78 of file show-progress.cc.

References m_verbose, NS_LOG_FUNCTION, and verbose.

◆ Start()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ HYSTERESIS

const int64x64_t ns3::ShowProgress::HYSTERESIS = 1.2
private

Hysteresis factor.

See also
Feedback()

Definition at line 121 of file show-progress.h.

Referenced by Feedback().

◆ m_event

EventId ns3::ShowProgress::m_event
private

The next progress event.

Definition at line 131 of file show-progress.h.

Referenced by SetInterval(), and Start().

◆ m_eventCount

uint64_t ns3::ShowProgress::m_eventCount
private

Simulator event count.

Definition at line 132 of file show-progress.h.

Referenced by Feedback().

◆ m_interval

Time ns3::ShowProgress::m_interval
private

The target update interval, in wallclock time.

Definition at line 129 of file show-progress.h.

Referenced by Feedback(), and SetInterval().

◆ m_os

std::ostream* ns3::ShowProgress::m_os
private

The output stream to use.

Definition at line 135 of file show-progress.h.

Referenced by Feedback(), and SetStream().

◆ m_printer

TimePrinter ns3::ShowProgress::m_printer
private

The TimePrinter to use.

Definition at line 134 of file show-progress.h.

Referenced by SetTimePrinter().

◆ m_repCount

uint64_t ns3::ShowProgress::m_repCount
private

Count of progress lines printed.

Definition at line 137 of file show-progress.h.

Referenced by Feedback().

◆ m_timer

SystemWallClockMs ns3::ShowProgress::m_timer
private

Wallclock timer.

Definition at line 128 of file show-progress.h.

Referenced by Feedback(), and Start().

◆ m_verbose

bool ns3::ShowProgress::m_verbose
private

Verbose mode flag.

Definition at line 136 of file show-progress.h.

Referenced by Feedback(), and SetVerbose().

◆ m_vtime

Time ns3::ShowProgress::m_vtime
private

The virtual time interval.

Definition at line 130 of file show-progress.h.

Referenced by Feedback(), SetInterval(), and Start().

◆ MAXGAIN

const int64x64_t ns3::ShowProgress::MAXGAIN = 2.0
private

Maximum growth factor.

See also
Feedback()

Definition at line 126 of file show-progress.h.

Referenced by Feedback().


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