profileon/profileoff in debugscript
[ipdf/code.git] / src / profiler.cpp
1 #include "profiler.h"
2 #include "log.h"
3
4 #include "SDL.h" 
5
6 using namespace IPDF;
7
8 Profiler IPDF::g_profiler;
9
10 void Profiler::BeginZone(std::string name)
11 {
12         if (!m_zones.count(name))
13                 m_zones[name] = ProfileZone{0,0,0,0,0,0};
14         m_zones[name].tics_begin = SDL_GetPerformanceCounter();
15         m_zone_stack.push(name);
16 }
17
18 void Profiler::EndZone()
19 {
20         std::string name = m_zone_stack.top();
21         m_zone_stack.pop();
22         m_zones[name].tics_end = SDL_GetPerformanceCounter();
23         m_zones[name].tics_frame += m_zones[name].tics_end - m_zones[name].tics_begin;
24         m_zones[name].tics_total += m_zones[name].tics_end - m_zones[name].tics_begin;
25         m_zones[name].calls_frame++;
26         m_zones[name].calls_total++;
27 }
28
29 void Profiler::EndFrame()
30 {
31         // Zero all of the frame counts
32         for (auto& it : m_zones)
33         {
34                 if (m_enabled)
35                 {
36                         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);
37                 }
38                 it.second.tics_frame = 0;
39                 it.second.calls_frame = 0;
40         }
41 }

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