Kea 2.7.6
|
Stopwatch
class implementation.
More...
#include <stopwatch_impl.h>
Public Member Functions | |
StopwatchImpl () | |
Constructor. | |
virtual | ~StopwatchImpl () |
Virtual destructor. | |
boost::posix_time::time_duration | getLastDuration () const |
Retrieves the measured duration. | |
boost::posix_time::time_duration | getTotalDuration () const |
Retrieves the total measured duration. | |
void | reset () |
Reset the stopwatch. | |
void | start () |
Starts the stopwatch. | |
void | stop () |
Stop the stopwatch. | |
Static Public Member Functions | |
static std::string | logFormat (const boost::posix_time::time_duration &duration) |
Returns the duration in the textual format which can be directly used in log messages. | |
Protected Member Functions | |
virtual boost::posix_time::ptime | getCurrentTime () const |
Returns the current time. | |
Stopwatch
class implementation.
The Stopwatch
class uses the plimpl idiom to make it easier to unit test behavior of the Stopwatch
class without a need to rely on the system clock. The StopwatchImpl
API allows for overriding the getCurrentTime
method to return the arbitrary time value as current time to various methods. By setting the current time to arbitrary values the test can expect arbitrary values being returned by the class methods.
Also, by using the pimpl idiom the Stopwatch
class hides its implementation details and leaves the header with only the pointer to the StopwatchImpl
class.
Definition at line 28 of file stopwatch_impl.h.
isc::util::StopwatchImpl::StopwatchImpl | ( | ) |
Constructor.
Initializes the internally used timestamps. It also sets the state of the stopwatch to "stopped".
Definition at line 18 of file stopwatch_impl.cc.
|
virtual |
Virtual destructor.
This destructor is virtual because the StopwatchImpl::getCurrentTime
is virtual.
Definition at line 25 of file stopwatch_impl.cc.
|
protectedvirtual |
Returns the current time.
This method is used internally by the StopwatchImpl
class and its derivations. This class simply returns the value of boost::posix_time::microsec_clock::univeral_time()
, which is a current timestamp. The derivations may replace it with the custom implementations. The typical use case is for the unit tests to customize the behavior of this function to return well known (deterministic) values. As a result, it is possible to influence the "measured" values returned by accessors of this class, which can be compared against some exact values.
Definition at line 97 of file stopwatch_impl.cc.
Referenced by getLastDuration(), getTotalDuration(), reset(), start(), and stop().
time_duration isc::util::StopwatchImpl::getLastDuration | ( | ) | const |
Retrieves the measured duration.
Also see the Stopwatch::getLastDuration
for details.
Definition at line 61 of file stopwatch_impl.cc.
References getCurrentTime().
time_duration isc::util::StopwatchImpl::getTotalDuration | ( | ) | const |
Retrieves the total measured duration.
Also see the Stopwatch::getTotalDuration
for details.
Definition at line 70 of file stopwatch_impl.cc.
References getCurrentTime().
|
static |
Returns the duration in the textual format which can be directly used in log messages.
duration | Duration to be converted to the textual format. |
Definition at line 82 of file stopwatch_impl.cc.
Referenced by isc::util::Stopwatch::logFormatLastDuration(), and isc::util::Stopwatch::logFormatTotalDuration().
void isc::util::StopwatchImpl::reset | ( | ) |
Reset the stopwatch.
Also see the Stopwatch::reset
for details.
Definition at line 49 of file stopwatch_impl.cc.
References getCurrentTime().
void isc::util::StopwatchImpl::start | ( | ) |
Starts the stopwatch.
Sets the stopwatch to the "started" state. It also records the time when the stopwatch is started. This method is no-op if the stopwatch is already in the "started" state.
Also see the Stopwatch::start
for details.
Definition at line 29 of file stopwatch_impl.cc.
References getCurrentTime().
void isc::util::StopwatchImpl::stop | ( | ) |
Stop the stopwatch.
Sets the stopwatch to the "stopped" state. The stop time is recorded and the cumulative time is updated to include the duration between the most recent start and stop. This method is no-op if the stopwatch is already in the "stopped" state.
Also see the Stopwatch::stop
for details.
Definition at line 38 of file stopwatch_impl.cc.
References getCurrentTime().