在Linux上查看dotnetcore 2自包含应用程序的内存使用情况统计信息

时间:2017-12-05 15:17:51

标签: c# linux .net-core

我有一个c#dotnet core 2应用程序,它在Linux 14.04 LTS上作为systemd服务运行,在运行一周或更长时间之后会慢慢爬行,最终应用程序和操作系统挂起,我甚至无法打开htop。我使用了perfcollect和perfview,但只能获得调用堆栈信息。如何收集应用程序的内存使用情况统计信息,然后以可读格式显示它们?

1 个答案:

答案 0 :(得分:2)

您可以使用System.Diagnostic.Process检索和记录内存使用情况:

var process = Process.GetCurrentProcess();
var currentMemoryUsage = process.WorkingSet64;

WorkingSet64属性返回的值表示进程使用的当前工作集内存大小(以字节为单位)。

和峰值内存使用情况:

var peakPhysicalMemoryUsage = process.PeakWorkingSet64;