Skip to content

Commit 56eacee

Browse files
committed
report first steady ping after initial resources loaded
1 parent 06d7de0 commit 56eacee

3 files changed

Lines changed: 48 additions & 31 deletions

File tree

front_end/core/host/RNPerfMetrics.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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} = 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(count: number): void {
191+
// eslint-disable-next-line no-console
192+
console.info('Initial %d resources are loaded after %sms', count, performance.now());
193+
this.#initialResourcesLoadedInfo = {count};
196194
}
197195

198196
fuseboxSetClientMetadataStarted(): void {
@@ -215,10 +213,21 @@ class RNPerfMetrics {
215213
}
216214
}
217215

218-
firstSteadyPing(): void {
216+
tryReportingSteadyPing(): boolean {
217+
if (this.#initialResourcesLoadedInfo === null) {
218+
return false;
219+
}
220+
221+
// eslint-disable-next-line no-console
222+
console.info('Startup time is %s', performance.now());
223+
219224
this.sendEvent({
220-
eventName: 'FirstSteadyPing',
225+
eventName: 'FirstSteadyPingAfterInitialResourcesLoaded',
226+
params: {
227+
bundleCount: this.#initialResourcesLoadedInfo.count,
228+
}
221229
});
230+
return true;
222231
}
223232

224233
heapSnapshotStarted(): void {
@@ -432,13 +441,6 @@ export type DeveloperResourceLoadingFinishedEvent = Readonly<{
432441
}>,
433442
}>;
434443

435-
export type AllInitialDeveloperResourcesLoadingFinished = Readonly<{
436-
eventName: 'DeveloperResource.AllInitialLoadingFinished',
437-
params: Readonly<{
438-
count: number,
439-
}>,
440-
}>;
441-
442444
export type FuseboxSetClientMetadataStartedEvent = Readonly<{
443445
eventName: 'FuseboxSetClientMetadataStarted',
444446
}>;
@@ -511,16 +513,19 @@ export type StackTraceFrameUrlResolutionFailed = Readonly<{
511513
}>,
512514
}>;
513515

514-
export type FirstSteadyPing = Readonly<{
515-
eventName: 'FirstSteadyPing',
516+
export type FirstSteadyPingAfterInitialResourcesLoaded = Readonly<{
517+
eventName: 'FirstSteadyPingAfterInitialResourcesLoaded',
518+
params: Readonly<{
519+
bundleCount: number,
520+
}>,
516521
}>;
517522

518523
export type ReactNativeChromeDevToolsEvent =
519524
EntrypointLoadingStartedEvent|EntrypointLoadingFinishedEvent|DebuggerReadyEvent|BrowserVisibilityChangeEvent|
520525
BrowserErrorEvent|RemoteDebuggingTerminatedEvent|DeveloperResourceLoadingStartedEvent|
521-
DeveloperResourceLoadingFinishedEvent|AllInitialDeveloperResourcesLoadingFinished|FuseboxSetClientMetadataStartedEvent|
526+
DeveloperResourceLoadingFinishedEvent|FuseboxSetClientMetadataStartedEvent|
522527
FuseboxSetClientMetadataFinishedEvent|MemoryPanelActionStartedEvent|MemoryPanelActionFinishedEvent|
523528
PanelShownEvent|PanelClosedEvent|StackTraceSymbolicationSucceeded|StackTraceSymbolicationFailed|
524-
StackTraceFrameUrlResolutionSucceeded|StackTraceFrameUrlResolutionFailed|FirstSteadyPing;
529+
StackTraceFrameUrlResolutionSucceeded|StackTraceFrameUrlResolutionFailed|FirstSteadyPingAfterInitialResourcesLoaded;
525530

526531
export type DecoratedReactNativeChromeDevToolsEvent = CommonEventFields&ReactNativeChromeDevToolsEvent;

front_end/core/sdk/PageResourceLoader.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ interface LoadQueueEntry {
8282
*/
8383
export class PageResourceLoader extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
8484
#currentlyLoading = 0;
85-
#reportedAllInitialResourcesLoaded = false;
85+
#reportedInitialResourcesLoaded = false;
8686
#currentlyLoadingPerTarget = new Map<Protocol.Target.TargetID|'main', number>();
8787
readonly #maxConcurrentLoads: number;
8888
#pageResources = new Map<string, PageResource>();
@@ -356,13 +356,15 @@ export class PageResourceLoader extends Common.ObjectWrapper.ObjectWrapper<Event
356356
Host.rnPerfMetrics.developerResourceLoadingFinished(
357357
parsedURL, Host.UserMetrics.DeveloperResourceLoaded.FALLBACK_AFTER_FAILURE, result);
358358

359-
// Will be decreased to 0 right after this function in "releaseLoadSlot".
360-
// Tracking it here so it is next to the rest of "rnPerfMetrics" in this file.
361-
const allResourcesLoaded = this.#currentlyLoading === 1;
362-
if (allResourcesLoaded && !this.#reportedAllInitialResourcesLoaded) {
363-
Host.rnPerfMetrics.allInitialDeveloperResourcesLoadingFinished(this.getNumberOfResources().resources);
364-
this.#reportedAllInitialResourcesLoaded = true;
365-
}
359+
// Wait for several seconds to ensure no new resources were loaded
360+
// by the resources that just finished loading
361+
setTimeout(() => {
362+
const allResourcesLoaded = this.#currentlyLoading === 0;
363+
if (allResourcesLoaded && !this.#reportedInitialResourcesLoaded) {
364+
Host.rnPerfMetrics.initialResourcesLoaded(this.getNumberOfResources().resources);
365+
this.#reportedInitialResourcesLoaded = true;
366+
}
367+
}, 3000);
366368

367369
return result;
368370
}

front_end/entrypoints/inspector_main/InspectorMain.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export class InspectorMainImpl implements Common.Runnable.Runnable {
6868
}
6969

7070
const startMs = Date.now();
71+
// Issues and waits for a response from a simple "Debugger.enable" when the debugger is enabled
72+
// which noops and retuns a truthy response:
73+
// https://github.com/facebook/hermes/blob/ae235193b9329867afaa2838183cbffa34aca098/API/hermes/cdp/DebuggerDomainAgent.cpp#L224-L228
74+
// https://github.com/facebook/hermes/blob/ae235193b9329867afaa2838183cbffa34aca098/API/hermes/cdp/DebuggerDomainAgent.cpp#L183-L185
75+
// It measures the round trip time for CDP message after being queued in the CDP queue in each direction.
7176
await debuggerModel.syncDebuggerId();
7277
const ping = Date.now() - startMs;
7378

@@ -77,10 +82,15 @@ export class InspectorMainImpl implements Common.Runnable.Runnable {
7782
this.#consecutiveLowPing++;
7883
}
7984

85+
let reportedSteadyPing = false;
8086
if (this.#consecutiveLowPing > 1) {
81-
Host.rnPerfMetrics.firstSteadyPing();
82-
} else {
83-
setTimeout(() => void this.#measureMainConnectionPing(debuggerModel), COOLDOWN_BETWEEN_PINGS);
87+
reportedSteadyPing = Host.rnPerfMetrics.tryReportingSteadyPing();
88+
}
89+
90+
if (!reportedSteadyPing) {
91+
setTimeout(() => {
92+
void this.#measureMainConnectionPing(debuggerModel);
93+
}, COOLDOWN_BETWEEN_PINGS);
8494
}
8595
}
8696

0 commit comments

Comments
 (0)