|
Gaudi Framework, version v23r4 |
| Home | Generated: Mon Sep 17 2012 |
00001 // $Id: TimerForSequencer.h,v 1.5 2004/11/25 13:26:26 mato Exp $ 00002 #ifndef TIMERFORSEQUENCER_H 00003 00004 #include "GaudiKernel/MsgStream.h" 00005 #include "GaudiKernel/Timing.h" 00006 00014 class TimerForSequencer { 00015 00016 public: 00019 TimerForSequencer( std::string name, double factor ) { 00020 m_name = name; 00021 m_num = 0L; 00022 m_min = 0.; 00023 m_max = 0.; 00024 m_sum = 0.; 00025 m_sumCpu = 0.; 00026 m_factor = factor; 00027 m_lastTime = 0.; 00028 m_lastCpu = 0.; 00029 m_startClock = 0LL; 00030 m_startCpu = 0LL; 00031 } 00032 00033 ~TimerForSequencer() {}; 00034 00036 void start () { 00037 m_startClock = System::currentTime( System::microSec ); 00038 m_startCpu = System::cpuTime( System::microSec ); 00039 } 00040 00044 double stop() { 00045 double cpuTime = double(System::cpuTime( System::microSec ) - m_startCpu ); 00046 double lastTime = double(System::currentTime( System::microSec ) - m_startClock ); 00047 00048 //== Change to normalized millisecond 00049 cpuTime *= m_factor; 00050 lastTime *= m_factor; 00051 00052 //== Update the counter 00053 m_num += 1; 00054 m_sum += lastTime; 00055 m_sumCpu += cpuTime; 00056 00057 if ( 1 == m_num ) { 00058 m_min = lastTime; 00059 m_max = lastTime; 00060 } else { 00061 if ( lastTime < m_min ) m_min = lastTime; 00062 if ( lastTime > m_max ) m_max = lastTime; 00063 } 00064 m_lastTime = lastTime; 00065 m_lastCpu = cpuTime; 00066 return lastTime; 00067 } 00068 00070 std::string name() const { return m_name; } 00071 00073 double lastTime() const { return m_lastTime; } 00074 00076 double lastCpu() const { return m_lastCpu; } 00077 00079 double elapsedTotal() 00080 { 00081 return m_sum; 00082 } 00083 00085 double cpuTotal() 00086 { 00087 return m_sumCpu; 00088 } 00089 00091 double count() 00092 { 00093 return m_num; 00094 } 00095 00097 MsgStream & fillStream(MsgStream & s) const { 00098 double ave = 0.; 00099 double cpu = 0.; 00100 00101 if ( 0 != m_num ) { 00102 ave = m_sum / m_num; 00103 cpu = m_sumCpu / m_num; 00104 } 00105 00106 return s << m_name 00107 << format( "| %9.3f | %9.3f | %8.3f %9.1f | %7d | %9.3f |", 00108 cpu, ave, m_min, m_max, m_num, m_sum * 0.001 ); 00109 } 00110 00112 static std::string header( std::string::size_type size ) { 00113 if ( size < 21 ) size = 21; 00114 std::string blank( size - 20, ' ' ); 00115 std::string s = "Algorithm" + blank + "(millisec) | <user> | <clock> |"; 00116 s += " min max | entries | total (s) |"; 00117 return s; 00118 } 00119 00120 private: 00121 std::string m_name; 00122 double m_factor; 00123 longlong m_startClock; 00124 longlong m_startCpu; 00125 00126 long m_num; 00127 double m_lastTime; 00128 double m_lastCpu; 00129 double m_min; 00130 double m_max; 00131 double m_sum; 00132 double m_sumCpu; 00133 }; 00134 00135 inline MsgStream& operator<<(MsgStream& ms, const TimerForSequencer& count) { 00136 return count.fillStream( ms ); 00137 } 00138 00139 #endif // TIMERFORSEQUENCER_H