Skip to content

Commit

Permalink
RavenDB-23036 getting thread name for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
ppekrol committed Oct 17, 2024
1 parent d36fda0 commit 5006bc2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Raven.Server/Utils/ThreadHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.IO;
using System.Threading;
using Sparrow.Logging;
using Sparrow.Platform;

namespace Raven.Server.Utils;

Expand Down Expand Up @@ -34,4 +36,19 @@ public static ThreadPriority GetThreadPriority()
return ThreadPriority.Normal;
}
}

public static string GetThreadName(int processId, int threadId)
{
if (PlatformDetails.RunningOnLinux == false)
return null;

try
{
return File.ReadAllText($"/proc/{processId}/task/{threadId}/comm");
}
catch
{
return null;
}
}
}
4 changes: 3 additions & 1 deletion src/Raven.Server/Utils/ThreadsUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,14 @@ public ThreadsInfo Calculate(int? take = null, HashSet<int> threadIds = null)
}
else
{
threadName = threadStats.Name ?? "Thread Pool Thread";
threadName = threadStats.Name ?? ThreadHelper.GetThreadName(process.Id, thread.Id) ?? "Thread Pool Thread";
}

unmanagedAllocations = threadStats.TotalAllocated;
}

threadName ??= ThreadHelper.GetThreadName(process.Id, thread.Id);

var threadState = GetThreadInfoOrDefault<ThreadState?>(() => thread.ThreadState);
threadsInfo.List.Add(new ThreadInfo
{
Expand Down

0 comments on commit 5006bc2

Please sign in to comment.