The Gaudi Framework  v33r0 (d5ea422b)
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 }
constexpr auto size(const T &, Args &&...) noexcept
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:34
static std::string header(std::string::size_type size)
header matching the previous format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
Definition: Counters.h:34
uint64_t stop()
Stop time measurement and return the last elapsed time.
EventIDBase min(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:212
unsigned long long uint64_t
Definition: instrset.h:143
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:225
STL class.
GAUDI_API long long currentTime()
Retrieve absolute system time.
Definition: Timing.h:260
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
T max(T... args)
string s
Definition: gaudirun.py:328
T substr(T... args)
MsgStream & fillStream(MsgStream &s) const
Write measured time into the message stream.
double lastTime() const
returns the last measured time