void mem_alloc_show_stats	()
	{
		u32						size = (u32)stats.size();
		STATS_PAIR				*strings = (STATS_PAIR*)_alloca(size*sizeof(STATS_PAIR));
		STATS_PAIR				*e = strings + size;
		STATS_PAIR				*i = strings;

		u32						accumulator = 0;
		STATS::const_iterator	I = stats.begin();
		STATS::const_iterator	E = stats.end();
		for ( ; I != E; ++I, ++i) {
			*i					= (*I).second;
			accumulator			+= (*I).second.second;
		}

		struct predicate {
			static inline bool compare	(const STATS_PAIR &_0, const STATS_PAIR &_1)
			{
				return			(_0.second < _1.second);
			}
		};

		std::sort				(strings,e,predicate::compare);

		int						j = 0;
		for (i = strings; i != e; ++i, ++j) {
			Msg					("%d(%d)-----------------%d[%d]:%5.2f%%------------------",j,size,(*i).second,accumulator,((*i).second*100)/float(accumulator));
			Log					((*i).first);
		}
	}
	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)));
	}
示例#3
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);
}
	void mem_alloc_clear_stats	()
	{
		STATS::iterator			I = stats.begin();
		STATS::iterator			E = stats.end();
		for ( ; I != E; ++I)
			free				((*I).second.first);

		stats.clear				();
	}
示例#5
0
IC	void CSmartCastStats::show					()
{
	if (m_stats.empty()) {
		Msg								("CONGRATULATIONS : SmartCast stats is empty!!!");
		return;
	}

	m_temp.clear						();
	m_temp.insert						(m_temp.begin(),m_stats.begin(),m_stats.end());
	std::sort							(m_temp.begin(),m_temp.end(),CStatsPredicate());
	u32									total = 0;

	xr_vector<CStats>::const_iterator	I = m_temp.begin();
	xr_vector<CStats>::const_iterator	E = m_temp.end();
	for ( ; I != E; ++I)
		total							+= (*I).m_count;

	Msg									("SmartCast stats (different %d, total %d) : ",(u32)m_stats.size(),total);

	I									= m_temp.begin();
	for ( ; I != E; ++I)
		Msg								("%8d %6.2f% : smart_cast<%s>(%s)",(*I).m_count,float((*I).m_count)*100.f/float(total),(*I).m_to,(*I).m_from);
}