mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 12:23:53 +00:00
Set worker thread name.
This commit is contained in:
parent
a5d6039aea
commit
4a05da273f
@ -1,6 +1,7 @@
|
||||
#include <assert.h>
|
||||
|
||||
#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()
|
||||
|
49
client/TracySystem.cpp
Executable file
49
client/TracySystem.cpp
Executable file
@ -0,0 +1,49 @@
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
#else
|
||||
# include <pthread.h>
|
||||
# include <unistd.h>
|
||||
#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<HANDLE>( 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
|
||||
|
||||
}
|
||||
|
||||
}
|
13
client/TracySystem.hpp
Executable file
13
client/TracySystem.hpp
Executable file
@ -0,0 +1,13 @@
|
||||
#ifndef __TRACYSYSTEM_HPP__
|
||||
#define __TRACYSYSTEM_HPP__
|
||||
|
||||
#include <thread>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
void SetThreadName( std::thread& thread, const char* name );
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user