X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fdebug%2Fprofiler.cpp;h=3ccf2987106d423aa313bfa50e1e0080df120533;hp=4251797a974bb33e676b288120c03a57f97f0d1b;hb=967785734be5c3fc6f75da122c2d93ebbb338271;hpb=e7638f74d3e4869020a19dfa1cc700d52373f01c diff --git a/source/debug/profiler.cpp b/source/debug/profiler.cpp index 4251797..3ccf298 100644 --- a/source/debug/profiler.cpp +++ b/source/debug/profiler.cpp @@ -1,10 +1,3 @@ -/* $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 "profiler.h" @@ -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,46 +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-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); + map::const_iterator i = scopes.find(sn); if(i==scopes.end()) throw KeyError("Unknown scope");