@@ -54,7 +54,7 @@ export type AppleXctracePerfMode = 'cpu-profile' | 'trace';
5454
5555type AppleXctraceRecordTarget = number [ ] | 'all-processes' ;
5656
57- type AppleXctraceRecordAttempt < T > = { started : T } | { failure : ExecResult } ;
57+ type AppleXctraceRecordAttempt < T > = { recorded : T } | { failure : ExecResult } ;
5858
5959export type AppleXctraceTimedRecord = {
6060 startedAt : string ;
@@ -135,9 +135,9 @@ export async function startAppleXctracePerfCapture(params: {
135135 failureMessage : `Failed to start Apple xctrace ${ params . mode } capture for ${ params . appBundleId } ` ,
136136 } ,
137137 async ( ) : Promise < AppleXctraceRecordAttempt < ExecBackgroundResult > > => {
138- const started = runCmdBackground ( 'xcrun' , args , { allowFailure : true } ) ;
139- const immediate = await waitForImmediateAppleXctraceExit ( started . wait ) ;
140- return immediate ? { failure : immediate } : { started } ;
138+ const recorded = runCmdBackground ( 'xcrun' , args , { allowFailure : true } ) ;
139+ const immediate = await waitForImmediateAppleXctraceExit ( recorded . wait ) ;
140+ return immediate ? { failure : immediate } : { recorded } ;
141141 } ,
142142 ) ;
143143 return {
@@ -282,7 +282,12 @@ export async function recordAppleXctraceTimedTrace(params: {
282282 } ) ;
283283 if ( result . exitCode !== 0 ) return { failure : result } ;
284284 return {
285- started : { result, startedAt, endedAt : new Date ( ) . toISOString ( ) , capturedAtMs : Date . now ( ) } ,
285+ recorded : {
286+ result,
287+ startedAt,
288+ endedAt : new Date ( ) . toISOString ( ) ,
289+ capturedAtMs : Date . now ( ) ,
290+ } ,
286291 } ;
287292 } ,
288293 ) ;
@@ -402,25 +407,29 @@ async function recordAppleXctraceWithRetry<T>(
402407 } ,
403408 attemptRecord : ( ) => Promise < AppleXctraceRecordAttempt < T > > ,
404409) : Promise < T > {
405- let failure : ExecResult = { stdout : '' , stderr : '' , exitCode : 1 } ;
406- for ( let attempt = 1 ; attempt <= IOS_DEVICE_TRACE_RECORD_MAX_ATTEMPTS ; attempt += 1 ) {
410+ for ( let attempt = 1 ; ; attempt += 1 ) {
407411 await prepareAppleTraceRecordRetry ( tracePath , attempt ) ;
408412 const outcome = await attemptRecord ( ) ;
409- if ( 'started' in outcome ) return outcome . started ;
410- failure = outcome . failure ;
411- if ( ! isRetryableIosDeviceTraceRecordFailure ( failure ) ) break ;
413+ if ( 'recorded' in outcome ) return outcome . recorded ;
414+ if (
415+ attempt < IOS_DEVICE_TRACE_RECORD_MAX_ATTEMPTS &&
416+ isRetryableIosDeviceTraceRecordFailure ( outcome . failure )
417+ ) {
418+ continue ;
419+ }
420+ const { failure } = outcome ;
421+ throw new AppError (
422+ 'COMMAND_FAILED' ,
423+ context . failureMessage ,
424+ execFailureDetails ( failure , {
425+ cmd : 'xcrun' ,
426+ args,
427+ appBundleId : context . appBundleId ,
428+ deviceId : context . device . id ,
429+ hint : resolveIosDevicePerfHint ( failure . stdout , failure . stderr ) ,
430+ } ) ,
431+ ) ;
412432 }
413- throw new AppError (
414- 'COMMAND_FAILED' ,
415- context . failureMessage ,
416- execFailureDetails ( failure , {
417- cmd : 'xcrun' ,
418- args,
419- appBundleId : context . appBundleId ,
420- deviceId : context . device . id ,
421- hint : resolveIosDevicePerfHint ( failure . stdout , failure . stderr ) ,
422- } ) ,
423- ) ;
424433}
425434
426435export function isRetryableIosDeviceTraceRecordFailure ( result : {
0 commit comments