Skip to content

Commit 2ffa339

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

3 files changed

Lines changed: 40 additions & 27 deletions

File tree

front_end/core/host/RNPerfMetrics.ts

Lines changed: 23 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,8 @@ 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+
this.#initialResourcesLoadedInfo = {count};
196192
}
197193

198194
fuseboxSetClientMetadataStarted(): void {
@@ -215,10 +211,21 @@ class RNPerfMetrics {
215211
}
216212
}
217213

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

224231
heapSnapshotStarted(): void {
@@ -432,13 +439,6 @@ export type DeveloperResourceLoadingFinishedEvent = Readonly<{
432439
}>,
433440
}>;
434441

435-
export type AllInitialDeveloperResourcesLoadingFinished = Readonly<{
436-
eventName: 'DeveloperResource.AllInitialLoadingFinished',
437-
params: Readonly<{
438-
count: number,
439-
}>,
440-
}>;
441-
442442
export type FuseboxSetClientMetadataStartedEvent = Readonly<{
443443
eventName: 'FuseboxSetClientMetadataStarted',
444444
}>;
@@ -511,16 +511,19 @@ export type StackTraceFrameUrlResolutionFailed = Readonly<{
511511
}>,
512512
}>;
513513

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

518521
export type ReactNativeChromeDevToolsEvent =
519522
EntrypointLoadingStartedEvent|EntrypointLoadingFinishedEvent|DebuggerReadyEvent|BrowserVisibilityChangeEvent|
520523
BrowserErrorEvent|RemoteDebuggingTerminatedEvent|DeveloperResourceLoadingStartedEvent|
521-
DeveloperResourceLoadingFinishedEvent|AllInitialDeveloperResourcesLoadingFinished|FuseboxSetClientMetadataStartedEvent|
524+
DeveloperResourceLoadingFinishedEvent|FuseboxSetClientMetadataStartedEvent|
522525
FuseboxSetClientMetadataFinishedEvent|MemoryPanelActionStartedEvent|MemoryPanelActionFinishedEvent|
523526
PanelShownEvent|PanelClosedEvent|StackTraceSymbolicationSucceeded|StackTraceSymbolicationFailed|
524-
StackTraceFrameUrlResolutionSucceeded|StackTraceFrameUrlResolutionFailed|FirstSteadyPing;
527+
StackTraceFrameUrlResolutionSucceeded|StackTraceFrameUrlResolutionFailed|FirstSteadyPingAfterInitialResourcesLoaded;
525528

526529
export type DecoratedReactNativeChromeDevToolsEvent = CommonEventFields&ReactNativeChromeDevToolsEvent;

front_end/core/sdk/PageResourceLoader.ts

Lines changed: 4 additions & 4 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>();
@@ -359,9 +359,9 @@ export class PageResourceLoader extends Common.ObjectWrapper.ObjectWrapper<Event
359359
// Will be decreased to 0 right after this function in "releaseLoadSlot".
360360
// Tracking it here so it is next to the rest of "rnPerfMetrics" in this file.
361361
const allResourcesLoaded = this.#currentlyLoading === 1;
362-
if (allResourcesLoaded && !this.#reportedAllInitialResourcesLoaded) {
363-
Host.rnPerfMetrics.allInitialDeveloperResourcesLoadingFinished(this.getNumberOfResources().resources);
364-
this.#reportedAllInitialResourcesLoaded = true;
362+
if (allResourcesLoaded && !this.#reportedInitialResourcesLoaded) {
363+
Host.rnPerfMetrics.initialResourcesLoaded(this.getNumberOfResources().resources);
364+
this.#reportedInitialResourcesLoaded = true;
365365
}
366366

367367
return result;

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)