Skip to content

Commit 7edec7c

Browse files
authored
track the duration between user setting a breakpoint and the breakpoint being painted (#201)
1 parent 273f026 commit 7edec7c

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

front_end/core/host/RNPerfMetrics.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ class RNPerfMetrics {
298298
});
299299
}
300300

301+
manualBreakpointSetSucceeded(bpSettingDuration: number): void {
302+
this.sendEvent({
303+
eventName: 'ManualBreakpointSetSucceeded',
304+
params: {
305+
bpSettingDuration
306+
}
307+
});
308+
}
309+
301310
panelShown(_panelName: string, _isLaunching?: boolean): void {
302311
// no-op
303312
// We only care about the "main" and "drawer" panels for now via panelShownInLocation(…)
@@ -489,12 +498,19 @@ export type StackTraceFrameUrlResolutionFailed = Readonly<{
489498
}>,
490499
}>;
491500

501+
export type ManualBreakpointSetSucceeded = Readonly<{
502+
eventName: 'ManualBreakpointSetSucceeded',
503+
params: Readonly<{
504+
bpSettingDuration: number,
505+
}>,
506+
}>;
507+
492508
export type ReactNativeChromeDevToolsEvent =
493509
EntrypointLoadingStartedEvent|EntrypointLoadingFinishedEvent|DebuggerReadyEvent|BrowserVisibilityChangeEvent|
494510
BrowserErrorEvent|RemoteDebuggingTerminatedEvent|DeveloperResourceLoadingStartedEvent|
495511
DeveloperResourceLoadingFinishedEvent|FuseboxSetClientMetadataStartedEvent|FuseboxSetClientMetadataFinishedEvent|
496512
MemoryPanelActionStartedEvent|MemoryPanelActionFinishedEvent|PanelShownEvent|PanelClosedEvent|
497513
StackTraceSymbolicationSucceeded|StackTraceSymbolicationFailed|StackTraceFrameUrlResolutionSucceeded|
498-
StackTraceFrameUrlResolutionFailed;
514+
StackTraceFrameUrlResolutionFailed|ManualBreakpointSetSucceeded;
499515

500516
export type DecoratedReactNativeChromeDevToolsEvent = CommonEventFields&ReactNativeChromeDevToolsEvent;

front_end/panels/sources/DebuggerPlugin.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,37 @@ export class DebuggerPlugin extends Plugin {
308308
}),
309309
CodeMirror.lineNumbers({
310310
domEventHandlers: {
311-
click: (view, block, event) => this.handleGutterClick(view.state.doc.lineAt(block.from), event as MouseEvent),
311+
click: (view, block, event) => {
312+
if (Host.rnPerfMetrics.isEnabled()) {
313+
const element = (event.target as Element);
314+
const isClickAddingBreakpoint = (
315+
element.classList &&
316+
element.classList.contains('cm-gutterElement') &&
317+
!element.classList.contains('cm-breakpoint')
318+
);
319+
if (isClickAddingBreakpoint) {
320+
const setBreakpointStartMs = Date.now();
321+
const observer = new MutationObserver(mutations => {
322+
mutations.forEach(mutation => {
323+
if (
324+
mutation.type === 'attributes' &&
325+
mutation.attributeName === 'class'
326+
) {
327+
if (element.classList.contains('cm-breakpoint')) {
328+
Host.rnPerfMetrics.manualBreakpointSetSucceeded(Date.now() - setBreakpointStartMs);
329+
observer.disconnect();
330+
}
331+
}
332+
});
333+
});
334+
observer.observe(element, { attributes: true });
335+
// if there's no breakpoint set on the line in 3 seconds, don't track the event.
336+
// this could happen due to a different line getting the breakpoint, or an error.
337+
setTimeout(() => observer.disconnect(), 3000);
338+
}
339+
}
340+
return this.handleGutterClick(view.state.doc.lineAt(block.from), event as MouseEvent);
341+
},
312342
},
313343
}),
314344
breakpointMarkers,

0 commit comments

Comments
 (0)