diff --git a/common/TracySystem.cpp b/common/TracySystem.cpp index bfe06266..06398fa1 100644 --- a/common/TracySystem.cpp +++ b/common/TracySystem.cpp @@ -6,6 +6,11 @@ # include #endif +#ifdef __linux__ +#include +#include +#endif + #include #include @@ -135,11 +140,26 @@ const char* GetThreadName( uint64_t id ) } } # endif -# elif defined _GNU_SOURCE && !defined __ANDROID__ && !defined __EMSCRIPTEN__ +# elif defined __GLIBC__ && !defined __ANDROID__ && !defined __EMSCRIPTEN__ if( pthread_getname_np( (pthread_t)id, buf, 256 ) == 0 ) { return buf; } +# elif defined __linux__ + int cs, fd; + char path[32]; + int tid = (int)syscall( SYS_gettid ); + snprintf( path, sizeof(path), "/proc/self/task/%d/comm", tid ); + sprintf( buf, "%" PRIu64, id ); + pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &cs ); + if ((fd = open(path, O_RDONLY)) > 0) { + int len = read( fd, buf, 255 ); + if (len > 0) + buf[len] = 0; + close(fd); + } + pthread_setcancelstate(cs, 0); + return buf; # endif #endif sprintf( buf, "%" PRIu64, id );