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

Enumerator
kRunning 
kStopped 

Definition at line 63 of file WallclockTimer.h.

Constructor & Destructor Documentation

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 ( )

Definition at line 47 of file WallclockTimer.cc.

47 {}
edm::WallclockTimer::WallclockTimer ( WallclockTimer &&  )
default
edm::WallclockTimer::WallclockTimer ( const WallclockTimer )
privatedelete

Member Function Documentation

void WallclockTimer::add ( double  t)

Definition at line 87 of file WallclockTimer.cc.

References accumulatedRealTime_, and OrderedSet::t.

Referenced by counter.Counter::register().

double WallclockTimer::calculateDeltaTime ( ) const
private

Definition at line 89 of file WallclockTimer.cc.

References startRealTime_.

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_
const WallclockTimer& edm::WallclockTimer::operator= ( const WallclockTimer )
privatedelete
double WallclockTimer::realTime ( ) const

Definition at line 110 of file WallclockTimer.cc.

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

Referenced by fillPathSummary().

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

Definition at line 85 of file WallclockTimer.cc.

References accumulatedRealTime_.

85 { accumulatedRealTime_ = 0; }
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_
double WallclockTimer::stop ( )

Definition at line 74 of file WallclockTimer.cc.

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

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

Member Data Documentation

double edm::WallclockTimer::accumulatedRealTime_
private

Definition at line 70 of file WallclockTimer.h.

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

struct timeval edm::WallclockTimer::startRealTime_
private

Definition at line 67 of file WallclockTimer.h.

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

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

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