Removed profiler listener
This commit is contained in:
parent
7ed4166f0c
commit
6aa677e133
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#include <testbed/framework/json_profiler.h>
|
#include <testbed/framework/json_profiler.h>
|
||||||
|
|
||||||
|
JsonProfiler* g_jsonProfiler = nullptr;
|
||||||
|
|
||||||
#define STRING(x) String(x, sizeof(x) - 1)
|
#define STRING(x) String(x, sizeof(x) - 1)
|
||||||
|
|
||||||
JsonProfiler::JsonProfiler()
|
JsonProfiler::JsonProfiler()
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
#ifndef JSON_PROFILER_H
|
#ifndef JSON_PROFILER_H
|
||||||
#define JSON_PROFILER_H
|
#define JSON_PROFILER_H
|
||||||
|
|
||||||
#include <testbed/framework/profiler.h>
|
|
||||||
|
|
||||||
#include <bounce/common/settings.h>
|
#include <bounce/common/settings.h>
|
||||||
|
|
||||||
#include <rapidjson/filewritestream.h>
|
#include <rapidjson/filewritestream.h>
|
||||||
@ -28,30 +26,32 @@
|
|||||||
|
|
||||||
using namespace rapidjson;
|
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.
|
// or terminated.
|
||||||
// When it receives the notification it immediately saves its data into a .json file format.
|
// 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.
|
// The .json file can be read and interpreted by the Google Chrome Tracing.
|
||||||
// Say chrome://tracing to the web browser and load the file
|
// Say chrome://tracing to the web browser and load the file
|
||||||
// This file is by default called "profile.json". Any name can be given.
|
// This file is by default called "profile.json". Any name can be given.
|
||||||
// For implementation details, see json_profile.cpp.
|
// For implementation details, see json_profile.cpp.
|
||||||
class JsonProfiler : public ProfilerListener
|
class JsonProfiler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonProfiler();
|
JsonProfiler();
|
||||||
~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:
|
private:
|
||||||
FILE * m_file;
|
FILE* m_file;
|
||||||
FileWriteStream* m_stream;
|
FileWriteStream* m_stream;
|
||||||
Writer<FileWriteStream>* m_writer;
|
Writer<FileWriteStream>* m_writer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern JsonProfiler* g_jsonProfiler;
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -142,6 +142,10 @@ static void Run()
|
|||||||
|
|
||||||
g_profilerSt->End();
|
g_profilerSt->End();
|
||||||
|
|
||||||
|
#if PROFILE_JSON == 1
|
||||||
|
g_model->UpdateJson();
|
||||||
|
#endif
|
||||||
|
|
||||||
g_profiler->End();
|
g_profiler->End();
|
||||||
|
|
||||||
g_view->EndInterface();
|
g_view->EndInterface();
|
||||||
|
@ -29,7 +29,7 @@ Model::Model()
|
|||||||
g_profilerSt = &m_profilerSt;
|
g_profilerSt = &m_profilerSt;
|
||||||
|
|
||||||
#if (PROFILE_JSON == 1)
|
#if (PROFILE_JSON == 1)
|
||||||
g_profilerListener = &m_jsonListener;
|
g_jsonProfiler = &m_jsonProfiler;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_test = nullptr;
|
m_test = nullptr;
|
||||||
@ -59,7 +59,7 @@ Model::~Model()
|
|||||||
g_profilerSt = nullptr;
|
g_profilerSt = nullptr;
|
||||||
|
|
||||||
#if (PROFILE_JSON == 1)
|
#if (PROFILE_JSON == 1)
|
||||||
g_profilerListener = nullptr;
|
g_jsonProfiler = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delete m_test;
|
delete m_test;
|
||||||
@ -229,4 +229,34 @@ void Model::Update()
|
|||||||
m_test->Step();
|
m_test->Step();
|
||||||
|
|
||||||
m_draw.Flush();
|
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 Command_ZoomCamera(float32 d);
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
|
#if (PROFILE_JSON == 1)
|
||||||
|
void UpdateJson();
|
||||||
|
#endif
|
||||||
|
|
||||||
bool IsPaused() const { return m_pause; }
|
bool IsPaused() const { return m_pause; }
|
||||||
private:
|
private:
|
||||||
friend class ViewModel;
|
friend class ViewModel;
|
||||||
@ -74,7 +78,7 @@ private:
|
|||||||
ProfilerSt m_profilerSt;
|
ProfilerSt m_profilerSt;
|
||||||
|
|
||||||
#if (PROFILE_JSON == 1)
|
#if (PROFILE_JSON == 1)
|
||||||
JsonProfiler m_jsonListener;
|
JsonProfiler m_jsonProfiler;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Test* m_test;
|
Test* m_test;
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
#include <testbed/framework/profiler.h>
|
#include <testbed/framework/profiler.h>
|
||||||
|
|
||||||
Profiler* g_profiler = nullptr;
|
Profiler* g_profiler = nullptr;
|
||||||
ProfilerListener* g_profilerListener = nullptr;
|
|
||||||
|
|
||||||
Profiler::Profiler() : m_pool(sizeof(ProfilerNode))
|
Profiler::Profiler() : m_pool(sizeof(ProfilerNode))
|
||||||
{
|
{
|
||||||
@ -89,23 +88,6 @@ void Profiler::Begin()
|
|||||||
assert(m_top == nullptr);
|
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)
|
void Profiler::RecurseDestroyNode(ProfilerNode* node)
|
||||||
{
|
{
|
||||||
for (u32 i = 0; i < node->children.Count(); ++i)
|
for (u32 i = 0; i < node->children.Count(); ++i)
|
||||||
@ -119,24 +101,10 @@ void Profiler::RecurseDestroyNode(ProfilerNode* node)
|
|||||||
void Profiler::End()
|
void Profiler::End()
|
||||||
{
|
{
|
||||||
assert(m_top == nullptr);
|
assert(m_top == nullptr);
|
||||||
|
|
||||||
ProfilerListener* listener = g_profilerListener;
|
|
||||||
|
|
||||||
if (listener)
|
|
||||||
{
|
|
||||||
listener->BeginEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_root)
|
if (m_root)
|
||||||
{
|
{
|
||||||
RecurseEvents(m_root);
|
|
||||||
|
|
||||||
RecurseDestroyNode(m_root);
|
RecurseDestroyNode(m_root);
|
||||||
m_root = nullptr;
|
m_root = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listener)
|
|
||||||
{
|
|
||||||
listener->EndEvents();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -24,8 +24,6 @@
|
|||||||
#include <bounce/common/template/array.h>
|
#include <bounce/common/template/array.h>
|
||||||
#include <bounce/common/time.h>
|
#include <bounce/common/time.h>
|
||||||
|
|
||||||
class ProfilerListener;
|
|
||||||
|
|
||||||
// Profiler node
|
// Profiler node
|
||||||
struct ProfilerNode
|
struct ProfilerNode
|
||||||
{
|
{
|
||||||
@ -75,33 +73,4 @@ private:
|
|||||||
|
|
||||||
extern Profiler* g_profiler;
|
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
|
#endif
|
Loading…
x
Reference in New Issue
Block a user