Removed profiler listener
This commit is contained in:
parent
7ed4166f0c
commit
6aa677e133
@ -18,6 +18,8 @@
|
||||
|
||||
#include <testbed/framework/json_profiler.h>
|
||||
|
||||
JsonProfiler* g_jsonProfiler = nullptr;
|
||||
|
||||
#define STRING(x) String(x, sizeof(x) - 1)
|
||||
|
||||
JsonProfiler::JsonProfiler()
|
||||
|
@ -19,8 +19,6 @@
|
||||
#ifndef JSON_PROFILER_H
|
||||
#define JSON_PROFILER_H
|
||||
|
||||
#include <testbed/framework/profiler.h>
|
||||
|
||||
#include <bounce/common/settings.h>
|
||||
|
||||
#include <rapidjson/filewritestream.h>
|
||||
@ -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<FileWriteStream>* m_writer;
|
||||
};
|
||||
|
||||
extern JsonProfiler* g_jsonProfiler;
|
||||
|
||||
#endif
|
@ -142,6 +142,10 @@ static void Run()
|
||||
|
||||
g_profilerSt->End();
|
||||
|
||||
#if PROFILE_JSON == 1
|
||||
g_model->UpdateJson();
|
||||
#endif
|
||||
|
||||
g_profiler->End();
|
||||
|
||||
g_view->EndInterface();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
#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
|
@ -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;
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <testbed/framework/profiler.h>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -24,8 +24,6 @@
|
||||
#include <bounce/common/template/array.h>
|
||||
#include <bounce/common/time.h>
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user