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.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..dd3da0a5 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-%u", 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();