From 340bf804357c83c2c02f1cdbe532f0fc7b69a379 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 22 Sep 2017 02:09:39 +0200 Subject: [PATCH] Better thread name retrieval. --- client/TracyThread.hpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/client/TracyThread.hpp b/client/TracyThread.hpp index a5d7dc06..bdd5aeff 100755 --- a/client/TracyThread.hpp +++ b/client/TracyThread.hpp @@ -27,7 +27,25 @@ namespace tracy static inline const char* GetThreadName( uint64_t id ) { - static char buf[64]; + static char buf[256]; +#ifdef _MSC_VER +# ifdef NTDDI_WIN10_RS2 + auto hnd = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, id ); + PWSTR tmp; + GetThreadDescription( hnd, &tmp ); + auto ret = wcstombs( buf, tmp, 256 ); + CloseHandle( hnd ); + if( ret != 0 ) + { + return buf; + } +# endif +#else + if( pthread_getname_np( (pthread_t)id, buf, 256 ) == 0 ) + { + return buf; + } +#endif sprintf( buf, "%" PRIu64, id ); return buf; }