简体   繁体   English

cpu在Powershell中使用代码块的情况

[英]cpu usage of a code block in powershell

I am trying to get Powershell to give me the average CPU usage of a code block, but can't figure out what wmi class to use. 我正在尝试让Powershell为我提供代码块的平均CPU使用率,但无法弄清楚要使用的wmi类。

This only gives me the current usage: 这只是给我当前的用法:

Get-WmiObject win32_processor | Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | 测量对象-属性LoadPercentage-平均值| Select Average 选择平均值

The class used will return data on CPU level. 使用的类将返回CPU级别的数据。 Try looking at process level to get more fine-grained numbers. 尝试查看流程级别以获取更多细粒度的数字。

The member UserModeTime contains the process' CPU time usage. 成员UserModeTime包含进程的CPU时间使用情况。 A simple way to convert it into more readable values is to use TimeSpan like so, [TimeSpan]::FromMilliseconds() 将其转换为更具可读性的值的一种简单方法是使用TimeSpan例如[TimeSpan]::FromMilliseconds()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM