KiCad PCB EDA Suite
Loading...
Searching...
No Matches
SCOPED_PROF_TIMER< DURATION > Class Template Reference

A simple RAII class to measure the time of an operation. More...

#include <profile.h>

Inheritance diagram for SCOPED_PROF_TIMER< DURATION >:
PROF_TIMER

Public Member Functions

 SCOPED_PROF_TIMER (DURATION &aDuration)
 
 ~SCOPED_PROF_TIMER ()
 
void Start ()
 Start or restart the counter. More...
 
void Stop ()
 Save the time when this function was called, and set the counter stane to stop. More...
 
void Show (std::ostream &aStream=std::cerr)
 Print the elapsed time (in a suitable unit) to a stream. More...
 
template<typename DURATION >
DURATION SinceStart (bool aSinceLast=false)
 
double msecs (bool aSinceLast=false)
 
std::string to_string ()
 

Private Types

using CLOCK = std::chrono::high_resolution_clock
 
using TIME_POINT = std::chrono::time_point< CLOCK >
 

Private Attributes

PROF_TIMER m_counter
 < The counter to use to do the profiling More...
 
DURATION & m_duration
 
std::string m_name
 
bool m_running
 
TIME_POINT m_starttime
 
TIME_POINT m_lasttime
 
TIME_POINT m_stoptime
 

Detailed Description

template<typename DURATION>
class SCOPED_PROF_TIMER< DURATION >

A simple RAII class to measure the time of an operation.

On construction, a timer is started, and on destruction, the timer is ended, and the time difference is written into the given duration.

For example:

DURATION duration; // select a duration type as needed { SCOPED_PROF_TIMER<DURATION> timer( duration ); timed_activity(); } // duration is now the time timed activity took

From C++17, with class template argument deduction, you should be able to omit the <DURATION>.

Definition at line 191 of file profile.h.

Member Typedef Documentation

◆ CLOCK

using PROF_TIMER::CLOCK = std::chrono::high_resolution_clock
privateinherited

Definition at line 165 of file profile.h.

◆ TIME_POINT

using PROF_TIMER::TIME_POINT = std::chrono::time_point<CLOCK>
privateinherited

Definition at line 166 of file profile.h.

Constructor & Destructor Documentation

◆ SCOPED_PROF_TIMER()

template<typename DURATION >
SCOPED_PROF_TIMER< DURATION >::SCOPED_PROF_TIMER ( DURATION &  aDuration)
inline

Definition at line 194 of file profile.h.

◆ ~SCOPED_PROF_TIMER()

template<typename DURATION >
SCOPED_PROF_TIMER< DURATION >::~SCOPED_PROF_TIMER ( )
inline

Member Function Documentation

◆ msecs()

◆ Show()

void PROF_TIMER::Show ( std::ostream &  aStream = std::cerr)
inlineinherited

Print the elapsed time (in a suitable unit) to a stream.

The unit is automatically chosen from ns, us, ms and s, depending on the size of the current count.

Parameters
thestream to print to.

Definition at line 104 of file profile.h.

References PROF_TIMER::m_name.

Referenced by CONNECTION_GRAPH::buildConnectionGraph(), RES_EQUIV_CALC::Calculate(), RN_NET::compute(), SCH_EDIT_FRAME::OpenProjectFiles(), CN_CONNECTIVITY_ALGO::searchConnections(), PCB_TEST_FRAME_BASE::SetBoard(), SCH_SCREEN::TestDanglingEnds(), and CONNECTIVITY_DATA::updateRatsnest().

◆ SinceStart()

template<typename DURATION >
DURATION PROF_TIMER::SinceStart ( bool  aSinceLast = false)
inlineinherited
Returns
the time since the timer was started. If the timer is stopped, the duration is from the start time to the time it was stopped, else it is to the current time.

Definition at line 134 of file profile.h.

References PROF_TIMER::m_lasttime, PROF_TIMER::m_running, PROF_TIMER::m_starttime, and PROF_TIMER::m_stoptime.

Referenced by parse(), and SCOPED_PROF_TIMER< DURATION >::~SCOPED_PROF_TIMER().

◆ Start()

void PROF_TIMER::Start ( )
inlineinherited

◆ Stop()

◆ to_string()

std::string PROF_TIMER::to_string ( )
inlineinherited

Member Data Documentation

◆ m_counter

template<typename DURATION >
PROF_TIMER SCOPED_PROF_TIMER< DURATION >::m_counter
private

< The counter to use to do the profiling

The duration to update at the end of the scope

Definition at line 206 of file profile.h.

Referenced by SCOPED_PROF_TIMER< DURATION >::~SCOPED_PROF_TIMER().

◆ m_duration

template<typename DURATION >
DURATION& SCOPED_PROF_TIMER< DURATION >::m_duration
private

Definition at line 209 of file profile.h.

Referenced by SCOPED_PROF_TIMER< DURATION >::~SCOPED_PROF_TIMER().

◆ m_lasttime

TIME_POINT PROF_TIMER::m_lasttime
privateinherited

Definition at line 168 of file profile.h.

Referenced by PROF_TIMER::SinceStart(), and PROF_TIMER::Start().

◆ m_name

std::string PROF_TIMER::m_name
privateinherited

Definition at line 162 of file profile.h.

Referenced by PROF_TIMER::Show(), and PROF_TIMER::to_string().

◆ m_running

bool PROF_TIMER::m_running
privateinherited

Definition at line 163 of file profile.h.

Referenced by PROF_TIMER::SinceStart(), PROF_TIMER::Start(), and PROF_TIMER::Stop().

◆ m_starttime

TIME_POINT PROF_TIMER::m_starttime
privateinherited

Definition at line 168 of file profile.h.

Referenced by PROF_TIMER::SinceStart(), and PROF_TIMER::Start().

◆ m_stoptime

TIME_POINT PROF_TIMER::m_stoptime
privateinherited

Definition at line 168 of file profile.h.

Referenced by PROF_TIMER::SinceStart(), and PROF_TIMER::Stop().


The documentation for this class was generated from the following file: