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 ()
 Print the elapsed time (in ms) to STDERR. More...
 
void Show (const std::string &aMessage)
 Print a message and the elapsed time (in ms) since the start time and since the last call to STDERR. More...
 
void ShowDlg ()
 Show the elapsed time (in ms) in a wxLogMessage window. More...
 
double msecs () const
 

Private Types

typedef std::chrono::time_point< std::chrono::high_resolution_clock > TIME_POINT
 

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 millisecondes) between its creation (or the last call to Start() ) and the last call to Stop()

Definition at line 45 of file profile.h.

Member Typedef Documentation

◆ TIME_POINT

typedef std::chrono::time_point<std::chrono::high_resolution_clock> PROF_COUNTER::TIME_POINT
private

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

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

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

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

References Start().

Member Function Documentation

◆ msecs()

double PROF_COUNTER::msecs ( ) const
inline
Returns
the elapsed time in ms

Definition at line 144 of file profile.h.

145  {
146  TIME_POINT stoptime = m_running ?
147  std::chrono::high_resolution_clock::now() :
148  m_stoptime;
149 
150  std::chrono::duration<double, std::milli> elapsed = stoptime - m_starttime;
151 
152  return elapsed.count();
153  }
std::chrono::time_point< std::chrono::high_resolution_clock > TIME_POINT
Definition: profile.h:159
TIME_POINT m_stoptime
Definition: profile.h:161
bool m_running
Definition: profile.h:157
TIME_POINT m_starttime
Definition: profile.h:161

References m_running, m_starttime, and m_stoptime.

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_EDITOR_CONTROL::UpdateSelectionRatsnest().

◆ Show() [1/2]

void PROF_COUNTER::Show ( )
inline

Print the elapsed time (in ms) to STDERR.

Definition at line 94 of file profile.h.

95  {
96  TIME_POINT display_stoptime = m_running ?
97  std::chrono::high_resolution_clock::now() :
98  m_stoptime;
99 
100  std::chrono::duration<double, std::milli> elapsed = display_stoptime - m_starttime;
101  m_lasttime = display_stoptime;
102  std::cerr << m_name << " took " << elapsed.count() << " ms." << std::endl;
103  }
std::chrono::time_point< std::chrono::high_resolution_clock > TIME_POINT
Definition: profile.h:159
TIME_POINT m_lasttime
Definition: profile.h:161
std::string m_name
Definition: profile.h:156
TIME_POINT m_stoptime
Definition: profile.h:161
bool m_running
Definition: profile.h:157
TIME_POINT m_starttime
Definition: profile.h:161

References m_lasttime, m_name, m_running, m_starttime, and m_stoptime.

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

◆ Show() [2/2]

void PROF_COUNTER::Show ( const std::string &  aMessage)
inline

Print a message and the elapsed time (in ms) since the start time and since the last call to STDERR.

Parameters
aMessageis the message to print

Definition at line 110 of file profile.h.

111  {
112  TIME_POINT display_stoptime = m_running ?
113  std::chrono::high_resolution_clock::now() :
114  m_stoptime;
115 
116  std::chrono::duration<double, std::milli> elapsed = display_stoptime - m_starttime;
117  std::chrono::duration<double, std::milli> delta_time = display_stoptime - m_lasttime;
118  std::cerr << m_name << " (" << aMessage << ") took " << elapsed.count() << " ms."
119  << " delta " << delta_time.count() << " ms." << std::endl;
120  m_lasttime = display_stoptime;
121  }
std::chrono::time_point< std::chrono::high_resolution_clock > TIME_POINT
Definition: profile.h:159
TIME_POINT m_lasttime
Definition: profile.h:161
std::string m_name
Definition: profile.h:156
TIME_POINT m_stoptime
Definition: profile.h:161
bool m_running
Definition: profile.h:157
TIME_POINT m_starttime
Definition: profile.h:161

References m_lasttime, m_name, m_running, m_starttime, and m_stoptime.

◆ ShowDlg()

void PROF_COUNTER::ShowDlg ( )
inline

Show the elapsed time (in ms) in a wxLogMessage window.

Definition at line 126 of file profile.h.

127  {
128  TIME_POINT display_stoptime = m_running ?
129  std::chrono::high_resolution_clock::now() :
130  m_stoptime;
131 
132  std::chrono::duration<double, std::milli> elapsed = display_stoptime - m_starttime;
133  wxString msg;
134  if( elapsed.count() < 1000.0 )
135  msg << m_name << " took " << elapsed.count() << " ms.";
136  else
137  msg << m_name << " took " << elapsed.count()/1000.0 << " sec.";
138  wxLogMessage( msg );
139  }
std::chrono::time_point< std::chrono::high_resolution_clock > TIME_POINT
Definition: profile.h:159
std::string m_name
Definition: profile.h:156
TIME_POINT m_stoptime
Definition: profile.h:161
bool m_running
Definition: profile.h:157
TIME_POINT m_starttime
Definition: profile.h:161

References m_name, m_running, m_starttime, and m_stoptime.

◆ Start()

void PROF_COUNTER::Start ( )
inline

Starts or restarts the counter.

Definition at line 72 of file profile.h.

73  {
74  m_running = true;
75  m_starttime = std::chrono::high_resolution_clock::now();
77  }
TIME_POINT m_lasttime
Definition: profile.h:161
bool m_running
Definition: profile.h:157
TIME_POINT m_starttime
Definition: profile.h:161

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

Referenced by Show(), and Start().

◆ m_name

std::string PROF_COUNTER::m_name
private

Definition at line 156 of file profile.h.

Referenced by Show(), and ShowDlg().

◆ m_running

bool PROF_COUNTER::m_running
private

Definition at line 157 of file profile.h.

Referenced by msecs(), Show(), ShowDlg(), Start(), and Stop().

◆ m_starttime

TIME_POINT PROF_COUNTER::m_starttime
private

Definition at line 161 of file profile.h.

Referenced by msecs(), Show(), ShowDlg(), and Start().

◆ m_stoptime

TIME_POINT PROF_COUNTER::m_stoptime
private

Definition at line 161 of file profile.h.

Referenced by msecs(), Show(), ShowDlg(), and Stop().


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