David's final changes: more profiler features, fixes.
[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
25                 void AddCounter(std::string name, uint64_t amt);
26         private:
27                 struct ProfileZone
28                 {
29                         uint64_t tics_begin;
30                         uint64_t tics_end;
31                         uint64_t tics_frame;
32                         uint64_t tics_total;
33                         uint64_t calls_frame;
34                         uint64_t calls_total;
35                 };
36
37                 std::map<std::string, ProfileZone> m_zones;
38                 std::map<std::string, uint64_t> m_counters;
39                 std::stack<std::string> m_zone_stack;
40                 bool m_enabled;
41         };
42
43         extern Profiler g_profiler;
44         struct ProfilerScope
45         {
46                 ProfilerScope(std::string name) { g_profiler.BeginZone(name); }
47                 ~ProfilerScope() { g_profiler.EndZone(); }
48         };
49
50 }
51
52 #endif

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