X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdebug%2Fprofiler.cpp;h=e3d98408d6d2244c47da824c8cf0fde3c0998c89;hb=f4cf84ddec17f4fec0d9ba7e6814a8af8ff50395;hp=af1380000639c9698ae333046654b11026929495;hpb=cac699732d60d05edc73c39075b85f45a91a620a;p=libs%2Fcore.git diff --git a/source/debug/profiler.cpp b/source/debug/profiler.cpp index af13800..e3d9840 100644 --- a/source/debug/profiler.cpp +++ b/source/debug/profiler.cpp @@ -1,12 +1,5 @@ -/* $Id$ - -This file is part of libmspcore -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include "../core/except.h" -#include "../time/units.h" +#include +#include #include "profiler.h" using namespace std; @@ -24,15 +17,15 @@ void Profiler::set_period(unsigned p) if(p==period) return; - period=p; + period = p; for(map::iterator i=scopes.begin(); i!=scopes.end(); ++i) { - ScopeInfo &si=i->second; + ScopeInfo &si = i->second; if(p==0) si.history.clear(); else si.history.assign(period, Time::zero); - si.hist_pos=0; + si.hist_pos = 0; } } @@ -40,50 +33,46 @@ void Profiler::add_scope(const std::string &name) { if(!scopes.count(name)) { - map::iterator i=scopes.insert(map::value_type(name, ScopeInfo())).first; + map::iterator i = scopes.insert(map::value_type(name, ScopeInfo())).first; i->second.history.resize(period); } } ProfilingScope *Profiler::enter(ProfilingScope *ps) { - ProfilingScope *old=inner; - inner=ps; + ProfilingScope *old = inner; + inner = ps; return old; } void Profiler::record(const string &scope_name, const string &parent, const Time::TimeDelta &time, const Time::TimeDelta &child_t) { - map::iterator i=scopes.find(scope_name); + map::iterator i = scopes.find(scope_name); if(i==scopes.end()) { - i=scopes.insert(map::value_type(scope_name, ScopeInfo())).first; + i = scopes.insert(map::value_type(scope_name, ScopeInfo())).first; i->second.history.resize(period); } - ScopeInfo &si=i->second; + ScopeInfo &si = i->second; ++si.calls; ++si.called_from[parent]; - si.total_time+=time; - si.self_time+=time-child_t; + si.total_time += time; + si.self_time += time-child_t; if(period) { - si.avg_time+=time/period-si.history[si.hist_pos]/period; - si.history[si.hist_pos++]=time; + si.avg_time += time/period-si.history[si.hist_pos]/period; + si.history[si.hist_pos++] = time; if(si.hist_pos>=period) - si.hist_pos-=period; + si.hist_pos -= period; } else - si.avg_time=si.total_time/si.calls; + si.avg_time = si.total_time/si.calls; } const Profiler::ScopeInfo &Profiler::scope(const string &sn) const { - map::const_iterator i=scopes.find(sn); - if(i==scopes.end()) - throw KeyError("Unknown scope"); - - return i->second; + return get_item(scopes, sn); }