refactor Profiler startup/shutdown (#11105)

This commit is contained in:
minggo
2022-05-16 11:36:33 +08:00
committed by GitHub
parent 17874c6fbd
commit b6debf5d3f
4 changed files with 12 additions and 20 deletions
+2 -2
View File
@@ -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();
+2
View File
@@ -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);
+3 -12
View File
@@ -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) {
+5 -6
View File
@@ -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);