<# .SYNOPSIS Captures the drift subset and the volatile state of the reference laptop (record RHW-WIN-265U-NPU r1). .DESCRIPTION Read-only. Uses the same locale-independent forms as the command catalogue in spec node reference-hardware/win-core-ultra-7-265u-npu.md (C04, C07, C08, C09, C11, C13, C14, C15, C17, C18): CIM classes, setting GUIDs and ISO-8601 UTC times, no parsing of translated labels. Every benchmark run calls this before and after and stores both objects with its results. The drift result follows the record's rule: overall is 'pass' only when every field matches; the power mode has no read-only command, so it is 'not-comparable' unless -PowerModeAttested is given, and the overall result is then 'incomplete', never a silent pass. .EXAMPLE . .\Capture-MachineState.ps1; Get-MachineState | ConvertTo-Json -Depth 6 #> $script:ReferenceDrift = [ordered]@{ os_build = '26100' os_ubr = 9448 npu_driver_version = '32.0.100.4778' igpu_driver_version = '32.0.101.8860' bios_version = '1.17.0' power_plan_guid = '381b4222-f694-41f0-9685-ff5bb260df2e' } function Get-UtcNow { [DateTime]::UtcNow.ToString('yyyy-MM-ddTHH:mm:ss', [Globalization.CultureInfo]::InvariantCulture) + 'Z' } function Get-MachineState { [CmdletBinding()] param( # Operator-attested power mode shown by the OS settings (no documented read-only command exists). [string] $PowerModeAttested = $null, [string] $Attester = $null ) $ci = [Globalization.CultureInfo]::InvariantCulture $state = [ordered]@{ captured_utc = (Get-UtcNow) } # C08 OS $k = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' $state.os_build = [string]$k.CurrentBuildNumber $state.os_ubr = [int]$k.UBR # C04 NPU driver, C07 iGPU driver, C09 BIOS $npu = @(Get-PnpDevice -Class ComputeAccelerator -ErrorAction SilentlyContinue) if ($npu.Count -gt 0) { $v = Get-PnpDeviceProperty -InstanceId $npu[0].InstanceId -KeyName 'DEVPKEY_Device_DriverVersion' -ErrorAction SilentlyContinue $state.npu_driver_version = [string]$v.Data $state.npu_status = [string]$npu[0].Status } $gpu = @(Get-CimInstance Win32_VideoController | Where-Object { $_.Name -match 'Intel' }) if ($gpu.Count -gt 0) { $state.igpu_driver_version = [string]$gpu[0].DriverVersion } $state.bios_version = [string](Get-CimInstance Win32_BIOS).SMBIOSBIOSVersion # C11 power plan GUID by pattern $rx = '[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}' $state.power_plan_guid = [regex]::Match((powercfg /getactivescheme | Out-String), $rx, 'IgnoreCase').Value # C14 power source $bat = Get-CimInstance -Namespace root\wmi -ClassName BatteryStatus -ErrorAction SilentlyContinue if ($bat) { $state.ac_online = [bool]$bat.PowerOnline; $state.discharging = [bool]$bat.Discharging } # C13 memory $m = Get-CimInstance Win32_PerfFormattedData_PerfOS_Memory $state.available_mbytes = [int]$m.AvailableMBytes $state.committed_bytes = [long]$m.CommittedBytes $state.commit_limit_bytes = [long]$m.CommitLimit # C15 frequency and utility, three samples one second apart $samples = @() 1..3 | ForEach-Object { $c = Get-CimInstance Win32_PerfFormattedData_Counters_ProcessorInformation -Filter "Name='_Total'" $samples += [ordered]@{ utc = (Get-UtcNow); perf = [int]$c.PercentProcessorPerformance; pct_max_freq = [int]$c.PercentofMaximumFrequency; mhz = [int]$c.ProcessorFrequency; utility = [int]$c.PercentProcessorUtility } Start-Sleep -Seconds 1 } $state.cpu_samples = $samples # C17 load, C18 Docker/WSL and the heavy desktop processes that disturb a run $state.processes = (@(Get-Process)).Count $wsl = @(Get-Process -Name vmmemWSL -ErrorAction SilentlyContinue) $state.vmmemwsl_working_set_bytes = [long](($wsl | Measure-Object WorkingSet64 -Sum).Sum) $state.docker_desktop_processes = @(Get-Process -Name 'Docker Desktop' -ErrorAction SilentlyContinue).Count $state.browser_processes = @(Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.ProcessName -match '^(chrome|msedge|firefox|brave)$' }).Count $state.browser_working_set_bytes = [long]((Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.ProcessName -match '^(chrome|msedge|firefox|brave)$' } | Measure-Object WorkingSet64 -Sum).Sum) $state.security_agent_running = [bool](Get-Process -Name 'SentinelAgent' -ErrorAction SilentlyContinue) $state.top_cpu_processes = @(Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 | ForEach-Object { [ordered]@{ name = $_.ProcessName; cpu_seconds = [int]$_.CPU } }) # Drift comparison against the reference record (field names are the record's frozen drift subset). $drift = [ordered]@{} foreach ($name in $script:ReferenceDrift.Keys) { $drift[$name] = if ("$($state[$name])" -eq "$($script:ReferenceDrift[$name])") { 'match' } else { 'mismatch' } } if ($PowerModeAttested) { $state.power_mode_attestation = [ordered]@{ method = 'operator_attested'; mode = $PowerModeAttested; attester = $Attester; captured_utc = (Get-UtcNow) } $drift['power_mode'] = 'attested-match-not-checked-against-reference' } else { $drift['power_mode'] = 'not-comparable' } if ($drift.Values -contains 'mismatch') { $drift['overall'] = 'stale' } elseif ($drift.Values -contains 'not-comparable') { $drift['overall'] = 'incomplete' } else { $drift['overall'] = 'pass' } $state.reference_record = [ordered]@{ record_id = 'RHW-WIN-265U-NPU'; revision = 1 } $state.drift_result = $drift return $state } # Quiet-machine gate for benchmark runs. Returns a list of reasons the machine is NOT quiet (empty = quiet). function Test-QuietMachine { [CmdletBinding()] param([int] $MinFreeRamMB = 16000, [int] $MaxCpuUtilityPercent = 15) $reasons = @() $s = Get-MachineState if ($s.available_mbytes -lt $MinFreeRamMB) { $reasons += "available RAM $($s.available_mbytes) MB is below $MinFreeRamMB MB" } if ($s.vmmemwsl_working_set_bytes -gt 0) { $reasons += "WSL/Docker VM holds $([int]($s.vmmemwsl_working_set_bytes/1MB)) MB" } if ($s.browser_working_set_bytes -gt 500MB) { $reasons += "$($s.browser_processes) browser processes hold $([int]($s.browser_working_set_bytes/1MB)) MB" } $u = ($s.cpu_samples | ForEach-Object { $_.utility } | Measure-Object -Average).Average if ($u -gt $MaxCpuUtilityPercent) { $reasons += "CPU utility averages $([int]$u) percent" } if ($s.ac_online -eq $false) { $reasons += 'running on battery' } return $reasons }