Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor perf #67

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions front_end/core/host/RNPerfMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ class RNPerfMetrics {
}
}

registerPerfMetricsGlobalPostMessageHandler(): void {
if (globalThis.enableReactNativePerfMetrics !== true ||
globalThis.enableReactNativePerfMetricsGlobalPostMessage !== true) {
return;
}

this.addEventListener(event => {
window.postMessage({event, tag: 'react-native-chrome-devtools-perf-metrics'}, window.location.origin);
});
}

setLaunchId(launchId: string|null): void {
this.#launchId = launchId;
}
Expand Down Expand Up @@ -80,17 +91,6 @@ function getPerfTimestamp(): DOMHighResTimeStamp {
return performance.timeOrigin + performance.now();
}

export function registerPerfMetricsGlobalPostMessageHandler(): void {
if (globalThis.enableReactNativePerfMetrics !== true ||
globalThis.enableReactNativePerfMetricsGlobalPostMessage !== true) {
return;
}

getInstance().addEventListener(event => {
window.postMessage({event, tag: 'react-native-chrome-devtools-perf-metrics'}, window.location.origin);
});
}

type CommonEventFields = Readonly<{
timestamp: DOMHighResTimeStamp,
launchId: string | void | null,
Expand Down
14 changes: 8 additions & 6 deletions front_end/entrypoints/rn_fusebox/rn_fusebox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ import * as SDK from '../../core/sdk/sdk.js';
import * as UI from '../../ui/legacy/legacy.js';
import * as Main from '../main/main.js';

import type * as InspectorBackend from '../../core/protocol_client/InspectorBackend.js';
import type * as Platform from '../../core/platform/platform.js';
import type * as Sources from '../../panels/sources/sources.js';
import * as RNExperiments from '../../core/rn_experiments/rn_experiments.js';

/*
* To ensure accurate timing measurements,
* please make sure these perf metrics lines are called ahead of everything else
*/
Host.rnPerfMetrics.registerPerfMetricsGlobalPostMessageHandler();
Host.rnPerfMetrics.setLaunchId(Root.Runtime.Runtime.queryParam('launchId'));
Host.rnPerfMetrics.entryPointLoadingStarted('rn_fusebox');

const UIStrings = {
/**
*@description Title of the 'React Native' tool in the Network Navigator View, which is part of the Sources tool
Expand Down Expand Up @@ -67,11 +74,6 @@ RNExperiments.RNExperimentsImpl.Instance.enableExperimentsByDefault([
Root.Runtime.ExperimentName.REACT_NATIVE_SPECIFIC_UI,
]);

Host.RNPerfMetrics.registerPerfMetricsGlobalPostMessageHandler();

Host.rnPerfMetrics.setLaunchId(Root.Runtime.Runtime.queryParam('launchId'));
Host.rnPerfMetrics.entryPointLoadingStarted('rn_fusebox');

class FuseboxClientMetadataModel extends SDK.SDKModel.SDKModel<void> {
constructor(target: SDK.Target.Target) {
super(target);
Expand Down
7 changes: 5 additions & 2 deletions front_end/entrypoints/rn_inspector/rn_inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import type * as Sources from '../../panels/sources/sources.js';
import * as RNExperiments from '../../core/rn_experiments/rn_experiments.js';
import * as Host from '../../core/host/host.js';

Host.RNPerfMetrics.registerPerfMetricsGlobalPostMessageHandler();

/*
* To ensure accurate timing measurements,
* please make sure these perf metrics lines are called ahead of everything else
*/
Host.rnPerfMetrics.registerPerfMetricsGlobalPostMessageHandler();
Host.rnPerfMetrics.setLaunchId(Root.Runtime.Runtime.queryParam('launchId'));
Host.rnPerfMetrics.entryPointLoadingStarted('rn_inspector');

Expand Down
Loading