The Gaudi Framework  master (594c33fa)
Gaudi::Timers::GenericTimer< Clock, Unit >::ScopeTimer Class Reference

A scoped timer that starts/stops on con/de-struction. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/Gaudi/Timers/GenericTimer.h>

Collaboration diagram for Gaudi::Timers::GenericTimer< Clock, Unit >::ScopeTimer:

Public Member Functions

 ScopeTimer (Stats_t &stat)
 Start Scoped timer accumulating into stat. More...
 
 ~ScopeTimer ()
 Destructor stopping timer. More...
 
auto elapsed () const
 Return the elapsed time without stopping the timer. More...
 

Private Member Functions

void stop () const
 Stop the timer, accumulate elapsed time and return current measurement. More...
 

Private Attributes

Stats_tm_stats
 reference to statistics counter More...
 
Clock::time_point m_t0
 start time of timer More...
 

Detailed Description

template<typename Clock, typename Unit>
class Gaudi::Timers::GenericTimer< Clock, Unit >::ScopeTimer

A scoped timer that starts/stops on con/de-struction.

Definition at line 51 of file GenericTimer.h.

Constructor & Destructor Documentation

◆ ScopeTimer()

template<typename Clock , typename Unit >
Gaudi::Timers::GenericTimer< Clock, Unit >::ScopeTimer::ScopeTimer ( Stats_t stat)
inline

Start Scoped timer accumulating into stat.

Definition at line 54 of file GenericTimer.h.

54 : m_stats( stat ), m_t0( Clock::now() ) {}

◆ ~ScopeTimer()

template<typename Clock , typename Unit >
Gaudi::Timers::GenericTimer< Clock, Unit >::ScopeTimer::~ScopeTimer ( )
inline

Destructor stopping timer.

Definition at line 57 of file GenericTimer.h.

57 { stop(); }

Member Function Documentation

◆ elapsed()

template<typename Clock , typename Unit >
auto Gaudi::Timers::GenericTimer< Clock, Unit >::ScopeTimer::elapsed ( ) const
inline

Return the elapsed time without stopping the timer.

Returns
std::chrono::duration<Unit>

Definition at line 61 of file GenericTimer.h.

61  {
62  // Fenced according to https://codereview.stackexchange.com/q/196245
63  std::atomic_thread_fence( std::memory_order_relaxed );
64  auto dt = Clock::now() - m_t0;
65  std::atomic_thread_fence( std::memory_order_relaxed );
66  return std::chrono::duration_cast<Unit>( dt );
67  }

◆ stop()

template<typename Clock , typename Unit >
void Gaudi::Timers::GenericTimer< Clock, Unit >::ScopeTimer::stop ( ) const
inlineprivate

Stop the timer, accumulate elapsed time and return current measurement.

Definition at line 71 of file GenericTimer.h.

71 { m_stats += elapsed(); }

Member Data Documentation

◆ m_stats

template<typename Clock , typename Unit >
Stats_t& Gaudi::Timers::GenericTimer< Clock, Unit >::ScopeTimer::m_stats
private

reference to statistics counter

Definition at line 73 of file GenericTimer.h.

◆ m_t0

template<typename Clock , typename Unit >
Clock::time_point Gaudi::Timers::GenericTimer< Clock, Unit >::ScopeTimer::m_t0
private

start time of timer

Definition at line 74 of file GenericTimer.h.


The documentation for this class was generated from the following file:
Gaudi::Timers::GenericTimer::ScopeTimer::m_t0
Clock::time_point m_t0
start time of timer
Definition: GenericTimer.h:74
Gaudi::Timers::GenericTimer::ScopeTimer::stop
void stop() const
Stop the timer, accumulate elapsed time and return current measurement.
Definition: GenericTimer.h:71
Gaudi::Timers::GenericTimer::ScopeTimer::m_stats
Stats_t & m_stats
reference to statistics counter
Definition: GenericTimer.h:73
Gaudi::Timers::GenericTimer::ScopeTimer::elapsed
auto elapsed() const
Return the elapsed time without stopping the timer.
Definition: GenericTimer.h:61
std::atomic_thread_fence
T atomic_thread_fence(T... args)