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(); }