Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] opt and extend Optick::EventDescription::CreateShared #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ Publish/
.DS_Store
/Samples/UnrealEnginePlugin/Binaries
/.vs
/.idea
1 change: 1 addition & 0 deletions src/optick.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 26 additions & 1 deletion src/optick_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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<std::mutex> lock(sharedLock);

std::pair<DescriptionMap::iterator, bool> 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<std::mutex> lock(sharedLock);

Expand Down
2 changes: 2 additions & 0 deletions src/optick_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down