CMS 3D CMS Logo

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 ()
 
 CPUTimer (const CPUTimer &)=delete
 
 CPUTimer (CPUTimer &&)=default
 
CPUTimeroperator= (const CPUTimer &)=delete
 
double realTime () const
 
void reset ()
 
void start ()
 
Times stop ()
 
 ~CPUTimer ()
 

Private Types

enum  State { kRunning, kStopped }
 

Private Member Functions

Times calculateDeltaTime () const
 

Private Attributes

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

Detailed Description

Definition at line 37 of file CPUTimer.h.

Member Enumeration Documentation

◆ State

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

Definition at line 68 of file CPUTimer.h.

Constructor & Destructor Documentation

◆ CPUTimer() [1/3]

CPUTimer::CPUTimer ( )

Definition at line 33 of file CPUTimer.cc.

35 #ifdef USE_CLOCK_GETTIME
36  startRealTime_.tv_sec = 0;
37  startRealTime_.tv_nsec = 0;
38  startCPUTime_.tv_sec = 0;
39  startCPUTime_.tv_nsec = 0;
40 #else
41  startRealTime_.tv_sec = 0;
42  startRealTime_.tv_usec = 0;
43  startCPUTime_.tv_sec = 0;
44  startCPUTime_.tv_usec = 0;
45 #endif
46 }

References startCPUTime_, and startRealTime_.

◆ ~CPUTimer()

CPUTimer::~CPUTimer ( )

Definition at line 52 of file CPUTimer.cc.

52 {}

◆ CPUTimer() [2/3]

edm::CPUTimer::CPUTimer ( CPUTimer &&  )
default

◆ CPUTimer() [3/3]

edm::CPUTimer::CPUTimer ( const CPUTimer )
delete

Member Function Documentation

◆ add()

void CPUTimer::add ( const Times t)

Definition at line 104 of file CPUTimer.cc.

104  {
105  accumulatedCPUTime_ += t.cpu_;
106  accumulatedRealTime_ += t.real_;
107 }

References accumulatedCPUTime_, accumulatedRealTime_, and submitPVValidationJobs::t.

Referenced by counter.Counter::register().

◆ calculateDeltaTime()

CPUTimer::Times CPUTimer::calculateDeltaTime ( ) const
private

Definition at line 109 of file CPUTimer.cc.

109  {
110  Times returnValue;
111 #ifdef USE_CLOCK_GETTIME
112  double const nanosecToSec = 1E-9;
113  struct timespec tp;
114 
115  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
116  returnValue.cpu_ = tp.tv_sec - startCPUTime_.tv_sec + nanosecToSec * (tp.tv_nsec - startCPUTime_.tv_nsec);
117 
118  clock_gettime(CLOCK_MONOTONIC, &tp);
119  returnValue.real_ = tp.tv_sec - startRealTime_.tv_sec + nanosecToSec * (tp.tv_nsec - startRealTime_.tv_nsec);
120 #else
121  rusage theUsage;
122  if (0 != getrusage(RUSAGE_SELF, &theUsage)) {
123  throw cms::Exception("CPUTimerFailed") << errno;
124  }
125  double const microsecToSec = 1E-6;
126 
127  struct timeval tp;
128  gettimeofday(&tp, 0);
129 
130  returnValue.cpu_ = theUsage.ru_stime.tv_sec + theUsage.ru_utime.tv_sec - startCPUTime_.tv_sec +
131  microsecToSec * (theUsage.ru_stime.tv_usec + theUsage.ru_utime.tv_usec - startCPUTime_.tv_usec);
132  returnValue.real_ = tp.tv_sec - startRealTime_.tv_sec + microsecToSec * (tp.tv_usec - startRealTime_.tv_usec);
133 #endif
134  return returnValue;
135 }

References edm::CPUTimer::Times::cpu_, Exception, edm::CPUTimer::Times::real_, startCPUTime_, startRealTime_, and cmsswSequenceInfo::tp.

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

◆ cpuTime()

double CPUTimer::cpuTime ( ) const

◆ operator=()

CPUTimer& edm::CPUTimer::operator= ( const CPUTimer )
delete

◆ realTime()

double CPUTimer::realTime ( ) const

◆ reset()

void CPUTimer::reset ( void  )

Definition at line 99 of file CPUTimer.cc.

99  {
102 }

References accumulatedCPUTime_, and accumulatedRealTime_.

Referenced by CastorMonitorModule::analyze().

◆ start()

void CPUTimer::start ( )

Definition at line 68 of file CPUTimer.cc.

68  {
69  if (kStopped == state_) {
70 #ifdef USE_CLOCK_GETTIME
71  clock_gettime(CLOCK_MONOTONIC, &startRealTime_);
72  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &startCPUTime_);
73 #else
74  gettimeofday(&startRealTime_, 0);
75 
76  rusage theUsage;
77  if (0 != getrusage(RUSAGE_SELF, &theUsage)) {
78  throw cms::Exception("CPUTimerFailed") << errno;
79  }
80  startCPUTime_.tv_sec = theUsage.ru_stime.tv_sec + theUsage.ru_utime.tv_sec;
81  startCPUTime_.tv_usec = theUsage.ru_stime.tv_usec + theUsage.ru_utime.tv_usec;
82 #endif
83  state_ = kRunning;
84  }
85 }

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

Referenced by progressbar.ProgressBar::__next__(), CastorMonitorModule::analyze(), XrdAdaptor::RequestManager::handle(), edm::service::ResourceEnforcer::ResourceEnforcer(), and edm::SystemTimeKeeper::startProcessingLoop().

◆ stop()

CPUTimer::Times CPUTimer::stop ( )

Definition at line 87 of file CPUTimer.cc.

87  {
88  if (kRunning == state_) {
89  Times t = calculateDeltaTime();
90  accumulatedCPUTime_ += t.cpu_;
91  accumulatedRealTime_ += t.real_;
92 
93  state_ = kStopped;
94  return t;
95  }
96  return Times();
97 }

References accumulatedCPUTime_, accumulatedRealTime_, calculateDeltaTime(), kRunning, kStopped, state_, and submitPVValidationJobs::t.

Referenced by CastorMonitorModule::analyze(), XrdAdaptor::RequestManager::handle(), and edm::SystemTimeKeeper::stopProcessingLoop().

Member Data Documentation

◆ accumulatedCPUTime_

double edm::CPUTimer::accumulatedCPUTime_
private

Definition at line 78 of file CPUTimer.h.

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

◆ accumulatedRealTime_

double edm::CPUTimer::accumulatedRealTime_
private

Definition at line 77 of file CPUTimer.h.

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

◆ startCPUTime_

struct timeval edm::CPUTimer::startCPUTime_
private

Definition at line 74 of file CPUTimer.h.

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

◆ startRealTime_

struct timeval edm::CPUTimer::startRealTime_
private

Definition at line 73 of file CPUTimer.h.

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

◆ state_

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

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

edm::CPUTimer::state_
enum edm::CPUTimer::State state_
edm::CPUTimer::Times::real_
double real_
Definition: CPUTimer.h:47
edm::CPUTimer::startCPUTime_
struct timeval startCPUTime_
Definition: CPUTimer.h:74
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
edm::CPUTimer::kRunning
Definition: CPUTimer.h:68
Exception
Definition: hltDiff.cc:245
edm::CPUTimer::accumulatedCPUTime_
double accumulatedCPUTime_
Definition: CPUTimer.h:78
edm::CPUTimer::Times::cpu_
double cpu_
Definition: CPUTimer.h:48
edm::CPUTimer::kStopped
Definition: CPUTimer.h:68
edm::CPUTimer::startRealTime_
struct timeval startRealTime_
Definition: CPUTimer.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::CPUTimer::accumulatedRealTime_
double accumulatedRealTime_
Definition: CPUTimer.h:77
edm::CPUTimer::calculateDeltaTime
Times calculateDeltaTime() const
Definition: CPUTimer.cc:109