KiCad PCB EDA Suite
PROF_COUNTER Class Reference

The class PROF_COUNTER is a small class to help profiling. More...

#include <profile.h>

Public Member Functions

 PROF_COUNTER (const std::string &aName, bool aAutostart=true)
 Creates a PROF_COUNTER for measuring an elapsed time in milliseconds. More...
 
 PROF_COUNTER ()
 Creates a PROF_COUNTER for measuring an elapsed time in milliseconds The counter is started and the string to print in message is left empty. More...
 
void Start ()
 Starts or restarts 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)
 

Private Types

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

Private Attributes

std::string m_name
 
bool m_running
 
TIME_POINT m_starttime
 
TIME_POINT m_lasttime
 
TIME_POINT m_stoptime
 

Detailed Description

The class PROF_COUNTER is a small class to help profiling.

It allows the calculation of the elapsed time (in milliseconds) between its creation (or the last call to Start() ) and the last call to Stop()

Definition at line 44 of file profile.h.

Member Typedef Documentation

◆ CLOCK

using PROF_COUNTER::CLOCK = std::chrono::high_resolution_clock
private

Definition at line 153 of file profile.h.

◆ TIME_POINT

using PROF_COUNTER::TIME_POINT = std::chrono::time_point<CLOCK>
private

Definition at line 154 of file profile.h.

Constructor & Destructor Documentation

◆ PROF_COUNTER() [1/2]

PROF_COUNTER::PROF_COUNTER ( const std::string &  aName,
bool  aAutostart = true 
)
inline

Creates a PROF_COUNTER for measuring an elapsed time in milliseconds.

Parameters
aName= a string that will be printed in message.
aAutostart= true (default) to immediately start the timer

Definition at line 52 of file profile.h.

52  :
53  m_name( aName ), m_running( false )
54  {
55  if( aAutostart )
56  Start();
57  }
std::string m_name
Definition: profile.h:150
bool m_running
Definition: profile.h:151
void Start()
Starts or restarts the counter.
Definition: profile.h:71

References Start().

◆ PROF_COUNTER() [2/2]

PROF_COUNTER::PROF_COUNTER ( )
inline

Creates a PROF_COUNTER for measuring an elapsed time in milliseconds The counter is started and the string to print in message is left empty.

Definition at line 63 of file profile.h.

64  {
65  Start();
66  }
void Start()
Starts or restarts the counter.
Definition: profile.h:71

References Start().

Member Function Documentation

◆ msecs()

double PROF_COUNTER::msecs ( bool  aSinceLast = false)
inline
Parameters
aSinceLastonly get the time since the last time the time was read
Returns
the elapsed time in ms since the timer was started.

Definition at line 143 of file profile.h.

144  {
145  using DUR_MS = std::chrono::duration<double, std::milli>;
146  return SinceStart<DUR_MS>( aSinceLast ).count();
147  }

Referenced by KIGFX::OPENGL_GAL::beginDrawing(), KIGFX::CACHED_CONTAINER_GPU::defragmentResize(), KIGFX::CACHED_CONTAINER_RAM::defragmentResize(), KIGFX::CACHED_CONTAINER_GPU::defragmentResizeMemcpy(), KIGFX::GPU_CACHED_MANAGER::EndDrawing(), KIGFX::GPU_NONCACHED_MANAGER::EndDrawing(), KIGFX::OPENGL_GAL::endDrawing(), KIGFX::CACHED_CONTAINER::mergeFreeChunks(), EDA_DRAW_PANEL_GAL::onPaint(), CONNECTION_GRAPH::Recalculate(), SCH_EDIT_FRAME::RecalculateConnections(), KIGFX::VIEW::Redraw(), and PCB_INSPECTION_TOOL::UpdateSelectionRatsnest().

◆ Show()

void PROF_COUNTER::Show ( std::ostream &  aStream = std::cerr)
inline

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

100  {
101  using DURATION = std::chrono::duration<double, std::nano>;
102 
103  const auto duration = SinceStart<DURATION>();
104  const double cnt = duration.count();
105 
106  if( m_name.size() )
107  {
108  aStream << m_name << " took ";
109  }
110 
111  if( cnt < 1e3 )
112  aStream << cnt << "ns";
113  else if( cnt < 1e6 )
114  aStream << cnt / 1e3 << "┬Ás";
115  else if( cnt < 1e9 )
116  aStream << cnt / 1e6 << "ms";
117  else
118  aStream << cnt / 1e9 << "s";
119 
120  aStream << std::endl;
121  }
std::string m_name
Definition: profile.h:150

References m_name.

Referenced by RN_NET::compute(), CN_CONNECTIVITY_ALGO::searchConnections(), and CONNECTIVITY_DATA::updateRatsnest().

◆ SinceStart()

template<typename DURATION >
DURATION PROF_COUNTER::SinceStart ( bool  aSinceLast = false)
inline
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 129 of file profile.h.

130  {
131  const TIME_POINT stoptime = m_running ? CLOCK::now() : m_stoptime;
132  const TIME_POINT starttime = aSinceLast ? m_lasttime : m_starttime;
133 
134  m_lasttime = stoptime;
135 
136  return std::chrono::duration_cast<DURATION>( stoptime - starttime );
137  }
std::chrono::time_point< CLOCK > TIME_POINT
Definition: profile.h:154
TIME_POINT m_lasttime
Definition: profile.h:156
TIME_POINT m_stoptime
Definition: profile.h:156
bool m_running
Definition: profile.h:151
TIME_POINT m_starttime
Definition: profile.h:156

References m_lasttime, m_running, m_starttime, and m_stoptime.

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

◆ Start()

void PROF_COUNTER::Start ( )
inline

Starts or restarts the counter.

Definition at line 71 of file profile.h.

72  {
73  m_running = true;
74  m_starttime = CLOCK::now();
76  }
TIME_POINT m_lasttime
Definition: profile.h:156
bool m_running
Definition: profile.h:151
TIME_POINT m_starttime
Definition: profile.h:156

References m_lasttime, m_running, and m_starttime.

Referenced by PROF_COUNTER().

◆ Stop()

Member Data Documentation

◆ m_lasttime

TIME_POINT PROF_COUNTER::m_lasttime
private

Definition at line 156 of file profile.h.

Referenced by SinceStart(), and Start().

◆ m_name

std::string PROF_COUNTER::m_name
private

Definition at line 150 of file profile.h.

Referenced by Show().

◆ m_running

bool PROF_COUNTER::m_running
private

Definition at line 151 of file profile.h.

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

◆ m_starttime

TIME_POINT PROF_COUNTER::m_starttime
private

Definition at line 156 of file profile.h.

Referenced by SinceStart(), and Start().

◆ m_stoptime

TIME_POINT PROF_COUNTER::m_stoptime
private

Definition at line 156 of file profile.h.

Referenced by SinceStart(), and Stop().


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