X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fprofiler.cpp;h=13595af5c2f97c8a4b1166b8707312c57ccb9079;hp=4348603c75d4986ab911a4d8c0522912a1fd6ed0;hb=HEAD;hpb=a8297c3461718f2d9afc7a2f8ca620d320ac5f97 diff --git a/src/profiler.cpp b/src/profiler.cpp index 4348603..13595af 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -15,6 +15,14 @@ void Profiler::BeginZone(std::string name) m_zone_stack.push(name); } +void Profiler::AddCounter(std::string name, uint64_t amt) +{ + if (!m_counters.count(name)) + m_counters[name] = amt; + else + m_counters[name] += amt; +} + void Profiler::EndZone() { std::string name = m_zone_stack.top(); @@ -31,10 +39,20 @@ 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 + 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; } + + for (auto& it : m_counters) + { + if (m_enabled) + { + printf("perf_counter\t\"%s\"\t%lu\n", it.first.c_str(), it.second); + } + it.second = 0; + } }