Helios++
Helios software for LiDAR simulations
TimeWatcher Class Reference

A time watcher can be used to perform and report time measures. More...

#include <TimeWatcher.h>

Public Member Functions

 TimeWatcher ()
 Instantiate a time watcher.
 
void start ()
 Start the time watcher, which sets the starting point for a time measure. More...
 
void startIfNull ()
 Start the time watcher but only if it has not been started before. Previous start might come either from TimeWatcher::start or from TimeWatcher::startIfNull. More...
 
void releaseStart ()
 Release stored start so it is null. More...
 
bool hasStarted () const
 Check if time watcher has been started. More...
 
void stop ()
 Stop the time watcher, which sets the ending point for a time measure.
 
void saveStart ()
 Save the start time to local cache. More...
 
void loadStart ()
 Load the start time from local cache. More...
 
std::shared_ptr< std::chrono::high_resolution_clock::duration > getElapsedTime ()
 Obtain the elapsed time as the difference between the last start() and the last stop() invocations. More...
 
double getElapsedDecimalSeconds ()
 Obtain the elapsed time as the real number of seconds. More...
 
long getElapsedSeconds ()
 Obtain the elapsed time as the integer number of seconds. More...
 
long getElapsedMillis ()
 Obtain the elapsed time as the integer number of milliseconds. More...
 
long getElapsedNanos ()
 Obtain the elapsed time as the integer number of nanoseconds. More...
 
std::string getElapsedFormat ()
 Obtain the elapsed time as a string with format "HH:MM:SS". More...
 
void reportSeconds (std::string msg="Total elapsed seconds: ")
 Report elapsed seconds through specified output stream. More...
 
void reportMillis (std::string msg="Total elapsed milliseconds: ")
 Report elapsed seconds through specified output stream. More...
 
void reportFormat (std::string msg="Total elapsed time: ")
 Report elapsed time through specified output stream using "HH:MM:SS" format. More...
 
void synchronize (TimeWatcher const &source)
 Synchronizes start, end and saved start times with those of given source. More...
 

Private Member Functions

bool hasNulls ()
 Check if the time watcher has null start or end time points. More...
 
void syncTimePoints (std::unique_ptr< std::chrono::high_resolution_clock::time_point > &p, std::unique_ptr< std::chrono::high_resolution_clock::time_point > const &q)
 Synchronize time point \(p\) with time point \(q\). More...
 

Private Attributes

std::unique_ptr< std::chrono::high_resolution_clock::time_point > tStart
 Start time point. More...
 
std::unique_ptr< std::chrono::high_resolution_clock::time_point > tEnd
 End time point. More...
 
std::unique_ptr< std::chrono::high_resolution_clock::time_point > savedStart
 Used to store a temporary copy of current tStart. More...
 

Detailed Description

A time watcher can be used to perform and report time measures.

Author
Alberto M. Esmoris Pena
Version
1.0

Member Function Documentation

◆ getElapsedDecimalSeconds()

double TimeWatcher::getElapsedDecimalSeconds ( )

Obtain the elapsed time as the real number of seconds.

Returns
Elapsed time in real seconds

◆ getElapsedFormat()

std::string TimeWatcher::getElapsedFormat ( )

Obtain the elapsed time as a string with format "HH:MM:SS".

Returns
Elapsed time as "HH:MM:SS" string

◆ getElapsedMillis()

long TimeWatcher::getElapsedMillis ( )

Obtain the elapsed time as the integer number of milliseconds.

Returns
Elapsed time in integer milliseconds

◆ getElapsedNanos()

long TimeWatcher::getElapsedNanos ( )

Obtain the elapsed time as the integer number of nanoseconds.

Returns
Elapsed time in integer nanoseconds

◆ getElapsedSeconds()

long TimeWatcher::getElapsedSeconds ( )

Obtain the elapsed time as the integer number of seconds.

Returns
Elapsed time in integer seconds

◆ getElapsedTime()

std::shared_ptr< std::chrono::high_resolution_clock::duration > TimeWatcher::getElapsedTime ( )

Obtain the elapsed time as the difference between the last start() and the last stop() invocations.

Returns
Elapsed time
See also
TimeWatcher::start
TimeWatcher::stop

◆ hasNulls()

bool TimeWatcher::hasNulls ( )
private

Check if the time watcher has null start or end time points.

Returns
FALSE if the time watcher does not have neither a null start nor end time point. TRUE otherwise.

◆ hasStarted()

bool TimeWatcher::hasStarted ( ) const

Check if time watcher has been started.

Returns
True if time watcher has been started, false otherwise

◆ loadStart()

void TimeWatcher::loadStart ( )

Load the start time from local cache.

See also
TimeWatcher::tStart
TimeWatcher::saveStart

◆ releaseStart()

void TimeWatcher::releaseStart ( )

Release stored start so it is null.

For instance, following piece of code will only set the start time at first TimeWatcher::startIfNull call

// Do stuff here
A time watcher can be used to perform and report time measures.
Definition: TimeWatcher.h:13
void startIfNull()
Start the time watcher but only if it has not been started before. Previous start might come either f...
Definition: TimeWatcher.cpp:22

However, following piece of code will set the start time at second TimeWatcher::startIfNull too

// Do some stuff
// Do more stuff
void releaseStart()
Release stored start so it is null.
Definition: TimeWatcher.cpp:25

◆ reportFormat()

void TimeWatcher::reportFormat ( std::string  msg = "Total elapsed time: ")

Report elapsed time through specified output stream using "HH:MM:SS" format.

Parameters
msgMessage to be shown by the report. By default "Total elapsed time: "

◆ reportMillis()

void TimeWatcher::reportMillis ( std::string  msg = "Total elapsed milliseconds: ")

Report elapsed seconds through specified output stream.

Parameters
msgMessage to be shown by the report. By default "Total elapsed millisecconds: "

◆ reportSeconds()

void TimeWatcher::reportSeconds ( std::string  msg = "Total elapsed seconds: ")

Report elapsed seconds through specified output stream.

Parameters
msgMessage to be shown by the report. By default "Total elapsed seconds: "

◆ saveStart()

void TimeWatcher::saveStart ( )

Save the start time to local cache.

See also
TimeWatcher::tStart
TimeWatcher::loadStart

◆ start()

void TimeWatcher::start ( )

Start the time watcher, which sets the starting point for a time measure.

See also
TimeWatcher::startIfNull

◆ startIfNull()

void TimeWatcher::startIfNull ( )

Start the time watcher but only if it has not been started before. Previous start might come either from TimeWatcher::start or from TimeWatcher::startIfNull.

See also
TimeWatcher::start

◆ synchronize()

void TimeWatcher::synchronize ( TimeWatcher const &  source)

Synchronizes start, end and saved start times with those of given source.

Parameters
sourceTime watcher to be synchronized with

◆ syncTimePoints()

void TimeWatcher::syncTimePoints ( std::unique_ptr< std::chrono::high_resolution_clock::time_point > &  p,
std::unique_ptr< std::chrono::high_resolution_clock::time_point > const &  q 
)
private

Synchronize time point \(p\) with time point \(q\).

Parameters
pTime point to be synchronized
qTime point to synchronize with

Member Data Documentation

◆ savedStart

std::unique_ptr<std::chrono::high_resolution_clock::time_point> TimeWatcher::savedStart
private

Used to store a temporary copy of current tStart.

See also
TimeWatcher::tStart
TimeWatcher::saveStart
TimeWatcher::loadStart

◆ tEnd

std::unique_ptr<std::chrono::high_resolution_clock::time_point> TimeWatcher::tEnd
private

End time point.

See also
TimeWatcher::stop

◆ tStart

std::unique_ptr<std::chrono::high_resolution_clock::time_point> TimeWatcher::tStart
private

Start time point.

See also
TimeWatcher::start
TimeWatcher::savedStart

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