diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index ebc981d844..3728962e1e 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -161,8 +161,7 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) return; #ifdef PROFILE - prof_counter totalRealTime; - prof_start( &totalRealTime ); + PROF_COUNTER totalRealTime; #endif /* PROFILE */ m_drawing = true; @@ -196,8 +195,8 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) m_gal->EndDrawing(); #ifdef PROFILE - prof_end( &totalRealTime ); - wxLogDebug( wxT( "EDA_DRAW_PANEL_GAL::onPaint(): %.1f ms" ), totalRealTime.msecs() ); + totalRealTime.Stop(); + wxLogDebug( "EDA_DRAW_PANEL_GAL::onPaint(): %.1f ms", totalRealTime.msecs() ); #endif /* PROFILE */ m_lastRefresh = wxGetLocalTimeMillis(); diff --git a/common/gal/opengl/cached_container.cpp b/common/gal/opengl/cached_container.cpp index 84fbe51375..d7e5d04a34 100644 --- a/common/gal/opengl/cached_container.cpp +++ b/common/gal/opengl/cached_container.cpp @@ -342,7 +342,7 @@ void CACHED_CONTAINER::mergeFreeChunks() return; #ifdef __WXDEBUG__ - PROF_COUNTER totalTime( "CACHED_CONTAINER::mergeFreeChunks()", true ); + PROF_COUNTER totalTime; #endif /* __WXDEBUG__ */ // Reversed free chunks map - this one stores chunk size with its offset as the key @@ -386,9 +386,8 @@ void CACHED_CONTAINER::mergeFreeChunks() m_freeChunks.insert( std::make_pair( size, offset ) ); #ifdef __WXDEBUG__ - totalTime.stop(); - - wxLogDebug( wxT( "Merged free chunks / %.1f ms" ), totalTime.msecs() ); + totalTime.Stop(); + wxLogDebug( "Merged free chunks / %.1f ms", totalTime.msecs() ); #endif /* __WXDEBUG__ */ #if CACHED_CONTAINER_TEST > 0 test(); @@ -411,7 +410,7 @@ bool CACHED_CONTAINER::defragmentResize( unsigned int aNewSize ) return false; #ifdef __WXDEBUG__ - PROF_COUNTER totalTime( "CACHED_CONTAINER::defragmentResize()", true ); + PROF_COUNTER totalTime; #endif /* __WXDEBUG__ */ GLuint newBuffer; @@ -479,10 +478,10 @@ bool CACHED_CONTAINER::defragmentResize( unsigned int aNewSize ) checkGlError( "switching buffers during defragmentation" ); #ifdef __WXDEBUG__ - totalTime.stop(); + totalTime.Stop(); wxLogTrace( "GAL_CACHED_CONTAINER", - wxT( "Defragmented container storing %d vertices / %.1f ms" ), + "Defragmented container storing %d vertices / %.1f ms", m_currentSize - m_freeSpace, totalTime.msecs() ); #endif /* __WXDEBUG__ */ @@ -510,7 +509,7 @@ bool CACHED_CONTAINER::defragmentResizeMemcpy( unsigned int aNewSize ) return false; #ifdef __WXDEBUG__ - PROF_COUNTER totalTime( "CACHED_CONTAINER::defragmentResizeMemcpy()", true ); + PROF_COUNTER totalTime; #endif /* __WXDEBUG__ */ GLuint newBuffer; @@ -572,10 +571,10 @@ bool CACHED_CONTAINER::defragmentResizeMemcpy( unsigned int aNewSize ) checkGlError( "switching buffers during defragmentation" ); #ifdef __WXDEBUG__ - totalTime.stop(); + totalTime.Stop(); wxLogTrace( "GAL_CACHED_CONTAINER", - wxT( "Defragmented container storing %d vertices / %.1f ms" ), + "Defragmented container storing %d vertices / %.1f ms", m_currentSize - m_freeSpace, totalTime.msecs() ); #endif /* __WXDEBUG__ */ diff --git a/common/gal/opengl/gpu_manager.cpp b/common/gal/opengl/gpu_manager.cpp index 0ee32d10fc..7cdfded922 100644 --- a/common/gal/opengl/gpu_manager.cpp +++ b/common/gal/opengl/gpu_manager.cpp @@ -145,7 +145,7 @@ void GPU_CACHED_MANAGER::DrawAll() void GPU_CACHED_MANAGER::EndDrawing() { #ifdef __WXDEBUG__ - PROF_COUNTER totalRealTime( "GPU_CACHED_MANAGER::EndDrawing()", true ); + PROF_COUNTER totalRealTime; #endif /* __WXDEBUG__ */ wxASSERT( m_isDrawing ); @@ -204,7 +204,7 @@ void GPU_CACHED_MANAGER::EndDrawing() m_isDrawing = false; #ifdef __WXDEBUG__ - totalRealTime.stop(); + totalRealTime.Stop(); wxLogTrace( "GAL_PROFILE", wxT( "GPU_CACHED_MANAGER::EndDrawing(): %.1f ms" ), totalRealTime.msecs() ); #endif /* __WXDEBUG__ */ @@ -250,7 +250,7 @@ void GPU_NONCACHED_MANAGER::DrawAll() void GPU_NONCACHED_MANAGER::EndDrawing() { #ifdef __WXDEBUG__ - PROF_COUNTER totalRealTime( "GPU_NONCACHED_MANAGER::EndDrawing()", true ); + PROF_COUNTER totalRealTime; #endif /* __WXDEBUG__ */ if( m_container->GetSize() == 0 ) @@ -294,7 +294,7 @@ void GPU_NONCACHED_MANAGER::EndDrawing() } #ifdef __WXDEBUG__ - totalRealTime.stop(); + totalRealTime.Stop(); wxLogTrace( "GAL_PROFILE", wxT( "GPU_NONCACHED_MANAGER::EndDrawing(): %.1f ms" ), totalRealTime.msecs() ); #endif /* __WXDEBUG__ */ diff --git a/common/view/view.cpp b/common/view/view.cpp index c4f09f5cf0..3508e5617e 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -1000,7 +1000,7 @@ void VIEW::ClearTargets() void VIEW::Redraw() { #ifdef __WXDEBUG__ - PROF_COUNTER totalRealTime( "VIEW::Redraw()", true ); + PROF_COUNTER totalRealTime; #endif /* __WXDEBUG__ */ VECTOR2D screenSize = m_gal->GetScreenPixelSize(); @@ -1016,7 +1016,7 @@ void VIEW::Redraw() markTargetClean( TARGET_OVERLAY ); #ifdef __WXDEBUG__ - totalRealTime.stop(); + totalRealTime.Stop(); wxLogTrace( "GAL_PROFILE", wxT( "VIEW::Redraw(): %.1f ms" ), totalRealTime.msecs() ); #endif /* __WXDEBUG__ */ } diff --git a/include/profile.h b/include/profile.h index 81d04a023a..1a9f8acd15 100644 --- a/include/profile.h +++ b/include/profile.h @@ -39,54 +39,76 @@ class PROF_COUNTER { public: - PROF_COUNTER( const std::string& name, bool autostart = true ) : - m_name( name ), + /** + * Creates a PROF_COUNTER for measuring an elapsed time in milliseconds + * @param aName = a string that will be printed in message. + * @param aAutostart = true (default) to immediately start the timer + */ + PROF_COUNTER( const std::string& aName, bool aAutostart = true ) : + m_name( aName ), m_running( false ) + { + if( aAutostart ) + Start(); + } + + /** + * Creates a PROF_COUNTER for measuring an elapsed time in milliseconds + * The string that will be printed in message is left empty. + * @param aAutostart = true (default) to immediately start the timer + */ + PROF_COUNTER( bool aAutostart = true ) : m_running( false ) { - if( autostart ) - start(); + if( aAutostart ) + Start(); } - void start() + void Start() { m_running = true; - starttime = std::chrono::system_clock::now(); + m_starttime = std::chrono::system_clock::now(); } - void stop() + void Stop() { if( !m_running ) return; - stoptime = std::chrono::system_clock::now(); + m_stoptime = std::chrono::system_clock::now(); } - void show() + /** + * Print the elapsed time (in ms) to STDERR. + */ + void Show() { - time_point display_stoptime; + TIME_POINT display_stoptime; if( m_running ) display_stoptime = std::chrono::system_clock::now(); else - display_stoptime = stoptime; + display_stoptime = m_stoptime; - std::chrono::duration d = display_stoptime - starttime; + std::chrono::duration d = display_stoptime - m_starttime; std::cerr << m_name << " took " << std::setprecision(1) << d.count() << "milliseconds." << std::endl; } + /** + * @return the elapsed time in ms + */ double msecs() const { - std::chrono::duration d = stoptime - starttime; + std::chrono::duration d = m_stoptime - m_starttime; return d.count(); } private: - std::string m_name; + std::string m_name; // a string printed in message bool m_running; - typedef std::chrono::time_point time_point; + typedef std::chrono::time_point TIME_POINT; - time_point starttime, stoptime; + TIME_POINT m_starttime, m_stoptime; }; diff --git a/pcbnew/ratsnest_data.cpp b/pcbnew/ratsnest_data.cpp index 0302c9768a..ea9055088f 100644 --- a/pcbnew/ratsnest_data.cpp +++ b/pcbnew/ratsnest_data.cpp @@ -1269,8 +1269,7 @@ void RN_DATA::Recalculate( int aNet ) if( aNet <= 0 && netCount > 1 ) // Recompute everything { #ifdef PROFILE - prof_counter totalRealTime; - prof_start( &totalRealTime ); + PROF_COUNTER totalRealTime; #endif unsigned int i; @@ -1290,9 +1289,8 @@ void RN_DATA::Recalculate( int aNet ) } } /* end of parallel section */ #ifdef PROFILE - prof_end( &totalRealTime ); - - wxLogDebug( wxT( "Recalculate all nets: %.1f ms" ), totalRealTime.msecs() ); + totalRealTime.Stop(); + wxLogDebug( "Recalculate all nets: %.1f ms", totalRealTime.msecs() ); #endif /* PROFILE */ } else if( aNet > 0 ) // Recompute only specific net