Gaudi Framework, version v21r8

Home   Generated: 17 Mar 2010

ChronoEntity Class Reference

a small helper class for implementation of ChronoStatSvc service, It also could be used as some local timer More...

#include <GaudiKernel/ChronoEntity.h>

Collaboration diagram for ChronoEntity:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 ChronoEntity ()
 default constructor
 ~ChronoEntity ()
 destructor
IChronoSvc::ChronoStatus start ()
 start the current chrono
IChronoSvc::ChronoStatus stop ()
 stop the chrono
IChronoSvc::ChronoTime delta (IChronoSvc::ChronoType type) const
 return the last delta-time of type "type"
IChronoSvc::ChronoStatus status () const
 return the status of chrono
unsigned long nOfMeasurements () const
 number of chrono measurements
double uMinimalTime () const
 minimal measurement for user time
double kMinimalTime () const
 minimal measurement for kernel time
double eMinimalTime () const
 minimal measurement for ellapsed time
double uMaximalTime () const
 maximal measurement for user time
double kMaximalTime () const
 maximal measurement for kernel time
double eMaximalTime () const
 maximal measurement for ellapsed time
double uTotalTime () const
 total user time
double kTotalTime () const
 total Kernel time
double eTotalTime () const
 total Elapsed time
double totalTime () const
 total time
double kMeanTime () const
 average Kernel Time
double uMeanTime () const
 average User Time
double eMeanTime () const
 average Elapsed Time
double kRMSTime () const
 r.m.s Kernel Time
double uRMSTime () const
 r.m.s User Time
double eRMSTime () const
 r.m.s Elapsed Time
double kMeanErrorTime () const
 error in mean Kernel time
double uMeanErrorTime () const
 error in mean User time
double eMeanErrorTime () const
 error in mean Elapsed time
bool operator< (const ChronoEntity &entity) const
 comparison operator
std::string outputUserTime () const
 print the chrono ;
std::string outputSystemTime () const
 print the chrono ;
std::string outputElapsedTime () const
 print the chrono ;
std::string outputUserTime (const std::string &fmt, System::TimeType unit) const
 print the chrono according the format and units
std::string outputSystemTime (const std::string &fmt, System::TimeType unit) const
 print the chrono according the format and units
std::string outputElapsedTime (const std::string &fmt, System::TimeType unit) const
 print the chrono according the format and units
std::string outputTime (IChronoSvc::ChronoType typ, const std::string &fmt, System::TimeType unit) const
 print the chrono according the format and units

Protected Member Functions

std::string format (const double total, const double minimal, const double mean, const double rms, const double maximal, const unsigned long number) const
 format

Private Attributes

IChronoSvc::ChronoStatus m_status
 current status of this chrono object;
IChronoSvc::ChronoTime m_delta_user
 delta user time
IChronoSvc::ChronoTime m_delta_kernel
 delta Kernel time
IChronoSvc::ChronoTime m_delta_elapsed
 delta Elapsed time
IChronoSvc::ChronoTime m_start_user
 start stamp for current measurement of user time
IChronoSvc::ChronoTime m_start_kernel
 start stamp for current measurement of Kernel time
IChronoSvc::ChronoTime m_start_elapsed
 start stamp for current measurement of Elapsed time
StatEntity m_user
 the actual storage of "user" time
StatEntity m_kernel
 the actual storage of "kernel" time
StatEntity m_elapsed
 the actual storage of "elapsed" time


Detailed Description

a small helper class for implementation of ChronoStatSvc service, It also could be used as some local timer

Author:
Vanya BELYAEV Ivan.Belyaev@itep.ru
Date:
December 1, 1999

Definition at line 23 of file ChronoEntity.h.


Constructor & Destructor Documentation

ChronoEntity::ChronoEntity (  ) 

default constructor

current status of this chrono object;

Definition at line 50 of file ChronoEntity.cpp.

00052   : m_status        ( IChronoSvc::UNKNOWN )  // current status
00054   , m_delta_user    ( -1 ) // delta user time
00056   , m_delta_kernel  ( -1 ) // delta kernel time
00058   , m_delta_elapsed ( -1 ) // delta elapsed time
00060   , m_start_user    (  0 ) // start for user 
00062   , m_start_kernel  (  0 ) // start for kernel 
00064   , m_start_elapsed (  0 ) // start for elapsed  
00065 {}

ChronoEntity::~ChronoEntity (  )  [inline]

destructor

Definition at line 29 of file ChronoEntity.h.

00029 {};


Member Function Documentation

IChronoSvc::ChronoStatus ChronoEntity::start (  ) 

start the current chrono

Definition at line 69 of file ChronoEntity.cpp.

00070 {
00071   if ( IChronoSvc::RUNNING == m_status ) { return m_status ; }
00072   //
00073   // following lines could be platform dependent!
00074   //
00075   // Store in object the measured times
00076   m_start_user    = static_cast<IChronoSvc::ChronoTime>(System::userTime     ( MyUnit ));
00077   m_start_kernel  = static_cast<IChronoSvc::ChronoTime>(System::kernelTime   ( MyUnit ));
00078   m_start_elapsed = static_cast<IChronoSvc::ChronoTime>(System::ellapsedTime ( MyUnit ));
00080   m_status = IChronoSvc::RUNNING;
00082   return m_status ;
00083 }

IChronoSvc::ChronoStatus ChronoEntity::stop (  ) 

stop the chrono

Definition at line 87 of file ChronoEntity.cpp.

00088 {
00089   if ( IChronoSvc::RUNNING != m_status ) { return m_status ; }
00090   
00091   // following lines could be platform dependent!
00092   
00093   m_delta_user    = System::userTime     ( MyUnit ) - m_start_user    ;
00094   m_delta_kernel  = System::kernelTime   ( MyUnit ) - m_start_kernel  ;
00095   m_delta_elapsed = System::ellapsedTime ( MyUnit ) - m_start_elapsed ;
00096   
00097   // update the counters:
00098   
00099   m_user     += m_delta_user    ;
00100   m_kernel   += m_delta_kernel  ;
00101   m_elapsed  += m_delta_elapsed ;
00102   
00103   // set new status
00104   
00105   m_status = IChronoSvc::STOPPED;  
00106   
00107   return m_status ;
00108 }

IChronoSvc::ChronoTime ChronoEntity::delta ( IChronoSvc::ChronoType  type  )  const [inline]

return the last delta-time of type "type"

Definition at line 303 of file ChronoEntity.h.

00304 {
00305   const IChronoSvc::ChronoTime result = -1 ;
00306   switch ( type )
00307   {
00308   case IChronoSvc::USER    : return m_delta_user    ;
00309   case IChronoSvc::KERNEL  : return m_delta_kernel  ;
00310   case IChronoSvc::ELAPSED : return m_delta_elapsed ;
00311   default                  : return result          ;
00312   }
00313   // cannot reach this point
00314 }

IChronoSvc::ChronoStatus ChronoEntity::status (  )  const [inline]

return the status of chrono

Definition at line 197 of file ChronoEntity.h.

00197 { return m_status; }

unsigned long ChronoEntity::nOfMeasurements (  )  const [inline]

number of chrono measurements

Definition at line 202 of file ChronoEntity.h.

00202 { return m_user   . nEntries() ; }

double ChronoEntity::uMinimalTime (  )  const [inline]

minimal measurement for user time

Definition at line 206 of file ChronoEntity.h.

00207 { return m_user   . flagMin () ; }

double ChronoEntity::kMinimalTime (  )  const [inline]

minimal measurement for kernel time

Definition at line 212 of file ChronoEntity.h.

00212 { return m_kernel . flagMin () ; }

double ChronoEntity::eMinimalTime (  )  const [inline]

minimal measurement for ellapsed time

Definition at line 217 of file ChronoEntity.h.

00217 { return m_elapsed. flagMin () ; }

double ChronoEntity::uMaximalTime (  )  const [inline]

maximal measurement for user time

Definition at line 222 of file ChronoEntity.h.

00222 { return m_user   . flagMax () ; }

double ChronoEntity::kMaximalTime (  )  const [inline]

maximal measurement for kernel time

Definition at line 227 of file ChronoEntity.h.

00227 { return m_kernel . flagMax () ; }

double ChronoEntity::eMaximalTime (  )  const [inline]

maximal measurement for ellapsed time

Definition at line 232 of file ChronoEntity.h.

00232 { return m_elapsed . flagMax () ; }

double ChronoEntity::uTotalTime (  )  const [inline]

total user time

Definition at line 237 of file ChronoEntity.h.

00237 { return m_user    . flag () ; }

double ChronoEntity::kTotalTime (  )  const [inline]

total Kernel time

Definition at line 242 of file ChronoEntity.h.

00242 { return m_kernel  . flag () ; }

double ChronoEntity::eTotalTime (  )  const [inline]

total Elapsed time

Definition at line 247 of file ChronoEntity.h.

00247 { return m_elapsed . flag () ; }

double ChronoEntity::totalTime (  )  const [inline]

total time

Definition at line 252 of file ChronoEntity.h.

00253 { return uTotalTime() + kTotalTime()  ; }

double ChronoEntity::kMeanTime (  )  const [inline]

average Kernel Time

Definition at line 258 of file ChronoEntity.h.

00258 { return m_kernel  . flagMean () ; }

double ChronoEntity::uMeanTime (  )  const [inline]

average User Time

Definition at line 263 of file ChronoEntity.h.

00263 { return m_user    . flagMean () ; }

double ChronoEntity::eMeanTime (  )  const [inline]

average Elapsed Time

Definition at line 268 of file ChronoEntity.h.

00268 { return m_elapsed . flagMean () ; }

double ChronoEntity::kRMSTime (  )  const [inline]

r.m.s Kernel Time

Definition at line 273 of file ChronoEntity.h.

00273 { return m_kernel  . flagRMS  () ; }

double ChronoEntity::uRMSTime (  )  const [inline]

r.m.s User Time

Definition at line 278 of file ChronoEntity.h.

00278 { return m_user    . flagRMS  () ; }

double ChronoEntity::eRMSTime (  )  const [inline]

r.m.s Elapsed Time

Definition at line 283 of file ChronoEntity.h.

00283 { return m_elapsed . flagRMS () ; }

double ChronoEntity::kMeanErrorTime (  )  const [inline]

error in mean Kernel time

Definition at line 288 of file ChronoEntity.h.

00288 { return m_kernel  . flagMeanErr () ; }

double ChronoEntity::uMeanErrorTime (  )  const [inline]

error in mean User time

Definition at line 293 of file ChronoEntity.h.

00293 { return m_user    . flagMeanErr () ; }

double ChronoEntity::eMeanErrorTime (  )  const [inline]

error in mean Elapsed time

Definition at line 298 of file ChronoEntity.h.

00298 { return m_elapsed . flagMeanErr () ; }

bool ChronoEntity::operator< ( const ChronoEntity entity  )  const

comparison operator

Definition at line 240 of file ChronoEntity.cpp.

00241 { 
00242   return 
00243     ( &e           == this          ) ? false : 
00244     ( totalTime () < e.totalTime () ) ? true  :
00245     ( totalTime () > e.totalTime () ) ? false :
00246     ( m_user       < e.m_user       ) ? true  :
00247     ( e.m_user     <   m_user       ) ? false : 
00248     ( m_kernel     < e.m_kernel     ) ? true  :
00249     ( e.m_kernel   <   m_kernel     ) ? false : 
00250     ( m_elapsed    < e.m_elapsed    ) ? true  :
00251     ( e.m_elapsed  <   m_elapsed    ) ? false : false ;
00252 }

std::string ChronoEntity::outputUserTime (  )  const

print the chrono ;

Definition at line 112 of file ChronoEntity.cpp.

00113 {
00114   std::string res ("Time User   : ") ;
00115   return res += format 
00116     ( uTotalTime     () ,
00117       uMinimalTime   () ,
00118       uMeanTime      () ,
00119       uRMSTime       () ,
00120       uMaximalTime   () ,
00121       nOfMeasurements() );
00122 }

std::string ChronoEntity::outputSystemTime (  )  const

print the chrono ;

Definition at line 126 of file ChronoEntity.cpp.

00127 {
00128   std::string res ("Time System : ") ;
00129   return res += format
00130     ( kTotalTime     () ,
00131       kMinimalTime   () ,
00132                         kMeanTime      () ,
00133                         kRMSTime       () ,
00134                         kMaximalTime   () ,
00135                         nOfMeasurements() );
00136 }

std::string ChronoEntity::outputElapsedTime (  )  const

print the chrono ;

Definition at line 139 of file ChronoEntity.cpp.

00140 {
00141   std::string res ("TimeElapsed: ") ;
00142   return res += format
00143     ( eTotalTime     () , 
00144       eMinimalTime   () , 
00145       eMeanTime      () , 
00146       eRMSTime       () , 
00147       eMaximalTime   () , 
00148       nOfMeasurements() );  
00149 }

std::string ChronoEntity::outputUserTime ( const std::string fmt,
System::TimeType  unit 
) const [inline]

print the chrono according the format and units

Parameters:
fmt the format string
unit the unit
Returns:
the string representations
See also:
boost::format

Definition at line 325 of file ChronoEntity.h.

00327 {
00328   return outputTime ( IChronoSvc::USER , fmt , unit ) ;
00329 }

std::string ChronoEntity::outputSystemTime ( const std::string fmt,
System::TimeType  unit 
) const [inline]

print the chrono according the format and units

Parameters:
fmt the format string
unit the unit
Returns:
the string representations
See also:
boost::format

Definition at line 340 of file ChronoEntity.h.

00342 {
00343   return outputTime ( IChronoSvc::KERNEL , fmt , unit ) ;
00344 }

std::string ChronoEntity::outputElapsedTime ( const std::string fmt,
System::TimeType  unit 
) const [inline]

print the chrono according the format and units

Parameters:
fmt the format string
unit the unit
Returns:
the string representations
See also:
boost::format

Definition at line 355 of file ChronoEntity.h.

00357 {
00358   return outputTime ( IChronoSvc::ELAPSED , fmt , unit ) ;
00359 }

std::string ChronoEntity::outputTime ( IChronoSvc::ChronoType  typ,
const std::string fmt,
System::TimeType  unit 
) const

print the chrono according the format and units

The format fields are:

  1. number of entries
  2. total time (in the specified units)
  3. mean time (in the specified units)
  4. r.m.s. time (in the specified units)
  5. error in mean time (in the specified units)
  6. minimal time (in the specified units)
  7. maximal time (in the specified units)

Parameters:
typ the chrono type
fmt the format string
unit the unit
Returns:
the string representations
See also:
boost::format

Definition at line 263 of file ChronoEntity.cpp.

00266 {
00267   boost::format _fmt ( fmt ) ;
00268   // allow various number of arguments 
00269   using namespace boost::io ;  
00270   _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
00271   //
00272   double _unit = microsecond ;
00273   switch ( unit ) 
00274   {
00275   case System::Year     : _unit = year        ; break ;
00276   case System::Month    : _unit = month       ; break ;
00277   case System::Day      : _unit = day         ; break ;
00278   case System::Hour     : _unit = hour        ; break ;
00279   case System::Min      : _unit = minute      ; break ;
00280   case System::Sec      : _unit = second      ; break ;
00281   case System::milliSec : _unit = millisecond ; break ;
00282   case System::microSec : _unit = microsecond ; break ;
00283   case System::nanoSec  : _unit = nanosecond  ; break ;
00284   default               : _unit = microsecond ; break ;
00285   }
00286   //
00287   const StatEntity* stat = &m_user;
00288   switch ( typ ) 
00289   {
00290   case IChronoSvc::USER    : stat = &m_user    ; break ;
00291   case IChronoSvc::KERNEL  : stat = &m_kernel  ; break ;
00292   case IChronoSvc::ELAPSED : stat = &m_elapsed ; break ;
00293   default                  : stat = &m_user    ; break ;
00294   }
00295   //  
00296   _fmt 
00297     %   ( stat -> nEntries    ()         )   // %1 : #entries 
00298     %   ( stat -> flag        () / _unit )   // %2 : total time 
00299     %   ( stat -> flagMean    () / _unit )   // %3 : mean time 
00300     %   ( stat -> flagRMS     () / _unit )   // %4 : RMS  time 
00301     %   ( stat -> flagMeanErr () / _unit )   // %5 : error in mean time 
00302     %   ( stat -> flagMin     () / _unit )   // %6 : minimal time 
00303     %   ( stat -> flagMax     () / _unit ) ; // %7 : maximal time 
00304   //
00305   return _fmt.str() ;
00306 }

std::string ChronoEntity::format ( const double  total,
const double  minimal,
const double  mean,
const double  rms,
const double  maximal,
const unsigned long  number 
) const [protected]

format

Definition at line 154 of file ChronoEntity.cpp.

00160 {
00162   const int buffer_size         = 256 ;
00163   char      buffer[buffer_size]       ;
00164   int       index               = 0   ;
00166   long double  unit = 1.0 ;
00167   std::string cunit = ""  ; 
00169   if     ( total / microsecond  <  500 ) 
00170   { unit = microsecond ; cunit = " [us]"    ; } 
00171   else if( total / millisecond  <  500 )
00172   { unit = millisecond ; cunit = " [ms]"    ; } 
00173   else if( total /      second  <  500 ) 
00174   { unit =      second ; cunit = "  [s]"     ; }
00175   else if( total /      minute  <  500 )
00176   { unit =      minute ; cunit = "[min]"   ; }
00177   else if( total /        hour  <  500 ) 
00178     { unit =        hour ; cunit = "  [h]"     ; }
00179   else if( total /         day  <   10 )
00180   { unit =         day ; cunit = "[day]"   ; }
00181   else if( total /        week  <    5 ) 
00182   { unit =        week ; cunit = "  [w]"  ; }
00183   else if( total /       month  <   20 ) 
00184   { unit =       month ; cunit = "[mon]" ; }
00185   else                                   
00186   { unit =        year ; cunit = "  [y]"  ; } 
00188   index += sprintf( buffer + index , "Tot=%5.3g" , (double) (total / unit) ) ;
00189   index += sprintf( buffer + index , "%s" , cunit.c_str()          ) ;
00191   if( 1 < number )
00192   {
00193     
00194     if     ( mean / microsecond  <  500 ) 
00195     { unit = microsecond ; cunit = " [us]"    ; } 
00196     else if( mean / millisecond  <  500 )
00197     { unit = millisecond ; cunit = " [ms]"    ; } 
00198     else if( mean /      second  <  500 ) 
00199     { unit =      second ; cunit = "  [s]"     ; }
00200     else if( mean /      minute  <  500 )
00201     { unit =      minute ; cunit = "[min]"   ; }
00202     else if( mean /        hour  <  500 ) 
00203     { unit =        hour ; cunit = "  [h]"     ; }
00204     else if( mean /         day  <   10 )
00205     { unit =         day ; cunit = "[day]"   ; }
00206     else if( mean /        week  <    5 ) 
00207     { unit =        week ; cunit = "  [w]"  ; }
00208     else if( mean /       month  <   20 ) 
00209     { unit =       month ; cunit = "[mon]" ; }
00210     else                                   
00211     { unit =        year ; cunit = "[year]"  ; } 
00213     index += 
00214       sprintf( buffer + index , 
00215                " Ave/Min/Max=%5.3g" , (double) ( mean / unit ) ) ;
00216     index += 
00217       sprintf( buffer + index , 
00218                "(+-%5.3g)"          , (double) ( rms  / unit ) ) ;
00219     index += 
00220       sprintf( buffer + index , 
00221                "/%5.3g"             , (double) ( minimal  / unit ) ) ;
00222     index += 
00223       sprintf( buffer + index , 
00224                "/%5.3g"             , (double) ( maximal  / unit ) ) ;
00226     index += sprintf( buffer + index , "%s" , cunit.c_str() );
00228   }
00229   else
00230   { index += sprintf( buffer + index , "%44s" , " " ); }    
00232   index += sprintf( buffer + index , " #=%3lu" , number );
00234   return std::string( buffer, 0 , index );
00236 }


Member Data Documentation

current status of this chrono object;

Definition at line 172 of file ChronoEntity.h.

delta user time

Definition at line 174 of file ChronoEntity.h.

delta Kernel time

Definition at line 176 of file ChronoEntity.h.

delta Elapsed time

Definition at line 178 of file ChronoEntity.h.

start stamp for current measurement of user time

Definition at line 180 of file ChronoEntity.h.

start stamp for current measurement of Kernel time

Definition at line 182 of file ChronoEntity.h.

start stamp for current measurement of Elapsed time

Definition at line 184 of file ChronoEntity.h.

the actual storage of "user" time

Definition at line 186 of file ChronoEntity.h.

the actual storage of "kernel" time

Definition at line 188 of file ChronoEntity.h.

the actual storage of "elapsed" time

Definition at line 190 of file ChronoEntity.h.


The documentation for this class was generated from the following files:

Generated at Wed Mar 17 18:16:35 2010 for Gaudi Framework, version v21r8 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004