All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TimerForSequencer Class Reference

Auxilliary class. More...

#include <src/components/TimerForSequencer.h>

Collaboration diagram for TimerForSequencer:

Public Member Functions

 TimerForSequencer (const std::string &name, const unsigned int size, const double factor)
 Constructor. More...
 
 ~TimerForSequencer ()
 
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
 
long long m_startCpu
 
long long m_num
 
double m_lastTime
 
double m_lastCpu
 
double m_min
 
double m_max
 
double m_sum
 
double m_sumCpu
 

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 14 of file TimerForSequencer.h.

Constructor & Destructor Documentation

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

Constructor.

Specify the name, for later printing.

Definition at line 20 of file TimerForSequencer.h.

23  : m_name ( name ),
24  m_size ( size ),
25  m_factor ( factor ),
26  m_startClock ( 0LL ),
27  m_startCpu ( 0LL ),
28  m_num ( 0LL ),
29  m_lastTime ( 0. ),
30  m_lastCpu ( 0. ),
31  m_min ( 0. ),
32  m_max ( 0. ),
33  m_sum ( 0. ),
34  m_sumCpu ( 0. )
35  { }
const std::string & name() const
returns the name
TimerForSequencer::~TimerForSequencer ( )
inline

Definition at line 37 of file TimerForSequencer.h.

37 {}

Member Function Documentation

double TimerForSequencer::count ( ) const
inline

Returns the number run count.

Definition at line 67 of file TimerForSequencer.h.

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

returns the total cpu time

Definition at line 64 of file TimerForSequencer.h.

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

returns the total elapsed time

Definition at line 61 of file TimerForSequencer.h.

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

Write measured time into the message stream.

Definition at line 40 of file TimerForSequencer.cpp.

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

header matching the previous format

Definition at line 56 of file TimerForSequencer.cpp.

57 {
58  if ( size < 21 ) size = 21;
59  const std::string blank( size - 20, ' ' );
60  const std::string s =
61  "Algorithm" + blank + "(millisec) | <user> | <clock> |" +
62  " min max | entries | total (s) |";
63  return s;
64 }
string s
Definition: gaudirun.py:210
double TimerForSequencer::lastCpu ( ) const
inline

returns the last measured time

Definition at line 58 of file TimerForSequencer.h.

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

returns the last measured time

Definition at line 55 of file TimerForSequencer.h.

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

returns the name

Definition at line 52 of file TimerForSequencer.h.

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

Start a time measurement.

Definition at line 40 of file TimerForSequencer.h.

41  {
44  }
GAUDI_API longlong cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:169
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:80
double TimerForSequencer::stop ( )

Stop time measurement and return the last elapsed time.

Returns
Measured time in ms

Definition at line 11 of file TimerForSequencer.cpp.

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

Member Data Documentation

double TimerForSequencer::m_factor
private

Definition at line 79 of file TimerForSequencer.h.

double TimerForSequencer::m_lastCpu
private

Definition at line 85 of file TimerForSequencer.h.

double TimerForSequencer::m_lastTime
private

Definition at line 84 of file TimerForSequencer.h.

double TimerForSequencer::m_max
private

Definition at line 87 of file TimerForSequencer.h.

double TimerForSequencer::m_min
private

Definition at line 86 of file TimerForSequencer.h.

std::string TimerForSequencer::m_name
private

Definition at line 77 of file TimerForSequencer.h.

long long TimerForSequencer::m_num
private

Definition at line 83 of file TimerForSequencer.h.

unsigned int TimerForSequencer::m_size
private

Definition at line 78 of file TimerForSequencer.h.

long long TimerForSequencer::m_startClock
private

Definition at line 80 of file TimerForSequencer.h.

long long TimerForSequencer::m_startCpu
private

Definition at line 81 of file TimerForSequencer.h.

double TimerForSequencer::m_sum
private

Definition at line 88 of file TimerForSequencer.h.

double TimerForSequencer::m_sumCpu
private

Definition at line 89 of file TimerForSequencer.h.


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