Skip to content

Commit

Permalink
Set thread name on Linux for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebear94 committed Sep 18, 2024
1 parent 65ac7a5 commit be3c80a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/framework/global/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,24 @@

#include "runtime.h"

#ifdef Q_OS_LINUX
#include <pthread.h>
#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()
Expand Down

0 comments on commit be3c80a

Please sign in to comment.