changeset 961:92e32e263ae9 toa2019082601

Removed log in IsContextLost (too many calls) + removed glGetError guards on calls (expensive) + added shared_ptr ref count dump in LoaderCache (still needs to figure that one out)
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 26 Aug 2019 11:01:53 +0200
parents 733be18fe140
children e70d75f199c5
files Framework/Loaders/LoaderCache.cpp Framework/Loaders/LoaderCache.h Framework/OpenGL/OpenGLIncludes.h Framework/OpenGL/WebAssemblyOpenGLContext.cpp
diffstat 4 files changed, 44 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Loaders/LoaderCache.cpp	Fri Aug 23 15:02:42 2019 +0200
+++ b/Framework/Loaders/LoaderCache.cpp	Mon Aug 26 11:01:53 2019 +0200
@@ -240,10 +240,36 @@
 #if ORTHANC_ENABLE_WASM != 1
     LockingEmitter::WriterLock lock(lockingEmitter_);
 #endif
+    
+//#ifndef NDEBUG
+    // ISO way of checking for debug builds
+    DebugDisplayObjRefCounts();
+//#endif
     seriesVolumeProgressiveLoaders_.clear();
     multiframeVolumeLoaders_.clear();
     dicomVolumeImageMPRSlicers_.clear();
     dicomStructureSetLoaders_.clear();
   }
 
+
+  template<typename T> void DebugDisplayObjRefCountsInMap(
+    const std::string& name, const std::map<std::string, boost::shared_ptr<T> >& myMap)
+  {
+    LOG(TRACE) << "Map \"" << name << "\" ref counts:";
+    size_t i = 0;
+    for (const auto& it : myMap)
+    {
+      auto ptr = it.second;
+      LOG(TRACE) << "  element #" << i << ": ref count = " << it.second.use_count();
+      i++;
+    }
+  }
+
+  void LoaderCache::DebugDisplayObjRefCounts()
+  {
+    DebugDisplayObjRefCountsInMap("seriesVolumeProgressiveLoaders_", seriesVolumeProgressiveLoaders_);
+    DebugDisplayObjRefCountsInMap("multiframeVolumeLoaders_", multiframeVolumeLoaders_);
+    DebugDisplayObjRefCountsInMap("dicomVolumeImageMPRSlicers_", dicomVolumeImageMPRSlicers_);
+    DebugDisplayObjRefCountsInMap("dicomStructureSetLoaders_", dicomStructureSetLoaders_);
+  }
 }
--- a/Framework/Loaders/LoaderCache.h	Fri Aug 23 15:02:42 2019 +0200
+++ b/Framework/Loaders/LoaderCache.h	Mon Aug 26 11:01:53 2019 +0200
@@ -64,6 +64,7 @@
 
   private:
     
+    void DebugDisplayObjRefCounts();
 #if ORTHANC_ENABLE_WASM == 1
     WebAssemblyOracle& oracle_;
 #else
--- a/Framework/OpenGL/OpenGLIncludes.h	Fri Aug 23 15:02:42 2019 +0200
+++ b/Framework/OpenGL/OpenGLIncludes.h	Mon Aug 26 11:01:53 2019 +0200
@@ -41,9 +41,19 @@
 #endif
 
 #if ORTHANC_ENABLE_SDL == 1
-#include <SDL_video.h>
+# include <SDL_video.h>
+
+# ifdef NDEBUG
+
+// glGetError is very expensive!
 
-#define ORTHANC_OPENGL_CHECK(name) \
+#   define ORTHANC_OPENGL_CHECK(name)
+#   define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg)
+#   define ORTHANC_CHECK_CURRENT_CONTEXT(context)
+
+# else 
+
+#   define ORTHANC_OPENGL_CHECK(name) \
 if(true)                                                                                                                                \
 {                                                                                                                                       \
   GLenum error = glGetError();                                                                                                          \
@@ -54,14 +64,14 @@
   }                                                                                                                                     \
 } else (void)0
 
-#define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg)                          \
+#   define ORTHANC_OPENGL_TRACE_CURRENT_CONTEXT(msg)                          \
 if(true)                                                                   \
 {                                                                          \
   SDL_GLContext ctx = SDL_GL_GetCurrentContext();                          \
   LOG(TRACE) << msg << " | Current OpenGL context is " << std::hex << ctx; \
 } else (void)0
 
-#define ORTHANC_CHECK_CURRENT_CONTEXT(context)                                                                                                         \
+#   define ORTHANC_CHECK_CURRENT_CONTEXT(context)                                                                                                         \
 if(true)                                                                                                                                               \
 {                                                                                                                                                      \
   SDL_GLContext actualCtx = SDL_GL_GetCurrentContext();                                                                                                \
@@ -72,6 +82,8 @@
   }                                                                                                                                                    \
 } else (void)0
 
+# endif
+
 #endif
 
 #if ORTHANC_ENABLE_WASM == 1
--- a/Framework/OpenGL/WebAssemblyOpenGLContext.cpp	Fri Aug 23 15:02:42 2019 +0200
+++ b/Framework/OpenGL/WebAssemblyOpenGLContext.cpp	Mon Aug 26 11:01:53 2019 +0200
@@ -71,7 +71,7 @@
 
       bool IsContextLost()
       {
-        LOG(TRACE) << "IsContextLost() for context " << std::hex << context_ << std::dec;
+        //LOG(TRACE) << "IsContextLost() for context " << std::hex << context_ << std::dec;
         bool apiFlag = (emscripten_is_webgl_context_lost(context_) != 0);
         isContextLost_ = apiFlag;
         return isContextLost_;