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

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