Bugfixes, performance fixes, tears.
[ipdf/code.git] / src / profiler.h
1 #ifndef _PROFILER_H
2 #define _PROFILER_H
3
4 #include <map>
5 #include <string>
6 #include <stack>
7
8 #define PROFILE_SCOPE(name) IPDF::ProfilerScope _localProfZone(name)
9
10 namespace IPDF
11 {
12         class Profiler
13         {
14         public:
15                 Profiler() : m_enabled(false) {}
16                 
17                 void BeginZone(std::string name);
18                 void EndZone();
19
20                 void EndFrame();
21
22                 void Enable(bool enabled) { m_enabled = enabled; }
23         private:
24                 struct ProfileZone
25                 {
26                         uint64_t tics_begin;
27                         uint64_t tics_end;
28                         uint64_t tics_frame;
29                         uint64_t tics_total;
30                         uint64_t calls_frame;
31                         uint64_t calls_total;
32                 };
33
34                 std::map<std::string, ProfileZone> m_zones;
35                 std::stack<std::string> m_zone_stack;
36                 bool m_enabled;
37         };
38
39         extern Profiler g_profiler;
40         struct ProfilerScope
41         {
42                 ProfilerScope(std::string name) { g_profiler.BeginZone(name); }
43                 ~ProfilerScope() { g_profiler.EndZone(); }
44         };
45
46 }
47
48 #endif

UCC git Repository :: git.ucc.asn.au