From 45c1d91f959902d7a70e2136ca9d16a3453a48f5 Mon Sep 17 00:00:00 2001 From: +merlan #flirora Date: Tue, 17 Sep 2024 21:06:56 -0400 Subject: [PATCH 1/4] Set thread name on Linux for debugging --- src/framework/global/runtime.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/framework/global/runtime.cpp b/src/framework/global/runtime.cpp index c0acb42ac191e..d95ca2c233803 100644 --- a/src/framework/global/runtime.cpp +++ b/src/framework/global/runtime.cpp @@ -22,11 +22,24 @@ #include "runtime.h" +#ifdef Q_OS_LINUX +#include +#endif + static thread_local std::string s_threadName; void muse::runtime::setThreadName(const std::string& name) { s_threadName = name; +#ifdef Q_OS_LINUX + // Set thread name through pthreads to aid debuggers that display such names. + // Thread names are limited to 16 bytes on Linux, including the + // terminating null. + std::string truncated_name = name.length() > 15 ? name.substr(0, 15) : name; + if (pthread_setname_np(pthread_self(), truncated_name.c_str()) > 0) { + qWarning() << Q_FUNC_INFO << "Couldn't set thread name through pthreads"; + } +#endif } const std::string& muse::runtime::threadName() From 589db2fc384755b93a83a3c7d98a652d79d6bd33 Mon Sep 17 00:00:00 2001 From: +merlan #flirora Date: Wed, 18 Sep 2024 09:37:27 -0400 Subject: [PATCH 2/4] Implement suggestions --- src/framework/global/runtime.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/framework/global/runtime.cpp b/src/framework/global/runtime.cpp index d95ca2c233803..9da72ea46c49d 100644 --- a/src/framework/global/runtime.cpp +++ b/src/framework/global/runtime.cpp @@ -22,7 +22,9 @@ #include "runtime.h" -#ifdef Q_OS_LINUX +#include "log.h" + +#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_MACOS) #include #endif @@ -31,14 +33,17 @@ static thread_local std::string s_threadName; void muse::runtime::setThreadName(const std::string& name) { s_threadName = name; -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) // Set thread name through pthreads to aid debuggers that display such names. // Thread names are limited to 16 bytes on Linux, including the // terminating null. + DO_ASSERT(name.length() <= 15); std::string truncated_name = name.length() > 15 ? name.substr(0, 15) : name; if (pthread_setname_np(pthread_self(), truncated_name.c_str()) > 0) { - qWarning() << Q_FUNC_INFO << "Couldn't set thread name through pthreads"; + LOGW() << "Couldn't set thread name through pthreads"; } +#elif defined(Q_OS_MACOS) + pthread_setname_np(name.c_str()); #endif } From e087e173b30075d3dc38c860fee1b00442692f40 Mon Sep 17 00:00:00 2001 From: +merlan #flirora Date: Wed, 18 Sep 2024 09:38:58 -0400 Subject: [PATCH 3/4] Include correct header for FreeBSD --- src/framework/global/runtime.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/framework/global/runtime.cpp b/src/framework/global/runtime.cpp index 9da72ea46c49d..d7cd0d67f4df5 100644 --- a/src/framework/global/runtime.cpp +++ b/src/framework/global/runtime.cpp @@ -27,6 +27,9 @@ #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_MACOS) #include #endif +#if defined(Q_OS_FREEBSD) +#include // Needed for pthread_setname_np on FreeBSD +#endif static thread_local std::string s_threadName; From 6faf918bfd747052a9d5524408b2c5cd5e63d897 Mon Sep 17 00:00:00 2001 From: +merlan #flirora Date: Thu, 19 Sep 2024 13:11:16 -0400 Subject: [PATCH 4/4] Implement suggestions (part 2) --- src/framework/global/runtime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/framework/global/runtime.cpp b/src/framework/global/runtime.cpp index d7cd0d67f4df5..625576def3c08 100644 --- a/src/framework/global/runtime.cpp +++ b/src/framework/global/runtime.cpp @@ -24,7 +24,7 @@ #include "log.h" -#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_MACOS) +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) #include #endif #if defined(Q_OS_FREEBSD)