diff --git a/examples/testbed/framework/json_profiler.cpp b/examples/testbed/framework/json_profiler.cpp index ac2415c..bce7c98 100644 --- a/examples/testbed/framework/json_profiler.cpp +++ b/examples/testbed/framework/json_profiler.cpp @@ -18,6 +18,8 @@ #include +JsonProfiler* g_jsonProfiler = nullptr; + #define STRING(x) String(x, sizeof(x) - 1) JsonProfiler::JsonProfiler() diff --git a/examples/testbed/framework/json_profiler.h b/examples/testbed/framework/json_profiler.h index 8266302..dc547a5 100644 --- a/examples/testbed/framework/json_profiler.h +++ b/examples/testbed/framework/json_profiler.h @@ -19,8 +19,6 @@ #ifndef JSON_PROFILER_H #define JSON_PROFILER_H -#include - #include #include @@ -28,30 +26,32 @@ using namespace rapidjson; -// The following profiler listener is notified by a profiler when events are initiated +// The following profiler is notified when events are initiated // or terminated. // When it receives the notification it immediately saves its data into a .json file format. // The .json file can be read and interpreted by the Google Chrome Tracing. // Say chrome://tracing to the web browser and load the file // This file is by default called "profile.json". Any name can be given. // For implementation details, see json_profile.cpp. -class JsonProfiler : public ProfilerListener +class JsonProfiler { public: JsonProfiler(); ~JsonProfiler(); - void BeginEvents() override; + void BeginEvents(); - void EndEvents() override; + void EndEvents(); - void BeginEvent(const char* name, float64 time) override; + void BeginEvent(const char* name, float64 time); - void EndEvent(const char* name, float64 time) override; + void EndEvent(const char* name, float64 time); private: - FILE * m_file; + FILE* m_file; FileWriteStream* m_stream; Writer* m_writer; }; +extern JsonProfiler* g_jsonProfiler; + #endif \ No newline at end of file diff --git a/examples/testbed/framework/main.cpp b/examples/testbed/framework/main.cpp index 3917fd1..823170d 100644 --- a/examples/testbed/framework/main.cpp +++ b/examples/testbed/framework/main.cpp @@ -142,6 +142,10 @@ static void Run() g_profilerSt->End(); +#if PROFILE_JSON == 1 + g_model->UpdateJson(); +#endif + g_profiler->End(); g_view->EndInterface(); diff --git a/examples/testbed/framework/model.cpp b/examples/testbed/framework/model.cpp index d15067b..ce522d8 100644 --- a/examples/testbed/framework/model.cpp +++ b/examples/testbed/framework/model.cpp @@ -29,7 +29,7 @@ Model::Model() g_profilerSt = &m_profilerSt; #if (PROFILE_JSON == 1) - g_profilerListener = &m_jsonListener; + g_jsonProfiler = &m_jsonProfiler; #endif m_test = nullptr; @@ -59,7 +59,7 @@ Model::~Model() g_profilerSt = nullptr; #if (PROFILE_JSON == 1) - g_profilerListener = nullptr; + g_jsonProfiler = nullptr; #endif delete m_test; @@ -229,4 +229,34 @@ void Model::Update() m_test->Step(); m_draw.Flush(); -} \ No newline at end of file +} + +#if (PROFILE_JSON == 1) + +static inline void RecurseEvents(ProfilerNode* node) +{ + g_jsonProfiler->BeginEvent(node->name, node->t0); + + g_jsonProfiler->EndEvent(node->name, node->t1); + + for (u32 i = 0; i < node->children.Count(); ++i) + { + RecurseEvents(node->children[i]); + } +} + +void Model::UpdateJson() +{ + m_jsonProfiler.BeginEvents(); + + ProfilerNode* root = m_profiler.GetRoot(); + + if (root) + { + RecurseEvents(root); + } + + m_jsonProfiler.EndEvents(); +} + +#endif \ No newline at end of file diff --git a/examples/testbed/framework/model.h b/examples/testbed/framework/model.h index 017c7ce..f586afa 100644 --- a/examples/testbed/framework/model.h +++ b/examples/testbed/framework/model.h @@ -61,7 +61,11 @@ public: void Command_ZoomCamera(float32 d); void Update(); - + +#if (PROFILE_JSON == 1) + void UpdateJson(); +#endif + bool IsPaused() const { return m_pause; } private: friend class ViewModel; @@ -74,7 +78,7 @@ private: ProfilerSt m_profilerSt; #if (PROFILE_JSON == 1) - JsonProfiler m_jsonListener; + JsonProfiler m_jsonProfiler; #endif Test* m_test; diff --git a/examples/testbed/framework/profiler.cpp b/examples/testbed/framework/profiler.cpp index faef74e..fea9077 100644 --- a/examples/testbed/framework/profiler.cpp +++ b/examples/testbed/framework/profiler.cpp @@ -19,7 +19,6 @@ #include Profiler* g_profiler = nullptr; -ProfilerListener* g_profilerListener = nullptr; Profiler::Profiler() : m_pool(sizeof(ProfilerNode)) { @@ -89,23 +88,6 @@ void Profiler::Begin() assert(m_top == nullptr); } -static inline void RecurseEvents(ProfilerNode* node) -{ - ProfilerListener* listener = g_profilerListener; - - if (listener) - { - listener->BeginEvent(node->name, node->t0); - - listener->EndEvent(node->name, node->t1); - } - - for (u32 i = 0; i < node->children.Count(); ++i) - { - RecurseEvents(node->children[i]); - } -} - void Profiler::RecurseDestroyNode(ProfilerNode* node) { for (u32 i = 0; i < node->children.Count(); ++i) @@ -119,24 +101,10 @@ void Profiler::RecurseDestroyNode(ProfilerNode* node) void Profiler::End() { assert(m_top == nullptr); - - ProfilerListener* listener = g_profilerListener; - - if (listener) - { - listener->BeginEvents(); - } if (m_root) { - RecurseEvents(m_root); - RecurseDestroyNode(m_root); m_root = nullptr; } - - if (listener) - { - listener->EndEvents(); - } } \ No newline at end of file diff --git a/examples/testbed/framework/profiler.h b/examples/testbed/framework/profiler.h index 75861f8..3940537 100644 --- a/examples/testbed/framework/profiler.h +++ b/examples/testbed/framework/profiler.h @@ -24,8 +24,6 @@ #include #include -class ProfilerListener; - // Profiler node struct ProfilerNode { @@ -75,33 +73,4 @@ private: extern Profiler* g_profiler; -// Any implementation of this interface passed to Profiler::End will listen to profile events. -class ProfilerListener -{ -public: - virtual ~ProfilerListener() { } - - // This function is called when profiling has began. - virtual void BeginEvents() { } - - // This function is called when profiling has ended. - virtual void EndEvents() { } - - // This function is called when a profiler event begins. - virtual void BeginEvent(const char* name, float64 time) - { - B3_NOT_USED(name); - B3_NOT_USED(time); - } - - // This function is called when a profiler event ends. - virtual void EndEvent(const char* name, float64 time) - { - B3_NOT_USED(name); - B3_NOT_USED(time); - } -}; - -extern ProfilerListener* g_profilerListener; - #endif \ No newline at end of file