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 136 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:133
bool m_running
Definition: profile.h:134
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 121 of file profile.h.

References m_running, m_starttime, and m_stoptime.

Referenced by KIGFX::OPENGL_GAL::BeginDrawing(), KIGFX::CACHED_CONTAINER::defragmentResize(), KIGFX::CACHED_CONTAINER::defragmentResizeMemcpy(), KIGFX::OPENGL_GAL::EndDrawing(), KIGFX::GPU_CACHED_MANAGER::EndDrawing(), KIGFX::GPU_NONCACHED_MANAGER::EndDrawing(), KIGFX::CACHED_CONTAINER::mergeFreeChunks(), EDA_DRAW_PANEL_GAL::onPaint(), RN_DATA::Recalculate(), and KIGFX::VIEW::Redraw().

122  {
123  TIME_POINT stoptime = m_running ?
124  std::chrono::high_resolution_clock::now() :
125  m_stoptime;
126 
127  std::chrono::duration<double, std::milli> elapsed = stoptime - m_starttime;
128 
129  return elapsed.count();
130  }
std::chrono::time_point< std::chrono::high_resolution_clock > TIME_POINT
Definition: profile.h:136
TIME_POINT m_stoptime
Definition: profile.h:138
bool m_running
Definition: profile.h:134
TIME_POINT m_starttime
Definition: profile.h:138
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.

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:136
std::string m_name
Definition: profile.h:133
TIME_POINT m_stoptime
Definition: profile.h:138
bool m_running
Definition: profile.h:134
TIME_POINT m_starttime
Definition: profile.h:138
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  msg << m_name << " took " << elapsed.count() << " ms.";
115  wxLogMessage( msg );
116  }
std::chrono::time_point< std::chrono::high_resolution_clock > TIME_POINT
Definition: profile.h:136
std::string m_name
Definition: profile.h:133
TIME_POINT m_stoptime
Definition: profile.h:138
bool m_running
Definition: profile.h:134
TIME_POINT m_starttime
Definition: profile.h:138
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:134
TIME_POINT m_starttime
Definition: profile.h:138
void PROF_COUNTER::Stop ( )
inline

save the time when this function was called, and set the counter stane to stop

Definition at line 82 of file profile.h.

References m_running, and m_stoptime.

Referenced by KIGFX::OPENGL_GAL::BeginDrawing(), KIGFX::CACHED_CONTAINER::defragmentResize(), KIGFX::CACHED_CONTAINER::defragmentResizeMemcpy(), KIGFX::OPENGL_GAL::EndDrawing(), KIGFX::GPU_CACHED_MANAGER::EndDrawing(), KIGFX::GPU_NONCACHED_MANAGER::EndDrawing(), KIGFX::CACHED_CONTAINER::mergeFreeChunks(), EDA_DRAW_PANEL_GAL::onPaint(), RN_DATA::Recalculate(), and KIGFX::VIEW::Redraw().

83  {
84  if( !m_running )
85  return;
86 
87  m_stoptime = std::chrono::high_resolution_clock::now();
88  }
TIME_POINT m_stoptime
Definition: profile.h:138
bool m_running
Definition: profile.h:134

Member Data Documentation

std::string PROF_COUNTER::m_name
private

Definition at line 133 of file profile.h.

Referenced by Show(), and ShowDlg().

bool PROF_COUNTER::m_running
private

Definition at line 134 of file profile.h.

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

TIME_POINT PROF_COUNTER::m_starttime
private

Definition at line 138 of file profile.h.

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

TIME_POINT PROF_COUNTER::m_stoptime
private

Definition at line 138 of file profile.h.

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


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