Performance counter rework: Add comments, fix coding style issues.

This commit is contained in:
jean-pierre charras 2016-12-31 13:00:24 +01:00
parent ac9f858813
commit fff449ecf0
6 changed files with 59 additions and 41 deletions

View File

@ -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();

View File

@ -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__ */

View File

@ -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__ */

View File

@ -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__ */
}

View File

@ -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<double, std::milli> d = display_stoptime - starttime;
std::chrono::duration<double, std::milli> 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<double, std::milli> d = stoptime - starttime;
std::chrono::duration<double, std::milli> 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<std::chrono::high_resolution_clock> time_point;
typedef std::chrono::time_point<std::chrono::high_resolution_clock> TIME_POINT;
time_point starttime, stoptime;
TIME_POINT m_starttime, m_stoptime;
};

View File

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