【发布时间】:2016-11-27 20:04:38
【问题描述】:
我希望能够每 5 秒将最高 CPU 消耗者输出到日志文件。这样我就可以在我的测试中看到谁使用了最多的 cpu。
我发现这个答案很常见:
$cpu = Get-Counter -ComputerName localhost "\Process(*)\% Processor Time" `
| Select-Object -ExpandProperty countersamples `
| where {$_.InstanceName -ne 'idle' } `
| where {$_.InstanceName -ne '_total' }`
| Select-Object -Property instancename, cookedvalue `
| Sort-Object -Property cookedvalue -Descending `
| Select-Object -First 5 `
| ft @{L='Date';E={Get-Date}}, InstanceName, @{L='CPU';E={(($_.Cookedvalue/100)/$NumberOfLogicalProcessors).toString('P')}} -HideTableHeaders `
| Format-Table -Auto | Out-String
我有两个问题:
-
有时我会得到:
Get-Counter:性能计数器样本之一中的数据无效。查看每个 PerformanceCounterSample 对象的 Status 属性以确保它包含有效数据。
-
我想获取完整的进程名称,而不是
java 25% 想法64 0.8% ...
【问题讨论】:
标签: windows performance powershell cpu monitor