Skip to content

Commit 07a8b8c

Browse files
committed
Formalise ENABLE_TIMELINE_FRAMES experiment (#242)
1 parent ff7f376 commit 07a8b8c

File tree

9 files changed

+61
-2
lines changed

9 files changed

+61
-2
lines changed

front_end/core/rn_experiments/experimentsImpl.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,9 @@ Instance.register({
184184
unstable: false,
185185
enabledByDefault: ({ isReactNativeEntryPoint }) => isReactNativeEntryPoint,
186186
});
187+
188+
Instance.register({
189+
name: RNExperimentName.ENABLE_TIMELINE_FRAMES,
190+
title: 'Enable performance frames track',
191+
unstable: true,
192+
});

front_end/core/root/Runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ export const experiments = new ExperimentsSupport();
305305
export enum RNExperimentName {
306306
REACT_NATIVE_SPECIFIC_UI = 'react-native-specific-ui',
307307
JS_HEAP_PROFILER_ENABLE = 'js-heap-profiler-enable',
308+
ENABLE_TIMELINE_FRAMES = 'enable-timeline-frames',
308309
}
309310

310311
export enum ConditionName {
@@ -339,6 +340,7 @@ export const enum ExperimentName {
339340
JS_HEAP_PROFILER_ENABLE = RNExperimentName.JS_HEAP_PROFILER_ENABLE,
340341
REACT_NATIVE_SPECIFIC_UI = RNExperimentName.REACT_NATIVE_SPECIFIC_UI,
341342
NOT_REACT_NATIVE_SPECIFIC_UI = '!' + RNExperimentName.REACT_NATIVE_SPECIFIC_UI,
343+
ENABLE_TIMELINE_FRAMES = RNExperimentName.ENABLE_TIMELINE_FRAMES,
342344
}
343345

344346
export enum GenAiEnterprisePolicyValue {

front_end/entrypoints/rn_fusebox/FuseboxFeatureObserver.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ const UIStrings = {
2929
* @description Title shown when a feature is unavailable due to multiple React Native hosts.
3030
*/
3131
multiHostFeatureUnavailableTitle: 'Feature is unavailable',
32+
/**
33+
* @description Message for the "settings changed" banner shown when a reload
34+
* is required for frame timings in the Performance panel.
35+
*/
36+
reloadRequiredForTimelineFramesMessage:
37+
'Frame timings and screenshots are now available in the Performance panel. Please reload to enable.',
3238
/**
3339
* @description Detail message shown when a feature is disabled due to multiple React Native hosts.
3440
*/
@@ -75,7 +81,7 @@ export class FuseboxFeatureObserver implements
7581
#handleMetadataUpdated(
7682
event: Common.EventTarget.EventTargetEvent<Protocol.ReactNativeApplication.MetadataUpdatedEvent>): void {
7783
// eslint-disable-next-line @typescript-eslint/naming-convention
78-
const {unstable_isProfilingBuild, unstable_networkInspectionEnabled} = event.data;
84+
const {unstable_isProfilingBuild, unstable_networkInspectionEnabled, unstable_frameRecordingEnabled} = event.data;
7985

8086
if (unstable_isProfilingBuild) {
8187
FuseboxWindowTitleManager.instance().setSuffix('[PROFILING]');
@@ -87,6 +93,10 @@ export class FuseboxFeatureObserver implements
8793
if (!unstable_networkInspectionEnabled && !Root.Runtime.conditions.reactNativeExpoNetworkPanel()) {
8894
this.#hideNetworkPanel();
8995
}
96+
97+
if (unstable_frameRecordingEnabled) {
98+
void this.#ensureTimelineFramesEnabled();
99+
}
90100
}
91101

92102
#handleSystemStateChanged(
@@ -132,6 +142,14 @@ export class FuseboxFeatureObserver implements
132142
});
133143
}
134144

145+
async #ensureTimelineFramesEnabled(): Promise<void> {
146+
if (!Root.Runtime.experiments.isEnabled(Root.Runtime.RNExperimentName.ENABLE_TIMELINE_FRAMES)) {
147+
Root.Runtime.experiments.setEnabled(Root.Runtime.RNExperimentName.ENABLE_TIMELINE_FRAMES, true);
148+
UI.InspectorView?.InspectorView?.instance()?.displayReloadRequiredWarning(
149+
i18nString(UIStrings.reloadRequiredForTimelineFramesMessage));
150+
}
151+
}
152+
135153
#disableSingleHostOnlyFeatures(): void {
136154
if (this.#singleHostFeaturesDisabled) {
137155
return;

front_end/generated/protocol.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ export namespace ReactNativeApplication {
6161
* Enables the Network Panel.
6262
*/
6363
unstable_networkInspectionEnabled?: boolean;
64+
/**
65+
* Whether Frame Timings and screenshots are supported in performance
66+
* traces.
67+
*/
68+
unstable_frameRecordingEnabled?: boolean;
6469
}
6570

6671
/**

front_end/panels/timeline/TimelineFlameChartDataProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ export class TimelineFlameChartDataProvider extends Common.ObjectWrapper.ObjectW
615615
// In CPU Profiles the trace data will not have frames nor
616616
// screenshots, so we can keep this call as it will be a no-op in
617617
// these cases.
618-
if (!this.isReactNative) {
618+
if (Root.Runtime.experiments.isEnabled(Root.Runtime.RNExperimentName.ENABLE_TIMELINE_FRAMES) || !this.isReactNative) {
619619
this.#appendFramesAndScreenshotsTrack();
620620
}
621621

front_end/panels/timeline/TimelinePanel.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,14 @@ export class TimelinePanel extends UI.Panel.Panel implements Client, TimelineMod
712712
SDK.ReactNativeApplicationModel.ReactNativeApplicationModel,
713713
{
714714
modelAdded: (model: SDK.ReactNativeApplicationModel.ReactNativeApplicationModel) => {
715+
model.addEventListener(
716+
SDK.ReactNativeApplicationModel.Events.METADATA_UPDATED,
717+
(event: Common.EventTarget.EventTargetEvent<Protocol.ReactNativeApplication.MetadataUpdatedEvent>) => {
718+
if (event.data.platform === 'android') {
719+
this.showScreenshotsToolbarCheckbox?.setVisible(true);
720+
}
721+
}
722+
);
715723
model.addEventListener(
716724
SDK.ReactNativeApplicationModel.Events.TRACE_REQUESTED, () => this.rnPrepareForTraceCapturedInBackground());
717725
},
@@ -1192,6 +1200,17 @@ export class TimelinePanel extends UI.Panel.Panel implements Client, TimelineMod
11921200
if (!isNode && !isReactNative) {
11931201
this.showScreenshotsToolbarCheckbox =
11941202
this.createSettingCheckbox(this.showScreenshotsSetting, i18nString(UIStrings.captureScreenshots));
1203+
1204+
let showScreenshotsToggle = false;
1205+
1206+
const reactNativeApplicationModel = SDK.TargetManager.TargetManager.instance().primaryPageTarget()?.model(SDK.ReactNativeApplicationModel.ReactNativeApplicationModel);
1207+
if (reactNativeApplicationModel !== null && reactNativeApplicationModel !== undefined) {
1208+
showScreenshotsToggle = reactNativeApplicationModel.metadataCached?.platform === 'android';
1209+
}
1210+
1211+
// Only show this toggle if we are on android, to address a possible race condition with the platform metadata,
1212+
// this is also checked again on SDK.ReactNativeApplicationModel.Events.METADATA_UPDATED
1213+
this.showScreenshotsToolbarCheckbox.setVisible(showScreenshotsToggle);
11951214
this.panelToolbar.appendToolbarItem(this.showScreenshotsToolbarCheckbox);
11961215
}
11971216

front_end/testing/EnvironmentHelpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const REGISTERED_EXPERIMENTS = [
130130
Root.Runtime.ExperimentName.TIMELINE_ALTERNATIVE_NAVIGATION,
131131
Root.Runtime.ExperimentName.REACT_NATIVE_SPECIFIC_UI,
132132
Root.Runtime.ExperimentName.NOT_REACT_NATIVE_SPECIFIC_UI,
133+
Root.Runtime.ExperimentName.ENABLE_TIMELINE_FRAMES,
133134
];
134135

135136
export async function initializeGlobalVars({reset = true} = {}) {

third_party/blink/public/devtools_protocol/browser_protocol.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
"description": "Enables the Network Panel.",
7070
"optional": true,
7171
"type": "boolean"
72+
},
73+
{
74+
"name": "unstable_frameRecordingEnabled",
75+
"description": "Whether Frame Timings and screenshots are supported in performance traces.",
76+
"optional": true,
77+
"type": "boolean"
7278
}
7379
]
7480
},

third_party/blink/public/devtools_protocol/react_native_domains.pdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ experimental domain ReactNativeApplication
3030
optional boolean unstable_isProfilingBuild
3131
# Enables the Network Panel.
3232
optional boolean unstable_networkInspectionEnabled
33+
# Whether Frame Timings and screenshots are supported in performance traces.
34+
optional boolean unstable_frameRecordingEnabled
3335

3436
# Emitted when assertions about the debugger backend have changed.
3537
event systemStateChanged

0 commit comments

Comments
 (0)