The Gaudi Framework  v30r3 (a5ef0a68)
TimerForSequencer Class Reference

Auxiliary class. More...

#include <src/components/TimerForSequencer.h>

Collaboration diagram for TimerForSequencer:

Public Member Functions

 TimerForSequencer (std::string name, unsigned int size, double factor)
 Constructor. More...
 
 ~TimerForSequencer ()=default
 
void start ()
 Start a time measurement. More...
 
uint64_t stop ()
 Stop time measurement and return the last elapsed time. More...
 
const std::stringname () const
 returns the name More...
 
double lastTime () const
 returns the last measured time More...
 
double lastCpu () const
 returns the last measured time More...
 
double elapsedTotal () const
 returns the total elapsed time More...
 
double cpuTotal () const
 returns the toptal cpu time More...
 
uint64_t count () const
 Returns the number run count. More...
 
MsgStreamfillStream (MsgStream &s) const
 Write measured time into the message stream. More...
 

Static Public Member Functions

static std::string header (std::string::size_type size)
 header matching the previous format More...
 

Private Attributes

std::string m_name
 
unsigned int m_size
 
double m_factor
 
uint64_t m_startClock = 0ULL
 
uint64_t m_startCpu = 0ULL
 
uint64_t m_num = 0ULL
 
uint64_t m_lastTime = 0ULL
 
uint64_t m_lastCpu = 0ULL
 
uint64_t m_min = 0ULL
 
uint64_t m_max = 0ULL
 
uint64_t m_sum = 0ULL
 
uint64_t m_sum2 = 0ULL
 
uint64_t m_sumCpu = 0ULL
 

Detailed Description

Auxiliary class.

Measure the time between start and stop, and compute average, min and max. In fact, measure the cpu time, and the elapsed time but gives min/max only for elapsed.

Avoid usage of double precision floating point to cumulate counts and use unsigned long long integers instead. The total capacity is enough (~1.8e19) and there is no risk to loose counts when the available sum is big with respect to the added duration. The sigma

Author
O.Callot
D.Piparo

Definition at line 20 of file TimerForSequencer.h.

Constructor & Destructor Documentation

TimerForSequencer::TimerForSequencer ( std::string  name,
unsigned int  size,
double  factor 
)
inline

Constructor.

Specify the name, for later printing.

Definition at line 25 of file TimerForSequencer.h.

26  : m_name( std::move( name ) ), m_size( size ), m_factor( factor )
27  {
28  }
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
T move(T...args)
TimerForSequencer::~TimerForSequencer ( )
default

Member Function Documentation

uint64_t TimerForSequencer::count ( ) const
inline

Returns the number run count.

Definition at line 60 of file TimerForSequencer.h.

60 { return m_num; }
double TimerForSequencer::cpuTotal ( ) const
inline

returns the toptal cpu time

Definition at line 57 of file TimerForSequencer.h.

57 { return m_sumCpu * m_factor; }
double TimerForSequencer::elapsedTotal ( ) const
inline

returns the total elapsed time

Definition at line 54 of file TimerForSequencer.h.

54 { return m_sum * m_factor; }
MsgStream & TimerForSequencer::fillStream ( MsgStream s) const

Write measured time into the message stream.

Definition at line 35 of file TimerForSequencer.cpp.

36 {
37  float ave = 0.f;
38  float cpu = 0.f;
39 
40  if ( 0ULL != m_num ) {
41  ave = m_sum / m_num;
42  cpu = m_sumCpu / m_num;
43  }
44 
45  ave *= m_factor;
46  cpu *= m_factor;
47  float min = m_min * m_factor;
48  float max = m_max * m_factor;
49  float sum = m_sum * m_factor;
50 
51  // Calculate the sigma with 2 momenta. ROOT histos call this quantity
52  // RMS but just to be consistent with paw.
53  // The division is by N-1 since one degree of freedom is used to calculate
54  // the average. See your favourite book for the proof!
55  float sigma = m_num <= 1ULL ? 0.f : m_factor * sqrt( ( m_sum2 - m_sum * m_sum / m_num ) / ( m_num - 1 ) );
56 
57  return s << m_name.substr( 0, m_size ) << format( "| %9.3f | %9.3f | %8.3f %9.1f %8.2f | %7d | %9.3f |", cpu, ave,
58  min, max, sigma, m_num, sum * 0.001f );
59 }
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120
double sum(double x, double y, double z)
T min(T...args)
T max(T...args)
T substr(T...args)
T sqrt(T...args)
std::string TimerForSequencer::header ( std::string::size_type  size)
static

header matching the previous format

Definition at line 61 of file TimerForSequencer.cpp.

62 {
63  return "Algorithm" + std::string( std::max( std::string::size_type( 21 ), size ) - 20, ' ' ) +
64  "(millisec) | <user> | <clock> |" + " min max sigma | entries | total (s) |";
65 }
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
STL class.
T max(T...args)
double TimerForSequencer::lastCpu ( ) const
inline

returns the last measured time

Definition at line 51 of file TimerForSequencer.h.

51 { return m_lastCpu * m_factor; }
double TimerForSequencer::lastTime ( ) const
inline

returns the last measured time

Definition at line 48 of file TimerForSequencer.h.

48 { return m_lastTime * m_factor; }
const std::string& TimerForSequencer::name ( ) const
inline

returns the name

Definition at line 45 of file TimerForSequencer.h.

45 { return m_name; }
void TimerForSequencer::start ( )
inline

Start a time measurement.

Definition at line 33 of file TimerForSequencer.h.

34  {
37  }
GAUDI_API longlong cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:196
GAUDI_API longlong currentTime()
Retrieve absolute system time.
Definition: Timing.h:269
uint64_t TimerForSequencer::stop ( )

Stop time measurement and return the last elapsed time.

Returns
Measured time in ms

Definition at line 10 of file TimerForSequencer.cpp.

11 {
14 
15  //== Update the counter
16  m_num += 1ULL;
17  m_sum += lastTime;
18  m_sum2 += lastTime * lastTime;
19  m_sumCpu += cpuTime;
20 
21  // Branchless update, only cast
22  bool numIsFirst = ( 1ULL == m_num );
23  m_min += lastTime * numIsFirst;
24  m_max += lastTime * numIsFirst;
25 
26  m_min = lastTime < m_min ? lastTime : m_min;
27  m_max = lastTime > m_max ? lastTime : m_max;
28 
31 
32  return lastTime;
33 }
unsigned long long uint64_t
Definition: instrset.h:143
GAUDI_API longlong cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:196
double lastTime() const
returns the last measured time
GAUDI_API longlong currentTime()
Retrieve absolute system time.
Definition: Timing.h:269

Member Data Documentation

double TimerForSequencer::m_factor
private

Definition at line 71 of file TimerForSequencer.h.

uint64_t TimerForSequencer::m_lastCpu = 0ULL
private

Definition at line 77 of file TimerForSequencer.h.

uint64_t TimerForSequencer::m_lastTime = 0ULL
private

Definition at line 76 of file TimerForSequencer.h.

uint64_t TimerForSequencer::m_max = 0ULL
private

Definition at line 79 of file TimerForSequencer.h.

uint64_t TimerForSequencer::m_min = 0ULL
private

Definition at line 78 of file TimerForSequencer.h.

std::string TimerForSequencer::m_name
private

Definition at line 69 of file TimerForSequencer.h.

uint64_t TimerForSequencer::m_num = 0ULL
private

Definition at line 75 of file TimerForSequencer.h.

unsigned int TimerForSequencer::m_size
private

Definition at line 70 of file TimerForSequencer.h.

uint64_t TimerForSequencer::m_startClock = 0ULL
private

Definition at line 72 of file TimerForSequencer.h.

uint64_t TimerForSequencer::m_startCpu = 0ULL
private

Definition at line 73 of file TimerForSequencer.h.

uint64_t TimerForSequencer::m_sum = 0ULL
private

Definition at line 80 of file TimerForSequencer.h.

uint64_t TimerForSequencer::m_sum2 = 0ULL
private

Definition at line 81 of file TimerForSequencer.h.

uint64_t TimerForSequencer::m_sumCpu = 0ULL
private

Definition at line 82 of file TimerForSequencer.h.


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