diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 89d53ad2..16db0ef1 100755 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -1,6 +1,7 @@ #include #include "TracyProfiler.hpp" +#include "TracySystem.hpp" namespace tracy { @@ -14,6 +15,7 @@ Profiler::Profiler() s_instance = this; m_thread = std::thread( [this] { Worker(); } ); + SetThreadName( m_thread, "Tracy Profiler" ); } Profiler::~Profiler() diff --git a/client/TracySystem.cpp b/client/TracySystem.cpp new file mode 100755 index 00000000..781f09c4 --- /dev/null +++ b/client/TracySystem.cpp @@ -0,0 +1,49 @@ +#ifdef _WIN32 +# include +#else +# include +# include +#endif + + +#include "TracySystem.hpp" + +namespace tracy +{ + +void SetThreadName( std::thread& thread, const char* name ) +{ +#ifdef _WIN32 + const DWORD MS_VC_EXCEPTION=0x406D1388; + +# pragma pack( push, 8 ) + struct THREADNAME_INFO + { + DWORD dwType; + LPCSTR szName; + DWORD dwThreadID; + DWORD dwFlags; + }; +# pragma pack(pop) + + DWORD ThreadId = GetThreadId( static_cast( thread.native_handle() ) ); + THREADNAME_INFO info; + info.dwType = 0x1000; + info.szName = name; + info.dwThreadID = ThreadId; + info.dwFlags = 0; + + __try + { + RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + } +#else + pthread_setname_np( thread.native_handle(), name ); +#endif + +} + +} \ No newline at end of file diff --git a/client/TracySystem.hpp b/client/TracySystem.hpp new file mode 100755 index 00000000..970d33d4 --- /dev/null +++ b/client/TracySystem.hpp @@ -0,0 +1,13 @@ +#ifndef __TRACYSYSTEM_HPP__ +#define __TRACYSYSTEM_HPP__ + +#include + +namespace tracy +{ + +void SetThreadName( std::thread& thread, const char* name ); + +} + +#endif