/* * bfVFS : vfs/Tools/vfs_profiler.cpp * - basic profiler class and macros to measure execution time of code blocks * * Copyright (C) 2008 - 2010 (BF) john.bf.smith@googlemail.com * * This file is part of the bfVFS library * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define NOMINMAX #include #include #include #include namespace vfs { class CProfileStarter { public: CProfileStarter() { Profiler::getProfiler(); } }; static CProfileStarter starter; } vfs::Profiler& vfs::Profiler::getProfiler() { static Profiler* _prof = new Profiler; return *_prof; } vfs::Profiler::Profiler() { m_vMarker.resize(1024); _nextMarker = 0; } void vfs::Profiler::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; } vfs::Profiler::tMarkerID vfs::Profiler::registerMarker(const char *marker) { m_vMarker[_nextMarker].markername = marker; return _nextMarker++; } void vfs::Profiler::startMarker(tMarkerID id) { m_vMarker[id].timer.startTimer(); } void vfs::Profiler::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