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

Private Types

enum  State { kRunning, kStopped }
 

Private Member Functions

double calculateDeltaTime () const
 
const WallclockTimeroperator= (const WallclockTimer &)=delete
 
 WallclockTimer (const WallclockTimer &)=delete
 

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 63 of file WallclockTimer.h.

Constructor & Destructor Documentation

◆ WallclockTimer() [1/3]

WallclockTimer::WallclockTimer ( )

Definition at line 33 of file WallclockTimer.cc.

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 }

References 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 )
privatedelete

Member Function Documentation

◆ add()

void WallclockTimer::add ( double  t)

Definition at line 87 of file WallclockTimer.cc.

87 { accumulatedRealTime_ += t; }

References accumulatedRealTime_, and OrderedSet::t.

Referenced by counter.Counter::register().

◆ calculateDeltaTime()

double WallclockTimer::calculateDeltaTime ( ) const
private

Definition at line 89 of file WallclockTimer.cc.

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 }

References startRealTime_, and cmsswSequenceInfo::tp.

Referenced by realTime(), and stop().

◆ operator=()

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

◆ realTime()

double WallclockTimer::realTime ( ) const

Definition at line 110 of file WallclockTimer.cc.

110  {
111  if (kStopped == state_) {
112  return accumulatedRealTime_;
113  }
115 }

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

◆ reset()

void WallclockTimer::reset ( void  )

Definition at line 85 of file WallclockTimer.cc.

85 { accumulatedRealTime_ = 0; }

References accumulatedRealTime_.

◆ start()

void WallclockTimer::start ( )

Definition at line 63 of file WallclockTimer.cc.

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 }

References kRunning, kStopped, startRealTime_, and state_.

Referenced by progressbar.ProgressBar::__next__().

◆ stop()

double WallclockTimer::stop ( )

Definition at line 74 of file WallclockTimer.cc.

74  {
75  if (kRunning == state_) {
76  auto t = calculateDeltaTime();
78 
79  state_ = kStopped;
80  return t;
81  }
82  return 0.;
83 }

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

Member Data Documentation

◆ accumulatedRealTime_

double edm::WallclockTimer::accumulatedRealTime_
private

Definition at line 70 of file WallclockTimer.h.

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

◆ startRealTime_

struct timeval edm::WallclockTimer::startRealTime_
private

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

edm::WallclockTimer::kStopped
Definition: WallclockTimer.h:63
OrderedSet.t
t
Definition: OrderedSet.py:90
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
edm::WallclockTimer::kRunning
Definition: WallclockTimer.h:63
edm::WallclockTimer::accumulatedRealTime_
double accumulatedRealTime_
Definition: WallclockTimer.h:70
edm::WallclockTimer::startRealTime_
struct timeval startRealTime_
Definition: WallclockTimer.h:67
edm::WallclockTimer::state_
enum edm::WallclockTimer::State state_
edm::WallclockTimer::calculateDeltaTime
double calculateDeltaTime() const
Definition: WallclockTimer.cc:89