| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 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   std::string header( ) const {
    00093     std::string s = "Algorithm          (millisec) |    <user> |   <clock> |";
    00094     s += "      min       max | entries | total (s) |";
    00095     return s;
    00096   }
    00097
    00098 private:
    00099   std::string m_name;
    00100   double m_factor;
    00101   longlong m_startClock;
    00102   longlong m_startCpu;
    00103
    00104   long m_num;
    00105   double m_lastTime;
    00106   double m_lastCpu;
    00107   double m_min;
    00108   double m_max;
    00109   double m_sum;
    00110   double m_sumCpu;
    00111 };
    00112
    00113 inline MsgStream& operator<<(MsgStream& ms, const TimerForSequencer& count) {
    00114   return count.fillStream( ms );
    00115 }
    00116
    00117 #endif // TIMERFORSEQUENCER_H