peachsim 0.1.2713 → 0.1.2715
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/cli/commands/perf.ts +1 -1
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +2 -2
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +5 -5
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +3 -3
- package/dist-lib/bundle-channel.cjs +20 -8
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +3 -3
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +3 -3
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +2 -2
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +7 -7
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +5 -5
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-UGPYFRXH.mjs → acorn-3T32YI42.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-QJSFPWDX.mjs → chunk-3AZ5RGJB.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-VYIGK2NW.mjs → chunk-4LW7D2PZ.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-W2MPQLYH.mjs → chunk-4TVCBJSE.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-4YSMVQI2.mjs → chunk-6OKXKEDU.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-UQLFJLJR.mjs → chunk-AFCRKCAY.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-LELSN3IC.mjs → chunk-ARJH2MCS.mjs} +30 -18
- package/dist-lib/esm-chunks/{chunk-HFQCZLJR.mjs → chunk-DLCN45QE.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-PLWG3FJA.mjs → chunk-DRHI6OCF.mjs} +6 -6
- package/dist-lib/esm-chunks/{chunk-NYKAL7R3.mjs → chunk-EFOWEUVI.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-VPPAKIKE.mjs → chunk-EGW4G66X.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ICEHCZBA.mjs → chunk-EHCJ4A5V.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-OG7ECWYK.mjs → chunk-EVREAEZS.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ZWCHRDL2.mjs → chunk-HDN5S2CU.mjs} +6 -6
- package/dist-lib/esm-chunks/{chunk-FSNXHMC4.mjs → chunk-IWHNEHK6.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-XGAJHG6Q.mjs → chunk-JQT4YVH3.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-YEYBG6NV.mjs → chunk-NUFB4RSS.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-IGGDAE7X.mjs → chunk-OOUXYWYE.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-62LJAKDD.mjs → chunk-QCUO3D43.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-RAJ2OZXX.mjs → chunk-SCA2GVHL.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-OQBFLVDR.mjs → chunk-TLIFHJCP.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ZVC26DCL.mjs → chunk-ULO746TE.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-HBCXO46K.mjs → chunk-XBV7QPXS.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-4JDUSZX2.mjs → chunk-ZA32Y6Z4.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-SXKCBHDC.mjs → chunk-ZYZ7ZGAE.mjs} +1 -1
- package/dist-lib/esm-chunks/{metro-layout-parser-5NGUQXXS.mjs → metro-layout-parser-HL4VIWPT.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-4LCBDXJI.mjs → swift-package-prebuilt-JSHKZUIE.mjs} +12 -12
- package/dist-lib/esm-chunks/{swift-sdk-app-module-SKHLUPWO.mjs → swift-sdk-app-module-HNP2GPAV.mjs} +16 -16
- package/dist-lib/esm-chunks/{swift-sdk-image-TNISY3PU.mjs → swift-sdk-image-S4FTOYML.mjs} +16 -16
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-FPKEM5PE.mjs → swift-sdk-image-producer-3VF3CF3M.mjs} +5 -5
- package/dist-lib/expo-swift-bundle.cjs +20 -8
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +7 -7
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +20 -8
- package/dist-lib/host/fetch-proxy-handler.cjs +3 -3
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +3 -3
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +3 -3
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +4 -4
- package/dist-lib/native-app-identity-project.cjs +1 -1
- package/dist-lib/native-app-identity-project.mjs +15 -15
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +6 -6
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +3 -3
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +2 -2
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +3 -3
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +85 -85
- package/dist-lib/public-origins-lib.json +64 -64
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +2 -2
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +8 -8
- package/dist-lib/skills.cjs +20 -8
- package/dist-lib/swift-compile.cjs +17 -5
- package/dist-lib/swift-compile.mjs +12 -12
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +3 -3
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +6 -6
- package/dist-lib/swift-svg-raster.cjs +1 -1
- package/dist-lib/swift-svg-raster.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
- package/dist-lib/vendor/acorn.cjs +1 -1
- package/dist-lib/vendor/magic-string.cjs +1 -1
- package/dist-lib/vendor/stream-json.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
- package/dist-lib/vendor/sucrase.cjs +1 -1
- package/dist-lib/vendor/terser.cjs +1 -1
- package/dist-lib/vendor/valibot.cjs +1 -1
- package/dist-lib/vendor/ws.cjs +1 -1
- package/dist-lib/vendor/zod.cjs +1 -1
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +3 -3
- package/dist-types/packages/peach-engine/src/render-worker/compositor-runtime/presentation-book-host.d.ts +0 -2
- package/dist-types/packages/peach-engine/src/render-worker/compositor-runtime/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/swift-guest-compile.ts +14 -2
- package/src/swiftSdkLinkContract.ts +1 -0
- package/cli/commands/diagnose-native.ts +0 -717
- package/cli/commands/perf-native.ts +0 -1592
|
@@ -1,1592 +0,0 @@
|
|
|
1
|
-
import { execFileSync, spawnSync } from 'node:child_process'
|
|
2
|
-
import { randomUUID } from 'node:crypto'
|
|
3
|
-
import {
|
|
4
|
-
copyFileSync,
|
|
5
|
-
existsSync,
|
|
6
|
-
mkdirSync,
|
|
7
|
-
readdirSync,
|
|
8
|
-
readFileSync,
|
|
9
|
-
rmSync,
|
|
10
|
-
statSync,
|
|
11
|
-
writeFileSync,
|
|
12
|
-
} from 'node:fs'
|
|
13
|
-
import { basename, dirname, join, resolve } from 'node:path'
|
|
14
|
-
import { parseArgs } from 'node:util'
|
|
15
|
-
|
|
16
|
-
type NativeProfileJsTiers = {
|
|
17
|
-
aot: number
|
|
18
|
-
interpreter: number
|
|
19
|
-
interpreterBuiltin: number
|
|
20
|
-
jit: number
|
|
21
|
-
host: number
|
|
22
|
-
native: number
|
|
23
|
-
regexp: number
|
|
24
|
-
wasm: number
|
|
25
|
-
unknown: number
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type NativeProfileFunction = {
|
|
29
|
-
name: string
|
|
30
|
-
url: string
|
|
31
|
-
line: number
|
|
32
|
-
column: number
|
|
33
|
-
tier?: string
|
|
34
|
-
builtin?: boolean
|
|
35
|
-
selfMs: number
|
|
36
|
-
totalMs: number
|
|
37
|
-
selfSamples: number
|
|
38
|
-
totalSamples: number
|
|
39
|
-
selfPct: number
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type NativeProfileComponent = {
|
|
43
|
-
name: string
|
|
44
|
-
commits: number
|
|
45
|
-
renders: number
|
|
46
|
-
totalMs: number
|
|
47
|
-
maxMs: number
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export type NativeProfileReport = {
|
|
51
|
-
schema: number
|
|
52
|
-
bundleId: string
|
|
53
|
-
build: string
|
|
54
|
-
executableUUID: string
|
|
55
|
-
route: string
|
|
56
|
-
startWallMs: number
|
|
57
|
-
durationMs: number
|
|
58
|
-
frames: number
|
|
59
|
-
droppedFrames: number
|
|
60
|
-
fps: number
|
|
61
|
-
longestFrameMs: number
|
|
62
|
-
mainThreadBusyMs: number
|
|
63
|
-
mainThreadBusyPct: number
|
|
64
|
-
jsMs: number
|
|
65
|
-
nativeMs: number
|
|
66
|
-
phases: Record<string, number>
|
|
67
|
-
jsSamples: number
|
|
68
|
-
jsTiers?: NativeProfileJsTiers
|
|
69
|
-
topJsFunctions: NativeProfileFunction[]
|
|
70
|
-
topJsCallers?: NativeProfileFunction[]
|
|
71
|
-
topInterpretedJsFunctions?: NativeProfileFunction[]
|
|
72
|
-
reactCommits: number
|
|
73
|
-
topReactComponents: NativeProfileComponent[]
|
|
74
|
-
nativeSamples: number
|
|
75
|
-
topNativeSelf: Record<string, unknown>[]
|
|
76
|
-
topNativeInclusive: Record<string, unknown>[]
|
|
77
|
-
topNativeStacks: Record<string, unknown>[]
|
|
78
|
-
turnsOver16ms: number
|
|
79
|
-
worstStall: Record<string, unknown> | null
|
|
80
|
-
slowBridgeCalls: Record<string, unknown>[]
|
|
81
|
-
slowBridgeTotal: number
|
|
82
|
-
budget: Record<string, unknown> | null
|
|
83
|
-
spans: Record<string, unknown>[]
|
|
84
|
-
files: {
|
|
85
|
-
cpuprofile: string
|
|
86
|
-
trace: string
|
|
87
|
-
summary: string
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
type ParsedSourceMap = {
|
|
92
|
-
sources: string[]
|
|
93
|
-
names: string[]
|
|
94
|
-
lines: Array<
|
|
95
|
-
Array<{
|
|
96
|
-
genCol: number
|
|
97
|
-
srcIdx: number
|
|
98
|
-
origLine: number
|
|
99
|
-
origCol: number
|
|
100
|
-
nameIdx: number
|
|
101
|
-
}>
|
|
102
|
-
>
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
type SourceMapBundle = {
|
|
106
|
-
directory: string
|
|
107
|
-
compiled: { offset: number; name: string }[]
|
|
108
|
-
compiledEnd: number
|
|
109
|
-
rawMaps: Record<string, string>
|
|
110
|
-
decoded: Map<string, ParsedSourceMap | null>
|
|
111
|
-
declByFileAndName: Map<string, number>
|
|
112
|
-
declByName: Map<string, { file: string; line: number }>
|
|
113
|
-
demangledCache: Map<string, { name?: string; source?: string; line?: number } | null>
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const VLQ_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
|
117
|
-
const VLQ_MAP = new Int8Array(128).fill(-1)
|
|
118
|
-
for (let i = 0; i < VLQ_CHARS.length; i++) VLQ_MAP[VLQ_CHARS.charCodeAt(i)] = i
|
|
119
|
-
|
|
120
|
-
function decodeSourceMap(raw: string): ParsedSourceMap | null {
|
|
121
|
-
try {
|
|
122
|
-
const parsed: unknown = JSON.parse(raw)
|
|
123
|
-
if (!parsed || typeof parsed !== 'object') return null
|
|
124
|
-
const sourcesVal = Reflect.get(parsed, 'sources')
|
|
125
|
-
const namesVal = Reflect.get(parsed, 'names')
|
|
126
|
-
const mappingsVal = Reflect.get(parsed, 'mappings')
|
|
127
|
-
if (!Array.isArray(sourcesVal) || typeof mappingsVal !== 'string') return null
|
|
128
|
-
const sources = sourcesVal.map((s) => (typeof s === 'string' ? s : ''))
|
|
129
|
-
const names = Array.isArray(namesVal)
|
|
130
|
-
? namesVal.map((n) => (typeof n === 'string' ? n : ''))
|
|
131
|
-
: []
|
|
132
|
-
const lines: ParsedSourceMap['lines'] = []
|
|
133
|
-
let srcIdx = 0
|
|
134
|
-
let origLine = 0
|
|
135
|
-
let origCol = 0
|
|
136
|
-
let nameIdx = 0
|
|
137
|
-
let pos = 0
|
|
138
|
-
const len = mappingsVal.length
|
|
139
|
-
const readVlq = (): number => {
|
|
140
|
-
let result = 0
|
|
141
|
-
let shift = 0
|
|
142
|
-
while (pos < len) {
|
|
143
|
-
const code = mappingsVal.charCodeAt(pos++)
|
|
144
|
-
const digit = code < 128 ? VLQ_MAP[code]! : -1
|
|
145
|
-
if (digit < 0) break
|
|
146
|
-
const cont = (digit & 32) !== 0
|
|
147
|
-
result += (digit & 31) << shift
|
|
148
|
-
shift += 5
|
|
149
|
-
if (!cont) break
|
|
150
|
-
}
|
|
151
|
-
return (result & 1) === 1 ? -(result >> 1) : result >> 1
|
|
152
|
-
}
|
|
153
|
-
let currentLine: ParsedSourceMap['lines'][number] = []
|
|
154
|
-
while (pos < len) {
|
|
155
|
-
const ch = mappingsVal.charCodeAt(pos)
|
|
156
|
-
if (ch === 59) {
|
|
157
|
-
lines.push(currentLine)
|
|
158
|
-
currentLine = []
|
|
159
|
-
pos++
|
|
160
|
-
continue
|
|
161
|
-
}
|
|
162
|
-
if (ch === 44) {
|
|
163
|
-
pos++
|
|
164
|
-
continue
|
|
165
|
-
}
|
|
166
|
-
let genCol = currentLine.length ? currentLine[currentLine.length - 1]!.genCol : 0
|
|
167
|
-
genCol += readVlq()
|
|
168
|
-
if (
|
|
169
|
-
pos < len &&
|
|
170
|
-
mappingsVal.charCodeAt(pos) !== 44 &&
|
|
171
|
-
mappingsVal.charCodeAt(pos) !== 59
|
|
172
|
-
) {
|
|
173
|
-
srcIdx += readVlq()
|
|
174
|
-
origLine += readVlq()
|
|
175
|
-
origCol += readVlq()
|
|
176
|
-
let segName = -1
|
|
177
|
-
if (
|
|
178
|
-
pos < len &&
|
|
179
|
-
mappingsVal.charCodeAt(pos) !== 44 &&
|
|
180
|
-
mappingsVal.charCodeAt(pos) !== 59
|
|
181
|
-
) {
|
|
182
|
-
nameIdx += readVlq()
|
|
183
|
-
segName = nameIdx
|
|
184
|
-
}
|
|
185
|
-
currentLine.push({ genCol, srcIdx, origLine, origCol, nameIdx: segName })
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
lines.push(currentLine)
|
|
189
|
-
return { sources, names, lines }
|
|
190
|
-
} catch {
|
|
191
|
-
return null
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function lookupPosition(
|
|
196
|
-
map: ParsedSourceMap,
|
|
197
|
-
line1: number,
|
|
198
|
-
col1: number,
|
|
199
|
-
): { source: string; line: number; column: number; name?: string } | null {
|
|
200
|
-
const row = map.lines[line1 - 1]
|
|
201
|
-
if (!row || row.length === 0) return null
|
|
202
|
-
const targetCol = Math.max(0, col1 - 1)
|
|
203
|
-
let lo = 0
|
|
204
|
-
let hi = row.length - 1
|
|
205
|
-
let best = row[0]!
|
|
206
|
-
while (lo <= hi) {
|
|
207
|
-
const mid = (lo + hi) >> 1
|
|
208
|
-
const seg = row[mid]!
|
|
209
|
-
if (seg.genCol <= targetCol) {
|
|
210
|
-
best = seg
|
|
211
|
-
lo = mid + 1
|
|
212
|
-
} else {
|
|
213
|
-
hi = mid - 1
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
const source = map.sources[best.srcIdx]
|
|
217
|
-
if (!source) return null
|
|
218
|
-
return {
|
|
219
|
-
source,
|
|
220
|
-
line: best.origLine + 1,
|
|
221
|
-
column: best.origCol + 1,
|
|
222
|
-
name: best.nameIdx >= 0 ? map.names[best.nameIdx] : undefined,
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function loadSourceMapsBundle(
|
|
227
|
-
sourceMapsPath: string | undefined,
|
|
228
|
-
executableUUID: string,
|
|
229
|
-
): SourceMapBundle {
|
|
230
|
-
const empty: SourceMapBundle = {
|
|
231
|
-
directory: '',
|
|
232
|
-
compiled: [],
|
|
233
|
-
compiledEnd: 0,
|
|
234
|
-
rawMaps: {},
|
|
235
|
-
decoded: new Map(),
|
|
236
|
-
declByFileAndName: new Map(),
|
|
237
|
-
declByName: new Map(),
|
|
238
|
-
demangledCache: new Map(),
|
|
239
|
-
}
|
|
240
|
-
if (!sourceMapsPath) return empty
|
|
241
|
-
let targetFile = resolve(sourceMapsPath)
|
|
242
|
-
if (existsSync(targetFile) && statSync(targetFile).isDirectory()) {
|
|
243
|
-
const expected = `OneJavaScriptSourceMaps-${executableUUID}.json`
|
|
244
|
-
const direct = join(targetFile, expected)
|
|
245
|
-
if (existsSync(direct)) {
|
|
246
|
-
targetFile = direct
|
|
247
|
-
} else {
|
|
248
|
-
const candidate = readdirSync(targetFile).find(
|
|
249
|
-
(name) =>
|
|
250
|
-
name.startsWith('OneJavaScriptSourceMaps-') &&
|
|
251
|
-
name.endsWith('.json') &&
|
|
252
|
-
(!executableUUID || name.toLowerCase().includes(executableUUID.toLowerCase())),
|
|
253
|
-
)
|
|
254
|
-
if (!candidate) return empty
|
|
255
|
-
targetFile = join(targetFile, candidate)
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (!existsSync(targetFile)) return empty
|
|
259
|
-
empty.directory = dirname(targetFile)
|
|
260
|
-
const parsed: unknown = JSON.parse(readFileSync(targetFile, 'utf8'))
|
|
261
|
-
if (!parsed || typeof parsed !== 'object') return empty
|
|
262
|
-
const imageUUID = Reflect.get(parsed, 'imageUUID')
|
|
263
|
-
if (
|
|
264
|
-
executableUUID &&
|
|
265
|
-
typeof imageUUID === 'string' &&
|
|
266
|
-
imageUUID.toLowerCase() !== executableUUID.toLowerCase()
|
|
267
|
-
) {
|
|
268
|
-
throw new Error(
|
|
269
|
-
`Source map UUID ${imageUUID} does not match executable ${executableUUID}`,
|
|
270
|
-
)
|
|
271
|
-
}
|
|
272
|
-
const mapsObj = Reflect.get(parsed, 'maps')
|
|
273
|
-
if (mapsObj && typeof mapsObj === 'object') {
|
|
274
|
-
for (const [key, value] of Object.entries(mapsObj)) {
|
|
275
|
-
if (typeof value === 'string') empty.rawMaps[key] = value
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
const compiledFrames = Reflect.get(parsed, 'compiledFrames')
|
|
279
|
-
const entries =
|
|
280
|
-
compiledFrames && typeof compiledFrames === 'object'
|
|
281
|
-
? Reflect.get(compiledFrames, 'entries')
|
|
282
|
-
: null
|
|
283
|
-
const end =
|
|
284
|
-
compiledFrames && typeof compiledFrames === 'object'
|
|
285
|
-
? Reflect.get(compiledFrames, 'end')
|
|
286
|
-
: null
|
|
287
|
-
if (typeof end === 'number') empty.compiledEnd = end
|
|
288
|
-
if (Array.isArray(entries)) {
|
|
289
|
-
const frameRe = /^(\S+)\s+.*one-native-aot\/([a-f0-9]{64}\.[a-z.]+):(\d+)$/
|
|
290
|
-
for (const entry of entries) {
|
|
291
|
-
if (!entry || typeof entry !== 'object') continue
|
|
292
|
-
const name = Reflect.get(entry, 'name')
|
|
293
|
-
if (typeof name !== 'string') continue
|
|
294
|
-
const offset = Reflect.get(entry, 'offset')
|
|
295
|
-
if (typeof offset === 'number') empty.compiled.push({ offset, name })
|
|
296
|
-
const match = frameRe.exec(name)
|
|
297
|
-
if (!match) continue
|
|
298
|
-
const fn = match[1]!
|
|
299
|
-
const file = match[2]!
|
|
300
|
-
const line = Number(match[3])
|
|
301
|
-
if (fn.startsWith('(')) continue
|
|
302
|
-
const fk = `${file}|${fn}`
|
|
303
|
-
if (!empty.declByFileAndName.has(fk)) empty.declByFileAndName.set(fk, line)
|
|
304
|
-
if (!empty.declByName.has(fn)) empty.declByName.set(fn, { file, line })
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return empty
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function getDecodedMap(bundle: SourceMapBundle, fileKey: string): ParsedSourceMap | null {
|
|
311
|
-
if (bundle.decoded.has(fileKey)) return bundle.decoded.get(fileKey) ?? null
|
|
312
|
-
const raw = bundle.rawMaps[fileKey]
|
|
313
|
-
const parsed = raw ? decodeSourceMap(raw) : null
|
|
314
|
-
bundle.decoded.set(fileKey, parsed)
|
|
315
|
-
return parsed
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
function demangleAotSymbol(
|
|
319
|
-
bundle: SourceMapBundle,
|
|
320
|
-
fileKey: string | undefined,
|
|
321
|
-
fnName: string,
|
|
322
|
-
): { name?: string; source?: string; line?: number } | null {
|
|
323
|
-
if (!fnName || fnName.startsWith('(')) return null
|
|
324
|
-
const cacheKey = `${fileKey ?? ''}|${fnName}`
|
|
325
|
-
if (bundle.demangledCache.has(cacheKey))
|
|
326
|
-
return bundle.demangledCache.get(cacheKey) ?? null
|
|
327
|
-
let resolvedFile = fileKey
|
|
328
|
-
let declLine = fileKey
|
|
329
|
-
? bundle.declByFileAndName.get(`${fileKey}|${fnName}`)
|
|
330
|
-
: undefined
|
|
331
|
-
if (declLine === undefined) {
|
|
332
|
-
const byName = bundle.declByName.get(fnName)
|
|
333
|
-
if (byName) {
|
|
334
|
-
resolvedFile = byName.file
|
|
335
|
-
declLine = byName.line
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
if (!resolvedFile || declLine === undefined) {
|
|
339
|
-
bundle.demangledCache.set(cacheKey, null)
|
|
340
|
-
return null
|
|
341
|
-
}
|
|
342
|
-
const map = getDecodedMap(bundle, resolvedFile)
|
|
343
|
-
if (!map) {
|
|
344
|
-
bundle.demangledCache.set(cacheKey, null)
|
|
345
|
-
return null
|
|
346
|
-
}
|
|
347
|
-
const row = map.lines[declLine - 1]
|
|
348
|
-
let origName: string | undefined
|
|
349
|
-
let origSrc: string | undefined
|
|
350
|
-
let origLine: number | undefined
|
|
351
|
-
if (row) {
|
|
352
|
-
for (const seg of row) {
|
|
353
|
-
if (!origSrc && map.sources[seg.srcIdx]) {
|
|
354
|
-
origSrc = map.sources[seg.srcIdx]
|
|
355
|
-
origLine = seg.origLine + 1
|
|
356
|
-
}
|
|
357
|
-
if (seg.nameIdx >= 0 && map.names[seg.nameIdx]) {
|
|
358
|
-
origName = map.names[seg.nameIdx]
|
|
359
|
-
origSrc = map.sources[seg.srcIdx] || origSrc
|
|
360
|
-
origLine = seg.origLine + 1
|
|
361
|
-
break
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
const out =
|
|
366
|
-
origName || origSrc ? { name: origName, source: origSrc, line: origLine } : null
|
|
367
|
-
bundle.demangledCache.set(cacheKey, out)
|
|
368
|
-
return out
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
function resolveAotLocation(
|
|
372
|
-
bundle: SourceMapBundle,
|
|
373
|
-
url: string,
|
|
374
|
-
line1: number,
|
|
375
|
-
col1: number,
|
|
376
|
-
fnName: string,
|
|
377
|
-
): { url: string; line: number; column: number; name?: string } | null {
|
|
378
|
-
if (!url) return null
|
|
379
|
-
const match = /one-native-aot\/([a-f0-9]{64}\.[a-z.]+)$/.exec(url)
|
|
380
|
-
const fileKey = match ? match[1]! : basename(url)
|
|
381
|
-
const map = getDecodedMap(bundle, fileKey)
|
|
382
|
-
if (!map) return null
|
|
383
|
-
const demangled = demangleAotSymbol(bundle, fileKey, fnName)
|
|
384
|
-
if (line1 > 0) {
|
|
385
|
-
const resolved = lookupPosition(map, line1, Math.max(1, col1))
|
|
386
|
-
if (resolved) {
|
|
387
|
-
return {
|
|
388
|
-
url: resolved.source,
|
|
389
|
-
line: resolved.line,
|
|
390
|
-
column: resolved.column,
|
|
391
|
-
name: demangled?.name ?? resolved.name,
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
const fallbackSource = demangled?.source ?? map.sources[0]
|
|
396
|
-
if (!fallbackSource) return null
|
|
397
|
-
return {
|
|
398
|
-
url: fallbackSource,
|
|
399
|
-
line: demangled?.line ?? -1,
|
|
400
|
-
column: -1,
|
|
401
|
-
name: demangled?.name,
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
function symbolicateCpuProfile(cpuProfilePath: string, bundle: SourceMapBundle): void {
|
|
406
|
-
if (!Object.keys(bundle.rawMaps).length || !existsSync(cpuProfilePath)) return
|
|
407
|
-
const parsed: unknown = JSON.parse(readFileSync(cpuProfilePath, 'utf8'))
|
|
408
|
-
if (!parsed || typeof parsed !== 'object') return
|
|
409
|
-
const nodes = Reflect.get(parsed, 'nodes')
|
|
410
|
-
if (!Array.isArray(nodes)) return
|
|
411
|
-
let changed = false
|
|
412
|
-
for (const node of nodes) {
|
|
413
|
-
if (!node || typeof node !== 'object') continue
|
|
414
|
-
const frame = Reflect.get(node, 'callFrame')
|
|
415
|
-
if (!frame || typeof frame !== 'object') continue
|
|
416
|
-
const url = Reflect.get(frame, 'url')
|
|
417
|
-
const lineNumber = Reflect.get(frame, 'lineNumber')
|
|
418
|
-
const columnNumber = Reflect.get(frame, 'columnNumber')
|
|
419
|
-
const fnName = Reflect.get(frame, 'functionName')
|
|
420
|
-
if (typeof url !== 'string' || !url) continue
|
|
421
|
-
const resolved = resolveAotLocation(
|
|
422
|
-
bundle,
|
|
423
|
-
url,
|
|
424
|
-
typeof lineNumber === 'number' && lineNumber >= 0 ? lineNumber + 1 : -1,
|
|
425
|
-
typeof columnNumber === 'number' && columnNumber >= 0 ? columnNumber + 1 : 1,
|
|
426
|
-
typeof fnName === 'string' ? fnName : '',
|
|
427
|
-
)
|
|
428
|
-
if (!resolved) continue
|
|
429
|
-
Reflect.set(frame, 'url', resolved.url)
|
|
430
|
-
if (resolved.line > 0) Reflect.set(frame, 'lineNumber', resolved.line - 1)
|
|
431
|
-
if (resolved.column > 0) Reflect.set(frame, 'columnNumber', resolved.column - 1)
|
|
432
|
-
if (
|
|
433
|
-
resolved.name &&
|
|
434
|
-
(!fnName || fnName === '(anonymous)' || fnName !== resolved.name)
|
|
435
|
-
) {
|
|
436
|
-
Reflect.set(frame, 'functionName', resolved.name)
|
|
437
|
-
}
|
|
438
|
-
changed = true
|
|
439
|
-
}
|
|
440
|
-
if (changed) writeFileSync(cpuProfilePath, JSON.stringify(parsed))
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
function symbolicateTrace(tracePath: string, bundle: SourceMapBundle): void {
|
|
444
|
-
if (!bundle.declByName.size || !existsSync(tracePath)) return
|
|
445
|
-
const parsed: unknown = JSON.parse(readFileSync(tracePath, 'utf8'))
|
|
446
|
-
if (!parsed || typeof parsed !== 'object') return
|
|
447
|
-
const events = Reflect.get(parsed, 'traceEvents')
|
|
448
|
-
if (!Array.isArray(events)) return
|
|
449
|
-
let changed = false
|
|
450
|
-
for (const ev of events) {
|
|
451
|
-
if (!ev || typeof ev !== 'object') continue
|
|
452
|
-
if (ev.cat === 'react' && ev.name === 'ReactCommit' && isRecord(ev.args)) {
|
|
453
|
-
if (symbolicateReactNames(ev.args.components, bundle)) changed = true
|
|
454
|
-
continue
|
|
455
|
-
}
|
|
456
|
-
if (Reflect.get(ev, 'cat') !== 'js.sample') continue
|
|
457
|
-
const name = Reflect.get(ev, 'name')
|
|
458
|
-
if (typeof name !== 'string' || !name || name.startsWith('(')) continue
|
|
459
|
-
const demangled = demangleAotSymbol(bundle, undefined, name)
|
|
460
|
-
if (demangled?.name && demangled.name !== name) {
|
|
461
|
-
Reflect.set(ev, 'name', demangled.name)
|
|
462
|
-
changed = true
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
if (changed) writeFileSync(tracePath, JSON.stringify(parsed))
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
type ProfileLocation = Pick<NativeProfileFunction, 'name' | 'url' | 'line' | 'column'>
|
|
469
|
-
|
|
470
|
-
function symbolicateFnList(list: ProfileLocation[], bundle: SourceMapBundle): void {
|
|
471
|
-
for (const entry of list) {
|
|
472
|
-
const resolved = resolveAotLocation(
|
|
473
|
-
bundle,
|
|
474
|
-
entry.url,
|
|
475
|
-
entry.line,
|
|
476
|
-
entry.column,
|
|
477
|
-
entry.name,
|
|
478
|
-
)
|
|
479
|
-
if (!resolved) continue
|
|
480
|
-
entry.url = resolved.url
|
|
481
|
-
if (resolved.line > 0) entry.line = resolved.line
|
|
482
|
-
if (resolved.column > 0) entry.column = resolved.column
|
|
483
|
-
if (resolved.name) entry.name = resolved.name
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
function symbolicateReport(report: NativeProfileReport, bundle: SourceMapBundle): void {
|
|
488
|
-
if (Object.keys(bundle.rawMaps).length) {
|
|
489
|
-
symbolicateFnList(report.topJsFunctions, bundle)
|
|
490
|
-
if (report.topJsCallers) symbolicateFnList(report.topJsCallers, bundle)
|
|
491
|
-
if (report.topInterpretedJsFunctions)
|
|
492
|
-
symbolicateFnList(report.topInterpretedJsFunctions, bundle)
|
|
493
|
-
symbolicateReactNames(report.topReactComponents, bundle)
|
|
494
|
-
}
|
|
495
|
-
if (report.executableUUID)
|
|
496
|
-
symbolicateNativeFrames([report], bundle, report.executableUUID)
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
function symbolicateReactNames(components: unknown, bundle: SourceMapBundle): boolean {
|
|
500
|
-
let changed = false
|
|
501
|
-
for (const comp of records(components)) {
|
|
502
|
-
if (typeof comp.name !== 'string') continue
|
|
503
|
-
const demangled = demangleAotSymbol(bundle, undefined, comp.name)
|
|
504
|
-
if (!demangled) continue
|
|
505
|
-
const name = demangled.name ?? comp.name
|
|
506
|
-
const file = demangled.source && basename(demangled.source)
|
|
507
|
-
const location = file && (demangled.line ? `${file}:${demangled.line}` : file)
|
|
508
|
-
const label = location ? `${name} (${location})` : name
|
|
509
|
-
if (label === comp.name) continue
|
|
510
|
-
comp.name = label
|
|
511
|
-
changed = true
|
|
512
|
-
}
|
|
513
|
-
return changed
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// the device names an app frame it has no symbol for as image`0x<offset of the function start>.
|
|
517
|
-
const rawNativeFrame = /^([^`]+)`0x([0-9a-f]+)$/
|
|
518
|
-
const aotFrame = /^(\S+) (\S*one-native-aot\/[a-f0-9]{64}\.[a-z.]+):(\d+)/
|
|
519
|
-
const bridgeFrame =
|
|
520
|
-
/PeachJSC|JscRuntime|facebook::jsi::|margelo::nitro::|JSObjectCallAsFunction|JSObjectMakeFunction|bridge_watch/
|
|
521
|
-
const engineFrame = /`(?:JSC::|WTF::|llint_|jsc_llint|bmalloc)/
|
|
522
|
-
|
|
523
|
-
type NativeLayer = 'JS' | 'Bridge' | 'Native'
|
|
524
|
-
|
|
525
|
-
// names the app image's frames for one executable UUID: compiled javascript through the
|
|
526
|
-
// source map's compiled frame table, everything else through atos and the matching dSYM.
|
|
527
|
-
class AppImageSymbols {
|
|
528
|
-
private readonly names = new Map<number, string>()
|
|
529
|
-
private readonly pending = new Set<number>()
|
|
530
|
-
private constructor(
|
|
531
|
-
private readonly bundle: SourceMapBundle,
|
|
532
|
-
private readonly image: string,
|
|
533
|
-
private readonly dwarf: string | undefined,
|
|
534
|
-
) {}
|
|
535
|
-
|
|
536
|
-
get hasDsym(): boolean {
|
|
537
|
-
return this.dwarf !== undefined
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
// the executable is the image that owns main, so its compiled javascript resolves without a dSYM.
|
|
541
|
-
static load(
|
|
542
|
-
bundle: SourceMapBundle,
|
|
543
|
-
uuid: string,
|
|
544
|
-
frames: string[],
|
|
545
|
-
directories: string[],
|
|
546
|
-
warn: boolean,
|
|
547
|
-
): AppImageSymbols {
|
|
548
|
-
const dwarf = findDsymBinary([bundle.directory, ...directories], uuid)
|
|
549
|
-
if (!dwarf && warn)
|
|
550
|
-
console.error(`no dSYM found for ${uuid}; native app frames keep their offsets`)
|
|
551
|
-
const image = dwarf
|
|
552
|
-
? basename(dwarf)
|
|
553
|
-
: (frames.find((frame) => frame.endsWith('`main'))?.slice(0, -'`main'.length) ?? '')
|
|
554
|
-
return new AppImageSymbols(bundle, image, dwarf)
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
want(frame: string): void {
|
|
558
|
-
const offset = this.offset(frame)
|
|
559
|
-
if (offset === undefined || this.compiled(offset) || this.names.has(offset)) return
|
|
560
|
-
this.pending.add(offset)
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
resolve(): void {
|
|
564
|
-
if (!this.dwarf || !this.pending.size) return
|
|
565
|
-
const offsets = [...this.pending]
|
|
566
|
-
this.pending.clear()
|
|
567
|
-
const lines = execFileSync(
|
|
568
|
-
'xcrun',
|
|
569
|
-
['atos', '-o', this.dwarf, '-arch', 'arm64', '-offset'],
|
|
570
|
-
{
|
|
571
|
-
input: offsets.map((offset) => `0x${offset.toString(16)}`).join('\n'),
|
|
572
|
-
encoding: 'utf8',
|
|
573
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
574
|
-
},
|
|
575
|
-
).split('\n')
|
|
576
|
-
offsets.forEach((offset, i) => {
|
|
577
|
-
const match = /^(.*?) \(in [^)]+\)(?: \+ \d+)?(?: \((.+)\))?$/.exec(lines[i] ?? '')
|
|
578
|
-
if (match?.[1] && !match[1].startsWith('0x'))
|
|
579
|
-
this.names.set(
|
|
580
|
-
offset,
|
|
581
|
-
`${this.image}\`${match[1]}${match[2] ? ` (${match[2]})` : ''}`,
|
|
582
|
-
)
|
|
583
|
-
})
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
name(frame: string): { layer: NativeLayer; name: string } {
|
|
587
|
-
const offset = this.offset(frame)
|
|
588
|
-
let name = frame
|
|
589
|
-
if (offset !== undefined) {
|
|
590
|
-
const entry = this.compiled(offset)
|
|
591
|
-
const js = entry && aotFrame.exec(entry.name)
|
|
592
|
-
if (js) {
|
|
593
|
-
const location = resolveAotLocation(this.bundle, js[2]!, Number(js[3]), 1, js[1]!)
|
|
594
|
-
const fn = location?.name ?? js[1]!
|
|
595
|
-
const source = location ? formatLocation(location.url, location.line) : ''
|
|
596
|
-
return { layer: 'JS', name: source ? `${fn} (${source})` : fn }
|
|
597
|
-
}
|
|
598
|
-
if (entry?.name.includes(' /$bun/js/')) return { layer: 'JS', name: entry.name }
|
|
599
|
-
name = entry ? `${this.image}\`${entry.name}` : (this.names.get(offset) ?? frame)
|
|
600
|
-
}
|
|
601
|
-
if (bridgeFrame.test(name)) return { layer: 'Bridge', name }
|
|
602
|
-
return { layer: engineFrame.test(name) ? 'JS' : 'Native', name }
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
private offset(frame: string): number | undefined {
|
|
606
|
-
const match = rawNativeFrame.exec(frame)
|
|
607
|
-
return match && match[1] === this.image ? Number.parseInt(match[2]!, 16) : undefined
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
private compiled(offset: number) {
|
|
611
|
-
const { compiled, compiledEnd } = this.bundle
|
|
612
|
-
if (!compiled.length || offset < compiled[0]!.offset || offset >= compiledEnd) return
|
|
613
|
-
let low = 0
|
|
614
|
-
let high = compiled.length - 1
|
|
615
|
-
while (low < high) {
|
|
616
|
-
const mid = (low + high + 1) >> 1
|
|
617
|
-
if (compiled[mid]!.offset <= offset) low = mid
|
|
618
|
-
else high = mid - 1
|
|
619
|
-
}
|
|
620
|
-
return compiled[low]
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
// the build keeps OneNativeSymbols-<uuid>.dSYM beside its source map; spotlight finds a dSYM
|
|
625
|
-
// that was moved or archived anywhere else.
|
|
626
|
-
function findDsymBinary(directories: string[], uuid: string): string | undefined {
|
|
627
|
-
if (process.platform !== 'darwin' || !profileUUID.test(uuid)) return
|
|
628
|
-
const bundles = (function* () {
|
|
629
|
-
for (const dir of new Set(directories.filter(Boolean))) {
|
|
630
|
-
yield join(dir, `OneNativeSymbols-${uuid}.dSYM`)
|
|
631
|
-
const archives = join(dir, 'dSYMs')
|
|
632
|
-
if (existsSync(archives))
|
|
633
|
-
for (const bundle of readdirSync(archives))
|
|
634
|
-
if (bundle.endsWith('.dSYM')) yield join(archives, bundle)
|
|
635
|
-
}
|
|
636
|
-
const indexed = spawnSync('mdfind', [`com_apple_xcode_dsym_uuids == '${uuid}'`], {
|
|
637
|
-
encoding: 'utf8',
|
|
638
|
-
})
|
|
639
|
-
yield* indexed.stdout?.split('\n').filter(Boolean) ?? []
|
|
640
|
-
})()
|
|
641
|
-
for (const bundle of bundles) {
|
|
642
|
-
const dwarfDirectory = join(bundle, 'Contents/Resources/DWARF')
|
|
643
|
-
if (!bundle || !existsSync(dwarfDirectory)) continue
|
|
644
|
-
for (const name of readdirSync(dwarfDirectory)) {
|
|
645
|
-
const binary = join(dwarfDirectory, name)
|
|
646
|
-
const uuids = spawnSync('xcrun', ['dwarfdump', '--uuid', binary], {
|
|
647
|
-
encoding: 'utf8',
|
|
648
|
-
}).stdout
|
|
649
|
-
if (uuids?.toUpperCase().includes(`UUID: ${uuid.toUpperCase()} (ARM64)`))
|
|
650
|
-
return binary
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
// every native frame list a report or snapshot carries, renamed in place. worstStall and
|
|
656
|
-
// slowBridgeCalls trade their leaf-first nativeStack for one stack read from the root down,
|
|
657
|
-
// each frame tagged with the layer it runs in.
|
|
658
|
-
function nativeFrameLists(report: Record<string, unknown>) {
|
|
659
|
-
const entries = ['topNativeSelf', 'topNativeInclusive', 'topNativeStacks'].flatMap(
|
|
660
|
-
(key) => {
|
|
661
|
-
const list = report[key]
|
|
662
|
-
return Array.isArray(list) ? list.filter(isRecord) : []
|
|
663
|
-
},
|
|
664
|
-
)
|
|
665
|
-
const stacks = [
|
|
666
|
-
report.worstStall,
|
|
667
|
-
...(Array.isArray(report.slowBridgeCalls) ? report.slowBridgeCalls : []),
|
|
668
|
-
].filter(isRecord)
|
|
669
|
-
const framesOf = (row: Record<string, unknown>) =>
|
|
670
|
-
Array.isArray(row.nativeStack)
|
|
671
|
-
? row.nativeStack.filter((frame): frame is string => typeof frame === 'string')
|
|
672
|
-
: []
|
|
673
|
-
return {
|
|
674
|
-
frames: [
|
|
675
|
-
...entries.flatMap((entry) =>
|
|
676
|
-
typeof entry.name === 'string' ? entry.name.split(' > ') : [],
|
|
677
|
-
),
|
|
678
|
-
...stacks.flatMap(framesOf),
|
|
679
|
-
],
|
|
680
|
-
rename(symbols: AppImageSymbols) {
|
|
681
|
-
for (const entry of entries) {
|
|
682
|
-
if (typeof entry.name !== 'string') continue
|
|
683
|
-
entry.name = entry.name
|
|
684
|
-
.split(' > ')
|
|
685
|
-
.map((frame) => symbols.name(frame).name)
|
|
686
|
-
.join(' > ')
|
|
687
|
-
}
|
|
688
|
-
for (const key of ['topNativeSelf', 'topNativeStacks'] as const) {
|
|
689
|
-
const list = report[key]
|
|
690
|
-
if (!Array.isArray(list)) continue
|
|
691
|
-
const merged = new Map<string, number>()
|
|
692
|
-
for (const row of list) {
|
|
693
|
-
if (!isRecord(row) || typeof row.name !== 'string') continue
|
|
694
|
-
merged.set(row.name, (merged.get(row.name) ?? 0) + asNum(row.samples))
|
|
695
|
-
}
|
|
696
|
-
report[key] = [...merged.entries()]
|
|
697
|
-
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
698
|
-
.map(([name, samples]) => ({ name, samples }))
|
|
699
|
-
}
|
|
700
|
-
for (const row of stacks) {
|
|
701
|
-
if (!Array.isArray(row.nativeStack)) continue
|
|
702
|
-
row.stack = framesOf(row)
|
|
703
|
-
.reverse()
|
|
704
|
-
.map((frame) => {
|
|
705
|
-
const { layer, name } = symbols.name(frame)
|
|
706
|
-
return `${layer}: ${name}`
|
|
707
|
-
})
|
|
708
|
-
delete row.nativeStack
|
|
709
|
-
}
|
|
710
|
-
},
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
function symbolicateNativeFrames(
|
|
715
|
-
reports: Record<string, unknown>[],
|
|
716
|
-
bundle: SourceMapBundle,
|
|
717
|
-
uuid: string,
|
|
718
|
-
directories: string[] = [],
|
|
719
|
-
warn = true,
|
|
720
|
-
) {
|
|
721
|
-
const lists = reports.map(nativeFrameLists)
|
|
722
|
-
const symbols = AppImageSymbols.load(
|
|
723
|
-
bundle,
|
|
724
|
-
uuid,
|
|
725
|
-
lists.flatMap((list) => list.frames),
|
|
726
|
-
directories,
|
|
727
|
-
warn,
|
|
728
|
-
)
|
|
729
|
-
for (const list of lists) for (const frame of list.frames) symbols.want(frame)
|
|
730
|
-
symbols.resolve()
|
|
731
|
-
for (const list of lists) list.rename(symbols)
|
|
732
|
-
return symbols.hasDsym
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
export const profileUUID = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i
|
|
736
|
-
|
|
737
|
-
export function symbolicateDiagnosticReports(
|
|
738
|
-
reports: NativeProfileReport[],
|
|
739
|
-
uuid: string,
|
|
740
|
-
sourceMaps: string | undefined,
|
|
741
|
-
directories: string[],
|
|
742
|
-
) {
|
|
743
|
-
const maps = loadSourceMapsBundle(sourceMaps, uuid)
|
|
744
|
-
const stacks = reports.map(({ worstStall, slowBridgeCalls }) => ({
|
|
745
|
-
worstStall,
|
|
746
|
-
slowBridgeCalls,
|
|
747
|
-
}))
|
|
748
|
-
return symbolicateNativeFrames(stacks, maps, uuid, directories, false)
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
function symbolicateTelemetry(
|
|
752
|
-
input: string,
|
|
753
|
-
mapsPath: string,
|
|
754
|
-
filter: SpanFilter,
|
|
755
|
-
): string {
|
|
756
|
-
const mapDirectory = statSync(mapsPath).isDirectory()
|
|
757
|
-
const snapshots: Record<string, unknown>[] = []
|
|
758
|
-
const byUUID = new Map<string, Record<string, unknown>[]>()
|
|
759
|
-
const filterSpans = filter.kinds.length > 0 || filter.route || filter.target
|
|
760
|
-
for (const line of readFileSync(input, 'utf8').split('\n')) {
|
|
761
|
-
if (!line.trim()) continue
|
|
762
|
-
const row: unknown = JSON.parse(line)
|
|
763
|
-
if (!isRecord(row)) continue
|
|
764
|
-
const snapshot = isRecord(row.details) ? row.details : row
|
|
765
|
-
const { executableUUID, topJsFunctions, topReactComponents } = snapshot
|
|
766
|
-
if (
|
|
767
|
-
typeof executableUUID !== 'string' ||
|
|
768
|
-
!profileUUID.test(executableUUID) ||
|
|
769
|
-
!Array.isArray(topJsFunctions) ||
|
|
770
|
-
!Array.isArray(topReactComponents)
|
|
771
|
-
)
|
|
772
|
-
continue
|
|
773
|
-
|
|
774
|
-
if (filterSpans) {
|
|
775
|
-
const spans = records(snapshot.spans).filter(
|
|
776
|
-
(span) => spanGroupKey(span, filter) !== undefined,
|
|
777
|
-
)
|
|
778
|
-
if (!spans.length) continue
|
|
779
|
-
snapshot.spans = spans
|
|
780
|
-
}
|
|
781
|
-
snapshots.push(row)
|
|
782
|
-
const reports = byUUID.get(executableUUID)
|
|
783
|
-
if (reports) reports.push(snapshot)
|
|
784
|
-
else byUUID.set(executableUUID, [snapshot])
|
|
785
|
-
}
|
|
786
|
-
if (!snapshots.length && !filterSpans)
|
|
787
|
-
throw new Error(`No profiler telemetry snapshots in ${input}`)
|
|
788
|
-
|
|
789
|
-
const toLocations = (list: unknown): ProfileLocation[] =>
|
|
790
|
-
Array.isArray(list)
|
|
791
|
-
? list.filter(
|
|
792
|
-
(entry: unknown): entry is ProfileLocation =>
|
|
793
|
-
isRecord(entry) &&
|
|
794
|
-
typeof entry.name === 'string' &&
|
|
795
|
-
typeof entry.url === 'string' &&
|
|
796
|
-
typeof entry.line === 'number' &&
|
|
797
|
-
typeof entry.column === 'number',
|
|
798
|
-
)
|
|
799
|
-
: []
|
|
800
|
-
for (const [uuid, reports] of byUUID) {
|
|
801
|
-
const expected = `OneJavaScriptSourceMaps-${uuid}.json`
|
|
802
|
-
const mapFile = mapDirectory ? join(mapsPath, expected) : mapsPath
|
|
803
|
-
if (basename(mapFile) !== expected || !existsSync(mapFile)) {
|
|
804
|
-
if (!mapDirectory) throw new Error(`Missing exact source map ${expected}`)
|
|
805
|
-
console.error(`Missing ${expected}; leaving its telemetry unsymbolicated`)
|
|
806
|
-
continue
|
|
807
|
-
}
|
|
808
|
-
const bundle = loadSourceMapsBundle(mapFile, uuid)
|
|
809
|
-
if (!Object.keys(bundle.rawMaps).length)
|
|
810
|
-
throw new Error(`No source maps in ${mapFile}`)
|
|
811
|
-
for (const snapshot of reports) {
|
|
812
|
-
const jsFunctions = toLocations(snapshot.topJsFunctions)
|
|
813
|
-
const interpretedJsFunctions = toLocations(snapshot.topInterpretedJsFunctions)
|
|
814
|
-
const components = records(snapshot.topReactComponents).filter(
|
|
815
|
-
(entry): entry is { name: string } => typeof entry.name === 'string',
|
|
816
|
-
)
|
|
817
|
-
symbolicateFnList(jsFunctions, bundle)
|
|
818
|
-
if (interpretedJsFunctions.length) symbolicateFnList(interpretedJsFunctions, bundle)
|
|
819
|
-
symbolicateReactNames(components, bundle)
|
|
820
|
-
}
|
|
821
|
-
symbolicateNativeFrames(reports, bundle, uuid)
|
|
822
|
-
}
|
|
823
|
-
return `${JSON.stringify(snapshots, null, 2)}\n`
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
function detectSimulatorBundleId(udid: string): string {
|
|
827
|
-
const running = runningSimulatorApps(udid)
|
|
828
|
-
if (running.length === 1) return running[0]!
|
|
829
|
-
if (running.length > 1) {
|
|
830
|
-
throw new Error(
|
|
831
|
-
`Multiple user apps are running on simulator ${udid}: ${running.join(', ')}. Pass --bundle-id <id>.`,
|
|
832
|
-
)
|
|
833
|
-
}
|
|
834
|
-
throw new Error(
|
|
835
|
-
`No running user app found on simulator ${udid}. Launch your app or pass --bundle-id <id>.`,
|
|
836
|
-
)
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
export function runningSimulatorApps(udid: string): string[] {
|
|
840
|
-
const list = execFileSync('xcrun', ['simctl', 'spawn', udid, 'launchctl', 'list'], {
|
|
841
|
-
encoding: 'utf8',
|
|
842
|
-
})
|
|
843
|
-
const running: string[] = []
|
|
844
|
-
for (const line of list.split('\n')) {
|
|
845
|
-
const match = /^\s*(\d+)\s+\S+\s+UIKitApplication:([^[]+)\[/.exec(line)
|
|
846
|
-
if (!match) continue
|
|
847
|
-
const id = match[2]!.trim()
|
|
848
|
-
if (!id.startsWith('com.apple.')) running.push(id)
|
|
849
|
-
}
|
|
850
|
-
return running
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
function simContainer(udid: string, bundleId: string): string {
|
|
854
|
-
return execFileSync('xcrun', ['simctl', 'get_app_container', udid, bundleId, 'data'], {
|
|
855
|
-
encoding: 'utf8',
|
|
856
|
-
}).trim()
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
async function waitForFile(path: string, timeoutMs: number): Promise<string> {
|
|
860
|
-
const deadline = Date.now() + timeoutMs
|
|
861
|
-
while (Date.now() < deadline) {
|
|
862
|
-
if (existsSync(path)) {
|
|
863
|
-
const content = readFileSync(path, 'utf8')
|
|
864
|
-
if (content.trim().startsWith('{')) return content
|
|
865
|
-
}
|
|
866
|
-
await new Promise((r) => setTimeout(r, 150))
|
|
867
|
-
}
|
|
868
|
-
throw new Error(`Timed out after ${timeoutMs}ms waiting for profiler result at ${path}`)
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
export async function requestSimulatorProfile(
|
|
872
|
-
udid: string,
|
|
873
|
-
bundleId: string,
|
|
874
|
-
payload: { id: string; action: string } & Record<string, unknown>,
|
|
875
|
-
timeoutMs: number,
|
|
876
|
-
): Promise<string> {
|
|
877
|
-
const profilerDir = join(
|
|
878
|
-
simContainer(udid, bundleId),
|
|
879
|
-
'Library/Application Support/OneProfiler',
|
|
880
|
-
)
|
|
881
|
-
mkdirSync(profilerDir, { recursive: true })
|
|
882
|
-
const resultFile = join(profilerDir, `result-${payload.id}.json`)
|
|
883
|
-
writeFileSync(join(profilerDir, 'command.json'), JSON.stringify(payload))
|
|
884
|
-
try {
|
|
885
|
-
execFileSync('xcrun', [
|
|
886
|
-
'simctl',
|
|
887
|
-
'notify_post',
|
|
888
|
-
udid,
|
|
889
|
-
`dev.one.profiler.command.${bundleId}`,
|
|
890
|
-
])
|
|
891
|
-
return await waitForFile(resultFile, timeoutMs)
|
|
892
|
-
} finally {
|
|
893
|
-
rmSync(resultFile, { force: true })
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
function formatLocation(url: string, line: number): string {
|
|
898
|
-
if (!url) return ''
|
|
899
|
-
const parts = url.split('/')
|
|
900
|
-
const short = parts.length > 2 ? parts.slice(-2).join('/') : url
|
|
901
|
-
return line > 0 ? `${short}:${line}` : short
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
function printSummary(
|
|
905
|
-
report: NativeProfileReport,
|
|
906
|
-
outFiles: { cpuprofile: string; trace: string; summary: string },
|
|
907
|
-
filter: SpanFilter,
|
|
908
|
-
): void {
|
|
909
|
-
console.log(
|
|
910
|
-
`One Profiler: ${report.bundleId || 'app'} (build ${report.build}, route ${report.route})`,
|
|
911
|
-
)
|
|
912
|
-
console.log(
|
|
913
|
-
` duration: ${report.durationMs.toFixed(1)} ms | fps: ${report.fps.toFixed(1)} (${report.frames} frames, ${report.droppedFrames} dropped, longest ${report.longestFrameMs.toFixed(1)} ms)`,
|
|
914
|
-
)
|
|
915
|
-
console.log(
|
|
916
|
-
` main thread busy: ${report.mainThreadBusyMs.toFixed(1)} ms (${report.mainThreadBusyPct.toFixed(1)}%) | JS ${report.jsMs.toFixed(1)} ms | Native ${report.nativeMs.toFixed(1)} ms`,
|
|
917
|
-
)
|
|
918
|
-
|
|
919
|
-
const phaseRows = Object.entries(report.phases)
|
|
920
|
-
.filter(([, ms]) => ms > 0.05)
|
|
921
|
-
.sort((a, b) => b[1] - a[1])
|
|
922
|
-
if (phaseRows.length) {
|
|
923
|
-
console.log('\nTop native & runtime phases:')
|
|
924
|
-
const denom = Math.max(1, report.mainThreadBusyMs)
|
|
925
|
-
for (const [name, ms] of phaseRows.slice(0, 10)) {
|
|
926
|
-
const pct = ((ms / denom) * 100).toFixed(1)
|
|
927
|
-
console.log(
|
|
928
|
-
` ${name.padEnd(16)} ${ms.toFixed(1).padStart(8)} ms (${pct.padStart(5)}%)`,
|
|
929
|
-
)
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
const formatTier = (fn: NativeProfileFunction): string => {
|
|
934
|
-
if (!fn.tier) return ''
|
|
935
|
-
return fn.builtin ? ` [${fn.tier}:builtin]` : ` [${fn.tier}]`
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
if (report.jsTiers) {
|
|
939
|
-
const t = report.jsTiers
|
|
940
|
-
const total =
|
|
941
|
-
t.aot + t.interpreter + t.jit + t.host + t.native + t.regexp + t.wasm + t.unknown
|
|
942
|
-
if (total > 0) {
|
|
943
|
-
const pct = (n: number) => `${((n / total) * 100).toFixed(1)}%`
|
|
944
|
-
const parts = [
|
|
945
|
-
`aot ${t.aot} (${pct(t.aot)})`,
|
|
946
|
-
`interpreter ${t.interpreter} (${pct(t.interpreter)}${t.interpreterBuiltin ? `, ${t.interpreterBuiltin} builtin` : ''})`,
|
|
947
|
-
`host ${t.host} (${pct(t.host)})`,
|
|
948
|
-
`native ${t.native} (${pct(t.native)})`,
|
|
949
|
-
]
|
|
950
|
-
if (t.jit) parts.push(`jit ${t.jit} (${pct(t.jit)})`)
|
|
951
|
-
if (t.regexp) parts.push(`regexp ${t.regexp} (${pct(t.regexp)})`)
|
|
952
|
-
if (t.wasm) parts.push(`wasm ${t.wasm} (${pct(t.wasm)})`)
|
|
953
|
-
if (t.unknown) parts.push(`unknown ${t.unknown} (${pct(t.unknown)})`)
|
|
954
|
-
console.log(`\nJS execution tiers (${total} leaf samples): ${parts.join(' | ')}`)
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
if (report.topJsFunctions.length) {
|
|
959
|
-
console.log(`\nTop JS functions by self time (${report.jsSamples} samples):`)
|
|
960
|
-
for (const fn of report.topJsFunctions.slice(0, 15)) {
|
|
961
|
-
const loc = formatLocation(fn.url, fn.line)
|
|
962
|
-
console.log(
|
|
963
|
-
` ${fn.selfMs.toFixed(1).padStart(7)} ms self (${fn.selfPct.toFixed(1).padStart(5)}%) | ${fn.totalMs.toFixed(1).padStart(7)} ms total | ${fn.name}${formatTier(fn)}${loc ? ` (${loc})` : ''}`,
|
|
964
|
-
)
|
|
965
|
-
}
|
|
966
|
-
} else {
|
|
967
|
-
console.log(`\nTop JS functions: none (${report.jsSamples} samples)`)
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
if (report.topInterpretedJsFunctions && report.topInterpretedJsFunctions.length) {
|
|
971
|
-
const interpLeaf = report.jsTiers?.interpreter ?? 0
|
|
972
|
-
console.log(
|
|
973
|
-
`\nTop interpreted JS functions (${interpLeaf} leaf samples of ${report.jsSamples} total):`,
|
|
974
|
-
)
|
|
975
|
-
for (const fn of report.topInterpretedJsFunctions.slice(0, 15)) {
|
|
976
|
-
const loc = formatLocation(fn.url, fn.line)
|
|
977
|
-
const interpShare =
|
|
978
|
-
interpLeaf > 0
|
|
979
|
-
? ` (${((fn.selfSamples / interpLeaf) * 100).toFixed(1)}% interp)`
|
|
980
|
-
: ''
|
|
981
|
-
console.log(
|
|
982
|
-
` ${String(fn.selfSamples).padStart(4)} self${interpShare} | ${String(fn.totalSamples).padStart(4)} total | ${fn.name}${fn.builtin ? ' [builtin]' : ''}${loc ? ` (${loc})` : ''}`,
|
|
983
|
-
)
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
if (report.topJsCallers && report.topJsCallers.length) {
|
|
988
|
-
console.log('\nTop JS callers by inclusive time:')
|
|
989
|
-
for (const fn of report.topJsCallers.slice(0, 10)) {
|
|
990
|
-
const loc = formatLocation(fn.url, fn.line)
|
|
991
|
-
console.log(
|
|
992
|
-
` ${fn.totalMs.toFixed(1).padStart(7)} ms total (${String(fn.totalSamples).padStart(3)} samples) | ${fn.selfMs.toFixed(1).padStart(6)} ms self | ${fn.name}${formatTier(fn)}${loc ? ` (${loc})` : ''}`,
|
|
993
|
-
)
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
if (report.topReactComponents.length) {
|
|
998
|
-
console.log(`\nTop React components (${report.reactCommits} commits):`)
|
|
999
|
-
for (const comp of report.topReactComponents.slice(0, 10)) {
|
|
1000
|
-
const timing =
|
|
1001
|
-
comp.totalMs > 0 ? `${comp.totalMs.toFixed(1)} ms` : `${comp.renders} renders`
|
|
1002
|
-
console.log(
|
|
1003
|
-
` ${comp.name.padEnd(36)} ${timing.padStart(12)} (${comp.commits} commits)`,
|
|
1004
|
-
)
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
const leafFrames = (row: Record<string, unknown>) =>
|
|
1009
|
-
(Array.isArray(row.stack)
|
|
1010
|
-
? row.stack
|
|
1011
|
-
: Array.isArray(row.nativeStack)
|
|
1012
|
-
? [...row.nativeStack].reverse()
|
|
1013
|
-
: []
|
|
1014
|
-
)
|
|
1015
|
-
.slice(-8)
|
|
1016
|
-
.map((frame) => ` ${String(frame)}`)
|
|
1017
|
-
const stall = report.worstStall
|
|
1018
|
-
if (stall) {
|
|
1019
|
-
console.log(
|
|
1020
|
-
`\nWorst stall (${report.turnsOver16ms} turns over 16 ms): ${asNum(stall.durationMs).toFixed(1)} ms in ${asStr(stall.phase)}, ${stall.idle === true ? 'idle' : 'during interaction'}`,
|
|
1021
|
-
)
|
|
1022
|
-
for (const line of leafFrames(stall)) console.log(line)
|
|
1023
|
-
}
|
|
1024
|
-
if (report.slowBridgeCalls.length) {
|
|
1025
|
-
console.log(`\nSlow bridge calls (${report.slowBridgeTotal} over 256 KB or 4 ms):`)
|
|
1026
|
-
const slowest = [...report.slowBridgeCalls]
|
|
1027
|
-
.sort((left, right) => asNum(right.durationMs) - asNum(left.durationMs))
|
|
1028
|
-
.slice(0, 5)
|
|
1029
|
-
for (const call of slowest) {
|
|
1030
|
-
console.log(
|
|
1031
|
-
` ${asStr(call.op)}: ${(asNum(call.bytes) / 1024).toFixed(0)} KB in ${asNum(call.durationMs).toFixed(1)} ms`,
|
|
1032
|
-
)
|
|
1033
|
-
for (const line of leafFrames(call)) console.log(line)
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
if (report.budget) {
|
|
1037
|
-
const state = (name: string, value: unknown) => {
|
|
1038
|
-
const row = isRecord(value) ? value : {}
|
|
1039
|
-
return ` ${name} ${asNum(row.seconds).toFixed(1)} s: ${asNum(row.busyMsPerSec).toFixed(1)} ms/s busy, ${asNum(row.droppedFrames)} dropped, ${asNum(row.commitsPerSec).toFixed(1)} commits/s`
|
|
1040
|
-
}
|
|
1041
|
-
console.log('\nIdle vs interaction:')
|
|
1042
|
-
console.log(state('Idle', report.budget.idle))
|
|
1043
|
-
console.log(state('Interaction', report.budget.interaction))
|
|
1044
|
-
for (const alarm of records(report.budget.alarms))
|
|
1045
|
-
console.log(` ${asStr(alarm.title)}: ${asStr(alarm.detail)}`)
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
printSpanGroups(groupSpans(report.spans, filter))
|
|
1049
|
-
printLargestInteractionGaps(
|
|
1050
|
-
report.spans.map((span) => ({ span, executableUUID: report.executableUUID })),
|
|
1051
|
-
filter,
|
|
1052
|
-
)
|
|
1053
|
-
|
|
1054
|
-
console.log('\nArtifacts:')
|
|
1055
|
-
console.log(` cpuprofile: ${outFiles.cpuprofile}`)
|
|
1056
|
-
console.log(` trace: ${outFiles.trace}`)
|
|
1057
|
-
console.log(` summary: ${outFiles.summary}`)
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
type SpanFilter = { kinds: string[]; route?: string; target?: string }
|
|
1061
|
-
|
|
1062
|
-
type SpanGroup = {
|
|
1063
|
-
kind: string
|
|
1064
|
-
target: string
|
|
1065
|
-
spans: number
|
|
1066
|
-
durationMs: number
|
|
1067
|
-
fpsP50: number
|
|
1068
|
-
fpsP95: number
|
|
1069
|
-
droppedFrames: number
|
|
1070
|
-
longestFrameMs: number
|
|
1071
|
-
worstStall: { durationMs: number; phase: string; route: string } | null
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
// the value that share of spans reached or beat, so fps p95 is the slow tail
|
|
1075
|
-
function percentileFloor(sorted: number[], share: number): number {
|
|
1076
|
-
return sorted[Math.min(sorted.length - 1, Math.ceil(share * sorted.length) - 1)] ?? 0
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
function spanGroupKey(
|
|
1080
|
-
span: Record<string, unknown>,
|
|
1081
|
-
filter: SpanFilter,
|
|
1082
|
-
): string | undefined {
|
|
1083
|
-
const kind = asStr(span.kind)
|
|
1084
|
-
const route = asStr(span.route)
|
|
1085
|
-
const target = kind === 'idle' ? route : asStr(span.target) || route
|
|
1086
|
-
if (filter.kinds.length && !filter.kinds.includes(kind)) return
|
|
1087
|
-
if (filter.route && !route.includes(filter.route)) return
|
|
1088
|
-
if (filter.target && !target.includes(filter.target)) return
|
|
1089
|
-
return `${kind}\u0000${target}`
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
// groups interaction spans by kind and target; idle windows group by route
|
|
1093
|
-
function groupSpans(spans: Record<string, unknown>[], filter: SpanFilter): SpanGroup[] {
|
|
1094
|
-
const groups = new Map<string, Record<string, unknown>[]>()
|
|
1095
|
-
for (const span of spans) {
|
|
1096
|
-
const key = spanGroupKey(span, filter)
|
|
1097
|
-
if (key === undefined) continue
|
|
1098
|
-
const group = groups.get(key)
|
|
1099
|
-
if (group) group.push(span)
|
|
1100
|
-
else groups.set(key, [span])
|
|
1101
|
-
}
|
|
1102
|
-
return [...groups.entries()]
|
|
1103
|
-
.map(([key, rows]) => {
|
|
1104
|
-
const [kind = '', target = ''] = key.split('\u0000')
|
|
1105
|
-
const fps: number[] = []
|
|
1106
|
-
let durationMs = 0
|
|
1107
|
-
let droppedFrames = 0
|
|
1108
|
-
let longestFrameMs = 0
|
|
1109
|
-
let worstStall: SpanGroup['worstStall'] = null
|
|
1110
|
-
for (const row of rows) {
|
|
1111
|
-
fps.push(asNum(row.fps))
|
|
1112
|
-
durationMs += asNum(row.durationMs)
|
|
1113
|
-
droppedFrames += asNum(row.droppedFrames)
|
|
1114
|
-
longestFrameMs = Math.max(longestFrameMs, asNum(row.longestFrameMs))
|
|
1115
|
-
const stall = isRecord(row.worstStall) ? row.worstStall : null
|
|
1116
|
-
if (stall && asNum(stall.durationMs) > (worstStall?.durationMs ?? 0))
|
|
1117
|
-
worstStall = {
|
|
1118
|
-
durationMs: asNum(stall.durationMs),
|
|
1119
|
-
phase: asStr(stall.phase),
|
|
1120
|
-
route: asStr(row.route),
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
fps.sort((left, right) => right - left)
|
|
1124
|
-
return {
|
|
1125
|
-
kind,
|
|
1126
|
-
target,
|
|
1127
|
-
spans: rows.length,
|
|
1128
|
-
durationMs,
|
|
1129
|
-
fpsP50: percentileFloor(fps, 0.5),
|
|
1130
|
-
fpsP95: percentileFloor(fps, 0.95),
|
|
1131
|
-
droppedFrames,
|
|
1132
|
-
longestFrameMs,
|
|
1133
|
-
worstStall,
|
|
1134
|
-
}
|
|
1135
|
-
})
|
|
1136
|
-
.sort((a, b) => a.kind.localeCompare(b.kind) || b.durationMs - a.durationMs)
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
function printSpanGroups(groups: SpanGroup[]): void {
|
|
1140
|
-
if (!groups.length) {
|
|
1141
|
-
console.log('\nInteractions: none')
|
|
1142
|
-
return
|
|
1143
|
-
}
|
|
1144
|
-
console.log('\nInteractions (fps p95 is the rate 95% of spans reached):')
|
|
1145
|
-
for (const group of groups) {
|
|
1146
|
-
const stall = group.worstStall
|
|
1147
|
-
? ` | worst stall ${group.worstStall.durationMs.toFixed(1)} ms ${group.worstStall.phase}`
|
|
1148
|
-
: ''
|
|
1149
|
-
console.log(
|
|
1150
|
-
` ${group.kind.padEnd(8)} ${group.target.padEnd(32)} ${String(group.spans).padStart(4)}x ${(group.durationMs / 1000).toFixed(1).padStart(6)} s | fps p50 ${group.fpsP50.toFixed(1).padStart(5)} p95 ${group.fpsP95.toFixed(1).padStart(5)} | ${group.droppedFrames} dropped | longest ${group.longestFrameMs.toFixed(1)} ms${stall}`,
|
|
1151
|
-
)
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
function printLargestInteractionGaps(
|
|
1156
|
-
spans: readonly { span: Record<string, unknown>; executableUUID?: string }[],
|
|
1157
|
-
filter: SpanFilter,
|
|
1158
|
-
): void {
|
|
1159
|
-
const worst = spans
|
|
1160
|
-
.filter(
|
|
1161
|
-
({ span }) =>
|
|
1162
|
-
asStr(span.kind) !== 'idle' &&
|
|
1163
|
-
asNum(span.droppedFrames) > 0 &&
|
|
1164
|
-
asNum(span.longestFrameMs) > 0 &&
|
|
1165
|
-
spanGroupKey(span, filter) !== undefined,
|
|
1166
|
-
)
|
|
1167
|
-
.sort((a, b) => asNum(b.span.longestFrameMs) - asNum(a.span.longestFrameMs))
|
|
1168
|
-
.slice(0, 5)
|
|
1169
|
-
if (!worst.length) return
|
|
1170
|
-
console.log('\nLargest interaction frame gaps (timestamps are span starts)')
|
|
1171
|
-
for (const { span, executableUUID } of worst) {
|
|
1172
|
-
const when = new Date(asNum(span.startWallMs))
|
|
1173
|
-
const time = when.getTime() > 0 ? when.toISOString() : 'time unavailable'
|
|
1174
|
-
const target = asStr(span.target)
|
|
1175
|
-
const route = asStr(span.route)
|
|
1176
|
-
const stall = isRecord(span.worstStall) ? span.worstStall : undefined
|
|
1177
|
-
const longestTurn = asNum(stall?.durationMs)
|
|
1178
|
-
const turn =
|
|
1179
|
-
longestTurn > 0
|
|
1180
|
-
? ` | longest turn in span ${longestTurn.toFixed(1)} ms ${asStr(stall?.phase)}`
|
|
1181
|
-
: ''
|
|
1182
|
-
const image =
|
|
1183
|
-
executableUUID && profileUUID.test(executableUUID)
|
|
1184
|
-
? ` | image ${executableUUID}`
|
|
1185
|
-
: ''
|
|
1186
|
-
console.log(
|
|
1187
|
-
` ${time} | ${asStr(span.kind)} ${[route, target === route ? '' : target].filter(Boolean).join(' ')} | ${asNum(span.longestFrameMs).toFixed(1)} ms, ${asNum(span.droppedFrames)} dropped${turn}${image}`,
|
|
1188
|
-
)
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
function printHelp(): void {
|
|
1193
|
-
console.log(`
|
|
1194
|
-
peach perf native: profile a running One v3 iOS simulator or device app
|
|
1195
|
-
|
|
1196
|
-
usage:
|
|
1197
|
-
peach perf native [--bundle-id <id>] [--udid <sim-udid>] [--duration <sec>] [-o <prefix>]
|
|
1198
|
-
peach perf native --device <device-udid> --bundle-id <id> --scheme <url-scheme> [--duration <sec>] [-o <prefix>]
|
|
1199
|
-
peach perf native --overlay <on|off|toggle> [--bundle-id <id>] [--udid <sim-udid>]
|
|
1200
|
-
peach perf native --start|--stop [--bundle-id <id>] [--udid <sim-udid>] [-o <prefix>]
|
|
1201
|
-
peach perf native --telemetry <jsonl> --source-maps <path> [-o <file>]
|
|
1202
|
-
peach perf native --telemetry <jsonl> [--kind <kinds>] [--route <text>] [--target <text>] [--json]
|
|
1203
|
-
|
|
1204
|
-
options:
|
|
1205
|
-
--bundle-id <id> App bundle identifier (auto-detected if one user app is running on simulator)
|
|
1206
|
-
--udid <id> Simulator UDID (default: booted)
|
|
1207
|
-
--device <id> Physical iOS device UDID (uses xcrun devicectl)
|
|
1208
|
-
--scheme <name> App URL scheme for physical device trigger
|
|
1209
|
-
--duration <sec> Capture window in seconds (default: 5)
|
|
1210
|
-
-o, --output <path> Output file prefix or directory (default: /tmp/one-profile-<ts>)
|
|
1211
|
-
--source-maps <path> Path to OneJavaScriptSourceMaps-<uuid>.json or build directory for AoT symbolication
|
|
1212
|
-
--telemetry <jsonl> With --source-maps, symbolicate saved rolling snapshots and print JSON; alone, group their interaction spans
|
|
1213
|
-
--kind <kinds> Show interaction spans of these kinds (comma separated: scroll,navigate,tap,type,sheet,idle)
|
|
1214
|
-
--route <text> Show interaction spans whose route contains text
|
|
1215
|
-
--target <text> Show interaction spans whose target contains text
|
|
1216
|
-
--interactions <mode> Which interactions record spans: auto (default), explicit or off
|
|
1217
|
-
--overlay <mode> Toggle floating overlay: on, off, or toggle
|
|
1218
|
-
--start Start profiling without waiting
|
|
1219
|
-
--stop Stop an active profile and pull artifacts
|
|
1220
|
-
--json Print JSON summary to stdout
|
|
1221
|
-
`)
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
1225
|
-
return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
export function asNum(value: unknown): number {
|
|
1229
|
-
return typeof value === 'number' && Number.isFinite(value) ? value : 0
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
export function asStr(value: unknown): string {
|
|
1233
|
-
return typeof value === 'string' ? value : ''
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
export function records(value: unknown): Record<string, unknown>[] {
|
|
1237
|
-
return Array.isArray(value) ? value.filter(isRecord) : []
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
export function parseNativeReport(value: unknown): NativeProfileReport | undefined {
|
|
1241
|
-
if (!isRecord(value)) return undefined
|
|
1242
|
-
const phasesRaw = isRecord(value.phases) ? value.phases : {}
|
|
1243
|
-
const phases: Record<string, number> = {}
|
|
1244
|
-
for (const [k, v] of Object.entries(phasesRaw)) {
|
|
1245
|
-
if (typeof v === 'number' && Number.isFinite(v)) phases[k] = v
|
|
1246
|
-
}
|
|
1247
|
-
const files = isRecord(value.files) ? value.files : {}
|
|
1248
|
-
const parseJsTiers = (raw: unknown): NativeProfileJsTiers | undefined => {
|
|
1249
|
-
if (!isRecord(raw)) return undefined
|
|
1250
|
-
return {
|
|
1251
|
-
aot: asNum(raw.aot),
|
|
1252
|
-
interpreter: asNum(raw.interpreter),
|
|
1253
|
-
interpreterBuiltin: asNum(raw.interpreterBuiltin),
|
|
1254
|
-
jit: asNum(raw.jit),
|
|
1255
|
-
host: asNum(raw.host),
|
|
1256
|
-
native: asNum(raw.native),
|
|
1257
|
-
regexp: asNum(raw.regexp),
|
|
1258
|
-
wasm: asNum(raw.wasm),
|
|
1259
|
-
unknown: asNum(raw.unknown),
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
const parseFnList = (raw: unknown): NativeProfileFunction[] =>
|
|
1263
|
-
Array.isArray(raw)
|
|
1264
|
-
? raw.filter(isRecord).map((row) => ({
|
|
1265
|
-
name: asStr(row.name),
|
|
1266
|
-
url: asStr(row.url),
|
|
1267
|
-
line: asNum(row.line),
|
|
1268
|
-
column: asNum(row.column),
|
|
1269
|
-
...(typeof row.tier === 'string' && row.tier ? { tier: row.tier } : {}),
|
|
1270
|
-
...(row.builtin === true ? { builtin: true } : {}),
|
|
1271
|
-
selfMs: asNum(row.selfMs),
|
|
1272
|
-
totalMs: asNum(row.totalMs),
|
|
1273
|
-
selfSamples: asNum(row.selfSamples),
|
|
1274
|
-
totalSamples: asNum(row.totalSamples),
|
|
1275
|
-
selfPct: asNum(row.selfPct),
|
|
1276
|
-
}))
|
|
1277
|
-
: []
|
|
1278
|
-
const jsTiers = parseJsTiers(value.jsTiers)
|
|
1279
|
-
const topJsFunctions = parseFnList(value.topJsFunctions)
|
|
1280
|
-
const topJsCallers = parseFnList(value.topJsCallers)
|
|
1281
|
-
const topInterpretedJsFunctions = parseFnList(value.topInterpretedJsFunctions)
|
|
1282
|
-
const topReactComponents = Array.isArray(value.topReactComponents)
|
|
1283
|
-
? value.topReactComponents.filter(isRecord).map((row) => ({
|
|
1284
|
-
name: asStr(row.name),
|
|
1285
|
-
commits: asNum(row.commits),
|
|
1286
|
-
renders: asNum(row.renders),
|
|
1287
|
-
totalMs: asNum(row.totalMs),
|
|
1288
|
-
maxMs: asNum(row.maxMs),
|
|
1289
|
-
}))
|
|
1290
|
-
: []
|
|
1291
|
-
return {
|
|
1292
|
-
schema: asNum(value.schema),
|
|
1293
|
-
bundleId: asStr(value.bundleId),
|
|
1294
|
-
build: asStr(value.build),
|
|
1295
|
-
executableUUID: asStr(value.executableUUID),
|
|
1296
|
-
route: asStr(value.route),
|
|
1297
|
-
startWallMs: asNum(value.startWallMs),
|
|
1298
|
-
durationMs: asNum(value.durationMs),
|
|
1299
|
-
frames: asNum(value.frames),
|
|
1300
|
-
droppedFrames: asNum(value.droppedFrames),
|
|
1301
|
-
fps: asNum(value.fps),
|
|
1302
|
-
longestFrameMs: asNum(value.longestFrameMs),
|
|
1303
|
-
mainThreadBusyMs: asNum(value.mainThreadBusyMs),
|
|
1304
|
-
mainThreadBusyPct: asNum(value.mainThreadBusyPct),
|
|
1305
|
-
jsMs: asNum(value.jsMs),
|
|
1306
|
-
nativeMs: asNum(value.nativeMs),
|
|
1307
|
-
phases,
|
|
1308
|
-
jsSamples: asNum(value.jsSamples),
|
|
1309
|
-
...(jsTiers ? { jsTiers } : {}),
|
|
1310
|
-
topJsFunctions,
|
|
1311
|
-
topJsCallers,
|
|
1312
|
-
...(topInterpretedJsFunctions.length ? { topInterpretedJsFunctions } : {}),
|
|
1313
|
-
reactCommits: asNum(value.reactCommits),
|
|
1314
|
-
topReactComponents,
|
|
1315
|
-
nativeSamples: asNum(value.nativeSamples),
|
|
1316
|
-
topNativeSelf: records(value.topNativeSelf),
|
|
1317
|
-
topNativeInclusive: records(value.topNativeInclusive),
|
|
1318
|
-
topNativeStacks: records(value.topNativeStacks),
|
|
1319
|
-
turnsOver16ms: asNum(value.turnsOver16ms),
|
|
1320
|
-
worstStall: isRecord(value.worstStall) ? value.worstStall : null,
|
|
1321
|
-
slowBridgeCalls: records(value.slowBridgeCalls),
|
|
1322
|
-
slowBridgeTotal: asNum(value.slowBridgeTotal),
|
|
1323
|
-
budget: isRecord(value.budget) ? value.budget : null,
|
|
1324
|
-
spans: records(value.spans),
|
|
1325
|
-
files: {
|
|
1326
|
-
cpuprofile: asStr(files.cpuprofile),
|
|
1327
|
-
trace: asStr(files.trace),
|
|
1328
|
-
summary: asStr(files.summary),
|
|
1329
|
-
},
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
export function parseReportEnvelope(raw: string): {
|
|
1334
|
-
ok: boolean
|
|
1335
|
-
error?: string
|
|
1336
|
-
report?: NativeProfileReport
|
|
1337
|
-
} {
|
|
1338
|
-
const parsed: unknown = JSON.parse(raw)
|
|
1339
|
-
if (!isRecord(parsed)) {
|
|
1340
|
-
return { ok: false, error: 'Invalid profiler response JSON' }
|
|
1341
|
-
}
|
|
1342
|
-
return {
|
|
1343
|
-
ok: Boolean(parsed.ok),
|
|
1344
|
-
error: typeof parsed.error === 'string' ? parsed.error : undefined,
|
|
1345
|
-
report: parseNativeReport(parsed.report),
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
export async function runPerfNative(args: string[]): Promise<number> {
|
|
1350
|
-
if (args.includes('--help') || args.includes('-h')) {
|
|
1351
|
-
printHelp()
|
|
1352
|
-
return 0
|
|
1353
|
-
}
|
|
1354
|
-
const { values } = parseArgs({
|
|
1355
|
-
args,
|
|
1356
|
-
options: {
|
|
1357
|
-
'bundle-id': { type: 'string' },
|
|
1358
|
-
udid: { type: 'string', default: 'booted' },
|
|
1359
|
-
device: { type: 'string' },
|
|
1360
|
-
scheme: { type: 'string' },
|
|
1361
|
-
duration: { type: 'string', default: '5' },
|
|
1362
|
-
output: { type: 'string', short: 'o' },
|
|
1363
|
-
'source-maps': { type: 'string' },
|
|
1364
|
-
telemetry: { type: 'string' },
|
|
1365
|
-
overlay: { type: 'string' },
|
|
1366
|
-
start: { type: 'boolean', default: false },
|
|
1367
|
-
stop: { type: 'boolean', default: false },
|
|
1368
|
-
json: { type: 'boolean', default: false },
|
|
1369
|
-
kind: { type: 'string' },
|
|
1370
|
-
route: { type: 'string' },
|
|
1371
|
-
target: { type: 'string' },
|
|
1372
|
-
interactions: { type: 'string' },
|
|
1373
|
-
},
|
|
1374
|
-
strict: true,
|
|
1375
|
-
})
|
|
1376
|
-
const filter: SpanFilter = {
|
|
1377
|
-
kinds: values.kind ? values.kind.split(',').filter(Boolean) : [],
|
|
1378
|
-
route: values.route,
|
|
1379
|
-
target: values.target,
|
|
1380
|
-
}
|
|
1381
|
-
if (values.interactions && !['auto', 'explicit', 'off'].includes(values.interactions))
|
|
1382
|
-
throw new Error('--interactions must be auto, explicit or off')
|
|
1383
|
-
|
|
1384
|
-
if (values.telemetry && !values['source-maps']) {
|
|
1385
|
-
const spans = readFileSync(values.telemetry, 'utf8')
|
|
1386
|
-
.split('\n')
|
|
1387
|
-
.filter((line) => line.trim())
|
|
1388
|
-
.flatMap((line) => {
|
|
1389
|
-
const row: unknown = JSON.parse(line)
|
|
1390
|
-
const snapshot = isRecord(row) && isRecord(row.details) ? row.details : row
|
|
1391
|
-
return isRecord(snapshot)
|
|
1392
|
-
? records(snapshot.spans).map((span) => ({
|
|
1393
|
-
span,
|
|
1394
|
-
executableUUID: asStr(snapshot.executableUUID),
|
|
1395
|
-
}))
|
|
1396
|
-
: []
|
|
1397
|
-
})
|
|
1398
|
-
const groups = groupSpans(
|
|
1399
|
-
spans.map(({ span }) => span),
|
|
1400
|
-
filter,
|
|
1401
|
-
)
|
|
1402
|
-
if (values.json) console.log(JSON.stringify(groups, null, 2))
|
|
1403
|
-
else {
|
|
1404
|
-
printSpanGroups(groups)
|
|
1405
|
-
printLargestInteractionGaps(spans, filter)
|
|
1406
|
-
}
|
|
1407
|
-
return 0
|
|
1408
|
-
}
|
|
1409
|
-
if (values.telemetry && values['source-maps']) {
|
|
1410
|
-
const named = symbolicateTelemetry(values.telemetry, values['source-maps'], filter)
|
|
1411
|
-
if (values.output) writeFileSync(values.output, named, { mode: 0o600 })
|
|
1412
|
-
else process.stdout.write(named)
|
|
1413
|
-
return 0
|
|
1414
|
-
}
|
|
1415
|
-
|
|
1416
|
-
const durationSec = Number(values.duration)
|
|
1417
|
-
if (!Number.isFinite(durationSec) || durationSec <= 0) {
|
|
1418
|
-
throw new Error('--duration must be a positive number of seconds')
|
|
1419
|
-
}
|
|
1420
|
-
const commandId = randomUUID().slice(0, 12)
|
|
1421
|
-
const outPrefix = resolve(values.output ?? `/tmp/one-profile-${Date.now()}`)
|
|
1422
|
-
const outBase =
|
|
1423
|
-
existsSync(outPrefix) && statSync(outPrefix).isDirectory()
|
|
1424
|
-
? join(outPrefix, `one-profile-${Date.now()}`)
|
|
1425
|
-
: outPrefix.replace(/\.(cpuprofile|trace\.json|summary\.json|json)$/, '')
|
|
1426
|
-
|
|
1427
|
-
if (values.device) {
|
|
1428
|
-
const bundleId = values['bundle-id']
|
|
1429
|
-
if (!bundleId) throw new Error('--device requires --bundle-id')
|
|
1430
|
-
if (values.overlay) {
|
|
1431
|
-
if (!values.scheme)
|
|
1432
|
-
throw new Error('--device requires --scheme for runtime triggers')
|
|
1433
|
-
const mode =
|
|
1434
|
-
values.overlay === 'on' ? '1' : values.overlay === 'off' ? '0' : 'toggle'
|
|
1435
|
-
execFileSync('xcrun', [
|
|
1436
|
-
'devicectl',
|
|
1437
|
-
'device',
|
|
1438
|
-
'process',
|
|
1439
|
-
'launch',
|
|
1440
|
-
'--device',
|
|
1441
|
-
values.device,
|
|
1442
|
-
bundleId,
|
|
1443
|
-
'--payload-url',
|
|
1444
|
-
`${values.scheme}://__one_profiler/overlay?visible=${mode}`,
|
|
1445
|
-
])
|
|
1446
|
-
console.log(`overlay ${values.overlay} sent to ${bundleId} on ${values.device}`)
|
|
1447
|
-
return 0
|
|
1448
|
-
}
|
|
1449
|
-
if (!values.scheme)
|
|
1450
|
-
throw new Error('--device requires --scheme to trigger capture on a running app')
|
|
1451
|
-
const url = values.stop
|
|
1452
|
-
? `${values.scheme}://__one_profiler/stop?id=${commandId}`
|
|
1453
|
-
: `${values.scheme}://__one_profiler/start?durationMs=${Math.round(durationSec * 1000)}&id=${commandId}`
|
|
1454
|
-
execFileSync('xcrun', [
|
|
1455
|
-
'devicectl',
|
|
1456
|
-
'device',
|
|
1457
|
-
'process',
|
|
1458
|
-
'launch',
|
|
1459
|
-
'--device',
|
|
1460
|
-
values.device,
|
|
1461
|
-
bundleId,
|
|
1462
|
-
'--payload-url',
|
|
1463
|
-
url,
|
|
1464
|
-
])
|
|
1465
|
-
if (values.start) {
|
|
1466
|
-
console.log(`started profiling ${bundleId} on ${values.device}`)
|
|
1467
|
-
return 0
|
|
1468
|
-
}
|
|
1469
|
-
if (!values.stop) {
|
|
1470
|
-
await new Promise((r) => setTimeout(r, Math.round(durationSec * 1000) + 1500))
|
|
1471
|
-
}
|
|
1472
|
-
const pullDir = `${outBase}-device`
|
|
1473
|
-
mkdirSync(pullDir, { recursive: true })
|
|
1474
|
-
execFileSync('xcrun', [
|
|
1475
|
-
'devicectl',
|
|
1476
|
-
'device',
|
|
1477
|
-
'copy',
|
|
1478
|
-
'from',
|
|
1479
|
-
'--device',
|
|
1480
|
-
values.device,
|
|
1481
|
-
'--domain-type',
|
|
1482
|
-
'appDataContainer',
|
|
1483
|
-
'--domain-identifier',
|
|
1484
|
-
bundleId,
|
|
1485
|
-
'--source',
|
|
1486
|
-
'Library/Application Support/OneProfiler',
|
|
1487
|
-
'--destination',
|
|
1488
|
-
pullDir,
|
|
1489
|
-
])
|
|
1490
|
-
const resultFile = join(pullDir, 'OneProfiler', `result-${commandId}.json`)
|
|
1491
|
-
if (!existsSync(resultFile)) {
|
|
1492
|
-
throw new Error(`Device profiler result not found at ${resultFile}`)
|
|
1493
|
-
}
|
|
1494
|
-
const env = parseReportEnvelope(readFileSync(resultFile, 'utf8'))
|
|
1495
|
-
if (!env.ok || !env.report) throw new Error(env.error ?? 'Device profiler failed')
|
|
1496
|
-
const maps = loadSourceMapsBundle(values['source-maps'], env.report.executableUUID)
|
|
1497
|
-
const pulledBase = join(pullDir, 'OneProfiler')
|
|
1498
|
-
const outFiles = {
|
|
1499
|
-
cpuprofile: `${outBase}.cpuprofile`,
|
|
1500
|
-
trace: `${outBase}.trace.json`,
|
|
1501
|
-
summary: `${outBase}.summary.json`,
|
|
1502
|
-
}
|
|
1503
|
-
mkdirSync(dirname(outBase), { recursive: true })
|
|
1504
|
-
copyFileSync(
|
|
1505
|
-
join(pulledBase, basename(env.report.files.cpuprofile)),
|
|
1506
|
-
outFiles.cpuprofile,
|
|
1507
|
-
)
|
|
1508
|
-
copyFileSync(join(pulledBase, basename(env.report.files.trace)), outFiles.trace)
|
|
1509
|
-
symbolicateCpuProfile(outFiles.cpuprofile, maps)
|
|
1510
|
-
symbolicateTrace(outFiles.trace, maps)
|
|
1511
|
-
symbolicateReport(env.report, maps)
|
|
1512
|
-
env.report.files = outFiles
|
|
1513
|
-
writeFileSync(outFiles.summary, JSON.stringify(env.report, null, 2) + '\n')
|
|
1514
|
-
rmSync(pullDir, { recursive: true, force: true })
|
|
1515
|
-
if (values.json) console.log(JSON.stringify(env.report, null, 2))
|
|
1516
|
-
else printSummary(env.report, outFiles, filter)
|
|
1517
|
-
return 0
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1520
|
-
const udid = values.udid
|
|
1521
|
-
const bundleId = values['bundle-id'] ?? detectSimulatorBundleId(udid)
|
|
1522
|
-
const action = values.overlay
|
|
1523
|
-
? 'overlay'
|
|
1524
|
-
: values.start
|
|
1525
|
-
? 'start'
|
|
1526
|
-
: values.stop
|
|
1527
|
-
? 'stop'
|
|
1528
|
-
: 'capture'
|
|
1529
|
-
const payload: { id: string; action: string } & Record<string, unknown> = {
|
|
1530
|
-
id: commandId,
|
|
1531
|
-
action,
|
|
1532
|
-
}
|
|
1533
|
-
if (action === 'overlay') {
|
|
1534
|
-
if (values.overlay === 'on' || values.overlay === '1' || values.overlay === 'true') {
|
|
1535
|
-
payload.visible = true
|
|
1536
|
-
} else if (
|
|
1537
|
-
values.overlay === 'off' ||
|
|
1538
|
-
values.overlay === '0' ||
|
|
1539
|
-
values.overlay === 'false'
|
|
1540
|
-
) {
|
|
1541
|
-
payload.visible = false
|
|
1542
|
-
}
|
|
1543
|
-
} else if (action === 'capture') {
|
|
1544
|
-
payload.durationMs = Math.round(durationSec * 1000)
|
|
1545
|
-
payload.sampleJs = true
|
|
1546
|
-
payload.react = true
|
|
1547
|
-
} else if (action === 'start') {
|
|
1548
|
-
payload.sampleJs = true
|
|
1549
|
-
payload.react = true
|
|
1550
|
-
}
|
|
1551
|
-
if (values.interactions && (action === 'capture' || action === 'start'))
|
|
1552
|
-
payload.interactions = values.interactions
|
|
1553
|
-
|
|
1554
|
-
const timeoutMs =
|
|
1555
|
-
action === 'capture' ? Math.round(durationSec * 1000) + 15_000 : 10_000
|
|
1556
|
-
const rawResult = await requestSimulatorProfile(udid, bundleId, payload, timeoutMs)
|
|
1557
|
-
|
|
1558
|
-
if (action === 'overlay' || action === 'start') {
|
|
1559
|
-
if (values.json) console.log(rawResult)
|
|
1560
|
-
else console.log(`${action} succeeded for ${bundleId}`)
|
|
1561
|
-
return 0
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
const env = parseReportEnvelope(rawResult)
|
|
1565
|
-
if (!env.ok || !env.report) {
|
|
1566
|
-
throw new Error(env.error ?? 'Profiler capture failed')
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
const report = env.report
|
|
1570
|
-
const maps = loadSourceMapsBundle(values['source-maps'], report.executableUUID)
|
|
1571
|
-
const outFiles = {
|
|
1572
|
-
cpuprofile: `${outBase}.cpuprofile`,
|
|
1573
|
-
trace: `${outBase}.trace.json`,
|
|
1574
|
-
summary: `${outBase}.summary.json`,
|
|
1575
|
-
}
|
|
1576
|
-
mkdirSync(dirname(outBase), { recursive: true })
|
|
1577
|
-
if (report.files.cpuprofile && existsSync(report.files.cpuprofile)) {
|
|
1578
|
-
copyFileSync(report.files.cpuprofile, outFiles.cpuprofile)
|
|
1579
|
-
symbolicateCpuProfile(outFiles.cpuprofile, maps)
|
|
1580
|
-
}
|
|
1581
|
-
if (report.files.trace && existsSync(report.files.trace)) {
|
|
1582
|
-
copyFileSync(report.files.trace, outFiles.trace)
|
|
1583
|
-
symbolicateTrace(outFiles.trace, maps)
|
|
1584
|
-
}
|
|
1585
|
-
symbolicateReport(report, maps)
|
|
1586
|
-
report.files = outFiles
|
|
1587
|
-
writeFileSync(outFiles.summary, JSON.stringify(report, null, 2) + '\n')
|
|
1588
|
-
|
|
1589
|
-
if (values.json) console.log(JSON.stringify(report, null, 2))
|
|
1590
|
-
else printSummary(report, outFiles, filter)
|
|
1591
|
-
return 0
|
|
1592
|
-
}
|