]> git.tdb.fi Git - libs/core.git/blob - source/debug/profilingscope.cpp
39222342123848e1ba7d768592bff0fbd981b2d1
[libs/core.git] / source / debug / profilingscope.cpp
1 /* $Id$
2
3 This file is part of libmspcore
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "../time/utils.h"
9 #include "profilingscope.h"
10
11 using namespace std;
12
13 namespace Msp {
14 namespace Debug {
15
16 ProfilingScope::ProfilingScope(Profiler &p, const string &n):
17         profiler(p),
18         name(n),
19         parent(profiler.enter(this)),
20         start_t(Time::now())
21 { }
22
23 ProfilingScope::~ProfilingScope()
24 {
25         const Time::TimeDelta dt = Time::now()-start_t;
26         if(parent)
27         {
28                 parent->child_t += dt;
29                 profiler.record(name, parent->name, dt, child_t);
30         }
31         else
32                 profiler.record(name, string(), dt, child_t);
33         profiler.enter(parent);
34 }
35
36 } // namespace Debug
37 } // namespace Msp