Gaudi Framework, version v23r2

Home   Generated: Thu Jun 28 2012
Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes

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 elapsed time
double uMaximalTime () const
 maximal measurement for user time
double kMaximalTime () const
 maximal measurement for kernel time
double eMaximalTime () const
 maximal measurement for elapsed 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;
System::ProcessTime m_delta
 delta process times
System::ProcessTime m_start
 start stamp for current measurement of process times
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

Static Private Attributes

static const System::TimeType TimeUnit = System::microSec
 internal unit used for the system time conversion (microseconds)

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 21 of file ChronoEntity.h.


Constructor & Destructor Documentation

ChronoEntity::ChronoEntity (  )

default constructor

Definition at line 46 of file ChronoEntity.cpp.

  : m_status( IChronoSvc::UNKNOWN )  // current status
{}
ChronoEntity::~ChronoEntity (  ) [inline]

destructor

Definition at line 27 of file ChronoEntity.h.

{}

Member Function Documentation

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

return the last delta-time of type "type"

Definition at line 295 of file ChronoEntity.h.

{
  const IChronoSvc::ChronoTime result = -1 ;
  switch ( type )
  {
  case IChronoSvc::USER    : return m_delta.userTime<TimeUnit>();
  case IChronoSvc::KERNEL  : return m_delta.kernelTime<TimeUnit>();
  case IChronoSvc::ELAPSED : return m_delta.elapsedTime<TimeUnit>();
  default                  : return result;
  }
  // cannot reach this point
}
double ChronoEntity::eMaximalTime (  ) const [inline]

maximal measurement for elapsed time

Definition at line 224 of file ChronoEntity.h.

{ return m_elapsed . flagMax () ; }
double ChronoEntity::eMeanErrorTime (  ) const [inline]

error in mean Elapsed time

Definition at line 290 of file ChronoEntity.h.

{ return m_elapsed . flagMeanErr () ; }
double ChronoEntity::eMeanTime (  ) const [inline]

average Elapsed Time

Definition at line 260 of file ChronoEntity.h.

{ return m_elapsed . flagMean () ; }
double ChronoEntity::eMinimalTime (  ) const [inline]

minimal measurement for elapsed time

Definition at line 209 of file ChronoEntity.h.

{ return m_elapsed. flagMin () ; }
double ChronoEntity::eRMSTime (  ) const [inline]

r.m.s Elapsed Time

Definition at line 275 of file ChronoEntity.h.

{ return m_elapsed . flagRMS () ; }
double ChronoEntity::eTotalTime (  ) const [inline]

total Elapsed time

Definition at line 239 of file ChronoEntity.h.

{ return m_elapsed . flag () ; }
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

Todo:
: cache the format
Todo:
: cache the format

Definition at line 133 of file ChronoEntity.cpp.

{

  boost::format fmt("Tot=%2$5.3g%1$s %4$43s #=%3$3lu");

  long double  unit = 1.0 ;

  if     ( total / microsecond  <  500 )
  { unit = microsecond ; fmt % " [us]" ; }
  else if( total / millisecond  <  500 )
  { unit = millisecond ; fmt % " [ms]" ; }
  else if( total /      second  <  500 )
  { unit =      second ; fmt % "  [s]" ; }
  else if( total /      minute  <  500 )
  { unit =      minute ; fmt % "[min]" ; }
  else if( total /        hour  <  500 )
  { unit =        hour ; fmt % "  [h]" ; }
  else if( total /         day  <   10 )
  { unit =         day ; fmt % "[day]" ; }
  else if( total /        week  <    5 )
  { unit =        week ; fmt % "  [w]" ; }
  else if( total /       month  <   20 )
  { unit =       month ; fmt % "[mon]" ; }
  else
  { unit =        year ; fmt % "  [y]" ; }

  fmt % (double) (total / unit) % number;

  if( 1 < number )
  {
    boost::format fmt1("Ave/Min/Max=%2$5.3g(+-%3$5.3g)/%4$5.3g/%5$5.3g%1$s");
    if     ( mean / microsecond  <  500 )
    { unit = microsecond ; fmt1 % " [us]" ; }
    else if( mean / millisecond  <  500 )
    { unit = millisecond ; fmt1 % " [ms]" ; }
    else if( mean /      second  <  500 )
    { unit =      second ; fmt1 % "  [s]" ; }
    else if( mean /      minute  <  500 )
    { unit =      minute ; fmt1 % "[min]" ; }
    else if( mean /        hour  <  500 )
    { unit =        hour ; fmt1 % "  [h]" ; }
    else if( mean /         day  <   10 )
    { unit =         day ; fmt1 % "[day]" ; }
    else if( mean /        week  <    5 )
    { unit =        week ; fmt1 % "  [w]" ; }
    else if( mean /       month  <   20 )
    { unit =       month ; fmt1 % "[mon]" ; }
    else
    { unit =        year ; fmt1 % "  [y]" ; }

    fmt1 % (double) ( mean / unit ) % (double) ( rms  / unit )
         % (double) ( minimal  / unit ) % (double) ( maximal  / unit );
    fmt % fmt1.str();
  }
  else {
    fmt % "";
  }

  return fmt.str();
}
double ChronoEntity::kMaximalTime (  ) const [inline]

maximal measurement for kernel time

Definition at line 219 of file ChronoEntity.h.

{ return m_kernel . flagMax () ; }
double ChronoEntity::kMeanErrorTime (  ) const [inline]

error in mean Kernel time

Definition at line 280 of file ChronoEntity.h.

{ return m_kernel  . flagMeanErr () ; }
double ChronoEntity::kMeanTime (  ) const [inline]

average Kernel Time

Definition at line 250 of file ChronoEntity.h.

{ return m_kernel  . flagMean () ; }
double ChronoEntity::kMinimalTime (  ) const [inline]

minimal measurement for kernel time

Definition at line 204 of file ChronoEntity.h.

{ return m_kernel . flagMin () ; }
double ChronoEntity::kRMSTime (  ) const [inline]

r.m.s Kernel Time

Definition at line 265 of file ChronoEntity.h.

{ return m_kernel  . flagRMS  () ; }
double ChronoEntity::kTotalTime (  ) const [inline]

total Kernel time

Definition at line 234 of file ChronoEntity.h.

{ return m_kernel  . flag () ; }
unsigned long ChronoEntity::nOfMeasurements (  ) const [inline]

number of chrono measurements

Definition at line 194 of file ChronoEntity.h.

{ return m_user   . nEntries() ; }
bool ChronoEntity::operator< ( const ChronoEntity entity ) const

comparison operator

Definition at line 203 of file ChronoEntity.cpp.

{
  return
    ( &e           == this          ) ? false :
    ( totalTime () < e.totalTime () ) ? true  :
    ( totalTime () > e.totalTime () ) ? false :
    ( m_user       < e.m_user       ) ? true  :
    ( e.m_user     <   m_user       ) ? false :
    ( m_kernel     < e.m_kernel     ) ? true  :
    ( e.m_kernel   <   m_kernel     ) ? false :
    ( m_elapsed    < e.m_elapsed    ) ? true  :
    ( e.m_elapsed  <   m_elapsed    ) ? false : false ;
}
std::string ChronoEntity::outputElapsedTime (  ) const

print the chrono ;

Definition at line 118 of file ChronoEntity.cpp.

{
  std::string res ("TimeElapsed: ") ;
  return res += format
    ( eTotalTime     () ,
      eMinimalTime   () ,
      eMeanTime      () ,
      eRMSTime       () ,
      eMaximalTime   () ,
      nOfMeasurements() );
}
std::string ChronoEntity::outputElapsedTime ( const std::string fmt,
System::TimeType  unit 
) const [inline]

print the chrono according the format and units

Parameters:
fmtthe format string
unitthe unit
Returns:
the string representations
See also:
boost::format

Definition at line 347 of file ChronoEntity.h.

{
  return outputTime ( IChronoSvc::ELAPSED , fmt , unit ) ;
}
std::string ChronoEntity::outputSystemTime ( const std::string fmt,
System::TimeType  unit 
) const [inline]

print the chrono according the format and units

Parameters:
fmtthe format string
unitthe unit
Returns:
the string representations
See also:
boost::format

Definition at line 332 of file ChronoEntity.h.

{
  return outputTime ( IChronoSvc::KERNEL , fmt , unit ) ;
}
std::string ChronoEntity::outputSystemTime (  ) const

print the chrono ;

Definition at line 105 of file ChronoEntity.cpp.

{
  std::string res ("Time System : ") ;
  return res += format
    ( kTotalTime     () ,
      kMinimalTime   () ,
      kMeanTime      () ,
      kRMSTime       () ,
      kMaximalTime   () ,
      nOfMeasurements() );
}
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:
typthe chrono type
fmtthe format string
unitthe unit
Returns:
the string representations
See also:
boost::format

Definition at line 226 of file ChronoEntity.cpp.

{
  boost::format _fmt ( fmt ) ;
  // allow various number of arguments
  using namespace boost::io ;
  _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
  //
  double _unit = microsecond ;
  switch ( unit )
  {
  case System::Year     : _unit = year        ; break ;
  case System::Month    : _unit = month       ; break ;
  case System::Day      : _unit = day         ; break ;
  case System::Hour     : _unit = hour        ; break ;
  case System::Min      : _unit = minute      ; break ;
  case System::Sec      : _unit = second      ; break ;
  case System::milliSec : _unit = millisecond ; break ;
  case System::microSec : _unit = microsecond ; break ;
  case System::nanoSec  : _unit = nanosecond  ; break ;
  default               : _unit = microsecond ; break ;
  }
  //
  const StatEntity* stat = &m_user;
  switch ( typ )
  {
  case IChronoSvc::USER    : stat = &m_user    ; break ;
  case IChronoSvc::KERNEL  : stat = &m_kernel  ; break ;
  case IChronoSvc::ELAPSED : stat = &m_elapsed ; break ;
  default                  : stat = &m_user    ; break ;
  }
  //
  _fmt
    %   ( stat -> nEntries    ()         )   // %1 : #entries
    %   ( stat -> flag        () / _unit )   // %2 : total time
    %   ( stat -> flagMean    () / _unit )   // %3 : mean time
    %   ( stat -> flagRMS     () / _unit )   // %4 : RMS  time
    %   ( stat -> flagMeanErr () / _unit )   // %5 : error in mean time
    %   ( stat -> flagMin     () / _unit )   // %6 : minimal time
    %   ( stat -> flagMax     () / _unit ) ; // %7 : maximal time
  //
  return _fmt.str() ;
}
std::string ChronoEntity::outputUserTime ( const std::string fmt,
System::TimeType  unit 
) const [inline]

print the chrono according the format and units

Parameters:
fmtthe format string
unitthe unit
Returns:
the string representations
See also:
boost::format

Definition at line 317 of file ChronoEntity.h.

{
  return outputTime ( IChronoSvc::USER , fmt , unit ) ;
}
std::string ChronoEntity::outputUserTime (  ) const

print the chrono ;

Definition at line 91 of file ChronoEntity.cpp.

{
  std::string res ("Time User   : ") ;
  return res += format
    ( uTotalTime     () ,
      uMinimalTime   () ,
      uMeanTime      () ,
      uRMSTime       () ,
      uMaximalTime   () ,
      nOfMeasurements() );
}
IChronoSvc::ChronoStatus ChronoEntity::start (  )

start the current chrono

Definition at line 53 of file ChronoEntity.cpp.

{
  if ( IChronoSvc::RUNNING == m_status ) { return m_status ; }
  //
  // following lines could be platform dependent!
  //
  // Store in object the measured times
  m_start = System::getProcessTime();

  m_status = IChronoSvc::RUNNING;

  return m_status ;
}
IChronoSvc::ChronoStatus ChronoEntity::status (  ) const [inline]

return the status of chrono

Definition at line 189 of file ChronoEntity.h.

{ return m_status; }
IChronoSvc::ChronoStatus ChronoEntity::stop (  )

stop the chrono

Definition at line 69 of file ChronoEntity.cpp.

{
  if ( IChronoSvc::RUNNING != m_status ) { return m_status ; }

  // following lines could be platform dependent!
  m_delta = System::getProcessTime() - m_start;

  // update the counters:

  m_user     += m_delta.userTime<TimeUnit>();
  m_kernel   += m_delta.kernelTime<TimeUnit>();
  m_elapsed  += m_delta.elapsedTime<TimeUnit>();

  // set new status

  m_status = IChronoSvc::STOPPED;

  return m_status ;
}
double ChronoEntity::totalTime (  ) const [inline]

total time

Definition at line 244 of file ChronoEntity.h.

{ return uTotalTime() + kTotalTime()  ; }
double ChronoEntity::uMaximalTime (  ) const [inline]

maximal measurement for user time

Definition at line 214 of file ChronoEntity.h.

{ return m_user   . flagMax () ; }
double ChronoEntity::uMeanErrorTime (  ) const [inline]

error in mean User time

Definition at line 285 of file ChronoEntity.h.

{ return m_user    . flagMeanErr () ; }
double ChronoEntity::uMeanTime (  ) const [inline]

average User Time

Definition at line 255 of file ChronoEntity.h.

{ return m_user    . flagMean () ; }
double ChronoEntity::uMinimalTime (  ) const [inline]

minimal measurement for user time

Definition at line 198 of file ChronoEntity.h.

{ return m_user   . flagMin () ; }
double ChronoEntity::uRMSTime (  ) const [inline]

r.m.s User Time

Definition at line 270 of file ChronoEntity.h.

{ return m_user    . flagRMS  () ; }
double ChronoEntity::uTotalTime (  ) const [inline]

total user time

Definition at line 229 of file ChronoEntity.h.

{ return m_user    . flag () ; }

Member Data Documentation

delta process times

Definition at line 172 of file ChronoEntity.h.

the actual storage of "elapsed" time

Definition at line 180 of file ChronoEntity.h.

the actual storage of "kernel" time

Definition at line 178 of file ChronoEntity.h.

start stamp for current measurement of process times

Definition at line 174 of file ChronoEntity.h.

current status of this chrono object;

Definition at line 170 of file ChronoEntity.h.

the actual storage of "user" time

Definition at line 176 of file ChronoEntity.h.

const System::TimeType ChronoEntity::TimeUnit = System::microSec [static, private]

internal unit used for the system time conversion (microseconds)

Definition at line 182 of file ChronoEntity.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 23:27:35 for Gaudi Framework, version v23r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004