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 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_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

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

Definition at line 139 of file profile.h.

Constructor & Destructor Documentation

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.

References Start().

53  :
54  m_name( aName ), m_running( false )
55  {
56  if( aAutostart )
57  Start();
58  }
std::string m_name
Definition: profile.h:136
bool m_running
Definition: profile.h:137
void Start()
Starts or restarts the counter.
Definition: profile.h:72
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.

References Start().

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

Member Function Documentation

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

Definition at line 124 of file profile.h.

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::OPENGL_GAL::EndDrawing(), KIGFX::GPU_CACHED_MANAGER::EndDrawing(), KIGFX::GPU_NONCACHED_MANAGER::EndDrawing(), KIGFX::CACHED_CONTAINER::mergeFreeChunks(), EDA_DRAW_PANEL_GAL::onPaint(), KIGFX::VIEW::Redraw(), and PCB_EDITOR_CONTROL::UpdateSelectionRatsnest().

125  {
126  TIME_POINT stoptime = m_running ?
127  std::chrono::high_resolution_clock::now() :
128  m_stoptime;
129 
130  std::chrono::duration<double, std::milli> elapsed = stoptime - m_starttime;
131 
132  return elapsed.count();
133  }
std::chrono::time_point< std::chrono::high_resolution_clock > TIME_POINT
Definition: profile.h:139
TIME_POINT m_stoptime
Definition: profile.h:141
bool m_running
Definition: profile.h:137
TIME_POINT m_starttime
Definition: profile.h:141
void PROF_COUNTER::Show ( )
inline

Print the elapsed time (in ms) to STDERR.

Definition at line 93 of file profile.h.

References m_name, m_running, m_starttime, and m_stoptime.

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

94  {
95  TIME_POINT display_stoptime = m_running ?
96  std::chrono::high_resolution_clock::now() :
97  m_stoptime;
98 
99  std::chrono::duration<double, std::milli> elapsed = display_stoptime - m_starttime;
100  std::cerr << m_name << " took " << elapsed.count() << " milliseconds." << std::endl;
101  }
std::chrono::time_point< std::chrono::high_resolution_clock > TIME_POINT
Definition: profile.h:139
std::string m_name
Definition: profile.h:136
TIME_POINT m_stoptime
Definition: profile.h:141
bool m_running
Definition: profile.h:137
TIME_POINT m_starttime
Definition: profile.h:141
void PROF_COUNTER::ShowDlg ( )
inline

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

Definition at line 106 of file profile.h.

References m_name, m_running, m_starttime, and m_stoptime.

107  {
108  TIME_POINT display_stoptime = m_running ?
109  std::chrono::high_resolution_clock::now() :
110  m_stoptime;
111 
112  std::chrono::duration<double, std::milli> elapsed = display_stoptime - m_starttime;
113  wxString msg;
114  if( elapsed.count() < 1000.0 )
115  msg << m_name << " took " << elapsed.count() << " ms.";
116  else
117  msg << m_name << " took " << elapsed.count()/1000.0 << " sec.";
118  wxLogMessage( msg );
119  }
std::chrono::time_point< std::chrono::high_resolution_clock > TIME_POINT
Definition: profile.h:139
std::string m_name
Definition: profile.h:136
TIME_POINT m_stoptime
Definition: profile.h:141
bool m_running
Definition: profile.h:137
TIME_POINT m_starttime
Definition: profile.h:141
void PROF_COUNTER::Start ( )
inline

Starts or restarts the counter.

Definition at line 72 of file profile.h.

References m_running, and m_starttime.

Referenced by PROF_COUNTER().

73  {
74  m_running = true;
75  m_starttime = std::chrono::high_resolution_clock::now();
76  }
bool m_running
Definition: profile.h:137
TIME_POINT m_starttime
Definition: profile.h:141

Member Data Documentation

std::string PROF_COUNTER::m_name
private

Definition at line 136 of file profile.h.

Referenced by Show(), and ShowDlg().

bool PROF_COUNTER::m_running
private

Definition at line 137 of file profile.h.

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

TIME_POINT PROF_COUNTER::m_starttime
private

Definition at line 141 of file profile.h.

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

TIME_POINT PROF_COUNTER::m_stoptime
private

Definition at line 141 of file profile.h.

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


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