From 5aac97a5b0c5a84deb040038bcc7a93b55347700 Mon Sep 17 00:00:00 2001 From: Huang Date: Mon, 15 Jul 2019 11:25:41 +0800 Subject: [PATCH 1/2] [feat] opt and extend Optick::EventDescription::CreateShared --- src/optick.h | 1 + src/optick_core.cpp | 27 ++++++++++++++++++++++++++- src/optick_core.h | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/optick.h b/src/optick.h index 3ebdf15c..20790bcb 100644 --- a/src/optick.h +++ b/src/optick.h @@ -499,6 +499,7 @@ struct OPTICK_API EventDescription static EventDescription* Create(const char* eventName, const char* fileName, const unsigned long fileLine, const unsigned long eventColor = Color::Null, const unsigned long filter = 0); static EventDescription* CreateShared(const char* eventName, const char* fileName = nullptr, const unsigned long fileLine = 0, const unsigned long eventColor = Color::Null, const unsigned long filter = 0); + static EventDescription* CreateShared(unsigned long long hash, const char* eventName, const char* fileName = nullptr, const unsigned long fileLine = 0, const unsigned long eventColor = Color::Null, const unsigned long filter = 0); EventDescription(); private: diff --git a/src/optick_core.cpp b/src/optick_core.cpp index 287da686..6a553a25 100644 --- a/src/optick_core.cpp +++ b/src/optick_core.cpp @@ -206,6 +206,11 @@ EventDescription* EventDescription::CreateShared(const char* eventName, const ch return EventDescriptionBoard::Get().CreateSharedDescription(eventName, fileName, fileLine, eventColor, filter); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +EventDescription* EventDescription::CreateShared(unsigned long long hash, const char* eventName, const char* fileName, const unsigned long fileLine, const unsigned long eventColor /*= Color::Null*/, const unsigned long filter /*= 0*/) +{ + return EventDescriptionBoard::Get().CreateSharedDescription(hash, eventName, fileName, fileLine, eventColor, filter); +} +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// EventDescription::EventDescription() : name(""), file(""), line(0), color(0) { } @@ -444,7 +449,27 @@ EventDescription* EventDescriptionBoard::CreateDescription(const char* name, con //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// EventDescription* EventDescriptionBoard::CreateSharedDescription(const char* name, const char* file /*= nullptr*/, uint32_t line /*= 0*/, uint32_t color /*= Color::Null*/, uint32_t filter /*= 0*/) { - StringHash nameHash(name); + char hashBuf[256] = { 0 }; + snprintf(hashBuf, 256, "%s-%s-%d", name, file, line); + StringHash nameHash(hashBuf); + + std::lock_guard lock(sharedLock); + + std::pair cached = sharedDescriptions.insert({ nameHash, nullptr }); + + if (cached.second) + { + const char* nameCopy = sharedNames.Add(name, strlen(name) + 1, false); + cached.first->second = CreateDescription(nameCopy, file, line, color, filter); + } + + return cached.first->second; +} +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +EventDescription* EventDescriptionBoard::CreateSharedDescription(unsigned long long hash, + const char* name, const char* file /*= nullptr*/, uint32_t line /*= 0*/, uint32_t color /*= Color::Null*/, uint32_t filter /*= 0*/) +{ + StringHash nameHash(hash); std::lock_guard lock(sharedLock); diff --git a/src/optick_core.h b/src/optick_core.h index a15bd1a6..15133299 100644 --- a/src/optick_core.h +++ b/src/optick_core.h @@ -183,6 +183,8 @@ class EventDescriptionBoard public: EventDescription* CreateDescription(const char* name, const char* file = nullptr, uint32_t line = 0, uint32_t color = Color::Null, uint32_t filter = 0); EventDescription* CreateSharedDescription(const char* name, const char* file = nullptr, uint32_t line = 0, uint32_t color = Color::Null, uint32_t filter = 0); + EventDescription* CreateSharedDescription(unsigned long long hash, + const char* name, const char* file = nullptr, uint32_t line = 0, uint32_t color = Color::Null, uint32_t filter = 0); static EventDescriptionBoard& Get(); From a1ac05fbc0fe6ff0a0d2152bc63c3b3aef61d285 Mon Sep 17 00:00:00 2001 From: Huang Date: Mon, 15 Jul 2019 11:36:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[fix]=20CreateSharedDescription=EF=BC=8Chtt?= =?UTF-8?q?ps://app.codacy.com/app/bombomby/optick/pullRequest=3Fprid=3D38?= =?UTF-8?q?54814?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + src/optick_core.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b4bba0c2..1479d3d8 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ Publish/ .DS_Store /Samples/UnrealEnginePlugin/Binaries /.vs +/.idea diff --git a/src/optick_core.cpp b/src/optick_core.cpp index 6a553a25..dd3da0a5 100644 --- a/src/optick_core.cpp +++ b/src/optick_core.cpp @@ -450,7 +450,7 @@ EventDescription* EventDescriptionBoard::CreateDescription(const char* name, con EventDescription* EventDescriptionBoard::CreateSharedDescription(const char* name, const char* file /*= nullptr*/, uint32_t line /*= 0*/, uint32_t color /*= Color::Null*/, uint32_t filter /*= 0*/) { char hashBuf[256] = { 0 }; - snprintf(hashBuf, 256, "%s-%s-%d", name, file, line); + snprintf(hashBuf, 256, "%s-%s-%u", name, file, line); StringHash nameHash(hashBuf); std::lock_guard lock(sharedLock);