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

Private Types

enum  State { kRunning, kStopped }
 

Private Member Functions

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

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

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

Definition at line 70 of file CPUTimer.h.

Constructor & Destructor Documentation

CPUTimer::CPUTimer ( )

Definition at line 33 of file CPUTimer.cc.

References startCPUTime_, and startRealTime_.

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 }
enum edm::CPUTimer::State state_
struct timeval startCPUTime_
Definition: CPUTimer.h:76
struct timeval startRealTime_
Definition: CPUTimer.h:75
double accumulatedCPUTime_
Definition: CPUTimer.h:80
double accumulatedRealTime_
Definition: CPUTimer.h:79
CPUTimer::~CPUTimer ( )

Definition at line 52 of file CPUTimer.cc.

52 {}
edm::CPUTimer::CPUTimer ( CPUTimer &&  )
default
edm::CPUTimer::CPUTimer ( const CPUTimer )
privatedelete

Member Function Documentation

void CPUTimer::add ( const Times t)

Definition at line 104 of file CPUTimer.cc.

References accumulatedCPUTime_, accumulatedRealTime_, edm::CPUTimer::Times::cpu_, and edm::CPUTimer::Times::real_.

Referenced by counter.Counter::register().

104  {
105  accumulatedCPUTime_ += t.cpu_;
106  accumulatedRealTime_ += t.real_;
107 }
double accumulatedCPUTime_
Definition: CPUTimer.h:80
double accumulatedRealTime_
Definition: CPUTimer.h:79
CPUTimer::Times CPUTimer::calculateDeltaTime ( ) const
private

Definition at line 109 of file CPUTimer.cc.

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

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

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 }
struct timeval startCPUTime_
Definition: CPUTimer.h:76
struct timeval startRealTime_
Definition: CPUTimer.h:75
double CPUTimer::cpuTime ( ) const

Definition at line 146 of file CPUTimer.cc.

References accumulatedCPUTime_, calculateDeltaTime(), edm::CPUTimer::Times::cpu_, kStopped, and state_.

Referenced by edm::SystemTimeKeeper::fillTriggerTimingReport().

146  {
147  if (kStopped == state_) {
148  return accumulatedCPUTime_;
149  }
151 }
enum edm::CPUTimer::State state_
double accumulatedCPUTime_
Definition: CPUTimer.h:80
Times calculateDeltaTime() const
Definition: CPUTimer.cc:109
const CPUTimer& edm::CPUTimer::operator= ( const CPUTimer )
privatedelete
double CPUTimer::realTime ( ) const

Definition at line 139 of file CPUTimer.cc.

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

Referenced by edm::service::ResourceEnforcer::check(), and edm::SystemTimeKeeper::fillTriggerTimingReport().

139  {
140  if (kStopped == state_) {
141  return accumulatedRealTime_;
142  }
144 }
enum edm::CPUTimer::State state_
double accumulatedRealTime_
Definition: CPUTimer.h:79
Times calculateDeltaTime() const
Definition: CPUTimer.cc:109
void CPUTimer::reset ( void  )

Definition at line 99 of file CPUTimer.cc.

References accumulatedCPUTime_, and accumulatedRealTime_.

99  {
102 }
double accumulatedCPUTime_
Definition: CPUTimer.h:80
double accumulatedRealTime_
Definition: CPUTimer.h:79
void CPUTimer::start ( )

Definition at line 68 of file CPUTimer.cc.

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

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

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 }
enum edm::CPUTimer::State state_
struct timeval startCPUTime_
Definition: CPUTimer.h:76
struct timeval startRealTime_
Definition: CPUTimer.h:75
CPUTimer::Times CPUTimer::stop ( )

Definition at line 87 of file CPUTimer.cc.

References accumulatedCPUTime_, accumulatedRealTime_, calculateDeltaTime(), edm::CPUTimer::Times::cpu_, kRunning, kStopped, edm::CPUTimer::Times::real_, state_, and lumiQTWidget::t.

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

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 }
enum edm::CPUTimer::State state_
double accumulatedCPUTime_
Definition: CPUTimer.h:80
double accumulatedRealTime_
Definition: CPUTimer.h:79
Times calculateDeltaTime() const
Definition: CPUTimer.cc:109

Member Data Documentation

double edm::CPUTimer::accumulatedCPUTime_
private

Definition at line 80 of file CPUTimer.h.

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

double edm::CPUTimer::accumulatedRealTime_
private

Definition at line 79 of file CPUTimer.h.

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

struct timeval edm::CPUTimer::startCPUTime_
private

Definition at line 76 of file CPUTimer.h.

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

struct timeval edm::CPUTimer::startRealTime_
private

Definition at line 75 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().