Added a profiler, which outputs time taken and calls to various functions.
[ipdf/code.git] / src / profiler.h
diff --git a/src/profiler.h b/src/profiler.h
new file mode 100644 (file)
index 0000000..a20b8d8
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef _PROFILER_H
+#define _PROFILER_H
+
+#include <map>
+#include <string>
+#include <stack>
+
+#define PROFILE_SCOPE(name) IPDF::ProfilerScope _localProfZone(name)
+
+namespace IPDF
+{
+       class Profiler
+       {
+       public:
+               Profiler() {}
+               
+               void BeginZone(std::string name);
+               void EndZone();
+
+               void EndFrame();
+       private:
+               struct ProfileZone
+               {
+                       uint64_t tics_begin;
+                       uint64_t tics_end;
+                       uint64_t tics_frame;
+                       uint64_t tics_total;
+                       uint64_t calls_frame;
+                       uint64_t calls_total;
+               };
+
+               std::map<std::string, ProfileZone> m_zones;
+               std::stack<std::string> m_zone_stack;
+       };
+
+       extern Profiler g_profiler;
+       struct ProfilerScope
+       {
+               ProfilerScope(std::string name) { g_profiler.BeginZone(name); }
+               ~ProfilerScope() { g_profiler.EndZone(); }
+       };
+
+}
+
+#endif

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