DABC (Data Acquisition Backbone Core)  2.9.9
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends
dabc::TimeStamp Struct Reference

Class for acquiring and holding timestamps. More...

#include <dabc/timing.h>

Public Member Functions

double AsDouble () const
 Return time stamp in form of double (in seconds) More...
 
bool Expired (const TimeStamp &curr, double interval) const
 Method returns true if specified time interval expired relative to time, kept in TimeStamp instance. More...
 
bool Expired (double interval=0.) const
 Method returns true if specified time interval expired relative to time, kept in TimeStamp instance. More...
 
void GetNow ()
 Method to acquire current time stamp. More...
 
void GetNow (double shift)
 Method to acquire current time stamp plus shift in seconds. More...
 
bool null () const
 Returns true if time stamp is not initialized or its value less than 0. More...
 
double operator() () const
 
TimeStamp operator+ (double _add) const
 
TimeStampoperator+= (double _add)
 
double operator- (const TimeStamp &src) const
 
TimeStamp operator- (double _sub) const
 
TimeStampoperator-= (double _sub)
 
bool operator< (const TimeStamp &src) const
 
TimeStampoperator= (const TimeStamp &src)
 
bool operator== (const TimeStamp &src) const
 
bool operator> (const TimeStamp &src) const
 
void Reset ()
 Set time stamp value to null. More...
 
double SpentTillNow () const
 Method return time in second, spent from the time kept in TimeStamp instance If time was not set before, returns 0. More...
 
double SpentTillNow (bool set_to_now)
 Method return time in second, spent from the time kept in TimeStamp instance If specified, automatically set to the current time If time was not set before, returns 0. More...
 
 TimeStamp ()
 
 TimeStamp (const TimeStamp &src)
 

Static Public Member Functions

static TimeStamp Now ()
 Method returns TimeStamp instance with current time stamp value, measured either by fast TSC (if it is detected and working correctly), otherwise slow getclock() method will be used. More...
 
static void SetUseSlow ()
 

Protected Types

typedef slowclock_t fastclock_t
 
typedef long long int slowclock_t
 

Protected Member Functions

 TimeStamp (double v)
 

Static Protected Member Functions

static double CalculateFastClockMult ()
 
static bool CheckLinuxTSC ()
 
static TimeStamp Fast ()
 Method returns TimeStamp instance with current time, measure by fast TSC clock. More...
 
static fastclock_t GetFastClock ()
 
static slowclock_t GetSlowClock ()
 
static TimeStamp Slow ()
 Method returns TimeStamp instance with current time, measured by 'slow' getclock() function. More...
 

Protected Attributes

double fValue
 time since start of the application in seconds More...
 

Static Protected Attributes

static bool gFast = false
 indicates if fast or slow method is used for time measurement More...
 
static double gFastClockMult = CalculateFastClockMult()
 
static fastclock_t gFastClockZero = dabc::TimeStamp::GetFastClock()
 
static slowclock_t gSlowClockZero = dabc::TimeStamp::GetSlowClock()
 

Friends

class Profiler
 

Detailed Description

Class for acquiring and holding timestamps.

Time measurement is done in seconds relative to program start. In normal case constant tsc counter is used - by program start during 0.1 seconds value of tsc counter compared with normal monolitic clock. If deviation is less than 0.01%, tsc counter will be used for the measurement, otherwise normal standard getclock. Major difference is performance. TSC counter can be read within 20 nanosec while getclock call takes about 300 ns. Before usage of TSC it is checked that constant_tsc is supported by the CPU looking in /proc/cpuinfo file.

Definition at line 40 of file timing.h.

Member Typedef Documentation

◆ slowclock_t

typedef long long int dabc::TimeStamp::slowclock_t
protected

Definition at line 49 of file timing.h.

◆ fastclock_t

Definition at line 80 of file timing.h.

Constructor & Destructor Documentation

◆ TimeStamp() [1/3]

dabc::TimeStamp::TimeStamp ( double  v)
inlineprotected

Definition at line 91 of file timing.h.

◆ TimeStamp() [2/3]

dabc::TimeStamp::TimeStamp ( )
inline

Definition at line 103 of file timing.h.

◆ TimeStamp() [3/3]

dabc::TimeStamp::TimeStamp ( const TimeStamp src)
inline

Definition at line 105 of file timing.h.

Member Function Documentation

◆ GetSlowClock()

dabc::TimeStamp::slowclock_t dabc::TimeStamp::GetSlowClock ( )
staticprotected

Definition at line 31 of file timing.cxx.

◆ GetFastClock()

static fastclock_t dabc::TimeStamp::GetFastClock ( )
inlinestaticprotected

Definition at line 81 of file timing.h.

◆ CalculateFastClockMult()

double dabc::TimeStamp::CalculateFastClockMult ( )
staticprotected

Definition at line 39 of file timing.cxx.

◆ CheckLinuxTSC()

bool dabc::TimeStamp::CheckLinuxTSC ( )
staticprotected

Definition at line 102 of file timing.cxx.

◆ Slow()

static TimeStamp dabc::TimeStamp::Slow ( )
inlinestaticprotected

Method returns TimeStamp instance with current time, measured by 'slow' getclock() function.

Definition at line 95 of file timing.h.

◆ Fast()

static TimeStamp dabc::TimeStamp::Fast ( )
inlinestaticprotected

Method returns TimeStamp instance with current time, measure by fast TSC clock.

One should not use this method directly while TSC clock may not be correctly working

Definition at line 99 of file timing.h.

◆ operator=()

TimeStamp& dabc::TimeStamp::operator= ( const TimeStamp src)
inline

Definition at line 107 of file timing.h.

◆ operator+=()

TimeStamp& dabc::TimeStamp::operator+= ( double  _add)
inline

Definition at line 109 of file timing.h.

◆ operator-=()

TimeStamp& dabc::TimeStamp::operator-= ( double  _sub)
inline

Definition at line 111 of file timing.h.

◆ operator+()

TimeStamp dabc::TimeStamp::operator+ ( double  _add) const
inline

Definition at line 113 of file timing.h.

◆ operator-() [1/2]

TimeStamp dabc::TimeStamp::operator- ( double  _sub) const
inline

Definition at line 115 of file timing.h.

◆ operator()()

double dabc::TimeStamp::operator() ( ) const
inline

Definition at line 117 of file timing.h.

◆ AsDouble()

double dabc::TimeStamp::AsDouble ( ) const
inline

Return time stamp in form of double (in seconds)

Definition at line 120 of file timing.h.

◆ operator-() [2/2]

double dabc::TimeStamp::operator- ( const TimeStamp src) const
inline

Definition at line 122 of file timing.h.

◆ operator<()

bool dabc::TimeStamp::operator< ( const TimeStamp src) const
inline

Definition at line 124 of file timing.h.

◆ operator>()

bool dabc::TimeStamp::operator> ( const TimeStamp src) const
inline

Definition at line 126 of file timing.h.

◆ operator==()

bool dabc::TimeStamp::operator== ( const TimeStamp src) const
inline

Definition at line 128 of file timing.h.

◆ null()

bool dabc::TimeStamp::null ( ) const
inline

Returns true if time stamp is not initialized or its value less than 0.

Definition at line 131 of file timing.h.

◆ Reset()

void dabc::TimeStamp::Reset ( )
inline

Set time stamp value to null.

Definition at line 134 of file timing.h.

◆ GetNow() [1/2]

void dabc::TimeStamp::GetNow ( )
inline

Method to acquire current time stamp.

Definition at line 137 of file timing.h.

◆ GetNow() [2/2]

void dabc::TimeStamp::GetNow ( double  shift)
inline

Method to acquire current time stamp plus shift in seconds.

Definition at line 140 of file timing.h.

◆ SpentTillNow() [1/2]

double dabc::TimeStamp::SpentTillNow ( ) const
inline

Method return time in second, spent from the time kept in TimeStamp instance If time was not set before, returns 0.

Definition at line 144 of file timing.h.

◆ SpentTillNow() [2/2]

double dabc::TimeStamp::SpentTillNow ( bool  set_to_now)
inline

Method return time in second, spent from the time kept in TimeStamp instance If specified, automatically set to the current time If time was not set before, returns 0.

Definition at line 152 of file timing.h.

◆ Expired() [1/2]

bool dabc::TimeStamp::Expired ( double  interval = 0.) const
inline

Method returns true if specified time interval expired relative to time, kept in TimeStamp instance.

Definition at line 163 of file timing.h.

◆ Expired() [2/2]

bool dabc::TimeStamp::Expired ( const TimeStamp curr,
double  interval 
) const
inline

Method returns true if specified time interval expired relative to time, kept in TimeStamp instance.

Parameters
[in]currcurrent time
[in]intervaltime which should expire
Returns
true if specified time interval had expired

Definition at line 171 of file timing.h.

◆ Now()

static TimeStamp dabc::TimeStamp::Now ( )
inlinestatic

Method returns TimeStamp instance with current time stamp value, measured either by fast TSC (if it is detected and working correctly), otherwise slow getclock() method will be used.

Definition at line 176 of file timing.h.

◆ SetUseSlow()

static void dabc::TimeStamp::SetUseSlow ( )
inlinestatic

Definition at line 178 of file timing.h.

Friends And Related Function Documentation

◆ Profiler

friend class Profiler
friend

Definition at line 42 of file timing.h.

Field Documentation

◆ fValue

double dabc::TimeStamp::fValue
protected

time since start of the application in seconds

Definition at line 45 of file timing.h.

◆ gFast

bool dabc::TimeStamp::gFast = false
staticprotected

indicates if fast or slow method is used for time measurement

Definition at line 47 of file timing.h.

◆ gSlowClockZero

dabc::TimeStamp::slowclock_t dabc::TimeStamp::gSlowClockZero = dabc::TimeStamp::GetSlowClock()
staticprotected

Definition at line 51 of file timing.h.

◆ gFastClockZero

dabc::TimeStamp::fastclock_t dabc::TimeStamp::gFastClockZero = dabc::TimeStamp::GetFastClock()
staticprotected

Definition at line 84 of file timing.h.

◆ gFastClockMult

double dabc::TimeStamp::gFastClockMult = CalculateFastClockMult()
staticprotected

Definition at line 85 of file timing.h.


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