diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a98d4ac6c..b9d0fbb908 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,6 +157,10 @@ option( KICAD_DRC_PROTO "Build the DRC prototype QA tool" OFF ) +option( KICAD_GAL_PROFILE + "Enable profiling info for GAL" + OFF ) + # when option KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES is enabled: # PYTHON_EXECUTABLE can be defined when invoking cmake # ( use -DPYTHON_EXECUTABLE=/python.exe or python2 ) @@ -199,6 +203,10 @@ if( KICAD_USE_VALGRIND ) add_definitions( -DKICAD_USE_VALGRIND ) endif() +if( KICAD_GAL_PROFILE ) + add_definitions( -DKICAD_GAL_PROFILE ) +endif() + # Ensure DEBUG is defined for all platforms in Debug builds # change to add_compile_definitions() after minimum required CMake version is 3.12 set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$:DEBUG> ) diff --git a/common/gal/opengl/cached_container.cpp b/common/gal/opengl/cached_container.cpp index 32700f74a4..e14fdee491 100644 --- a/common/gal/opengl/cached_container.cpp +++ b/common/gal/opengl/cached_container.cpp @@ -40,10 +40,10 @@ #include #include -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE #include #include -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ using namespace KIGFX; @@ -308,9 +308,9 @@ void CACHED_CONTAINER::mergeFreeChunks() if( m_freeChunks.size() <= 1 ) // There are no chunks that can be merged return; -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE PROF_COUNTER totalTime; -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ // Reversed free chunks map - this one stores chunk size with its offset as the key std::list freeChunks; @@ -379,7 +379,7 @@ void CACHED_CONTAINER::showUsedChunks() void CACHED_CONTAINER::test() { -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE // Free space check unsigned int freeSpace = 0; FREE_CHUNK_MAP::iterator itf; @@ -405,5 +405,5 @@ void CACHED_CONTAINER::test() assert( ( m_freeSpace + used_space ) == m_currentSize ); // Overlapping check TODO -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ } diff --git a/common/gal/opengl/cached_container_gpu.cpp b/common/gal/opengl/cached_container_gpu.cpp index ce60420744..24b7baaba0 100644 --- a/common/gal/opengl/cached_container_gpu.cpp +++ b/common/gal/opengl/cached_container_gpu.cpp @@ -34,9 +34,9 @@ #include -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE #include -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ using namespace KIGFX; @@ -139,9 +139,9 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize ) if( usedSpace() > aNewSize ) return false; -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE PROF_COUNTER totalTime; -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ GLuint newBuffer; @@ -153,11 +153,11 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize ) // It would be best to use GL_COPY_WRITE_BUFFER here, // but it is not available everywhere -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE GLint eaBuffer = -1; glGetIntegerv( GL_ELEMENT_ARRAY_BUFFER_BINDING, &eaBuffer ); wxASSERT( eaBuffer == 0 ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, newBuffer ); glBufferData( GL_ELEMENT_ARRAY_BUFFER, aNewSize * VERTEX_SIZE, nullptr, GL_DYNAMIC_DRAW ); checkGlError( "creating buffer during defragmentation", __FILE__, __LINE__ ); @@ -208,12 +208,12 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize ) Map(); checkGlError( "switching buffers during defragmentation", __FILE__, __LINE__ ); -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE totalTime.Stop(); wxLogTrace( traceGalCachedContainerGpu, "Defragmented container storing %d vertices / %.1f ms", m_currentSize - m_freeSpace, totalTime.msecs() ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ m_freeSpace += ( aNewSize - m_currentSize ); m_currentSize = aNewSize; @@ -238,9 +238,9 @@ bool CACHED_CONTAINER_GPU::defragmentResizeMemcpy( unsigned int aNewSize ) if( usedSpace() > aNewSize ) return false; -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE PROF_COUNTER totalTime; -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ GLuint newBuffer; VERTEX* newBufferMem; @@ -250,11 +250,11 @@ bool CACHED_CONTAINER_GPU::defragmentResizeMemcpy( unsigned int aNewSize ) // It would be best to use GL_COPY_WRITE_BUFFER here, // but it is not available everywhere -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE GLint eaBuffer = -1; glGetIntegerv( GL_ELEMENT_ARRAY_BUFFER_BINDING, &eaBuffer ); wxASSERT( eaBuffer == 0 ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, newBuffer ); glBufferData( GL_ELEMENT_ARRAY_BUFFER, aNewSize * VERTEX_SIZE, nullptr, GL_DYNAMIC_DRAW ); newBufferMem = static_cast( glMapBuffer( GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY ) ); @@ -273,12 +273,12 @@ bool CACHED_CONTAINER_GPU::defragmentResizeMemcpy( unsigned int aNewSize ) Map(); checkGlError( "switching buffers during defragmentation", __FILE__, __LINE__ ); -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE totalTime.Stop(); wxLogTrace( traceGalCachedContainerGpu, "Defragmented container storing %d vertices / %.1f ms", m_currentSize - m_freeSpace, totalTime.msecs() ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ m_freeSpace += ( aNewSize - m_currentSize ); m_currentSize = aNewSize; diff --git a/common/gal/opengl/cached_container_ram.cpp b/common/gal/opengl/cached_container_ram.cpp index 75c149608e..848ed74fb2 100644 --- a/common/gal/opengl/cached_container_ram.cpp +++ b/common/gal/opengl/cached_container_ram.cpp @@ -34,10 +34,10 @@ #include #include -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE #include #include -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ using namespace KIGFX; @@ -100,9 +100,9 @@ bool CACHED_CONTAINER_RAM::defragmentResize( unsigned int aNewSize ) if( usedSpace() > aNewSize ) return false; -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE PROF_COUNTER totalTime; -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ VERTEX* newBufferMem = static_cast( malloc( aNewSize * VERTEX_SIZE ) ); @@ -115,12 +115,12 @@ bool CACHED_CONTAINER_RAM::defragmentResize( unsigned int aNewSize ) free( m_vertices ); m_vertices = newBufferMem; -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE totalTime.Stop(); wxLogTrace( traceGalCachedContainer, "Defragmented container storing %d vertices / %.1f ms", m_currentSize - m_freeSpace, totalTime.msecs() ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ m_freeSpace += ( aNewSize - m_currentSize ); m_currentSize = aNewSize; diff --git a/common/gal/opengl/gpu_manager.cpp b/common/gal/opengl/gpu_manager.cpp index ea07881c84..c7fae553a1 100644 --- a/common/gal/opengl/gpu_manager.cpp +++ b/common/gal/opengl/gpu_manager.cpp @@ -35,10 +35,10 @@ #include #include -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE #include #include -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ using namespace KIGFX; @@ -153,9 +153,9 @@ void GPU_CACHED_MANAGER::DrawAll() void GPU_CACHED_MANAGER::EndDrawing() { -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE PROF_COUNTER totalRealTime; -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ wxASSERT( m_isDrawing ); @@ -198,9 +198,9 @@ void GPU_CACHED_MANAGER::EndDrawing() glDrawElements( GL_TRIANGLES, m_indicesSize, GL_UNSIGNED_INT, NULL ); -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE wxLogTrace( traceGalProfile, wxT( "Cached manager size: %d" ), m_indicesSize ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); @@ -218,11 +218,11 @@ void GPU_CACHED_MANAGER::EndDrawing() m_isDrawing = false; -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE totalRealTime.Stop(); wxLogTrace( traceGalProfile, wxT( "GPU_CACHED_MANAGER::EndDrawing(): %.1f ms" ), totalRealTime.msecs() ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ } @@ -264,9 +264,9 @@ void GPU_NONCACHED_MANAGER::DrawAll() void GPU_NONCACHED_MANAGER::EndDrawing() { -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE PROF_COUNTER totalRealTime; -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ if( m_container->GetSize() == 0 ) return; @@ -299,9 +299,9 @@ void GPU_NONCACHED_MANAGER::EndDrawing() glDrawArrays( GL_TRIANGLES, 0, m_container->GetSize() ); -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE wxLogTrace( traceGalProfile, wxT( "Noncached manager size: %d" ), m_container->GetSize() ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ // Deactivate vertex array glDisableClientState( GL_COLOR_ARRAY ); @@ -315,11 +315,11 @@ void GPU_NONCACHED_MANAGER::EndDrawing() m_container->Clear(); -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE totalRealTime.Stop(); wxLogTrace( traceGalProfile, wxT( "GPU_NONCACHED_MANAGER::EndDrawing(): %.1f ms" ), totalRealTime.msecs() ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ } void GPU_MANAGER::EnableDepthTest( bool aEnabled ) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 8949e2590d..95690a75d8 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -49,10 +49,10 @@ #include -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE #include #include -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ #include #include @@ -412,9 +412,9 @@ VECTOR2D OPENGL_GAL::getScreenPixelSize() const void OPENGL_GAL::beginDrawing() { -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE PROF_COUNTER totalRealTime( "OPENGL_GAL::beginDrawing()", true ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ wxASSERT_MSG( m_isContextLocked, "GAL_DRAWING_CONTEXT RAII object should have locked context. " "Calling GAL::beginDrawing() directly is not allowed." ); @@ -553,11 +553,11 @@ void OPENGL_GAL::beginDrawing() // Unbind buffers - set compositor for direct drawing m_compositor->SetBuffer( OPENGL_COMPOSITOR::DIRECT_RENDERING ); -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE totalRealTime.Stop(); wxLogTrace( traceGalProfile, wxT( "OPENGL_GAL::beginDrawing(): %.1f ms" ), totalRealTime.msecs() ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ } @@ -565,9 +565,9 @@ void OPENGL_GAL::endDrawing() { wxASSERT_MSG( m_isContextLocked, "What happened to the context lock?" ); -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE PROF_COUNTER totalRealTime( "OPENGL_GAL::endDrawing()", true ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ // Cached & non-cached containers are rendered to the same buffer m_compositor->SetBuffer( m_mainBuffer ); @@ -594,11 +594,11 @@ void OPENGL_GAL::endDrawing() SwapBuffers(); -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE totalRealTime.Stop(); wxLogTrace( traceGalProfile, wxT( "OPENGL_GAL::endDrawing(): %.1f ms" ), totalRealTime.msecs() ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ } diff --git a/common/view/view.cpp b/common/view/view.cpp index b3d8442444..28d739aefe 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -40,9 +40,9 @@ #include #include -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE #include -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ namespace KIGFX { @@ -1124,9 +1124,9 @@ void VIEW::ClearTargets() void VIEW::Redraw() { -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE PROF_COUNTER totalRealTime; -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ VECTOR2D screenSize = m_gal->GetScreenPixelSize(); BOX2D rect( ToWorld( VECTOR2D( 0, 0 ) ), @@ -1147,10 +1147,10 @@ void VIEW::Redraw() markTargetClean( TARGET_NONCACHED ); markTargetClean( TARGET_OVERLAY ); -#ifdef __WXDEBUG__ +#ifdef KICAD_GAL_PROFILE totalRealTime.Stop(); wxLogTrace( traceGalProfile, "VIEW::Redraw(): %.1f ms", totalRealTime.msecs() ); -#endif /* __WXDEBUG__ */ +#endif /* KICAD_GAL_PROFILE */ }