是否可以打印系统中每个核心的当前CPU使用情况?
这是我到目前为止使用的PowerShell:
Get-WmiObject -Query "select Name, PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor"
答案 0 :(得分:4)
可以使用以下powershell命令完成:
(Get-WmiObject -Query "select Name, PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor") | foreach-object { write-host "$($_.Name): $($_.PercentProcessorTime)" };
您还可以使用以下内容创建名为get_cpu_usage.ps1
的文件:
while ($true)
{
$cores = (Get-WmiObject -Query "select Name, PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor")
$cores | foreach-object { write-host "$($_.Name): $($_.PercentProcessorTime)" };
Start-Sleep -m 200
}
然后使用:
运行它powershell -executionpolicy bypass "get_cpu_usage.ps1"
答案 1 :(得分:2)
作为替代方案,您可以使用Get-Counter
命令。
例如:
Get-Counter -Counter '\Processor(*)\% Processor Time' -Computer $desktop | select -ExpandProperty CounterSamples
从我的测试来看,它比查询WMI快4倍(至少在我的机器上)。
编辑:
在测试了一些之后,对查询的重复使用更快(得到284 ms
的平均值),因为Get-Counter
需要最少1秒来获取样本。
答案 2 :(得分:0)
在Powershell Core 6中,命令已更改。
from("file:C:\\input?filter=#testFilter").split(body().tokenize("\n")).
streaming().setHeader(Exchange.FILE_NAME,simple(newFileName+".dat")).bean(LineParser.class, "process").to("file:C:\\output"+ Constants.getMapping().get(argumentName)+"?fileExist=Append");
该脚本在Powershell Core 6中看起来像这样。
fig, ((ax,ax0)) = plt.subplots(nrows=2, ncols=1, sharex=False, sharey=False,
figsize=[5,4],gridspec_kw={"height_ratios":[1,4],'hspace':0.05})
ax0.set_xlabel('X AXIS LABEL')
ax0.set_ylabel(r'Y AXIS LABEL')
ax.set_xticks([])
ax.set_yticks([])
ax.text(.5,.5,"IMAGE",ha='center',va='center')
plt.tight_layout()
我就像两次更新之间的屏幕一样清晰。 :)