Record the 1.0 release benchmark on the reference laptop (#32)
Measured 995f454 (1.0.0-beta.5) on the Ryzen 5 7640U, release build and
its profile build. Budgets 1, 2, 4 and the minimised CPU of budget 3 are
over; budget 5 and the no-rendering part of budget 3 hold. Idle CPU has
a floor set by GPUI's vsync thread, recorded without changing the limit.
The scenarios are written down under Measuring, with
scripts/budget-probe.ps1 to repeat them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0192He3E5kSZykyLnuoXsBC2
This commit is contained in:
1 parent
995f454a9c
commit
2b40dcf2d3
3 files changed
+319
-11
No files matched your search
@@ -68,9 +68,9 @@ $h = [IO.File]::Open("$env:LOCALAPPDATA\ArenaTracker\current\verrou.tmp", 'Creat
|
|||||||
|
|
||||||
La 1.0 est une version majeure : son feu vert dépend du benchmark complet de #32, à l’étape 1 de [Publier une stable](publication.md#publier-une-stable). Les chiffres et leur date sont dans le [tableau des budgets](performance.md#budgets).
|
La 1.0 est une version majeure : son feu vert dépend du benchmark complet de #32, à l’étape 1 de [Publier une stable](publication.md#publier-une-stable). Les chiffres et leur date sont dans le [tableau des budgets](performance.md#budgets).
|
||||||
|
|
||||||
| Commit mesuré | Date |
|
| Commit mesuré | Date | Résultat |
|
||||||
| --- | --- |
|
| --- | --- | --- |
|
||||||
| | |
|
| `995f454` (1.0.0-beta.5) | 2026-11-23 | budgets 1, 2, 3 (fenêtre minimisée) et 4 dépassés : pas de feu vert |
|
||||||
|
|
||||||
## Publication publique
|
## Publication publique
|
||||||
|
|
||||||
|
|||||||
+29
-8
@@ -10,13 +10,22 @@ Measured on the **reference machine**, on a **release build** (`scripts/prod run
|
|||||||
|
|
||||||
| # | Budget | Limit | Current value | Status |
|
| # | Budget | Limit | Current value | Status |
|
||||||
| --- | --- | --- | --- | --- |
|
| --- | --- | --- | --- | --- |
|
||||||
| 1 | Interactions (hover, scroll, sort, filter, moving or resizing the window): cost of one frame | at most **2 ms** at the 99th percentile, aiming for 1 ms | 5–7 ms for a full frame of the statistics page; a window move redraws one, 5–8 ms per move at the 95th percentile (before #31) | over budget; to re-measure since #31 |
|
| 1 | Interactions (hover, scroll, sort, filter, moving or resizing the window): cost of one frame | at most **2 ms** at the 99th percentile, aiming for 1 ms | every interaction draws a full frame: 4.0–4.2 ms at the median, 5.7–6.0 ms at the 99th percentile, plus 0.4 ms of presentation (profile build); a window move holds the UI thread 3.7–3.9 ms at the 95th percentile, 4.5–4.7 ms at the 99th (release) | over budget |
|
||||||
| 2 | Idle, window visible: CPU | at most **0.5 %** of one core on average | 0.3–1.4 % (about 0.8 %) | over budget |
|
| 2 | Idle, window visible: CPU | at most **0.5 %** of one core on average | 0.68–1.11 % (0.89 % over six phases of 30 s), no frame drawn; floor set by GPUI's vsync thread, see below | over budget |
|
||||||
| 3 | Window minimised or hidden | **no rendering**, CPU close to 0, outside an import | not measured | unknown |
|
| 3 | Window minimised or hidden | **no rendering**, CPU close to 0, outside an import | no frame drawn either way; hidden in the notification area 0.24–0.29 %, minimised 1.2–1.7 % | rendering within budget; CPU over budget when minimised |
|
||||||
| 4 | Memory, with the full page loaded (every champion and portrait) | at most **150 MB** working set | 120 MB working set, 99 MB private | within budget |
|
| 4 | Memory, with the full page loaded (every champion and portrait) | at most **150 MB** working set | 164–169 MB working set, 148 MB private from a fresh start; 179 MB and 156 MB after a long session | over budget |
|
||||||
| 5 | Background work (import, following the game client) | threads at **low priority**, never more than **one core** | not measured | unknown |
|
| 5 | Background work (import, following the game client) | threads at **low priority**, never more than **one core** | import of 466 Matches with the client open: at most 12 % of one core in a sample, the work on below-normal threads (1.5 s of CPU, against 0.1 s on normal-priority threads) | within budget |
|
||||||
|
|
||||||
Current values measured on 2026-11-16 and 2026-11-17 (issue #17). For information, #31 made a full frame about a third cheaper on the manual checks machine (drawing it: 2.37 → 1.57 ms at the median, 3.72 → 2.50 ms at the 99th percentile, plus 0.22 ms of presentation); its value here is still to measure.
|
Values of the 1.0 release benchmark: 2026-11-23, reference machine, release build of `995f454` (1.0.0-beta.5) and its `--features profile` build for the frame breakdown, scenarios and details below. No limit was beaten, so none is lowered. The previous values (2026-11-16 and 2026-11-17, issue #17) were 5–7 ms per full frame, 0.3–1.4 % idle and 120 MB working set, before the identity (#80) added the banner, its splash and the portrait cards.
|
||||||
|
|
||||||
|
### Release benchmark 1.0 (2026-11-23)
|
||||||
|
|
||||||
|
- **Budget 1.** Nothing a frame is asked for is cheap: each window move, hovered row or wheel step draws the whole window, at 60 frames per second (`request_layout` 0.7–1.0 ms, `prepaint` 1.6–2.2 ms, `paint` 0.7–1.3 ms at the median). On « Défi » the card grid's own prepaint takes 1.6–1.8 ms per frame, whether the window moves or the grid scrolls; on « Statistiques » the table's prepaint takes 0.8–1.0 ms and the charts' cached paint 0.3–0.4 ms; the page's layout 0.6 ms when it renders again; the rest is GPUI's own work, in pieces under the 0.5 ms the profile records. Hovering the table costs as much as moving the window: 31 % of one core at 240 moves per second, input waiting up to 5.2 ms at the 99th percentile. Scrolling the home grid draws a frame per wheel step at 4.0 ms median and 5.8–6.0 ms at the 99th percentile.
|
||||||
|
- **Budget 2.** The cause of each wake-up, window visible and nothing drawn: GPUI's `VSyncProvider` thread (`gpui-pre-windows`, `platform.rs`) waits on `DwmFlush` at each vsync (61 wakes per second, about 0.3 % of one core) and invalidates every window with `RedrawWindow`; the UI thread then takes a `WM_PAINT` at each vsync (67 wakes per second, 0.4–0.7 %), runs GPUI's frame callback, finds nothing to draw and draws nothing. The app's own threads wake about once per second (under 0.05 %). This floor, 0.7–1.1 %, cannot be lowered without modifying GPUI (ADR-0004): it is recorded here, and the limit stays until the user decides.
|
||||||
|
- **Budget 3.** Hidden in the notification area, the UI thread never wakes; GPUI's vsync thread alone still does, 61 times per second (0.24–0.29 %). Minimised, the vsync thread keeps invalidating the window (it only skips the frame signal for an iconic window) and the UI thread wakes about 89 times per second without drawing: 1.2–1.7 %, more than visible.
|
||||||
|
- **Budget 4.** With the full page loaded, the process commits about 108 MB of GPU memory, held in system memory on this integrated GPU (86–94 MB shared). Hiding parts with the profile build (`ARENA_TRACKER_HIDE`) splits the private memory: about 40 MB for the home grid's portraits, about 25 MB for the champion table, and 106 MB with both hidden, mostly GPUI's renderer (swap chain, atlases). The working set keeps 177 MB while the window is hidden.
|
||||||
|
- **Budget 5.** Following the client (open throughout) and importing a whole history into an empty data folder, with its 175 card portraits and splashes: the work ran on the two follower threads and the art download thread, all below normal. Threads at normal priority showed at most 1.1 % in a sample; threads born and gone between two samples (up to 5 % in a sample, priority unknown) match the short DNS thread `ureq` starts per request, which `worker.rs` already notes runs at normal priority.
|
||||||
|
- **Not measured: scrolling a champ select.** It needs a live Arena champ select in the game client; the captured one replays only in GPUI's test context, which draws nothing. Scrolling the home grid, which shares its cost structure, is the nearest value: 4.0 ms per frame at the median, 6.0 ms at the 99th percentile. To measure at the next champ select (see Measuring).
|
||||||
|
|
||||||
### Ratchet
|
### Ratchet
|
||||||
|
|
||||||
@@ -33,14 +42,26 @@ A measurement means something only with its machine and build: the probes print
|
|||||||
|
|
||||||
Budgets are checked by a **full benchmark before each major release** (X.0.0; other stables and betas run no probes): every probe below, on a release build, on the reference machine, with the results recorded in the budgets table above. Single changes are not measured, unless the user asks; a release that fails a budget is fixed before it ships, and the probes below (with `--features profile`) find the cause.
|
Budgets are checked by a **full benchmark before each major release** (X.0.0; other stables and betas run no probes): every probe below, on a release build, on the reference machine, with the results recorded in the budgets table above. Single changes are not measured, unless the user asks; a release that fails a budget is fixed before it ships, and the probes below (with `--features profile`) find the cause.
|
||||||
|
|
||||||
- **Window moves and idle CPU**: `powershell.exe -ExecutionPolicy Bypass -File scripts/move-probe.ps1 -Title "Arena Tracker"` from WSL, with the app open. It moves the window 240 times per second without touching the mouse, after an idle phase. `MOVE block` is the time each move holds the UI thread, close to the cost of the frame it causes; `IDLE cpu` is budget 2. Compare with File Explorer with `-Class CabinetWClass`. A real title-bar drag (Windows' modal move loop) is not covered: check it by hand.
|
- **Window moves and idle CPU**: `powershell.exe -ExecutionPolicy Bypass -File scripts/move-probe.ps1 -Title "Arena Tracker"` from WSL, with the app open. It moves the window 240 times per second without touching the mouse, after an idle phase. `MOVE block` is the time each move holds the UI thread, close to the cost of the frame it causes; `IDLE cpu` reads higher than budget 2, as the probe's own pings wake the UI thread: budget 2 is measured by `scripts/budget-probe.ps1` (Release benchmark scenarios, below). Compare with File Explorer with `-Class CabinetWClass`. A real title-bar drag (Windows' modal move loop) is not covered: check it by hand.
|
||||||
- **Champion table hover**: `powershell.exe -ExecutionPolicy Bypass -File scripts/hover-probe.ps1 -Title "Arena Tracker"` from WSL, with the « Statistiques » tab showing the table under the default band (adjust `-Top` and `-Bottom` otherwise). The app opens on « Défi »: open « Statistiques » first, as the band targets its table. After an idle phase, it posts synthetic mouse moves across table rows 240 times per second without touching the real cursor. Compare `HOVER cpu` with `IDLE cpu`; `HOVER ping` shows how long input waits behind the UI thread while hovering (budget 1). The default band is `-X 0.25 -Top 0.62 -Bottom 0.95 -Step 0.04` (fractions of the client area, about one row per move in a window at least 800 px tall). Leave the real cursor still over the window, outside the table: when it is outside the window, GPUI sees each synthetic move as the mouse entering then leaving, and refreshes the whole window, bypassing cached views.
|
- **Champion table hover**: `powershell.exe -ExecutionPolicy Bypass -File scripts/hover-probe.ps1 -Title "Arena Tracker"` from WSL, with the « Statistiques » tab showing the table under the default band (adjust `-Top` and `-Bottom` otherwise). The app opens on « Défi »: open « Statistiques » first, as the band targets its table. After an idle phase, it posts synthetic mouse moves across table rows 240 times per second without touching the real cursor. Compare `HOVER cpu` with `IDLE cpu`; `HOVER ping` shows how long input waits behind the UI thread while hovering (budget 1). The default band is `-X 0.25 -Top 0.62 -Bottom 0.95 -Step 0.04` (fractions of the client area, about one row per move in a window at least 800 px tall). Leave the real cursor still over the window, outside the table: when it is outside the window, GPUI sees each synthetic move as the mouse entering then leaving, and refreshes the whole window, bypassing cached views.
|
||||||
- **Where a frame goes**: build with `scripts/prod build --features profile` (never for everyday use) and start the app with `ARENA_TRACKER_PROFILE=<file.csv>` (from WSL, pass it through `WSLENV`, e.g. `WSLENV=ARENA_TRACKER_PROFILE/p:ARENA_TRACKER_HIDE`). Every second it appends the frames GPUI drew (`draw`: total, `request_layout`, `prepaint`, `paint` in ms), their presentation (`present`) and the views' own time (`view`, recorded by GPUI from 0.5 ms). `ARENA_TRACKER_HIDE=<parts>`, read at start, removes parts of the page so that a part's cost is the difference with the full page under the hover probe: `header`, `banners` (both tabs), then for « Statistiques » `statistics-title` (the page title), `tiles`, `placements`, `completed`, `attempts` (the three charts keep their height), `tabs`, `table`, and for « Défi » `banner` (the banner, on the home and during a champ select: ring, Season, counter-title, its two lines and the splash; it replaces `home-header`, and is not `banners`, the status messages), `home-tools` (the heading row: title, count, filters and search), `cards` (the card grid), and during an Arena champ select `anvil` (the Anvil champions heading and row, which take the place of `home-tools` and `cards`), then `others` (the « Autres champions » section: its header and, when open, its search and grid).
|
- **Where a frame goes**: build with `scripts/prod build --features profile` (never for everyday use) and start the app with `ARENA_TRACKER_PROFILE=<file.csv>` (from WSL, pass it through `WSLENV`, e.g. `WSLENV=ARENA_TRACKER_PROFILE/p:ARENA_TRACKER_HIDE`). Every second it appends the frames GPUI drew (`draw`: total, `request_layout`, `prepaint`, `paint` in ms), their presentation (`present`) and the views' own time (`view`, recorded by GPUI from 0.5 ms). `ARENA_TRACKER_HIDE=<parts>`, read at start, removes parts of the page so that a part's cost is the difference with the full page under the hover probe: `header`, `banners` (both tabs), then for « Statistiques » `statistics-title` (the page title), `tiles`, `placements`, `completed`, `attempts` (the three charts keep their height), `tabs`, `table`, and for « Défi » `banner` (the banner, on the home and during a champ select: ring, Season, counter-title, its two lines and the splash; it replaces `home-header`, and is not `banners`, the status messages), `home-tools` (the heading row: title, count, filters and search), `cards` (the card grid), and during an Arena champ select `anvil` (the Anvil champions heading and row, which take the place of `home-tools` and `cards`), then `others` (the « Autres champions » section: its header and, when open, its search and grid).
|
||||||
- **Memory**: working set of `arena-tracker.exe` in Task Manager, or `Get-Process arena-tracker` in PowerShell, once the page is fully loaded.
|
- **Memory**: working set of `arena-tracker.exe` in Task Manager, or `Get-Process arena-tracker` in PowerShell, once the page is fully loaded; for budget 4, the memory scenario below.
|
||||||
- **CI cannot check budgets**: its runner is Linux without a GPU, and the app only builds on Windows (ADR-0003). When a change relies on cached views to stay within budget, a structural test (for example, "hovering the table does not render the charts") guards it instead of a timed test. The charts row is a cached view (#31), and « Défi » never renders it (a structural test guards that too). The home's card grid is the second (#72) and the « Autres champions » grid, while the section is open, the third: their size comes from their style, and structural tests check that hovering outside it does not render its cards and that hovering or scrolling it recomputes no statistics. The champ select scrolls as one page: the « Autres champions » grid is as tall as all its rows and holds no scrolling of its own, it builds only the rows the page's scrolling has in view (read at its own render, after the page's scrolling is held within its content), and a structural test checks that a scroll to the end builds at most a few rows of cards. A grid wholly below the window keeps its first row built, for the keyboard to enter by (the page then scrolls to the card focused). Scrolling is no longer free of the page, though: a cached view is reused only while its bounds stay the same, and a scroll moves them, so each wheel step renders the page and draws again the ring, the Anvil hand and the « Autres champions » grid (as it already did in a window too short for the column); the scrollbar is its own view, so its fade draws no more than itself. The release benchmark must measure scrolling a champ select, and ratchet or fix the cost it finds. Each card grid reads its portraits through its own image cache, never GPUI's app-wide one, and keeps only those of the cards it paints (#77): structural tests check that scrolling drops the others, from the GPU atlas too, and that hovering outside the grid drops none; a grid that stops being shown (the home grid under « Statistiques » or during a champ select, the Anvil champions row once it ends) gives all its portraits back. The banner's ring is the fourth (#84), as wide as the window width gives: structural tests check that hovering or scrolling the grid draws it again only for the tick that lights up or goes out, that drawing it alone neither draws the grid nor builds a card, and that its fixed shapes are tessellated once per set of ticks and size, a hover tessellating only the lit tick and a scroll that moves it none. The banner decodes its splash itself, never through GPUI's app-wide cache, one at a time on GPUI's low-priority queue at below-normal thread priority: structural tests check that it holds two at most (the one shown and the one decoding; a splash asked for meanwhile waits), gives back the one replaced, from the GPU atlas too, and holds none under « Statistiques », behind « Paramètres » (with the grids' portraits), scrolled out of view in a low window, or without an illustration. A cached view is laid out from its style alone, never its content, so only a part whose size does not depend on its content can be one. A view that is not cached renders again with its parent and saves nothing, while its state must be kept in sync; a window move bypasses every cache.
|
- **CI cannot check budgets**: its runner is Linux without a GPU, and the app only builds on Windows (ADR-0003). When a change relies on cached views to stay within budget, a structural test (for example, "hovering the table does not render the charts") guards it instead of a timed test. The charts row is a cached view (#31), and « Défi » never renders it (a structural test guards that too). The home's card grid is the second (#72) and the « Autres champions » grid, while the section is open, the third: their size comes from their style, and structural tests check that hovering outside it does not render its cards and that hovering or scrolling it recomputes no statistics. The champ select scrolls as one page: the « Autres champions » grid is as tall as all its rows and holds no scrolling of its own, it builds only the rows the page's scrolling has in view (read at its own render, after the page's scrolling is held within its content), and a structural test checks that a scroll to the end builds at most a few rows of cards. A grid wholly below the window keeps its first row built, for the keyboard to enter by (the page then scrolls to the card focused). Scrolling is no longer free of the page, though: a cached view is reused only while its bounds stay the same, and a scroll moves them, so each wheel step renders the page and draws again the ring, the Anvil hand and the « Autres champions » grid (as it already did in a window too short for the column); the scrollbar is its own view, so its fade draws no more than itself. The release benchmark must measure scrolling a champ select, and ratchet or fix the cost it finds. Each card grid reads its portraits through its own image cache, never GPUI's app-wide one, and keeps only those of the cards it paints (#77): structural tests check that scrolling drops the others, from the GPU atlas too, and that hovering outside the grid drops none; a grid that stops being shown (the home grid under « Statistiques » or during a champ select, the Anvil champions row once it ends) gives all its portraits back. The banner's ring is the fourth (#84), as wide as the window width gives: structural tests check that hovering or scrolling the grid draws it again only for the tick that lights up or goes out, that drawing it alone neither draws the grid nor builds a card, and that its fixed shapes are tessellated once per set of ticks and size, a hover tessellating only the lit tick and a scroll that moves it none. The banner decodes its splash itself, never through GPUI's app-wide cache, one at a time on GPUI's low-priority queue at below-normal thread priority: structural tests check that it holds two at most (the one shown and the one decoding; a splash asked for meanwhile waits), gives back the one replaced, from the GPU atlas too, and holds none under « Statistiques », behind « Paramètres » (with the grids' portraits), scrolled out of view in a low window, or without an illustration. A cached view is laid out from its style alone, never its content, so only a part whose size does not depend on its content can be one. A view that is not cached renders again with its parent and saves nothing, while its state must be kept in sync; a window move bypasses every cache.
|
||||||
|
|
||||||
GPUI and gpui-component are not modified to meet a budget: the app's own rendering cost is the lever (ADR-0004).
|
GPUI and gpui-component are not modified to meet a budget: the app's own rendering cost is the lever (ADR-0004).
|
||||||
|
|
||||||
|
### Release benchmark scenarios
|
||||||
|
|
||||||
|
The release benchmark runs these scenarios, in this order, on the reference machine (#32). Builds come from `scripts/prod build`, then `scripts/prod build --features profile`; each `arena-tracker.exe` is copied out of the target directory before the next build overwrites it, and started from that copy. `scripts/budget-probe.ps1` (from WSL: `powershell.exe -ExecutionPolicy Bypass -File scripts/budget-probe.ps1 <action>`) reads the app's own counters (process CPU time, each thread's CPU time and context switches, process GPU time and memory), never system-wide ones, and drives the window with posted messages.
|
||||||
|
|
||||||
|
- **Conditions.** Each probe prints the machine and the build first: check the CPU is the Ryzen 5 7640U and the build is the copy meant. The laptop is on mains power, the user is away (`info` prints the time since their last input) and no game runs; stop and wait otherwise. The data folder (`%APPDATA%\arena-tracker`) holds a Riot key, the imported Matches and the portraits: an empty page measures nothing. Each phase lasts under a minute; split a longer scenario into phases.
|
||||||
|
- **Idle, window visible (budget 2).** Start the release build, wait 30 s, `front`, then `cursor -X 0.5 -Y 0.012` (the real cursor still over the title). Run `sample -Seconds 30` twice on « Défi » and once on « Statistiques » (`click -X 0.095 -Y 0.068`; « Défi » is at `-X 0.03`). The budget is the process CPU; the table names each thread waking. The `IDLE cpu` line of the move and hover probes is not this budget: their ping thread wakes the UI thread hundreds of times per second.
|
||||||
|
- **Interactions (budget 1).** On « Défi »: the move probe with `-Seconds 20`, then `wheel -X 0.5 -Y 0.75 -Count 300` (300 steps down at 20 per second) and the same with `-Delta 120` back up. On « Statistiques »: the hover probe and the move probe, `-Seconds 20` each. Then again on the profile build, started with `ARENA_TRACKER_PROFILE`, noting the CSV's line count at each phase's start and end to cut it into phases.
|
||||||
|
- **Minimised and hidden (budget 3).** `minimize`, wait 3 s, `sample -Seconds 30` twice; `restore`, then `close` (the window goes to the notification area, as `close_to_tray` is on), wait 3 s, `sample -Seconds 30`. Starting the app again shows the window again. On the profile build, the CSV shows no frame drawn during these phases.
|
||||||
|
- **Memory, full page loaded (budget 4).** From a fresh start, wait 15 s, `front`; scroll the home grid to its end (`wheel -X 0.5 -Y 0.75 -Count 150`), open « Statistiques » and scroll the table to its end (`wheel -X 0.5 -Y 0.85 -Count 120`), wait 10 s, then `memory`. Run it twice. To split the memory, the profile build runs the same scenario with `ARENA_TRACKER_HIDE` set to `cards`, `banner`, then `table,cards`.
|
||||||
|
- **Background work (budget 5).** Stop the app, copy `config.toml` and `seasons.toml` to an empty `<folder>\arena-tracker`, and start the release build with `APPDATA=<folder>` while the game client runs and is signed in: the app imports the whole history and downloads the portraits and splashes. Run `trace -Seconds 50` from the start, then again until the page shows the Matches imported. A sample's process CPU must stay under 100 % (one core), and the CPU must go to the `low` column. Delete the folder afterwards: it holds a copy of the Riot key.
|
||||||
|
- **Scrolling a champ select.** During a live Arena champ select, with « Autres champions » open: the profile build, then `wheel -X 0.5 -Y 0.75 -Count 100` down and the same back up, 20 steps per second, in two phases. The frames per wheel step and their cost are the figures, as for the home grid.
|
||||||
|
|
||||||
### Animations and splashes
|
### Animations and splashes
|
||||||
|
|
||||||
The identity (ring, banner, animations; `docs/interface.md`) follows the same rule:
|
The identity (ring, banner, animations; `docs/interface.md`) follows the same rule:
|
||||||
|
|||||||
@@ -0,0 +1,287 @@
|
|||||||
|
# Release benchmark helper for budgets 2 to 5 (issue #32, rule #1 in docs/performance.md): the
|
||||||
|
# app's own metrics only (process CPU time, per-thread CPU time and context switches, process GPU
|
||||||
|
# engine time and memory), never system-wide ones. Window lookups happen in C#: PowerShell would
|
||||||
|
# pass $null strings as "".
|
||||||
|
#
|
||||||
|
# Usage, from WSL at the repository root, with the app open (scenarios in docs/performance.md):
|
||||||
|
# powershell.exe -ExecutionPolicy Bypass -File scripts/budget-probe.ps1 info
|
||||||
|
# ... sample -Seconds 30 -Label idle CPU, GPU and memory over one phase; each thread's CPU and wakes
|
||||||
|
# ... trace -Seconds 50 -Label import one line per sample: CPU by kind of thread and priority
|
||||||
|
# ... memory working set, private bytes and GPU memory of the process
|
||||||
|
# ... front | minimize | restore | close (close hides to the notification area)
|
||||||
|
# ... click -X 0.1 -Y 0.07 posted click at fractions of the client area
|
||||||
|
# ... wheel -X 0.5 -Y 0.75 -Delta -120 -Count 150 -Rate 20
|
||||||
|
# ... cursor -X 0.5 -Y 0.012 puts the real cursor still over the window (the title)
|
||||||
|
# ... shot -Out C:\path\shot.png capture of the window's rectangle on screen
|
||||||
|
# Every phase lasts -Seconds of wall time: keep it under a minute and split longer scenarios.
|
||||||
|
param(
|
||||||
|
[Parameter(Position = 0)][string]$Action = 'info',
|
||||||
|
[double]$Seconds = 30,
|
||||||
|
[string]$Label = '',
|
||||||
|
[double]$X = 0.5,
|
||||||
|
[double]$Y = 0.5,
|
||||||
|
[int]$Delta = -120,
|
||||||
|
[int]$Count = 1,
|
||||||
|
[double]$Rate = 20,
|
||||||
|
[string]$Out = ''
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
# The output is usually read from WSL, which expects UTF-8 (the file itself has a BOM for the
|
||||||
|
# same reason: Windows PowerShell 5.1 reads scripts without one as ANSI).
|
||||||
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
|
|
||||||
|
Add-Type -ReferencedAssemblies System.Drawing -Language CSharp -TypeDefinition @'
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
public static class BudgetProbe {
|
||||||
|
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left, Top, Right, Bottom; }
|
||||||
|
[StructLayout(LayoutKind.Sequential)] public struct POINT { public int X, Y; }
|
||||||
|
[StructLayout(LayoutKind.Sequential)] struct LASTINPUTINFO { public uint cbSize; public uint dwTime; }
|
||||||
|
delegate bool EnumProc(IntPtr h, IntPtr l);
|
||||||
|
[DllImport("user32.dll")] static extern bool EnumWindows(EnumProc cb, IntPtr l);
|
||||||
|
[DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
|
||||||
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern IntPtr GetPropW(IntPtr h, string name);
|
||||||
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern int GetWindowTextW(IntPtr h, StringBuilder s, int n);
|
||||||
|
[DllImport("user32.dll")] static extern bool IsWindowVisible(IntPtr h);
|
||||||
|
[DllImport("user32.dll")] static extern bool IsIconic(IntPtr h);
|
||||||
|
[DllImport("user32.dll")] static extern bool ShowWindow(IntPtr h, int cmd);
|
||||||
|
[DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr h);
|
||||||
|
[DllImport("user32.dll")] static extern bool GetClientRect(IntPtr h, out RECT r);
|
||||||
|
[DllImport("user32.dll")] static extern bool GetWindowRect(IntPtr h, out RECT r);
|
||||||
|
[DllImport("user32.dll")] static extern bool ClientToScreen(IntPtr h, ref POINT p);
|
||||||
|
[DllImport("user32.dll")] static extern bool PostMessageW(IntPtr h, uint m, IntPtr w, IntPtr l);
|
||||||
|
[DllImport("user32.dll")] static extern bool SetCursorPos(int x, int y);
|
||||||
|
[DllImport("user32.dll")] static extern bool GetLastInputInfo(ref LASTINPUTINFO info);
|
||||||
|
[DllImport("user32.dll")] public static extern bool SetProcessDPIAware();
|
||||||
|
|
||||||
|
// Seconds since the user last touched the keyboard or mouse: measuring waits while they use
|
||||||
|
// the machine.
|
||||||
|
public static double UserIdleSeconds() {
|
||||||
|
var info = new LASTINPUTINFO(); info.cbSize = 8; GetLastInputInfo(ref info);
|
||||||
|
return (Environment.TickCount - (int)info.dwTime) / 1000.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The app's main window, shown or hidden: the window of an arena-tracker process carrying the
|
||||||
|
// single-instance marker, else the one titled "Arena Tracker".
|
||||||
|
public static IntPtr Find() {
|
||||||
|
var pids = new HashSet<uint>();
|
||||||
|
foreach (var p in Process.GetProcessesByName("arena-tracker")) pids.Add((uint)p.Id);
|
||||||
|
IntPtr marked = IntPtr.Zero, titled = IntPtr.Zero;
|
||||||
|
EnumWindows((h, l) => {
|
||||||
|
uint pid; GetWindowThreadProcessId(h, out pid);
|
||||||
|
if (!pids.Contains(pid)) return true;
|
||||||
|
if (GetPropW(h, "nessar.arena-tracker.main-window") != IntPtr.Zero) { marked = h; return false; }
|
||||||
|
var title = new StringBuilder(256); GetWindowTextW(h, title, 256);
|
||||||
|
if (title.ToString() == "Arena Tracker" && titled == IntPtr.Zero) titled = h;
|
||||||
|
return true;
|
||||||
|
}, IntPtr.Zero);
|
||||||
|
return marked != IntPtr.Zero ? marked : titled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IntPtr Need() {
|
||||||
|
var h = Find();
|
||||||
|
if (h == IntPtr.Zero) throw new Exception("Erreur : aucune fenêtre Arena Tracker.");
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static uint Pid(IntPtr h) { uint pid; GetWindowThreadProcessId(h, out pid); return pid; }
|
||||||
|
public static uint UiThread(IntPtr h) { uint pid; return GetWindowThreadProcessId(h, out pid); }
|
||||||
|
|
||||||
|
public static string State(IntPtr h) {
|
||||||
|
RECT r; GetClientRect(h, out r);
|
||||||
|
return String.Format("pid {0}, UI thread {1}, visible {2}, minimised {3}, client {4}x{5}",
|
||||||
|
Pid(h), UiThread(h), IsWindowVisible(h), IsIconic(h), r.Right, r.Bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Show(IntPtr h, int cmd) { ShowWindow(h, cmd); }
|
||||||
|
public static void Front(IntPtr h) { ShowWindow(h, 9 /* SW_RESTORE */); SetForegroundWindow(h); }
|
||||||
|
public static void Close(IntPtr h) { PostMessageW(h, 0x0010 /* WM_CLOSE */, IntPtr.Zero, IntPtr.Zero); }
|
||||||
|
|
||||||
|
static POINT ClientPoint(IntPtr h, double fx, double fy) {
|
||||||
|
RECT r; GetClientRect(h, out r);
|
||||||
|
var p = new POINT(); p.X = (int)(r.Right * fx); p.Y = (int)(r.Bottom * fy);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntPtr LParam(int x, int y) { return new IntPtr((x & 0xffff) | ((y & 0xffff) << 16)); }
|
||||||
|
|
||||||
|
public static void Click(IntPtr h, double fx, double fy) {
|
||||||
|
var p = ClientPoint(h, fx, fy);
|
||||||
|
PostMessageW(h, 0x0200 /* WM_MOUSEMOVE */, IntPtr.Zero, LParam(p.X, p.Y));
|
||||||
|
Thread.Sleep(30);
|
||||||
|
PostMessageW(h, 0x0201 /* WM_LBUTTONDOWN */, new IntPtr(1), LParam(p.X, p.Y));
|
||||||
|
Thread.Sleep(30);
|
||||||
|
PostMessageW(h, 0x0202 /* WM_LBUTTONUP */, IntPtr.Zero, LParam(p.X, p.Y));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Cursor(IntPtr h, double fx, double fy) {
|
||||||
|
var p = ClientPoint(h, fx, fy); ClientToScreen(h, ref p); SetCursorPos(p.X, p.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// WM_MOUSEWHEEL carries screen coordinates.
|
||||||
|
public static void Wheel(IntPtr h, double fx, double fy, int delta, int count, double rate) {
|
||||||
|
var p = ClientPoint(h, fx, fy); ClientToScreen(h, ref p);
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
PostMessageW(h, 0x020A, new IntPtr((delta & 0xffff) << 16), LParam(p.X, p.Y));
|
||||||
|
Thread.Sleep((int)(1000 / rate));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Shot(IntPtr h, string path) {
|
||||||
|
RECT r; GetWindowRect(h, out r);
|
||||||
|
using (var bitmap = new Bitmap(r.Right - r.Left, r.Bottom - r.Top)) {
|
||||||
|
using (var g = Graphics.FromImage(bitmap)) g.CopyFromScreen(r.Left, r.Top, 0, 0, bitmap.Size);
|
||||||
|
bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Png);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'@
|
||||||
|
[BudgetProbe]::SetProcessDPIAware() | Out-Null
|
||||||
|
|
||||||
|
# Raw counters of the process: CPU time, each thread's CPU time (100 ns units), context switches
|
||||||
|
# and priorities, GPU engine running time and memory.
|
||||||
|
function Snapshot($procId) {
|
||||||
|
$p = Get-Process -Id $procId
|
||||||
|
$threads = @{}
|
||||||
|
foreach ($t in Get-CimInstance Win32_PerfRawData_PerfProc_Thread -Filter "IDProcess=$procId") {
|
||||||
|
$threads[[uint32]$t.IDThread] = $t
|
||||||
|
}
|
||||||
|
$gpu = 0
|
||||||
|
foreach ($e in Get-CimInstance Win32_PerfRawData_GPUPerformanceCounters_GPUEngine -Filter "Name LIKE 'pid_$($procId)_%'") {
|
||||||
|
$gpu += [double]$e.RunningTime
|
||||||
|
}
|
||||||
|
[pscustomobject]@{
|
||||||
|
At = [Diagnostics.Stopwatch]::GetTimestamp(); Cpu = $p.TotalProcessorTime.TotalMilliseconds
|
||||||
|
Threads = $threads; GpuMs = $gpu / 10000.0; Ws = $p.WorkingSet64; Private = $p.PrivateMemorySize64
|
||||||
|
Count = $p.Threads.Count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Seconds($a, $b) { ($b.At - $a.At) / [Diagnostics.Stopwatch]::Frequency }
|
||||||
|
|
||||||
|
# A measurement only means something on a known machine and build (docs/performance.md).
|
||||||
|
function Machine($procId) {
|
||||||
|
$cpu = (Get-CimInstance Win32_Processor | Select-Object -First 1).Name.Trim()
|
||||||
|
$game = [bool](Get-Process 'League of Legends' -ErrorAction SilentlyContinue)
|
||||||
|
"Machine: $cpu; user idle for $([Math]::Round([BudgetProbe]::UserIdleSeconds())) s; game running: $game"
|
||||||
|
if ($procId) { "Build: $((Get-Process -Id $procId).Path)" }
|
||||||
|
}
|
||||||
|
|
||||||
|
function Memory($procId) {
|
||||||
|
$p = Get-Process -Id $procId
|
||||||
|
$g = Get-CimInstance Win32_PerfRawData_GPUPerformanceCounters_GPUProcessMemory -Filter "Name LIKE 'pid_$($procId)_%'"
|
||||||
|
"Memory: working set {0:F1} MB, private {1:F1} MB, peak working set {2:F1} MB; GPU shared {3:F1} MB, dedicated {4:F1} MB, committed {5:F1} MB" -f `
|
||||||
|
($p.WorkingSet64 / 1MB), ($p.PrivateMemorySize64 / 1MB), ($p.PeakWorkingSet64 / 1MB),
|
||||||
|
(($g | Measure-Object SharedUsage -Sum).Sum / 1MB), (($g | Measure-Object DedicatedUsage -Sum).Sum / 1MB),
|
||||||
|
(($g | Measure-Object TotalCommitted -Sum).Sum / 1MB)
|
||||||
|
}
|
||||||
|
|
||||||
|
function AppPid() {
|
||||||
|
$h = [BudgetProbe]::Find()
|
||||||
|
if ($h -ne [IntPtr]::Zero) { return [BudgetProbe]::Pid($h) }
|
||||||
|
$p = Get-Process arena-tracker -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||||
|
if (-not $p) { throw "Erreur : Arena Tracker n'est pas lancé." }
|
||||||
|
$p.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($Action) {
|
||||||
|
'info' {
|
||||||
|
$procId = AppPid
|
||||||
|
Machine $procId
|
||||||
|
$h = [BudgetProbe]::Find()
|
||||||
|
if ($h -ne [IntPtr]::Zero) { "Window: $([BudgetProbe]::State($h))" }
|
||||||
|
Memory $procId
|
||||||
|
}
|
||||||
|
'memory' { Memory (AppPid) }
|
||||||
|
'sample' {
|
||||||
|
$procId = AppPid
|
||||||
|
Machine $procId
|
||||||
|
$h = [BudgetProbe]::Need(); $ui = [BudgetProbe]::UiThread($h)
|
||||||
|
"Window: $([BudgetProbe]::State($h))"
|
||||||
|
$a = Snapshot $procId
|
||||||
|
Start-Sleep -Milliseconds ([int]($Seconds * 1000))
|
||||||
|
$b = Snapshot $procId
|
||||||
|
$s = Seconds $a $b; $cpu = $b.Cpu - $a.Cpu
|
||||||
|
"[$Label] over {0:F1} s: process CPU {1:F0} ms ({2:F2}% of one core), GPU {3:F1} ms, working set {4:F1} MB, private {5:F1} MB, {6} threads" -f `
|
||||||
|
$s, $cpu, ($cpu / ($s * 10)), ($b.GpuMs - $a.GpuMs), ($b.Ws / 1MB), ($b.Private / 1MB), $b.Count
|
||||||
|
# Wakes are context switches: a thread waking 60 times a second follows the display.
|
||||||
|
$rows = foreach ($id in $b.Threads.Keys) {
|
||||||
|
$tb = $b.Threads[$id]; $ta = $a.Threads[$id]
|
||||||
|
$cpu0 = 0; $wakes0 = 0
|
||||||
|
if ($ta) { $cpu0 = [double]$ta.PercentProcessorTime; $wakes0 = [double]$ta.ContextSwitchesPersec }
|
||||||
|
$wakes = [double]$tb.ContextSwitchesPersec - $wakes0
|
||||||
|
[pscustomobject]@{
|
||||||
|
Thread = $id; UI = ($id -eq $ui); CpuMs = [Math]::Round(([double]$tb.PercentProcessorTime - $cpu0) / 10000.0, 1)
|
||||||
|
Wakes = $wakes; PerSecond = [Math]::Round($wakes / $s, 1)
|
||||||
|
BasePriority = $tb.PriorityBase; CurrentPriority = $tb.PriorityCurrent; New = (-not $ta)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$rows | Where-Object { $_.Wakes -gt 0 -or $_.CpuMs -gt 0 } | Sort-Object CpuMs, Wakes -Descending |
|
||||||
|
Format-Table -AutoSize | Out-String -Width 200
|
||||||
|
"Threads without activity: $(@($rows | Where-Object { $_.Wakes -eq 0 -and $_.CpuMs -eq 0 }).Count)"
|
||||||
|
}
|
||||||
|
'trace' {
|
||||||
|
# One line per sample, each about 2 to 3 s apart (the counter queries take time): process
|
||||||
|
# CPU, then CPU by kind of thread. ui = the window's thread; vsync = a thread at current
|
||||||
|
# priority 15 waking more than 40 times a second (GPUI's VSyncProvider); low = base
|
||||||
|
# priority below normal; normal = the others. "unseen" is CPU of threads born and gone
|
||||||
|
# between two samples, whose priority is unknown.
|
||||||
|
$procId = AppPid
|
||||||
|
Machine $procId
|
||||||
|
$h = [BudgetProbe]::Find(); $ui = 0
|
||||||
|
if ($h -ne [IntPtr]::Zero) { $ui = [BudgetProbe]::UiThread($h) }
|
||||||
|
$prev = Snapshot $procId
|
||||||
|
$deadline = $prev.At + [long]($Seconds * [Diagnostics.Stopwatch]::Frequency)
|
||||||
|
$low = 0; $normal = 0; $maxProcess = 0; $maxThread = 0; $normalThreads = @{}
|
||||||
|
while ([Diagnostics.Stopwatch]::GetTimestamp() -lt $deadline) {
|
||||||
|
Start-Sleep -Milliseconds 1000
|
||||||
|
$cur = Snapshot $procId
|
||||||
|
$s = Seconds $prev $cur
|
||||||
|
$process = ($cur.Cpu - $prev.Cpu) / ($s * 10)
|
||||||
|
$kind = @{ ui = 0.0; vsync = 0.0; low = 0.0; normal = 0.0 }; $top = 0.0; $lowCount = 0
|
||||||
|
foreach ($id in $cur.Threads.Keys) {
|
||||||
|
$tb = $cur.Threads[$id]; $ta = $prev.Threads[$id]
|
||||||
|
$cpu0 = 0; $wakes0 = 0
|
||||||
|
if ($ta) { $cpu0 = [double]$ta.PercentProcessorTime; $wakes0 = [double]$ta.ContextSwitchesPersec }
|
||||||
|
$percent = ([double]$tb.PercentProcessorTime - $cpu0) / 100000.0 / $s
|
||||||
|
$wakes = ([double]$tb.ContextSwitchesPersec - $wakes0) / $s
|
||||||
|
if ($percent -gt $top) { $top = $percent }
|
||||||
|
if ($id -eq $ui) { $kind.ui += $percent }
|
||||||
|
elseif ($tb.PriorityCurrent -ge 15 -and $wakes -gt 40) { $kind.vsync += $percent }
|
||||||
|
elseif ([int]$tb.PriorityBase -lt 8) { $kind.low += $percent; if ($percent -gt 0) { $lowCount++ } }
|
||||||
|
else {
|
||||||
|
$kind.normal += $percent
|
||||||
|
if ($percent -gt 0) { $normalThreads[$id] = [Math]::Max([double]$normalThreads[$id], $percent) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$unseen = [Math]::Max(0, $process - ($kind.ui + $kind.vsync + $kind.low + $kind.normal))
|
||||||
|
"process {0,5:F1}% ui {1,4:F1} vsync {2,4:F1} low {3,5:F1} ({4} threads) normal {5,4:F1} unseen {6,4:F1} top thread {7,4:F1}% working set {8:F0} MB" -f `
|
||||||
|
$process, $kind.ui, $kind.vsync, $kind.low, $lowCount, $kind.normal, $unseen, $top, ($cur.Ws / 1MB)
|
||||||
|
$low += $kind.low * $s / 100; $normal += $kind.normal * $s / 100
|
||||||
|
if ($process -gt $maxProcess) { $maxProcess = $process }
|
||||||
|
if ($top -gt $maxThread) { $maxThread = $top }
|
||||||
|
$prev = $cur
|
||||||
|
}
|
||||||
|
"[$Label] highest sample: process {0:F1}% of one core, one thread {1:F1}%; background CPU time at low priority {2:F2} s, at normal priority {3:F2} s" -f `
|
||||||
|
$maxProcess, $maxThread, $low, $normal
|
||||||
|
if ($normalThreads.Count) {
|
||||||
|
"Normal-priority threads with CPU (thread: highest %): " + (($normalThreads.GetEnumerator() | ForEach-Object { "$($_.Key): {0:F1}" -f $_.Value }) -join ', ')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'front' { [BudgetProbe]::Front([BudgetProbe]::Need()); [BudgetProbe]::State([BudgetProbe]::Need()) }
|
||||||
|
'minimize' { [BudgetProbe]::Show([BudgetProbe]::Need(), 6 <# SW_MINIMIZE #>); [BudgetProbe]::State([BudgetProbe]::Need()) }
|
||||||
|
'restore' { [BudgetProbe]::Show([BudgetProbe]::Need(), 9 <# SW_RESTORE #>); [BudgetProbe]::State([BudgetProbe]::Need()) }
|
||||||
|
'close' { [BudgetProbe]::Close([BudgetProbe]::Need()); Start-Sleep 1; [BudgetProbe]::State([BudgetProbe]::Need()) }
|
||||||
|
'click' { [BudgetProbe]::Click([BudgetProbe]::Need(), $X, $Y) }
|
||||||
|
'cursor' { [BudgetProbe]::Cursor([BudgetProbe]::Need(), $X, $Y) }
|
||||||
|
'wheel' { [BudgetProbe]::Wheel([BudgetProbe]::Need(), $X, $Y, $Delta, $Count, $Rate) }
|
||||||
|
'shot' { [BudgetProbe]::Shot([BudgetProbe]::Need(), $Out); "Saved $Out" }
|
||||||
|
default { throw "Erreur : action inconnue '$Action'." }
|
||||||
|
}
|
||||||
Reference in new issue
Block a user