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)));
	}
Example #2
0
IC	void CSmartCastStats::add					(LPCSTR from, LPCSTR to)
{
	CStats					temp(from,to,1);
	STATS::iterator			I = m_stats.find(temp);
	if (I == m_stats.end())
		m_stats.insert		(temp);
	else
		++(const_cast<CStats&>(*I).m_count);
}