| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
TimerForSequencer Class Reference

Auxiliary class. More...

`#include <src/components/TimerForSequencer.h>`

Collaboration diagram for TimerForSequencer:
[legend]

## 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::string & | name () 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...
MsgStream & | fillStream (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::TimerForSequencer | ( | std::string | name,
|  | unsigned int | size,
|  | double | factor
| ) |  |
| inline

Constructor.

Specify the name, for later printing.

Definition at line 24 of file TimerForSequencer.h.

25 : m_name( std::move( name ) ), m_size( size ), m_factor( factor ) {}
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:14
TimerForSequencer::name
const std::string & name() const
returns the name
Definition: TimerForSequencer.h:41
TimerForSequencer::m_factor
double m_factor
Definition: TimerForSequencer.h:67
TimerForSequencer::m_size
unsigned int m_size
Definition: TimerForSequencer.h:66
std::move
T move(T... args)
TimerForSequencer::m_name
std::string m_name
Definition: TimerForSequencer.h:65

## ◆ ~TimerForSequencer()

TimerForSequencer::~TimerForSequencer | ( |  | ) |
| default

## Member Function Documentation

## ◆ count()

uint64_t TimerForSequencer::count | ( |  | ) | const
| inline

Returns the number run count.

Definition at line 56 of file TimerForSequencer.h.

56 { return m_num; }
TimerForSequencer::m_num
uint64_t m_num
Definition: TimerForSequencer.h:71

## ◆ cpuTotal()

double TimerForSequencer::cpuTotal | ( |  | ) | const
| inline

returns the toptal cpu time

Definition at line 53 of file TimerForSequencer.h.

53 { return m_sumCpu * m_factor; }
TimerForSequencer::m_factor
double m_factor
Definition: TimerForSequencer.h:67
TimerForSequencer::m_sumCpu
uint64_t m_sumCpu
Definition: TimerForSequencer.h:78

## ◆ elapsedTotal()

double TimerForSequencer::elapsedTotal | ( |  | ) | const
| inline

returns the total elapsed time

Definition at line 50 of file TimerForSequencer.h.

50 { return m_sum * m_factor; }
TimerForSequencer::m_factor
double m_factor
Definition: TimerForSequencer.h:67
TimerForSequencer::m_sum
uint64_t m_sum
Definition: TimerForSequencer.h:76

## ◆ fillStream()

MsgStream & TimerForSequencer::fillStream | ( | MsgStream & | s | ) | const

Write measured time into the message stream.

Definition at line 34 of file TimerForSequencer.cpp.

34 {
35 float ave = 0.f;
36 float cpu = 0.f;
37
38 if ( 0ULL != m_num ) {
39 ave = m_sum / m_num;
40 cpu = m_sumCpu / m_num;
41 }
42
43 ave *= m_factor;
44 cpu *= m_factor;
45 float min = m_min * m_factor;
46 float max = m_max * m_factor;
47 float sum = m_sum * m_factor;
48
49 // Calculate the sigma with 2 momenta. ROOT histos call this quantity
50 // RMS but just to be consistent with paw.
51 // The division is by N-1 since one degree of freedom is used to calculate
52 // the average. See your favourite book for the proof!
53 float sigma = m_num <= 1ULL ? 0.f : m_factor * sqrt( ( m_sum2 - m_sum * m_sum / m_num ) / ( m_num - 1 ) );
54
55 return s << m_name.substr( 0, m_size )
56 << format( "| %9.3f | %9.3f | %8.3f %9.1f %8.2f | %7d | %9.3f |", cpu, ave, min, max, sigma, m_num,
57 sum * 0.001f );
58 }
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
min
EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:202
max
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:215
TimerForSequencer::m_min
uint64_t m_min
Definition: TimerForSequencer.h:74
TimerForSequencer::m_factor
double m_factor
Definition: TimerForSequencer.h:67
TimerForSequencer::m_size
unsigned int m_size
Definition: TimerForSequencer.h:66
TimerForSequencer::m_sum
uint64_t m_sum
Definition: TimerForSequencer.h:76
TimerForSequencer::m_sum2
uint64_t m_sum2
Definition: TimerForSequencer.h:77
Gaudi::Accumulators::sqrt
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
Definition: Counters.h:28
TimerForSequencer::m_max
uint64_t m_max
Definition: TimerForSequencer.h:75
gaudirun.s
string s
Definition: gaudirun.py:316
std::string::substr
T substr(T... args)
TimerForSequencer::m_name
std::string m_name
Definition: TimerForSequencer.h:65
TimerForSequencer::m_num
uint64_t m_num
Definition: TimerForSequencer.h:71
TimerForSequencer::m_sumCpu
uint64_t m_sumCpu
Definition: TimerForSequencer.h:78

## ◆ header()

std::string TimerForSequencer::header | ( | std::string::size_type | size | ) |
| static

header matching the previous format

Definition at line 60 of file TimerForSequencer.cpp.

60 {
61 return "Algorithm" + std::string( std::max( std::string::size_type( 21 ), size ) - 20, ' ' ) +
62 "(millisec) | <user> | <clock> |" + " min max sigma | entries | total (s) |";
63 }
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:14
std::string
STL class.
std::max
T max(T... args)

## ◆ lastCpu()

double TimerForSequencer::lastCpu | ( |  | ) | const
| inline

returns the last measured time

Definition at line 47 of file TimerForSequencer.h.

47 { return m_lastCpu * m_factor; }
TimerForSequencer::m_lastCpu
uint64_t m_lastCpu
Definition: TimerForSequencer.h:73
TimerForSequencer::m_factor
double m_factor
Definition: TimerForSequencer.h:67

## ◆ lastTime()

double TimerForSequencer::lastTime | ( |  | ) | const
| inline

returns the last measured time

Definition at line 44 of file TimerForSequencer.h.

44 { return m_lastTime * m_factor; }
TimerForSequencer::m_factor
double m_factor
Definition: TimerForSequencer.h:67
TimerForSequencer::m_lastTime
uint64_t m_lastTime
Definition: TimerForSequencer.h:72

## ◆ name()

const std::string& TimerForSequencer::name | ( |  | ) | const
| inline

returns the name

Definition at line 41 of file TimerForSequencer.h.

41 { return m_name; }
TimerForSequencer::m_name
std::string m_name
Definition: TimerForSequencer.h:65

## ◆ start()

void TimerForSequencer::start | ( |  | ) |
| inline

Start a time measurement.

Definition at line 30 of file TimerForSequencer.h.

30 {
31 m_startClock = System::currentTime( System::microSec );
32 m_startCpu = System::cpuTime( System::microSec );
33 }
TimerForSequencer::m_startClock
uint64_t m_startClock
Definition: TimerForSequencer.h:68
System::currentTime
GAUDI_API long long currentTime()
Retrieve absolute system time.
Definition: Timing.h:250
System::microSec
Definition: Timing.h:57
System::cpuTime
GAUDI_API long long cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:186
TimerForSequencer::m_startCpu
uint64_t m_startCpu
Definition: TimerForSequencer.h:69

## ◆ stop()

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.

10 {
11 uint64_t cpuTime = System::cpuTime( System::microSec ) - m_startCpu;
12 uint64_t lastTime = System::currentTime( System::microSec ) - m_startClock;
13
14 //== Update the counter
15 m_num += 1ULL;
16 m_sum += lastTime;
17 m_sum2 += lastTime * lastTime;
18 m_sumCpu += cpuTime;
19
20 // Branchless update, only cast
21 bool numIsFirst = ( 1ULL == m_num );
22 m_min += lastTime * numIsFirst;
23 m_max += lastTime * numIsFirst;
24
25 m_min = lastTime < m_min ? lastTime : m_min;
26 m_max = lastTime > m_max ? lastTime : m_max;
27
28 m_lastTime = lastTime;
29 m_lastCpu = cpuTime;
30
31 return lastTime;
32 }
TimerForSequencer::m_lastCpu
uint64_t m_lastCpu
Definition: TimerForSequencer.h:73
uint64_t
unsigned long long uint64_t
Definition: instrset.h:143
TimerForSequencer::m_min
uint64_t m_min
Definition: TimerForSequencer.h:74
TimerForSequencer::m_startClock
uint64_t m_startClock
Definition: TimerForSequencer.h:68
System::currentTime
GAUDI_API long long currentTime()
Retrieve absolute system time.
Definition: Timing.h:250
System::microSec
Definition: Timing.h:57
System::cpuTime
GAUDI_API long long cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:186
TimerForSequencer::m_sum
uint64_t m_sum
Definition: TimerForSequencer.h:76
TimerForSequencer::m_sum2
uint64_t m_sum2
Definition: TimerForSequencer.h:77
TimerForSequencer::m_startCpu
uint64_t m_startCpu
Definition: TimerForSequencer.h:69
TimerForSequencer::m_max
uint64_t m_max
Definition: TimerForSequencer.h:75
TimerForSequencer::m_lastTime
uint64_t m_lastTime
Definition: TimerForSequencer.h:72
TimerForSequencer::m_num
uint64_t m_num
Definition: TimerForSequencer.h:71
TimerForSequencer::m_sumCpu
uint64_t m_sumCpu
Definition: TimerForSequencer.h:78
TimerForSequencer::lastTime
double lastTime() const
returns the last measured time
Definition: TimerForSequencer.h:44

## Member Data Documentation

## ◆ m_factor

double TimerForSequencer::m_factor
| private

Definition at line 67 of file TimerForSequencer.h.

## ◆ m_lastCpu

uint64_t TimerForSequencer::m_lastCpu = 0ULL
| private

Definition at line 73 of file TimerForSequencer.h.

## ◆ m_lastTime

uint64_t TimerForSequencer::m_lastTime = 0ULL
| private

Definition at line 72 of file TimerForSequencer.h.

## ◆ m_max

uint64_t TimerForSequencer::m_max = 0ULL
| private

Definition at line 75 of file TimerForSequencer.h.

## ◆ m_min

uint64_t TimerForSequencer::m_min = 0ULL
| private

Definition at line 74 of file TimerForSequencer.h.

## ◆ m_name

std::string TimerForSequencer::m_name
| private

Definition at line 65 of file TimerForSequencer.h.

## ◆ m_num

uint64_t TimerForSequencer::m_num = 0ULL
| private

Definition at line 71 of file TimerForSequencer.h.

## ◆ m_size

unsigned int TimerForSequencer::m_size
| private

Definition at line 66 of file TimerForSequencer.h.

## ◆ m_startClock

uint64_t TimerForSequencer::m_startClock = 0ULL
| private

Definition at line 68 of file TimerForSequencer.h.

## ◆ m_startCpu

uint64_t TimerForSequencer::m_startCpu = 0ULL
| private

Definition at line 69 of file TimerForSequencer.h.

## ◆ m_sum

uint64_t TimerForSequencer::m_sum = 0ULL
| private

Definition at line 76 of file TimerForSequencer.h.

## ◆ m_sum2

uint64_t TimerForSequencer::m_sum2 = 0ULL
| private

Definition at line 77 of file TimerForSequencer.h.

## ◆ m_sumCpu

uint64_t TimerForSequencer::m_sumCpu = 0ULL
| private

Definition at line 78 of file TimerForSequencer.h.

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

- GaudiAlg/src/components/TimerForSequencer.h
- GaudiAlg/src/components/TimerForSequencer.cpp