Skip to content

Commit 54d80ef

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

3 files changed

Lines changed: 33 additions & 24 deletions

File tree

front_end/core/host/RNPerfMetrics.ts

Lines changed: 24 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+
#initialBundlesLoadedInfo: 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,22 @@ class RNPerfMetrics {
215211
}
216212
}
217213

218-
firstSteadyPing(): void {
214+
tryReportingSteadyPing(): boolean {
215+
if (this.#initialBundlesLoadedInfo === null) {
216+
return false;
217+
}
218+
219+
// const [navigationEntry] = performance.getEntriesByType('navigation');
220+
// eslint-disable-next-line
221+
console.info('Startup time is %s', performance.now());
222+
219223
this.sendEvent({
220-
eventName: 'FirstSteadyPing',
224+
eventName: 'FirstSteadyPingAfterInitialResourcesLoaded',
225+
params: {
226+
bundleCount: this.#initialBundlesLoadedInfo.count,
227+
}
221228
});
229+
return true;
222230
}
223231

224232
heapSnapshotStarted(): void {
@@ -432,13 +440,6 @@ export type DeveloperResourceLoadingFinishedEvent = Readonly<{
432440
}>,
433441
}>;
434442

435-
export type AllInitialDeveloperResourcesLoadingFinished = Readonly<{
436-
eventName: 'DeveloperResource.AllInitialLoadingFinished',
437-
params: Readonly<{
438-
count: number,
439-
}>,
440-
}>;
441-
442443
export type FuseboxSetClientMetadataStartedEvent = Readonly<{
443444
eventName: 'FuseboxSetClientMetadataStarted',
444445
}>;
@@ -511,16 +512,19 @@ export type StackTraceFrameUrlResolutionFailed = Readonly<{
511512
}>,
512513
}>;
513514

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

518522
export type ReactNativeChromeDevToolsEvent =
519523
EntrypointLoadingStartedEvent|EntrypointLoadingFinishedEvent|DebuggerReadyEvent|BrowserVisibilityChangeEvent|
520524
BrowserErrorEvent|RemoteDebuggingTerminatedEvent|DeveloperResourceLoadingStartedEvent|
521-
DeveloperResourceLoadingFinishedEvent|AllInitialDeveloperResourcesLoadingFinished|FuseboxSetClientMetadataStartedEvent|
525+
DeveloperResourceLoadingFinishedEvent|FuseboxSetClientMetadataStartedEvent|
522526
FuseboxSetClientMetadataFinishedEvent|MemoryPanelActionStartedEvent|MemoryPanelActionFinishedEvent|
523527
PanelShownEvent|PanelClosedEvent|StackTraceSymbolicationSucceeded|StackTraceSymbolicationFailed|
524-
StackTraceFrameUrlResolutionSucceeded|StackTraceFrameUrlResolutionFailed|FirstSteadyPing;
528+
StackTraceFrameUrlResolutionSucceeded|StackTraceFrameUrlResolutionFailed|FirstSteadyPingAfterInitialResourcesLoaded;
525529

526530
export type DecoratedReactNativeChromeDevToolsEvent = CommonEventFields&ReactNativeChromeDevToolsEvent;

front_end/core/sdk/PageResourceLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ export class PageResourceLoader extends Common.ObjectWrapper.ObjectWrapper<Event
360360
// Tracking it here so it is next to the rest of "rnPerfMetrics" in this file.
361361
const allResourcesLoaded = this.#currentlyLoading === 1;
362362
if (allResourcesLoaded && !this.#reportedAllInitialResourcesLoaded) {
363-
Host.rnPerfMetrics.allInitialDeveloperResourcesLoadingFinished(this.getNumberOfResources().resources);
363+
Host.rnPerfMetrics.initialResourcesLoaded(this.getNumberOfResources().resources);
364364
this.#reportedAllInitialResourcesLoaded = true;
365365
}
366366

front_end/entrypoints/inspector_main/InspectorMain.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,15 @@ export class InspectorMainImpl implements Common.Runnable.Runnable {
7777
this.#consecutiveLowPing++;
7878
}
7979

80+
let reportedSteadyPing = false;
8081
if (this.#consecutiveLowPing > 1) {
81-
Host.rnPerfMetrics.firstSteadyPing();
82-
} else {
83-
setTimeout(() => void this.#measureMainConnectionPing(debuggerModel), COOLDOWN_BETWEEN_PINGS);
82+
reportedSteadyPing = Host.rnPerfMetrics.tryReportingSteadyPing();
83+
}
84+
85+
if (!reportedSteadyPing) {
86+
setTimeout(() => {
87+
void this.#measureMainConnectionPing(debuggerModel);
88+
}, COOLDOWN_BETWEEN_PINGS);
8489
}
8590
}
8691

0 commit comments

Comments
 (0)