Add repeatable Ollama memory snapshots
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$OllamaUrl = 'http://127.0.0.1:11434',
|
||||
[string]$OutputPath = ''
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$endpoint = $OllamaUrl.TrimEnd('/') + '/api/ps'
|
||||
$runtime = Invoke-RestMethod -Uri $endpoint -TimeoutSec 15
|
||||
$models = @($runtime.models | ForEach-Object {
|
||||
[ordered]@{
|
||||
name = $_.name
|
||||
model = $_.model
|
||||
loaded_size_bytes = $_.size
|
||||
vram_size_bytes = $_.size_vram
|
||||
parameter_size = $_.details.parameter_size
|
||||
quantization = $_.details.quantization_level
|
||||
context_length = $_.context_length
|
||||
expires_at = $_.expires_at
|
||||
}
|
||||
})
|
||||
$runners = @(Get-Process -Name 'llama-server' -ErrorAction SilentlyContinue | ForEach-Object {
|
||||
[ordered]@{
|
||||
process_id = $_.Id
|
||||
working_set_bytes = $_.WorkingSet64
|
||||
private_bytes = $_.PrivateMemorySize64
|
||||
}
|
||||
})
|
||||
|
||||
$report = [ordered]@{
|
||||
collected_at_local = [DateTimeOffset]::Now.ToString('o')
|
||||
source = $endpoint
|
||||
loaded_models = $models
|
||||
llama_server_processes = $runners
|
||||
note = 'Point-in-time snapshot, not peak memory. Process-to-model mapping and total host RAM are not asserted.'
|
||||
}
|
||||
|
||||
if (-not $OutputPath) {
|
||||
$resultsDirectory = Join-Path $PSScriptRoot '..\evals\results'
|
||||
$stamp = Get-Date -Format 'yyyy-MM-dd_HHmmss'
|
||||
$OutputPath = Join-Path $resultsDirectory "ollama_runtime_$stamp.json"
|
||||
}
|
||||
|
||||
$resolvedOutput = [System.IO.Path]::GetFullPath($OutputPath)
|
||||
$outputDirectory = Split-Path -Parent $resolvedOutput
|
||||
New-Item -ItemType Directory -Force -Path $outputDirectory | Out-Null
|
||||
$report | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $resolvedOutput -Encoding utf8
|
||||
Write-Output "Saved runtime snapshot: $resolvedOutput"
|
||||
Write-Output ("Loaded models: {0}; llama-server processes: {1}" -f $models.Count, $runners.Count)
|
||||
Reference in New Issue
Block a user