Skip to content

Commit 0192348

Browse files
authored
fix(ios): parse the Xcode 27 <tagged-backtrace> time-profile stack (#2889)
* fix(ios): parse the Xcode 27 <tagged-backtrace> time-profile stack Xcode 27 renamed the time-profile stack element and its engineering-type to tagged-backtrace while keeping the same frame children and id/ref reuse. The parser matched only <backtrace>, so every row of an Xcode 27 export resolved no stack, and writeAppleXctracePerfReport failed a trace holding tens of thousands of samples with "Apple xctrace CPU report contained no samples". Read either spelling through one name set so id/ref resolution, the innermost-frame rule, and the report shape stay exactly as they were for older exports. The fixture is a verbatim 22-row prefix of an xctrace 27.1 (27A9269) export: 19 stack definitions, 2 rows naming their stack through a tagged-backtrace ref, 4 innermost frames and 3 innermost binaries reached through refs, and one row whose stack column is a sentinel. The multi-run test now carries a cross-run frame ref because a real append-run export numbers ids with one counter across its runs. Closes #2860 * chore(gates): own .xml package captures in the affected selector The package-capture ownership rule matched .json only, so the first recorded xctrace export under a package fixture directory had no derivable owner and failed the gate open to all 59 checks even though exactly one suite reads it. Accept .xml beside .json and pin both spellings in the ownership test. * test(ios): synthesize the Xcode 27 time-profile rows instead of committing a capture The captured export leaked a machine's home directory, per-user temp-dir token, and installed-software identity — an MDM endpoint-security agent among them — into a public repo, and a 30 KB blob of 2000-char lines defeats diff, format, and grep for coverage the synthetic rows already give. Keep the shapes that capture proved: a `<tagged-backtrace>` definition, a row that names its stack by ref, a `truncated="YES"` stack whose innermost frame is a `<frame ref>`, an innermost `<binary ref>`, and a stack-column `<sentinel/>` row. The binary-ref case is the one the pre-existing suite survived before. Symbols, binaries, and weights are synthetic. Give the cross-run frame reference its own test, so the multi-run aggregation case keeps answering independently the way it did before this PR. * chore(gates): drop the .xml package-capture extension That extension was added only to own the captured xctrace export this branch no longer commits, so the rule would own nothing real. Revert to the `.json` capture rule and keep the ownership test on the captures that exist.
1 parent 7286206 commit 0192348

3 files changed

Lines changed: 90 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
- Fixed (ios): `perf cpu profile report --kind xctrace` on Xcode 27 no longer fails with
6+
`Apple xctrace CPU report contained no samples` on a trace that holds thousands of samples. Xcode
7+
27 exports each `time-profile` sample stack as `<tagged-backtrace>` instead of `<backtrace>`, and
8+
the parser read only the old element, so every row resolved no stack at all. Both spellings now
9+
parse through the same `id`/`ref` resolution, so a profile recorded with an older Xcode reports
10+
what it did before. (#2860)
511
- Changed (apple): a read-only runner command is resent inside the same request only when the
612
runner refused it as `RUNNER_BUSY`. Before, any `COMMAND_FAILED` carrying `details.retriable:
713
true` was sent up to three times. That flag tells a caller's own poll, such as `wait`, to try

‎packages/platform-apple/src/core/__tests__/perf-time-profile.test.ts‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,58 @@ import assert from 'node:assert/strict';
22
import { test } from 'vitest';
33
import { parseAppleTimeProfileSummary } from '../perf-time-profile.ts';
44

5+
test('reads Xcode 27 tagged-backtrace stacks and skips stack sentinels', () => {
6+
// xctrace 27 renamed the `time-profile` stack element to `<tagged-backtrace>` and kept the same
7+
// `id`/`ref` reuse over frames and binaries. These row shapes come from a real 27.1 export; the
8+
// symbols, binaries, and weights here are synthetic.
9+
const summary = parseAppleTimeProfileSummary(
10+
`<trace-query-result><node>
11+
<row>
12+
<weight id="weight-1">1000000</weight>
13+
<tagged-backtrace id="stack-1">
14+
<frame id="frame-1" name="hot"><binary id="binary-1" name="App"/></frame>
15+
<frame name="caller"><binary name="Framework"/></frame>
16+
</tagged-backtrace>
17+
</row>
18+
<row><weight ref="weight-1"/><tagged-backtrace ref="stack-1"/></row>
19+
<row>
20+
<weight ref="weight-1"/>
21+
<tagged-backtrace id="stack-2" truncated="YES"><frame ref="frame-1"/></tagged-backtrace>
22+
</row>
23+
<row>
24+
<weight ref="weight-1"/>
25+
<tagged-backtrace id="stack-3">
26+
<frame id="frame-2" name="warm"><binary ref="binary-1"/></frame>
27+
</tagged-backtrace>
28+
</row>
29+
<row><weight ref="weight-1"/><sentinel/></row>
30+
</node></trace-query-result>`,
31+
2,
32+
);
33+
34+
// `hot` is sampled as a stack definition, through a `<tagged-backtrace ref>`, and through a
35+
// truncated stack whose innermost frame is a `<frame ref>`. `warm` reaches its binary only
36+
// through `<binary ref>`, and the sentinel row carries a weight with no stack at all.
37+
assert.deepEqual(summary, {
38+
sampleCount: 4,
39+
totalSampleWeightMs: 4,
40+
topFunctions: [
41+
{
42+
symbol: 'hot',
43+
binary: 'App',
44+
selfSampleMs: 3,
45+
selfSamplePercent: 75,
46+
},
47+
{
48+
symbol: 'warm',
49+
binary: 'App',
50+
selfSampleMs: 1,
51+
selfSamplePercent: 25,
52+
},
53+
],
54+
});
55+
});
56+
557
test('aggregates weighted innermost frames and follows xctrace references', () => {
658
const summary = parseAppleTimeProfileSummary(
759
`<trace-query-result><node><row>
@@ -44,6 +96,30 @@ test('aggregates rows exported from multiple trace runs', () => {
4496
assert.equal(summary.topFunctions[0]?.symbol, 'runTwo');
4597
});
4698

99+
test('resolves a frame reference an earlier trace run defined', () => {
100+
// A real `xctrace record --append-run` export numbers element ids with one counter across its
101+
// runs, so a row of a later run refs a frame an earlier run defined. Scoping the id index per
102+
// `<node>` would drop that row's frame instead of attributing it to the earlier symbol.
103+
const summary = parseAppleTimeProfileSummary(
104+
`<trace-query-result>
105+
<node xpath="/trace-toc/run[1]"><row><weight>1000000</weight><tagged-backtrace><frame id="frame-1" name="shared"/></tagged-backtrace></row></node>
106+
<node xpath="/trace-toc/run[2]"><row><weight>3000000</weight><tagged-backtrace><frame ref="frame-1"/></tagged-backtrace></row></node>
107+
</trace-query-result>`,
108+
);
109+
assert.deepEqual(summary, {
110+
sampleCount: 2,
111+
totalSampleWeightMs: 4,
112+
topFunctions: [
113+
{
114+
symbol: 'shared',
115+
binary: undefined,
116+
selfSampleMs: 4,
117+
selfSamplePercent: 100,
118+
},
119+
],
120+
});
121+
});
122+
47123
test('skips incomplete rows', () => {
48124
assert.deepEqual(
49125
parseAppleTimeProfileSummary(

‎packages/platform-apple/src/core/perf-time-profile.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { findAllXmlNodes, indexXmlNodesById, resolveXmlReference } from './perf-
44

55
const APPLE_TIME_PROFILE_FUNCTION_LIMIT = 10;
66

7+
// Xcode 27 renamed the `time-profile` stack element and its `engineering-type` to
8+
// `<tagged-backtrace>` while keeping the same `<frame>` children and `id`/`ref` reuse, so both
9+
// spellings carry one sampled stack.
10+
const APPLE_TIME_PROFILE_STACK_ELEMENT_NAMES = new Set(['backtrace', 'tagged-backtrace']);
11+
712
export type AppleTimeProfileFunction = {
813
symbol: string;
914
binary?: string;
@@ -78,14 +83,14 @@ function readRowWeightNs(row: XmlNode, nodesById: Map<string, XmlNode>): number
7883
}
7984

8085
function readInnermostFrame(row: XmlNode, nodesById: Map<string, XmlNode>): XmlNode | undefined {
81-
const backtrace = resolveXmlReference(
82-
row.children.find((node) => node.name === 'backtrace'),
86+
const stack = resolveXmlReference(
87+
row.children.find((node) => APPLE_TIME_PROFILE_STACK_ELEMENT_NAMES.has(node.name)),
8388
nodesById,
8489
);
8590
// xctrace lists a sampled backtrace from the innermost frame outward. The first
8691
// frame therefore owns self time; a focused multi-frame test pins this ordering.
8792
return resolveXmlReference(
88-
backtrace?.children.find((node) => node.name === 'frame'),
93+
stack?.children.find((node) => node.name === 'frame'),
8994
nodesById,
9095
);
9196
}

0 commit comments

Comments
 (0)