Returning CPU usage in WMI using C#

后端 未结 3 1293
醉酒成梦
醉酒成梦 2020-12-06 17:28

To return the CPU usage by using WMI, do I return the PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor?

If not, which class should I l

3条回答
  •  甜味超标
    2020-12-06 18:08

    It seems like the info is also available in WMI here:

    select LoadPercentage from Win32_Processor

    • https://msdn.microsoft.com/en-us/library/aa394373%28v=vs.85%29.aspx

    "Load capacity of each processor, averaged to the last second. Processor loading refers to the total computing burden for each processor at one time."

    OR:

    select LoadPercentage from CIM_Processor

    • https://msdn.microsoft.com/en-us/library/aa387978(v=vs.85).aspx

    "Loading of the processor, averaged over the last minute, in a percentage."

    OR:

    select PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor also seems to work.


    Note: these often return multiple results per CPU core and have to be summed to get the total CPU usage for the system as a whole, so look for that.

    This question and answer really has more to do with WMI since getting info from WMI with C# is really a different question and should be very similar for any WMI query in C#.

提交回复
热议问题