CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
edm::WallclockTimer Class Reference

#include <WallclockTimer.h>

Public Member Functions

void add (double t)
 
WallclockTimeroperator= (const WallclockTimer &)=delete
 
double realTime () const
 
void reset ()
 
void start ()
 
double stop ()
 
 WallclockTimer ()
 
 WallclockTimer (WallclockTimer &&)=default
 
 WallclockTimer (const WallclockTimer &)=delete
 
 ~WallclockTimer ()
 

Private Types

enum  State { kRunning, kStopped }
 

Private Member Functions

double calculateDeltaTime () const
 

Private Attributes

double accumulatedRealTime_
 
struct timeval startRealTime_
 
enum edm::WallclockTimer::State state_
 

Detailed Description

Definition at line 37 of file WallclockTimer.h.

Member Enumeration Documentation

◆ State

Enumerator
kRunning 
kStopped 

Definition at line 61 of file WallclockTimer.h.

Constructor & Destructor Documentation

◆ WallclockTimer() [1/3]

WallclockTimer::WallclockTimer ( )

Definition at line 33 of file WallclockTimer.cc.

References startRealTime_.

34 #ifdef USE_CLOCK_GETTIME
35  startRealTime_.tv_sec = 0;
36  startRealTime_.tv_nsec = 0;
37 #else
38  startRealTime_.tv_sec = 0;
39  startRealTime_.tv_usec = 0;
40 #endif
41 }
enum edm::WallclockTimer::State state_
struct timeval startRealTime_

◆ ~WallclockTimer()

WallclockTimer::~WallclockTimer ( )

Definition at line 47 of file WallclockTimer.cc.

47 {}

◆ WallclockTimer() [2/3]

edm::WallclockTimer::WallclockTimer ( WallclockTimer &&  )
default

◆ WallclockTimer() [3/3]

edm::WallclockTimer::WallclockTimer ( const WallclockTimer )
delete

Member Function Documentation

◆ add()

void WallclockTimer::add ( double  t)

◆ calculateDeltaTime()

double WallclockTimer::calculateDeltaTime ( ) const
private

Definition at line 89 of file WallclockTimer.cc.

References startRealTime_, and cmsswSequenceInfo::tp.

Referenced by realTime(), and stop().

89  {
90  double returnValue;
91 #ifdef USE_CLOCK_GETTIME
92  double const nanosecToSec = 1E-9;
93  struct timespec tp;
94 
95  clock_gettime(CLOCK_MONOTONIC, &tp);
96  returnValue = tp.tv_sec - startRealTime_.tv_sec + nanosecToSec * (tp.tv_nsec - startRealTime_.tv_nsec);
97 #else
98  double const microsecToSec = 1E-6;
99 
100  struct timeval tp;
101  gettimeofday(&tp, 0);
102 
103  returnValue = tp.tv_sec - startRealTime_.tv_sec + microsecToSec * (tp.tv_usec - startRealTime_.tv_usec);
104 #endif
105  return returnValue;
106 }
struct timeval startRealTime_

◆ operator=()

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

◆ realTime()

double WallclockTimer::realTime ( ) const

Definition at line 110 of file WallclockTimer.cc.

References accumulatedRealTime_, calculateDeltaTime(), kStopped, and state_.

110  {
111  if (kStopped == state_) {
112  return accumulatedRealTime_;
113  }
115 }
enum edm::WallclockTimer::State state_
double calculateDeltaTime() const

◆ reset()

void WallclockTimer::reset ( void  )

Definition at line 85 of file WallclockTimer.cc.

References accumulatedRealTime_.

85 { accumulatedRealTime_ = 0; }

◆ start()

void WallclockTimer::start ( )

Definition at line 63 of file WallclockTimer.cc.

References kRunning, kStopped, startRealTime_, and state_.

Referenced by progressbar.ProgressBar::__next__().

63  {
64  if (kStopped == state_) {
65 #ifdef USE_CLOCK_GETTIME
66  clock_gettime(CLOCK_MONOTONIC, &startRealTime_);
67 #else
68  gettimeofday(&startRealTime_, 0);
69 #endif
70  state_ = kRunning;
71  }
72 }
enum edm::WallclockTimer::State state_
struct timeval startRealTime_

◆ stop()

double WallclockTimer::stop ( )

Definition at line 74 of file WallclockTimer.cc.

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

74  {
75  if (kRunning == state_) {
76  auto t = calculateDeltaTime();
78 
79  state_ = kStopped;
80  return t;
81  }
82  return 0.;
83 }
enum edm::WallclockTimer::State state_
double calculateDeltaTime() const

Member Data Documentation

◆ accumulatedRealTime_

double edm::WallclockTimer::accumulatedRealTime_
private

Definition at line 68 of file WallclockTimer.h.

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

◆ startRealTime_

struct timeval edm::WallclockTimer::startRealTime_
private

Definition at line 65 of file WallclockTimer.h.

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

◆ state_

enum edm::WallclockTimer::State edm::WallclockTimer::state_
private

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