1 #include <msp/core/maputils.h>
2 #include <msp/time/units.h>
15 void Profiler::set_period(unsigned p)
21 for(map<string, ScopeInfo>::iterator i=scopes.begin(); i!=scopes.end(); ++i)
23 ScopeInfo &si = i->second;
27 si.history.assign(period, Time::zero);
32 void Profiler::add_scope(const std::string &name)
34 if(!scopes.count(name))
36 map<string, ScopeInfo>::iterator i = scopes.insert(map<string, ScopeInfo>::value_type(name, ScopeInfo())).first;
37 i->second.history.resize(period);
41 ProfilingScope *Profiler::enter(ProfilingScope *ps)
43 ProfilingScope *old = inner;
48 void Profiler::record(const string &scope_name, const string &parent, const Time::TimeDelta &time, const Time::TimeDelta &child_t)
50 map<string, ScopeInfo>::iterator i = scopes.find(scope_name);
53 i = scopes.insert(map<string, ScopeInfo>::value_type(scope_name, ScopeInfo())).first;
54 i->second.history.resize(period);
57 ScopeInfo &si = i->second;
59 ++si.called_from[parent];
60 si.total_time += time;
61 si.self_time += time-child_t;
64 si.avg_time += time/period-si.history[si.hist_pos]/period;
65 si.history[si.hist_pos++] = time;
66 if(si.hist_pos>=period)
67 si.hist_pos -= period;
70 si.avg_time = si.total_time/si.calls;
73 const Profiler::ScopeInfo &Profiler::scope(const string &sn) const
75 return get_item(scopes, sn);
79 Profiler::ScopeInfo::ScopeInfo():