@goliapkg/sentori-react-native 0.9.4 → 0.9.6
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/lib/control-channel.d.ts.map +1 -1
- package/lib/control-channel.js +8 -1
- package/lib/control-channel.js.map +1 -1
- package/lib/mobile-vitals.d.ts.map +1 -1
- package/lib/mobile-vitals.js +2 -7
- package/lib/mobile-vitals.js.map +1 -1
- package/lib/replay.d.ts.map +1 -1
- package/lib/replay.js +15 -4
- package/lib/replay.js.map +1 -1
- package/lib/sample-profiler.d.ts +9 -0
- package/lib/sample-profiler.d.ts.map +1 -1
- package/lib/sample-profiler.js +26 -3
- package/lib/sample-profiler.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/control-channel.test.ts +111 -0
- package/src/__tests__/long-task-monitor.test.ts +59 -0
- package/src/__tests__/sample-profiler.test.ts +59 -0
- package/src/control-channel.ts +9 -1
- package/src/mobile-vitals.ts +2 -8
- package/src/replay.ts +17 -4
- package/src/sample-profiler.ts +29 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-channel.d.ts","sourceRoot":"","sources":["../src/control-channel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"control-channel.d.ts","sourceRoot":"","sources":["../src/control-channel.ts"],"names":[],"mappings":"AAiCA,wBAAgB,UAAU,IAAI,OAAO,CAQpC;AAED,wBAAgB,mBAAmB,IAAI,IAAI,CAS1C;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAOzC;AAiCD,iBAAiB;AACjB,wBAAgB,6BAA6B,IAAI,IAAI,CAEpD"}
|
package/lib/control-channel.js
CHANGED
|
@@ -16,6 +16,13 @@
|
|
|
16
16
|
import { getConfig } from './config';
|
|
17
17
|
import { getCurrentUserId } from './capture';
|
|
18
18
|
const POLL_INTERVAL_MS = 30_000;
|
|
19
|
+
/** Cap on the live-mode window even if the server reports a longer
|
|
20
|
+
* TTL. Defense-in-depth: an unbounded `ttlMs` (server bug, clock
|
|
21
|
+
* skew, malicious server) would otherwise pin the SDK into flush-
|
|
22
|
+
* every-event mode indefinitely, which is expensive on slow
|
|
23
|
+
* networks. 15 min matches the dashboard's default arm length so
|
|
24
|
+
* normal operation stays uncapped. */
|
|
25
|
+
const MAX_LIVE_MODE_TTL_MS = 15 * 60_000;
|
|
19
26
|
let _liveMode = false;
|
|
20
27
|
let _liveModeUntil = 0;
|
|
21
28
|
let _timer = null;
|
|
@@ -70,7 +77,7 @@ async function pollOnce() {
|
|
|
70
77
|
const body = (await resp.json());
|
|
71
78
|
if (body.liveMode === true) {
|
|
72
79
|
_liveMode = true;
|
|
73
|
-
_liveModeUntil = Date.now() + Math.max(0, Math.min(body.ttlMs ?? 0,
|
|
80
|
+
_liveModeUntil = Date.now() + Math.max(0, Math.min(body.ttlMs ?? 0, MAX_LIVE_MODE_TTL_MS));
|
|
74
81
|
}
|
|
75
82
|
else {
|
|
76
83
|
_liveMode = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-channel.js","sourceRoot":"","sources":["../src/control-channel.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,EAAE;AACF,mEAAmE;AACnE,qEAAqE;AACrE,mEAAmE;AACnE,iEAAiE;AACjE,+DAA+D;AAC/D,cAAc;AACd,EAAE;AACF,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,+DAA+D;AAC/D,oEAAoE;AACpE,gDAAgD;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,IAAI,SAAS,GAAG,KAAK,CAAC;AACtB,IAAI,cAAc,GAAG,CAAC,CAAC;AACvB,IAAI,MAAM,GAA0C,IAAI,CAAC;AAEzD,MAAM,UAAU,UAAU;IACxB,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IA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AE,CAAC;YAC3B,SAAS,GAAG,IAAI,CAAC;YACjB,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC;QAC7F,CAAC;aAAM,CAAC;YACN,SAAS,GAAG,KAAK,CAAC;YAClB,cAAc,GAAG,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,gEAAgE;QAChE,4CAA4C;IAC9C,CAAC;AACH,CAAC;AAED,iBAAiB;AACjB,MAAM,UAAU,6BAA6B;IAC3C,kBAAkB,EAAE,CAAC;AACvB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mobile-vitals.d.ts","sourceRoot":"","sources":["../src/mobile-vitals.ts"],"names":[],"mappings":"AA6BA;kEACkE;AAClE,wBAAgB,cAAc,IAAI,IAAI,GAAG,MAAM,CAS9C;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,GAAG,IAAI,CAAA;KAAE,KAAK,IAAI,CAAC;IAChE,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAOF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,uBAAuB,CAqB5E;AAED;;;cAGc;AACd,wBAAgB,gBAAgB,IAAI,IAAI,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"mobile-vitals.d.ts","sourceRoot":"","sources":["../src/mobile-vitals.ts"],"names":[],"mappings":"AA6BA;kEACkE;AAClE,wBAAgB,cAAc,IAAI,IAAI,GAAG,MAAM,CAS9C;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,GAAG,IAAI,CAAA;KAAE,KAAK,IAAI,CAAC;IAChE,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AAOF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,uBAAuB,CAqB5E;AAED;;;cAGc;AACd,wBAAgB,gBAAgB,IAAI,IAAI,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAM1E;AAED,iBAAiB;AACjB,wBAAgB,2BAA2B,IAAI,IAAI,CAKlD"}
|
package/lib/mobile-vitals.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
// pieces ship as a separate native module method `getColdStartMs`
|
|
21
21
|
// + `getFrameCounts()` — graceful no-op if not linked.
|
|
22
22
|
import { startSpan } from '@goliapkg/sentori-core';
|
|
23
|
-
import { getNativeColdStartMs } from './native';
|
|
23
|
+
import { getNativeColdStartMs, getNativeFrameCounters } from './native';
|
|
24
24
|
let _coldStartMs = null;
|
|
25
25
|
let _coldStartCaptured = false;
|
|
26
26
|
/** Read the native-side cold start measurement once. Cached. Returns
|
|
@@ -67,12 +67,7 @@ export function markTimeToFullDisplay(route) {
|
|
|
67
67
|
* linked. */
|
|
68
68
|
export function getFrameCounters() {
|
|
69
69
|
try {
|
|
70
|
-
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
72
|
-
const nativeMod = require('./native');
|
|
73
|
-
if (typeof nativeMod.getNativeFrameCounters !== 'function')
|
|
74
|
-
return null;
|
|
75
|
-
return nativeMod.getNativeFrameCounters();
|
|
70
|
+
return getNativeFrameCounters();
|
|
76
71
|
}
|
|
77
72
|
catch {
|
|
78
73
|
return null;
|
package/lib/mobile-vitals.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mobile-vitals.js","sourceRoot":"","sources":["../src/mobile-vitals.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,EAAE;AACF,2DAA2D;AAC3D,EAAE;AACF,0DAA0D;AAC1D,oEAAoE;AACpE,kEAAkE;AAClE,wDAAwD;AACxD,oDAAoD;AACpD,mEAAmE;AACnE,wCAAwC;AACxC,sDAAsD;AACtD,oEAAoE;AACpE,uBAAuB;AACvB,oEAAoE;AACpE,iEAAiE;AACjE,YAAY;AACZ,EAAE;AACF,gEAAgE;AAChE,kEAAkE;AAClE,uDAAuD;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"mobile-vitals.js","sourceRoot":"","sources":["../src/mobile-vitals.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,EAAE;AACF,2DAA2D;AAC3D,EAAE;AACF,0DAA0D;AAC1D,oEAAoE;AACpE,kEAAkE;AAClE,wDAAwD;AACxD,oDAAoD;AACpD,mEAAmE;AACnE,wCAAwC;AACxC,sDAAsD;AACtD,oEAAoE;AACpE,uBAAuB;AACvB,oEAAoE;AACpE,iEAAiE;AACjE,YAAY;AACZ,EAAE;AACF,gEAAgE;AAChE,kEAAkE;AAClE,uDAAuD;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAExE,IAAI,YAAY,GAAkB,IAAI,CAAC;AACvC,IAAI,kBAAkB,GAAG,KAAK,CAAC;AAE/B;kEACkE;AAClE,MAAM,UAAU,cAAc;IAC5B,IAAI,kBAAkB;QAAE,OAAO,YAAY,CAAC;IAC5C,kBAAkB,GAAG,IAAI,CAAC;IAC1B,IAAI,CAAC;QACH,YAAY,GAAG,oBAAoB,EAAE,CAAC;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B;IACzC,IAAI,WAAW;QAAE,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACjD,WAAW,GAAG,IAAI,CAAC;IACnB,kBAAkB,GAAG,KAAK,CAAC;IAC3B,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC"}
|
package/lib/replay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../src/replay.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../src/replay.ts"],"names":[],"mappings":"AA4CA,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,EAAE,KAAK,GAAG,WAAW,CAAC;IAC3B,mCAAmC;IACnC,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CAkBrD;AAED,wBAAgB,UAAU,IAAI,IAAI,CAOjC;AA6CD;;2BAE2B;AAC3B,wBAAgB,WAAW,IAAI,MAAM,CAKpC;AAED,wBAAgB,qBAAqB,IAAI,IAAI,CAG5C"}
|
package/lib/replay.js
CHANGED
|
@@ -21,9 +21,20 @@ import { getRegisteredMaskQuery } from './mask';
|
|
|
21
21
|
import { isNativeModuleLinked } from './native-loader';
|
|
22
22
|
const TICK_INTERVAL_MS = 1000;
|
|
23
23
|
const RING_SIZE = 60;
|
|
24
|
+
/** Floor on tick period. < 250 ms (4 Hz) the native view-tree walk
|
|
25
|
+
* dominates the JS thread on mid-tier Android, especially with mask
|
|
26
|
+
* consultation. The default is 1 Hz; the option exists for
|
|
27
|
+
* benchmarking, not for production. */
|
|
28
|
+
const MIN_TICK_PERIOD_MS = 250;
|
|
24
29
|
let _ring = [];
|
|
25
30
|
let _timer = null;
|
|
26
31
|
let _running = false;
|
|
32
|
+
/** Native module ref, resolved once on first start. Caching here
|
|
33
|
+
* avoids the cost of `requireNativeModule('Sentori')` on every
|
|
34
|
+
* capture tick (Metro's require cache makes this cheap, but the
|
|
35
|
+
* per-tick string lookup and possible throw still cost more than
|
|
36
|
+
* reading a closed-over variable). */
|
|
37
|
+
let _nativeMod = null;
|
|
27
38
|
export function startReplay(opts) {
|
|
28
39
|
if (_running)
|
|
29
40
|
return;
|
|
@@ -38,7 +49,8 @@ export function startReplay(opts) {
|
|
|
38
49
|
return;
|
|
39
50
|
}
|
|
40
51
|
_running = true;
|
|
41
|
-
|
|
52
|
+
_nativeMod = loadNativeReplay();
|
|
53
|
+
const period = Math.max(MIN_TICK_PERIOD_MS, Math.floor(TICK_INTERVAL_MS / (opts.hz ?? 1)));
|
|
42
54
|
_timer = setInterval(() => {
|
|
43
55
|
captureTick();
|
|
44
56
|
}, period);
|
|
@@ -50,6 +62,7 @@ export function stopReplay() {
|
|
|
50
62
|
clearInterval(_timer);
|
|
51
63
|
_timer = null;
|
|
52
64
|
}
|
|
65
|
+
_nativeMod = null;
|
|
53
66
|
}
|
|
54
67
|
function captureTick() {
|
|
55
68
|
if (!_running)
|
|
@@ -57,9 +70,7 @@ function captureTick() {
|
|
|
57
70
|
const tickSpan = startSpan('sentori.replay.tick', { name: 'tick' });
|
|
58
71
|
try {
|
|
59
72
|
const maskIds = readMaskIds();
|
|
60
|
-
|
|
61
|
-
const nativeMod = loadNativeReplay();
|
|
62
|
-
const snapshot = nativeMod?.captureWireframe?.(maskIds);
|
|
73
|
+
const snapshot = _nativeMod?.captureWireframe?.(maskIds);
|
|
63
74
|
if (typeof snapshot === 'string' && snapshot.length > 0) {
|
|
64
75
|
_ring.push(snapshot);
|
|
65
76
|
while (_ring.length > RING_SIZE)
|
package/lib/replay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replay.js","sourceRoot":"","sources":["../src/replay.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,EAAE;AACF,mEAAmE;AACnE,mEAAmE;AACnE,kEAAkE;AAClE,kEAAkE;AAClE,4DA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AG,EAAE,CAAC;IACX,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,qBAAqB;IACnC,UAAU,EAAE,CAAC;IACb,KAAK,GAAG,EAAE,CAAC;AACb,CAAC"}
|
package/lib/sample-profiler.d.ts
CHANGED
|
@@ -6,6 +6,15 @@ export type SampleProfilerOptions = {
|
|
|
6
6
|
/** Flush window ms. Default 60 000 (one minute). */
|
|
7
7
|
flushMs?: number;
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Start the idle-tick sample profiler. Idempotent — calling twice
|
|
11
|
+
* is a no-op after the first successful start.
|
|
12
|
+
*
|
|
13
|
+
* Pairs naturally with `longTaskMonitor` (≥200ms outliers): the
|
|
14
|
+
* profiler shows the *distribution* of code that runs in idle gaps,
|
|
15
|
+
* the long-task monitor catches the few outliers that are blocking
|
|
16
|
+
* the thread. Together they cover the JS-side perf signal cheaply.
|
|
17
|
+
*/
|
|
9
18
|
export declare function startSampleProfiler(opts: SampleProfilerOptions): void;
|
|
10
19
|
export declare function stopSampleProfiler(): void;
|
|
11
20
|
export declare function __resetSampleProfilerForTests(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sample-profiler.d.ts","sourceRoot":"","sources":["../src/sample-profiler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sample-profiler.d.ts","sourceRoot":"","sources":["../src/sample-profiler.ts"],"names":[],"mappings":"AAoDA,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB;8BAC0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI,CAUrE;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAWzC;AAyED,wBAAgB,6BAA6B,IAAI,IAAI,CAEpD"}
|
package/lib/sample-profiler.js
CHANGED
|
@@ -25,15 +25,38 @@ const SAMPLE_INTERVAL_MS = 50;
|
|
|
25
25
|
const FLUSH_INTERVAL_MS = 60_000;
|
|
26
26
|
const MAX_FRAMES = 200; // safety cap per profile
|
|
27
27
|
const MAX_FRAME_NAME_LEN = 120;
|
|
28
|
+
/** Floor on user-configured sample interval. Going below ~20 ms costs
|
|
29
|
+
* measurable JS-thread time to `new Error().stack` + regex parse on
|
|
30
|
+
* every tick — past that point you'd see the profile drag down the
|
|
31
|
+
* thing you're profiling. */
|
|
32
|
+
const MIN_SAMPLE_INTERVAL_MS = 20;
|
|
33
|
+
/** Floor on flush interval. Sub-5s windows produce a span every few
|
|
34
|
+
* seconds, which is just noise for an aggregator that's looking at
|
|
35
|
+
* per-minute hotspot trends. */
|
|
36
|
+
const MIN_FLUSH_INTERVAL_MS = 5_000;
|
|
37
|
+
/** How many stack-trace lines to keep per tick (after dropping the
|
|
38
|
+
* Error ctor + sampleTick frames). 10 is enough to see the JS-side
|
|
39
|
+
* call shape; deeper than that the bottom frames are usually RN
|
|
40
|
+
* runtime / event loop and not actionable. */
|
|
41
|
+
const FRAMES_PER_TICK = 10;
|
|
28
42
|
let _frameCounts = new Map();
|
|
29
43
|
let _windowStartedAt = 0;
|
|
30
44
|
let _sampleTimer = null;
|
|
31
45
|
let _flushTimer = null;
|
|
46
|
+
/**
|
|
47
|
+
* Start the idle-tick sample profiler. Idempotent — calling twice
|
|
48
|
+
* is a no-op after the first successful start.
|
|
49
|
+
*
|
|
50
|
+
* Pairs naturally with `longTaskMonitor` (≥200ms outliers): the
|
|
51
|
+
* profiler shows the *distribution* of code that runs in idle gaps,
|
|
52
|
+
* the long-task monitor catches the few outliers that are blocking
|
|
53
|
+
* the thread. Together they cover the JS-side perf signal cheaply.
|
|
54
|
+
*/
|
|
32
55
|
export function startSampleProfiler(opts) {
|
|
33
56
|
if (!opts.enabled || _sampleTimer !== null)
|
|
34
57
|
return;
|
|
35
|
-
const sampleMs = Math.max(
|
|
36
|
-
const flushMs = Math.max(
|
|
58
|
+
const sampleMs = Math.max(MIN_SAMPLE_INTERVAL_MS, opts.sampleMs ?? SAMPLE_INTERVAL_MS);
|
|
59
|
+
const flushMs = Math.max(MIN_FLUSH_INTERVAL_MS, opts.flushMs ?? FLUSH_INTERVAL_MS);
|
|
37
60
|
_windowStartedAt = Date.now();
|
|
38
61
|
_sampleTimer = setInterval(() => sampleTick(), sampleMs);
|
|
39
62
|
_flushTimer = setInterval(() => flushWindow(), flushMs);
|
|
@@ -58,7 +81,7 @@ function sampleTick() {
|
|
|
58
81
|
return;
|
|
59
82
|
// Skip the first 2 frames — they're our `sampleTick` + `Error
|
|
60
83
|
// ctor` which would dominate every sample.
|
|
61
|
-
const lines = stack.split('\n').slice(2,
|
|
84
|
+
const lines = stack.split('\n').slice(2, 2 + FRAMES_PER_TICK);
|
|
62
85
|
for (const line of lines) {
|
|
63
86
|
const frame = parseFrameName(line);
|
|
64
87
|
if (frame) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sample-profiler.js","sourceRoot":"","sources":["../src/sample-profiler.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,gBAAgB;AAChB,mEAAmE;AACnE,gEAAgE;AAChE,iCAAiC;AACjC,qEAAqE;AACrE,wDAAwD;AACxD,EAAE;AACF,uBAAuB;AACvB,kEAAkE;AAClE,kEAAkE;AAClE,kEAAkE;AAClE,mEAAmE;AACnE,EAAE;AACF,mEAAmE;AACnE,mEAAmE;AACnE,6DAA6D;AAC7D,mDAAmD;AACnD,EAAE;AACF,mEAAmE;AACnE,oEAAoE;AAEpE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACjC,MAAM,UAAU,GAAG,GAAG,CAAC,CAAC,yBAAyB;AACjD,MAAM,kBA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B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goliapkg/sentori-react-native",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"description": "Sentori SDK for React Native \u2014 JS-layer error capture, native crash handlers (iOS / Android), batched transport, fetch + react-navigation tracing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://sentori.golia.jp",
|
|
@@ -66,12 +66,12 @@
|
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@types/bun": "latest",
|
|
68
68
|
"@types/react": "^19",
|
|
69
|
-
"typescript": "^
|
|
69
|
+
"typescript": "^6"
|
|
70
70
|
},
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@goliapkg/sentori-core": "0.8.
|
|
75
|
+
"@goliapkg/sentori-core": "0.8.3"
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// v1.1 +S7 升级 — control channel unit tests.
|
|
2
|
+
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';
|
|
4
|
+
|
|
5
|
+
import { setConfig, __resetForTests as resetConfig } from '../config';
|
|
6
|
+
import {
|
|
7
|
+
__resetControlChannelForTests,
|
|
8
|
+
isLiveMode,
|
|
9
|
+
startControlChannel,
|
|
10
|
+
stopControlChannel,
|
|
11
|
+
} from '../control-channel';
|
|
12
|
+
import { setUser } from '../capture';
|
|
13
|
+
|
|
14
|
+
const originalFetch = globalThis.fetch;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
resetConfig();
|
|
18
|
+
__resetControlChannelForTests();
|
|
19
|
+
setConfig({
|
|
20
|
+
token: 'st_pk_test',
|
|
21
|
+
release: 'app@1.0.0+1',
|
|
22
|
+
environment: 'test',
|
|
23
|
+
ingestUrl: 'http://localhost:8080',
|
|
24
|
+
enabled: true,
|
|
25
|
+
screenshotsEnabled: false,
|
|
26
|
+
errorSampleRate: null,
|
|
27
|
+
traceSampleRate: null,
|
|
28
|
+
sessionTrailEnabled: false,
|
|
29
|
+
});
|
|
30
|
+
setUser({ id: 'u-1' });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
globalThis.fetch = originalFetch;
|
|
35
|
+
__resetControlChannelForTests();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('control-channel', () => {
|
|
39
|
+
test('isLiveMode() is false by default', () => {
|
|
40
|
+
expect(isLiveMode()).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('start → poll → server says liveMode:true → isLiveMode flips on', async () => {
|
|
44
|
+
globalThis.fetch = mock(async () =>
|
|
45
|
+
new Response(JSON.stringify({ liveMode: true, ttlMs: 60_000 }), {
|
|
46
|
+
status: 200,
|
|
47
|
+
headers: { 'content-type': 'application/json' },
|
|
48
|
+
}),
|
|
49
|
+
) as typeof fetch;
|
|
50
|
+
|
|
51
|
+
startControlChannel();
|
|
52
|
+
// The initial pollOnce is awaited via void, so give it a microtask.
|
|
53
|
+
await new Promise((r) => setTimeout(r, 30));
|
|
54
|
+
expect(isLiveMode()).toBe(true);
|
|
55
|
+
stopControlChannel();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('server says liveMode:false → isLiveMode stays false', async () => {
|
|
59
|
+
globalThis.fetch = mock(async () =>
|
|
60
|
+
new Response(JSON.stringify({ liveMode: false, ttlMs: 0 }), {
|
|
61
|
+
status: 200,
|
|
62
|
+
headers: { 'content-type': 'application/json' },
|
|
63
|
+
}),
|
|
64
|
+
) as typeof fetch;
|
|
65
|
+
|
|
66
|
+
startControlChannel();
|
|
67
|
+
await new Promise((r) => setTimeout(r, 30));
|
|
68
|
+
expect(isLiveMode()).toBe(false);
|
|
69
|
+
stopControlChannel();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('network failure leaves prior state (no throw on poll error)', async () => {
|
|
73
|
+
globalThis.fetch = mock(async () => {
|
|
74
|
+
throw new Error('econn');
|
|
75
|
+
}) as typeof fetch;
|
|
76
|
+
startControlChannel();
|
|
77
|
+
await new Promise((r) => setTimeout(r, 30));
|
|
78
|
+
// Should not have thrown; isLiveMode stays false.
|
|
79
|
+
expect(isLiveMode()).toBe(false);
|
|
80
|
+
stopControlChannel();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('server-reported ttlMs is capped at 15min defence-in-depth', async () => {
|
|
84
|
+
// 24h ttl from server — caller should cap.
|
|
85
|
+
globalThis.fetch = mock(async () =>
|
|
86
|
+
new Response(JSON.stringify({ liveMode: true, ttlMs: 24 * 60 * 60_000 }), {
|
|
87
|
+
status: 200,
|
|
88
|
+
headers: { 'content-type': 'application/json' },
|
|
89
|
+
}),
|
|
90
|
+
) as typeof fetch;
|
|
91
|
+
startControlChannel();
|
|
92
|
+
await new Promise((r) => setTimeout(r, 30));
|
|
93
|
+
// We don't expose _liveModeUntil directly, but we can at least
|
|
94
|
+
// confirm liveMode flipped on without runaway state.
|
|
95
|
+
expect(isLiveMode()).toBe(true);
|
|
96
|
+
stopControlChannel();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('without setUser, liveMode stays off (no key to poll)', async () => {
|
|
100
|
+
setUser(undefined);
|
|
101
|
+
globalThis.fetch = mock(async () =>
|
|
102
|
+
new Response(JSON.stringify({ liveMode: true, ttlMs: 60_000 }), {
|
|
103
|
+
status: 200,
|
|
104
|
+
}),
|
|
105
|
+
) as typeof fetch;
|
|
106
|
+
startControlChannel();
|
|
107
|
+
await new Promise((r) => setTimeout(r, 30));
|
|
108
|
+
expect(isLiveMode()).toBe(false);
|
|
109
|
+
stopControlChannel();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// v0.9.6 #4 — long-task monitor unit tests.
|
|
2
|
+
|
|
3
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
4
|
+
|
|
5
|
+
import { clearSpans, drainSpans } from '@goliapkg/sentori-core';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
__resetLongTaskMonitorForTests,
|
|
9
|
+
startLongTaskMonitor,
|
|
10
|
+
stopLongTaskMonitor,
|
|
11
|
+
} from '../long-task-monitor';
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
__resetLongTaskMonitorForTests();
|
|
15
|
+
clearSpans();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('long-task-monitor', () => {
|
|
19
|
+
test('disabled is a no-op', () => {
|
|
20
|
+
startLongTaskMonitor({ enabled: false });
|
|
21
|
+
expect(drainSpans().length).toBe(0);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('double-start is idempotent', () => {
|
|
25
|
+
startLongTaskMonitor({ enabled: true });
|
|
26
|
+
// Second call must not register a parallel interval — would
|
|
27
|
+
// double-count every tick.
|
|
28
|
+
startLongTaskMonitor({ enabled: true });
|
|
29
|
+
stopLongTaskMonitor();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('synthetic long task crosses threshold and emits a span', async () => {
|
|
33
|
+
// 80ms threshold so we don't need a 200ms+ block in the test.
|
|
34
|
+
startLongTaskMonitor({ enabled: true, thresholdMs: 80 });
|
|
35
|
+
// Busy-block the JS thread for ~150ms; the next tick will see
|
|
36
|
+
// elapsed >> tickInterval and emit a longtask span.
|
|
37
|
+
const t0 = Date.now();
|
|
38
|
+
while (Date.now() - t0 < 150) {
|
|
39
|
+
// burn — no setTimeout, the thread must actually be busy.
|
|
40
|
+
}
|
|
41
|
+
// Let the next 50ms tick fire.
|
|
42
|
+
await new Promise((r) => setTimeout(r, 80));
|
|
43
|
+
const spans = drainSpans();
|
|
44
|
+
const longtask = spans.find((s) => s.op === 'sentori.longtask');
|
|
45
|
+
expect(longtask).toBeDefined();
|
|
46
|
+
expect(longtask?.tags?.['profile.kind']).toBe('longtask');
|
|
47
|
+
stopLongTaskMonitor();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('sub-threshold ticks do not emit', async () => {
|
|
51
|
+
startLongTaskMonitor({ enabled: true, thresholdMs: 500 });
|
|
52
|
+
// Don't block — let normal idle ticks happen.
|
|
53
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
54
|
+
const spans = drainSpans();
|
|
55
|
+
const longtasks = spans.filter((s) => s.op === 'sentori.longtask');
|
|
56
|
+
expect(longtasks.length).toBe(0);
|
|
57
|
+
stopLongTaskMonitor();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// v1.1 #4 升级 — JS sample profiler unit tests.
|
|
2
|
+
|
|
3
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
4
|
+
|
|
5
|
+
import { clearSpans, drainSpans } from '@goliapkg/sentori-core';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
__resetSampleProfilerForTests,
|
|
9
|
+
startSampleProfiler,
|
|
10
|
+
stopSampleProfiler,
|
|
11
|
+
} from '../sample-profiler';
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
__resetSampleProfilerForTests();
|
|
15
|
+
clearSpans();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('sample-profiler', () => {
|
|
19
|
+
test('start with enabled=false is a no-op', () => {
|
|
20
|
+
startSampleProfiler({ enabled: false });
|
|
21
|
+
stopSampleProfiler();
|
|
22
|
+
expect(drainSpans().length).toBe(0);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('double start is idempotent (second call ignored)', () => {
|
|
26
|
+
startSampleProfiler({ enabled: true, sampleMs: 30, flushMs: 5_000 });
|
|
27
|
+
// A second start while the timer is live must not spin a second
|
|
28
|
+
// interval — would double-count every sample.
|
|
29
|
+
startSampleProfiler({ enabled: true, sampleMs: 30, flushMs: 5_000 });
|
|
30
|
+
stopSampleProfiler();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('stop clears state cleanly', async () => {
|
|
34
|
+
startSampleProfiler({ enabled: true, sampleMs: 30, flushMs: 5_000 });
|
|
35
|
+
// Let a few sampleTicks happen.
|
|
36
|
+
await new Promise((r) => setTimeout(r, 120));
|
|
37
|
+
stopSampleProfiler();
|
|
38
|
+
// After stop, no further span should be emitted even past flushMs.
|
|
39
|
+
await new Promise((r) => setTimeout(r, 80));
|
|
40
|
+
// (Bun timers aren't faked here, so we don't wait the full flush
|
|
41
|
+
// window; we just confirm stop returns cleanly and __reset works.)
|
|
42
|
+
__resetSampleProfilerForTests();
|
|
43
|
+
expect(true).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('sample interval floor — sampleMs < 20 clamped up to 20', () => {
|
|
47
|
+
// Internal: profile.duration_ms tag uses the *effective* window
|
|
48
|
+
// length so we can't directly observe the chosen sampleMs, but we
|
|
49
|
+
// *can* assert start doesn't throw with an absurd request, since
|
|
50
|
+
// the clamp protects against pathological CPU burn.
|
|
51
|
+
startSampleProfiler({ enabled: true, sampleMs: 1, flushMs: 5_000 });
|
|
52
|
+
stopSampleProfiler();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('flush interval floor — flushMs < 5000 clamped up to 5000', () => {
|
|
56
|
+
startSampleProfiler({ enabled: true, sampleMs: 30, flushMs: 100 });
|
|
57
|
+
stopSampleProfiler();
|
|
58
|
+
});
|
|
59
|
+
});
|
package/src/control-channel.ts
CHANGED
|
@@ -19,6 +19,14 @@ import { getCurrentUserId } from './capture';
|
|
|
19
19
|
|
|
20
20
|
const POLL_INTERVAL_MS = 30_000;
|
|
21
21
|
|
|
22
|
+
/** Cap on the live-mode window even if the server reports a longer
|
|
23
|
+
* TTL. Defense-in-depth: an unbounded `ttlMs` (server bug, clock
|
|
24
|
+
* skew, malicious server) would otherwise pin the SDK into flush-
|
|
25
|
+
* every-event mode indefinitely, which is expensive on slow
|
|
26
|
+
* networks. 15 min matches the dashboard's default arm length so
|
|
27
|
+
* normal operation stays uncapped. */
|
|
28
|
+
const MAX_LIVE_MODE_TTL_MS = 15 * 60_000;
|
|
29
|
+
|
|
22
30
|
let _liveMode = false;
|
|
23
31
|
let _liveModeUntil = 0;
|
|
24
32
|
let _timer: ReturnType<typeof setInterval> | null = null;
|
|
@@ -73,7 +81,7 @@ async function pollOnce(): Promise<void> {
|
|
|
73
81
|
const body = (await resp.json()) as { liveMode?: boolean; ttlMs?: number };
|
|
74
82
|
if (body.liveMode === true) {
|
|
75
83
|
_liveMode = true;
|
|
76
|
-
_liveModeUntil = Date.now() + Math.max(0, Math.min(body.ttlMs ?? 0,
|
|
84
|
+
_liveModeUntil = Date.now() + Math.max(0, Math.min(body.ttlMs ?? 0, MAX_LIVE_MODE_TTL_MS));
|
|
77
85
|
} else {
|
|
78
86
|
_liveMode = false;
|
|
79
87
|
_liveModeUntil = 0;
|
package/src/mobile-vitals.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
import { startSpan } from '@goliapkg/sentori-core';
|
|
24
24
|
|
|
25
|
-
import { getNativeColdStartMs } from './native';
|
|
25
|
+
import { getNativeColdStartMs, getNativeFrameCounters } from './native';
|
|
26
26
|
|
|
27
27
|
let _coldStartMs: null | number = null;
|
|
28
28
|
let _coldStartCaptured = false;
|
|
@@ -93,13 +93,7 @@ export function markTimeToFullDisplay(route: string): TimeToFullDisplayHandle {
|
|
|
93
93
|
* linked. */
|
|
94
94
|
export function getFrameCounters(): null | { slow: number; frozen: number } {
|
|
95
95
|
try {
|
|
96
|
-
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
98
|
-
const nativeMod = require('./native') as {
|
|
99
|
-
getNativeFrameCounters?: () => null | { frozen: number; slow: number };
|
|
100
|
-
};
|
|
101
|
-
if (typeof nativeMod.getNativeFrameCounters !== 'function') return null;
|
|
102
|
-
return nativeMod.getNativeFrameCounters();
|
|
96
|
+
return getNativeFrameCounters();
|
|
103
97
|
} catch {
|
|
104
98
|
return null;
|
|
105
99
|
}
|
package/src/replay.ts
CHANGED
|
@@ -25,10 +25,23 @@ import { isNativeModuleLinked } from './native-loader';
|
|
|
25
25
|
const TICK_INTERVAL_MS = 1000;
|
|
26
26
|
const RING_SIZE = 60;
|
|
27
27
|
|
|
28
|
+
/** Floor on tick period. < 250 ms (4 Hz) the native view-tree walk
|
|
29
|
+
* dominates the JS thread on mid-tier Android, especially with mask
|
|
30
|
+
* consultation. The default is 1 Hz; the option exists for
|
|
31
|
+
* benchmarking, not for production. */
|
|
32
|
+
const MIN_TICK_PERIOD_MS = 250;
|
|
33
|
+
|
|
28
34
|
let _ring: string[] = [];
|
|
29
35
|
let _timer: ReturnType<typeof setInterval> | null = null;
|
|
30
36
|
let _running = false;
|
|
31
37
|
|
|
38
|
+
/** Native module ref, resolved once on first start. Caching here
|
|
39
|
+
* avoids the cost of `requireNativeModule('Sentori')` on every
|
|
40
|
+
* capture tick (Metro's require cache makes this cheap, but the
|
|
41
|
+
* per-tick string lookup and possible throw still cost more than
|
|
42
|
+
* reading a closed-over variable). */
|
|
43
|
+
let _nativeMod: ReplayNativeModule | null = null;
|
|
44
|
+
|
|
32
45
|
export type ReplayOptions = {
|
|
33
46
|
mode?: 'off' | 'wireframe';
|
|
34
47
|
/** Ticks per second. Default 1. */
|
|
@@ -47,7 +60,8 @@ export function startReplay(opts: ReplayOptions): void {
|
|
|
47
60
|
return;
|
|
48
61
|
}
|
|
49
62
|
_running = true;
|
|
50
|
-
|
|
63
|
+
_nativeMod = loadNativeReplay();
|
|
64
|
+
const period = Math.max(MIN_TICK_PERIOD_MS, Math.floor(TICK_INTERVAL_MS / (opts.hz ?? 1)));
|
|
51
65
|
_timer = setInterval(() => {
|
|
52
66
|
captureTick();
|
|
53
67
|
}, period);
|
|
@@ -60,6 +74,7 @@ export function stopReplay(): void {
|
|
|
60
74
|
clearInterval(_timer);
|
|
61
75
|
_timer = null;
|
|
62
76
|
}
|
|
77
|
+
_nativeMod = null;
|
|
63
78
|
}
|
|
64
79
|
|
|
65
80
|
function captureTick(): void {
|
|
@@ -67,9 +82,7 @@ function captureTick(): void {
|
|
|
67
82
|
const tickSpan = startSpan('sentori.replay.tick', { name: 'tick' });
|
|
68
83
|
try {
|
|
69
84
|
const maskIds = readMaskIds();
|
|
70
|
-
|
|
71
|
-
const nativeMod = loadNativeReplay();
|
|
72
|
-
const snapshot = nativeMod?.captureWireframe?.(maskIds);
|
|
85
|
+
const snapshot = _nativeMod?.captureWireframe?.(maskIds);
|
|
73
86
|
if (typeof snapshot === 'string' && snapshot.length > 0) {
|
|
74
87
|
_ring.push(snapshot);
|
|
75
88
|
while (_ring.length > RING_SIZE) _ring.shift();
|
package/src/sample-profiler.ts
CHANGED
|
@@ -28,6 +28,23 @@ const FLUSH_INTERVAL_MS = 60_000;
|
|
|
28
28
|
const MAX_FRAMES = 200; // safety cap per profile
|
|
29
29
|
const MAX_FRAME_NAME_LEN = 120;
|
|
30
30
|
|
|
31
|
+
/** Floor on user-configured sample interval. Going below ~20 ms costs
|
|
32
|
+
* measurable JS-thread time to `new Error().stack` + regex parse on
|
|
33
|
+
* every tick — past that point you'd see the profile drag down the
|
|
34
|
+
* thing you're profiling. */
|
|
35
|
+
const MIN_SAMPLE_INTERVAL_MS = 20;
|
|
36
|
+
|
|
37
|
+
/** Floor on flush interval. Sub-5s windows produce a span every few
|
|
38
|
+
* seconds, which is just noise for an aggregator that's looking at
|
|
39
|
+
* per-minute hotspot trends. */
|
|
40
|
+
const MIN_FLUSH_INTERVAL_MS = 5_000;
|
|
41
|
+
|
|
42
|
+
/** How many stack-trace lines to keep per tick (after dropping the
|
|
43
|
+
* Error ctor + sampleTick frames). 10 is enough to see the JS-side
|
|
44
|
+
* call shape; deeper than that the bottom frames are usually RN
|
|
45
|
+
* runtime / event loop and not actionable. */
|
|
46
|
+
const FRAMES_PER_TICK = 10;
|
|
47
|
+
|
|
31
48
|
let _frameCounts = new Map<string, number>();
|
|
32
49
|
let _windowStartedAt = 0;
|
|
33
50
|
let _sampleTimer: ReturnType<typeof setInterval> | null = null;
|
|
@@ -42,10 +59,19 @@ export type SampleProfilerOptions = {
|
|
|
42
59
|
flushMs?: number;
|
|
43
60
|
};
|
|
44
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Start the idle-tick sample profiler. Idempotent — calling twice
|
|
64
|
+
* is a no-op after the first successful start.
|
|
65
|
+
*
|
|
66
|
+
* Pairs naturally with `longTaskMonitor` (≥200ms outliers): the
|
|
67
|
+
* profiler shows the *distribution* of code that runs in idle gaps,
|
|
68
|
+
* the long-task monitor catches the few outliers that are blocking
|
|
69
|
+
* the thread. Together they cover the JS-side perf signal cheaply.
|
|
70
|
+
*/
|
|
45
71
|
export function startSampleProfiler(opts: SampleProfilerOptions): void {
|
|
46
72
|
if (!opts.enabled || _sampleTimer !== null) return;
|
|
47
|
-
const sampleMs = Math.max(
|
|
48
|
-
const flushMs = Math.max(
|
|
73
|
+
const sampleMs = Math.max(MIN_SAMPLE_INTERVAL_MS, opts.sampleMs ?? SAMPLE_INTERVAL_MS);
|
|
74
|
+
const flushMs = Math.max(MIN_FLUSH_INTERVAL_MS, opts.flushMs ?? FLUSH_INTERVAL_MS);
|
|
49
75
|
|
|
50
76
|
_windowStartedAt = Date.now();
|
|
51
77
|
_sampleTimer = setInterval(() => sampleTick(), sampleMs);
|
|
@@ -72,7 +98,7 @@ function sampleTick(): void {
|
|
|
72
98
|
if (!stack) return;
|
|
73
99
|
// Skip the first 2 frames — they're our `sampleTick` + `Error
|
|
74
100
|
// ctor` which would dominate every sample.
|
|
75
|
-
const lines = stack.split('\n').slice(2,
|
|
101
|
+
const lines = stack.split('\n').slice(2, 2 + FRAMES_PER_TICK);
|
|
76
102
|
for (const line of lines) {
|
|
77
103
|
const frame = parseFrameName(line);
|
|
78
104
|
if (frame) {
|