CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
FastTimer Class Reference

#include <FastTimer.h>

Public Types

typedef
std::chrono::high_resolution_clock 
Clock
 
typedef std::chrono::nanoseconds Duration
 
enum  State { State::kStopped, State::kRunning, State::kPaused }
 

Public Member Functions

 FastTimer ()
 
Clock::time_point const & getStartTime () const
 
Clock::time_point const & getStopTime () const
 
void pause ()
 
void reset ()
 
void resume ()
 
double seconds () const
 
double secondsUntilNow () const
 
void setStartTime (Clock::time_point const &)
 
void setStopTime (Clock::time_point const &)
 
void start ()
 
State state () const
 
void stop ()
 
Duration untilNow () const
 
Duration value () const
 

Private Member Functions

std::string const & describe () const
 

Private Attributes

Duration m_duration
 
Clock::time_point m_start
 
State m_state
 
Clock::time_point m_stop
 

Detailed Description

Definition at line 7 of file FastTimer.h.

Member Typedef Documentation

typedef std::chrono::high_resolution_clock FastTimer::Clock

Definition at line 9 of file FastTimer.h.

typedef std::chrono::nanoseconds FastTimer::Duration

Definition at line 10 of file FastTimer.h.

Member Enumeration Documentation

enum FastTimer::State
strong
Enumerator
kStopped 
kRunning 
kPaused 

Definition at line 11 of file FastTimer.h.

11  {
12  kStopped,
13  kRunning,
14  kPaused
15  };

Constructor & Destructor Documentation

FastTimer::FastTimer ( )

Definition at line 9 of file FastTimer.cc.

9  :
10  m_start(),
11  m_stop(),
12  m_duration(Duration::zero()),
14 { }
Duration m_duration
Definition: FastTimer.h:40
Clock::time_point m_stop
Definition: FastTimer.h:39
Clock::time_point m_start
Definition: FastTimer.h:38
State m_state
Definition: FastTimer.h:41

Member Function Documentation

std::string const & FastTimer::describe ( ) const
private

Definition at line 95 of file FastTimer.cc.

References kPaused, kRunning, kStopped, and m_state.

Referenced by pause(), resume(), setStartTime(), setStopTime(), start(), and stop().

95  {
96  static const std::vector<std::string> states{ "stopped", "running", "paused", "unknown" };
97 
98  switch (m_state) {
102  return states[static_cast<unsigned int>(m_state)];
103 
104  default:
105  return states.back();
106  }
107 }
State m_state
Definition: FastTimer.h:41
FastTimer::Clock::time_point const & FastTimer::getStartTime ( ) const

Definition at line 109 of file FastTimer.cc.

References m_start.

109  {
110  return m_start;
111 }
Clock::time_point m_start
Definition: FastTimer.h:38
FastTimer::Clock::time_point const & FastTimer::getStopTime ( ) const

Definition at line 113 of file FastTimer.cc.

References m_stop.

113  {
114  return m_stop;
115 }
Clock::time_point m_stop
Definition: FastTimer.h:39
void FastTimer::pause ( )

Definition at line 40 of file FastTimer.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, describe(), kPaused, kRunning, m_duration, m_start, m_state, m_stop, and fileCollector::now.

Referenced by FastTimerService::preModuleEventDelayedGet().

40  {
41  if (m_state == State::kRunning) {
42  m_stop = Clock::now();
43  m_duration += std::chrono::duration_cast<Duration>(m_stop - m_start);
45  } else {
46  std::cerr << "attempting to pause a " << describe() << " timer" << std::endl;
47  }
48 }
Duration m_duration
Definition: FastTimer.h:40
Clock::time_point m_stop
Definition: FastTimer.h:39
Clock::time_point m_start
Definition: FastTimer.h:38
State m_state
Definition: FastTimer.h:41
std::string const & describe() const
Definition: FastTimer.cc:95
std::chrono::nanoseconds Duration
Definition: FastTimer.h:10
void FastTimer::reset ( void  )

Definition at line 62 of file FastTimer.cc.

References kStopped, m_duration, m_start, m_state, and m_stop.

Referenced by FastTimerService::ModuleInfo::reset(), FastTimerService::PathInfo::reset(), and FastTimerService::StreamData::reset().

62  {
63  m_start = Clock::time_point();
64  m_stop = Clock::time_point();
65  m_duration = Duration::zero();
67 }
Duration m_duration
Definition: FastTimer.h:40
Clock::time_point m_stop
Definition: FastTimer.h:39
Clock::time_point m_start
Definition: FastTimer.h:38
State m_state
Definition: FastTimer.h:41
void FastTimer::resume ( )

Definition at line 51 of file FastTimer.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, describe(), kPaused, kRunning, m_start, m_state, m_stop, and fileCollector::now.

Referenced by FastTimerService::postModuleEventDelayedGet().

51  {
52  if (m_state == State::kPaused) {
53  m_start = Clock::now();
54  m_stop = Clock::time_point();
56  } else {
57  std::cerr << "attempting to resume a " << describe() << " timer" << std::endl;
58  }
59 }
Clock::time_point m_stop
Definition: FastTimer.h:39
Clock::time_point m_start
Definition: FastTimer.h:38
State m_state
Definition: FastTimer.h:41
std::string const & describe() const
Definition: FastTimer.cc:95
double FastTimer::seconds ( ) const

Definition at line 75 of file FastTimer.cc.

References KineDebug3::count(), and m_duration.

Referenced by FastTimerService::postModuleEvent().

75  {
76  return std::chrono::duration_cast<std::chrono::duration<double>>(m_duration).count();
77 }
Duration m_duration
Definition: FastTimer.h:40
double FastTimer::secondsUntilNow ( ) const

Definition at line 85 of file FastTimer.cc.

References KineDebug3::count(), and untilNow().

85  {
86  return std::chrono::duration_cast<std::chrono::duration<double>>(untilNow()).count();
87 }
Duration untilNow() const
Definition: FastTimer.cc:81
void FastTimer::setStartTime ( Clock::time_point const &  )

Definition at line 117 of file FastTimer.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, describe(), kRunning, kStopped, m_duration, m_start, m_state, and m_stop.

117  {
118  if (m_state == State::kStopped) {
119  m_start = time;
120  m_stop = Clock::time_point();
121  m_duration = Duration::zero();
123  } else {
124  std::cerr << "attempting to start a " << describe() << " timer" << std::endl;
125  }
126 }
Duration m_duration
Definition: FastTimer.h:40
Clock::time_point m_stop
Definition: FastTimer.h:39
Clock::time_point m_start
Definition: FastTimer.h:38
State m_state
Definition: FastTimer.h:41
std::string const & describe() const
Definition: FastTimer.cc:95
void FastTimer::setStopTime ( Clock::time_point const &  )

Definition at line 128 of file FastTimer.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, describe(), kRunning, kStopped, m_duration, m_start, m_state, and m_stop.

128  {
129  if (m_state == State::kRunning) {
130  m_stop = time;
131  m_duration += std::chrono::duration_cast<Duration>(m_stop - m_start);
133  } else {
134  std::cerr << "attempting to stop a " << describe() << " timer" << std::endl;
135  }
136 }
Duration m_duration
Definition: FastTimer.h:40
Clock::time_point m_stop
Definition: FastTimer.h:39
Clock::time_point m_start
Definition: FastTimer.h:38
State m_state
Definition: FastTimer.h:41
std::string const & describe() const
Definition: FastTimer.cc:95
std::chrono::nanoseconds Duration
Definition: FastTimer.h:10
void FastTimer::start ( void  )

Definition at line 17 of file FastTimer.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, describe(), kRunning, kStopped, m_duration, m_start, m_state, m_stop, and fileCollector::now.

Referenced by progressbar.ProgressBar::__next__(), and FastTimerService::preModuleEvent().

17  {
18  if (m_state == State::kStopped) {
19  m_start = Clock::now();
20  m_stop = Clock::time_point();
21  m_duration = Duration::zero();
23  } else {
24  std::cerr << "attempting to start a " << describe() << " timer" << std::endl;
25  }
26 }
Duration m_duration
Definition: FastTimer.h:40
Clock::time_point m_stop
Definition: FastTimer.h:39
Clock::time_point m_start
Definition: FastTimer.h:38
State m_state
Definition: FastTimer.h:41
std::string const & describe() const
Definition: FastTimer.cc:95
FastTimer::State FastTimer::state ( ) const

Definition at line 90 of file FastTimer.cc.

References m_state.

90  {
91  return m_state;
92 }
State m_state
Definition: FastTimer.h:41
void FastTimer::stop ( )

Definition at line 29 of file FastTimer.cc.

References ecal_dqm_sourceclient-live_cfg::cerr, describe(), kRunning, kStopped, m_duration, m_start, m_state, m_stop, and fileCollector::now.

Referenced by FastTimerService::postModuleEvent().

29  {
30  if (m_state == State::kRunning) {
31  m_stop = Clock::now();
32  m_duration += std::chrono::duration_cast<Duration>(m_stop - m_start);
34  } else {
35  std::cerr << "attempting to stop a " << describe() << " timer" << std::endl;
36  }
37 }
Duration m_duration
Definition: FastTimer.h:40
Clock::time_point m_stop
Definition: FastTimer.h:39
Clock::time_point m_start
Definition: FastTimer.h:38
State m_state
Definition: FastTimer.h:41
std::string const & describe() const
Definition: FastTimer.cc:95
std::chrono::nanoseconds Duration
Definition: FastTimer.h:10
FastTimer::Duration FastTimer::untilNow ( ) const

Definition at line 81 of file FastTimer.cc.

References kRunning, m_duration, m_start, m_state, and fileCollector::now.

Referenced by secondsUntilNow().

81  {
82  return m_duration + ( (m_state == State::kRunning) ? std::chrono::duration_cast<Duration>(Clock::now() - m_start) : Duration::zero() );
83 }
Duration m_duration
Definition: FastTimer.h:40
Clock::time_point m_start
Definition: FastTimer.h:38
State m_state
Definition: FastTimer.h:41
FastTimer::Duration FastTimer::value ( void  ) const

Definition at line 70 of file FastTimer.cc.

References m_duration.

Referenced by average.Average::average().

70  {
71  return m_duration;
72 }
Duration m_duration
Definition: FastTimer.h:40

Member Data Documentation

Duration FastTimer::m_duration
private

Definition at line 40 of file FastTimer.h.

Referenced by pause(), reset(), seconds(), setStartTime(), setStopTime(), start(), stop(), untilNow(), and value().

Clock::time_point FastTimer::m_start
private

Definition at line 38 of file FastTimer.h.

Referenced by getStartTime(), pause(), reset(), resume(), setStartTime(), setStopTime(), start(), stop(), and untilNow().

State FastTimer::m_state
private

Definition at line 41 of file FastTimer.h.

Referenced by describe(), pause(), reset(), resume(), setStartTime(), setStopTime(), start(), state(), stop(), and untilNow().

Clock::time_point FastTimer::m_stop
private

Definition at line 39 of file FastTimer.h.

Referenced by getStopTime(), pause(), reset(), resume(), setStartTime(), setStopTime(), start(), and stop().