A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
show-progress.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Lawrence Livermore National Laboratory
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Gustavo Carneiro <gjc@inescporto.pt>
18 * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
19 */
20
21#ifndef SHOW_PROGRESS_H
22#define SHOW_PROGRESS_H
23
24/**
25 * \file
26 * \ingroup core
27 * ns3::ShowProgress declaration.
28 */
29
30#include "event-id.h"
31#include "nstime.h"
34#include "time-printer.h"
35
36#include <iostream>
37
38namespace ns3
39{
40
41/**
42 * \ingroup core
43 * \ingroup debugging
44 *
45 * Periodically print a status message indicating simulator progress.
46 *
47 * Print a status message showing the simulator time and
48 * execution speed, relative to wall clock time, as well as the number
49 * of events executed each interval of wall clock time.
50 *
51 * The output interval is based on wall clock time, rather than simulation
52 * time, to avoid too many events for fast simulations, and too long of
53 * a reporting interval for very slow simulations.
54 *
55 * The target update interval (and output stream) can be configured
56 * at construction. The default output stream, if unspecified, is cout.
57 *
58 * Example usage:
59 *
60 * \code
61 * int main (int arg, char ** argv)
62 * {
63 * // Create your model
64 *
65 * ShowProgress progress (Seconds (10), std::cerr);
66 * Simulator::Run ();
67 * Simulator::Destroy ();
68 * }
69 * \endcode
70 *
71 * This generates output similar to the following:
72 *
73 * \code
74 * Start wall clock: Tue May 19 10:24:07 2020
75 * +17.179869183s ( 4.937x real time) 29559 events processed
76 * +25.769803775s ( 4.965x real time) 45179 events processed
77 * +51.539607551s ( 8.810x real time) 49421 events processed
78 * +90.324463739s ( 7.607x real time) 58021 events processed
79 * +129.770882188s ( 7.576x real time) 53850 events processed
80 * +170.958751090s ( 8.321x real time) 56473 events processed
81 * +194.339562435s ( 12.776x real time) 30957 events processed
82 * End wall clock: Tue May 19 10:24:23 2020
83 * Elapsed wall clock: 16s
84 * \endcode
85 *
86 * A more extensive example of use is provided in sample-show-progress.cc.
87 *
88 * Based on a python version by Gustavo Carneiro <gjcarneiro@gmail.com>,
89 * as released here:
90 *
91 * https://mailman.isi.edu/pipermail/ns-developers/2009-January/005039.html
92 */
94{
95 public:
96 /**
97 * Constructor.
98 * \param [in] interval The target wallclock interval to show progress.
99 * \param [in] os The stream to print on.
100 */
101 ShowProgress(const Time interval = Seconds(1.0), std::ostream& os = std::cout);
102
103 /** Destructor. */
105
106 /**
107 * Set the target update interval, in wallclock time.
108 * \param [in] interval The target wallclock interval to show progress.
109 */
110 void SetInterval(const Time interval);
111
112 /**
113 * Set the TimePrinter function to be used
114 * to prepend progress messages with the simulation time.
115 *
116 * The default is DefaultTimePrinter().
117 *
118 * \param [in] lp The TimePrinter function.
119 */
121
122 /**
123 * Set the output stream to show progress on.
124 * \param [in] os The output stream; defaults to std::cerr.
125 */
126 void SetStream(std::ostream& os);
127
128 /**
129 * Set verbose mode to print real and virtual time intervals.
130 *
131 * \param [in] verbose \c true to turn on verbose mode
132 */
133 void SetVerbose(bool verbose);
134
135 private:
136 /**
137 * Start the elapsed wallclock timestamp and print the start time.
138 * This is triggered by the constructor.
139 */
140 void Start();
141
142 /**
143 * Stop the elapsed wallclock timestamp and print the total elapsed time.
144 * This is triggered by the destructor.
145 */
146 void Stop();
147
148 /**
149 * Schedule the next CheckProgress.
150 */
152
153 /**
154 * Check on execution progress.
155 * This function is executed periodically, updates the internal
156 * state on rate of progress, and decides if it's time to generate
157 * output.
158 */
159 void CheckProgress();
160
161 /**
162 * Show execution progress.
163 * This function actually generates output, when directed by CheckProgress().
164 * \param [in] nEvents The actual number of events processed since the last
165 * progress output.
166 * \param [in] ratio The current ratio of elapsed wall clock time to the
167 * target update interval.
168 * \param [in] speed The execution speed relative to wall clock time.
169 */
170 void GiveFeedback(uint64_t nEvents, int64x64_t ratio, int64x64_t speed);
171
172 /**
173 * Hysteresis factor.
174 * \see Feedback()
175 */
176 static const int64x64_t HYSTERESIS;
177 /**
178 * Maximum growth factor.
179 * \see Feedback()
180 */
181 static const int64x64_t MAXGAIN;
182
183 SystemWallClockMs m_timer; //!< Wallclock timer
184 SystemWallClockTimestamp m_stamp; //!< Elapsed wallclock time.
185 Time m_elapsed; //!< Total elapsed wallclock time since last update.
186 Time m_interval; //!< The target update interval, in wallclock time
187 Time m_vtime; //!< The virtual time interval.
188 EventId m_event; //!< The next progress event.
189 uint64_t m_eventCount; //!< Simulator event count
190
191 TimePrinter m_printer; //!< The TimePrinter to use
192 std::ostream* m_os; //!< The output stream to use.
193 bool m_verbose; //!< Verbose mode flag
194 uint64_t m_repCount; //!< Number of CheckProgress events
195
196}; // class ShowProgress
197
198} // namespace ns3
199
200#endif /* SHOW_PROGRESS_H */
An identifier for simulation events.
Definition: event-id.h:55
Periodically print a status message indicating simulator progress.
Definition: show-progress.h:94
bool m_verbose
Verbose mode flag.
void SetVerbose(bool verbose)
Set verbose mode to print real and virtual time intervals.
std::ostream * m_os
The output stream to use.
void Start()
Start the elapsed wallclock timestamp and print the start time.
void SetTimePrinter(TimePrinter lp)
Set the TimePrinter function to be used to prepend progress messages with the simulation time.
void Stop()
Stop the elapsed wallclock timestamp and print the total elapsed time.
Time m_interval
The target update interval, in wallclock time.
uint64_t m_repCount
Number of CheckProgress events.
~ShowProgress()
Destructor.
void GiveFeedback(uint64_t nEvents, int64x64_t ratio, int64x64_t speed)
Show execution progress.
void SetStream(std::ostream &os)
Set the output stream to show progress on.
static const int64x64_t MAXGAIN
Maximum growth factor.
SystemWallClockTimestamp m_stamp
Elapsed wallclock time.
Time m_elapsed
Total elapsed wallclock time since last update.
Time m_vtime
The virtual time interval.
void ScheduleCheckProgress()
Schedule the next CheckProgress.
EventId m_event
The next progress event.
void CheckProgress()
Check on execution progress.
TimePrinter m_printer
The TimePrinter to use.
SystemWallClockMs m_timer
Wallclock timer.
void SetInterval(const Time interval)
Set the target update interval, in wallclock time.
static const int64x64_t HYSTERESIS
Hysteresis factor.
uint64_t m_eventCount
Simulator event count.
Measure elapsed wall clock time in milliseconds.
Utility class to record the difference between two wall-clock times.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
High precision numerical type, implementing Q64.64 fixed precision.
Definition: int64x64-128.h:56
ns3::EventId declarations.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void(* TimePrinter)(std::ostream &os)
Function signature for features requiring a time formatter, such as logging or ShowProgress.
Definition: time-printer.h:43
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.
bool verbose
ns3::SystemWallClockMs declaration.
ns3::SystemWallClockTimestamp declaration.
Declaration of ns3::TimePrinter function pointer type and ns3::DefaultTimePrinter function.