# OmniDx Bench - a game's frame rate on this PC, stock and with OmniDx, measured the way reviewers measure it. # # irm omnidx.net/bench.ps1 | iex # # Free, and it changes nothing on the PC. It uses PresentMon, Intel's open-source frame-time capture tool (the one # reviewers use), fetched once from its GitHub release and checked against the SHA-256 pinned below before every use. # You play the same scene for a minute; it writes down every frame and says: # average FPS; the 1% low and the 0.1% low (the slowest frames, the ones you feel); stutters a minute; # what set the pace (the graphics card, the CPU, or a cap) and what that means for the game's settings; # the PC's part of the input delay, from your input to the screen; # and what the PC did meanwhile, read once a second from Windows' own counters (and nvidia-smi on an NVIDIA card): # the CPU held back by heat or power, the graphics card slowing for heat, memory running short, the other programs # using the CPU, and which of the stutters came with any of it. # Run it once stock and once with OmniDx (after the tune and a restart), same game, same scene, same settings: it puts # the two side by side and draws a 1080 x 1920 result card in C:\OmniDx\bench, ready to post. # # $env:OMNIDX_BENCH_GAME='cs2.exe' record this game only (otherwise: the game that drew the most frames) # $env:OMNIDX_BENCH_LABEL='stock' or 'omnidx': skips the question # $env:OMNIDX_BENCH_SECONDS='90' how long to record (default 60, 20 to 300) # $env:OMNIDX_BENCH_MODE='compare' record nothing: the side by side and the card from the runs already saved # $env:OMNIDX_BENCH_MODE='fetch' only fetch and check PresentMon $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { } # Everything but PresentMon comes from omnidx.net; the Windows check serves a copy on the build machine (127.0.0.1 # only), answers the questions with OMNIDX_YES and reads a PresentMon file it made (OMNIDX_BENCH_CSV) instead of a game. $base = 'https://omnidx.net' if ("$env:OMNIDX_BASE" -match '^http://(127\.0\.0\.1|localhost)(:\d+)?$') { $base = "$env:OMNIDX_BASE" } $BenchVersion = '1.2.0' $quiet = "$env:OMNIDX_YES" -eq '1' $mode = "$env:OMNIDX_BENCH_MODE".ToLower(); if (-not $mode) { $mode = 'run' } $dir = if ($env:OMNIDX_BENCH_DIR) { $env:OMNIDX_BENCH_DIR } else { 'C:\OmniDx\bench' } $csvIn = "$env:OMNIDX_BENCH_CSV" $want = ("$env:OMNIDX_BENCH_GAME" -replace '[^A-Za-z0-9 ._()-]', '').Trim() $label = "$env:OMNIDX_BENCH_LABEL".ToLower(); if ($label -notin @('stock', 'omnidx')) { $label = '' } $secs = 60; if ("$env:OMNIDX_BENCH_SECONDS" -match '^\d+$') { $secs = [Math]::Min(300, [Math]::Max(20, [int]$env:OMNIDX_BENCH_SECONDS)) } $delay = 10 # PresentMon, pinned: this release, this file, this SHA-256. A download that does not match is deleted, never run. $pmVersion = '2.4.1' $pmUrl = "https://github.com/GameTechDev/PresentMon/releases/download/v$pmVersion/PresentMon-$pmVersion-x64.exe" $pmSha = 'D74183E7AE630F72CD3690BE0373ECBFDC6CBB86578148AAB8FA2A7166068F34' # Games by their exe, for the name on the card and to pick the game out of everything that drew frames. $Games = @{ 'FortniteClient-Win64-Shipping.exe' = 'Fortnite'; 'VALORANT-Win64-Shipping.exe' = 'VALORANT'; 'cs2.exe' = 'Counter-Strike 2' 'r5apex.exe' = 'Apex Legends'; 'r5apex_dx12.exe' = 'Apex Legends'; 'RocketLeague.exe' = 'Rocket League' 'RainbowSix.exe' = 'Rainbow Six Siege'; 'RainbowSix_Vulkan.exe' = 'Rainbow Six Siege'; 'Marvel-Win64-Shipping.exe' = 'Marvel Rivals' 'javaw.exe' = 'Minecraft'; 'Minecraft.Windows.exe' = 'Minecraft'; 'Overwatch.exe' = 'Overwatch'; 'cod.exe' = 'Call of Duty' 'League of Legends.exe' = 'League of Legends'; 'GTA5.exe' = 'GTA V'; 'GTA5_Enhanced.exe' = 'GTA V'; 'RobloxPlayerBeta.exe' = 'Roblox' 'TslGame.exe' = 'PUBG'; 'dota2.exe' = 'Dota 2'; 'destiny2.exe' = 'Destiny 2'; 'Cyberpunk2077.exe' = 'Cyberpunk 2077' 'eldenring.exe' = 'Elden Ring'; 'project8.exe' = 'Deadlock'; 'Discovery.exe' = 'THE FINALS' } # Things that draw frames and are not the game: never recorded, never picked. $NotGames = @('dwm.exe', 'explorer.exe', 'WindowsTerminal.exe', 'OpenConsole.exe', 'conhost.exe', 'powershell.exe', 'pwsh.exe', 'msedge.exe', 'msedgewebview2.exe', 'chrome.exe', 'firefox.exe', 'opera.exe', 'brave.exe', 'Discord.exe', 'Spotify.exe', 'steam.exe', 'steamwebhelper.exe', 'EpicGamesLauncher.exe', 'EpicWebHelper.exe', 'Battle.net.exe', 'RiotClientServices.exe', 'RiotClientUx.exe', 'RiotClientUxRender.exe', 'obs64.exe', 'NVIDIA Overlay.exe', 'nvsphelper64.exe', 'GameBar.exe', 'TextInputHost.exe', 'SearchHost.exe', 'StartMenuExperienceHost.exe', 'ShellExperienceHost.exe', 'ApplicationFrameHost.exe', 'SystemSettings.exe', 'Taskmgr.exe', 'Code.exe', 'Medal.exe', 'Overwolf.exe', "PresentMon-$pmVersion-x64.exe") function Say([string]$t, [string]$c = 'Gray') { Write-Host " $t" -ForegroundColor $c } function Ask([string]$q, [string]$default = '') { if ($quiet) { return $default } $a = Read-Host " $q" if ([string]::IsNullOrWhiteSpace($a)) { return $default } return $a.Trim() } function Beep([int]$f, [int]$ms) { try { [Console]::Beep($f, $ms) } catch { } } function Pct([double[]]$sorted, [double]$p) { $n = $sorted.Length; return $sorted[[Math]::Min($n - 1, [Math]::Max(0, [int][Math]::Ceiling($p * $n) - 1))] } function Median([double[]]$v) { $s = [double[]]$v.Clone(); [Array]::Sort($s); $n = $s.Length if ($n % 2) { return $s[($n - 1) / 2] } else { return ($s[$n / 2 - 1] + $s[$n / 2]) / 2 } } function Side([string]$l) { if ($l -eq 'omnidx') { 'With OmniDx' } else { 'Stock' } } function Say-NoGame([string[]]$seen) { Say 'No game frames were recorded. Was the game in front and drawing for the whole minute?' 'Red' if ($seen.Count) { Say ('Seen: {0}' -f ($seen -join ', ')) 'DarkGray' } Say "To name the game: `$env:OMNIDX_BENCH_GAME='game.exe'; irm omnidx.net/bench.ps1 | iex" 'DarkGray' } Write-Host '' Say 'OmniDx Bench' 'Magenta' Say 'Your game, your PC: average FPS, 1% and 0.1% lows, stutters, input delay and what holds your frames back, stock and with OmniDx. Free; changes nothing.' 'DarkGray' Write-Host '' if ($mode -notin @('run', 'compare', 'fetch')) { Say "Unknown mode '$mode': use compare or fetch, or leave it empty." 'Yellow'; return } # Recording frames needs administrator rights (PresentMon listens to Windows' own frame events). Reading a file or # the saved runs does not. The new window gets the same choices, cleaned so nothing but them crosses. $records = $mode -ne 'compare' -and -not $csvIn # C:\OmniDx is changed by administrators only (the tune closes it: the scripts in it run as administrator), so a # comparison from an ordinary window, which writes its card there, asks for the rights as well. function Test-Writable([string]$d) { try { New-Item -ItemType Directory -Force -Path $d -ErrorAction Stop | Out-Null; $t = Join-Path $d ('.w' + [guid]::NewGuid().ToString('N')); [IO.File]::WriteAllText($t, ''); Remove-Item -LiteralPath $t -Force; return $true } catch { return $false } } $isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $isAdmin -and (($records -and $mode -eq 'run') -or -not (Test-Writable $dir))) { Say $(if ($records) { 'Asking for administrator rights (PresentMon needs them to see the frames)...' } else { "Asking for administrator rights (the runs are kept in $dir, which only administrators change)..." }) 'DarkGray' $cmd = "`$env:OMNIDX_BENCH_MODE='$mode'; `$env:OMNIDX_BENCH_GAME='$want'; `$env:OMNIDX_BENCH_LABEL='$label'; `$env:OMNIDX_BENCH_SECONDS='$secs'; irm $base/bench.ps1 | iex" Start-Process powershell.exe -Verb RunAs -ArgumentList @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-NoExit', '-Command', $cmd) return } New-Item -ItemType Directory -Force -Path $dir | Out-Null # ---------------------------------------------------------------- PresentMon function Get-PresentMon { $exe = Join-Path $dir "PresentMon-$pmVersion-x64.exe" for ($try = 0; $try -lt 2; $try++) { if (-not (Test-Path $exe)) { Say "Fetching PresentMon $pmVersion from Intel's GitHub release (about 1 MB, once)..." 'DarkGray' Invoke-WebRequest -Uri $pmUrl -OutFile $exe -UseBasicParsing -TimeoutSec 120 } $h = (Get-FileHash -Path $exe -Algorithm SHA256).Hash if ($h -eq $pmSha) { return $exe } Say "PresentMon's fingerprint is $h, not the one pinned here; deleting it." 'Yellow' Remove-Item $exe -Force } throw 'PresentMon did not match its pinned SHA-256 twice, so it was not run. Nothing was changed.' } # ---------------------------------------------------------------- reading PresentMon's file # One list of frame times per swap chain (a game has one; the menu and the match can be two). PresentMon 2 calls the # column MsBetweenPresents, 1.x msBetweenPresents: the time from one frame to the next, the frame rate as the game ran it. function Read-PresentMon([string]$path) { $chains = @{} $rd = New-Object System.IO.StreamReader $path try { $head = $rd.ReadLine(); if (-not $head) { return $chains } $cols = $head.Split(','); $ix = @{} for ($i = 0; $i -lt $cols.Count; $i++) { $ix[$cols[$i].Trim()] = $i } $cFt = $null; foreach ($n in 'MsBetweenPresents', 'FrameTime') { if ($ix.ContainsKey($n)) { $cFt = $ix[$n]; break } } if (-not $ix.ContainsKey('Application') -or $null -eq $cFt) { throw "$path is not a PresentMon file (no Application or MsBetweenPresents column)." } $cApp = $ix['Application']; $cPid = $ix['ProcessID']; $cSwap = $ix['SwapChainAddress']; $cMode = $ix['PresentMode']; $cSync = $ix['SyncInterval'] # PresentMon 2's split of each frame (1.1.0): how long the CPU and the graphics card each worked on it, and how long # it took to reach the screen, from the frame's start and from the input that went into it. A 1.x file has none of # these; a frame without one says NA. The names PresentMon has used for each, newest first. $col = { param([string[]]$names) foreach ($n in $names) { if ($ix.ContainsKey($n)) { return $ix[$n] } }; return -1 } $cCpu = & $col 'MsCPUBusy', 'CPUBusy'; $cGpu = & $col 'MsGPUBusy', 'GPUBusy' $cDisp = & $col 'DisplayLatency', 'MsDisplayLatency'; $cIn = & $col 'MsAllInputToPhotonLatency', 'AllInputToPhotonLatency'; $cPcl = & $col 'MsPCLatency', 'PCLatency' $inv = [Globalization.CultureInfo]::InvariantCulture; $flt = [Globalization.NumberStyles]::Float; $ft = 0.0; $v = 0.0 while ($null -ne ($line = $rd.ReadLine())) { $f = $line.Split(',') if ($f.Count -le $cFt) { continue } if (-not [double]::TryParse($f[$cFt], $flt, $inv, [ref]$ft) -or $ft -le 0 -or $ft -gt 5000) { continue } $k = '{0}|{1}|{2}' -f $f[$cApp], $(if ($null -ne $cPid) { $f[$cPid] }), $(if ($null -ne $cSwap) { $f[$cSwap] }) $c = $chains[$k] if (-not $c) { $c = @{ app = $f[$cApp]; ft = New-Object 'System.Collections.Generic.List[double]'; modes = @{}; sync = @{} cpu = New-Object 'System.Collections.Generic.List[double]'; gpu = New-Object 'System.Collections.Generic.List[double]' disp = New-Object 'System.Collections.Generic.List[double]'; inp = New-Object 'System.Collections.Generic.List[double]'; pcl = New-Object 'System.Collections.Generic.List[double]' } $chains[$k] = $c } $c.ft.Add($ft) if ($null -ne $cMode) { $c.modes[$f[$cMode]] = 1 + [int]$c.modes[$f[$cMode]] } if ($null -ne $cSync) { $c.sync[$f[$cSync]] = 1 + [int]$c.sync[$f[$cSync]] } # One entry per frame for the CPU and graphics-card times (-1 where the frame has none), so each lines up with its # frame time; the latencies only where the frame has one. $c.cpu.Add($(if ($cCpu -ge 0 -and $cCpu -lt $f.Count -and [double]::TryParse($f[$cCpu], $flt, $inv, [ref]$v) -and $v -ge 0) { $v } else { -1.0 })) $c.gpu.Add($(if ($cGpu -ge 0 -and $cGpu -lt $f.Count -and [double]::TryParse($f[$cGpu], $flt, $inv, [ref]$v) -and $v -ge 0) { $v } else { -1.0 })) if ($cDisp -ge 0 -and $cDisp -lt $f.Count -and [double]::TryParse($f[$cDisp], $flt, $inv, [ref]$v) -and $v -gt 0 -and $v -lt 1000) { $c.disp.Add($v) } if ($cIn -ge 0 -and $cIn -lt $f.Count -and [double]::TryParse($f[$cIn], $flt, $inv, [ref]$v) -and $v -gt 0 -and $v -lt 1000) { $c.inp.Add($v) } if ($cPcl -ge 0 -and $cPcl -lt $f.Count -and [double]::TryParse($f[$cPcl], $flt, $inv, [ref]$v) -and $v -gt 0 -and $v -lt 1000) { $c.pcl.Add($v) } } } finally { $rd.Close() } return $chains } function Select-Chain($chains) { $list = @($chains.Values | Where-Object { $_.ft.Count -ge 100 }) if ($want) { $list = @($list | Where-Object { $_.app -ieq $want }) } else { $list = @($list | Where-Object { $NotGames -notcontains $_.app }) } if (-not $list.Count) { return $null } $known = @($list | Where-Object { $Games.ContainsKey($_.app) }) $pool = if ($known.Count) { $known } else { $list } return ($pool | Sort-Object { $_.ft.Count } -Descending | Select-Object -First 1) } # Average FPS is frames over time. The 1% low is the frame rate at the 99th percentile frame time (one frame in a # hundred is slower than this), the 0.1% low at the 99.9th. A stutter is a frame that took over twice the median. function Get-Stats($chain) { $ft = $chain.ft.ToArray(); $n = $ft.Length; $total = 0.0 foreach ($x in $ft) { $total += $x } $sorted = [double[]]$ft.Clone(); [Array]::Sort($sorted) $median = Pct $sorted 0.5 $stutters = 0; foreach ($x in $ft) { if ($x -gt 2 * $median) { $stutters++ } } $top = { param($h) if ($h.Count) { ($h.GetEnumerator() | Sort-Object Value -Descending | Select-Object -First 1).Key } else { '' } } $s = [ordered]@{ frames = $n; seconds = [Math]::Round($total / 1000, 1) avg = [Math]::Round($n * 1000 / $total, 1) low1 = [Math]::Round(1000 / (Pct $sorted 0.99), 1) low01 = [Math]::Round(1000 / (Pct $sorted 0.999), 1) medianMs = [Math]::Round($median, 2) stuttersPerMin = [Math]::Round($stutters / [Math]::Max($total / 60000, 0.01), 1) presentMode = [string](& $top $chain.modes); syncInterval = [string](& $top $chain.sync) } foreach ($k in (Get-Split $chain).GetEnumerator()) { $s[$k.Key] = $k.Value } return $s } <# What set the pace (1.1.0). A frame the graphics card worked on for 85% of its time or more, and longer than the CPU did, waited on the card; one the CPU worked on for 85% or more, and longer, waited on the CPU (in practice the game's own main thread). Most frames one way names the limit; neither busy for most frames means something else set the pace: a frame cap, V-Sync, or the game's own limit. And the PC's part of the input delay, as PresentMon measures it: from the earliest key press or mouse move that went into a frame until the frame was on the screen (median, and the 95th percentile for the slow end), else from the frame's start to the screen. #> function Get-Split($chain) { $r = [ordered]@{ splitFrames = 0; gpuBoundPct = $null; cpuBoundPct = $null; limit = ''; cpuMs = $null; gpuMs = $null; inputMs = $null; inputP95 = $null; displayMs = $null; pcLatencyMs = $null } $ft = $chain.ft; $n = $ft.Count if ($chain.cpu -and $chain.gpu -and $chain.cpu.Count -eq $n -and $chain.gpu.Count -eq $n) { $valid = 0; $g = 0; $c = 0 $cpuL = New-Object 'System.Collections.Generic.List[double]'; $gpuL = New-Object 'System.Collections.Generic.List[double]' for ($i = 0; $i -lt $n; $i++) { $cv = $chain.cpu[$i]; $gv = $chain.gpu[$i] if ($cv -lt 0 -or $gv -lt 0) { continue } $valid++; $cpuL.Add($cv); $gpuL.Add($gv) $x = $ft[$i] if ($gv -ge 0.85 * $x -and $gv -ge $cv) { $g++ } elseif ($cv -ge 0.85 * $x -and $cv -gt $gv) { $c++ } } # Half the frames or more carry the split, or it says nothing about the run. if ($valid -ge [Math]::Max(50, $n / 2)) { $r.splitFrames = $valid $r.gpuBoundPct = [Math]::Round(100.0 * $g / $valid, 0); $r.cpuBoundPct = [Math]::Round(100.0 * $c / $valid, 0) $r.cpuMs = [Math]::Round((Median $cpuL.ToArray()), 2); $r.gpuMs = [Math]::Round((Median $gpuL.ToArray()), 2) $r.limit = if ($r.gpuBoundPct -ge 60) { 'gpu' } elseif ($r.cpuBoundPct -ge 60) { 'cpu' } elseif ($r.gpuBoundPct + $r.cpuBoundPct -ge 60) { 'mixed' } else { 'neither' } } } if ($chain.inp -and $chain.inp.Count -ge 20) { $a = $chain.inp.ToArray(); $r.inputMs = [Math]::Round((Median $a), 1); $sa = [double[]]$a.Clone(); [Array]::Sort($sa); $r.inputP95 = [Math]::Round((Pct $sa 0.95), 1) } if ($chain.disp -and $chain.disp.Count -ge 20) { $r.displayMs = [Math]::Round((Median $chain.disp.ToArray()), 1) } if ($chain.pcl -and $chain.pcl.Count -ge 20) { $r.pcLatencyMs = [Math]::Round((Median $chain.pcl.ToArray()), 1) } return $r } function Get-PcInfo { $pc = [ordered]@{ cpu = ''; gpu = ''; ramGb = 0; refreshHz = 0 } try { $pc.cpu = ((Get-CimInstance Win32_Processor | Select-Object -First 1).Name -replace '\s+', ' ').Trim() } catch { } try { $v = @(Get-CimInstance Win32_VideoController | Where-Object { $_.Name -notmatch 'Basic Display|Remote|Virtual|Parsec|Meta' }) if ($v.Count) { $pc.gpu = [string]$v[0].Name; $pc.refreshHz = [int]$v[0].CurrentRefreshRate } } catch { } try { $pc.ramGb = [int][Math]::Round((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB) } catch { } return $pc } # Whether the tune has run here, and whether the PC restarted since: the numbers after a tune count after a restart. function Get-TuneState { $s = [ordered]@{ ran = $false; version = ''; stamp = ''; restartedSince = $false } $sum = Get-ChildItem 'C:\OmniDx' -Filter 'summary-*.json' -ErrorAction SilentlyContinue | Sort-Object Name -Descending | Select-Object -First 1 if ($sum) { try { $j = Get-Content $sum.FullName -Raw | ConvertFrom-Json; if ([int]$j.changes -gt 0) { $s.ran = $true; $s.version = [string]$j.version; $s.stamp = [string]$j.stamp } } catch { } try { $s.restartedSince = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime -gt $sum.LastWriteTime } catch { } } return $s } # ---------------------------------------------------------------- what the PC did meanwhile (1.1.0) <# Once a second while PresentMon records: the CPU's speed against its rated clock and the limit its firmware puts on it (heat or power), the memory left, and on an NVIDIA card its temperature and whether it slowed for heat. All read from Windows' own counters by their WMI names (the same in every Windows language) and from NVIDIA's own nvidia-smi; no driver is installed and nothing is changed. Every program's CPU time is read at the start and the end, for what else ran during the game. #> # A program's arguments as one line, each one with a space in it quoted (NVIDIA Overlay.exe among the exclusions). function Join-Args([string[]]$argv) { return (($argv | ForEach-Object { if ($_ -match '[\s"]') { '"' + ($_ -replace '"', '\"') + '"' } else { $_ } }) -join ' ') } function Invoke-Quick([string]$exe, [string[]]$argv, [int]$ms = 3000) { try { $psi = New-Object System.Diagnostics.ProcessStartInfo $exe $psi.Arguments = Join-Args $argv $psi.UseShellExecute = $false; $psi.CreateNoWindow = $true; $psi.RedirectStandardOutput = $true; $psi.RedirectStandardError = $true $p = [System.Diagnostics.Process]::Start($psi) $o = $p.StandardOutput.ReadToEndAsync(); $null = $p.StandardError.ReadToEndAsync() if (-not $p.WaitForExit($ms)) { try { $p.Kill() } catch { }; return $null } return $o.Result } catch { return $null } } function Get-CpuTimes { $t = @{} foreach ($p in Get-Process -ErrorAction SilentlyContinue) { try { if ($null -ne $p.CPU) { $t[$p.Id] = @{ name = $p.ProcessName; cpu = [double]$p.CPU } } } catch { } } return $t } function New-Sampler { $s = @{ samples = New-Object System.Collections.ArrayList; sw = [System.Diagnostics.Stopwatch]::StartNew(); smi = $null; ramMb = 0; battery = $false; cpuRead = $false; procs = (Get-CpuTimes) } try { $s.ramMb = [int]((Get-CimInstance Win32_ComputerSystem -ErrorAction Stop).TotalPhysicalMemory / 1MB) } catch { } try { $s.battery = [bool](@(Get-CimInstance Win32_Battery -ErrorAction Stop | Where-Object { $_.BatteryStatus -eq 1 }).Count) } catch { } $s.smi = @("$env:SystemRoot\System32\nvidia-smi.exe", "$env:ProgramFiles\NVIDIA Corporation\NVSMI\nvidia-smi.exe") | Where-Object { Test-Path $_ } | Select-Object -First 1 return $s } function Add-Sample($s) { $x = [ordered]@{ t = [Math]::Round($s.sw.Elapsed.TotalSeconds, 1); perf = $null; limit = $null; busy = $null; mhz = $null; dpc = $null; availMb = $null; commitPct = $null; gpuC = $null; gpuHot = $false; gpuSlow = $false } try { $c = Get-CimInstance -ClassName Win32_PerfFormattedData_Counters_ProcessorInformation -Filter "Name='_Total'" -ErrorAction Stop | Select-Object -First 1 if ($c) { $s.cpuRead = $true $x.perf = [double]$c.PercentProcessorPerformance; $x.limit = [double]$c.PercentPerformanceLimit; $x.busy = [double]$c.PercentProcessorTime $x.dpc = [double]$c.PercentDPCTime + [double]$c.PercentInterruptTime if ([double]$c.ProcessorFrequency -gt 0 -and $x.perf -gt 0) { $x.mhz = [Math]::Round([double]$c.ProcessorFrequency * $x.perf / 100) } } } catch { } try { $m = Get-CimInstance -ClassName Win32_PerfFormattedData_PerfOS_Memory -ErrorAction Stop | Select-Object -First 1 if ($m) { $x.availMb = [double]$m.AvailableMBytes; if ([double]$m.CommitLimit -gt 0) { $x.commitPct = [Math]::Round(100.0 * [double]$m.CommittedBytes / [double]$m.CommitLimit, 1) } } } catch { } if ($s.smi) { # The same fields the tune reads; Active or Not Active, in English in every Windows language. $o = Invoke-Quick $s.smi @('--query-gpu=temperature.gpu,clocks_throttle_reasons.hw_thermal_slowdown,clocks_throttle_reasons.sw_thermal_slowdown,clocks_throttle_reasons.hw_slowdown,clocks_throttle_reasons.hw_power_brake_slowdown', '--format=csv,noheader,nounits') 2500 if ($o) { $f = @(($o -split "`r?`n")[0] -split ',\s*') if ($f.Count -ge 5) { $tc = 0; if ([int]::TryParse($f[0].Trim(), [ref]$tc)) { $x.gpuC = $tc } $x.gpuHot = ($f[1].Trim() -eq 'Active' -or $f[2].Trim() -eq 'Active') $x.gpuSlow = ($f[3].Trim() -eq 'Active' -or $f[4].Trim() -eq 'Active') } } } [void]$s.samples.Add($x) } <# The verdict on one run: what set the pace and what it means for settings, the PC's part of the input delay, and what the PC did meanwhile, with the stutters laid against it. Said in plain words, and saved with the run. #> function Get-Doctor($stats, $chain, $s, [string]$gameExe) { $d = [ordered]@{ limit = $stats.limit; gpuBoundPct = $stats.gpuBoundPct; cpuBoundPct = $stats.cpuBoundPct; inputMs = $stats.inputMs; inputP95 = $stats.inputP95; displayMs = $stats.displayMs; presentMode = $stats.presentMode sampled = 0; cpuRead = $false; cpuMhz = $null; cpuHeldSec = 0; memShortSec = 0; minAvailMb = $null; gpuMaxC = $null; gpuHotSec = 0; gpuSlowSec = 0; driverPct = $null; battery = $false; background = @(); stutters = 0; stuttersWith = [ordered]@{ memory = 0; cpuHeld = 0; gpuHot = 0 } } if (-not $s) { return $d } $d.battery = $s.battery; $d.cpuRead = $s.cpuRead # The first reading of a rate counter compares against nothing: it is left out. $sm = @($s.samples | Select-Object -Skip 1) $d.sampled = $sm.Count if ($sm.Count) { $mhz = @($sm | Where-Object { $_.mhz } | ForEach-Object { [double]$_.mhz }) if ($mhz.Count) { $d.cpuMhz = [int](($mhz | Measure-Object -Average).Average) } # A limit of 0 is a counter this CPU or this machine does not fill in, never a CPU held to nothing. $held = { param($x) $null -ne $x.limit -and $x.limit -ge 1 -and $x.limit -lt 95 -and $null -ne $x.busy -and $x.busy -ge 10 } $short = { param($x) ($null -ne $x.availMb -and $x.availMb -lt [Math]::Max(500, 0.04 * $s.ramMb)) -or ($null -ne $x.commitPct -and $x.commitPct -ge 92) } $d.cpuHeldSec = @($sm | Where-Object { & $held $_ }).Count $d.memShortSec = @($sm | Where-Object { & $short $_ }).Count $av = @($sm | Where-Object { $null -ne $_.availMb } | ForEach-Object { [double]$_.availMb }); if ($av.Count) { $d.minAvailMb = [int](($av | Measure-Object -Minimum).Minimum) } $gc = @($sm | Where-Object { $null -ne $_.gpuC } | ForEach-Object { [int]$_.gpuC }); if ($gc.Count) { $d.gpuMaxC = ($gc | Measure-Object -Maximum).Maximum } $d.gpuHotSec = @($sm | Where-Object { $_.gpuHot }).Count; $d.gpuSlowSec = @($sm | Where-Object { $_.gpuSlow }).Count $dp = @($sm | Where-Object { $null -ne $_.dpc } | ForEach-Object { [double]$_.dpc }); if ($dp.Count) { $d.driverPct = [Math]::Round(($dp | Measure-Object -Average).Average, 1) } # Each stutter against the readings around it: a frame's time is the sum of the frames before it, and a reading # within a second and a half either side counts (PresentMon starts its session in about a second). if ($chain) { $ft = $chain.ft; $sorted = [double[]]$ft.ToArray().Clone(); [Array]::Sort($sorted); $med = Pct $sorted 0.5 $t = 0.0 for ($i = 0; $i -lt $ft.Count; $i++) { $t += $ft[$i] / 1000 if ($ft[$i] -le 2 * $med) { continue } $d.stutters += 1 $near = @($sm | Where-Object { [Math]::Abs($_.t - $t) -le 1.5 }) if (@($near | Where-Object { & $short $_ }).Count) { $d.stuttersWith['memory'] += 1 } if (@($near | Where-Object { & $held $_ }).Count) { $d.stuttersWith['cpuHeld'] += 1 } if (@($near | Where-Object { $_.gpuHot -or $_.gpuSlow }).Count) { $d.stuttersWith['gpuHot'] += 1 } } } } # What else used the CPU between the first reading and now, by program, as a share of one core over the recording. $now = Get-CpuTimes; $secs = [Math]::Max(1.0, $s.sw.Elapsed.TotalSeconds) $use = @{} foreach ($id in $now.Keys) { if (-not $s.procs.ContainsKey($id)) { continue } $a = $s.procs[$id]; $b = $now[$id] if ($a.name -ne $b.name) { continue } $nm = $b.name if ($nm -in @('Idle', 'powershell', 'pwsh', 'conhost', 'nvidia-smi', 'WmiPrvSE') -or $nm -like 'PresentMon*' -or ($gameExe -and ($nm + '.exe') -ieq $gameExe)) { continue } $use[$nm] = [double]$use[$nm] + ($b.cpu - $a.cpu) } $d.background = @($use.GetEnumerator() | Where-Object { $_.Value / $secs * 100 -ge 2 } | Sort-Object Value -Descending | Select-Object -First 6 | ForEach-Object { [ordered]@{ name = $_.Key; corePct = [Math]::Round($_.Value / $secs * 100) } }) return $d } function Show-Doctor($d) { Write-Host '' Say 'What holds your frames back' 'White' switch ($d.limit) { 'gpu' { Say ("The graphics card set the pace: it worked through the whole frame in {0}% of frames, the CPU in {1}%." -f $d.gpuBoundPct, $d.cpuBoundPct) 'Cyan' Say " More frames come from the game's graphics settings: resolution or render scale, shadows, effects, and upscaling (DLSS, FSR or XeSS)." 'DarkGray' } 'cpu' { Say ("The CPU set the pace (in practice the game's own main thread): it worked through the whole frame in {0}% of frames, the graphics card in {1}%." -f $d.cpuBoundPct, $d.gpuBoundPct) 'Cyan' Say " Graphics settings change little here. View distance, crowds and physics do, and so does everything else that runs: the list below. A frame cap a little under your 1% low keeps the frame times even." 'DarkGray' } 'mixed' { Say ("The CPU and the graphics card took turns setting the pace (the card in {0}% of frames, the CPU in {1}%)." -f $d.gpuBoundPct, $d.cpuBoundPct) 'Cyan' } 'neither' { Say ("Neither was busy for most frames (the graphics card in {0}%, the CPU in {1}%): a frame cap, V-Sync or the game's own limit set the pace." -f $d.gpuBoundPct, $d.cpuBoundPct) 'Cyan' Say ' For the most the PC can do, lift the cap for the test; for steady frames in play, a cap is fine.' 'DarkGray' } default { Say 'This run carries no CPU and graphics-card split (an older PresentMon file): only the frame times.' 'DarkGray' } } if ($null -ne $d.inputMs) { Say ("The PC's part of your input delay: {0} ms from your input to the screen (median; {1} ms at the slow end). Your mouse and monitor add their own." -f $d.inputMs, $d.inputP95) 'Cyan' if ($d.limit -eq 'gpu') { Say " With the card at its limit, frames queue up in front of it: NVIDIA Reflex or AMD Anti-Lag in the game's own settings, or a frame cap a little under what the card reaches, takes that queue away." 'DarkGray' } } elseif ($null -ne $d.displayMs) { Say ("From a frame's start to the screen: {0} ms (median). No input landed in the recording, so the input-to-screen time is not measured here." -f $d.displayMs) 'Cyan' } # How the frames reached the screen, PresentMon's PresentMode for most of them (1.2.0): straight from the game (the # legacy flip of exclusive fullscreen, an independent flip a borderless window is promoted to, or a hardware overlay # plane's) or composed by Windows' desktop, which draws each frame again: about one refresh more delay. if ($d.presentMode -match '^Composed') { Say ("Frames reached the screen through Windows' desktop ({0}): it draws each one again, about one refresh of extra delay." -f $d.presentMode) 'Yellow' Say " Exclusive fullscreen in the game, or borderless with Optimizations for windowed games on (Settings > System > Display > Graphics), lets the game show its frames itself. An overlay or a window over the game keeps it composed." 'DarkGray' } elseif ($d.presentMode -match 'Flip|front buffer') { Say ("Frames reached the screen straight from the game ({0}): nothing added on the way." -f $d.presentMode) 'Gray' } if ($d.sampled -ge 3) { Say ('While you played (read every second, {0} readings):' -f $d.sampled) 'White' if ($d.battery) { Say ' This PC ran on battery: Windows and the maker hold it back on purpose then. Plug it in for a fair number.' 'Yellow' } if ($d.cpuMhz) { Say (" CPU: {0:0.0} GHz on average; held below its rated speed by its own heat or power limit for {1} of {2} s." -f ($d.cpuMhz / 1000), $d.cpuHeldSec, $d.sampled) $(if ($d.cpuHeldSec -ge [Math]::Max(3, $d.sampled / 10)) { 'Yellow' } else { 'Gray' }) } if ($d.cpuHeldSec -ge [Math]::Max(3, $d.sampled / 10)) { Say ' Heat or power: dust in the cooler, a fan curve that waits too long, or (on a laptop) the maker''s quiet mode. The undervolt guide on omnidx.net lowers the heat for the same speed.' 'DarkGray' } if ($null -ne $d.gpuMaxC) { Say (" Graphics card: {0} C at most; slowed for heat for {1} s, by its own hardware for {2} s." -f $d.gpuMaxC, $d.gpuHotSec, $d.gpuSlowSec) $(if ($d.gpuHotSec + $d.gpuSlowSec -ge 3) { 'Yellow' } else { 'Gray' }) } if ($null -ne $d.minAvailMb) { Say (" Memory: {0:0.0} GB free at the lowest; short for {1} s." -f ($d.minAvailMb / 1024), $d.memShortSec) $(if ($d.memShortSec -ge 3) { 'Yellow' } else { 'Gray' }) } if ($d.memShortSec -ge 3) { Say ' When memory runs short Windows reads it back from the disk, and that is a hitch you feel. Close what you do not need while playing (the list below), or add memory.' 'DarkGray' } if ($null -ne $d.driverPct -and $d.driverPct -ge 3) { Say (" Drivers took {0}% of the CPU on their own (interrupts and deferred calls): a lot. The OmniDx Hub's Drivers page measures which one." -f $d.driverPct) 'Yellow' } } if (@($d.background).Count) { Say (' Other programs using the CPU meanwhile: {0}.' -f ((@($d.background) | ForEach-Object { '{0} {1}% of a core' -f $_.name, $_.corePct }) -join ', ')) } if ($d.stutters -and $d.sampled -ge 3) { $w = $d.stuttersWith; $parts = @() if ($w.memory) { $parts += ('{0} with memory short' -f $w.memory) } if ($w.cpuHeld) { $parts += ('{0} with the CPU held back' -f $w.cpuHeld) } if ($w.gpuHot) { $parts += ('{0} with the graphics card slowed' -f $w.gpuHot) } Say (' Stutters: {0}{1}.' -f $d.stutters, $(if ($parts.Count) { '; around the same second: ' + ($parts -join ', ') } else { '; none came with heat, power or memory trouble, so look at the game itself (loading, shader compiling) or the programs above' })) 'Gray' } } # ---------------------------------------------------------------- side by side function Get-Side($runs, [string]$l) { $r = @($runs | Where-Object { $_.label -eq $l }) if (-not $r.Count) { return $null } return [ordered]@{ runs = $r.Count avg = Median ([double[]]@($r | ForEach-Object { [double]$_.avg })); low1 = Median ([double[]]@($r | ForEach-Object { [double]$_.low1 })) low01 = Median ([double[]]@($r | ForEach-Object { [double]$_.low01 })); stutters = Median ([double[]]@($r | ForEach-Object { [double]$_.stuttersPerMin })) modes = @($r | ForEach-Object { [string]$_.presentMode } | Select-Object -Unique); sync = @($r | ForEach-Object { [string]$_.syncInterval } | Select-Object -Unique) seconds = [int](Median ([double[]]@($r | ForEach-Object { [double]$_.seconds }))) # The PC's part of the input delay (1.1.0): only when every run of this side measured it. inputMs = $(if (-not @($r | Where-Object { $null -eq $_.inputMs }).Count) { Median ([double[]]@($r | ForEach-Object { [double]$_.inputMs })) } else { $null }) } } function Change([double]$a, [double]$b) { if ($a -le 0) { return 0.0 } return [Math]::Round(($b - $a) / $a * 100, 1) } function ChangeText([double]$pct) { if ([Math]::Abs($pct) -lt 3) { return 'about the same' } return ('{0}{1:0.0}%' -f $(if ($pct -gt 0) { '+' } else { '' }), $pct) } function Show-Compare([string]$gdir) { $runs = @(Get-ChildItem $gdir -Filter '*.json' -ErrorAction SilentlyContinue | Sort-Object Name | ForEach-Object { try { Get-Content $_.FullName -Raw | ConvertFrom-Json } catch { } } | Where-Object { $_ -and $_.avg }) if (-not $runs.Count) { Say "No runs saved in $gdir yet." 'Yellow'; return $null } $game = [string]$runs[-1].game $st = Get-Side $runs 'stock'; $om = Get-Side $runs 'omnidx' Write-Host '' if ($st -and $om) { Say "$game, on this PC" 'White' Say ('{0,-22}{1,10}{2,12} {3}' -f '', 'Stock', 'With OmniDx', 'Change') 'DarkGray' $rows = @(@('Average FPS', $st.avg, $om.avg, $false), @('1% low', $st.low1, $om.low1, $false), @('0.1% low', $st.low01, $om.low01, $false), @('Stutters a minute', $st.stutters, $om.stutters, $true)) if ($null -ne $st.inputMs -and $null -ne $om.inputMs) { $rows += , @('Input to screen, ms', $st.inputMs, $om.inputMs, $true) } foreach ($r in $rows) { $pc = Change $r[1] $r[2] $good = if ($r[3]) { $pc -le -3 } else { $pc -ge 3 }; $bad = if ($r[3]) { $pc -ge 3 } else { $pc -le -3 } Say ('{0,-22}{1,10:0.0}{2,12:0.0} {3}' -f $r[0], $r[1], $r[2], (ChangeText $pc)) $(if ($good) { 'Green' } elseif ($bad) { 'Red' } else { 'Gray' }) } Write-Host '' Say ('Medians of {0} stock run{1} and {2} with OmniDx. Two runs of one scene differ by 2 to 3% on their own, so a' -f $st.runs, $(if ($st.runs -ne 1) { 's' }), $om.runs) 'DarkGray' Say 'change smaller than 3% is called "about the same". Two or three runs each make the answer surer.' 'DarkGray' if (($st.modes + $om.modes | Select-Object -Unique).Count -gt 1) { Say ("The runs were not all in the same display mode ({0}): fullscreen against windowed is not a fair test." -f (($st.modes + $om.modes | Select-Object -Unique) -join ', ')) 'Yellow' } } else { $one = if ($st) { $st } else { $om } Say ('{0}, {1}: average {2:0.0} FPS, 1% low {3:0.0}, 0.1% low {4:0.0}, {5:0.0} stutters a minute ({6} run{7}).' -f $game, (Side $(if ($st) { 'stock' } else { 'omnidx' })), $one.avg, $one.low1, $one.low01, $one.stutters, $one.runs, $(if ($one.runs -ne 1) { 's' })) 'White' if ($st) { Say 'Now run the tune, restart, and run this again in the same scene: the two go side by side.' 'DarkGray' } else { Say 'For the side by side: undo (put everything back), restart, run this for the stock number, then the tune again.' 'DarkGray' } } foreach ($side in @($st, $om)) { if (-not $side) { continue } if ($side.sync | Where-Object { $_ -match '^[1-4]$' }) { Say 'V-Sync was on in a run: the frame rate stops at your refresh rate, which hides any gain. Turn it off for the test.' 'Yellow'; break } } foreach ($side in @($st, $om)) { if (-not $side) { continue } foreach ($cap in 30, 60, 75, 90, 100, 120, 144, 165, 180, 200, 240, 300, 360) { if ([Math]::Abs($side.avg - $cap) / $cap -lt 0.015 -and $side.low1 -gt 0.85 * $side.avg) { Say "A run looks capped at $cap FPS (a frame cap or V-Sync): the average cannot go above it, so compare the lows, or lift the cap for the test." 'Yellow'; break } } } return @{ game = $game; stock = $st; omnidx = $om; last = $runs[-1] } } # ---------------------------------------------------------------- the card function New-Card([string]$path, $cmp) { Add-Type -AssemblyName System.Drawing $W = 1080; $H = 1920 $bmp = New-Object System.Drawing.Bitmap $W, $H $g = [System.Drawing.Graphics]::FromImage($bmp) $g.SmoothingMode = 'AntiAlias'; $g.TextRenderingHint = 'AntiAlias'; $g.InterpolationMode = 'HighQualityBicubic' $col = { param($hex, $a = 255) $v = [Convert]::ToInt32($hex.TrimStart('#'), 16); [System.Drawing.Color]::FromArgb($a, ($v -shr 16) -band 255, ($v -shr 8) -band 255, $v -band 255) } $font = { param($size, $style = 'Bold', $family = 'Segoe UI') New-Object System.Drawing.Font($family, [single]$size, [System.Drawing.FontStyle]$style, [System.Drawing.GraphicsUnit]::Pixel) } $brush = { param($c) New-Object System.Drawing.SolidBrush $c } $center = New-Object System.Drawing.StringFormat; $center.Alignment = 'Center'; $center.LineAlignment = 'Near' $left = New-Object System.Drawing.StringFormat; $left.Alignment = 'Near' $right = New-Object System.Drawing.StringFormat; $right.Alignment = 'Far' $grad = { param($x, $y, $w, $h) New-Object System.Drawing.Drawing2D.LinearGradientBrush((New-Object System.Drawing.RectangleF $x, $y, $w, $h), (& $col '#8B5CF6'), (& $col '#D946EF'), [single]0) } $round = { param($x, $y, $w, $h, $r) $p = New-Object System.Drawing.Drawing2D.GraphicsPath $p.AddArc($x, $y, $r * 2, $r * 2, 180, 90); $p.AddArc($x + $w - $r * 2, $y, $r * 2, $r * 2, 270, 90) $p.AddArc($x + $w - $r * 2, $y + $h - $r * 2, $r * 2, $r * 2, 0, 90); $p.AddArc($x, $y + $h - $r * 2, $r * 2, $r * 2, 90, 90); $p.CloseFigure(); $p } $fit = { param($text, $size, $maxW, $style = 'Bold') $s = $size; while ($s -gt 20 -and $g.MeasureString($text, (& $font $s $style)).Width -gt $maxW) { $s -= 4 }; & $font $s $style } $num = { param($v) if ($v -ge 100) { '{0:0}' -f $v } else { '{0:0.#}' -f $v } } $g.Clear((& $col '#050308')) foreach ($glow in @(@(-260, -420, 1600, 1300, '#6D28D9', 120), @(300, 1250, 1100, 900, '#D946EF', 46))) { $gp = New-Object System.Drawing.Drawing2D.GraphicsPath; $gp.AddEllipse($glow[0], $glow[1], $glow[2], $glow[3]) $pg = New-Object System.Drawing.Drawing2D.PathGradientBrush $gp $pg.CenterColor = & $col $glow[4] $glow[5]; $pg.SurroundColors = @((& $col '#050308' 0)); $g.FillPath($pg, $gp) } # The logo (from omnidx.net, kept next to the runs), or the name when it cannot be fetched. $logo = Join-Path $dir 'omnidx-logo.png' if (-not (Test-Path $logo)) { try { Invoke-WebRequest -Uri "$base/studio/assets/logo/omnidx-logo.png" -OutFile $logo -UseBasicParsing -TimeoutSec 20 } catch { } } $y = 96 if (Test-Path $logo) { try { $im = [System.Drawing.Image]::FromFile($logo); $lw = 380; $lh = [int]($im.Height * $lw / $im.Width); $g.DrawImage($im, [int](($W - $lw) / 2), $y, $lw, $lh); $im.Dispose(); $y += $lh + 26 } catch { $y += 10 } } else { $g.DrawString('OMNIDX', (& $font 64 'Bold'), (& $grad 0 $y $W 80), [single]($W / 2), [single]$y, $center); $y += 110 } $g.DrawString('B E N C H R E S U L T', (& $font 28 'Bold'), (& $brush (& $col '#A78BFA')), [single]($W / 2), [single]$y, $center); $y += 52 $g.DrawString($cmp.game, (& $fit $cmp.game 88 960), (& $brush (& $col '#F1ECFF')), [single]($W / 2), [single]$y, $center); $y += 118 $g.DrawString('Measured on this PC with PresentMon', (& $font 32 'Regular'), (& $brush (& $col '#9A8FB8')), [single]($W / 2), [single]$y, $center); $y += 80 $st = $cmp.stock; $om = $cmp.omnidx; $both = $st -and $om $panelY = $y $arrow = [string][char]0x2192 $g.FillPath((& $brush (& $col '#0E0A17' 235)), (& $round 60 $panelY 960 480 36)); $g.DrawPath((New-Object System.Drawing.Pen (& $col '#2A1F45'), 2), (& $round 60 $panelY 960 480 36)) $g.DrawString('AVERAGE FPS', (& $font 30 'Bold'), (& $brush (& $col '#7D7199')), [single]($W / 2), [single]($panelY + 40), $center) if ($both) { $g.DrawString('STOCK', (& $font 28 'Bold'), (& $brush (& $col '#9A8FB8')), [single]290, [single]($panelY + 110), $center) $g.DrawString('WITH OMNIDX', (& $font 28 'Bold'), (& $brush (& $col '#C4B5FD')), [single]790, [single]($panelY + 110), $center) $g.DrawString((& $num $st.avg), (& $font 150 'Bold'), (& $brush (& $col '#CFC6E6')), [single]290, [single]($panelY + 140), $center) $g.DrawString((& $num $om.avg), (& $font 150 'Bold'), (& $grad 560 ($panelY + 140) 460 200), [single]790, [single]($panelY + 140), $center) $g.DrawString($arrow, (& $font 90 'Bold'), (& $brush (& $col '#6D5A99')), [single]540, [single]($panelY + 170), $center) $pc = Change $st.avg $om.avg; $t = ChangeText $pc $cc = if ($pc -ge 3) { '#34D399' } elseif ($pc -le -3) { '#F87171' } else { '#C4B5FD' } $g.DrawString($t, (& $font 64 'Bold'), (& $brush (& $col $cc)), [single]($W / 2), [single]($panelY + 356), $center) } else { $one = if ($st) { $st } else { $om } $g.DrawString((Side $(if ($st) { 'stock' } else { 'omnidx' })).ToUpper(), (& $font 28 'Bold'), (& $brush (& $col '#C4B5FD')), [single]($W / 2), [single]($panelY + 110), $center) $g.DrawString((& $num $one.avg), (& $font 190 'Bold'), (& $grad 200 ($panelY + 150) 680 240), [single]($W / 2), [single]($panelY + 160), $center) } $y = $panelY + 520 $rows = @(@('1% low', 'low1', $false), @('0.1% low', 'low01', $false), @('Stutters a minute', 'stutters', $true)) # The PC's part of the input delay as a fourth row when both sides measured it (1.1.0); the rows close up to fit. if ($both -and $null -ne $st.inputMs -and $null -ne $om.inputMs) { $rows += , @('Input delay, ms', 'inputMs', $true) } $step = if ($rows.Count -gt 3) { 96 } else { 110 } $panelH = 50 + $step * $rows.Count $g.FillPath((& $brush (& $col '#0E0A17' 235)), (& $round 60 $y 960 $panelH 36)); $g.DrawPath((New-Object System.Drawing.Pen (& $col '#2A1F45'), 2), (& $round 60 $y 960 $panelH 36)) $ry = $y + 28 foreach ($r in $rows) { $g.DrawString($r[0], (& $font 40 'Bold'), (& $brush (& $col '#F1ECFF')), [single]104, [single]($ry + 26), $left) if ($both) { $a = $st[$r[1]]; $b = $om[$r[1]]; $pc = Change $a $b $good = if ($r[2]) { $pc -le -3 } else { $pc -ge 3 }; $bad = if ($r[2]) { $pc -ge 3 } else { $pc -le -3 } $g.DrawString(('{0} {2} {1}' -f (& $num $a), (& $num $b), $arrow), (& $font 54 'Bold'), (& $brush (& $col '#F1ECFF')), [single]976, [single]($ry + 6), $right) $g.DrawString((ChangeText $pc), (& $font 28 'Bold'), (& $brush (& $col $(if ($good) { '#34D399' } elseif ($bad) { '#F87171' } else { '#9A8FB8' }))), [single]976, [single]($ry + 72), $right) } else { $one = if ($st) { $st } else { $om } $g.DrawString((& $num $one[$r[1]]), (& $font 54 'Bold'), (& $brush (& $col '#F1ECFF')), [single]976, [single]($ry + 14), $right) } $ry += $step if ($r[0] -ne $rows[-1][0]) { $g.FillRectangle((& $brush (& $col '#2A1F45')), 104, $ry - 4, 872, 2) } } $y += $panelH + 40 $last = $cmp.last $secsTxt = if ($both) { '{0} s of the same scene each' -f $st.seconds } else { '{0} s' -f $(if ($st) { $st.seconds } else { $om.seconds }) } $foot = @(('{0} | PresentMon {1} | {2}' -f $secsTxt, $pmVersion, (Get-Date).ToString('d MMM yyyy', [Globalization.CultureInfo]::InvariantCulture)), [string]$last.pc.cpu, $(if ($last.pc.gpu) { '{0}{1}' -f $last.pc.gpu, $(if ([int]$last.pc.refreshHz -ge 30) { " | $($last.pc.refreshHz) Hz" }) } else { '' })) foreach ($l in $foot) { if ($l) { $g.DrawString($l, (& $fit $l 30 960 'Regular'), (& $brush (& $col '#9A8FB8')), [single]($W / 2), [single]$y, $center); $y += 46 } } $y += 14 $note = if ($both) { 'One PC, one scene. Yours will differ: run the free bench on yours.' } else { 'Run it again with the other setup for the side by side.' } $g.DrawString($note, (& $fit $note 30 960 'Regular'), (& $brush (& $col '#7D7199')), [single]($W / 2), [single]$y, $center) $y = [Math]::Max($y + 70, 1740) $g.DrawString('omnidx.net', (& $font 64 'Bold'), (& $grad 300 $y 480 80), [single]($W / 2), [single]$y, $center) $g.Dispose() $bmp.Save($path, [System.Drawing.Imaging.ImageFormat]::Png); $bmp.Dispose() } # ---------------------------------------------------------------- run if ($records) { $pm = Get-PresentMon; Say "PresentMon $pmVersion checked (SHA-256 matches)." 'Green' } if ($mode -eq 'fetch') { return } if ($mode -eq 'compare') { $gdir = if ($want) { Join-Path $dir (($(if ($Games.ContainsKey($want)) { $Games[$want] } else { $want -replace '\.exe$', '' }) -replace '[^A-Za-z0-9]+', '-').Trim('-').ToLower()) } else { (Get-ChildItem $dir -Directory -ErrorAction SilentlyContinue | Sort-Object LastWriteTime -Descending | Select-Object -First 1).FullName } if (-not $gdir -or -not (Test-Path $gdir)) { Say "No runs saved in $dir yet: run it without a mode first." 'Yellow'; return } $cmp = Show-Compare $gdir if ($cmp) { $card = Join-Path $gdir 'card.png'; New-Card $card $cmp; Say "Result card: $card" 'Green'; if (-not $quiet) { Start-Process $card } } return } $tune = Get-TuneState if (-not $label) { $def = if ($tune.ran) { '2' } else { '1' } Say '1 Stock: OmniDx has not run on this PC (or undo ran and the PC restarted since)' 'White' Say '2 With OmniDx: after the tune and a restart' 'White' $label = if ((Ask "Type 1 or 2 and press Enter (Enter alone: $def)" $def) -eq '2') { 'omnidx' } else { 'stock' } } if ($label -eq 'omnidx' -and $tune.ran -and -not $tune.restartedSince) { Say 'The PC has not restarted since the tune: what it switched off is still running until it does. Restart first for the real number.' 'Yellow' } if ($label -eq 'stock' -and $tune.ran) { Say 'Heads up: the tune has run here. For a stock number, undo first ($env:OMNIDX_MODE=''undo''; irm omnidx.net/go.ps1 | iex), then restart.' 'Yellow' } $stamp = Get-Date -Format 'yyyy-MM-dd_HH-mm-ss' $csv = Join-Path $dir "capture-$stamp.csv" $sampler = $null if ($csvIn) { Copy-Item $csvIn $csv -Force # The Windows check reads the counters on their own for a few seconds (no game, no PresentMon) to prove they answer. if ("$env:OMNIDX_BENCH_SAMPLE" -match '^\d+$') { $sampler = New-Sampler while ($sampler.sw.Elapsed.TotalSeconds -lt [int]$env:OMNIDX_BENCH_SAMPLE) { Add-Sample $sampler; Start-Sleep -Milliseconds ([Math]::Max(50, 1000 - ($sampler.sw.ElapsedMilliseconds % 1000))) } } } else { Write-Host '' Say 'For a fair test: same game, same map or replay or benchmark scene, same settings, V-Sync and frame caps off,' 'DarkGray' Say 'nothing else open you would not normally have open. Do it twice each way if you can.' 'DarkGray' Write-Host '' Say 'Start the game and get to the scene. Then come back here and press Enter.' 'White' if (-not $quiet) { [void](Read-Host ' Press Enter when you are ready') } Say "Click back into the game now. Recording starts in $delay seconds and lasts $secs; one beep at the start, two at the end." 'White' for ($i = $delay; $i -gt 0; $i--) { Write-Host ("`r {0,2} " -f $i) -NoNewline; Start-Sleep -Seconds 1 } Write-Host "`r Recording... " Beep 880 200 $a = @('--output_file', $csv, '--timed', "$secs", '--terminate_after_timed', '--stop_existing_session', '--session_name', 'OmniDxBench', '--no_console_stats') if ($want) { $a += @('--process_name', $want) } else { foreach ($n in $NotGames) { $a += @('--exclude', $n) } } # PresentMon runs on its own while the readings are taken, once a second, until it stops at the end of the time. $sampler = New-Sampler $psi = New-Object System.Diagnostics.ProcessStartInfo $pm $psi.Arguments = Join-Args $a $psi.UseShellExecute = $false; $psi.CreateNoWindow = $true; $psi.RedirectStandardOutput = $true; $psi.RedirectStandardError = $true $p = [System.Diagnostics.Process]::Start($psi) $oT = $p.StandardOutput.ReadToEndAsync(); $eT = $p.StandardError.ReadToEndAsync() while (-not $p.HasExited) { Add-Sample $sampler [void]$p.WaitForExit([Math]::Max(50, 1000 - ($sampler.sw.ElapsedMilliseconds % 1000))) } $p.WaitForExit() $code = $p.ExitCode $out = @((([string]$oT.Result) + "`n" + ([string]$eT.Result)) -split "`r?`n" | Where-Object { $_.Trim() }) Beep 660 150; Start-Sleep -Milliseconds 120; Beep 660 150 # PresentMon writes its file only once something it records draws a frame: no file and a clean exit is a minute # with no game in it, anything else is PresentMon failing. if (-not (Test-Path $csv)) { if ($code -eq 0) { Say-NoGame @(); return } Say "PresentMon could not record (exit $code): $(($out | Select-Object -Last 3) -join ' ')" 'Red'; return } } $chains = Read-PresentMon $csv $chain = Select-Chain $chains if (-not $chain) { Say-NoGame @($chains.Values | Sort-Object { $_.ft.Count } -Descending | Select-Object -First 5 | ForEach-Object { '{0} ({1} frames)' -f $_.app, $_.ft.Count }) Remove-Item $csv -Force -ErrorAction SilentlyContinue return } $app = [string]$chain.app $game = if ($Games.ContainsKey($app)) { $Games[$app] } else { $app -replace '\.exe$', '' } $gdir = Join-Path $dir (($game -replace '[^A-Za-z0-9]+', '-').Trim('-').ToLower()) New-Item -ItemType Directory -Force -Path $gdir | Out-Null $stats = Get-Stats $chain $rec = [ordered]@{ tool = 'OmniDx Bench'; bench = $BenchVersion; presentmon = $pmVersion; game = $game; exe = $app; label = $label; when = (Get-Date).ToString('s') } foreach ($k in $stats.Keys) { $rec[$k] = $stats[$k] } $rec.pc = Get-PcInfo $rec.tune = $tune $doctor = Get-Doctor $stats $chain $sampler $app $rec.doctor = $doctor $json = Join-Path $gdir "$stamp-$label.json" $rec | ConvertTo-Json -Depth 5 | Set-Content -Path $json -Encoding UTF8 Move-Item $csv (Join-Path $gdir "$stamp-$label.csv") -Force Say ('{0} ({1}), {2}: {3} frames in {4} s.' -f $game, $app, (Side $label), $stats.frames, $stats.seconds) 'Green' Show-Doctor $doctor $cmp = Show-Compare $gdir if ($cmp) { $card = Join-Path $gdir 'card.png' New-Card $card $cmp Write-Host '' Say "Result card: $card" 'Green' Say "Everything is in $gdir (each run's numbers and PresentMon's own file)." 'DarkGray' if (-not $quiet) { Start-Process $card } }