Kea 2.5.8
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.
 
 ~Stopwatch ()
 Destructor.
 
boost::posix_time::time_duration getLastDuration () const
 Retrieves last measured duration.
 
long getLastMicroseconds () const
 Retrieves the last measured duration in microseconds.
 
long getLastMilliseconds () const
 Retrieves the last measured duration in milliseconds.
 
boost::posix_time::time_duration getTotalDuration () const
 Retrieves total measured duration.
 
long getTotalMicroseconds () const
 Retrieves the total measured duration in microseconds.
 
long getTotalMilliseconds () const
 Retrieves the total measured duration in milliseconds.
 
std::string logFormatLastDuration () const
 Returns the last measured duration in the format directly usable in log messages.
 
std::string logFormatTotalDuration () const
 Returns the total measured duration in the format directly usable in the log messages.
 
void reset ()
 Resets the stopwatch.
 
void start ()
 Starts the stopwatch.
 
void stop ()
 Stops the stopwatch.
 

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

◆ Stopwatch()

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:

◆ ~Stopwatch()

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

Destructor.

Destroys the implementation instance.

Definition at line 25 of file stopwatch.cc.

Member Function Documentation

◆ getLastDuration()

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 44 of file stopwatch.cc.

Referenced by getLastMicroseconds(), getLastMilliseconds(), and logFormatLastDuration().

◆ getLastMicroseconds()

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

Retrieves the last measured duration in microseconds.

Definition at line 64 of file stopwatch.cc.

References getLastDuration().

+ Here is the call graph for this function:

◆ getLastMilliseconds()

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

Retrieves the last measured duration in milliseconds.

Definition at line 54 of file stopwatch.cc.

References getLastDuration().

+ Here is the call graph for this function:

◆ getTotalDuration()

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 49 of file stopwatch.cc.

Referenced by getTotalMicroseconds(), getTotalMilliseconds(), and logFormatTotalDuration().

◆ getTotalMicroseconds()

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

Retrieves the total measured duration in microseconds.

Definition at line 69 of file stopwatch.cc.

References getTotalDuration().

+ Here is the call graph for this function:

◆ getTotalMilliseconds()

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

Retrieves the total measured duration in milliseconds.

Definition at line 59 of file stopwatch.cc.

References getTotalDuration().

Referenced by isc::dhcp::AllocEngine::reclaimExpiredLeases4Internal(), and isc::dhcp::AllocEngine::reclaimExpiredLeases6Internal().

+ Here is the call graph for this function:

◆ logFormatLastDuration()

std::string isc::util::Stopwatch::logFormatLastDuration ( ) const

Returns the last measured duration in the format directly usable in log messages.

Definition at line 74 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:

◆ logFormatTotalDuration()

std::string isc::util::Stopwatch::logFormatTotalDuration ( ) const

Returns the total measured duration in the format directly usable in the log messages.

Definition at line 79 of file stopwatch.cc.

References getTotalDuration(), and isc::util::StopwatchImpl::logFormat().

Referenced by isc::hooks::CalloutManager::callCallouts(), isc::dhcp::AllocEngine::reclaimExpiredLeases4Internal(), and isc::dhcp::AllocEngine::reclaimExpiredLeases6Internal().

+ Here is the call graph for this function:

◆ reset()

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 39 of file stopwatch.cc.

◆ start()

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 29 of file stopwatch.cc.

Referenced by Stopwatch(), and isc::hooks::CalloutManager::callCallouts().

◆ stop()

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 34 of file stopwatch.cc.

Referenced by isc::hooks::CalloutManager::callCallouts(), isc::dhcp::AllocEngine::reclaimExpiredLeases4Internal(), isc::dhcp::AllocEngine::reclaimExpiredLeases6Internal(), isc::ha::HAService::sendLeaseUpdatesFromBacklog(), and isc::ha::HAService::synchronize().


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