Skip to content

Commit e013f9d

Browse files
HJLeeejkotas
andauthored
Set names to runtime internal threads (#75113)
* Set names to runtime internal threads * Fix MAC build * Shorten ThreadPool thread names * Fix not to return SetThreadDescription() * Change SetThreadDescription to SetThreadName * Set thread names inside thread functions * Add missing name for MAC * Move name change info thread function Co-authored-by: Jan Kotas <[email protected]>
1 parent c81e7a2 commit e013f9d

File tree

11 files changed

+46
-6
lines changed

11 files changed

+46
-6
lines changed

src/coreclr/debug/ee/rcthread.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,11 @@ void DebuggerRCThread::TemporaryHelperThreadMainLoop()
13111311

13121312
DebuggerRCThread* t = (DebuggerRCThread*)g_pRCThread;
13131313

1314+
if (FAILED(SetThreadName(t->m_thread, W(".NET Debugger"))))
1315+
{
1316+
LOG((LF_CORDB, LL_INFO10000, "DebuggerRCThread name set failed\n"));
1317+
}
1318+
13141319
t->ThreadProc(); // this thread is local, go and become the helper
13151320

13161321
return 0;
@@ -1366,7 +1371,6 @@ HRESULT DebuggerRCThread::Start(void)
13661371
{
13671372
LOG((LF_CORDB, LL_EVERYTHING, "DebuggerRCThread failed, err=%d\n", GetLastError()));
13681373
hr = HRESULT_FROM_GetLastError();
1369-
13701374
}
13711375
else
13721376
{

src/coreclr/debug/shared/dbgtransportsession.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,8 @@ void DbgTransportSession::InitSessionState()
12271227
// instance method version defined below for convenience in the implementation.
12281228
DWORD WINAPI DbgTransportSession::TransportWorkerStatic(LPVOID pvContext)
12291229
{
1230+
SetThreadName(GetCurrentThread(), W(".NET DebugPipe"));
1231+
12301232
((DbgTransportSession*)pvContext)->TransportWorker();
12311233

12321234
// Nobody looks at this result, the choice of 0 is arbitrary.

src/coreclr/pal/src/synchmgr/synchmanager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,10 @@ namespace CorUnix
17071707
reinterpret_cast<CPalSynchronizationManager*>(pArg);
17081708
CPalThread * pthrWorker = InternalGetCurrentThread();
17091709

1710+
InternalSetThreadDescription(pthrWorker,
1711+
PAL_GetCurrentThread(),
1712+
W(".NET SynchManager"));
1713+
17101714
while (!fWorkerIsDone)
17111715
{
17121716
LONG lProcessCount;

src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,14 @@ ep_rt_thread_create (
20472047
return result;
20482048
}
20492049

2050+
static
2051+
inline
2052+
void
2053+
ep_rt_set_server_name()
2054+
{
2055+
::SetThreadName(GetCurrentThread(), W(".NET EventPipe"));
2056+
}
2057+
20502058
static
20512059
inline
20522060
void

src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.GateThread.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private static void CreateGateThread(PortableThreadPool threadPoolInstance)
239239
{
240240
IsThreadPoolThread = true,
241241
IsBackground = true,
242-
Name = ".NET ThreadPool Gate"
242+
Name = ".NET TP Gate"
243243
};
244244
gateThread.UnsafeStart();
245245
}

src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WaitThread.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public WaitThread()
187187
{
188188
IsThreadPoolThread = true,
189189
IsBackground = true,
190-
Name = ".NET ThreadPool Wait"
190+
Name = ".NET TP Wait"
191191
};
192192
waitThread.UnsafeStart();
193193
}

src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ internal static void PerformWaitOrTimerCallback(_ThreadPoolWaitOrTimerCallback h
13551355

13561356
public static partial class ThreadPool
13571357
{
1358-
internal const string WorkerThreadName = ".NET ThreadPool Worker";
1358+
internal const string WorkerThreadName = ".NET TP Worker";
13591359

13601360
internal static readonly ThreadPoolWorkQueue s_workQueue = new ThreadPoolWorkQueue();
13611361

src/mono/mono/eventpipe/ep-rt-mono.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,14 @@ ep_rt_thread_create (
13591359
return false;
13601360
}
13611361

1362+
static
1363+
inline
1364+
void
1365+
ep_rt_set_server_name()
1366+
{
1367+
mono_native_thread_set_name(mono_native_thread_id_get(), ".NET EventPipe");
1368+
}
1369+
13621370
static
13631371
inline
13641372
void

src/native/eventpipe/ds-server.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ EP_RT_DEFINE_THREAD_FUNC (server_thread)
116116
{
117117
EP_ASSERT (server_volatile_load_shutting_down_state () || ds_ipc_stream_factory_has_active_ports ());
118118

119+
ep_rt_set_server_name();
120+
119121
if (!ds_ipc_stream_factory_has_active_ports ()) {
120122
#ifndef DS_IPC_DISABLE_LISTEN_PORTS
121123
DS_LOG_ERROR_0 ("Diagnostics IPC listener was undefined");
@@ -256,7 +258,7 @@ ds_server_shutdown (void)
256258
void
257259
ds_server_pause_for_diagnostics_monitor (void)
258260
{
259-
_is_paused_for_startup = true;
261+
_is_paused_for_startup = true;
260262

261263
if (ds_ipc_stream_factory_any_suspended_ports ()) {
262264
EP_ASSERT (ep_rt_wait_event_is_valid (&_server_resume_runtime_startup_event));
@@ -278,7 +280,7 @@ ds_server_resume_runtime_startup (void)
278280
ds_ipc_stream_factory_resume_current_port ();
279281
if (!ds_ipc_stream_factory_any_suspended_ports () && ep_rt_wait_event_is_valid (&_server_resume_runtime_startup_event)) {
280282
ep_rt_wait_event_set (&_server_resume_runtime_startup_event);
281-
_is_paused_for_startup = false;
283+
_is_paused_for_startup = false;
282284
}
283285
}
284286

src/native/eventpipe/ep-rt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@ ep_rt_thread_create (
566566
EventPipeThreadType thread_type,
567567
void *id);
568568

569+
static
570+
void
571+
ep_rt_set_server_name (void);
572+
569573
static
570574
void
571575
ep_rt_thread_sleep (uint64_t ns);

0 commit comments

Comments
 (0)