window bat cmd 获取cpu 利用率(使用率)跟 性能计数器一致,方式收集
1. typeperf (1秒一输出)
typeperf "processor(_total)\% processor time"
若是只要执行一次,末尾添加 -sc 1,如下:
typeperf "processor(_total)\% processor time" -sc 1
2. powershell
Powershell "Get-Counter '\Processor(*)\% Processor Time' | Select -Expand Countersamples |Select InstanceName, CookedValue"
Get-Counter -Counter "\Processor(_Total)\% Processor Time" -Continuous
3.wmic
wmic cpu get loadpercentage
5. bat
@echo off
for /f "tokens=2 delims==" %%a in ('wmic path Win32_PerfFormattedData_PerfOS_Processor get PercentProcessorTime /value^|findstr "PercentProcessorTime"') do (
set UseCPU=%%a
)
echo CPU使用率:%UseCPU%%%
pause
获取到跟任务管理器不大一样,性能监视器(perfmon)又是一致的。
cmd 输入 perfmon 监视项选择 Processor Time
标签:%%,windows,Counter,processor,采集,wmic,监控,Time,Processor From: https://www.cnblogs.com/ruiy/p/16902561.html