]> git.tdb.fi Git - libs/core.git/blob - source/debug/profilingscope.cpp
ffb093a4b3c90a56f7ce9e3b3f9befb405bcbe92
[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