@@ -29,6 +29,7 @@ class RNPerfMetrics {
2929 #telemetryInfo: Object = { } ;
3030 // map of panel location to panel name
3131 #currentPanels = new Map < PanelLocation , string > ( ) ;
32+ #initialResourcesLoadedInfo: null | { count : number , time : number } = null ;
3233
3334 isEnabled ( ) : boolean {
3435 return globalThis . enableReactNativePerfMetrics === true ;
@@ -186,13 +187,10 @@ class RNPerfMetrics {
186187 } ) ;
187188 }
188189
189- allInitialDeveloperResourcesLoadingFinished ( count : number ) : void {
190- this . sendEvent ( {
191- eventName : 'DeveloperResource.AllInitialLoadingFinished' ,
192- params : {
193- count,
194- } ,
195- } ) ;
190+ initialResourcesLoaded ( info : { count : number , time : number } ) : void {
191+ // eslint-disable-next-line no-console
192+ console . info ( 'Initial %d resources are loaded at %sms since launch' , info . count , info . time ) ;
193+ this . #initialResourcesLoadedInfo = info ;
196194 }
197195
198196 fuseboxSetClientMetadataStarted ( ) : void {
@@ -215,10 +213,30 @@ class RNPerfMetrics {
215213 }
216214 }
217215
218- firstSteadyPing ( ) : void {
216+ tryReportingCdpLowRoundtrip ( cdpLowRoundtripStartTime : number ) : boolean {
217+ if ( this . #initialResourcesLoadedInfo === null ) {
218+ return false ;
219+ }
220+
221+ // if the roundtrip is fine for a long time, just take the initial resources loading time
222+ // if it got better only after the initial resources were loaded, take the cdp low roundtrip time instead
223+ const startupTime = Math . max ( cdpLowRoundtripStartTime , this . #initialResourcesLoadedInfo. time ) ;
224+
225+ // eslint-disable-next-line no-console
226+ console . info ( 'The app had a low CDP roundtrip at %sms since launch' , cdpLowRoundtripStartTime ) ;
227+ // eslint-disable-next-line no-console
228+ console . info ( 'Startup time is %sms' , startupTime ) ;
229+
219230 this . sendEvent ( {
220- eventName : 'FirstSteadyPing' ,
231+ eventName : 'StartUpFinished' ,
232+ params : {
233+ bundleCount : this . #initialResourcesLoadedInfo. count ,
234+ duration : startupTime ,
235+ initialResourcesLoadedTime : this . #initialResourcesLoadedInfo. time ,
236+ cdpLowRoundtripStartTime,
237+ }
221238 } ) ;
239+ return true ;
222240 }
223241
224242 heapSnapshotStarted ( ) : void {
@@ -432,13 +450,6 @@ export type DeveloperResourceLoadingFinishedEvent = Readonly<{
432450 } > ,
433451} > ;
434452
435- export type AllInitialDeveloperResourcesLoadingFinished = Readonly < {
436- eventName : 'DeveloperResource.AllInitialLoadingFinished' ,
437- params : Readonly < {
438- count : number ,
439- } > ,
440- } > ;
441-
442453export type FuseboxSetClientMetadataStartedEvent = Readonly < {
443454 eventName : 'FuseboxSetClientMetadataStarted' ,
444455} > ;
@@ -511,16 +522,22 @@ export type StackTraceFrameUrlResolutionFailed = Readonly<{
511522 } > ,
512523} > ;
513524
514- export type FirstSteadyPing = Readonly < {
515- eventName : 'FirstSteadyPing' ,
525+ export type StartUpFinished = Readonly < {
526+ eventName : 'StartUpFinished' ,
527+ params : Readonly < {
528+ bundleCount : number ,
529+ duration : number ,
530+ initialResourcesLoadedTime : number ,
531+ cdpLowRoundtripStartTime : number ,
532+ } > ,
516533} > ;
517534
518535export type ReactNativeChromeDevToolsEvent =
519536 EntrypointLoadingStartedEvent | EntrypointLoadingFinishedEvent | DebuggerReadyEvent | BrowserVisibilityChangeEvent |
520537 BrowserErrorEvent | RemoteDebuggingTerminatedEvent | DeveloperResourceLoadingStartedEvent |
521- DeveloperResourceLoadingFinishedEvent | AllInitialDeveloperResourcesLoadingFinished | FuseboxSetClientMetadataStartedEvent |
538+ DeveloperResourceLoadingFinishedEvent | FuseboxSetClientMetadataStartedEvent |
522539 FuseboxSetClientMetadataFinishedEvent | MemoryPanelActionStartedEvent | MemoryPanelActionFinishedEvent |
523540 PanelShownEvent | PanelClosedEvent | StackTraceSymbolicationSucceeded | StackTraceSymbolicationFailed |
524- StackTraceFrameUrlResolutionSucceeded | StackTraceFrameUrlResolutionFailed | FirstSteadyPing ;
541+ StackTraceFrameUrlResolutionSucceeded | StackTraceFrameUrlResolutionFailed | StartUpFinished ;
525542
526543export type DecoratedReactNativeChromeDevToolsEvent = CommonEventFields & ReactNativeChromeDevToolsEvent ;
0 commit comments