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
파일: config.hpp 프로젝트: woyager/blizzard
		void clear()
		{
			pid_file_name.clear();
			log_file_name.clear();
			log_level.clear();
			access_log_file_name.clear();
			stats.clear();
			plugin.clear();
		}
예제 #6
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);
}
예제 #7
0
IC	void CSmartCastStats::clear					()
{
	m_stats.clear			();
}
예제 #8
0
BOOL8 test_underline(                   //look for underlines
    BOOL8 testing_on,  //< drawing blob
    C_BLOB *blob,      //< blob to test
    inT16 baseline,    //< coords of baseline
    inT16 xheight      //< height of line
) {
    inT16 occ;
    inT16 blob_width;              //width of blob
    TBOX blob_box;                  //bounding box
    inT32 desc_occ;
    inT32 x_occ;
    inT32 asc_occ;
    STATS projection;

    blob_box = blob->bounding_box ();
    blob_width = blob->bounding_box ().width ();
    projection.set_range (blob_box.bottom (), blob_box.top () + 1);
    if (testing_on) {
        //              blob->plot(to_win,GOLDENROD,GOLDENROD);
        //              line_color_index(to_win,GOLDENROD);
        //              move2d(to_win,blob_box.left(),baseline);
        //              draw2d(to_win,blob_box.right(),baseline);
        //              move2d(to_win,blob_box.left(),baseline+xheight);
        //              draw2d(to_win,blob_box.right(),baseline+xheight);
        tprintf
        ("Testing underline on blob at (%d,%d)->(%d,%d), base=%d\nOccs:",
         blob->bounding_box ().left (), blob->bounding_box ().bottom (),
         blob->bounding_box ().right (), blob->bounding_box ().top (),
         baseline);
    }
    horizontal_cblob_projection(blob, &projection);
    desc_occ = 0;
    for (occ = blob_box.bottom (); occ < baseline; occ++)
        if (occ <= blob_box.top () && projection.pile_count (occ) > desc_occ)
            //max in region
            desc_occ = projection.pile_count (occ);
    x_occ = 0;
    for (occ = baseline; occ <= baseline + xheight; occ++)
        if (occ >= blob_box.bottom () && occ <= blob_box.top ()
                && projection.pile_count (occ) > x_occ)
            //max in region
            x_occ = projection.pile_count (occ);
    asc_occ = 0;
    for (occ = baseline + xheight + 1; occ <= blob_box.top (); occ++)
        if (occ >= blob_box.bottom () && projection.pile_count (occ) > asc_occ)
            asc_occ = projection.pile_count (occ);
    if (testing_on) {
        tprintf ("%d %d %d\n", desc_occ, x_occ, asc_occ);
    }
    if (desc_occ == 0 && x_occ == 0 && asc_occ == 0) {
        tprintf ("Bottom=%d, top=%d, base=%d, x=%d\n",
                 blob_box.bottom (), blob_box.top (), baseline, xheight);
        projection.print (stdout, TRUE);
    }
    if (desc_occ > x_occ + x_occ
            && desc_occ > blob_width * textord_underline_threshold)
        return TRUE;                 //real underline
    if (asc_occ > x_occ + x_occ
            && asc_occ > blob_width * textord_underline_threshold)
        return TRUE;                 //overline
    return FALSE;                  //neither
}
예제 #9
0
VOID Fini(int, VOID * v)
{
    string filename;
    std::ofstream out;

    // dump insmix profile
    
    filename =  KnobOutputFile.Value();

    if( KnobPid )
    {
        filename += "." + decstr( getpid_portable() );
    }
    out.open(filename.c_str());

    out << "INSMIX        1.0         0\n";

    DumpStats(out, GlobalStatsStatic, false, 0, "$static-counts");
    
    out << endl;

    // dynamic Counts 

    sort( statsList.begin(), statsList.end(), CompareLess );
    statsList.push_back(0); // add terminator marker

    STATS DynamicRtn;
    UINT32 rtn_num = 0;

    for (vector<const BBLSTATS*>::iterator bi = statsList.begin(); bi != statsList.end(); bi++)
    {
        const BBLSTATS *b = (*bi);

        if( b  == 0 || rtn_num != b->_rtn_num )
        {
            if( rtn_num>0 && KnobProfileRoutines )
            {
                DumpStats(out, DynamicRtn, false, 0,
                          "$rtn-counts " + longstr(rtn_num, rtn_table[rtn_num]->_name) + " at " + hexstr(rtn_table[rtn_num]->_address) );
                out << "#" << endl;
            }

            if( b != 0 )
            {
                rtn_num = b->_rtn_num;
                DynamicRtn.Clear();
            }
            else
            {
                break;
            }
            
        }

        for (const UINT16 * stats = b->_stats; *stats; stats++)
        {
            ASSERT( *stats < MAX_INDEX,"bad index " + decstr(*stats) + " at " + hexstr(b->_addr) + "\n"  );
            DynamicRtn.unpredicated[*stats] += b->_counter;
            GlobalStatsDynamic.unpredicated[*stats] += b->_counter;
        }

    }

    DumpStats(out, GlobalStatsDynamic, KnobProfilePredicated, 0, "$dynamic-counts");                

    out << "# $eof" <<  endl;

    out.close();


    // dump bblcnt profile

    filename =  KnobOutput2File.Value();

    if( KnobPid )
    {
        filename += "." + decstr( getpid_portable() );
    }

    out.open(filename.c_str());

    out << "BBLCOUNT        1.0         0\n";
     
    for (vector<const BBLSTATS*>::iterator bi = statsList.begin(); bi != statsList.end(); bi++)
    {
        const BBLSTATS *b = (*bi);
        if (b == 0) break; // sentinel
        
        out << "0x" << hex << b->_addr << " " << dec << b->_counter << " " << b->_numins << " " << b->_size << endl;
    }
    
    out << "# $eof" <<  endl;

    out.close();
}