X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fprofiler.cpp;fp=src%2Fprofiler.cpp;h=4348603c75d4986ab911a4d8c0522912a1fd6ed0;hp=0000000000000000000000000000000000000000;hb=a8297c3461718f2d9afc7a2f8ca620d320ac5f97;hpb=667281b828c8515e995c0000706157cee180fa08 diff --git a/src/profiler.cpp b/src/profiler.cpp new file mode 100644 index 0000000..4348603 --- /dev/null +++ b/src/profiler.cpp @@ -0,0 +1,40 @@ +#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) + { +#ifndef PROFILER_SILENT + Debug("Perf: Zone \"%s\" frame: %d ms (%d calls), total: %d ms (%d calls)", 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); +#endif + it.second.tics_frame = 0; + it.second.calls_frame = 0; + } +}