]> git.tdb.fi Git - libs/core.git/blobdiff - source/debug/profilingscope.cpp
Add Debug::Profiler
[libs/core.git] / source / debug / profilingscope.cpp
diff --git a/source/debug/profilingscope.cpp b/source/debug/profilingscope.cpp
new file mode 100644 (file)
index 0000000..f92749b
--- /dev/null
@@ -0,0 +1,30 @@
+#include "../time/utils.h"
+#include "profilingscope.h"
+
+using namespace std;
+
+namespace Msp {
+namespace Debug {
+
+ProfilingScope::ProfilingScope(Profiler &p, const string &n):
+       profiler(p),
+       name(n),
+       parent(profiler.enter(this)),
+       start_t(Time::now())
+{ }
+
+ProfilingScope::~ProfilingScope()
+{
+       const Time::TimeDelta dt=start_t-Time::now();
+       if(parent)
+       {
+               parent->child_t+=dt;
+               profiler.record(name, parent->name, dt, child_t);
+       }
+       else
+               profiler.record(name, string(), dt, child_t);
+       profiler.enter(parent);
+}
+
+} // namespace Debug
+} // namespace Msp