diff --git a/src/coreclr/debug/ee/rcthread.cpp b/src/coreclr/debug/ee/rcthread.cpp index 23a61151de436..e7aa9f2b067ce 100644 --- a/src/coreclr/debug/ee/rcthread.cpp +++ b/src/coreclr/debug/ee/rcthread.cpp @@ -1311,6 +1311,11 @@ void DebuggerRCThread::TemporaryHelperThreadMainLoop() DebuggerRCThread* t = (DebuggerRCThread*)g_pRCThread; + if (FAILED(SetThreadName(t->m_thread, W(".NET Debugger")))) + { + LOG((LF_CORDB, LL_INFO10000, "DebuggerRCThread name set failed\n")); + } + t->ThreadProc(); // this thread is local, go and become the helper return 0; @@ -1366,7 +1371,6 @@ HRESULT DebuggerRCThread::Start(void) { LOG((LF_CORDB, LL_EVERYTHING, "DebuggerRCThread failed, err=%d\n", GetLastError())); hr = HRESULT_FROM_GetLastError(); - } else { diff --git a/src/coreclr/debug/shared/dbgtransportsession.cpp b/src/coreclr/debug/shared/dbgtransportsession.cpp index 259e45f42fa23..b1b4cee234038 100644 --- a/src/coreclr/debug/shared/dbgtransportsession.cpp +++ b/src/coreclr/debug/shared/dbgtransportsession.cpp @@ -1227,6 +1227,8 @@ void DbgTransportSession::InitSessionState() // instance method version defined below for convenience in the implementation. DWORD WINAPI DbgTransportSession::TransportWorkerStatic(LPVOID pvContext) { + SetThreadName(GetCurrentThread(), W(".NET DebugPipe")); + ((DbgTransportSession*)pvContext)->TransportWorker(); // Nobody looks at this result, the choice of 0 is arbitrary. diff --git a/src/coreclr/pal/src/synchmgr/synchmanager.cpp b/src/coreclr/pal/src/synchmgr/synchmanager.cpp index 091e746a8170b..d8a4fcfe00b20 100644 --- a/src/coreclr/pal/src/synchmgr/synchmanager.cpp +++ b/src/coreclr/pal/src/synchmgr/synchmanager.cpp @@ -1707,6 +1707,10 @@ namespace CorUnix reinterpret_cast(pArg); CPalThread * pthrWorker = InternalGetCurrentThread(); + InternalSetThreadDescription(pthrWorker, + PAL_GetCurrentThread(), + W(".NET SynchManager")); + while (!fWorkerIsDone) { LONG lProcessCount; diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index a494b4d156607..2f0348d452fa6 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -2047,6 +2047,14 @@ ep_rt_thread_create ( return result; } +static +inline +void +ep_rt_set_server_name() +{ + ::SetThreadName(GetCurrentThread(), W(".NET EventPipe")); +} + static inline void diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.GateThread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.GateThread.cs index 9eff225e7941d..c2a8544479b64 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.GateThread.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.GateThread.cs @@ -239,7 +239,7 @@ private static void CreateGateThread(PortableThreadPool threadPoolInstance) { IsThreadPoolThread = true, IsBackground = true, - Name = ".NET ThreadPool Gate" + Name = ".NET TP Gate" }; gateThread.UnsafeStart(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs index ff944b29597c5..4c8512f9cdc79 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs @@ -187,7 +187,7 @@ public WaitThread() { IsThreadPoolThread = true, IsBackground = true, - Name = ".NET ThreadPool Wait" + Name = ".NET TP Wait" }; waitThread.UnsafeStart(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs index 21a1e6bf0acb9..8ad921e002cd5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs @@ -1355,7 +1355,7 @@ internal static void PerformWaitOrTimerCallback(_ThreadPoolWaitOrTimerCallback h public static partial class ThreadPool { - internal const string WorkerThreadName = ".NET ThreadPool Worker"; + internal const string WorkerThreadName = ".NET TP Worker"; internal static readonly ThreadPoolWorkQueue s_workQueue = new ThreadPoolWorkQueue(); diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index 348c7cbd3526a..7afada2dba418 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -1359,6 +1359,14 @@ ep_rt_thread_create ( return false; } +static +inline +void +ep_rt_set_server_name() +{ + mono_native_thread_set_name(mono_native_thread_id_get(), ".NET EventPipe"); +} + static inline void diff --git a/src/native/eventpipe/ds-server.c b/src/native/eventpipe/ds-server.c index 5185bc09f49f5..b3cf9f3b27e03 100644 --- a/src/native/eventpipe/ds-server.c +++ b/src/native/eventpipe/ds-server.c @@ -116,6 +116,8 @@ EP_RT_DEFINE_THREAD_FUNC (server_thread) { EP_ASSERT (server_volatile_load_shutting_down_state () || ds_ipc_stream_factory_has_active_ports ()); + ep_rt_set_server_name(); + if (!ds_ipc_stream_factory_has_active_ports ()) { #ifndef DS_IPC_DISABLE_LISTEN_PORTS DS_LOG_ERROR_0 ("Diagnostics IPC listener was undefined"); @@ -256,7 +258,7 @@ ds_server_shutdown (void) void ds_server_pause_for_diagnostics_monitor (void) { - _is_paused_for_startup = true; + _is_paused_for_startup = true; if (ds_ipc_stream_factory_any_suspended_ports ()) { EP_ASSERT (ep_rt_wait_event_is_valid (&_server_resume_runtime_startup_event)); @@ -278,7 +280,7 @@ ds_server_resume_runtime_startup (void) ds_ipc_stream_factory_resume_current_port (); if (!ds_ipc_stream_factory_any_suspended_ports () && ep_rt_wait_event_is_valid (&_server_resume_runtime_startup_event)) { ep_rt_wait_event_set (&_server_resume_runtime_startup_event); - _is_paused_for_startup = false; + _is_paused_for_startup = false; } } diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h index 086975834d820..e7d7a12c7d0a7 100644 --- a/src/native/eventpipe/ep-rt.h +++ b/src/native/eventpipe/ep-rt.h @@ -566,6 +566,10 @@ ep_rt_thread_create ( EventPipeThreadType thread_type, void *id); +static +void +ep_rt_set_server_name (void); + static void ep_rt_thread_sleep (uint64_t ns); diff --git a/src/native/libs/System.Native/pal_signal.c b/src/native/libs/System.Native/pal_signal.c index 0271f8c216ff0..88f43fac5023c 100644 --- a/src/native/libs/System.Native/pal_signal.c +++ b/src/native/libs/System.Native/pal_signal.c @@ -313,6 +313,14 @@ static void* SignalHandlerLoop(void* arg) free(arg); assert(pipeFd >= 0); + char* threadName = ".NET SigHandler"; +#if defined(__linux__) || defined(__FreeBSD__) + pthread_setname_np(pthread_self(), threadName); +#endif +#if defined(__APPLE__) + pthread_setname_np(threadName); +#endif + // Continually read a signal code from the signal pipe and process it, // until the pipe is closed. while (true)