@playcanvas/inspector 0.3.0 → 0.4.0
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 +113 -4
- package/package.json +1 -1
- package/src/entity-inspector-script.js +10 -0
- package/src/frame-graph-view.js +40 -9
- package/src/inspector.js +555 -24
- package/src/node-model.js +3 -2
- package/src/perf-capture.js +2034 -0
- package/src/perf-chart.js +3989 -0
- package/src/perf-copy.js +367 -0
- package/src/perf-view.js +1224 -0
- package/src/property-view.js +3 -0
- package/src/styles.js +179 -1
- package/types/entity-inspector-script.d.ts +8 -0
- package/types/frame-graph-view.d.ts +7 -0
- package/types/inspector.d.ts +199 -5
- package/types/perf-capture.d.ts +871 -0
- package/types/perf-chart.d.ts +1407 -0
- package/types/perf-copy.d.ts +61 -0
- package/types/perf-view.d.ts +231 -0
package/README.md
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
| [User Manual](https://developer.playcanvas.com) | [Blog](https://blog.playcanvas.com) | [Forum](https://forum.playcanvas.com) |
|
|
11
11
|
|
|
12
12
|
A debug panel for running [PlayCanvas](https://github.com/playcanvas/engine) apps. It shows the entity
|
|
13
|
-
hierarchy and every component's properties, and tabs for the cameras, assets, frame graph,
|
|
14
|
-
targets, textures, meshes, materials, scripts, memory, shaders and physics of
|
|
15
|
-
previews of textures and render targets, picking and flying in the view, and a
|
|
16
|
-
that steps through the draw calls of a render pass.
|
|
13
|
+
hierarchy and every component's properties, and tabs for the cameras, assets, frame graph,
|
|
14
|
+
performance, render targets, textures, meshes, materials, scripts, memory, shaders and physics of
|
|
15
|
+
the app, with live previews of textures and render targets, picking and flying in the view, and a
|
|
16
|
+
debug frame mode that steps through the draw calls of a render pass.
|
|
17
17
|
|
|
18
18
|
The inspector is read-only, apart from toggling entities on and off, pausing and stepping the app,
|
|
19
19
|
and view-only overrides (render modes, wireframe, a flown or orbited camera) it removes when it
|
|
@@ -63,6 +63,109 @@ needs the debug build of the engine.
|
|
|
63
63
|
|
|
64
64
|

|
|
65
65
|
|
|
66
|
+
### Record performance
|
|
67
|
+
|
|
68
|
+
On the Performance tab, press the record button (a ring around a dot) to capture every frame, up to
|
|
69
|
+
the last 1000; it shows red while recording, and pressing it again stops. The button beside it
|
|
70
|
+
clears the capture. Charts cover the whole capture along its time, each frame as wide as it lasted,
|
|
71
|
+
with a pause longer than a second folded to a break mark: the frame interval, the CPU time on the
|
|
72
|
+
main thread by phase, the GPU time and the draw calls by kind. The Loading section, on the same
|
|
73
|
+
time, marks the moments of the page and the app, such as the first paint, the preload and the first
|
|
74
|
+
frame, the assets loading, from asking for them to their resource being ready, with their request
|
|
75
|
+
solid and what came after it, as parsing, faint, and how many requests were in flight; hover it for
|
|
76
|
+
what was loading, and click an asset to show it on the Assets tab. Below them, the Memory chart
|
|
77
|
+
draws the JavaScript heap, the video memory and each kind of it as lines sharing a scale, and the
|
|
78
|
+
Resources chart the count of textures, render targets, shaders, buffers and pipelines; untick a line
|
|
79
|
+
in the list beside a chart to hide it, and the chart rescales to the others. The Events section has
|
|
80
|
+
a row, which can be unticked too, for each kind of event, marking the frames that had one: hitches,
|
|
81
|
+
main thread blocked, lightmap bakes (for an app with a lightmapper), shaders compiled, garbage
|
|
82
|
+
collections, resources created or destroyed and the app's own measures; the assets loading are in
|
|
83
|
+
the Loading section. A hitch is a frame taking over twice the median, whatever held it back, so it
|
|
84
|
+
is what the user sees stutter. Main thread blocked is what the browser reports, in Chromium
|
|
85
|
+
browsers, as a long animation frame: its main thread busy for 50 ms or more, with the script that
|
|
86
|
+
ran longest, during a frame or between them. It tells why a frame was slow: a hitch without it was
|
|
87
|
+
held back by the GPU, the browser or the display, which its hover says. Click the name of a chart or
|
|
88
|
+
a section to collapse it. Hover a mark for what happened, or a chart for the figures of the frame
|
|
89
|
+
under the pointer. A dashed line marks the display interval on the Frame, CPU and GPU charts, which
|
|
90
|
+
are scaled to show it.
|
|
91
|
+
|
|
92
|
+
Click a frame, or a mark, to show it on a timeline of its own, and everything recorded for it below:
|
|
93
|
+
what held it back, the CPU time by phase, the GPU time of each pass, what loaded in it, the work it
|
|
94
|
+
submitted, memory and resources, and its events. The timeline is a flame chart: the update,
|
|
95
|
+
post-update, inspector and render of the CPU, and any lightmap bake where it ran, with the physics
|
|
96
|
+
step, the animation and the phases of the render under them, then the GPU passes, the events, and
|
|
97
|
+
the moments, assets and requests of the frame. With frames selected together, it shows their average
|
|
98
|
+
frame. Scroll over the timeline to zoom into part of the frame, drag the scrollbar under it, or drag
|
|
99
|
+
across it holding Shift, to pan, and double-click it to see the whole frame again; click its title
|
|
100
|
+
to collapse it. Drag the divider between the names and the charts, or the timeline, to make the
|
|
101
|
+
names wider. Drag across the charts to select frames together, with their averages, 95th percentiles
|
|
102
|
+
and largest figures; scroll to zoom, then drag the scrollbar under the charts, or drag across them
|
|
103
|
+
holding Shift, to pan, and double-click to see the whole capture again. **‹** and **›** step a
|
|
104
|
+
frame, **«** shows the first and **»** the newest, following it as frames are recorded. While the
|
|
105
|
+
panel has focus, the arrow keys step a frame (ten with <kbd>Shift</kbd>), <kbd>Home</kbd> shows the
|
|
106
|
+
first and <kbd>End</kbd> follows the newest.
|
|
107
|
+
|
|
108
|
+
Turn on **GPU timings** to record the GPU time. On WebGPU each pass is timed, and the timeline draws
|
|
109
|
+
the GPU as a flame chart: the effects, such as bloom or depth of field, on the GPU line, with the
|
|
110
|
+
passes each runs under it, and the passes of their own on the GPU line too. The effect of a pass
|
|
111
|
+
comes from the frame graph, the pass it is a before or after pass of; where the frame graph no
|
|
112
|
+
longer matches the passes timed, every pass goes on the GPU line. Passes of one name in a row share
|
|
113
|
+
a label, as Downsample ×5, the frame details list the time of each, and clicking a pass or an effect
|
|
114
|
+
shows it on the Frame graph tab. An engine that sums the passes sharing a name, before 2.24, gives
|
|
115
|
+
one time for each name, and WebGL times the frame as a whole. An engine whose GPU profiler does not
|
|
116
|
+
say which frame its timings belong to, such as 2.23, gets them a few frames late, which the tab
|
|
117
|
+
notes. The inspector runs inside the app's update, so its own time is shown apart, as Inspector;
|
|
118
|
+
turn off **Inspector time** to leave it out of the CPU chart, which then scales to the app's own
|
|
119
|
+
time. The release engine times the update and the render as a whole; the profiler and debug engines
|
|
120
|
+
add the phases of the render, the batcher's updating and creating of batches among them, and the
|
|
121
|
+
breakdown of the draw calls. Spans the app measures with `performance.measure` show on the timeline
|
|
122
|
+
of their frame.
|
|
123
|
+
|
|
124
|
+
Turn on **Script timing** to time each script type while recording: the time of its `update`,
|
|
125
|
+
`postUpdate` and `initialize` calls, without the calls nested in them, such as the scripts of an
|
|
126
|
+
entity a script creates, and how many times each was called. The CPU chart then stacks the scripts
|
|
127
|
+
apart from the other systems, and the timeline draws the scripts of the update and of the
|
|
128
|
+
post-update where they ran, with a line below breaking each down by script type: as the calls of
|
|
129
|
+
the types interleave, entity by entity, each type is its time in all, back to back in the order the
|
|
130
|
+
types first ran. Click a type there to show it on the Scripts tab. The Scripts chart stacks the ten script types that took the longest, over the
|
|
131
|
+
frames selected together or else the whole capture, so selecting a spike brings forward the
|
|
132
|
+
scripts behind it; the others share one band, whose hover lists the longest of them. **▸ 10 more**
|
|
133
|
+
under the list gives ten more types a band of their own. To follow a script whatever its time, pin
|
|
134
|
+
it: **Pin** beside it in the Scripts details, or Shift+click it in the list. Alt+click a line of a
|
|
135
|
+
list to show it alone, and again to show them all. Timing a call costs the app about half a
|
|
136
|
+
microsecond, estimated as recording starts and counted as the inspector's time. Time spent in
|
|
137
|
+
event handlers, timers and promises is not counted. On a page that is not cross-origin isolated,
|
|
138
|
+
the browser's clock steps by a tenth of a millisecond, so the times of small scripts read best over
|
|
139
|
+
many frames selected together.
|
|
140
|
+
|
|
141
|
+
The Counters section charts the counters the app keeps in `app.stats.user`, as each frame ended: a
|
|
142
|
+
line each, with a scale of its own, as their units are the app's. The frame details list their
|
|
143
|
+
values, and the frames selected together their averages, 95th percentiles and largest:
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
// counted afresh each frame
|
|
147
|
+
app.on('frameupdate', () => app.stats.user.set('enemies', 0));
|
|
148
|
+
|
|
149
|
+
// wherever the app counts them
|
|
150
|
+
app.stats.user.set('enemies', app.stats.user.get('enemies') + 1);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
To record from the first frame the app runs, pass `record: true` to the constructor, or set the
|
|
154
|
+
`record` attribute of the `EntityInspector` script. Create the inspector before the app runs its
|
|
155
|
+
first frame, as right after `app.init()`, to record the start of the app too: the capture then
|
|
156
|
+
begins with a Startup entry, from the page opening to the first frame, with the requests of the
|
|
157
|
+
page, its moments, the assets loaded and the times its main thread was blocked; its details list the
|
|
158
|
+
slowest assets, with their request and processing apart. It is one of the 1000 entries, so it makes
|
|
159
|
+
way for frames like any other. From code, set `inspector.recording` to start or stop a capture
|
|
160
|
+
around a part of the app:
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
const inspector = new Inspector(app, { record: true });
|
|
164
|
+
|
|
165
|
+
// once the part to look at has run
|
|
166
|
+
inspector.recording = false;
|
|
167
|
+
```
|
|
168
|
+
|
|
66
169
|
### Edit transforms
|
|
67
170
|
|
|
68
171
|
Click a position, rotation or the local scale in the Transform section of an entity to edit it as
|
|
@@ -84,6 +187,12 @@ the whole hierarchy. A link that is not followed is named by `$type` and its nam
|
|
|
84
187
|
marked `$stub`; an object already copied elsewhere in the copy is marked `$ref`. A node's parent
|
|
85
188
|
and the lists of what uses an object are left out, so a copy never climbs out of what was copied.
|
|
86
189
|
|
|
190
|
+
On the Performance tab, right-click the name of the tab to copy the whole capture, every frame with
|
|
191
|
+
all it recorded, or the name of a chart or section, or a line of its list, to copy that series a row
|
|
192
|
+
per frame, as JSON or as CSV for a spreadsheet; both cover the frames selected together when there
|
|
193
|
+
are any. Right-click a frame in the charts to copy it, inside the frames selected together to copy
|
|
194
|
+
their figures, and the timeline to copy its bars.
|
|
195
|
+
|
|
87
196
|
## Engine versions
|
|
88
197
|
|
|
89
198
|
Each inspector release names the engine versions it supports in its `playcanvas` peer dependency.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playcanvas/inspector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A debug panel for PlayCanvas apps: the entity hierarchy, assets, frame graph, render targets, textures, meshes, materials, scripts, cameras, memory, shaders and physics of a running app",
|
|
5
5
|
"author": "PlayCanvas <support@playcanvas.com>",
|
|
6
6
|
"homepage": "https://github.com/playcanvas/inspector#readme",
|
|
@@ -83,6 +83,15 @@ class EntityInspector extends Script {
|
|
|
83
83
|
*/
|
|
84
84
|
stepKey = 'F10';
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Whether to start recording frames for the Performance tab as soon as the panel is created,
|
|
88
|
+
* capturing the first frames of the scene.
|
|
89
|
+
*
|
|
90
|
+
* @attribute
|
|
91
|
+
* @type {boolean}
|
|
92
|
+
*/
|
|
93
|
+
record = false;
|
|
94
|
+
|
|
86
95
|
/**
|
|
87
96
|
* @type {Inspector|null}
|
|
88
97
|
* @private
|
|
@@ -107,6 +116,7 @@ class EntityInspector extends Script {
|
|
|
107
116
|
toggleKey: this.toggleKey,
|
|
108
117
|
pauseKey: this.pauseKey,
|
|
109
118
|
stepKey: this.stepKey,
|
|
119
|
+
record: this.record,
|
|
110
120
|
lockedNode: this.entity
|
|
111
121
|
});
|
|
112
122
|
|
package/src/frame-graph-view.js
CHANGED
|
@@ -254,7 +254,8 @@ function instancePage(list, key, ctx) {
|
|
|
254
254
|
// pass properties the model shows explicitly, or that are plumbing
|
|
255
255
|
const SKIP_PASS = [
|
|
256
256
|
'name', 'enabled', 'executeEnabled', 'requiresCubemaps', 'device', 'renderTarget', 'colorOps',
|
|
257
|
-
'colorArrayOps', 'depthStencilOps', 'beforePasses', 'afterPasses', 'children', 'samples',
|
|
257
|
+
'colorArrayOps', 'depthStencilOps', 'internalBeforePasses', 'beforePasses', 'afterPasses', 'children', 'samples',
|
|
258
|
+
'firstCameraUse', 'lastCameraUse',
|
|
258
259
|
'scaleX', 'scaleY', 'options', 'fullSizeClearRect', 'layerRenderSteps', 'renderer', 'scene',
|
|
259
260
|
'shadowRenderer'
|
|
260
261
|
];
|
|
@@ -326,12 +327,15 @@ function colorFormat(rt, index, device) {
|
|
|
326
327
|
*/
|
|
327
328
|
function captureFrameGraph(app) {
|
|
328
329
|
const device = app.graphicsDevice;
|
|
329
|
-
|
|
330
|
+
// engines before 2.24 name the list renderPasses
|
|
331
|
+
const passes = app.frameGraph?.passes ?? app.frameGraph?.renderPasses ?? [];
|
|
330
332
|
|
|
331
333
|
/** @type {Map<FramePass, FramePass>} */
|
|
332
334
|
const parentOf = new Map();
|
|
333
335
|
const mark = (pass) => {
|
|
334
|
-
|
|
336
|
+
// the internal before-passes, which engines before 2.24 do not have, execute ahead of the
|
|
337
|
+
// before-passes
|
|
338
|
+
const children = [...pass.internalBeforePasses ?? [], ...pass.beforePasses, ...pass.afterPasses, ...(Array.isArray(pass.children) ? pass.children : [])];
|
|
335
339
|
for (const child of children) {
|
|
336
340
|
parentOf.set(child, pass);
|
|
337
341
|
mark(child);
|
|
@@ -500,7 +504,8 @@ function passRows(frame, device) {
|
|
|
500
504
|
const layer = step.layer;
|
|
501
505
|
const enabled = layer.enabled && (pass.layerComposition?.isEnabled(layer, step.transparent) ?? true);
|
|
502
506
|
const camera = step.cameraComponent?.entity;
|
|
503
|
-
const
|
|
507
|
+
const use = cameraUse(step, i, pass);
|
|
508
|
+
const flags = `${use.first ? ' · first' : ''}${use.last ? ' · last' : ''}${enabled ? '' : ' · disabled'}`;
|
|
504
509
|
rows.push({
|
|
505
510
|
key: `${entry.key}/${i}`,
|
|
506
511
|
item: new LayerStepSelection(pass, step, i),
|
|
@@ -637,11 +642,14 @@ function buildPassModel(pass, ctx) {
|
|
|
637
642
|
const runs = Array.isArray(/** @type {any} */ (entry.parent).children) && /** @type {any} */ (entry.parent).children.includes(pass);
|
|
638
643
|
push(general, runs ? 'run by' : 'owned by', { text: passDisplayName(entry.parent), cls: 'ref', target: entry.parent });
|
|
639
644
|
}
|
|
645
|
+
const internalBeforePasses = /** @type {any} */ (pass).internalBeforePasses;
|
|
646
|
+
if (internalBeforePasses?.length) push(general, 'internal before passes', passList(internalBeforePasses));
|
|
640
647
|
if (pass.beforePasses.length) push(general, 'before passes', passList(pass.beforePasses));
|
|
641
648
|
if (pass.afterPasses.length) push(general, 'after passes', passList(pass.afterPasses));
|
|
642
649
|
const children = /** @type {any} */ (pass).children;
|
|
643
650
|
if (Array.isArray(children) && children.length) push(general, 'per-view passes', passList(children));
|
|
644
|
-
|
|
651
|
+
// engines from 2.24 no longer have the property
|
|
652
|
+
if (/** @type {any} */ (pass).requiresCubemaps !== undefined) push(general, 'requires cubemaps', read(pass, 'requiresCubemaps'));
|
|
645
653
|
sections.push(general);
|
|
646
654
|
|
|
647
655
|
const rt = entry ? entry.renderTarget : (pass.renderTarget === undefined ? undefined : (pass.renderTarget ?? device.backBuffer));
|
|
@@ -694,9 +702,10 @@ function buildPassModel(pass, ctx) {
|
|
|
694
702
|
push(section, `[${i}] camera`, describeValue(step.cameraComponent?.entity ?? null));
|
|
695
703
|
push(section, `[${i}] layer`, describeValue(layer));
|
|
696
704
|
const list = ctx.frame?.visible?.get(step) ?? null;
|
|
705
|
+
const use = cameraUse(step, i, pass);
|
|
697
706
|
push(section, `[${i}] draws`, {
|
|
698
707
|
text: `${step.transparent ? 'transparent' : 'opaque'}, ${drawnText(list, layer)}` +
|
|
699
|
-
`${enabled ? '' : ', disabled'}${
|
|
708
|
+
`${enabled ? '' : ', disabled'}${use.first ? ', first camera use' : ''}${use.last ? ', last camera use' : ''}`,
|
|
700
709
|
cls: 'obj',
|
|
701
710
|
expand: list ? () => instancePage(list, `${ctx.passKey ?? ''}/${i}`, ctx) : undefined
|
|
702
711
|
});
|
|
@@ -721,6 +730,27 @@ function stepEnabled(step, pass) {
|
|
|
721
730
|
return step.layer.enabled && (pass.layerComposition?.isEnabled(step.layer, step.transparent) ?? true);
|
|
722
731
|
}
|
|
723
732
|
|
|
733
|
+
/**
|
|
734
|
+
* Whether a layer render step of a forward pass is the first to render its camera in the frame,
|
|
735
|
+
* and whether it is the last. Engines before 2.24 keep these flags on each step. Later ones keep
|
|
736
|
+
* them on the pass, which renders a single camera, so they belong to its first and its last step.
|
|
737
|
+
*
|
|
738
|
+
* @param {*} step - A layer render step.
|
|
739
|
+
* @param {number} index - The index of the step in its pass.
|
|
740
|
+
* @param {RenderPassForward} pass - The pass it belongs to.
|
|
741
|
+
* @returns {{ first: boolean, last: boolean }} The flags.
|
|
742
|
+
*/
|
|
743
|
+
function cameraUse(step, index, pass) {
|
|
744
|
+
const forward = /** @type {any} */ (pass);
|
|
745
|
+
if (forward.firstCameraUse === undefined) {
|
|
746
|
+
return { first: !!step.firstCameraUse, last: !!step.lastCameraUse };
|
|
747
|
+
}
|
|
748
|
+
return {
|
|
749
|
+
first: !!forward.firstCameraUse && index === 0,
|
|
750
|
+
last: !!forward.lastCameraUse && index === pass.layerRenderSteps.length - 1
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
|
|
724
754
|
/**
|
|
725
755
|
* Everything the property view shows for one layer step of a forward pass: the camera and layer it
|
|
726
756
|
* renders, what it clears, and the instances it drew in draw order, listed straight away and paged
|
|
@@ -747,8 +777,9 @@ function buildStepModel(selection, ctx) {
|
|
|
747
777
|
push(general, 'draws', { text: drawnText(list, layer), cls: list ? 'num' : 'null' });
|
|
748
778
|
push(general, 'enabled', describeValue(enabled));
|
|
749
779
|
push(general, 'clears', { text: clears || 'nothing', cls: clears ? 'obj' : 'null' });
|
|
750
|
-
|
|
751
|
-
if (
|
|
780
|
+
const use = cameraUse(step, index, pass);
|
|
781
|
+
if (use.first) push(general, 'first camera use', describeValue(true));
|
|
782
|
+
if (use.last) push(general, 'last camera use', describeValue(true));
|
|
752
783
|
if (ctx.debug?.stepKey === ctx.passKey && list) {
|
|
753
784
|
push(general, 'debug frame', { text: `stops after draw ${ctx.debug.index} of ${list.instances.length}`, cls: 'num' });
|
|
754
785
|
}
|
|
@@ -765,4 +796,4 @@ function buildStepModel(selection, ctx) {
|
|
|
765
796
|
return sections;
|
|
766
797
|
}
|
|
767
798
|
|
|
768
|
-
export { INSTANCES_PER_PAGE, LayerStepSelection, buildPassModel, buildStepModel, captureFrameGraph, passRows };
|
|
799
|
+
export { INSTANCES_PER_PAGE, LayerStepSelection, buildPassModel, buildStepModel, captureFrameGraph, passRows, profilerName };
|