tracy icon indicating copy to clipboard operation
tracy copied to clipboard

Tracy client slow startup due to Symbol resolution pre-caching

Open KiviTK opened this issue 3 years ago • 6 comments

The Trarcy profilee starts up very slowly in my case, around 2-3 minutes, however after this the applications continues to run normally. A quick glance with a profiler (VerySleepy in this case) shows that almost all this time is taken up by the FindFirstFileW WinAPI function.

I have attached the typical call stack for this function in the application. callstack

Removing Tracy from the build fixes the issue and the application starts up instantly as expected. If breakpoints are added, it is clear that this hang is caused at static initialization time since the breakpoint in main will not get hit until the application starts normally.

KiviTK avatar Oct 21 '22 18:10 KiviTK

Pausing the application in a debugger would seem to be a more sensible approach for finding out what is happening.

wolfpld avatar Nov 03 '22 20:11 wolfpld

Yes, however like I said this occurs during static initialization time, before the main function starts executing, and I do not know the code for Tracy well enough to know where to debug it, a breakpoint in main would only be hit after the initial few minutes of startup. If you can tell me where I should start to debug Tracy I'll see if I can find what is slowing down.

KiviTK avatar Nov 04 '22 01:11 KiviTK

You can just pause the execution in MSVC and look where the threads are stopped.

wolfpld avatar Nov 04 '22 01:11 wolfpld

Same here. Our application is defining TRACY_DBGHELP_LOCK and is locked due to TracyCallstack.cpp is holding the lock. I tried unlocking earlier , and then protecting again the SymLoadModuleEx call, but it was still slow.

Commenting the SymLoadModuleEx and unlocking early seems to do the trick.

diff -r b979ac45de4f tracy/public/client/TracyCallstack.cpp
--- a/tracy/public/client/TracyCallstack.cpp	Wed Nov 23 10:52:45 2022 +0100
+++ b/tracy/public/client/TracyCallstack.cpp	Wed Nov 23 12:03:10 2022 +0100
@@ -157,6 +157,10 @@
     SymInitialize( GetCurrentProcess(), nullptr, true );
     SymSetOptions( SYMOPT_LOAD_LINES );
 
+#ifdef TRACY_DBGHELP_LOCK
+    DBGHELP_UNLOCK;
+#endif
+
     DWORD needed;
     LPVOID dev[4096];
     if( EnumDeviceDrivers( dev, sizeof(dev), &needed ) != 0 )
@@ -193,7 +197,9 @@
                         path = full;
                     }
 
-                    SymLoadModuleEx( GetCurrentProcess(), nullptr, path, nullptr, (DWORD64)dev[i], 0, nullptr, 0 );
+                    // DBGHELP_LOCK
+                    // SymLoadModuleEx( GetCurrentProcess(), nullptr, path, nullptr, (DWORD64)dev[i], 0, nullptr, 0 );
+                    // DBGHELP_UNLOCK
 
                     const auto psz = strlen( path );
                     auto pptr = (char*)tracy_malloc_fast( psz+1 );
@@ -245,7 +251,7 @@
     }
 
 #ifdef TRACY_DBGHELP_LOCK
-    DBGHELP_UNLOCK;
+    // DBGHELP_UNLOCK;
 #endif
 }
 

sacereda avatar Nov 23 '22 11:11 sacereda