(批量)"wmic cpu" 多核系统问题

(Batch) "wmic cpu" issue with multi-core system

我在具有 2 个逻辑 CPU 核心的虚拟机上 运行 "wmic cpu get loadpercentage /every:1" 命令,我只得到第一个核心的 LoadPercentage,如您在附图中所见: Multicore Issue

如何获得 "real" CPU 利用率(即 2 个核心的平均使用率)?

不然怎么把第二个CPU的用法也分开看?

谢谢

Win32_PerfFormattedData_PerfOS_Processor class:

The Win32_PerfFormattedData_PerfOS_Processor formatted data class performance counter class provides precalculated data from performance counters that monitor aspects of processor activity. The processor is the part of the computer that performs arithmetic and logical computations, initiates operations on peripherals, and runs the threads of processes. A computer can have multiple processors. The processor object represents each processor as an instance of the object.

This class is shown as the Processor object in System Monitor and returns the same data found in System Monitor. This class derives its raw data from the corresponding raw class Win32_PerfRawData_PerfOS_Processor. The original data source is the PerfOS performance library. Data is dynamically provided for this class from the performance library object by the WmiPerfInst provider.

在Windows cmd:

wmic path Win32_PerfFormattedData_PerfOS_Processor where "NOT name = '_Total'" get name, PercentProcessorTime /every:1

我回答我的问题可能很有趣,但由于我进行了很多搜索和测试,我想再分享一个选项:

我使用了 "typeperf",我发现结果非常接近任务管理器 CPU 的利用率。

控制台的命令是:

typeperf "\Processor Information(_Total)\% Processor Utility"

或下面的批处理文件:

typeperf "\Processor Information(_Total)\%% Processor Utility"

不好的地方是:

1)输出格式不是很方便(例如“01/29/2019 21:24:26.000”,“8.650791”)

2) 如果CPU利用率为100%,则输出>100(基本上~120)

3)如果CPU利用率为1-2%,输出为~0.5(基本<1.5)