TimerForSequencer Class Reference

Auxilliary 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...
 
double 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 total cpu time More...
 
double 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
 
long long m_startClock = 0LL
 
long long m_startCpu = 0LL
 
long long m_num = 0LL
 
double m_lastTime = 0.
 
double m_lastCpu = 0.
 
double m_min = 0.
 
double m_max = 0.
 
double m_sum = 0.
 
double m_sumCpu = 0.
 

Detailed Description

Auxilliary 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 givesmin/max only for elapsed.

Author
O.Callot

Definition at line 13 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 19 of file TimerForSequencer.h.

22  : m_name ( std::move(name) ),
23  m_size ( size ),
24  m_factor ( factor )
25  { }
const std::string & name() const
returns the name
TimerForSequencer::~TimerForSequencer ( )
default

Member Function Documentation

double TimerForSequencer::count ( ) const
inline

Returns the number run count.

Definition at line 57 of file TimerForSequencer.h.

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

returns the total cpu time

Definition at line 54 of file TimerForSequencer.h.

54 { return m_sumCpu; }
double TimerForSequencer::elapsedTotal ( ) const
inline

returns the total elapsed time

Definition at line 51 of file TimerForSequencer.h.

51 { return m_sum; }
MsgStream & TimerForSequencer::fillStream ( MsgStream s) const

Write measured time into the message stream.

Definition at line 39 of file TimerForSequencer.cpp.

40 {
41  double ave = 0.;
42  double cpu = 0.;
43 
44  if ( 0 != m_num )
45  {
46  ave = m_sum / m_num;
47  cpu = m_sumCpu / m_num;
48  }
49 
50  return s << m_name.substr(0,m_size)
51  << format( "| %9.3f | %9.3f | %8.3f %9.1f | %7d | %9.3f |",
52  cpu, ave, m_min, m_max, m_num, m_sum * 0.001 );
53 }
tuple cpu
Definition: ana.py:139
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120
std::string TimerForSequencer::header ( std::string::size_type  size)
static

header matching the previous format

Definition at line 55 of file TimerForSequencer.cpp.

56 {
57  return "Algorithm" + std::string( std::max(std::string::size_type(21),size) - 20, ' ' )
58  + "(millisec) | <user> | <clock> |"
59  + " min max | entries | total (s) |";
60 }
double TimerForSequencer::lastCpu ( ) const
inline

returns the last measured time

Definition at line 48 of file TimerForSequencer.h.

48 { return m_lastCpu; }
double TimerForSequencer::lastTime ( ) const
inline

returns the last measured time

Definition at line 45 of file TimerForSequencer.h.

45 { return m_lastTime; }
const std::string& TimerForSequencer::name ( ) const
inline

returns the name

Definition at line 42 of file TimerForSequencer.h.

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

Start a time measurement.

Definition at line 30 of file TimerForSequencer.h.

31  {
34  }
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:79
GAUDI_API longlong cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:168
double 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 {
12  double cpuTime = double(System::cpuTime( System::microSec ) - m_startCpu );
14 
15  //== Change to normalized millisecond
16  cpuTime *= m_factor;
17  lastTime *= m_factor;
18 
19  //== Update the counter
20  m_num += 1;
21  m_sum += lastTime;
22  m_sumCpu += cpuTime;
23 
24  if ( 1 == m_num )
25  {
26  m_min = lastTime;
27  m_max = lastTime;
28  }
29  else
30  {
31  if ( lastTime < m_min ) m_min = lastTime;
32  if ( lastTime > m_max ) m_max = lastTime;
33  }
36  return lastTime;
37 }
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:79
double lastTime() const
returns the last measured time
GAUDI_API longlong cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:168

Member Data Documentation

double TimerForSequencer::m_factor
private

Definition at line 69 of file TimerForSequencer.h.

double TimerForSequencer::m_lastCpu = 0.
private

Definition at line 75 of file TimerForSequencer.h.

double TimerForSequencer::m_lastTime = 0.
private

Definition at line 74 of file TimerForSequencer.h.

double TimerForSequencer::m_max = 0.
private

Definition at line 77 of file TimerForSequencer.h.

double TimerForSequencer::m_min = 0.
private

Definition at line 76 of file TimerForSequencer.h.

std::string TimerForSequencer::m_name
private

Definition at line 67 of file TimerForSequencer.h.

long long TimerForSequencer::m_num = 0LL
private

Definition at line 73 of file TimerForSequencer.h.

unsigned int TimerForSequencer::m_size
private

Definition at line 68 of file TimerForSequencer.h.

long long TimerForSequencer::m_startClock = 0LL
private

Definition at line 70 of file TimerForSequencer.h.

long long TimerForSequencer::m_startCpu = 0LL
private

Definition at line 71 of file TimerForSequencer.h.

double TimerForSequencer::m_sum = 0.
private

Definition at line 78 of file TimerForSequencer.h.

double TimerForSequencer::m_sumCpu = 0.
private

Definition at line 79 of file TimerForSequencer.h.


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