The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TimerForSequencer.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // local
12 #include "TimerForSequencer.h"
13 
14 //-----------------------------------------------------------------------------
15 // Implementation file for class : TimerForSequencer
16 //
17 // 2013-04-21 : Chris Jones
18 //-----------------------------------------------------------------------------
19 
23 
24  //== Update the counter
25  m_num += 1ULL;
26  m_sum += lastTime;
28  m_sumCpu += cpuTime;
29 
30  // Branchless update, only cast
31  bool numIsFirst = ( 1ULL == m_num );
32  m_min += lastTime * numIsFirst;
33  m_max += lastTime * numIsFirst;
34 
37 
40 
41  return lastTime;
42 }
43 
45  float ave = 0.f;
46  float cpu = 0.f;
47 
48  if ( 0ULL != m_num ) {
49  ave = m_sum / m_num;
50  cpu = m_sumCpu / m_num;
51  }
52 
53  ave *= m_factor;
54  cpu *= m_factor;
55  float min = m_min * m_factor;
56  float max = m_max * m_factor;
57  float sum = m_sum * m_factor;
58 
59  // Calculate the sigma with 2 momenta. ROOT histos call this quantity
60  // RMS but just to be consistent with paw.
61  // The division is by N-1 since one degree of freedom is used to calculate
62  // the average. See your favourite book for the proof!
63  float sigma = m_num <= 1ULL ? 0.f : m_factor * sqrt( ( m_sum2 - m_sum * m_sum / m_num ) / ( m_num - 1 ) );
64 
65  return s << m_name.substr( 0, m_size )
66  << format( "| %9.3f | %9.3f | %8.3f %9.1f %8.2f | %7lu | %9.3f |", cpu, ave, min, max, sigma, m_num,
67  sum * 0.001f );
68 }
69 
70 std::string TimerForSequencer::header( std::string::size_type size ) {
71  return "Algorithm" + std::string( std::max( std::string::size_type( 21 ), size ) - 20, ' ' ) +
72  "(millisec) | <user> | <clock> |" + " min max sigma | entries | total (s) |";
73 }
TimerForSequencer::m_lastCpu
uint64_t m_lastCpu
Definition: TimerForSequencer.h:83
Gaudi::Accumulators::sqrt
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
Definition: Counters.h:34
std::string
STL class.
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:22
TimerForSequencer::m_lastTime
uint64_t m_lastTime
Definition: TimerForSequencer.h:82
gaudirun.s
string s
Definition: gaudirun.py:346
TimerForSequencer::m_name
std::string m_name
Definition: TimerForSequencer.h:75
TimerForSequencer::m_startClock
uint64_t m_startClock
Definition: TimerForSequencer.h:78
System::microSec
@ microSec
Definition: Timing.h:67
max
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:225
TimerForSequencer::m_min
uint64_t m_min
Definition: TimerForSequencer.h:84
TimerForSequencer::m_size
unsigned int m_size
Definition: TimerForSequencer.h:76
TimerForSequencer::m_factor
double m_factor
Definition: TimerForSequencer.h:77
TimerForSequencer::stop
uint64_t stop()
Stop time measurement and return the last elapsed time.
Definition: TimerForSequencer.cpp:20
TimerForSequencer.h
TimerForSequencer::m_sum
uint64_t m_sum
Definition: TimerForSequencer.h:86
System::currentTime
GAUDI_API long long currentTime()
Retrieve absolute system time.
Definition: Timing.h:260
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
min
EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:212
MsgStream
Definition: MsgStream.h:34
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:197
std::string::substr
T substr(T... args)
TimerForSequencer::m_sum2
uint64_t m_sum2
Definition: TimerForSequencer.h:87
TimerForSequencer::fillStream
MsgStream & fillStream(MsgStream &s) const
Write measured time into the message stream.
Definition: TimerForSequencer.cpp:44
TimerForSequencer::m_sumCpu
uint64_t m_sumCpu
Definition: TimerForSequencer.h:88
TimerForSequencer::m_startCpu
uint64_t m_startCpu
Definition: TimerForSequencer.h:79
TimerForSequencer::m_num
uint64_t m_num
Definition: TimerForSequencer.h:81
TimerForSequencer::m_max
uint64_t m_max
Definition: TimerForSequencer.h:85
TimerForSequencer::header
static std::string header(std::string::size_type size)
header matching the previous format
Definition: TimerForSequencer.cpp:70
TimerForSequencer::lastTime
double lastTime() const
returns the last measured time
Definition: TimerForSequencer.h:54
std::max
T max(T... args)