Everything I learned about WMI and performance counters in the last couple of days.
WMI stands for Windows Management Tool. WMI is a set of classes registered in the WMI system and the Windows COM subsystem. These classes are known as providers and have any number of public properties that return dynamic data when requested.
Windows comes preloaded with a large number of WMI providers that provide you with information about the Windows environment. On this issue, we are dealing with suppliers of Win32_PerfRawData * and two wrappers that build it.
If you request any Win32_PerfRawData * provider directly, you will notice that the numbers returned by them look scary. This is because these providers provide source data that you can use to calculate what you want.
To simplify work with Win32_PerfRawData * providers, Microsoft has provided two wrappers that return better answers when requested, the PerfMon and Win32_PerfFormattedData * providers.
So how do we get the% processor utilization process? We have three options:
- Get a nicely formatted number from the Win32_PerfFormattedData_PerfProc_Process provider.
- Get a nicely formatted number from PerfMon
- Calculate% CPU usage for yourself using Win32_PerfRawData_PerfProc_Process
We will see that there is an error with parameter 1, so it does not work in all cases, even if it is the answer usually provided on the Internet.
If you want to get this value from Win32_PerfFormattedData_PerfProc_Process, you can use the query mentioned in the question. This will give you the sum of the PercentProcessorTime value for all of these process threads. The problem is that this amount can be> 100 if there is more than 1 core, but this property is maximized by 100. Thus, as long as the sum of all these process flows is less than 100, you can get the answer by dividing the process PercentProcessorTime by the number of machine cores.
If you want to get this value from PerfMon in PowerShell, you can use Get-Counter "\Process(SqlServr)\% Processor Time" . This will return a number between 0 - (CoreCount * 100).
If you want to calculate this value for yourself, the PercentProcessorTime property in the Win32_PerfRawData_PerfProc_Process provider returns the time of the processor that this process used. So, you will need to take two snapshots, which we will call s1 and s2. Then we execute (s2.PercentProcessorTime - s1.PercentProcessorTime) / (s2.TimeStamp_Sys100NS - s1.TimeStamp_Sys100NS).
And that is the last word. Hope this helps you.