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 72 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:78
struct timeval startRealTime_
Definition: CPUTimer.h:77
double accumulatedCPUTime_
Definition: CPUTimer.h:82
double accumulatedRealTime_
Definition: CPUTimer.h:81
CPUTimer::~CPUTimer ( )

Definition at line 56 of file CPUTimer.cc.

56  {
57 }
edm::CPUTimer::CPUTimer ( CPUTimer &&  )
default
edm::CPUTimer::CPUTimer ( const CPUTimer )
privatedelete

Member Function Documentation

void CPUTimer::add ( const Times t)

Definition at line 113 of file CPUTimer.cc.

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

Referenced by counter.Counter::register().

113  {
114  accumulatedCPUTime_ += t.cpu_;
115  accumulatedRealTime_ += t.real_;
116 }
double accumulatedCPUTime_
Definition: CPUTimer.h:82
double accumulatedRealTime_
Definition: CPUTimer.h:81
CPUTimer::Times CPUTimer::calculateDeltaTime ( ) const
private

Definition at line 119 of file CPUTimer.cc.

References CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, edm::CPUTimer::Times::cpu_, 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_MONOTONIC, &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 }
#define CLOCK_MONOTONIC
Definition: TimerService.h:33
struct timeval startCPUTime_
Definition: CPUTimer.h:78
struct timeval startRealTime_
Definition: CPUTimer.h:77
#define CLOCK_PROCESS_CPUTIME_ID
Definition: TimerService.h:34
double CPUTimer::cpuTime ( ) const

Definition at line 158 of file CPUTimer.cc.

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

Referenced by CastorMonitorModule::analyze(), and edm::SystemTimeKeeper::fillTriggerTimingReport().

158  {
159  if(kStopped == state_) {
160  return accumulatedCPUTime_;
161  }
163 }
enum edm::CPUTimer::State state_
double accumulatedCPUTime_
Definition: CPUTimer.h:82
Times calculateDeltaTime() const
Definition: CPUTimer.cc:119
const CPUTimer& edm::CPUTimer::operator= ( const CPUTimer )
privatedelete
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::SystemTimeKeeper::fillTriggerTimingReport().

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

Definition at line 107 of file CPUTimer.cc.

References accumulatedCPUTime_, and accumulatedRealTime_.

Referenced by CastorMonitorModule::analyze().

107  {
110 }
double accumulatedCPUTime_
Definition: CPUTimer.h:82
double accumulatedRealTime_
Definition: CPUTimer.h:81
void CPUTimer::start ( void  )

Definition at line 74 of file CPUTimer.cc.

References CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, 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().

74  {
75  if(kStopped == state_) {
76 #ifdef USE_CLOCK_GETTIME
77  clock_gettime(CLOCK_MONOTONIC, &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 }
#define CLOCK_MONOTONIC
Definition: TimerService.h:33
enum edm::CPUTimer::State state_
struct timeval startCPUTime_
Definition: CPUTimer.h:78
struct timeval startRealTime_
Definition: CPUTimer.h:77
#define CLOCK_PROCESS_CPUTIME_ID
Definition: TimerService.h:34
CPUTimer::Times CPUTimer::stop ( )

Definition at line 94 of file CPUTimer.cc.

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

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

94  {
95  if(kRunning == state_) {
96  Times t = calculateDeltaTime();
97  accumulatedCPUTime_ += t.cpu_;
98  accumulatedRealTime_ += t.real_;
99 
101  return t;
102  }
103  return Times();
104 }
enum edm::CPUTimer::State state_
double accumulatedCPUTime_
Definition: CPUTimer.h:82
double accumulatedRealTime_
Definition: CPUTimer.h:81
Times calculateDeltaTime() const
Definition: CPUTimer.cc:119

Member Data Documentation

double edm::CPUTimer::accumulatedCPUTime_
private

Definition at line 82 of file CPUTimer.h.

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

double edm::CPUTimer::accumulatedRealTime_
private

Definition at line 81 of file CPUTimer.h.

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

struct timeval edm::CPUTimer::startCPUTime_
private

Definition at line 78 of file CPUTimer.h.

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

struct timeval edm::CPUTimer::startRealTime_
private

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