| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# TimerForSequencer.h

Go to the documentation of this file.

    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    = 0;
    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   }
    00030
    00031   ~TimerForSequencer() {};
    00032
    00034   void start () {
    00035     m_startClock = System::currentTime( System::microSec );
    00036     m_startCpu   = System::cpuTime( System::microSec );
    00037   }
    00038
    00042   double stop() {
    00043     double cpuTime  =  double(System::cpuTime( System::microSec ) - m_startCpu );
    00044     double lastTime =  double(System::currentTime( System::microSec ) - m_startClock );
    00045
    00046     //== Change to normalized millisecond
    00047     cpuTime  *= m_factor;
    00048     lastTime *= m_factor;
    00049
    00050     //== Update the counter
    00051     m_num    += 1;
    00052     m_sum    += lastTime;
    00053     m_sumCpu += cpuTime;
    00054
    00055     if ( 1 == m_num ) {
    00056       m_min = lastTime;
    00057       m_max = lastTime;
    00058     } else {
    00059       if ( lastTime < m_min ) m_min = lastTime;
    00060       if ( lastTime > m_max ) m_max = lastTime;
    00061     }
    00062     m_lastTime = lastTime;
    00063     m_lastCpu  = cpuTime;
    00064     return lastTime;
    00065   }
    00066
    00068   std::string name() const { return m_name; }
    00069
    00071   double lastTime()   const { return m_lastTime; }
    00072
    00074   double lastCpu()   const { return m_lastCpu; }
    00075
    00077   MsgStream & fillStream(MsgStream & s) const {
    00078     double ave = 0.;
    00079     double cpu = 0.;
    00080
    00081     if ( 0 != m_num ) {
    00082       ave = m_sum    / m_num;
    00083       cpu = m_sumCpu / m_num;
    00084     }
    00085
    00086     return s << m_name
    00087              << format( "| %9.3f | %9.3f | %8.3f %9.1f | %7d | %9.3f |",
    00088                         cpu, ave, m_min, m_max, m_num, m_sum * 0.001 );
    00089   }
    00090
    00092   static std::string header( std::string::size_type size ) {
    00093     if ( size < 21 ) size = 21;
    00094     std::string blank( size - 20, ' ' );
    00095     std::string s = "Algorithm" + blank + "(millisec) |    <user> |   <clock> |";
    00096     s += "      min       max | entries | total (s) |";
    00097     return s;
    00098   }
    00099
    00100 private:
    00101   std::string m_name;
    00102   double m_factor;
    00103   longlong m_startClock;
    00104   longlong m_startCpu;
    00105
    00106   long m_num;
    00107   double m_lastTime;
    00108   double m_lastCpu;
    00109   double m_min;
    00110   double m_max;
    00111   double m_sum;
    00112   double m_sumCpu;
    00113 };
    00114
    00115 inline MsgStream& operator<<(MsgStream& ms, const TimerForSequencer& count) {
    00116   return count.fillStream( ms );
    00117 }
    00118
    00119 #endif // TIMERFORSEQUENCER_H