如何通过WMI了解进程的CPU和内存使用情况?
我正在使用 wmi 和 python 来跟踪我的机器上运行的进程的行为。
from win32com.client import GetObject wmi = GetObject('winmgmts:') processes = wmi.InstancesOf('Win32_Process') for process in processes: print process.ProcessId, process.Name
Win32_Process 有很多信息,但我没有看到任何用于跟踪 CPU 消耗的信息。窗口任务监视器正在显示此信息,因此我认为可以获取它。
我认为WorkingSetSize 属性给出了进程的内存消耗,但我可以看到与TaskMonitor 给出的值不同的值。
如何获取给定进程的这两个值?
更新: 任务监视器显示 PrivateWorkingSetSize,该大小似乎不适用于 Win32_Process。 WorkingSetSize 和 PrivateWorkingSetSize 之间有什么区别?
I am using a wmi and python in order to track the behavior of the process running on my machine.
from win32com.client import GetObject wmi = GetObject('winmgmts:') processes = wmi.InstancesOf('Win32_Process') for process in processes: print process.ProcessId, process.Name
The Win32_Process has a lot of information but I don't see anything for tracking the CPU consumption. The window Task Monitor is showing this info so I think it is possible to get it.
I thought that the WorkingSetSize property is giving the memory consumption of the process but I can see different value from what is given by TaskMonitor.
How to get these 2 values for a given process?
Update:
Task Monitor shows the PrivateWorkingSetSize which seems to be not available with the Win32_Process. What is the difference betwen WorkingSetSize and PrivateWorkingSetSize?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我很确定您想要 WMI 性能类
Win32_PerfFormattedData_PerfProc_Process 或
Win32_PerfRawData_PerfProc_Process
例如它们的属性PercentProcessorTime 和 WorkingSet
请注意,Perf 类需要花费一些精力才能理解。
但这些 WMI 类应该可以为您提供所需的所有信息。
I'm pretty sure you want the WMI perf classes
Win32_PerfFormattedData_PerfProc_Process or
Win32_PerfRawData_PerfProc_Process
E.g. their properties PercentProcessorTime and WorkingSet
Note that the Perf classes take a bit effort to understand.
But those WMI classes should give you all the info you're looking for.
请参阅:
WMI 使 C# 变得简单
如何在Python中获取当前CPU和RAM的使用情况?
可能也感兴趣:
Please see:
WMI Made Easy For C#
How to get current CPU and RAM usage in Python?
Might also be of interest:
Win32_Process 还具有 UserModeTime 和 KernelModeTime,可用于计算 CPU 使用率
另请参阅 http: //technet.microsoft.com/en-us/library/ee176718.aspx
Win32_Process also has UserModeTime and KernelModeTime which can be used to calculate CPU usage
Also look at http://technet.microsoft.com/en-us/library/ee176718.aspx