| # Gaudi Framework, version v23r1 |

Home |  | Generated: Wed Feb 29 2012

# 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    = 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   MsgStream & fillStream(MsgStream & s) const {
    00080     double ave = 0.;
    00081     double cpu = 0.;
    00082
    00083     if ( 0 != m_num ) {
    00084       ave = m_sum    / m_num;
    00085       cpu = m_sumCpu / m_num;
    00086     }
    00087
    00088     return s << m_name
    00089              << format( "| %9.3f | %9.3f | %8.3f %9.1f | %7d | %9.3f |",
    00090                         cpu, ave, m_min, m_max, m_num, m_sum * 0.001 );
    00091   }
    00092
    00094   static std::string header( std::string::size_type size ) {
    00095     if ( size < 21 ) size = 21;
    00096     std::string blank( size - 20, ' ' );
    00097     std::string s = "Algorithm" + blank + "(millisec) |    <user> |   <clock> |";
    00098     s += "      min       max | entries | total (s) |";
    00099     return s;
    00100   }
    00101
    00102 private:
    00103   std::string m_name;
    00104   double m_factor;
    00105   longlong m_startClock;
    00106   longlong m_startCpu;
    00107
    00108   long m_num;
    00109   double m_lastTime;
    00110   double m_lastCpu;
    00111   double m_min;
    00112   double m_max;
    00113   double m_sum;
    00114   double m_sumCpu;
    00115 };
    00116
    00117 inline MsgStream& operator<<(MsgStream& ms, const TimerForSequencer& count) {
    00118   return count.fillStream( ms );
    00119 }
    00120
    00121 #endif // TIMERFORSEQUENCER_H

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines