]> git.tdb.fi Git - libs/core.git/blob - source/debug/profilingscope.h
Make sure all classes have sensible copy semantics
[libs/core.git] / source / debug / profilingscope.h
1 #ifndef MSP_DEBUG_PROFILINGSCOPE_H_
2 #define MSP_DEBUG_PROFILINGSCOPE_H_
3
4 #include <msp/core/noncopyable.h>
5 #include <msp/time/timestamp.h>
6 #include "profiler.h"
7
8 namespace Msp {
9 namespace Debug {
10
11 /**
12 RAII timing class to accompany Profiler.  Timing starts when an object is
13 created and ends when it goes out of scope.  If there was another object in an
14 outer scope, it is notified of the time used in inner scopes.
15 */
16 class ProfilingScope: private NonCopyable
17 {
18 private:
19         Profiler &profiler;
20         std::string name;
21         ProfilingScope *parent;
22         Time::TimeStamp entry_time;
23         Time::TimeDelta time_spent;
24         Time::TimeDelta child_time;
25
26         ProfilingScope(const ProfilingScope &);
27         ProfilingScope &operator=(const ProfilingScope &);
28 public:
29         ProfilingScope(Profiler &p, const std::string &n);
30         ~ProfilingScope();
31
32         const std::string &get_name() const { return name; }
33         const ProfilingScope *get_parent() const { return parent; }
34         const Time::TimeStamp &get_entry_time() const { return entry_time; }
35         const Time::TimeDelta &get_time_spent() const { return time_spent; }
36         const Time::TimeDelta &get_child_time() const { return child_time; }
37 };
38
39 } // namespace Debug
40 } // namespace Msp
41
42 #endif