mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
refactor Profiler startup/shutdown (#11105)
This commit is contained in:
@@ -101,7 +101,7 @@ Engine::Engine() {
|
||||
se::ScriptEngine::getInstance();
|
||||
|
||||
#if CC_USE_PROFILER
|
||||
Profiler::getInstance();
|
||||
_profiler = new Profiler();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ Engine::~Engine() {
|
||||
Root::getInstance()->destroy();
|
||||
|
||||
#if CC_USE_PROFILER
|
||||
Profiler::destroyInstance();
|
||||
delete _profiler;
|
||||
#endif
|
||||
DebugRenderer::destroyInstance();
|
||||
FreeTypeFontFace::destroyFreeType();
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
namespace cc {
|
||||
|
||||
class FileUtils;
|
||||
class Profiler;
|
||||
|
||||
#define NANOSECONDS_PER_SECOND 1000000000
|
||||
#define NANOSECONDS_60FPS 16666667L
|
||||
@@ -133,6 +134,7 @@ private:
|
||||
|
||||
// Subsystems
|
||||
FileUtils *_fs{nullptr};
|
||||
Profiler *_profiler{nullptr};
|
||||
|
||||
std::map<OSEventType, EventCb> _eventCallbacks;
|
||||
CC_DISALLOW_COPY_MOVE_ASSIGN(Engine);
|
||||
|
||||
@@ -72,7 +72,6 @@ ProfilerBlock::~ProfilerBlock() {
|
||||
for (auto *child : _children) {
|
||||
CC_SAFE_DELETE(child);
|
||||
}
|
||||
|
||||
_children.clear();
|
||||
}
|
||||
|
||||
@@ -123,29 +122,21 @@ struct ProfilerBlockDepth {
|
||||
*/
|
||||
Profiler *Profiler::instance = nullptr;
|
||||
Profiler *Profiler::getInstance() {
|
||||
if (!instance) {
|
||||
instance = ccnew Profiler();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Profiler::destroyInstance() {
|
||||
if (instance) {
|
||||
delete instance;
|
||||
instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Profiler::Profiler() {
|
||||
_mainThreadId = std::this_thread::get_id();
|
||||
_root = ccnew ProfilerBlock(nullptr, "MainThread");
|
||||
_current = _root;
|
||||
|
||||
Profiler::instance = this;
|
||||
}
|
||||
|
||||
Profiler::~Profiler() {
|
||||
CC_SAFE_DELETE(_root);
|
||||
_current = nullptr;
|
||||
Profiler::instance = nullptr;
|
||||
}
|
||||
|
||||
void Profiler::setEnable(ShowOption option, bool b) {
|
||||
|
||||
@@ -48,14 +48,15 @@ enum class ShowOption : uint32_t {
|
||||
*/
|
||||
class Profiler {
|
||||
public:
|
||||
static Profiler *getInstance();
|
||||
|
||||
Profiler();
|
||||
~Profiler();
|
||||
Profiler(const Profiler &) = delete;
|
||||
Profiler(Profiler &&) = delete;
|
||||
Profiler &operator=(const Profiler &) = delete;
|
||||
Profiler &operator=(Profiler &&) = delete;
|
||||
|
||||
static Profiler *getInstance();
|
||||
static void destroyInstance();
|
||||
|
||||
void setEnable(ShowOption option, bool b = true);
|
||||
bool isEnabled(ShowOption option) const;
|
||||
|
||||
@@ -68,11 +69,9 @@ public:
|
||||
inline ObjectStats &getObjectStats() { return _objectStats; }
|
||||
|
||||
private:
|
||||
Profiler();
|
||||
~Profiler();
|
||||
static void doFrameUpdate();
|
||||
|
||||
void doIntervalUpdate();
|
||||
static void doFrameUpdate();
|
||||
void printStats();
|
||||
|
||||
void beginBlock(const ccstd::string &name);
|
||||
|
||||
Reference in New Issue
Block a user