Add env var "TRACY_NO_DBHELP_INIT_LOAD" to allow disabling dbghelp loading of DeviceDriver and ProcessModules at startup

This commit is contained in:
Tiago Rodrigues 2023-11-10 17:02:03 -05:00
parent 4c94b3eff7
commit 790d28911d

View File

@ -157,9 +157,20 @@ void InitCallstack()
SymInitialize( GetCurrentProcess(), nullptr, true ); SymInitialize( GetCurrentProcess(), nullptr, true );
SymSetOptions( SYMOPT_LOAD_LINES ); SymSetOptions( SYMOPT_LOAD_LINES );
// use TRACY_NO_DBHELP_INIT_LOAD=1 to disable preloading of driver
// and process module symbol loading at startup time - they will be loaded on demand later
// Sometimes this process can take a very long time and prevent resolving callstack frames
// symbols during that time.
const char* noInitLoadEnv = GetEnvVar("TRACY_NO_DBHELP_INIT_LOAD");
const bool initTimeLoadModules = !(noInitLoadEnv && noInitLoadEnv[0] == '1');
if (!initTimeLoadModules)
{
printf("TRACY: skipping init dbhelper module load\n");
}
DWORD needed; DWORD needed;
LPVOID dev[4096]; LPVOID dev[4096];
if( EnumDeviceDrivers( dev, sizeof(dev), &needed ) != 0 ) if( initTimeLoadModules && (EnumDeviceDrivers( dev, sizeof(dev), &needed ) != 0) )
{ {
char windir[MAX_PATH]; char windir[MAX_PATH];
if( !GetWindowsDirectoryA( windir, sizeof( windir ) ) ) memcpy( windir, "c:\\windows", 11 ); if( !GetWindowsDirectoryA( windir, sizeof( windir ) ) ) memcpy( windir, "c:\\windows", 11 );
@ -214,7 +225,7 @@ void InitCallstack()
HANDLE proc = GetCurrentProcess(); HANDLE proc = GetCurrentProcess();
HMODULE mod[1024]; HMODULE mod[1024];
if( EnumProcessModules( proc, mod, sizeof( mod ), &needed ) != 0 ) if( initTimeLoadModules && (EnumProcessModules( proc, mod, sizeof( mod ), &needed ) != 0) )
{ {
const auto sz = needed / sizeof( HMODULE ); const auto sz = needed / sizeof( HMODULE );
for( size_t i=0; i<sz; i++ ) for( size_t i=0; i<sz; i++ )