diff --git a/examples/testbed/framework/model.cpp b/examples/testbed/framework/model.cpp index df3357d..df07d7f 100644 --- a/examples/testbed/framework/model.cpp +++ b/examples/testbed/framework/model.cpp @@ -26,7 +26,7 @@ Model::Model() g_draw = &m_draw; g_camera = &m_camera; g_profiler = &m_profiler; - g_profilerRecorder = &m_profilerListener.m_recorderProfiler; + g_profilerRecorder = &m_profilerListener.m_recorderListener; g_profilerListener = &m_profilerListener; m_test = nullptr; diff --git a/examples/testbed/framework/profiler.cpp b/examples/testbed/framework/profiler.cpp index 296db7f..3678fe9 100644 --- a/examples/testbed/framework/profiler.cpp +++ b/examples/testbed/framework/profiler.cpp @@ -81,8 +81,6 @@ void Profiler::End() listener->BeginEvent(e.name, e.t0); listener->EndEvent(e.name, e.t1); - - listener->Duration(e.name, e.t1 - e.t0); } } diff --git a/examples/testbed/framework/profiler.h b/examples/testbed/framework/profiler.h index aa18bba..6189092 100644 --- a/examples/testbed/framework/profiler.h +++ b/examples/testbed/framework/profiler.h @@ -92,14 +92,6 @@ public: B3_NOT_USED(name); B3_NOT_USED(time); } - - // This function is called when a profiler event ends. - // However it supplies the duration of the last begin and end events. - virtual void Duration(const char* name, float64 duration) - { - B3_NOT_USED(name); - B3_NOT_USED(duration); - } }; extern ProfilerListener* g_profilerListener; diff --git a/examples/testbed/framework/recorder_profiler.cpp b/examples/testbed/framework/recorder_profiler.cpp index d597a49..016dbf0 100644 --- a/examples/testbed/framework/recorder_profiler.cpp +++ b/examples/testbed/framework/recorder_profiler.cpp @@ -61,27 +61,35 @@ ProfilerRecord* RecorderProfiler::FindRecord(const char* name) return nullptr; } -void RecorderProfiler::Add(const char* name, float64 elapsedTime) +void RecorderProfiler::BeginEvent(const char* name, float64 time) { - B3_ASSERT(elapsedTime >= 0.0); - ++m_call; - + ProfilerRecord* fr = FindRecord(name); if (fr) { - fr->elapsed += elapsedTime; - fr->maxElapsed = b3Max(fr->maxElapsed, elapsedTime); + fr->time = time; fr->call = m_call; - return; } ProfilerRecord r; r.name = name; - r.elapsed = elapsedTime; - r.maxElapsed = elapsedTime; + r.time = time; + r.elapsed = 0.0; + r.maxElapsed = 0.0; r.call = m_call; m_records.PushBack(r); +} + +void RecorderProfiler::EndEvent(const char* name, float64 time) +{ + ProfilerRecord* fr = FindRecord(name); + B3_ASSERT(fr != nullptr); + + float64 elapsedTime = time - fr->time; + + fr->elapsed += elapsedTime; + fr->maxElapsed = b3Max(fr->maxElapsed, elapsedTime); } \ No newline at end of file diff --git a/examples/testbed/framework/recorder_profiler.h b/examples/testbed/framework/recorder_profiler.h index c623851..f7b1fde 100644 --- a/examples/testbed/framework/recorder_profiler.h +++ b/examples/testbed/framework/recorder_profiler.h @@ -26,6 +26,7 @@ struct ProfilerRecord { const char* name; + float64 time; float64 elapsed; float64 maxElapsed; u32 call; @@ -41,7 +42,9 @@ public: void EndEvents(); - void Add(const char* name, float64 elapsedTime); + void BeginEvent(const char* name, float64 time); + + void EndEvent(const char* name, float64 time); ProfilerRecord* FindRecord(const char* name); diff --git a/examples/testbed/framework/testbed_listener.h b/examples/testbed/framework/testbed_listener.h index 847b700..9545384 100644 --- a/examples/testbed/framework/testbed_listener.h +++ b/examples/testbed/framework/testbed_listener.h @@ -36,7 +36,7 @@ class TestbedListener : public ProfilerListener public: void BeginEvents() override { - m_recorderProfiler.BeginEvents(); + m_recorderListener.BeginEvents(); #if (PROFILE_JSON == 1) m_jsonListener.BeginEvents(); @@ -46,7 +46,7 @@ public: void EndEvents() override { - m_recorderProfiler.EndEvents(); + m_recorderListener.EndEvents(); #if (PROFILE_JSON == 1) m_jsonListener.EndEvents(); @@ -56,6 +56,8 @@ public: void BeginEvent(const char* name, float64 time) override { + m_recorderListener.BeginEvent(name, time); + #if (PROFILE_JSON == 1) m_jsonListener.BeginEvent(name, time); #endif @@ -63,18 +65,14 @@ public: void EndEvent(const char* name, float64 time) override { + m_recorderListener.EndEvent(name, time); + #if (PROFILE_JSON == 1) m_jsonListener.EndEvent(name, time); #endif - } - void Duration(const char* name, float64 duration) override - { - m_recorderProfiler.Add(name, duration); - } - - RecorderProfiler m_recorderProfiler; + RecorderProfiler m_recorderListener; #if (PROFILE_JSON == 1) JsonProfiler m_jsonListener;