test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
edm::CPUTimer Class Reference

#include <CPUTimer.h>

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 39 of file CPUTimer.h.

Member Enumeration Documentation

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

Definition at line 73 of file CPUTimer.h.

Constructor & Destructor Documentation

CPUTimer::CPUTimer ( )

Definition at line 33 of file CPUTimer.cc.

References startCPUTime_, and startRealTime_.

33  :
39 #ifdef USE_CLOCK_GETTIME
40  startRealTime_.tv_sec=0;
41  startRealTime_.tv_nsec=0;
42  startCPUTime_.tv_sec=0;
43  startCPUTime_.tv_nsec=0;
44 #else
45  startRealTime_.tv_sec=0;
46  startRealTime_.tv_usec=0;
47  startCPUTime_.tv_sec=0;
48  startCPUTime_.tv_usec=0;
49 #endif
50 }
enum edm::CPUTimer::State state_
struct timeval startCPUTime_
Definition: CPUTimer.h:79
struct timeval startRealTime_
Definition: CPUTimer.h:78
double accumulatedCPUTime_
Definition: CPUTimer.h:83
double accumulatedRealTime_
Definition: CPUTimer.h:82
CPUTimer::~CPUTimer ( )
virtual

Definition at line 56 of file CPUTimer.cc.

56  {
57 }
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_, edm::hlt::Exception, edm::CPUTimer::Times::real_, startCPUTime_, and startRealTime_.

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

119  {
120  Times returnValue;
121 #ifdef USE_CLOCK_GETTIME
122  double const nanosecToSec = 1E-9;
123  struct timespec tp;
124 
125  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
126  returnValue.cpu_ = tp.tv_sec - startCPUTime_.tv_sec + nanosecToSec * (tp.tv_nsec - startCPUTime_.tv_nsec);
127 
128  clock_gettime(CLOCK_REALTIME, &tp);
129  returnValue.real_ = tp.tv_sec - startRealTime_.tv_sec + nanosecToSec * (tp.tv_nsec - startRealTime_.tv_nsec);
130 #else
131  rusage theUsage;
132  if(0 != getrusage(RUSAGE_SELF, &theUsage)) {
133  throw cms::Exception("CPUTimerFailed") << errno;
134  }
135  double const microsecToSec = 1E-6;
136 
137  struct timeval tp;
138  gettimeofday(&tp, 0);
139 
140  returnValue.cpu_ = theUsage.ru_stime.tv_sec + theUsage.ru_utime.tv_sec - startCPUTime_.tv_sec +
141  microsecToSec * (theUsage.ru_stime.tv_usec + theUsage.ru_utime.tv_usec - startCPUTime_.tv_usec);
142  returnValue.real_ = tp.tv_sec - startRealTime_.tv_sec + microsecToSec * (tp.tv_usec - startRealTime_.tv_usec);
143 #endif
144  return returnValue;
145 }
struct timeval startCPUTime_
Definition: CPUTimer.h:79
struct timeval startRealTime_
Definition: CPUTimer.h:78
#define CLOCK_PROCESS_CPUTIME_ID
Definition: TimerService.h:34
#define CLOCK_REALTIME
Definition: TimerService.h:32
double CPUTimer::cpuTime ( ) const
const CPUTimer& edm::CPUTimer::operator= ( const CPUTimer )
private
double CPUTimer::realTime ( ) const

Definition at line 150 of file CPUTimer.cc.

References accumulatedRealTime_, calculateDeltaTime(), kStopped, edm::CPUTimer::Times::real_, and state_.

Referenced by edm::service::ResourceEnforcer::check(), and edm::service::PathTimerService::postModule().

150  {
151  if(kStopped == state_) {
152  return accumulatedRealTime_;
153  }
155 }
enum edm::CPUTimer::State state_
double accumulatedRealTime_
Definition: CPUTimer.h:82
Times calculateDeltaTime() const
Definition: CPUTimer.cc:119
void CPUTimer::reset ( void  )
void CPUTimer::start ( void  )

Definition at line 74 of file CPUTimer.cc.

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

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

74  {
75  if(kStopped == state_) {
76 #ifdef USE_CLOCK_GETTIME
77  clock_gettime(CLOCK_REALTIME, &startRealTime_);
78  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &startCPUTime_);
79 #else
80  gettimeofday(&startRealTime_, 0);
81 
82  rusage theUsage;
83  if(0 != getrusage(RUSAGE_SELF, &theUsage)) {
84  throw cms::Exception("CPUTimerFailed")<<errno;
85  }
86  startCPUTime_.tv_sec =theUsage.ru_stime.tv_sec+theUsage.ru_utime.tv_sec;
87  startCPUTime_.tv_usec =theUsage.ru_stime.tv_usec+theUsage.ru_utime.tv_usec;
88 #endif
89  state_ = kRunning;
90  }
91 }
enum edm::CPUTimer::State state_
struct timeval startCPUTime_
Definition: CPUTimer.h:79
struct timeval startRealTime_
Definition: CPUTimer.h:78
#define CLOCK_PROCESS_CPUTIME_ID
Definition: TimerService.h:34
#define CLOCK_REALTIME
Definition: TimerService.h:32
CPUTimer::Times CPUTimer::stop ( )

Member Data Documentation

double edm::CPUTimer::accumulatedCPUTime_
private

Definition at line 83 of file CPUTimer.h.

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

double edm::CPUTimer::accumulatedRealTime_
private

Definition at line 82 of file CPUTimer.h.

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

struct timeval edm::CPUTimer::startCPUTime_
private

Definition at line 79 of file CPUTimer.h.

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

struct timeval edm::CPUTimer::startRealTime_
private

Definition at line 78 of file CPUTimer.h.

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

enum edm::CPUTimer::State edm::CPUTimer::state_
private

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