From db724e53aa2e457bee5dfc54d98de2e8c9440725 Mon Sep 17 00:00:00 2001 From: ShinniUwU Date: Thu, 26 Nov 2026 12:05:51 +0100 Subject: [PATCH] feat: opt-in test reports and a double-click start for testers --- README.md | 18 +++- measure-gta6.ps1 | 41 +++++++- scripts/check-tools.ps1 | 81 +++++++++++++++ scripts/test-report.ps1 | 221 ++++++++++++++++++++++++++++++++++++++++ start-measure.cmd | 17 ++++ 5 files changed, 376 insertions(+), 2 deletions(-) create mode 100644 scripts/check-tools.ps1 create mode 100644 scripts/test-report.ps1 create mode 100644 start-measure.cmd diff --git a/README.md b/README.md index ecc5c4292..3e7efb7ec 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,23 @@ powershell -ExecutionPolicy Bypass -File .\run-gta6.ps1 ``` `measure-gta6.ps1` does the same with the diagnostics build, the frame log and the card meter on, and saves -everything the game prints to `%LOCALAPPDATA%\leonida\logs`. +everything the game prints to `%LOCALAPPDATA%\leonida\logs`. `-SpeedSwitches off` runs it without the frame-rate +switches, for a comparison in the same place. + +### Testing for the project, with no programming experience + +1. Download this repository (Code, Download ZIP) and unpack it, or clone it. +2. Double-click `start-measure.cmd`. If the Visual Studio C++ build tools or Rust are missing, it offers to install + them with winget (about 3 GB, 5 to 15 minutes, asks first). The first build takes about 5 to 10 minutes. +3. Give it the folder of your copy of the game, answer its questions, and play until the place you want to test. +4. Close the game window. The script offers a short test report: your graphics card, driver, CPU, RAM, Windows + version, the switches that were on and the frame rates. It shows all of it before anything is shared, and never + includes log files, game files, paths or your user name. +5. If you agree, it copies the report and opens `#test-results` on our [Discord](https://discord.gg/dxMD2XqyEJ). + Paste it with Ctrl+V and send it. Nothing is uploaded unless you post it yourself. + +Run it once with the speed switches on and once with them off, in the same place: the pair is what lets us add a +profile for your card to `gpu-profiles.json`. Reports are kept in `%LOCALAPPDATA%\leonida\reports`. `shot-run.ps1` runs the game unattended and takes frame shots (`-ShotAt`, with `-Keys` to get through the menus) into `%LOCALAPPDATA%\leonida\shots`. Shots come from your game: keep them on your PC. diff --git a/measure-gta6.ps1 b/measure-gta6.ps1 index c4f39ebbf..3b659fd29 100644 --- a/measure-gta6.ps1 +++ b/measure-gta6.ps1 @@ -1,6 +1,8 @@ # Like run-gta6.ps1, but with the diagnostics build: frame log and card meter # (per pipeline) on, and everything the emulator prints saved to a log file. # Logs go under %LOCALAPPDATA%\leonida\logs (game-derived output stays out of the repo). +# When the game closes it offers a short test report (scripts\test-report.ps1): figures +# only, shown in full, and shared only if you say so. # # The first time, it asks for the folder of your copy of the game (the one with # MicrosoftGame.config in it) and offers to remember it in leonida.toml, which git ignores. @@ -8,12 +10,20 @@ # powershell -ExecutionPolicy Bypass -File .\measure-gta6.ps1 # powershell -ExecutionPolicy Bypass -File .\measure-gta6.ps1 -GameDir 'D:\Games\GTA VI' # this run only # powershell -ExecutionPolicy Bypass -File .\measure-gta6.ps1 -WarmUp yes # warm up the shader cache without asking +# powershell -ExecutionPolicy Bypass -File .\measure-gta6.ps1 -SpeedSwitches off # the same run without the switches +# powershell -ExecutionPolicy Bypass -File .\measure-gta6.ps1 -Report no # no report afterwards param( [string]$GameDir = '', # yes: warm up the shader cache before starting, no: skip it, ask: ask (default). [ValidateSet('ask', 'yes', 'no')] - [string]$WarmUp = 'ask' + [string]$WarmUp = 'ask', + # on: the switches gpu-profiles.json picks for this card (default), off: none, ask: ask. + [ValidateSet('on', 'off', 'ask')] + [string]$SpeedSwitches = 'on', + # ask: offer a test report when the game closes (default), no: don't. + [ValidateSet('ask', 'no')] + [string]$Report = 'ask' ) $ErrorActionPreference = 'Stop' @@ -61,6 +71,24 @@ try { . (Join-Path $PSScriptRoot 'scripts\leonida-settings.ps1') Set-LeonidaProfiles $PSScriptRoot + # Whatever LEONIDA_* is set now, besides paths and logging, is a speed switch. + $notSwitches = 'LEONIDA_CONFIG', 'LEONIDA_GAME_DIR', 'LEONIDA_CACHE_DIR', 'LEONIDA_DATA_DIR', 'LEONIDA_PROFILE', 'LEONIDA_LOG', 'LEONIDA_KEEP_WINDOW' + $switches = @(Get-ChildItem Env:LEONIDA_* | Where-Object { $_.Name -notin $notSwitches }) + if ($SpeedSwitches -eq 'ask') { + Write-Host '' + Write-Host 'Turn the speed switches on? They are the frame-rate switches measured faster for your card:' + Write-Host (($switches | ForEach-Object { $_.Name -replace '^LEONIDA_', '' }) -join ', ') + Write-Host 'To help compare, play once with them and once without, in the same place in the game.' + $answer = Read-Host 'Speed switches on? [Y/n]' + $SpeedSwitches = if ($answer.Trim() -match '^(y|yes)?$') { 'on' } else { 'off' } + } + if ($SpeedSwitches -eq 'off') { + $switches | ForEach-Object { Remove-Item -LiteralPath "Env:$($_.Name)" } + $switches = @() + Write-Host 'speed switches: off' + } + $switchList = @($switches | ForEach-Object { '{0}={1}' -f $_.Name, $_.Value }) + $env:LEONIDA_FRAME_LOG = '1' $env:LEONIDA_CARD_METER = '1' $env:LEONIDA_CARD_METER_PIPELINES = '1' @@ -89,7 +117,18 @@ try { # The emulator logs to stderr; PowerShell 5.1 wraps those lines as errors, so don't stop on them. $ErrorActionPreference = 'Continue' + $started = Get-Date & $exe run --execute 2>&1 | ForEach-Object { "$_" } | Tee-Object -FilePath $log + $exitCode = $LASTEXITCODE + + if ($Report -eq 'ask') { + try { + & (Join-Path $PSScriptRoot 'scripts\test-report.ps1') -Log $log -SpeedSwitches $switchList ` + -SwitchMode $SpeedSwitches -WarmUp $WarmUp -Started $started -ExitCode "$exitCode" -Exe $exe + } catch { + Write-Warning "the test report failed: $_" + } + } } finally { Pop-Location } diff --git a/scripts/check-tools.ps1 b/scripts/check-tools.ps1 new file mode 100644 index 000000000..9ec503442 --- /dev/null +++ b/scripts/check-tools.ps1 @@ -0,0 +1,81 @@ +# Checks for what building Leonida Legacy needs: the Visual Studio C++ build tools and +# Rust (rustup). Offers to install what is missing with winget, after asking. Run by +# start-measure.cmd; exits 1 when something is still missing. +# +# powershell -ExecutionPolicy Bypass -File .\scripts\check-tools.ps1 + +$ErrorActionPreference = 'Stop' +$root = Split-Path -Parent $PSScriptRoot + +function Test-BuildTools { + $vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe' + if (-not (Test-Path -LiteralPath $vswhere)) { return $false } + $path = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath + [bool]$path +} + +function Find-Rustup { + $cmd = Get-Command rustup -ErrorAction SilentlyContinue + if ($cmd) { return $cmd.Source } + # Installed in this session: the window's PATH doesn't have it yet. + $own = Join-Path $env:USERPROFILE '.cargo\bin\rustup.exe' + if (Test-Path -LiteralPath $own) { return $own } + $null +} + +function Install-WithWinget([string]$id, [string[]]$extra) { + & winget install --id $id --exact --accept-package-agreements --accept-source-agreements @extra + # winget returns a non-zero code when the package is already there; the checks after decide. +} + +$needTools = -not (Test-BuildTools) +$needRust = -not (Find-Rustup) +if (-not $needTools -and -not $needRust) { + Write-Host 'Build tools: found. Rust: found.' +} else { + Write-Host '' + Write-Host 'Building Leonida Legacy needs these, and this PC is missing:' + if ($needTools) { Write-Host ' - Visual Studio 2022 Build Tools with C++ (about 3 GB, 5 to 15 minutes; Windows asks for admin rights)' } + if ($needRust) { Write-Host ' - Rust, through rustup (about 300 MB, a few minutes)' } + $winget = Get-Command winget -ErrorAction SilentlyContinue + if (-not $winget) { + Write-Host '' + Write-Host 'winget is not on this PC, so they have to be installed by hand:' + if ($needTools) { Write-Host ' https://visualstudio.microsoft.com/visual-cpp-build-tools/ (pick "Desktop development with C++")' } + if ($needRust) { Write-Host ' https://rustup.rs/' } + Write-Host 'Then start this again.' + exit 1 + } + $answer = Read-Host 'Install them now with winget? [Y/n]' + if ($answer.Trim() -notmatch '^(y|yes)?$') { + Write-Host 'Nothing installed. Install them yourself and start this again.' + exit 1 + } + # The build tools first: rustup's installer looks for them. + if ($needTools) { + Install-WithWinget 'Microsoft.VisualStudio.2022.BuildTools' @( + '--override', '--wait --passive --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended') + if (-not (Test-BuildTools)) { + Write-Host 'The C++ build tools are still missing. Install them from' + Write-Host 'https://visualstudio.microsoft.com/visual-cpp-build-tools/ and start this again.' + exit 1 + } + } + if ($needRust) { + Install-WithWinget 'Rustlang.Rustup' @() + if (-not (Find-Rustup)) { + Write-Host 'Rust is still missing. Install it from https://rustup.rs/ and start this again.' + exit 1 + } + } +} + +# The Rust version rust-toolchain.toml pins; rustup installs it once and keeps it. +$rustup = Find-Rustup +Push-Location $root +try { + & $rustup toolchain install + if ($LASTEXITCODE -ne 0) { Write-Warning "rustup could not install the pinned Rust version (exit $LASTEXITCODE)" } +} finally { + Pop-Location +} diff --git a/scripts/test-report.ps1 b/scripts/test-report.ps1 new file mode 100644 index 000000000..4cd84462c --- /dev/null +++ b/scripts/test-report.ps1 @@ -0,0 +1,221 @@ +# After a measure-gta6.ps1 run: asks whether to make a short test report, shows all of it, +# and if the player agrees, copies it to the clipboard and opens the test-results channel +# of the project's Discord, where they post it themselves. Nothing is sent from here. +# The report holds figures only (the card, its driver, the CPU, frame rates), never the log +# itself: logs can quote game data (docs/asset-policy.md). Reports are kept in +# %LOCALAPPDATA%\leonida\reports. +# +# powershell -ExecutionPolicy Bypass -File .\scripts\test-report.ps1 -Log + +param( + [Parameter(Mandatory = $true)] + [string]$Log, + # The LEONIDA_* switches the run had on, as NAME=value. + [string[]]$SpeedSwitches = @(), + [ValidateSet('on', 'off')] + [string]$SwitchMode = 'on', + [string]$WarmUp = 'not asked', + # When the run started; a crashes.log written since then means it crashed. The log's own + # creation time when not given. + [datetime]$Started = [datetime]::MinValue, + [string]$ExitCode = '', + # leonida.exe, to find the data folder (crashes.log) with `leonida config`. + [string]$Exe = '' +) + +$ErrorActionPreference = 'Stop' +$root = Split-Path -Parent $PSScriptRoot +. (Join-Path $PSScriptRoot 'leonida-settings.ps1') + +$server = '1574773017114841229' +$channel = '1575267731857739916' +$invite = 'https://discord.gg/dxMD2XqyEJ' +$inv = [cultureinfo]::InvariantCulture + +function Format-Num([double]$v, [int]$digits) { $v.ToString("F$digits", $inv) } + +function Limit-Text([string]$s, [int]$n) { + if ($s.Length -gt $n) { $s.Substring(0, $n) + '...' } else { $s } +} + +# The driver of the card named $name, in the vendor's own numbering where it has one. +function Get-DriverVersion([string]$name) { + $class = 'HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}' + foreach ($key in @(Get-ChildItem -LiteralPath $class -ErrorAction SilentlyContinue)) { + if ($key.PSChildName -notmatch '^\d{4}$') { continue } + $p = Get-ItemProperty -LiteralPath $key.PSPath -ErrorAction SilentlyContinue + if (-not $p -or [string]$p.DriverDesc -ne $name) { continue } + $v = [string]$p.DriverVersion + # NVIDIA's number is the last five digits of the Windows one: 32.0.16.2124 is 621.24. + if ([string]$p.MatchingDeviceId -match 'ven_10de' -and $v -match '(\d)\.(\d{4})$') { + $d = $Matches[1] + $Matches[2] + return '{0}.{1} ({2})' -f $d.Substring(0, 3), $d.Substring(3), $v + } + if ($p.RadeonSoftwareVersion) { return 'Adrenalin {0} ({1})' -f $p.RadeonSoftwareVersion, $v } + return $v + } + 'unknown' +} + +function Get-LeonidaVersion { + try { + $commit = & git -C $root rev-parse --short HEAD 2>$null + if ($LASTEXITCODE -ne 0 -or -not $commit) { return 'unknown (not a git checkout)' } + $changed = & git -C $root status --porcelain --untracked-files=no 2>$null + if ($changed) { "$commit with local changes" } else { "$commit" } + } catch { + 'unknown (git not found)' + } +} + +# The frame log's "frame times" lines (crates/leonida-gpu/src/framelog.rs): the seconds each +# reading covers and every frame's length in ms. +function Read-FrameReadings([string]$path) { + $readings = @() + foreach ($line in [System.IO.File]::ReadLines($path)) { + $plain = $line -replace '\x1b\[[0-9;]*m', '' + if ($plain -match 'frame times: \d+ frames in ([\d.]+) s: .*; each: ([\d ]+?)\s*$') { + $readings += [pscustomobject]@{ + Seconds = [double]$Matches[1] + Frames = @($Matches[2] -split ' ' | Where-Object { $_ } | ForEach-Object { [double]$_ }) + } + } + } + $readings +} + +# The readings from the last one back until they cover $want seconds (all of them for 0). +function Get-FrameSummary($readings, [double]$want) { + $seconds = 0.0 + $frames = @() + for ($i = $readings.Count - 1; $i -ge 0; $i--) { + $seconds += $readings[$i].Seconds + $frames += $readings[$i].Frames + if ($want -gt 0 -and $seconds -ge $want) { break } + } + if ($frames.Count -eq 0 -or $seconds -le 0) { return $null } + $sorted = @($frames | Sort-Object) + [pscustomobject]@{ + Seconds = $seconds + Count = $frames.Count + Fps = $frames.Count / $seconds + MedianMs = $sorted[[int][math]::Floor(($sorted.Count - 1) / 2)] + LongestMs = $sorted[-1] + } +} + +function Format-Summary($s, [string]$what) { + '{0} FPS average over {1} ({2} frames in {3} s); median frame {4} ms, longest {5} ms' -f ` + (Format-Num $s.Fps 1), $what, $s.Count, (Format-Num $s.Seconds 1), (Format-Num $s.MedianMs 0), (Format-Num $s.LongestMs 0) +} + +# Whether a crash report was written since $since; only that, never what is in it. +function Test-CrashWritten([string]$exe, [datetime]$since) { + if (-not $exe -or -not (Test-Path -LiteralPath $exe)) { return 'unknown' } + # leonida.toml is read from the current folder. + Push-Location $root + try { $out = & $exe config } finally { Pop-Location } + $line = $out | Where-Object { $_ -match '^data_dir\s*:' } | Select-Object -First 1 + if ($line -notmatch '^data_dir\s*:\s*(.+?)\s*$') { return 'unknown' } + $dir = $Matches[1] + if (-not (Test-Path -LiteralPath $dir)) { return 'no' } + $new = @(Get-ChildItem -LiteralPath $dir -Filter 'crashes.log' -Recurse -File -ErrorAction SilentlyContinue | + Where-Object { $_.LastWriteTime -ge $since }) + if ($new.Count -gt 0) { 'yes' } else { 'no' } +} + +Write-Host '' +Write-Host '=== Test report ===' +Write-Host 'A short report from this run helps make Leonida Legacy better: it shows which speed' +Write-Host 'switches help on which graphics card (gpu-profiles.json) and where the game crashes.' +Write-Host '' +Write-Host 'It holds only:' +Write-Host ' - your graphics card, its memory and driver; your CPU, RAM and Windows version' +Write-Host ' - the Leonida Legacy version, the speed switches that were on, and the shader warm-up' +Write-Host ' - frame rates from this run, and whether a crash report was written' +Write-Host ' - what you type in next, if anything' +Write-Host 'It never holds your name, user name, folder paths, log files, game files or screenshots.' +Write-Host '' +Write-Host 'This script sends nothing. If you agree to share, it copies the report and opens the' +Write-Host '#test-results channel in Discord; you read it there and decide whether to post it.' +$answer = Read-Host 'Make a report? [Y/n]' +if ($answer.Trim() -notmatch '^(y|yes)?$') { + Write-Host 'No report made.' + return +} + +Write-Host '' +Write-Host 'Two optional questions (press Enter to skip). Do not paste log lines or file paths.' +$where = Limit-Text (Read-Host 'Where in the game were you at the end (for example: opening cutscene, first room)?').Trim() 300 +$issue = Limit-Text (Read-Host 'Anything wrong (crash, missing textures, flashing, sound)?').Trim() 600 + +if ($Started -eq [datetime]::MinValue) { $Started = (Get-Item -LiteralPath $Log).CreationTime } +$gpu = Get-LeonidaGpu +$cpu = ([string]@(Get-CimInstance Win32_Processor)[0].Name).Trim() +$ram = [math]::Round((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB) +$os = (Get-CimInstance Win32_OperatingSystem).Caption -replace '^Microsoft\s+', '' +$nt = Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' +$names = @($SpeedSwitches | Where-Object { $_ } | ForEach-Object { + $name, $value = $_ -split '=', 2 + $short = $name -replace '^LEONIDA_', '' + if ($value -eq '1') { $short } else { "$short=$value" } +}) +$switchText = $SwitchMode +if ($names.Count -gt 0) { $switchText += ': ' + ($names -join ', ') } + +$readings = @(Read-FrameReadings $Log) +$last = Get-FrameSummary $readings 60 +$all = Get-FrameSummary $readings 0 +$crashed = Test-CrashWritten $Exe $Started + +$lines = @( + '**Leonida Legacy test report**' + "GPU: $($gpu.Name), $($gpu.VramMB) MB" + "Driver: $(Get-DriverVersion $gpu.Name)" + "CPU: $cpu" + "RAM: $ram GB" + ('Windows: {0} {1}, build {2}.{3}' -f $os, $nt.DisplayVersion, $nt.CurrentBuild, $nt.UBR) + "Build: Leonida Legacy $(Get-LeonidaVersion)" + "Speed switches: $switchText" + "Shader warm-up: $WarmUp" +) +if ($where) { $lines += "Where: $where" } +if (-not $all) { + $lines += 'Performance: no frame times in the log (the game closed before its first frames?)' +} elseif ($all.Seconds -le $last.Seconds) { + $lines += 'Performance: ' + (Format-Summary $all 'the whole run') +} else { + $lines += 'Performance: ' + (Format-Summary $last 'the last minute before the game closed') + $lines += 'Whole run: ' + (Format-Summary $all 'the whole run, menus and loading included') +} +$end = "Crash report written: $crashed" +if ($ExitCode -ne '') { $end += " (exit code $ExitCode)" } +$lines += $end +$lines += 'Issue: ' + $(if ($issue) { $issue } else { 'none noticed' }) +$text = $lines -join "`r`n" + +$dir = Join-Path $env:LOCALAPPDATA 'leonida\reports' +New-Item -ItemType Directory -Force $dir | Out-Null +$file = Join-Path $dir ('report-{0:yyyyMMdd-HHmmss}.txt' -f (Get-Date)) +Set-Content -LiteralPath $file -Value $text -Encoding UTF8 + +Write-Host '' +Write-Host '----- the report, exactly as it would be shared -----' +Write-Host $text +Write-Host '-----------------------------------------------------' +Write-Host "Saved to $file" +$answer = Read-Host 'Copy it and open #test-results in Discord to post it? [Y/n]' +if ($answer.Trim() -notmatch '^(y|yes)?$') { + Write-Host 'Not shared. The report stays in the file above.' + return +} +Set-Clipboard -Value $text +$url = if (Test-Path -LiteralPath 'Registry::HKEY_CLASSES_ROOT\discord') { + "discord://-/channels/$server/$channel" +} else { + "https://discord.com/channels/$server/$channel" +} +Start-Process $url +Write-Host 'Copied. In Discord, click the message box in #test-results, press Ctrl+V, read it, then Enter.' +Write-Host "Not on the server yet? Join first: $invite" +Write-Host 'Attach no log files: they can quote game data.' diff --git a/start-measure.cmd b/start-measure.cmd new file mode 100644 index 000000000..32117c8c6 --- /dev/null +++ b/start-measure.cmd @@ -0,0 +1,17 @@ +@echo off +rem Double-click start for testers: checks for the build tools and Rust (offers to install +rem them), then runs measure-gta6.ps1, which asks whether the speed switches go on and offers +rem a test report when the game closes. Arguments are passed on to measure-gta6.ps1. +setlocal +cd /d "%~dp0" +rem rustup installed by check-tools.ps1 is not on this window's PATH yet. +set "PATH=%USERPROFILE%\.cargo\bin;%PATH%" +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\check-tools.ps1" +if errorlevel 1 ( + echo. + pause + exit /b 1 +) +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0measure-gta6.ps1" -SpeedSwitches ask %* +echo. +pause