From d56a49d218fcf1982cd21259b3a4ad5264dd307e Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 2 Jan 2017 13:49:36 +0100 Subject: [PATCH] Performance counter rework: More comments, code cleaning, and move GetRunningMicroSecs() prototype from common.h to profile.h. profile.h should now contain all info for profiling. --- 3d-viewer/3d_cache/3d_cache.cpp | 1 - 3d-viewer/3d_canvas/eda_3d_canvas.cpp | 1 + .../c3d_render_createscene_ogl_legacy.cpp | 1 + .../c3d_render_createscene.cpp | 1 + .../c3d_render_raytracing.cpp | 1 + common/gal/opengl/opengl_gal.cpp | 4 +- common/getrunningmicrosecs.cpp | 17 ------ include/common.h | 12 +---- include/profile.h | 54 +++++++++++++------ 9 files changed, 45 insertions(+), 47 deletions(-) diff --git a/3d-viewer/3d_cache/3d_cache.cpp b/3d-viewer/3d_cache/3d_cache.cpp index 3a8a2e0eef..3c0f5a7fdf 100644 --- a/3d-viewer/3d_cache/3d_cache.cpp +++ b/3d-viewer/3d_cache/3d_cache.cpp @@ -42,7 +42,6 @@ #include "common.h" #include "3d_cache.h" #include "3d_info.h" -#include "common.h" #include "sg/scenegraph.h" #include "3d_filename_resolver.h" #include "3d_plugin_manager.h" diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.cpp b/3d-viewer/3d_canvas/eda_3d_canvas.cpp index 268812565c..1bd8e1a253 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.cpp +++ b/3d-viewer/3d_canvas/eda_3d_canvas.cpp @@ -39,6 +39,7 @@ #include #include "status_text_reporter.h" #include +#include // To use GetRunningMicroSecs or an other profiling utility /** * Trace mask used to enable or disable the trace output of this class. diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp index d2cf21e66c..485fcc56e3 100644 --- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp +++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp @@ -35,6 +35,7 @@ #include "../../3d_fastmath.h" #include #include +#include // To use GetRunningMicroSecs or an other profiling utility void C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer( const CFILLEDCIRCLE2D * aFilledCircle, diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp index 19211f50c5..560c7dd5c4 100644 --- a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp +++ b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp @@ -46,6 +46,7 @@ #include #include +#include // To use GetRunningMicroSecs or an other profiling utility /** * Scale convertion from 3d model units to pcb units diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp index de850d20eb..094541c0ac 100644 --- a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp +++ b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_raytracing.cpp @@ -36,6 +36,7 @@ #include "3d_fastmath.h" #include "3d_math.h" #include "../common_ogl/ogl_utils.h" +#include // To use GetRunningMicroSecs or an other profiling utility // This should be used in future for the function // convertLinearToSRGB diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index c24e28b344..5596a86ff5 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -307,7 +307,7 @@ void OPENGL_GAL::BeginDrawing() compositor->SetBuffer( OPENGL_COMPOSITOR::DIRECT_RENDERING ); #ifdef __WXDEBUG__ - totalRealTime.stop(); + totalRealTime.Stop(); wxLogTrace( "GAL_PROFILE", wxT( "OPENGL_GAL::BeginDrawing(): %.1f ms" ), totalRealTime.msecs() ); #endif /* __WXDEBUG__ */ @@ -341,7 +341,7 @@ void OPENGL_GAL::EndDrawing() GL_CONTEXT_MANAGER::Get().UnlockCtx( glPrivContext ); #ifdef __WXDEBUG__ - totalRealTime.stop(); + totalRealTime.Stop(); wxLogTrace( "GAL_PROFILE", wxT( "OPENGL_GAL::EndDrawing(): %.1f ms" ), totalRealTime.msecs() ); #endif /* __WXDEBUG__ */ } diff --git a/common/getrunningmicrosecs.cpp b/common/getrunningmicrosecs.cpp index 3fa5e4494e..e414028345 100644 --- a/common/getrunningmicrosecs.cpp +++ b/common/getrunningmicrosecs.cpp @@ -43,23 +43,6 @@ unsigned GetRunningMicroSecs() return unsigned( t ); } - -#if 0 -// test program -#include -int main( int argc, char** argv ) -{ - unsigned then = GetRunningMicroSecs(); - - Sleep( 2000 ); // Windows Sleep( msecs ) - - printf( "delta: %u\n", GetRunningMicroSecs() - then ); - - return 0; -} -#endif - - #elif defined(HAVE_CLOCK_GETTIME) #include diff --git a/include/common.h b/include/common.h index 70e73794e6..3ea8fad691 100644 --- a/include/common.h +++ b/include/common.h @@ -1,10 +1,10 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2014-2016 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2014-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2007-2015 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2008-2015 Wayne Stambaugh - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -304,14 +304,6 @@ double RoundTo0( double x, double precision ); */ void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSplitter ); -/** - * Function GetRunningMicroSecs - * returns an ever increasing indication of elapsed microseconds. Use this - * by computing differences between two calls. - * @author Dick Hollenbeck - */ -unsigned GetRunningMicroSecs(); - /** * Function SystemDirsAppend diff --git a/include/profile.h b/include/profile.h index 1a9f8acd15..a85589d800 100644 --- a/include/profile.h +++ b/include/profile.h @@ -3,7 +3,7 @@ * * Copyright (C) 2013 CERN * @author Tomasz Wlostowski - * 2016 KiCad Developers, see AUTHORS.txt for contributors. + * 2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -36,6 +36,11 @@ #include #include +/** + * 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() + */ class PROF_COUNTER { public: @@ -53,22 +58,26 @@ public: /** * 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 + * The counter is started and the string to print in message is left empty. */ - PROF_COUNTER( bool aAutostart = true ) : - m_running( false ) + PROF_COUNTER() { - if( aAutostart ) - Start(); + Start(); } + /** + * Starts or restarts the counter + */ void Start() { m_running = true; m_starttime = std::chrono::system_clock::now(); } + + /** + * save the time when this function was called, and set the counter stane to stop + */ void Stop() { if( !m_running ) @@ -82,15 +91,12 @@ public: */ void Show() { - TIME_POINT display_stoptime; + TIME_POINT display_stoptime = m_running ? + std::chrono::system_clock::now() : + m_stoptime; - if( m_running ) - display_stoptime = std::chrono::system_clock::now(); - else - display_stoptime = m_stoptime; - - std::chrono::duration d = display_stoptime - m_starttime; - std::cerr << m_name << " took " << std::setprecision(1) << d.count() << "milliseconds." << std::endl; + std::chrono::duration elapsed = display_stoptime - m_starttime; + std::cerr << m_name << " took " << elapsed.count() << " milliseconds." << std::endl; } /** @@ -98,8 +104,13 @@ public: */ double msecs() const { - std::chrono::duration d = m_stoptime - m_starttime; - return d.count(); + TIME_POINT stoptime = m_running ? + std::chrono::system_clock::now() : + m_stoptime; + + std::chrono::duration elapsed = stoptime - m_starttime; + + return elapsed.count(); } private: @@ -112,4 +123,13 @@ private: }; +/** + * Function GetRunningMicroSecs + * An alternate way to calculate an elapset time (in microsecondes) to class PROF_COUNTER + * @return an ever increasing indication of elapsed microseconds. + * Use this by computing differences between two calls. + * @author Dick Hollenbeck + */ +unsigned GetRunningMicroSecs(); + #endif