KiCad PCB EDA Suite
PROF_TIMER Class Reference

A small class to help profiling. More...

#include <profile.h>

Inheritance diagram for PROF_TIMER:

Public Member Functions

 PROF_TIMER (const std::string &aName, bool aAutostart=true)
 Create a PROF_COUNTER for measuring an elapsed time in milliseconds. More...
 Create a PROF_COUNTER for measuring an elapsed time in milliseconds. More...
void Start ()
 Start or restart 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)
std::string to_string ()

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

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

Member Typedef Documentation


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

Definition at line 164 of file profile.h.


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

Definition at line 165 of file profile.h.

Constructor & Destructor Documentation

◆ PROF_TIMER() [1/2]

PROF_TIMER::PROF_TIMER ( const std::string &  aName,
bool  aAutostart = true 

Create a PROF_COUNTER for measuring an elapsed time in milliseconds.

aNamea string that will be printed in message.
aAutostarttrue (default) to immediately start the timer

Definition at line 55 of file profile.h.

55 :
56 m_name( aName ), m_running( false )
57 {
58 if( aAutostart )
59 Start();
60 }
void Start()
Start or restart the counter.
Definition: profile.h:75
bool m_running
Definition: profile.h:162
std::string m_name
Definition: profile.h:161

References Start().

◆ PROF_TIMER() [2/2]


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

68 {
69 Start();
70 }

References Start().

Member Function Documentation

◆ msecs()

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

Definition at line 147 of file profile.h.

148 {
149 using DUR_MS = std::chrono::duration<double, std::milli>;
150 return SinceStart<DUR_MS>( aSinceLast ).count();
151 }

Referenced by KIGFX::OPENGL_GAL::BeginDrawing(), E_SERIE::combine4(), KIGFX::CACHED_CONTAINER_GPU::defragmentResize(), KIGFX::CACHED_CONTAINER_RAM::defragmentResize(), KIGFX::CACHED_CONTAINER_GPU::defragmentResizeMemcpy(), KIGFX::GPU_NONCACHED_MANAGER::EndDrawing(), SCH_EDIT_FRAME::RecalculateConnections(), KIGFX::VIEW::Redraw(), PCB_SELECTION_TOOL::selectAllConnectedTracks(), and to_string().

◆ Show()

void PROF_TIMER::Show ( std::ostream &  aStream = std::cerr)

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.

thestream to print to.

Definition at line 103 of file profile.h.

104 {
105 using DURATION = std::chrono::duration<double, std::nano>;
107 const auto duration = SinceStart<DURATION>();
108 const double cnt = duration.count();
110 if( m_name.size() )
111 {
112 aStream << m_name << " took ";
113 }
115 if( cnt < 1e3 )
116 aStream << cnt << "ns";
117 else if( cnt < 1e6 )
118 aStream << cnt / 1e3 << "┬Ás";
119 else if( cnt < 1e9 )
120 aStream << cnt / 1e6 << "ms";
121 else
122 aStream << cnt / 1e9 << "s";
124 aStream << std::endl;
125 }

References m_name.

Referenced by CONNECTION_GRAPH::buildConnectionGraph(), RN_NET::compute(), SCH_EDIT_FRAME::OpenProjectFiles(), CN_CONNECTIVITY_ALGO::searchConnections(), RN_NET::UpdateNet(), and CONNECTIVITY_DATA::updateRatsnest().

◆ SinceStart()

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

134 {
135 const TIME_POINT stoptime = m_running ? CLOCK::now() : m_stoptime;
136 const TIME_POINT starttime = aSinceLast ? m_lasttime : m_starttime;
138 m_lasttime = stoptime;
140 return std::chrono::duration_cast<DURATION>( stoptime - starttime );
141 }
TIME_POINT m_lasttime
Definition: profile.h:167
TIME_POINT m_stoptime
Definition: profile.h:167
std::chrono::time_point< CLOCK > TIME_POINT
Definition: profile.h:165
TIME_POINT m_starttime
Definition: profile.h:167

References m_lasttime, m_running, m_starttime, and m_stoptime.

Referenced by parse(), and SCOPED_PROF_TIMER< DURATION >::~SCOPED_PROF_TIMER().

◆ Start()

void PROF_TIMER::Start ( )

Start or restart the counter.

Definition at line 75 of file profile.h.

76 {
77 m_running = true;
78 m_starttime = CLOCK::now();
80 }

References m_lasttime, m_running, and m_starttime.

Referenced by EDA_DRAW_PANEL_GAL::DoRePaint(), KIGFX::OPENGL_GAL::EndDrawing(), PROF_TIMER(), and PCB_SELECTION_TOOL::selectAllConnectedTracks().

◆ Stop()

◆ to_string()

std::string PROF_TIMER::to_string ( )

Definition at line 153 of file profile.h.

154 {
155 char tmp[1024];
156 snprintf( tmp, sizeof( tmp ), "%s: %-6.1fms", m_name.c_str(), msecs() );
157 return tmp;
158 }
double msecs(bool aSinceLast=false)
Definition: profile.h:147

References m_name, and msecs().

Referenced by EDA_DRAW_PANEL_GAL::DoRePaint(), KIGFX::GPU_CACHED_MANAGER::EndDrawing(), KIGFX::OPENGL_GAL::EndDrawing(), and PCB_TEST_FRAME_BASE::SetBoard().

Member Data Documentation

◆ m_lasttime


Definition at line 167 of file profile.h.

Referenced by SinceStart(), and Start().

◆ m_name

std::string PROF_TIMER::m_name

Definition at line 161 of file profile.h.

Referenced by Show(), and to_string().

◆ m_running

bool PROF_TIMER::m_running

Definition at line 162 of file profile.h.

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

◆ m_starttime


Definition at line 167 of file profile.h.

Referenced by SinceStart(), and Start().

◆ m_stoptime


Definition at line 167 of file profile.h.

Referenced by SinceStart(), and Stop().

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