void save_stack_trace		()
	{
		if (!g_mem_alloc_gather_stats)
			return;
		
		if (::Random.randF() >= g_mem_alloc_gather_stats_frequency)
			return;

//		OutputDebugStackTrace	("----------------------------------------------------");

		BuildStackTrace		();

		if (g_stackTraceCount <= 2)
			return;

		u32					accumulator = 0;
		VERIFY				(g_stackTraceCount > 2);
		int					*lengths = (int*)_alloca((g_stackTraceCount - 2)*sizeof(int));
		{
			int				*I = lengths;
			for (int i=2; i<g_stackTraceCount; ++i, ++I) {
				*I			= xr_strlen(g_stackTrace[i]);
				accumulator	+= u32((*I)*sizeof(char) + 1);
			}
		}

		PSTR				string = (PSTR)malloc(accumulator);
		{
			PSTR			J = string;
			VERIFY			(g_stackTraceCount > 2);
			int				*I = lengths;
			for (int i=2; i<g_stackTraceCount; ++i, ++I, ++J) {
				memcpy		(J,g_stackTrace[i],*I);
				J			+= *I;
				*J			= '\n';
			}
			*--J			= 0;
		}

		boost::crc_32_type	temp;
		temp.process_block	(string,string + accumulator);
		u32					crc = temp.checksum();

		STATS::iterator		I = stats.find(crc);
		STATS::iterator		E = stats.end();
		for ( ; I != E; ++I) {
			if ((*I).first != crc)
				break;
			
			if (xr_strcmp((*I).second.first,string))
				continue;

			++((*I).second.second);
			return;
		}

		stats.insert		(std::make_pair(crc,std::make_pair(string,1)));
	}
示例#2
0
int ShowBlackBoxUI( EXCEPTION_POINTERS * pExPtrs, HINSTANCE hInstance )
{

	g_initDlg = CreateDialog(hInstance, (LPCTSTR)IDD_INIT_DLG, 
								NULL, (DLGPROC)InitBlackBoxUI_DlgProc);

	//SetWindowPos( g_initDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );  

	g_BlackBoxUIExPtrs = pExPtrs;	
	g_BlackBoxUIHInstance = hInstance;

	g_sysInfoString[0] = 0;
	g_memInfoString[0] = 0;
	g_versionInfoString[0] = 0;
	g_systemProcessListCount = 0;

	//GetOS info now
	ZeroMemory( &g_sysInfo, sizeof(g_sysInfo) );
	GetSystemInfo( &g_sysInfo );	
	
	
	ZeroMemory( &g_OSVersion, sizeof(g_OSVersion) );
	g_OSVersion.dwOSVersionInfoSize = sizeof(g_OSVersion);

	HasOSInfo = GetVersionEx( &g_OSVersion );
	

	ZeroMemory( &g_sysMemoryStatus, sizeof(MEMORYSTATUS) );
	g_sysMemoryStatus.dwLength = sizeof(MEMORYSTATUS);
	GlobalMemoryStatus ( &g_sysMemoryStatus );

	int processorIndex = 0;
	if ( g_sysInfo.dwProcessorType == PROCESSOR_INTEL_386 ) {
		processorIndex = 0;
	}
	else if ( g_sysInfo.dwProcessorType == PROCESSOR_INTEL_486 ) {
		processorIndex = 1;
	}
	else if ( g_sysInfo.dwProcessorType == PROCESSOR_INTEL_PENTIUM ) {
		processorIndex = 2;
	}

	wsprintf( g_sysInfoString, "Number of Processors: %d\nProcessor Type: %s", 
				g_sysInfo.dwNumberOfProcessors,
				g_ProcessorTypes[processorIndex] );


	int osIndex = 0;
	if ( g_OSVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) {
		if ( g_OSVersion.dwMinorVersion == 0 ) {
			osIndex = 0;
		}
		else if ( g_OSVersion.dwMinorVersion > 0 ) {
			osIndex = 1;
		}
	}
	else if ( g_OSVersion.dwPlatformId == VER_PLATFORM_WIN32_NT ) {
		if ( g_OSVersion.dwMajorVersion == 4 ) {
			osIndex = 3;
		}
		else if ( g_OSVersion.dwMajorVersion > 4 ) {
			osIndex = 4;
		}
	}
	wsprintf( g_versionInfoString, "Windows OS: %s\nVersion %d.%04d\nBuild Number %d\n%s\n",
				g_windowsOSTypes[osIndex], 
				g_OSVersion.dwMajorVersion, 
				g_OSVersion.dwMinorVersion,
				g_OSVersion.dwBuildNumber,
				g_OSVersion.szCSDVersion );




	wsprintf( g_memInfoString, 
		"Current Memory Load:\t\t%d%\nTotal Physical Memory:\t\t%d bytes\nAvailable Physical Memory:\t\t%d bytes"\
		"\nTotal Virtual Memory:\t\t%d bytes\nAvailable Virtual Memory:\t\t%d bytes",
		g_sysMemoryStatus.dwMemoryLoad,
		g_sysMemoryStatus.dwTotalPhys,
		g_sysMemoryStatus.dwAvailPhys,
		g_sysMemoryStatus.dwTotalVirtual,
		g_sysMemoryStatus.dwAvailVirtual  );


	if ( g_OSVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) {
		g_systemProcessListCount = 1;
		g_systemProcessList[0] = GetCurrentProcessId();

	}
	else if ( g_OSVersion.dwPlatformId == VER_PLATFORM_WIN32_NT ) {
		/*
		if ( ! EnumProcesses( g_systemProcessList, 512, &g_systemProcessListCount ) ) {
			g_systemProcessListCount = 0;
		}
		else {
			//try and get the module listings
		}
		*/		

		BuildProcessList();
		BuildModuleList();
	}		

	BuildStackTrace();

	DialogBox( hInstance, (LPCTSTR)IDD_BLACKBOX_ERR_DLG, NULL, (DLGPROC)BlackBoxUI_DlgProc);

	GlobalUnlock( g_procModListHandle );
	GlobalFree( g_procModListHandle );

	return TRUE;
}