Modules/businessdev.ALbuild.RuntimePackages/Private/Get-BcRuntimeFreeMemoryGb.ps1
|
function Get-BcRuntimeFreeMemoryGb { <# .SYNOPSIS Free host memory in GB, or 0 when it cannot be determined. .DESCRIPTION Sizes the worker pool. Kept as its own function so the pool arithmetic in Get-BcRuntimeWorkerCount stays a pure function that tests can drive with fixed numbers instead of whatever the machine running the suite happens to have free. Returning 0 rather than throwing is deliberate: an unreadable memory counter is a reason to be conservative, not a reason to fail a build that would otherwise have run. .OUTPUTS System.Double #> [CmdletBinding()] [OutputType([double])] param() try { $os = Get-CimInstance -ClassName Win32_OperatingSystem -ErrorAction Stop return [double]($os.FreePhysicalMemory / 1MB) # the counter is in KB } catch { Write-ALbuildLog -Level Verbose "Could not read free memory: $($_.Exception.Message)" return [double]0 } } |