powershellwmiwmi-queryget-wmiobject

What are _Base properties in Powershell and how do I use them?


Take for instance the output of

gwmi Win32_PerfRawData_PerfDisk_PhysicalDisk 

Among properties we find

PercentDiskTime 

and

PercentDiskTime_Base 

The documentation about this class at learn.microsoft.com makes no sense to me as it only states that the latter is "Base value for PercentDiskTime"

They're both very large numbers and I don't understand how to link one to the other.

My actual problem is that I need to log the disk activity and the formatted output may exceed 100% therefore one has to compute the value manually using raw values. I found old discussions online about this problem but the solution point to dead links. I also found code but it doesn't work properly.

Thanks


Solution

  • The PercentDiskTime_Base property represents the private timer for the PercentDiskTime used in calculations FormattedData_PerfDisk from RawData_PerfDisk:

    PERF_PRECISION_100NS_TIMER

    Description: This counter type shows a value that consists of two counter values: the count of the elapsed time of the event being monitored, and the "clock" time from a private timer in the same units. It measures time in 100 ns units.

    This counter type differs from other counter timers in that the clock tick value accompanies the counter value eliminating any possible difference due to latency from the function call. Precision counter types are used when standard system timers are not precise enough for accurate readings.

    Generic type: Percentage

    Formula: NX – N0 / D1 – D0 where the numerator (N) represents the counter value and the denominator (D) is the value of the private timer. The private timer has the same frequency as the 100 ns timer.

    Average: NX – N0 / D1 – D0

    Example: PhysicalDisk\% Disk Time

    For details and explanation, let's start analyzing Qualifiers of the following properties (sorry, Microsoft is no longer updating linked content regularly):

    From Win32_PerfRawData_PerfDisk_PhysicalDisk class:

    PercentDiskTime: Data type: uint64, Access type: Read-only

    Qualifiers: CounterType (542573824) , DefaultScale (0) , PerfDetail (100)

    Percentage of elapsed time that the selected disk drive is busy servicing read or write requests.

    PercentDiskTime_Base: Data type: uint64, Access type: Read-only

    Qualifiers: CounterType (1073939712) , DefaultScale (0) , PerfDetail (100)

    Base value for PercentDiskTime.

    Note that:

    From Win32_PerfFormattedData_PerfDisk_PhysicalDisk class:

    PercentDiskTime: Data type: uint64, Access type: Read-only

    Qualifiers: CookingType ("PERF_PRECISION_100NS_TIMER") , Counter ("PercentDiskTime") , PerfTimeStamp ("TimeStamp_Sys100NS") , PerfTimeFreq ("Frequency_Sys100NS") , Base ("PercentDiskTime_Base")

    Percentage of elapsed time that the selected disk drive is busy servicing read or write requests.

    Take a look into Property Qualifiers for Performance Counter Classes as well.

    A simple usage example:

    $xxx = Get-WmiObject Win32_PerfRawData_PerfDisk_PhysicalDisk
    $x0 = $xxx | Where-Object Name -eq '_Total' |
        Select-Object -Property Name, PercentDiskTime* 
    $x0
    Start-Sleep -Seconds 1
    $xxx = Get-WmiObject Win32_PerfRawData_PerfDisk_PhysicalDisk
    $xN = $xxx | Where-Object Name -eq '_Total' |
        Select-Object -Property Name, PercentDiskTime*
    '----'
    $xn
    '----'
    $FormattedPercentDiskTime = ( $xn.PercentDiskTime      - $x0.PercentDiskTime      ) / 
                                ( $xn.PercentDiskTime_Base - $x0.PercentDiskTime_Base )
    100*$FormattedPercentDiskTime             # not sure about the `100*` multiplier
    

    Output: D:\PShell\SO\58712142.ps1

    Name   PercentDiskTime PercentDiskTime_Base
    ----   --------------- --------------------
    _Total      2863146220   132202140117518636
    ----
    _Total      2863151515   132202140128078551
    ----
    0,0501424490632737