param([ValidateRange(1,20)][int]$Runs=3,[ValidateRange(100,10000)][int]$SettleMilliseconds=1500) # Private resident pages are counted externally, so the measurement buffer is # allocated in PowerShell, not in the measured process. Never trim working sets. $ErrorActionPreference='Stop' $root=Split-Path $PSScriptRoot -Parent $output=Join-Path $root 'build/memory-components' New-Item -ItemType Directory -Force $output | Out-Null $exe=Join-Path $output 'probe.exe' & "$root/.tools/w64devkit/bin/g++.exe" -std=c++20 -Os -static -s -DUNICODE -D_UNICODE -D_WIN32_WINNT=0x0A00 "$PSScriptRoot/memory-components.cpp" -o $exe -lole32 -loleaut32 -lshell32 -lpropsys -lshlwapi -luuid -luiautomationcore if($LASTEXITCODE) { throw 'Probe compilation failed' } Add-Type @' using System; using System.Runtime.InteropServices; public static class ComponentWorkingSet { [DllImport("psapi.dll", SetLastError=true)] static extern bool QueryWorkingSet(IntPtr process,IntPtr buffer,int size); public static long PrivateBytes(IntPtr process) { int size=4*1024*1024; IntPtr buffer=Marshal.AllocHGlobal(size); try { if(!QueryWorkingSet(process,buffer,size)) throw new System.ComponentModel.Win32Exception(); long count=Marshal.ReadIntPtr(buffer).ToInt64(), pages=0; if(count>(size/IntPtr.Size)-1) throw new InvalidOperationException("Working set buffer is too small"); for(int i=0;i