我有一個分配記憶體的程式。我從 Windows PowerShell 命令列運行它。它可以運行 1-2 個小時來分配和釋放記憶體塊。
我正在尋找的是一種在最后(程式完成時)獲得一些記憶體消耗統計資訊的方法。更具體地說,記憶體的峰值使用量是多少(分配的最大記憶體)。
uj5u.com熱心網友回復:
Get-Process -Id xxx為您提供 ID 為 xxx 的行程的Process物件實體。那里有各種與記憶體相關的屬性,包括像PeakVirtualMemorySize64和這樣的東西PeakWorkingSet64。選擇你覺得有用的那些。
您甚至可以設定后臺作業來獲取資料系列,例如
$proc = Start-Process "your_long_running.exe" -PassThru
$memoryWatcher = Start-Job -ScriptBlock {
while ($true) {
Get-Process -Id $args[0] | Select VirtualMemorySize64,PeakVirtualMemorySize64
Start-Sleep -Seconds 1
}
} -ArgumentList $proc.Id
# now wait for the process to end
Wait-Process -Id $proc.Id
$memoryWatcher.StopJob()
$results = Receive-Job $memoryWatcher
$results | Format-Table
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/345220.html
