Welcome to MSDN Blogs Sign in | Join | Help

How to get Processor Utilization for Hyper-V via WMI

There are a number of groups building management software (OEMs, Microsoft, …) for Hyper-V which is cool to see.  A common ask from these teams has been around reading and computing VM CPU usage.

The following is an example of how to compute Hyper-V guest processors usage.  You can use the same formula for “% Total Run  Time, “% Hypervisor Time” and “% Idle time”.   The counters show up in the Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor WMI object asPercentGuestRunTime”, “PercentTotalRunTime”, “PercentHypervisorRunTime”, and “PercentIdleTime”.

To make the formula easier to read lets use:

                GN – Percent Guest Run Time (substitute other usage values here)

                PN – Timestamp_PerfTime

                FN – Frequency_PerfTime

                LP = Number of logical processors (Get this from the “Hyper-V Hypervisor” counterset)

 

                         F1 * (G2 – G1)

 Utilization =  -----------------------------------

                     100000 * LP * (P2-P1)

 

G2 and P2 are the second values read and G1 and P1 are the first values read.

To test the formula lets read the “Hyper-V Hypervisor Logical Process” counterset twice via the Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor WMI object about 10 seconds apart with a single VM running at 100% Guest CPU.  Since my test machine has two CPU’s (2 LP) this means we should see about 50% overall utilization.

V:\backup>winrm enum wmi/root/cimv2/* -filter:"select * from Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor where name='_Total'"

Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor

    C1TransitionsPersec = 409197889

    C2TransitionsPersec = 0

    C3TransitionsPersec = 0

    Caption = null

    ContextSwitchesPersec = 889911109

    Description = null

    Frequency_Object = 0

    Frequency_PerfTime = 14318180

    Frequency_Sys100NS = 10000000

    HardwareInterruptsPersec = 92282462

    InterProcessorInterruptsPersec = 8174254

    InterProcessorInterruptsSentPersec = 8174254

    MonitorTransitionCost = 16

    Name = _Total

    PercentC1Time = 4193635539355

    PercentC2Time = 0

    PercentC3Time = 0

    PercentGuestRunTime = 314976793671

    PercentHypervisorRunTime = 53745475789

    PercentIdleTime = 8385447570540

    PercentTotalRunTime = 368722269460

    SchedulerInterruptsPersec = 384836664

    TimerInterruptsPersec = 33425466

    Timestamp_Object = 0

    Timestamp_PerfTime = 6268633722843

    Timestamp_Sys100NS = 4199325031975

    TotalInterruptsPersec = 518718846

 

V:\backup>winrm enum wmi/root/cimv2/* -filter:"select * from Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor where name='_Total'"

Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor

    C1TransitionsPersec = 409201218

    C2TransitionsPersec = 0

    C3TransitionsPersec = 0

    Caption = null

    ContextSwitchesPersec = 889922035

    Description = null

    Frequency_Object = 0

    Frequency_PerfTime = 14318180

    Frequency_Sys100NS = 10000000

    HardwareInterruptsPersec = 92283571

    InterProcessorInterruptsPersec = 8174425

    InterProcessorInterruptsSentPersec = 8174425

    MonitorTransitionCost = 16

    Name = _Total

    PercentC1Time = 4193667417779

    PercentC2Time = 0

    PercentC3Time = 0

    PercentGuestRunTime = 315044817737

    PercentHypervisorRunTime = 53746578312

    PercentIdleTime = 8385511363951

    PercentTotalRunTime = 368791396049

    SchedulerInterruptsPersec = 384840537

    TimerInterruptsPersec = 33426627

    Timestamp_Object = 0

    Timestamp_PerfTime = 6268728855292

    Timestamp_Sys100NS = 4199364353043

    TotalInterruptsPersec = 518725160

 

Based the formula above and the data below we get = 51% which is spot on.

  Enjoy,

    Tony Voellm

 

 

 

Published Monday, July 14, 2008 5:44 PM by tvoellm

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# a-foton » How to get Processor Utilization for Hyper-V via WMI

# re: How to get Processor Utilization for Hyper-V via WMI

Sunday, September 07, 2008 12:55 PM by Eric

Hello, i have no value for Frequency_PerfTime and Timestamp_PerfTime  with Hyper-V RTM with one Windows 2003 R2 VM.Should i have not install a features...

Thanks

-----

Tony's reply

Please post the full query you are using.  Thanks.

# re: How to get Processor Utilization for Hyper-V via WMI

Thursday, January 22, 2009 3:45 AM by chikura

Hi Tony,

On our Hyper-V machine(Windows 2008 x64 with Hyper-V Role enabled), we have created 5 VMs each with different no of virtual processors.

Using the wmi we were able to query all the performance related counters like PercentTotalRuntime, PercentGuestRuntime.

But suddenly we are seeing that most of the runtime counters are missing from WMI.

Can you please give us tips/help us to find the reason for this:

Please note that Perfmon is still showing all the %GuestRuntime and all other counter values properly.

c:\Users\Administrator>winrm enum wmi/root/cimv2/* -filter:"select * from Win32_

PerfRawData_HvStats_HyperVHypervisorLogicalProcessor where Name='_Total'"

Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor

   C1TransitionsPersec = 224586390

   C2TransitionsPersec = 0

   Caption = null

   ContextSwitchesPersec = 465444370

   Description = null

   Frequency_Object = 0

   Frequency_PerfTime = 25000000

   Frequency_Sys100NS = 10000000

   HardwareInterruptsPersec = 41350707

   InterProcessorInterruptsPersec = 58882296

   InterProcessorInterruptsSentPersec = 9885971

   MonitorTransitionCost = 138

   Name = _Total

   PercentC1Time = 444477161794

   PercentC2Time = 0

   SchedulerInterruptsPersec = 206489220

   TimerInterruptsPersec = 46487497

   Timestamp_Object = 0

   Timestamp_PerfTime = 1811834426354

   Timestamp_Sys100NS = 702268355257

c:\Users\Administrator>

Also, note that WMI Browser we are using is also showing only above properties.

Similar properties are missing under all Hyper-V Processor related WMI Objects,,

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker