Skip to content

Commit 7d4c777

Browse files
committed
track when all startup resources are loaded
1 parent 5a792db commit 7d4c777

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

front_end/core/host/RNPerfMetrics.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ class RNPerfMetrics {
186186
});
187187
}
188188

189+
developerResourcesStartupLoadingFinishedEvent(numResources: number, timeSinceLaunch: DOMHighResTimeStamp): void {
190+
this.sendEvent({
191+
eventName: 'DeveloperResources.StartupLoadingFinished',
192+
params: {
193+
numResources,
194+
timeSinceLaunch,
195+
},
196+
});
197+
}
198+
189199
fuseboxSetClientMetadataStarted(): void {
190200
this.sendEvent({eventName: 'FuseboxSetClientMetadataStarted'});
191201
}
@@ -435,6 +445,14 @@ export type DeveloperResourceLoadingFinishedEvent = Readonly<{
435445
}>,
436446
}>;
437447

448+
export type DeveloperResourcesStartupLoadingFinishedEvent = Readonly<{
449+
eventName: 'DeveloperResources.StartupLoadingFinished',
450+
params: Readonly<{
451+
numResources: number,
452+
timeSinceLaunch: DOMHighResTimeStamp,
453+
}>,
454+
}>;
455+
438456
export type FuseboxSetClientMetadataStartedEvent = Readonly<{
439457
eventName: 'FuseboxSetClientMetadataStarted',
440458
}>;
@@ -523,10 +541,10 @@ export type ManualBreakpointSetSucceeded = Readonly<{
523541

524542
export type ReactNativeChromeDevToolsEvent =
525543
EntrypointLoadingStartedEvent|EntrypointLoadingFinishedEvent|DebuggerReadyEvent|BrowserVisibilityChangeEvent|
526-
BrowserErrorEvent|RemoteDebuggingTerminatedEvent|DeveloperResourceLoadingStartedEvent|
527-
DeveloperResourceLoadingFinishedEvent|FuseboxSetClientMetadataStartedEvent|FuseboxSetClientMetadataFinishedEvent|
528-
MemoryPanelActionStartedEvent|MemoryPanelActionFinishedEvent|PanelShownEvent|PanelClosedEvent|
529-
StackTraceSymbolicationSucceeded|StackTraceSymbolicationFailed|StackTraceFrameUrlResolutionSucceeded|
544+
BrowserErrorEvent|RemoteDebuggingTerminatedEvent|DeveloperResourcesStartupLoadingFinishedEvent|
545+
DeveloperResourceLoadingStartedEvent|DeveloperResourceLoadingFinishedEvent|FuseboxSetClientMetadataStartedEvent|
546+
FuseboxSetClientMetadataFinishedEvent|MemoryPanelActionStartedEvent|MemoryPanelActionFinishedEvent|PanelShownEvent|
547+
PanelClosedEvent|StackTraceSymbolicationSucceeded|StackTraceSymbolicationFailed|StackTraceFrameUrlResolutionSucceeded|
530548
StackTraceFrameUrlResolutionFailed|ManualBreakpointSetSucceeded|StackTraceFrameClicked;
531549

532550
export type DecoratedReactNativeChromeDevToolsEvent = CommonEventFields&ReactNativeChromeDevToolsEvent;

front_end/core/sdk/PageResourceLoader.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
import type {Target} from './Target.js';
2121
import {TargetManager} from './TargetManager.js';
2222

23+
const RN_DT_STARTUP_RESOURCES_LOADED_COOLDOWN = 3000;
24+
2325
const UIStrings = {
2426
/**
2527
*@description Error message for canceled source map loads
@@ -82,6 +84,8 @@ interface LoadQueueEntry {
8284
*/
8385
export class PageResourceLoader extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
8486
#currentlyLoading = 0;
87+
#rndtStartupResourcesLoadedReported = false;
88+
#rndtStartupResourcesLoadedTimeout: number|undefined = undefined;
8589
#currentlyLoadingPerTarget = new Map<Protocol.Target.TargetID|'main', number>();
8690
readonly #maxConcurrentLoads: number;
8791
#pageResources = new Map<string, PageResource>();
@@ -354,6 +358,23 @@ export class PageResourceLoader extends Common.ObjectWrapper.ObjectWrapper<Event
354358
}
355359
Host.rnPerfMetrics.developerResourceLoadingFinished(
356360
parsedURL, Host.UserMetrics.DeveloperResourceLoaded.FALLBACK_AFTER_FAILURE, result);
361+
362+
if (!this.#rndtStartupResourcesLoadedReported) {
363+
// if no new resources were scheduled for loading for
364+
// RN_DT_STARTUP_RESOURCES_LOADED_COOLDOWN amount of time, for the first time,
365+
// we consider all startup resources to be loaded
366+
window.clearTimeout(this.#rndtStartupResourcesLoadedTimeout);
367+
this.#rndtStartupResourcesLoadedTimeout = window.setTimeout(() => {
368+
if (!this.#rndtStartupResourcesLoadedReported && this.#currentlyLoading === 0) {
369+
Host.rnPerfMetrics.developerResourcesStartupLoadingFinishedEvent(
370+
this.getNumberOfResources().resources /* numResources */,
371+
performance.now() - RN_DT_STARTUP_RESOURCES_LOADED_COOLDOWN /* timeSinceLaunch */,
372+
);
373+
this.#rndtStartupResourcesLoadedReported = true;
374+
}
375+
}, RN_DT_STARTUP_RESOURCES_LOADED_COOLDOWN);
376+
}
377+
357378
return result;
358379
}
359380

0 commit comments

Comments
 (0)