Created
December 14, 2017 11:39
-
-
Save abextm/62142caf3ab89e529e43773120d44a7c to your computer and use it in GitHub Desktop.
show memory usage by process name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
powershell -ExecutionPolicy Bypass -command "gc %~dp0%0.bat | select -skip 3" | powershell -ExecutionPolicy Bypass -command - | |
exit /B | |
#We are now in powershell | |
$procs = @{} | |
Get-Process | ForEach-Object { | |
$obj = $procs.Get_Item($_.Name) | |
if(!$obj){ | |
$obj = New-Object PSObject | |
$obj | Add-Member -type NoteProperty -Name Name -Value $_.Name | |
$obj | Add-Member -type NoteProperty -Name Count -Value 0 | |
$obj | Add-Member -type NoteProperty -Name PrivateMemory -Value 0 | |
} | |
$obj.PrivateMemory+=$_.PrivateMemorySize64 | |
$obj.Count++ | |
$procs.Set_Item($_.Name,$obj) | |
} | |
function fmt($v){ | |
$suffix="" | |
if($v -gt 9999){ | |
$suffix="Ki" | |
$v/=1024 | |
} | |
if($v -gt 9999){ | |
$suffix="Mi" | |
$v/=1024 | |
} | |
if($v -gt 9999){ | |
$suffix="Gi" | |
$v/=1024 | |
} | |
if($v -gt 9999){ | |
$suffix="Ti" | |
$v/=1024 | |
} | |
$v=[math]::Round($v) | |
$b="B" | |
return "$v $suffix$b" | |
} | |
$procs.GetEnumerator() | %{ $_.Value } | Sort-Object -desc PrivateMemory | % { $_.PrivateMemory=fmt($_.PrivateMemory);$_ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment