Fix issues with retrieving process memory

This commit is contained in:
Jordan Dominion
2024-08-18 00:00:14 -04:00
parent df43a072b2
commit 1c3a99ab6a
3 changed files with 17 additions and 3 deletions
@@ -122,7 +122,7 @@ namespace Tgstation.Server.Host.Components.Session
public FifoSemaphore TopicSendSemaphore { get; }
/// <inheritdoc />
public long MemoryUsage => process.MemoryUsage;
public long? MemoryUsage => process.MemoryUsage;
/// <summary>
/// The <see cref="Byond.TopicSender.ITopicClient"/> for the <see cref="SessionController"/>.
@@ -16,7 +16,7 @@ namespace Tgstation.Server.Host.System
/// <summary>
/// Gets the process' memory usage in bytes.
/// </summary>
long MemoryUsage { get; }
long? MemoryUsage { get; }
/// <summary>
/// Set's the owned <see cref="global::System.Diagnostics.Process.PriorityClass"/> to a non-normal value.
+15 -1
View File
@@ -23,7 +23,21 @@ namespace Tgstation.Server.Host.System
public Task<int?> Lifetime { get; }
/// <inheritdoc />
public long MemoryUsage => handle.VirtualMemorySize64;
public long? MemoryUsage
{
get
{
try
{
return handle.VirtualMemorySize64;
}
catch (Exception ex)
{
logger.LogWarning(ex, "Failed to get PID {pid}'s memory usage!", Id);
return null;
}
}
}
/// <summary>
/// The <see cref="IProcessFeatures"/> for the <see cref="Process"/>.