Powershell 中的 _Base 属性是什么?如何使用它们?

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

的输出为例
gwmi Win32_PerfRawData_PerfDisk_PhysicalDisk 

我们发现

PercentDiskTime 

PercentDiskTime_Base 

docs.microsoft.com 上关于这个 class 的文档对我来说毫无意义,因为它只说明后者是 "Base value for PercentDiskTime"

它们都是非常大的数字,我不知道如何 link 一个到另一个。

我的实际问题是我需要记录磁盘 activity 并且格式化输出可能会超过 100%,因此必须使用原始值手动计算该值。我在网上找到了关于这个问题的旧讨论,但解决方案指向死 links。我也找到了代码,但它不能正常工作。

谢谢

PercentDiskTime_Base属性表示PercentDiskTime用于计算的私有定时器FormattedData_PerfDisk 来自 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

细节和解释,下面开始分析Qualifiers的属性(不好意思, Microsoft 不再定期更新链接内容):

来自 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.

注意:

  • DefaultScale (sint32) = 用于显示计数器的 10 的幂。对于零,估计最大值为 10^0,或 1,以及
  • PerfDetail (sint32) = 受众知识水平。未使用。该值始终为 100.

来自 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.

也看看 Property Qualifiers for Performance Counter Classes

一个简单的用法例子:

$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

输出D:\PShell\SO712142.ps1

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