From a63031089a7d24b0901c38d750b196e53320dc70 Mon Sep 17 00:00:00 2001 From: Edmond Chui <1967998+EdmondChuiHW@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:21:52 +0000 Subject: [PATCH 1/4] rm interface from RNPerfMetrics --- front_end/core/host/RNPerfMetrics.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/front_end/core/host/RNPerfMetrics.ts b/front_end/core/host/RNPerfMetrics.ts index 104997934ab..f2f60f57bf1 100644 --- a/front_end/core/host/RNPerfMetrics.ts +++ b/front_end/core/host/RNPerfMetrics.ts @@ -5,26 +5,20 @@ export type RNReliabilityEventListener = (event: ReactNativeChromeDevToolsEvent) => void; -type UnsunscribeFn = () => void; -export type RNPerfMetrics = { - addEventListener: (listener: RNReliabilityEventListener) => UnsunscribeFn, - removeAllEventListeners: () => void, - sendEvent: (event: ReactNativeChromeDevToolsEvent) => void, -}; - let instance: RNPerfMetrics|null = null; export function getInstance(): RNPerfMetrics { if (instance === null) { - instance = new RNPerfMetricsImpl(); + instance = new RNPerfMetrics(); } return instance; } -class RNPerfMetricsImpl implements RNPerfMetrics { +type UnsunscribeFn = () => void; +class RNPerfMetrics { #listeners: Set = new Set(); - addEventListener(listener: RNReliabilityEventListener): () => void { + addEventListener(listener: RNReliabilityEventListener): UnsunscribeFn { this.#listeners.add(listener); const unsubscribe = (): void => { From 635a2bb06defb8f0152d319ee0e71a54e3e04e65 Mon Sep 17 00:00:00 2001 From: Edmond Chui <1967998+EdmondChuiHW@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:55:39 +0000 Subject: [PATCH 2/4] Fix typo in RNPerfMetrics.ts --- front_end/core/host/RNPerfMetrics.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/front_end/core/host/RNPerfMetrics.ts b/front_end/core/host/RNPerfMetrics.ts index f2f60f57bf1..cc78ad02400 100644 --- a/front_end/core/host/RNPerfMetrics.ts +++ b/front_end/core/host/RNPerfMetrics.ts @@ -14,11 +14,11 @@ export function getInstance(): RNPerfMetrics { return instance; } -type UnsunscribeFn = () => void; +type UnsubscribeFn = () => void; class RNPerfMetrics { #listeners: Set = new Set(); - addEventListener(listener: RNReliabilityEventListener): UnsunscribeFn { + addEventListener(listener: RNReliabilityEventListener): UnsubscribeFn { this.#listeners.add(listener); const unsubscribe = (): void => { From 002e94f43aeef862e052cddcd21dae76e5b62bc5 Mon Sep 17 00:00:00 2001 From: Edmond Chui <1967998+EdmondChuiHW@users.noreply.github.com> Date: Wed, 20 Mar 2024 22:23:47 +0000 Subject: [PATCH 3/4] add launch ID support --- front_end/core/host/RNPerfMetrics.ts | 6 ++++++ front_end/entrypoints/rn_inspector/rn_inspector.ts | 1 + 2 files changed, 7 insertions(+) diff --git a/front_end/core/host/RNPerfMetrics.ts b/front_end/core/host/RNPerfMetrics.ts index cc78ad02400..117428464e3 100644 --- a/front_end/core/host/RNPerfMetrics.ts +++ b/front_end/core/host/RNPerfMetrics.ts @@ -17,6 +17,7 @@ export function getInstance(): RNPerfMetrics { type UnsubscribeFn = () => void; class RNPerfMetrics { #listeners: Set = new Set(); + #launchId: string|null = null; addEventListener(listener: RNReliabilityEventListener): UnsubscribeFn { this.#listeners.add(listener); @@ -51,6 +52,11 @@ class RNPerfMetrics { console.error('Error occurred when calling event listeners', error); } } + + setLaunchId(launchId: string|null): void { + this.#launchId = launchId; + } + } export function registerPerfMetricsGlobalPostMessageHandler(): void { diff --git a/front_end/entrypoints/rn_inspector/rn_inspector.ts b/front_end/entrypoints/rn_inspector/rn_inspector.ts index ca88b10012a..164baf4090f 100644 --- a/front_end/entrypoints/rn_inspector/rn_inspector.ts +++ b/front_end/entrypoints/rn_inspector/rn_inspector.ts @@ -25,6 +25,7 @@ import type * as Sources from '../../panels/sources/sources.js'; Host.RNPerfMetrics.registerPerfMetricsGlobalPostMessageHandler(); +Host.rnPerfMetrics.setLaunchId(Root.Runtime.Runtime.queryParam('launchId')); // Legacy JavaScript Profiler - we support this until Hermes can support the // modern Performance panel. Root.Runtime.experiments.register( From 75315360049cce36533524a2cbd063ca74d45a17 Mon Sep 17 00:00:00 2001 From: Edmond Chui <1967998+EdmondChuiHW@users.noreply.github.com> Date: Wed, 20 Mar 2024 22:27:32 +0000 Subject: [PATCH 4/4] add debugger launch events --- front_end/core/host/RNPerfMetrics.ts | 34 ++++++++++++++++++- .../entrypoints/rn_inspector/rn_inspector.ts | 8 +++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/front_end/core/host/RNPerfMetrics.ts b/front_end/core/host/RNPerfMetrics.ts index 117428464e3..dcc3660988f 100644 --- a/front_end/core/host/RNPerfMetrics.ts +++ b/front_end/core/host/RNPerfMetrics.ts @@ -57,6 +57,25 @@ class RNPerfMetrics { this.#launchId = launchId; } + entryPointLoadingStarted(): void { + this.sendEvent({ + eventName: 'Entrypoint.LoadingStarted', + timestamp: getPerfTimestamp(), + launchId: this.#launchId, + }); + } + + debuggerReadyToPause(): void { + this.sendEvent({ + eventName: 'Debugger.IsReadyToPause', + timestamp: getPerfTimestamp(), + launchId: this.#launchId, + }); + } +} + +function getPerfTimestamp(): DOMHighResTimeStamp { + return performance.timeOrigin + performance.now(); } export function registerPerfMetricsGlobalPostMessageHandler(): void { @@ -70,4 +89,17 @@ export function registerPerfMetricsGlobalPostMessageHandler(): void { }); } -export type ReactNativeChromeDevToolsEvent = {}; +type CommonEventFields = Readonly<{ + timestamp: DOMHighResTimeStamp, + launchId: string | void | null, +}>; + +export type DebuggerLaunchedEvent = Readonly; + +export type DebuggerReadyEvent = Readonly; + +export type ReactNativeChromeDevToolsEvent = DebuggerLaunchedEvent|DebuggerReadyEvent; diff --git a/front_end/entrypoints/rn_inspector/rn_inspector.ts b/front_end/entrypoints/rn_inspector/rn_inspector.ts index 164baf4090f..6af2630b826 100644 --- a/front_end/entrypoints/rn_inspector/rn_inspector.ts +++ b/front_end/entrypoints/rn_inspector/rn_inspector.ts @@ -26,6 +26,14 @@ import type * as Sources from '../../panels/sources/sources.js'; Host.RNPerfMetrics.registerPerfMetricsGlobalPostMessageHandler(); Host.rnPerfMetrics.setLaunchId(Root.Runtime.Runtime.queryParam('launchId')); +Host.rnPerfMetrics.entryPointLoadingStarted(); + +SDK.TargetManager.TargetManager.instance().addModelListener( + SDK.DebuggerModel.DebuggerModel, + SDK.DebuggerModel.Events.DebuggerIsReadyToPause, + () => Host.rnPerfMetrics.debuggerReadyToPause(), +); + // Legacy JavaScript Profiler - we support this until Hermes can support the // modern Performance panel. Root.Runtime.experiments.register(