Kea  1.9.9-git
isc::util::Stopwatch Class Reference

Utility class to measure code execution times. More...

#include <stopwatch.h>

+ Inheritance diagram for isc::util::Stopwatch:

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

Detailed Description

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.

Constructor & Destructor Documentation

isc::util::Stopwatch::Stopwatch ( const bool  autostart = true)

Constructor.

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

+ Here is the call graph for this function:

isc::util::Stopwatch::~Stopwatch ( )

Destructor.

Destroys the implementation instance.

Definition at line 25 of file stopwatch.cc.

Member Function Documentation

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

+ Here is the call graph for this function:

long isc::util::Stopwatch::getLastMicroseconds ( ) const

Retrieves the last measured duration in microseconds.

Definition at line 65 of file stopwatch.cc.

References getLastDuration().

+ Here is the call graph for this function:

long isc::util::Stopwatch::getLastMilliseconds ( ) const

Retrieves the last measured duration in milliseconds.

Definition at line 55 of file stopwatch.cc.

References getLastDuration().

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

long isc::util::Stopwatch::getTotalMicroseconds ( ) const

Retrieves the total measured duration in microseconds.

Definition at line 70 of file stopwatch.cc.

References getTotalDuration().

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:


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