X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fprofiler.h;fp=src%2Fprofiler.h;h=e406536ecc74b49876066a5f9eaca7c497b5f1b0;hp=0000000000000000000000000000000000000000;hb=f0b6c9b6b95fde134927c395afbfbbbc057868e6;hpb=6c0dfe752994312ee58d307b383948bfeb2d6e2e;ds=sidebyside diff --git a/src/profiler.h b/src/profiler.h new file mode 100644 index 0000000..e406536 --- /dev/null +++ b/src/profiler.h @@ -0,0 +1,49 @@ +#ifndef _PROFILER_H +#define _PROFILER_H + +#include +#include +#include +#include + +#define PROFILE_SCOPE(name) IPDF::ProfilerScope _localProfZone(name) + +namespace IPDF +{ + class Profiler + { + public: + Profiler() : m_enabled(false) {} + + void BeginZone(std::string name); + void EndZone(); + + void EndFrame(); + + void Enable(bool enabled) { m_enabled = enabled; } + 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 m_zones; + std::stack m_zone_stack; + bool m_enabled; + }; + + extern Profiler g_profiler; + struct ProfilerScope + { + ProfilerScope(std::string name) { g_profiler.BeginZone(name); } + ~ProfilerScope() { g_profiler.EndZone(); } + }; + +} + +#endif