@combos-fun/plugin-stats 0.0.0-stage → 0.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -2
- package/combos-plugin.json +11 -0
- package/dist/plugin-stats.cjs.js +599 -0
- package/dist/plugin-stats.cjs.js.map +1 -0
- package/dist/plugin-stats.cjs.prod.js +1 -0
- package/dist/plugin-stats.d.ts +157 -0
- package/dist/plugin-stats.esm.js +587 -0
- package/dist/plugin-stats.esm.js.map +1 -0
- package/index.js +7 -0
- package/package.json +33 -3
package/README.md
CHANGED
|
@@ -1,3 +1,118 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @combos-fun/plugin-stats
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
One shared runtime stats system for 2D and 3D. The package depends only on the
|
|
4
|
+
engine. Its HUD uses DOM and Canvas 2D, never Pixi or Three.js. Renderer-specific
|
|
5
|
+
probes live in the renderer packages and register through `game.diagnostics`.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { StatsSystem } from '@combos-fun/plugin-stats';
|
|
9
|
+
|
|
10
|
+
const stats = new StatsSystem({
|
|
11
|
+
instanceId: 'main',
|
|
12
|
+
gpuTiming: false, // production default; demos explicitly enable it
|
|
13
|
+
panel: { enabled: false, position: 'top-right' },
|
|
14
|
+
reporting: { enabled: true, intervalMs: 10000 },
|
|
15
|
+
allowedMessageOrigins: ['http://localhost:9020'],
|
|
16
|
+
});
|
|
17
|
+
// Include stats in Game.systems alongside the chosen renderer.
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Reporting
|
|
21
|
+
|
|
22
|
+
Reporting defaults to enabled. A `combos-game:performance` snapshot is emitted
|
|
23
|
+
immediately **after each** `combos-game:ready` and `combos-game:resources-ready`.
|
|
24
|
+
The existing lifecycle event is plural `resources-ready`; no new singular alias
|
|
25
|
+
is introduced. If preload completed before the plugin was attached, its latest
|
|
26
|
+
batch is replayed with `replayed: true`. Resources are an engine-wide singleton,
|
|
27
|
+
so all installed Stats systems observe the same preload batches.
|
|
28
|
+
|
|
29
|
+
The first lifecycle snapshot starts the interval timer. Every subsequent 10 s,
|
|
30
|
+
the plugin emits a non-overlapping aggregate and resets that interval window.
|
|
31
|
+
Lifecycle snapshots do not reset or postpone the interval timer or consume the
|
|
32
|
+
window. Their `reason` is `ready` / `resources-ready`; periodic reports use
|
|
33
|
+
`interval`. A ready report may have no frame samples: these values are `null`,
|
|
34
|
+
not a fabricated 0 FPS. `seq` increases for every report. Failed resource batches
|
|
35
|
+
still trigger a report with the original `failed` list under `lifecycle`.
|
|
36
|
+
|
|
37
|
+
Each report is emitted through `game.emit`, a window `CustomEvent` and the
|
|
38
|
+
existing parent iframe / native runtime bridge. The host owns backend uploads;
|
|
39
|
+
this plugin does not send HTTP requests. All timestamps ending in `Ms` are
|
|
40
|
+
monotonic performance time, except `timestamp` which is epoch milliseconds.
|
|
41
|
+
|
|
42
|
+
Paused/hidden time is excluded from `activeDurationMs` and FPS denominators;
|
|
43
|
+
interval heartbeats continue with zero active time and no new samples. Resume
|
|
44
|
+
starts a new RAF baseline so the pause does not become a slow frame.
|
|
45
|
+
|
|
46
|
+
## Commands
|
|
47
|
+
|
|
48
|
+
Commands work through `game.emit(type, payload)`,
|
|
49
|
+
`window.dispatchEvent(new CustomEvent(type, { detail: payload }))` or
|
|
50
|
+
`postMessage({ type, ...payload }, origin)`. **Every command requires the intended
|
|
51
|
+
`instanceId`**. Optional `requestId` is echoed. Cross-frame commands validate
|
|
52
|
+
origin using engine allow-list rules and must come from the parent window.
|
|
53
|
+
|
|
54
|
+
| Command | Payload |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `combos-development-tool:set-stats-panel` | `enabled`, optional `position`, `rendererId`, `refreshIntervalMs` (100–10000), `metrics` |
|
|
57
|
+
| `combos-game:set-performance-reporting` | `enabled`, optional `intervalMs` (1000–3600000; default 10000) |
|
|
58
|
+
| `combos-development-tool:get-stats-state` | instanceId |
|
|
59
|
+
| `combos-development-tool:get-stats-snapshot` | instanceId |
|
|
60
|
+
|
|
61
|
+
Replies: `combos-development-tool:stats-ready`, `stats-state-changed`,
|
|
62
|
+
`stats-snapshot`, `stats-error` (each with the same namespace).
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
game.emit('combos-development-tool:set-stats-panel', {
|
|
66
|
+
instanceId: 'main', enabled: true, position: 'top-right',
|
|
67
|
+
});
|
|
68
|
+
game.emit('combos-game:set-performance-reporting', {
|
|
69
|
+
instanceId: 'main', enabled: true, intervalMs: 10000,
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The HUD is pointer-transparent, refreshed at 4 Hz by default, and is independent
|
|
74
|
+
of reporting. Disabling both removes sampling hooks, GPU queries and HUD timers.
|
|
75
|
+
All listeners and instrumentation are released on destruction. Renderer providers
|
|
76
|
+
can be registered before or after Stats, including extra 2D canvases.
|
|
77
|
+
|
|
78
|
+
## Metric definitions
|
|
79
|
+
|
|
80
|
+
- RAF FPS and frame intervals use physical monotonic time; update FPS counts real
|
|
81
|
+
engine updates; render FPS counts each renderer's actual render submissions.
|
|
82
|
+
None guarantees physical display presentation.
|
|
83
|
+
- `updateCpuMs` measures the full synchronous update/lateUpdate span, including
|
|
84
|
+
render submission. `renderSubmitMs` is a subset, not an additive CPU cost and
|
|
85
|
+
not GPU execution time. No CPU/GPU usage percentages are fabricated.
|
|
86
|
+
- A slow RAF interval exceeds 1.5 times the target frame budget. Absolute >50 ms
|
|
87
|
+
and >100 ms counters are also reported.
|
|
88
|
+
- WebGL drawing includes arrays, indexed and instanced draws. Pixi WebGPU counts
|
|
89
|
+
its encoder draw path (including render effects, excluding resource mipmaps).
|
|
90
|
+
Canvas 2D reports drawing API operations as `canvasDrawOps`, not GPU draw calls.
|
|
91
|
+
- Three.js counts all render passes including shadows. Resource numbers are
|
|
92
|
+
current renderer-managed counts, not bytes of VRAM.
|
|
93
|
+
- GPU queries are off by default (`gpuTiming: false`). With `gpuTiming: true`,
|
|
94
|
+
WebGL GPU time uses sparse asynchronous timer queries, approximately every 30
|
|
95
|
+
submissions. Invalid disjoint samples are discarded. The current Pixi-created
|
|
96
|
+
WebGPU device does not enable timestamp queries, so `gpuMs` is explicitly
|
|
97
|
+
unsupported there. Feature support is sent per renderer under `capabilities`.
|
|
98
|
+
- JS heap is page-scoped, optional, non-standard, and excludes GPU memory.
|
|
99
|
+
- Input delay/dispatch cover synchronous engine pointer event dispatch.
|
|
100
|
+
`inputToNextSubmitMs` is native input to the next submission on the same canvas,
|
|
101
|
+
not proof that the action has produced a visible response. Business completion
|
|
102
|
+
and physical presentation require additional application/platform instrumentation.
|
|
103
|
+
- Summaries contain mean, extrema, P95/P99 and sample counts. Percentile storage
|
|
104
|
+
retains at most 4096 samples per metric; if exceeded,
|
|
105
|
+
`percentilesApproximate: true` identifies the retained-window approximation.
|
|
106
|
+
Count, mean and extrema still cover every sample.
|
|
107
|
+
|
|
108
|
+
## Examples
|
|
109
|
+
|
|
110
|
+
From the repository root:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
pnpm demo:stats:2d # http://localhost:9020
|
|
114
|
+
pnpm demo:stats:3d # http://localhost:9021
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Each host page demonstrates postMessage panel toggles, pause/resume, simulated
|
|
118
|
+
stalls, immediate lifecycle reports, and 10 second aggregated reports.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@combos-fun/plugin-stats",
|
|
3
|
+
"pluginId": "stats",
|
|
4
|
+
"category": "devtool",
|
|
5
|
+
"dimension": "shared",
|
|
6
|
+
"isCore": false,
|
|
7
|
+
"keywords": ["performance", "stats", "fps", "draw-call", "telemetry", "panel"],
|
|
8
|
+
"agentSkill": null,
|
|
9
|
+
"requires": ["@combos-fun/engine"],
|
|
10
|
+
"exports": ["StatsSystem", "COMBOS_STATS_SET_PANEL", "COMBOS_STATS_SET_REPORTING", "COMBOS_STATS_PERFORMANCE"]
|
|
11
|
+
}
|