简体   繁体   English

获取进程的内存使用率(%)

[英]Get memory usage of process in %

I'd like to get the percentage of memory usage of a process.我想获得进程的内存使用百分比。

This is what I currently have:这是我目前拥有的:

return new PerformanceCounter("Memory", "% Committed Bytes In Use").NextValue();

However, this is the RAM usage of my whole computer, not only the process.但是,这是我整个计算机的RAM使用情况,而不仅仅是进程。

When trying to add a string parameter to PerformanceCounter , it doesn't work because you apparently can't provide a process name for this counters category.尝试向PerformanceCounter添加字符串参数时,它不起作用,因为您显然无法为此计数器类别提供进程名称。

Memory usage of the current process:当前进程的内存使用情况:

System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64

Total system memory:系统总内存:

Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory

Multiplying the first one by 100 and dividing the result by the second you get the percentage.将第一个乘以 100 并将结果除以第二个,您将得到百分比。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM