获取进程的 CPU 和内存使用情况的正确性能计数器是什么?
如何使用 .NET PerformanceCounter
类获取特定进程的 CPU 和 内存使用情况? 之间有什么区别
Processor\% Processor Time
和 Process\% Processor Time
?我对这两者有点困惑。
How can I get the CPU and Memory usage of a particular process using the .NET PerformanceCounter
class? And also what is the difference between
Processor\% Processor Time
and Process\% Processor Time
?
I am a bit confused between these two.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自此 post:
要获取整个PC CPU和内存使用情况:
然后全局声明:
然后要获取CPU时间,只需调用
NextValue()
方法:这将为您提供 CPU 使用情况
至于内存使用情况,同样的事情我相信适用:
然后要获取内存使用情况,只需调用
NextValue()
方法:对于特定进程 CPU 和内存使用情况:
,其中
Process.GetCurrentProcess().ProcessName
是您希望获取其信息的进程名称。其中
Process.GetCurrentProcess().ProcessName
是您希望获取相关信息的进程名称。请注意,工作集本身可能不足以确定进程的内存占用量 - 请参阅什么是私有字节、虚拟字节、工作集吗?
要检索所有类别,请参阅演练:检索类别和计数器
Processor\% Processor Time
和Process\% Processor Time
之间的区别> 是Processor
来自PC 本身,Process
是每个单独的进程。因此处理器的处理器时间将是PC 上的使用时间。进程的处理器时间将是指定的进程使用情况。有关类别名称的完整说明:性能监视器计数器替代方案使用性能计数器
使用 System.Diagnostics .Process.TotalProcessorTime 和 System.Diagnostics。 ProcessThread.TotalProcessorTime 属性用于计算处理器使用情况,如本文文章所述。
From this post:
To get the entire PC CPU and Memory usage:
Then declare globally:
Then to get the CPU time, simply call the
NextValue()
method:This will get you the CPU usage
As for memory usage, same thing applies I believe:
Then to get the memory usage, simply call the
NextValue()
method:For a specific process CPU and Memory usage:
where
Process.GetCurrentProcess().ProcessName
is the process name you wish to get the information about.where
Process.GetCurrentProcess().ProcessName
is the process name you wish to get the information about.Note that Working Set may not be sufficient in its own right to determine the process' memory footprint -- see What is private bytes, virtual bytes, working set?
To retrieve all Categories, see Walkthrough: Retrieving Categories and Counters
The difference between
Processor\% Processor Time
andProcess\% Processor Time
isProcessor
is from the PC itself andProcess
is per individual process. So the processor time of the processor would be usage on the PC. Processor time of a process would be the specified processes usage. For full description of category names: Performance Monitor CountersAn alternative to using the Performance Counter
Use System.Diagnostics.Process.TotalProcessorTime and System.Diagnostics.ProcessThread.TotalProcessorTime properties to calculate your processor usage as this article describes.
Pelo Hyper-V:
Pelo Hyper-V:
获取与任务管理器中显示的值类似的值
To get the value similar to that displayed in task manager