#include <msp/core/maputils.h>
#include <msp/time/units.h>
#include "profiler.h"
+#include "profilingscope.h"
using namespace std;
return old;
}
-void Profiler::record(const string &scope_name, const string &parent, const Time::TimeDelta &time, const Time::TimeDelta &child_t)
+void Profiler::record(const ProfilingScope &scope)
{
- map<string, ScopeInfo>::iterator i = scopes.find(scope_name);
+ map<string, ScopeInfo>::iterator i = scopes.find(scope.get_name());
if(i==scopes.end())
{
- i = scopes.insert(map<string, ScopeInfo>::value_type(scope_name, ScopeInfo())).first;
+ i = scopes.insert(map<string, ScopeInfo>::value_type(scope.get_name(), ScopeInfo())).first;
i->second.history.resize(period);
}
ScopeInfo &si = i->second;
++si.calls;
- ++si.called_from[parent];
- si.total_time += time;
- si.self_time += time-child_t;
+ if(scope.get_parent())
+ ++si.called_from[scope.get_parent()->get_name()];
+ si.total_time += scope.get_time_spent();
+ si.self_time += scope.get_time_spent()-scope.get_child_time();
if(period)
{
- si.avg_time += time/period-si.history[si.hist_pos]/period;
- si.history[si.hist_pos++] = time;
+ si.avg_time += scope.get_time_spent()/period-si.history[si.hist_pos]/period;
+ si.history[si.hist_pos++] = scope.get_time_spent();
if(si.hist_pos>=period)
si.hist_pos -= period;
}
si.avg_time = si.total_time/si.calls;
}
-const Profiler::ScopeInfo &Profiler::scope(const string &sn) const
+const Profiler::ScopeInfo &Profiler::get_scope(const string &sn) const
{
return get_item(scopes, sn);
}