mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-26 16:04:34 +00:00
Always fallback to using native thread name...
...even when TRACY_ENABLE is defined.
This commit is contained in:
parent
70e22ad045
commit
9da24b713c
@ -205,61 +205,57 @@ TRACY_API const char* GetThreadName( uint32_t id )
|
|||||||
}
|
}
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
# if defined _WIN32
|
|
||||||
# ifdef TRACY_UWP
|
|
||||||
static auto _GetThreadDescription = &::GetThreadDescription;
|
|
||||||
# else
|
|
||||||
static auto _GetThreadDescription = (t_GetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetThreadDescription" );
|
|
||||||
# endif
|
|
||||||
if( _GetThreadDescription )
|
|
||||||
{
|
|
||||||
auto hnd = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, (DWORD)id );
|
|
||||||
if( hnd != 0 )
|
|
||||||
{
|
|
||||||
PWSTR tmp;
|
|
||||||
_GetThreadDescription( hnd, &tmp );
|
|
||||||
auto ret = wcstombs( buf, tmp, 256 );
|
|
||||||
CloseHandle( hnd );
|
|
||||||
if( ret != 0 )
|
|
||||||
{
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
# elif defined __linux__
|
|
||||||
int cs, fd;
|
|
||||||
char path[32];
|
|
||||||
# ifdef __ANDROID__
|
|
||||||
int tid = gettid();
|
|
||||||
# else
|
|
||||||
int tid = (int) syscall( SYS_gettid );
|
|
||||||
# endif
|
|
||||||
snprintf( path, sizeof( path ), "/proc/self/task/%d/comm", tid );
|
|
||||||
sprintf( buf, "%" PRIu32, id );
|
|
||||||
# ifndef __ANDROID__
|
|
||||||
pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &cs );
|
|
||||||
# endif
|
|
||||||
if ( ( fd = open( path, O_RDONLY ) ) > 0) {
|
|
||||||
int len = read( fd, buf, 255 );
|
|
||||||
if( len > 0 )
|
|
||||||
{
|
|
||||||
buf[len] = 0;
|
|
||||||
if( len > 1 && buf[len-1] == '\n' )
|
|
||||||
{
|
|
||||||
buf[len-1] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close( fd );
|
|
||||||
}
|
|
||||||
# ifndef __ANDROID__
|
|
||||||
pthread_setcancelstate( cs, 0 );
|
|
||||||
# endif
|
|
||||||
return buf;
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
sprintf( buf, "%" PRIu32, id );
|
|
||||||
return buf;
|
#if defined _WIN32
|
||||||
|
# ifdef TRACY_UWP
|
||||||
|
static auto _GetThreadDescription = &::GetThreadDescription;
|
||||||
|
# else
|
||||||
|
static auto _GetThreadDescription = (t_GetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetThreadDescription" );
|
||||||
|
# endif
|
||||||
|
if( _GetThreadDescription )
|
||||||
|
{
|
||||||
|
auto hnd = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, (DWORD)id );
|
||||||
|
if( hnd != 0 )
|
||||||
|
{
|
||||||
|
PWSTR tmp;
|
||||||
|
_GetThreadDescription( hnd, &tmp );
|
||||||
|
auto ret = wcstombs( buf, tmp, 256 );
|
||||||
|
CloseHandle( hnd );
|
||||||
|
if( ret != 0 )
|
||||||
|
{
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif defined __linux__
|
||||||
|
int cs, fd;
|
||||||
|
char path[32];
|
||||||
|
snprintf( path, sizeof( path ), "/proc/self/task/%d/comm", id );
|
||||||
|
sprintf( buf, "%" PRIu32, id );
|
||||||
|
# ifndef __ANDROID__
|
||||||
|
pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &cs );
|
||||||
|
# endif
|
||||||
|
if ( ( fd = open( path, O_RDONLY ) ) > 0) {
|
||||||
|
int len = read( fd, buf, 255 );
|
||||||
|
if( len > 0 )
|
||||||
|
{
|
||||||
|
buf[len] = 0;
|
||||||
|
if( len > 1 && buf[len-1] == '\n' )
|
||||||
|
{
|
||||||
|
buf[len-1] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close( fd );
|
||||||
|
}
|
||||||
|
# ifndef __ANDROID__
|
||||||
|
pthread_setcancelstate( cs, 0 );
|
||||||
|
# endif
|
||||||
|
return buf;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sprintf( buf, "%" PRIu32, id );
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACY_API const char* GetEnvVar( const char* name )
|
TRACY_API const char* GetEnvVar( const char* name )
|
||||||
|
Loading…
Reference in New Issue
Block a user