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.
 
void Stop ()
 Save the time when this function was called, and set the counter stane to stop.
 
void Show (std::ostream &aStream=std::cerr)
 Print the elapsed time (in a suitable unit) to a stream.
 
template<typename DURATION>
DURATION SinceStart (bool aSinceLast=false)
 
double msecs (bool aSinceLast=false)
 
std::string to_string ()
 
const std::string & GetName () const
 

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
 
DURATION & m_duration
 
std::string m_name
 
bool m_running
 
bool m_started
 
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 223 of file profile.h.

Member Typedef Documentation

◆ CLOCK

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

Definition at line 197 of file profile.h.

◆ TIME_POINT

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

Definition at line 198 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 226 of file profile.h.

References m_duration, and PROF_TIMER::PROF_TIMER().

◆ ~SCOPED_PROF_TIMER()

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

Definition at line 230 of file profile.h.

References m_counter, and m_duration.

Member Function Documentation

◆ GetName()

const std::string & PROF_TIMER::GetName ( ) const
inlineinherited

Definition at line 190 of file profile.h.

References m_name.

Referenced by LATENCY_PROBE::AddTimer().

◆ 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 107 of file profile.h.

References m_name, and SinceStart().

Referenced by CONNECTION_GRAPH::buildConnectionGraph(), RES_EQUIV_CALC::Calculate(), RN_NET::compute(), SCH_EDIT_FRAME::OpenProjectFiles(), polygon_triangulation_main(), CONNECTION_GRAPH::Recalculate(), 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 137 of file profile.h.

References m_lasttime, m_running, m_starttime, and m_stoptime.

Referenced by PCB_PARSE_RUNNER::doParse(), msecs(), Show(), and to_string().

◆ Start()

◆ Stop()

◆ to_string()

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 238 of file profile.h.

Referenced by ~SCOPED_PROF_TIMER().

◆ m_duration

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

Definition at line 241 of file profile.h.

Referenced by SCOPED_PROF_TIMER(), and ~SCOPED_PROF_TIMER().

◆ m_lasttime

TIME_POINT PROF_TIMER::m_lasttime
privateinherited

Definition at line 200 of file profile.h.

Referenced by SinceStart(), and Start().

◆ m_name

std::string PROF_TIMER::m_name
privateinherited

Definition at line 193 of file profile.h.

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

◆ m_running

bool PROF_TIMER::m_running
privateinherited

Definition at line 194 of file profile.h.

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

◆ m_started

bool PROF_TIMER::m_started
privateinherited

Definition at line 195 of file profile.h.

Referenced by Start(), and to_string().

◆ m_starttime

TIME_POINT PROF_TIMER::m_starttime
privateinherited

Definition at line 200 of file profile.h.

Referenced by SinceStart(), and Start().

◆ m_stoptime

TIME_POINT PROF_TIMER::m_stoptime
privateinherited

Definition at line 200 of file profile.h.

Referenced by SinceStart(), and Stop().


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