From 6fb73a3d97d7b083824d62cff6fb4c9d2b463ae0 Mon Sep 17 00:00:00 2001 From: Arvid Gerstmann Date: Sat, 14 Jul 2018 13:26:55 +0200 Subject: [PATCH 1/3] Implement getname alternative if it's not available --- common/TracySystem.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 ); From f04e67779c30feccff7a3d2f24b103d58d4423da Mon Sep 17 00:00:00 2001 From: Arvid Gerstmann Date: Sat, 14 Jul 2018 13:46:25 +0200 Subject: [PATCH 2/3] Fix some minor code style issues --- common/TracySystem.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/TracySystem.cpp b/common/TracySystem.cpp index 06398fa1..7cf961b7 100644 --- a/common/TracySystem.cpp +++ b/common/TracySystem.cpp @@ -148,17 +148,17 @@ const char* GetThreadName( uint64_t id ) # 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 ); + 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) { + if ( ( fd = open( path, O_RDONLY ) ) > 0) { int len = read( fd, buf, 255 ); - if (len > 0) + if ( len > 0 ) buf[len] = 0; - close(fd); + close( fd ); } - pthread_setcancelstate(cs, 0); + pthread_setcancelstate( cs, 0 ); return buf; # endif #endif From 69dac3f611b9f1c83b1587ab6f0cfe138e3ef2aa Mon Sep 17 00:00:00 2001 From: Arvid Gerstmann Date: Tue, 24 Jul 2018 13:43:25 +0200 Subject: [PATCH 3/3] Fix accessing the thread id on Android --- common/TracySystem.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/TracySystem.cpp b/common/TracySystem.cpp index 7cf961b7..a1f8f5bc 100644 --- a/common/TracySystem.cpp +++ b/common/TracySystem.cpp @@ -7,8 +7,10 @@ #endif #ifdef __linux__ -#include -#include +# ifndef __ANDROID__ +# include +# endif +# include #endif #include @@ -148,7 +150,11 @@ const char* GetThreadName( uint64_t id ) # 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, "%" PRIu64, id ); pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &cs );