react-native-tapline 1.2.0 → 1.3.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/dist/client.js +7 -1
- package/dist/client.js.map +1 -1
- package/dist/crash.d.ts +37 -0
- package/dist/crash.js +212 -0
- package/dist/crash.js.map +1 -0
- package/dist/events.d.ts +2 -0
- package/dist/events.js +5 -0
- package/dist/events.js.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/logs.js +50 -12
- package/dist/logs.js.map +1 -1
- package/dist/methods.js +7 -0
- package/dist/methods.js.map +1 -1
- package/dist/perf.d.ts +120 -0
- package/dist/perf.js +366 -0
- package/dist/perf.js.map +1 -0
- package/dist/register.d.ts +5 -0
- package/dist/register.js +14 -0
- package/dist/register.js.map +1 -1
- package/dist/source.d.ts +5 -0
- package/dist/source.js +27 -0
- package/dist/source.js.map +1 -1
- package/dist/types.d.ts +4 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/perf.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AGENT-TOOLS §15.3 `performance`, Tapline's side: the JavaScript thread's frames, the Hermes heap and (in a
|
|
3
|
+
* development build) the slowest component renders, measured between `perfStart` and `perfStop`.
|
|
4
|
+
*
|
|
5
|
+
* Frames come from a requestAnimationFrame loop: each callback is one frame, the gap to the one before is the
|
|
6
|
+
* frame interval. A gap over 50 ms is a drop; the longest gap is how long the JS thread was busy at most.
|
|
7
|
+
* This is the JavaScript thread's view, not the screen's: native animations that don't need JS don't show.
|
|
8
|
+
*/
|
|
9
|
+
/** A frame interval longer than this is a drop (§15.3). */
|
|
10
|
+
export declare const DROP_MS = 50;
|
|
11
|
+
/** How often the heap is read while measuring. */
|
|
12
|
+
export declare const HEAP_SAMPLE_MS = 250;
|
|
13
|
+
/** A measurement nobody stopped (the host went away) ends by itself after this long. */
|
|
14
|
+
export declare const MAX_WINDOW_MS = 40000;
|
|
15
|
+
/** Renders shorter than this don't make the list. */
|
|
16
|
+
export declare const MIN_RENDER_MS = 1;
|
|
17
|
+
/** At most this many components are reported. */
|
|
18
|
+
export declare const MAX_RENDERS = 5;
|
|
19
|
+
export interface RenderTime {
|
|
20
|
+
name: string;
|
|
21
|
+
/** The longest this component took in one render in the window (its own time, without its children), in ms. */
|
|
22
|
+
ms: number;
|
|
23
|
+
/** How many times it rendered in the window. */
|
|
24
|
+
count: number;
|
|
25
|
+
}
|
|
26
|
+
export interface PerfResult {
|
|
27
|
+
/** The length of the window in seconds. */
|
|
28
|
+
seconds: number;
|
|
29
|
+
frames: number;
|
|
30
|
+
/** Average frames per second over the window. */
|
|
31
|
+
fps: number;
|
|
32
|
+
/** The lowest one-second sample (the whole window's average when it is shorter than a second). */
|
|
33
|
+
fpsLowest: number;
|
|
34
|
+
/** Frame intervals over 50 ms. */
|
|
35
|
+
drops: number;
|
|
36
|
+
/** The longest frame interval: the JS thread's longest stall. */
|
|
37
|
+
busyMs: number;
|
|
38
|
+
/** The Hermes heap now and at its peak, in MB; absent without Hermes. */
|
|
39
|
+
heapMb?: number;
|
|
40
|
+
heapPeakMb?: number;
|
|
41
|
+
/** The slowest components, longest first; absent outside a development build or when React gave no timing. */
|
|
42
|
+
renders?: RenderTime[];
|
|
43
|
+
}
|
|
44
|
+
export interface PerfDeps {
|
|
45
|
+
now: () => number;
|
|
46
|
+
requestFrame: (fn: () => void) => unknown;
|
|
47
|
+
cancelFrame: (handle: unknown) => void;
|
|
48
|
+
setInterval: (fn: () => void, ms: number) => unknown;
|
|
49
|
+
clearInterval: (handle: unknown) => void;
|
|
50
|
+
/** The Hermes heap in MB, or null when it can't be read. */
|
|
51
|
+
heapMb: () => number | null;
|
|
52
|
+
/** A development build: React times its renders. */
|
|
53
|
+
dev: boolean;
|
|
54
|
+
onCommitRoot: (listener: (root: unknown) => void) => () => void;
|
|
55
|
+
/** Foreground/background changes ("active", "inactive", "background"); returns the way to stop listening. */
|
|
56
|
+
onAppState: (listener: (state: string) => void) => () => void;
|
|
57
|
+
}
|
|
58
|
+
/** The Hermes heap in MB (live allocated bytes, else the heap's size); null without Hermes. */
|
|
59
|
+
export declare function hermesHeapMb(): number | null;
|
|
60
|
+
/** The numbers of one measurement window. */
|
|
61
|
+
export declare class PerfSampler {
|
|
62
|
+
private readonly deps;
|
|
63
|
+
private running;
|
|
64
|
+
private startedAt;
|
|
65
|
+
private lastFrame;
|
|
66
|
+
private frames;
|
|
67
|
+
private drops;
|
|
68
|
+
private busy;
|
|
69
|
+
/** Frames per one-second slot of the window. */
|
|
70
|
+
private slots;
|
|
71
|
+
private heap;
|
|
72
|
+
private heapPeak;
|
|
73
|
+
private frameHandle;
|
|
74
|
+
private heapTimer;
|
|
75
|
+
private stopCommits;
|
|
76
|
+
private stopAppState;
|
|
77
|
+
/** The app is not in front: requestAnimationFrame is paused, so no frame is due. */
|
|
78
|
+
private away;
|
|
79
|
+
/** The next frame follows a stretch away from the front: its interval is not a stall. */
|
|
80
|
+
private skipGap;
|
|
81
|
+
/** Time spent away from the front so far, and when the current stretch away began: left out of fps and slots. */
|
|
82
|
+
private awayMs;
|
|
83
|
+
private awaySince;
|
|
84
|
+
private readonly renders;
|
|
85
|
+
/** React gave no timing for a render that did work (a build without the profiler). */
|
|
86
|
+
private timingMissing;
|
|
87
|
+
constructor(deps?: Partial<PerfDeps>);
|
|
88
|
+
get active(): boolean;
|
|
89
|
+
start(): void;
|
|
90
|
+
/** requestAnimationFrame stops while the app is in the background: the pause is no frame interval. */
|
|
91
|
+
private onAppState;
|
|
92
|
+
/** Ends the window without a result (the host went away). */
|
|
93
|
+
abort(): void;
|
|
94
|
+
stop(): PerfResult;
|
|
95
|
+
private release;
|
|
96
|
+
private readonly onFrame;
|
|
97
|
+
private sampleHeap;
|
|
98
|
+
/**
|
|
99
|
+
* One commit's renders (development builds): every component that did work in this commit has an
|
|
100
|
+
* `actualDuration` (its time and its children's); its own time is that less what its children took.
|
|
101
|
+
* A subtree that did no work is skipped when React says so (`subtreeFlags`), which keeps this cheap.
|
|
102
|
+
*/
|
|
103
|
+
private onCommit;
|
|
104
|
+
private noteRender;
|
|
105
|
+
}
|
|
106
|
+
/** Ends any measurement without a result: the host is gone, so nobody will ask for it. */
|
|
107
|
+
export declare function stopPerf(): void;
|
|
108
|
+
/**
|
|
109
|
+
* `perfStart`: begins a window and answers its `id`. A window already running is not dropped: the start answers
|
|
110
|
+
* bad_params, so a second call can never reset the first one's numbers (Codex review of 1.3.0). A window nobody stops
|
|
111
|
+
* ends by itself after MAX_WINDOW_MS.
|
|
112
|
+
*/
|
|
113
|
+
export declare function perfStart(): Promise<{
|
|
114
|
+
started: true;
|
|
115
|
+
id: number;
|
|
116
|
+
dev: boolean;
|
|
117
|
+
heap: boolean;
|
|
118
|
+
}>;
|
|
119
|
+
/** `perfStop`: ends the window (`id`, when given, must be the running one) and answers its numbers. */
|
|
120
|
+
export declare function perfStop(params?: unknown): Promise<PerfResult>;
|
package/dist/perf.js
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PerfSampler = exports.MAX_RENDERS = exports.MIN_RENDER_MS = exports.MAX_WINDOW_MS = exports.HEAP_SAMPLE_MS = exports.DROP_MS = void 0;
|
|
4
|
+
exports.hermesHeapMb = hermesHeapMb;
|
|
5
|
+
exports.stopPerf = stopPerf;
|
|
6
|
+
exports.perfStart = perfStart;
|
|
7
|
+
exports.perfStop = perfStop;
|
|
8
|
+
const react_native_1 = require("react-native");
|
|
9
|
+
const fiber_1 = require("./fiber");
|
|
10
|
+
const register_1 = require("./register");
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
/**
|
|
13
|
+
* AGENT-TOOLS §15.3 `performance`, Tapline's side: the JavaScript thread's frames, the Hermes heap and (in a
|
|
14
|
+
* development build) the slowest component renders, measured between `perfStart` and `perfStop`.
|
|
15
|
+
*
|
|
16
|
+
* Frames come from a requestAnimationFrame loop: each callback is one frame, the gap to the one before is the
|
|
17
|
+
* frame interval. A gap over 50 ms is a drop; the longest gap is how long the JS thread was busy at most.
|
|
18
|
+
* This is the JavaScript thread's view, not the screen's: native animations that don't need JS don't show.
|
|
19
|
+
*/
|
|
20
|
+
/** A frame interval longer than this is a drop (§15.3). */
|
|
21
|
+
exports.DROP_MS = 50;
|
|
22
|
+
/** How often the heap is read while measuring. */
|
|
23
|
+
exports.HEAP_SAMPLE_MS = 250;
|
|
24
|
+
/** A measurement nobody stopped (the host went away) ends by itself after this long. */
|
|
25
|
+
exports.MAX_WINDOW_MS = 40_000;
|
|
26
|
+
/** Renders shorter than this don't make the list. */
|
|
27
|
+
exports.MIN_RENDER_MS = 1;
|
|
28
|
+
/** At most this many components are reported. */
|
|
29
|
+
exports.MAX_RENDERS = 5;
|
|
30
|
+
/** Fibers visited per commit at most (a bound on the cost of measuring). */
|
|
31
|
+
const MAX_FIBERS_PER_COMMIT = 20_000;
|
|
32
|
+
/** React's `PerformedWork` flag: this fiber's component rendered in the commit. */
|
|
33
|
+
const PERFORMED_WORK = 1;
|
|
34
|
+
/** The Hermes heap in MB (live allocated bytes, else the heap's size); null without Hermes. */
|
|
35
|
+
function hermesHeapMb() {
|
|
36
|
+
const hermes = globalThis.HermesInternal;
|
|
37
|
+
if (!(0, types_1.isRecord)(hermes) || typeof hermes.getInstrumentedStats !== 'function')
|
|
38
|
+
return null;
|
|
39
|
+
try {
|
|
40
|
+
const read = hermes.getInstrumentedStats;
|
|
41
|
+
const stats = read.call(hermes);
|
|
42
|
+
if (!(0, types_1.isRecord)(stats))
|
|
43
|
+
return null;
|
|
44
|
+
const bytes = typeof stats.js_allocatedBytes === 'number' ? stats.js_allocatedBytes : stats.js_heapSize;
|
|
45
|
+
return typeof bytes === 'number' && Number.isFinite(bytes) ? bytes / (1024 * 1024) : null;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function defaultDeps() {
|
|
52
|
+
const g = globalThis;
|
|
53
|
+
return {
|
|
54
|
+
now: () => Date.now(),
|
|
55
|
+
requestFrame: (fn) => (typeof g.requestAnimationFrame === 'function' ? g.requestAnimationFrame(fn) : setTimeout(fn, 16)),
|
|
56
|
+
cancelFrame: (handle) => {
|
|
57
|
+
if (typeof g.cancelAnimationFrame === 'function')
|
|
58
|
+
g.cancelAnimationFrame(handle);
|
|
59
|
+
else
|
|
60
|
+
clearTimeout(handle);
|
|
61
|
+
},
|
|
62
|
+
setInterval: (fn, ms) => setInterval(fn, ms),
|
|
63
|
+
clearInterval: (handle) => clearInterval(handle),
|
|
64
|
+
heapMb: hermesHeapMb,
|
|
65
|
+
dev: typeof __DEV__ !== 'undefined' && __DEV__,
|
|
66
|
+
onCommitRoot: register_1.onCommitRoot,
|
|
67
|
+
onAppState: (listener) => {
|
|
68
|
+
try {
|
|
69
|
+
const source = react_native_1.AppState;
|
|
70
|
+
const subscription = typeof source.addEventListener === 'function' ? source.addEventListener('change', listener) : undefined;
|
|
71
|
+
return () => {
|
|
72
|
+
try {
|
|
73
|
+
subscription?.remove?.();
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// ignore
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return () => undefined;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const round1 = (value) => Math.round(value * 10) / 10;
|
|
87
|
+
/** The numbers of one measurement window. */
|
|
88
|
+
class PerfSampler {
|
|
89
|
+
deps;
|
|
90
|
+
running = false;
|
|
91
|
+
startedAt = 0;
|
|
92
|
+
lastFrame = 0;
|
|
93
|
+
frames = 0;
|
|
94
|
+
drops = 0;
|
|
95
|
+
busy = 0;
|
|
96
|
+
/** Frames per one-second slot of the window. */
|
|
97
|
+
slots = [];
|
|
98
|
+
heap = null;
|
|
99
|
+
heapPeak = null;
|
|
100
|
+
frameHandle = null;
|
|
101
|
+
heapTimer = null;
|
|
102
|
+
stopCommits = null;
|
|
103
|
+
stopAppState = null;
|
|
104
|
+
/** The app is not in front: requestAnimationFrame is paused, so no frame is due. */
|
|
105
|
+
away = false;
|
|
106
|
+
/** The next frame follows a stretch away from the front: its interval is not a stall. */
|
|
107
|
+
skipGap = false;
|
|
108
|
+
/** Time spent away from the front so far, and when the current stretch away began: left out of fps and slots. */
|
|
109
|
+
awayMs = 0;
|
|
110
|
+
awaySince = 0;
|
|
111
|
+
renders = new Map();
|
|
112
|
+
/** React gave no timing for a render that did work (a build without the profiler). */
|
|
113
|
+
timingMissing = false;
|
|
114
|
+
constructor(deps = {}) {
|
|
115
|
+
this.deps = { ...defaultDeps(), ...deps };
|
|
116
|
+
}
|
|
117
|
+
get active() {
|
|
118
|
+
return this.running;
|
|
119
|
+
}
|
|
120
|
+
start() {
|
|
121
|
+
if (this.running)
|
|
122
|
+
return;
|
|
123
|
+
this.running = true;
|
|
124
|
+
const { deps } = this;
|
|
125
|
+
this.startedAt = deps.now();
|
|
126
|
+
this.lastFrame = this.startedAt;
|
|
127
|
+
this.sampleHeap();
|
|
128
|
+
this.frameHandle = deps.requestFrame(this.onFrame);
|
|
129
|
+
this.heapTimer = deps.setInterval(() => this.sampleHeap(), exports.HEAP_SAMPLE_MS);
|
|
130
|
+
if (deps.dev)
|
|
131
|
+
this.stopCommits = deps.onCommitRoot((root) => this.onCommit(root));
|
|
132
|
+
this.away = false;
|
|
133
|
+
this.skipGap = false;
|
|
134
|
+
this.awayMs = 0;
|
|
135
|
+
this.awaySince = 0;
|
|
136
|
+
this.stopAppState = deps.onAppState((state) => this.onAppState(state));
|
|
137
|
+
}
|
|
138
|
+
/** requestAnimationFrame stops while the app is in the background: the pause is no frame interval. */
|
|
139
|
+
onAppState(state) {
|
|
140
|
+
if (!this.running)
|
|
141
|
+
return;
|
|
142
|
+
const now = this.deps.now();
|
|
143
|
+
if (state === 'active') {
|
|
144
|
+
if (this.away)
|
|
145
|
+
this.awayMs += now - this.awaySince;
|
|
146
|
+
this.away = false;
|
|
147
|
+
// The next frame measures from coming back: a late first frame after that is a stall like any other.
|
|
148
|
+
this.lastFrame = now;
|
|
149
|
+
this.skipGap = false;
|
|
150
|
+
}
|
|
151
|
+
else if (!this.away) {
|
|
152
|
+
this.away = true;
|
|
153
|
+
this.awaySince = now;
|
|
154
|
+
this.skipGap = true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/** Ends the window without a result (the host went away). */
|
|
158
|
+
abort() {
|
|
159
|
+
if (!this.running)
|
|
160
|
+
return;
|
|
161
|
+
this.running = false;
|
|
162
|
+
this.release();
|
|
163
|
+
}
|
|
164
|
+
stop() {
|
|
165
|
+
if (!this.running)
|
|
166
|
+
throw new types_1.TaplineError('bad_params', 'no performance measurement is running; start one first');
|
|
167
|
+
const end = this.deps.now();
|
|
168
|
+
this.sampleHeap();
|
|
169
|
+
this.running = false;
|
|
170
|
+
this.release();
|
|
171
|
+
// A stall that is still going on counts: no frame has ended it yet, so it lasted at least this long.
|
|
172
|
+
const tail = this.away ? 0 : end - this.lastFrame;
|
|
173
|
+
if (tail > exports.DROP_MS) {
|
|
174
|
+
this.drops += 1;
|
|
175
|
+
if (tail > this.busy)
|
|
176
|
+
this.busy = tail;
|
|
177
|
+
}
|
|
178
|
+
// Only the time the app was in front counts (a background stretch has no frames to show).
|
|
179
|
+
const awayTotal = this.awayMs + (this.away ? end - this.awaySince : 0);
|
|
180
|
+
const elapsedMs = Math.max(1, end - this.startedAt - awayTotal);
|
|
181
|
+
const fps = this.frames / (elapsedMs / 1000);
|
|
182
|
+
const whole = Math.floor(elapsedMs / 1000);
|
|
183
|
+
let lowest = fps;
|
|
184
|
+
if (whole > 0) {
|
|
185
|
+
lowest = Infinity;
|
|
186
|
+
for (let i = 0; i < whole; i++)
|
|
187
|
+
lowest = Math.min(lowest, this.slots[i] ?? 0);
|
|
188
|
+
}
|
|
189
|
+
const result = {
|
|
190
|
+
seconds: round1(elapsedMs / 1000),
|
|
191
|
+
frames: this.frames,
|
|
192
|
+
fps: round1(fps),
|
|
193
|
+
fpsLowest: round1(lowest),
|
|
194
|
+
drops: this.drops,
|
|
195
|
+
busyMs: Math.round(this.busy),
|
|
196
|
+
};
|
|
197
|
+
if (this.heap !== null && this.heapPeak !== null) {
|
|
198
|
+
result.heapMb = round1(this.heap);
|
|
199
|
+
result.heapPeakMb = round1(this.heapPeak);
|
|
200
|
+
}
|
|
201
|
+
if (this.deps.dev && !this.timingMissing) {
|
|
202
|
+
result.renders = [...this.renders.entries()]
|
|
203
|
+
.map(([name, r]) => ({ name, ms: round1(r.ms), count: r.count }))
|
|
204
|
+
.filter((r) => r.ms >= exports.MIN_RENDER_MS)
|
|
205
|
+
.sort((a, b) => b.ms - a.ms)
|
|
206
|
+
.slice(0, exports.MAX_RENDERS);
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
release() {
|
|
211
|
+
if (this.frameHandle !== null)
|
|
212
|
+
this.deps.cancelFrame(this.frameHandle);
|
|
213
|
+
if (this.heapTimer !== null)
|
|
214
|
+
this.deps.clearInterval(this.heapTimer);
|
|
215
|
+
this.frameHandle = null;
|
|
216
|
+
this.heapTimer = null;
|
|
217
|
+
const stopCommits = this.stopCommits;
|
|
218
|
+
this.stopCommits = null;
|
|
219
|
+
if (stopCommits !== null)
|
|
220
|
+
stopCommits();
|
|
221
|
+
const stopAppState = this.stopAppState;
|
|
222
|
+
this.stopAppState = null;
|
|
223
|
+
if (stopAppState !== null)
|
|
224
|
+
stopAppState();
|
|
225
|
+
}
|
|
226
|
+
onFrame = () => {
|
|
227
|
+
if (!this.running)
|
|
228
|
+
return;
|
|
229
|
+
// A callback while the app is away (inactive) is no frame a person saw: it is not counted (Codex re-review 3).
|
|
230
|
+
if (this.away) {
|
|
231
|
+
this.frameHandle = this.deps.requestFrame(this.onFrame);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const t = this.deps.now();
|
|
235
|
+
// The first frame after the app was away: its interval spans the pause, so it is not counted.
|
|
236
|
+
const gap = this.skipGap ? 0 : t - this.lastFrame;
|
|
237
|
+
this.skipGap = false;
|
|
238
|
+
this.lastFrame = t;
|
|
239
|
+
this.frames += 1;
|
|
240
|
+
if (gap > exports.DROP_MS)
|
|
241
|
+
this.drops += 1;
|
|
242
|
+
if (gap > this.busy)
|
|
243
|
+
this.busy = gap;
|
|
244
|
+
const slot = Math.floor((t - this.startedAt - this.awayMs) / 1000);
|
|
245
|
+
this.slots[slot] = (this.slots[slot] ?? 0) + 1;
|
|
246
|
+
this.frameHandle = this.deps.requestFrame(this.onFrame);
|
|
247
|
+
};
|
|
248
|
+
sampleHeap() {
|
|
249
|
+
const mb = this.deps.heapMb();
|
|
250
|
+
if (mb === null)
|
|
251
|
+
return;
|
|
252
|
+
this.heap = mb;
|
|
253
|
+
if (this.heapPeak === null || mb > this.heapPeak)
|
|
254
|
+
this.heapPeak = mb;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* One commit's renders (development builds): every component that did work in this commit has an
|
|
258
|
+
* `actualDuration` (its time and its children's); its own time is that less what its children took.
|
|
259
|
+
* A subtree that did no work is skipped when React says so (`subtreeFlags`), which keeps this cheap.
|
|
260
|
+
*/
|
|
261
|
+
onCommit(root) {
|
|
262
|
+
if (!(0, types_1.isRecord)(root) || !(0, fiber_1.isFiber)(root.current))
|
|
263
|
+
return;
|
|
264
|
+
const stack = [root.current];
|
|
265
|
+
let visited = 0;
|
|
266
|
+
while (stack.length > 0 && visited < MAX_FIBERS_PER_COMMIT) {
|
|
267
|
+
const fiber = stack.pop();
|
|
268
|
+
visited += 1;
|
|
269
|
+
const raw = fiber;
|
|
270
|
+
const flags = typeof raw.flags === 'number' ? raw.flags : 0;
|
|
271
|
+
if ((0, fiber_1.isCompositeTag)(fiber.tag) && (flags & PERFORMED_WORK) !== 0)
|
|
272
|
+
this.noteRender(fiber);
|
|
273
|
+
const subtree = raw.subtreeFlags;
|
|
274
|
+
if (typeof subtree === 'number' && (subtree & PERFORMED_WORK) === 0)
|
|
275
|
+
continue;
|
|
276
|
+
for (let child = fiber.child; child; child = child.sibling)
|
|
277
|
+
stack.push(child);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
noteRender(fiber) {
|
|
281
|
+
const own = actualDuration(fiber);
|
|
282
|
+
if (own === null) {
|
|
283
|
+
this.timingMissing = true;
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
let children = 0;
|
|
287
|
+
for (let child = fiber.child; child; child = child.sibling) {
|
|
288
|
+
const flags = child.flags;
|
|
289
|
+
const worked = !(0, fiber_1.isCompositeTag)(child.tag) || (typeof flags === 'number' && (flags & PERFORMED_WORK) !== 0);
|
|
290
|
+
const d = worked ? actualDuration(child) : null;
|
|
291
|
+
if (d !== null)
|
|
292
|
+
children += d;
|
|
293
|
+
}
|
|
294
|
+
const name = (0, fiber_1.fiberName)(fiber);
|
|
295
|
+
if (name === null)
|
|
296
|
+
return;
|
|
297
|
+
const ms = Math.max(0, own - children);
|
|
298
|
+
const seen = this.renders.get(name);
|
|
299
|
+
if (seen === undefined)
|
|
300
|
+
this.renders.set(name, { ms, count: 1 });
|
|
301
|
+
else {
|
|
302
|
+
seen.count += 1;
|
|
303
|
+
if (ms > seen.ms)
|
|
304
|
+
seen.ms = ms;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
exports.PerfSampler = PerfSampler;
|
|
309
|
+
function actualDuration(fiber) {
|
|
310
|
+
const d = fiber.actualDuration;
|
|
311
|
+
return typeof d === 'number' && Number.isFinite(d) ? d : null;
|
|
312
|
+
}
|
|
313
|
+
/* -------------------------------------------------------------------------- */
|
|
314
|
+
/* The one measurement the host runs */
|
|
315
|
+
/* -------------------------------------------------------------------------- */
|
|
316
|
+
let current = null;
|
|
317
|
+
let guard = null;
|
|
318
|
+
/** The running window's number: a stop names the window it ends, so two calls never take each other's numbers. */
|
|
319
|
+
let currentId = 0;
|
|
320
|
+
let nextId = 1;
|
|
321
|
+
/** Ends any measurement without a result: the host is gone, so nobody will ask for it. */
|
|
322
|
+
function stopPerf() {
|
|
323
|
+
if (guard !== null)
|
|
324
|
+
clearTimeout(guard);
|
|
325
|
+
guard = null;
|
|
326
|
+
const sampler = current;
|
|
327
|
+
current = null;
|
|
328
|
+
currentId = 0;
|
|
329
|
+
if (sampler !== null)
|
|
330
|
+
sampler.abort();
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* `perfStart`: begins a window and answers its `id`. A window already running is not dropped: the start answers
|
|
334
|
+
* bad_params, so a second call can never reset the first one's numbers (Codex review of 1.3.0). A window nobody stops
|
|
335
|
+
* ends by itself after MAX_WINDOW_MS.
|
|
336
|
+
*/
|
|
337
|
+
async function perfStart() {
|
|
338
|
+
if (current !== null && current.active) {
|
|
339
|
+
throw new types_1.TaplineError('bad_params', 'a performance measurement is already running; wait for it to end');
|
|
340
|
+
}
|
|
341
|
+
stopPerf();
|
|
342
|
+
const sampler = new PerfSampler();
|
|
343
|
+
current = sampler;
|
|
344
|
+
currentId = nextId++;
|
|
345
|
+
sampler.start();
|
|
346
|
+
guard = setTimeout(stopPerf, exports.MAX_WINDOW_MS);
|
|
347
|
+
return { started: true, id: currentId, dev: typeof __DEV__ !== 'undefined' && __DEV__, heap: hermesHeapMb() !== null };
|
|
348
|
+
}
|
|
349
|
+
/** `perfStop`: ends the window (`id`, when given, must be the running one) and answers its numbers. */
|
|
350
|
+
async function perfStop(params) {
|
|
351
|
+
const sampler = current;
|
|
352
|
+
if (sampler === null || !sampler.active) {
|
|
353
|
+
throw new types_1.TaplineError('bad_params', 'no performance measurement is running; start one first');
|
|
354
|
+
}
|
|
355
|
+
const id = typeof params === 'object' && params !== null ? params.id : undefined;
|
|
356
|
+
if (id !== undefined && id !== currentId) {
|
|
357
|
+
throw new types_1.TaplineError('bad_params', 'that performance measurement is not the one running');
|
|
358
|
+
}
|
|
359
|
+
if (guard !== null)
|
|
360
|
+
clearTimeout(guard);
|
|
361
|
+
guard = null;
|
|
362
|
+
current = null;
|
|
363
|
+
currentId = 0;
|
|
364
|
+
return sampler.stop();
|
|
365
|
+
}
|
|
366
|
+
//# sourceMappingURL=perf.js.map
|
package/dist/perf.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perf.js","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":";;;AAwEA,oCAYC;AAwQD,4BAOC;AAOD,8BAWC;AAGD,4BAcC;AAtYD,+CAAwC;AACxC,mCAAyE;AACzE,yCAA0C;AAC1C,mCAAiD;AAEjD;;;;;;;GAOG;AAEH,2DAA2D;AAC9C,QAAA,OAAO,GAAG,EAAE,CAAC;AAC1B,kDAAkD;AACrC,QAAA,cAAc,GAAG,GAAG,CAAC;AAClC,wFAAwF;AAC3E,QAAA,aAAa,GAAG,MAAM,CAAC;AACpC,qDAAqD;AACxC,QAAA,aAAa,GAAG,CAAC,CAAC;AAC/B,iDAAiD;AACpC,QAAA,WAAW,GAAG,CAAC,CAAC;AAC7B,4EAA4E;AAC5E,MAAM,qBAAqB,GAAG,MAAM,CAAC;AACrC,mFAAmF;AACnF,MAAM,cAAc,GAAG,CAAC,CAAC;AA4CzB,+FAA+F;AAC/F,SAAgB,YAAY;IAC1B,MAAM,MAAM,GAAI,UAA2C,CAAC,cAAc,CAAC;IAC3E,IAAI,CAAC,IAAA,gBAAQ,EAAC,MAAM,CAAC,IAAI,OAAO,MAAM,CAAC,oBAAoB,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC;IACxF,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,CAAC,oBAAqC,CAAC;QAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;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;IACf,SAAS,GAAG,CAAC,CAAC;IACd,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;AACxB,CAAC"}
|
package/dist/register.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ import { type Fiber, type FiberRootLike } from './fiber';
|
|
|
12
12
|
export declare function commitRevision(): number;
|
|
13
13
|
/** Called after every React commit with the new revision; returns a function that stops it. */
|
|
14
14
|
export declare function onCommit(listener: (revision: number) => void): () => void;
|
|
15
|
+
/**
|
|
16
|
+
* Called with the committed root after every React commit (before `onCommit` listeners); returns a
|
|
17
|
+
* function that stops it. Only the performance sampler uses it, and only while it measures.
|
|
18
|
+
*/
|
|
19
|
+
export declare function onCommitRoot(listener: (root: unknown) => void): () => void;
|
|
15
20
|
/**
|
|
16
21
|
* Install (or wrap) the hook on `target` (default: globalThis). Idempotent per
|
|
17
22
|
* hook object. Returns the hook in effect.
|
package/dist/register.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.commitRevision = commitRevision;
|
|
4
4
|
exports.onCommit = onCommit;
|
|
5
|
+
exports.onCommitRoot = onCommitRoot;
|
|
5
6
|
exports.installHook = installHook;
|
|
6
7
|
exports.getRoots = getRoots;
|
|
7
8
|
exports.resetRegistry = resetRegistry;
|
|
@@ -39,6 +40,17 @@ function onCommit(listener) {
|
|
|
39
40
|
commitListeners.delete(listener);
|
|
40
41
|
};
|
|
41
42
|
}
|
|
43
|
+
const rootListeners = new Set();
|
|
44
|
+
/**
|
|
45
|
+
* Called with the committed root after every React commit (before `onCommit` listeners); returns a
|
|
46
|
+
* function that stops it. Only the performance sampler uses it, and only while it measures.
|
|
47
|
+
*/
|
|
48
|
+
function onCommitRoot(listener) {
|
|
49
|
+
rootListeners.add(listener);
|
|
50
|
+
return () => {
|
|
51
|
+
rootListeners.delete(listener);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
42
54
|
function record(rendererId, root) {
|
|
43
55
|
if (!(0, fiber_1.isFiberRoot)(root))
|
|
44
56
|
return;
|
|
@@ -142,6 +154,8 @@ function installHook(target = globalThis) {
|
|
|
142
154
|
}
|
|
143
155
|
wrap(hook, 'onCommitFiberRoot', (args) => {
|
|
144
156
|
record(numberArg(args[0]), args[1]);
|
|
157
|
+
for (const listener of rootListeners)
|
|
158
|
+
safely(() => listener(args[1]));
|
|
145
159
|
committed();
|
|
146
160
|
});
|
|
147
161
|
wrap(hook, 'onCommitFiberUnmount', (args) => forgetByFiber(args[1]));
|
package/dist/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":";;AA4CA,wCAEC;AAGD,4BAKC;AA+ED,
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":";;AA4CA,wCAEC;AAGD,4BAKC;AAQD,oCAKC;AA+ED,kCAiCC;AAGD,4BAiBC;AAGD,sCAGC;AA7MD;;;;;;;;GAQG;AACH,mCAAyF;AACzF,mCAAmC;AAkBnC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAElD,sDAAsD;AACtD,MAAM,eAAe,GAAG,IAAI,GAAG,EAA8B,CAAC;AAC9D,IAAI,aAAa,GAAoB,IAAI,CAAC;AAE1C,wFAAwF;AACxF,IAAI,QAAQ,GAAG,CAAC,CAAC;AACjB,MAAM,eAAe,GAAG,IAAI,GAAG,EAA8B,CAAC;AAE9D,SAAS,SAAS;IAChB,QAAQ,IAAI,CAAC,CAAC;IACd,KAAK,MAAM,QAAQ,IAAI,eAAe;QAAE,MAAM,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,uFAAuF;AACvF,SAAgB,cAAc;IAC5B,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,+FAA+F;AAC/F,SAAgB,QAAQ,C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,KAAK;wBAAE,IAAI,IAAA,mBAAW,EAAC,IAAI,CAAC;4BAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACnE,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;AAClE,CAAC;AAED,wEAAwE;AACxE,SAAgB,aAAa;IAC3B,eAAe,CAAC,KAAK,EAAE,CAAC;IACxB,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC;AAID,WAAW,EAAE,CAAC"}
|
package/dist/source.d.ts
CHANGED
|
@@ -47,6 +47,11 @@ type FetchLike = (url: string, init: {
|
|
|
47
47
|
export declare function setSourceFetch(next: FetchLike | null): void;
|
|
48
48
|
/** The stack React captured where this fiber's element was created, as frames; empty when there is none. */
|
|
49
49
|
export declare function framesOf(fiber: Fiber): Frame[];
|
|
50
|
+
/**
|
|
51
|
+
* A stack (as Hermes or V8 print it) with each frame Metro can map rewritten to the app's file and line.
|
|
52
|
+
* Frames Metro can't map, and lines that aren't frames, stay as they were. Development builds only.
|
|
53
|
+
*/
|
|
54
|
+
export declare function symbolicateStack(stack: string): Promise<string>;
|
|
50
55
|
/** A file of the app's own code (not a library, not React's internals). */
|
|
51
56
|
export declare function isAppFile(file: string): boolean;
|
|
52
57
|
/**
|
package/dist/source.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setSourceFetch = setSourceFetch;
|
|
4
4
|
exports.framesOf = framesOf;
|
|
5
|
+
exports.symbolicateStack = symbolicateStack;
|
|
5
6
|
exports.isAppFile = isAppFile;
|
|
6
7
|
exports.sourcesOf = sourcesOf;
|
|
7
8
|
exports.clearSourceCache = clearSourceCache;
|
|
@@ -77,6 +78,32 @@ async function symbolicate(frames) {
|
|
|
77
78
|
}
|
|
78
79
|
return frames.map((f) => cache.get(keyOf(f)) ?? null);
|
|
79
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* A stack (as Hermes or V8 print it) with each frame Metro can map rewritten to the app's file and line.
|
|
83
|
+
* Frames Metro can't map, and lines that aren't frames, stay as they were. Development builds only.
|
|
84
|
+
*/
|
|
85
|
+
async function symbolicateStack(stack) {
|
|
86
|
+
const lines = stack.split('\n');
|
|
87
|
+
const frames = [];
|
|
88
|
+
const at = [];
|
|
89
|
+
lines.forEach((line, i) => {
|
|
90
|
+
const m = /^\s*at\s+(?:(.*?)\s+\()?(.+?):(\d+):(\d+)\)?\s*$/.exec(line);
|
|
91
|
+
if (!m)
|
|
92
|
+
return;
|
|
93
|
+
frames.push({ methodName: m[1] ?? '', file: m[2].replace(/^address at\s+/, ''), lineNumber: Number(m[3]), column: Number(m[4]) });
|
|
94
|
+
at.push(i);
|
|
95
|
+
});
|
|
96
|
+
if (frames.length === 0)
|
|
97
|
+
return stack;
|
|
98
|
+
const mapped = await symbolicate(frames);
|
|
99
|
+
mapped.forEach((frame, k) => {
|
|
100
|
+
if (frame === null)
|
|
101
|
+
return;
|
|
102
|
+
const name = frame.methodName !== '' ? frame.methodName : frames[k].methodName;
|
|
103
|
+
lines[at[k]] = ` at ${name !== '' ? `${name} (` : ''}${frame.file}:${frame.lineNumber}:${frame.column}${name !== '' ? ')' : ''}`;
|
|
104
|
+
});
|
|
105
|
+
return lines.join('\n');
|
|
106
|
+
}
|
|
80
107
|
/** A file of the app's own code (not a library, not React's internals). */
|
|
81
108
|
function isAppFile(file) {
|
|
82
109
|
return !/[\\/]node_modules[\\/]/.test(file) && !/^https?:/.test(file) && !/^\[native code\]$/.test(file);
|