Kea
1.9.9-git
|
Utility class to measure code execution times. More...
#include <stopwatch.h>
Public Member Functions | |
Stopwatch (const bool autostart=true) | |
Constructor. More... | |
~Stopwatch () | |
Destructor. More... | |
boost::posix_time::time_duration | getLastDuration () const |
Retrieves last measured duration. More... | |
long | getLastMicroseconds () const |
Retrieves the last measured duration in microseconds. More... | |
long | getLastMilliseconds () const |
Retrieves the last measured duration in milliseconds. More... | |
boost::posix_time::time_duration | getTotalDuration () const |
Retrieves total measured duration. More... | |
long | getTotalMicroseconds () const |
Retrieves the total measured duration in microseconds. More... | |
long | getTotalMilliseconds () const |
Retrieves the total measured duration in milliseconds. More... | |
std::string | logFormatLastDuration () const |
Returns the last measured duration in the format directly usable in log messages. More... | |
std::string | logFormatTotalDuration () const |
Returns the total measured duration in the format directly usable in the log messages. More... | |
void | reset () |
Resets the stopwatch. More... | |
void | start () |
Starts the stopwatch. More... | |
void | stop () |
Stops the stopwatch. More... | |
Utility class to measure code execution times.
The API of this class is based on the use cases of a stopwatch. It is used to measure time spent executing portions of the code. The typical use case for the Stopwatch
is to measure the time spent invoking callouts in hooks library. This provides means for diagnosing the server's performance degradations when hooks libraries are in use.
This class exposes functions like start
, stop
and reset
which behave in the same way as a stopwatch used to measure time for sport activities.
It is possible to measure the cumulative execution time by invoking start
and stop
consecutively. The total measured time will be a sum of durations between the invocations of respective starts and stops.
Definition at line 35 of file stopwatch.h.
isc::util::Stopwatch::Stopwatch | ( | const bool | autostart = true | ) |
Constructor.
autostart | Indicates if the stopwatch should be initialized to the "started" state. In this state the stopwatch is measuring the time since it has been started (object has been constructed in this case. If the parameter is set to false (default value), the Stopwatch::start must be called to start time measurement. |
Definition at line 17 of file stopwatch.cc.
References start().
isc::util::Stopwatch::~Stopwatch | ( | ) |
boost::posix_time::time_duration isc::util::Stopwatch::getLastDuration | ( | ) | const |
Retrieves last measured duration.
If the stopwatch is in the "stopped" state this method retrieves the duration between the last start and stop. If the stopwatch is in the "started" state, the retrieved duration is the duration between the last start of the stopwatch and the current time.
Definition at line 45 of file stopwatch.cc.
References isc::util::StopwatchImpl::getLastDuration().
Referenced by getLastMicroseconds(), getLastMilliseconds(), and logFormatLastDuration().
long isc::util::Stopwatch::getLastMicroseconds | ( | ) | const |
Retrieves the last measured duration in microseconds.
Definition at line 65 of file stopwatch.cc.
References getLastDuration().
long isc::util::Stopwatch::getLastMilliseconds | ( | ) | const |
Retrieves the last measured duration in milliseconds.
Definition at line 55 of file stopwatch.cc.
References getLastDuration().
boost::posix_time::time_duration isc::util::Stopwatch::getTotalDuration | ( | ) | const |
Retrieves total measured duration.
If the stopwatch is in the "stopped" state this method retrieves the total duration between all starts and stops invoked during the lifetime of the object or since the last reset. If the stopwatch is in the "started" state, the returned is the sum of all durations between respective starts and stops, and the duration since the stopwatch has been last started and the current time.
Definition at line 50 of file stopwatch.cc.
References isc::util::StopwatchImpl::getTotalDuration().
Referenced by getTotalMicroseconds(), getTotalMilliseconds(), and logFormatTotalDuration().
long isc::util::Stopwatch::getTotalMicroseconds | ( | ) | const |
Retrieves the total measured duration in microseconds.
Definition at line 70 of file stopwatch.cc.
References getTotalDuration().
long isc::util::Stopwatch::getTotalMilliseconds | ( | ) | const |
Retrieves the total measured duration in milliseconds.
Definition at line 60 of file stopwatch.cc.
References getTotalDuration().
Referenced by isc::dhcp::AllocEngine::reclaimExpiredLeases4(), and isc::dhcp::AllocEngine::reclaimExpiredLeases6().
std::string isc::util::Stopwatch::logFormatLastDuration | ( | ) | const |
Returns the last measured duration in the format directly usable in log messages.
Definition at line 75 of file stopwatch.cc.
References getLastDuration(), and isc::util::StopwatchImpl::logFormat().
Referenced by isc::hooks::CalloutManager::callCallouts(), and isc::ha::HAService::synchronize().
std::string isc::util::Stopwatch::logFormatTotalDuration | ( | ) | const |
Returns the total measured duration in the format directly usable in the log messages.
Definition at line 80 of file stopwatch.cc.
References getTotalDuration(), and isc::util::StopwatchImpl::logFormat().
Referenced by isc::hooks::CalloutManager::callCallouts(), isc::dhcp::AllocEngine::reclaimExpiredLeases4(), and isc::dhcp::AllocEngine::reclaimExpiredLeases6().
void isc::util::Stopwatch::reset | ( | ) |
Resets the stopwatch.
It resets the stopwatch to the initial state. In this state, the last measured duration and the total duration is set to 0. The stopwatch is set to the "stopped" state.
Definition at line 40 of file stopwatch.cc.
References isc::util::StopwatchImpl::reset().
void isc::util::Stopwatch::start | ( | ) |
Starts the stopwatch.
Sets the stopwatch to the "started" state. In this state the stopwatch is measuring the duration since Stopwatch::start
has been invoked.This method is no-op if the stopwatch is already in the "started" state.
Definition at line 30 of file stopwatch.cc.
References isc::util::StopwatchImpl::start().
Referenced by isc::hooks::CalloutManager::callCallouts(), and Stopwatch().
void isc::util::Stopwatch::stop | ( | ) |
Stops the stopwatch.
Sets the stopwatch to the "stopped" state. The stopwatch stops the time measurement and records the duration between the last stopwatch start and the stop invocation. It also updates the total measured duration, i.e. the sum of durations between all start/stop invocations. Both values can be retrieved using Stopwatch::getLastDuration
and Stopwatch::getTotalDuration
respectively, or their variants.
This method is no-op if the stopwatch is already in the "stopped" state.
Definition at line 35 of file stopwatch.cc.
References isc::util::StopwatchImpl::stop().
Referenced by isc::hooks::CalloutManager::callCallouts(), isc::dhcp::AllocEngine::reclaimExpiredLeases4(), isc::dhcp::AllocEngine::reclaimExpiredLeases6(), and isc::ha::HAService::synchronize().