CMS 3D CMS Logo

Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes

edm::CPUTimer Class Reference

#include <CPUTimer.h>

List of all members.

Classes

struct  Times

Public Member Functions

void add (const Times &t)
double cpuTime () const
 CPUTimer ()
double realTime () const
void reset ()
void start ()
Times stop ()
virtual ~CPUTimer ()

Private Types

enum  State { kRunning, kStopped }

Private Member Functions

Times calculateDeltaTime () const
 CPUTimer (const CPUTimer &)
const CPUTimeroperator= (const CPUTimer &)

Private Attributes

double accumulatedCPUTime_
double accumulatedRealTime_
struct timeval startCPUTime_
struct timeval startRealTime_
enum edm::CPUTimer::State state_

Detailed Description

Definition at line 40 of file CPUTimer.h.


Member Enumeration Documentation

enum edm::CPUTimer::State [private]
Enumerator:
kRunning 
kStopped 

Definition at line 74 of file CPUTimer.h.


Constructor & Destructor Documentation

CPUTimer::CPUTimer ( )

Definition at line 33 of file CPUTimer.cc.

References startCPUTime_, and startRealTime_.

                   :
state_(kStopped),
startRealTime_(),
startCPUTime_(),
accumulatedRealTime_(0),
accumulatedCPUTime_(0) {
#ifdef USE_CLOCK_GETTIME
  startRealTime_.tv_sec=0;
  startRealTime_.tv_nsec=0;
  startCPUTime_.tv_sec=0;
  startCPUTime_.tv_nsec=0;
#else
  startRealTime_.tv_sec=0;
  startRealTime_.tv_usec=0;
  startCPUTime_.tv_sec=0;
  startCPUTime_.tv_usec=0;
#endif
}
CPUTimer::~CPUTimer ( ) [virtual]

Definition at line 56 of file CPUTimer.cc.

                    {
}
edm::CPUTimer::CPUTimer ( const CPUTimer ) [private]

Member Function Documentation

void CPUTimer::add ( const Times t)
CPUTimer::Times CPUTimer::calculateDeltaTime ( ) const [private]

Definition at line 119 of file CPUTimer.cc.

References CLOCK_PROCESS_CPUTIME_ID, CLOCK_REALTIME, edm::CPUTimer::Times::cpu_, Exception, edm::CPUTimer::Times::real_, startCPUTime_, and startRealTime_.

Referenced by cpuTime(), realTime(), and stop().

                                   {
  Times returnValue;
#ifdef USE_CLOCK_GETTIME
  double const nanosecToSec = 1E-9;
  struct timespec tp;
  clock_gettime(CLOCK_REALTIME, &tp);
  returnValue.real_ = tp.tv_sec - startRealTime_.tv_sec + nanosecToSec * (tp.tv_nsec - startRealTime_.tv_nsec);

  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
  returnValue.cpu_ = tp.tv_sec - startCPUTime_.tv_sec + nanosecToSec * (tp.tv_nsec - startCPUTime_.tv_nsec);
#else
  rusage theUsage;
  if(0 != getrusage(RUSAGE_SELF, &theUsage)) {
    throw cms::Exception("CPUTimerFailed") << errno;
  }
  double const microsecToSec = 1E-6;

  struct timeval tp;
  gettimeofday(&tp, 0);

  returnValue.cpu_ = theUsage.ru_stime.tv_sec + theUsage.ru_utime.tv_sec - startCPUTime_.tv_sec +
                     microsecToSec * (theUsage.ru_stime.tv_usec + theUsage.ru_utime.tv_usec - startCPUTime_.tv_usec);
  returnValue.real_ = tp.tv_sec - startRealTime_.tv_sec + microsecToSec * (tp.tv_usec - startRealTime_.tv_usec);
#endif
  return returnValue;
}
double CPUTimer::cpuTime ( ) const
const CPUTimer& edm::CPUTimer::operator= ( const CPUTimer ) [private]
double CPUTimer::realTime ( ) const
void CPUTimer::reset ( void  )
void CPUTimer::start ( void  )

Definition at line 74 of file CPUTimer.cc.

References CLOCK_PROCESS_CPUTIME_ID, CLOCK_REALTIME, Exception, kRunning, kStopped, startCPUTime_, startRealTime_, and state_.

Referenced by ZDCMonitorModule::analyze(), CastorMonitorModule::analyze(), edm::service::PathTimerService::preModule(), CastorPSMonitor::processEvent(), HcalZDCMonitor::processEvent(), CastorHIMonitor::processEvent(), CastorRecHitMonitor::processEvent(), CastorDigiMonitor::processEvent(), CastorEventDisplay::processEvent(), HcalZDCMonitor::setup(), HcalBaseMonitor::setupDepthHists1D(), and HcalBaseMonitor::setupDepthHists2D().

                {
  if(kStopped == state_) {
#ifdef USE_CLOCK_GETTIME
    clock_gettime(CLOCK_REALTIME, &startRealTime_);
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &startCPUTime_);
#else
    rusage theUsage;
    if(0 != getrusage(RUSAGE_SELF, &theUsage)) {
      throw cms::Exception("CPUTimerFailed")<<errno;
    }
    startCPUTime_.tv_sec =theUsage.ru_stime.tv_sec+theUsage.ru_utime.tv_sec;
    startCPUTime_.tv_usec =theUsage.ru_stime.tv_usec+theUsage.ru_utime.tv_usec;

    gettimeofday(&startRealTime_, 0);
#endif
    state_ = kRunning;
  }
}
CPUTimer::Times CPUTimer::stop ( )

Member Data Documentation

Definition at line 84 of file CPUTimer.h.

Referenced by add(), cpuTime(), reset(), and stop().

Definition at line 83 of file CPUTimer.h.

Referenced by add(), realTime(), reset(), and stop().

struct timeval edm::CPUTimer::startCPUTime_ [private]

Definition at line 80 of file CPUTimer.h.

Referenced by calculateDeltaTime(), CPUTimer(), and start().

struct timeval edm::CPUTimer::startRealTime_ [private]

Definition at line 79 of file CPUTimer.h.

Referenced by calculateDeltaTime(), CPUTimer(), and start().

Referenced by cpuTime(), realTime(), start(), and stop().