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

Perf: add support for launch ID #27

Merged
merged 3 commits into from
Mar 26, 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
20 changes: 10 additions & 10 deletions front_end/core/host/RNPerfMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@

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 UnsubscribeFn = () => void;
class RNPerfMetrics {
#listeners: Set<RNReliabilityEventListener> = new Set();
#launchId: string|null = null;
huntie marked this conversation as resolved.
Show resolved Hide resolved

addEventListener(listener: RNReliabilityEventListener): () => void {
addEventListener(listener: RNReliabilityEventListener): UnsubscribeFn {
this.#listeners.add(listener);

const unsubscribe = (): void => {
Expand Down Expand Up @@ -57,6 +52,11 @@ class RNPerfMetricsImpl implements RNPerfMetrics {
console.error('Error occurred when calling event listeners', error);
}
}

setLaunchId(launchId: string|null): void {
this.#launchId = launchId;
}

}

export function registerPerfMetricsGlobalPostMessageHandler(): void {
Expand Down
1 change: 1 addition & 0 deletions front_end/entrypoints/rn_inspector/rn_inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type * as Sources from '../../panels/sources/sources.js';

Host.RNPerfMetrics.registerPerfMetricsGlobalPostMessageHandler();

Host.rnPerfMetrics.setLaunchId(Root.Runtime.Runtime.queryParam('launchId'));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different casing here compared to L23? 🤔

Copy link
Author

@EdmondChuiHW EdmondChuiHW Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah one is static/constructor. One is the global instance. Following the pattern of the upstream UserMetrics:

/** @constructor */
Host.UserMetrics = HostModule.UserMetrics.UserMetrics;
Host.UserMetrics._PanelCodes = HostModule.UserMetrics.PanelCodes;
/** @enum {number} */
Host.UserMetrics.Action = HostModule.UserMetrics.Action;
/** @type {!Host.UserMetrics} */
Host.userMetrics = HostModule.userMetrics;

Can move the first call to become an instance method instead. At first it was a single function, but this repo enforces a namespace-style import so that's why it was put into RNPerfMetrics "static".

// Legacy JavaScript Profiler - we support this until Hermes can support the
// modern Performance panel.
Root.Runtime.experiments.register(
Expand Down
Loading