Skip to content

Commit 06d7de0

Browse files
committed
report on first steady ping
1 parent 4bec977 commit 06d7de0

2 files changed

Lines changed: 46 additions & 8 deletions

File tree

front_end/core/host/RNPerfMetrics.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ class RNPerfMetrics {
215215
}
216216
}
217217

218+
firstSteadyPing(): void {
219+
this.sendEvent({
220+
eventName: 'FirstSteadyPing',
221+
});
222+
}
223+
218224
heapSnapshotStarted(): void {
219225
this.sendEvent({
220226
eventName: 'MemoryPanelActionStarted',
@@ -505,12 +511,16 @@ export type StackTraceFrameUrlResolutionFailed = Readonly<{
505511
}>,
506512
}>;
507513

514+
export type FirstSteadyPing = Readonly<{
515+
eventName: 'FirstSteadyPing',
516+
}>;
517+
508518
export type ReactNativeChromeDevToolsEvent =
509519
EntrypointLoadingStartedEvent|EntrypointLoadingFinishedEvent|DebuggerReadyEvent|BrowserVisibilityChangeEvent|
510520
BrowserErrorEvent|RemoteDebuggingTerminatedEvent|DeveloperResourceLoadingStartedEvent|
511521
DeveloperResourceLoadingFinishedEvent|AllInitialDeveloperResourcesLoadingFinished|FuseboxSetClientMetadataStartedEvent|
512522
FuseboxSetClientMetadataFinishedEvent|MemoryPanelActionStartedEvent|MemoryPanelActionFinishedEvent|
513523
PanelShownEvent|PanelClosedEvent|StackTraceSymbolicationSucceeded|StackTraceSymbolicationFailed|
514-
StackTraceFrameUrlResolutionSucceeded|StackTraceFrameUrlResolutionFailed;
524+
StackTraceFrameUrlResolutionSucceeded|StackTraceFrameUrlResolutionFailed|FirstSteadyPing;
515525

516526
export type DecoratedReactNativeChromeDevToolsEvent = CommonEventFields&ReactNativeChromeDevToolsEvent;

front_end/entrypoints/inspector_main/InspectorMain.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import * as UI from '../../ui/legacy/legacy.js';
1515

1616
import nodeIconStyles from './nodeIcon.css.js';
1717

18+
const COOLDOWN_BETWEEN_PINGS = 3000;
19+
const LOW_PING_THRESHOLD = 200;
20+
1821
const UIStrings = {
1922
/**
2023
* @description Text that refers to the main target. The main target is the primary webpage that
@@ -46,6 +49,8 @@ const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
4649
let inspectorMainImplInstance: InspectorMainImpl;
4750

4851
export class InspectorMainImpl implements Common.Runnable.Runnable {
52+
#consecutiveLowPing = 0;
53+
4954
static instance(opts: {
5055
forceNew: boolean|null,
5156
} = {forceNew: null}): InspectorMainImpl {
@@ -57,6 +62,28 @@ export class InspectorMainImpl implements Common.Runnable.Runnable {
5762
return inspectorMainImplInstance;
5863
}
5964

65+
async #measureMainConnectionPing(debuggerModel: SDK.DebuggerModel.DebuggerModel): Promise<void> {
66+
if (!debuggerModel.debuggerEnabled()) {
67+
return;
68+
}
69+
70+
const startMs = Date.now();
71+
await debuggerModel.syncDebuggerId();
72+
const ping = Date.now() - startMs;
73+
74+
if (ping > LOW_PING_THRESHOLD) {
75+
this.#consecutiveLowPing = 0;
76+
} else {
77+
this.#consecutiveLowPing++;
78+
}
79+
80+
if (this.#consecutiveLowPing > 1) {
81+
Host.rnPerfMetrics.firstSteadyPing();
82+
} else {
83+
setTimeout(() => void this.#measureMainConnectionPing(debuggerModel), COOLDOWN_BETWEEN_PINGS);
84+
}
85+
}
86+
6087
async run(): Promise<void> {
6188
let firstCall = true;
6289
await SDK.Connections.initMainConnection(async () => {
@@ -94,13 +121,14 @@ export class InspectorMainImpl implements Common.Runnable.Runnable {
94121
}
95122
firstCall = false;
96123

97-
if (waitForDebuggerInPage) {
98-
const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel);
99-
if (debuggerModel) {
100-
if (!debuggerModel.isReadyToPause()) {
101-
await debuggerModel.once(SDK.DebuggerModel.Events.DebuggerIsReadyToPause);
102-
}
103-
debuggerModel.pause();
124+
const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel);
125+
if (debuggerModel) {
126+
void this.#measureMainConnectionPing(debuggerModel);
127+
if (waitForDebuggerInPage) {
128+
if (!debuggerModel.isReadyToPause()) {
129+
await debuggerModel.once(SDK.DebuggerModel.Events.DebuggerIsReadyToPause);
130+
}
131+
debuggerModel.pause();
104132
}
105133
}
106134

0 commit comments

Comments
 (0)