X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fprofiler.cpp;fp=src%2Fprofiler.cpp;h=f718637d72e6057e1f95a594bb6a9ea4115786fb;hp=0000000000000000000000000000000000000000;hb=f0b6c9b6b95fde134927c395afbfbbbc057868e6;hpb=6c0dfe752994312ee58d307b383948bfeb2d6e2e diff --git a/src/profiler.cpp b/src/profiler.cpp new file mode 100644 index 0000000..f718637 --- /dev/null +++ b/src/profiler.cpp @@ -0,0 +1,41 @@ +#include "profiler.h" +#include "log.h" + +#include "SDL.h" + +using namespace IPDF; + +Profiler IPDF::g_profiler; + +void Profiler::BeginZone(std::string name) +{ + if (!m_zones.count(name)) + m_zones[name] = ProfileZone{0,0,0,0,0,0}; + m_zones[name].tics_begin = SDL_GetPerformanceCounter(); + m_zone_stack.push(name); +} + +void Profiler::EndZone() +{ + std::string name = m_zone_stack.top(); + m_zone_stack.pop(); + m_zones[name].tics_end = SDL_GetPerformanceCounter(); + m_zones[name].tics_frame += m_zones[name].tics_end - m_zones[name].tics_begin; + m_zones[name].tics_total += m_zones[name].tics_end - m_zones[name].tics_begin; + m_zones[name].calls_frame++; + m_zones[name].calls_total++; +} + +void Profiler::EndFrame() +{ + // Zero all of the frame counts + for (auto& it : m_zones) + { + if (m_enabled) + { + printf("perf_zone\t\"%s\"\t%lu %lu\t%lu %lu\n", it.first.c_str(), it.second.tics_frame * 1000 / SDL_GetPerformanceFrequency(), it.second.calls_frame, it.second.tics_total * 1000 / SDL_GetPerformanceFrequency(), it.second.calls_total); + } + it.second.tics_frame = 0; + it.second.calls_frame = 0; + } +}