(Batch) “wmic cpu” issue with multi-core system

不问归期 提交于 2021-01-28 09:01:04

问题


I run the "wmic cpu get loadpercentage /every:1" command on a virtual machine with 2 logical CPU cores and I get the LoadPercentage of the 1st core only, as you can see on the image attached: Multicore Issue

How can I get the "real" CPU utilization (i.e. the average use of the 2 cores)?

Otherwise, how can I also read the 2nd CPU usage separately?

Thank you


回答1:


It is probably funny that I give an answer to MY question, but since I searched and tested a lot, I want to share one more option:

I used the "typeperf" and I found the result really close to the task manager CPU utilization.

The command for the console is:

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

or the one below for a batch file:

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

The bad points are:

1) The output format is not very handy (e.g. "01/29/2019 21:24:26.000","8.650791" )

2) If the CPU utilization is 100%, the output is >100 (Basically ~120)

3) If the CPU utilization is 1-2%, the output is ~0.5 (Basically <1.5)




回答2:


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.

In Windows cmd:

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


来源:https://stackoverflow.com/questions/53838387/batch-wmic-cpu-issue-with-multi-core-system

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!