Skip to content

Instantly share code, notes, and snippets.

@rleap-m
Created November 13, 2024 16:16
Show Gist options
  • Save rleap-m/6b01d0abbc7b55719b3cfde7ec6df403 to your computer and use it in GitHub Desktop.
Save rleap-m/6b01d0abbc7b55719b3cfde7ec6df403 to your computer and use it in GitHub Desktop.
Shows increase (or decrease) in memory usage for processes over time
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path -Path $_ -PathType Leaf})]
[string]
$ReportPath,
[Parameter(Mandatory=$false)]
[int]
$EntryCount = 10
)
$memUsageReport = Import-Csv -Path $ReportPath
$processList = $memUsageReport | Group-Object -Property ProcessId | Where-Object -Property Count -gt $EntryCount |
Select-Object -ExpandProperty Name | Sort-Object
$results = foreach ($processId in $processList) {
$firstLast = $memUsageReport.where({$_.ProcessId -eq $processId}) | Select-Object -First 1 -Last 1
[PSCustomObject]@{
ID = $firstLast[0].ProcessId
Name = $firstLast[0].Name
ElapsedMin = [math]::Round(((Get-Date -Date $firstLast[1].DateTime) - (Get-Date -Date $firstLast[0].DateTime)).TotalMinutes)
IncreaseInMBs = [math]::Round(($firstLast[1].WorkingSetSize - $firstLast[0].WorkingSetSize) / 1MB)
ArgTail = $firstLast[0].CommandLine.Split(' ')[-1]
}
}
$results | Sort-Object -Property IncreaseInMBs | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment