#define NOMINMAX #include "Prof.h" #include "../vfs_types.h" #include "../File/vfs_file.h" #include CProf* g_Profiler = NULL; class CProfileStarter { public: CProfileStarter() { CProf::GetProf(); } }; static CProfileStarter starter; CProf* CProf::GetProf() { if(!g_Profiler) { g_Profiler = new CProf(); } return g_Profiler; } CProf::CProf() { m_vMarker.resize(1024); _nextMarker = 0; } void CProf::Clear() { for(unsigned int i = 0; i < _nextMarker; ++i) { m_vMarker[i].markername = ""; m_vMarker[i].time = 0; m_vMarker[i].call_count = 0; m_vMarker[i].success_count = 0; m_vMarker[i].fail_count = 0; } _nextMarker = 0; } CProf::tMarkerID CProf::RegisterMarker(const char *marker) { m_vMarker[_nextMarker].markername = marker; return _nextMarker++; } void CProf::StartMarker(tMarkerID id) { m_vMarker[id].timer.StartTimer(); } void CProf::StopMarker(tMarkerID id, bool success) { m_vMarker[id].timer.StopTimer(); m_vMarker[id].time += m_vMarker[id].timer.GetElapsedTimeInSeconds(); m_vMarker[id].call_count++; if(success) m_vMarker[id].success_count++; else m_vMarker[id].fail_count++; } inline std::string MultChar(std::string::value_type c, unsigned int multiplicity) { std::string s; s.resize(multiplicity); for(unsigned int i=0; i max_time) { max_time = m_vMarker[i].time; } std::string::size_type prefix_length = m_vMarker[i].markername.length(); if(prefix_length > max_prefix) { max_prefix = prefix_length; } } const unsigned int WIDTH = 40; std::stringstream line; long double ld_success, ld_failure; for(unsigned int i=0; i