8 Profiler IPDF::g_profiler;
10 void Profiler::BeginZone(std::string name)
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);
18 void Profiler::AddCounter(std::string name, uint64_t amt)
20 if (!m_counters.count(name))
21 m_counters[name] = amt;
23 m_counters[name] += amt;
26 void Profiler::EndZone()
28 std::string name = m_zone_stack.top();
30 m_zones[name].tics_end = SDL_GetPerformanceCounter();
31 m_zones[name].tics_frame += m_zones[name].tics_end - m_zones[name].tics_begin;
32 m_zones[name].tics_total += m_zones[name].tics_end - m_zones[name].tics_begin;
33 m_zones[name].calls_frame++;
34 m_zones[name].calls_total++;
37 void Profiler::EndFrame()
39 // Zero all of the frame counts
40 for (auto& it : m_zones)
44 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);
46 it.second.tics_frame = 0;
47 it.second.calls_frame = 0;
50 for (auto& it : m_counters)
54 printf("perf_counter\t\"%s\"\t%lu\n", it.first.c_str(), it.second);