Skip to content

Commit 7e6fa15

Browse files
author
Brian Vaughn
committed
Add screenshots to Scheduling Profiler
1 parent e4e8226 commit 7e6fa15

File tree

10 files changed

+355
-18
lines changed

10 files changed

+355
-18
lines changed

packages/react-devtools-extensions/src/parseHookNames/parseHookNames.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {__DEBUG__} from 'react-devtools-shared/src/constants';
1616
import {getHookSourceLocationKey} from 'react-devtools-shared/src/hookNamesCache';
1717
import {decodeHookMap} from '../generateHookMap';
1818
import {getHookNameForLocation} from '../getHookNameForLocation';
19+
import {decodeBase64String} from 'react-devtools-shared/src/encoding';
1920

2021
import type {MixedSourceMap} from '../SourceMapTypes';
2122
import type {HookMap} from '../generateHookMap';
@@ -177,20 +178,6 @@ export async function parseHookNames(
177178
.then(() => findHookNames(hooksList, locationKeyToHookSourceData));
178179
}
179180

180-
function decodeBase64String(encoded: string): Object {
181-
if (typeof atob === 'function') {
182-
return atob(encoded);
183-
} else if (
184-
typeof Buffer !== 'undefined' &&
185-
Buffer !== null &&
186-
typeof Buffer.from === 'function'
187-
) {
188-
return Buffer.from(encoded, 'base64');
189-
} else {
190-
throw Error('Cannot decode base64 string');
191-
}
192-
}
193-
194181
function extractAndLoadSourceMaps(
195182
locationKeyToHookSourceData: Map<string, HookSourceData>,
196183
wasmMappingsURL: string,

packages/react-devtools-scheduling-profiler/src/CanvasPage.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
NativeEventsView,
4747
ReactMeasuresView,
4848
SchedulingEventsView,
49+
SnapshotsView,
4950
SuspenseEventsView,
5051
TimeAxisMarkersView,
5152
UserTimingMarksView,
@@ -157,6 +158,7 @@ function AutoSizedCanvas({
157158
const componentMeasuresViewRef = useRef(null);
158159
const reactMeasuresViewRef = useRef(null);
159160
const flamechartViewRef = useRef(null);
161+
const snapshotsViewRef = useRef(null);
160162

161163
const {hideMenu: hideContextMenu} = useContext(RegistryContext);
162164

@@ -304,6 +306,18 @@ function AutoSizedCanvas({
304306
);
305307
}
306308

309+
let snapshotsViewWrapper = null;
310+
if (data.snapshots.length > 0) {
311+
const snapshotsView = new SnapshotsView(surface, defaultFrame, data);
312+
snapshotsViewRef.current = snapshotsView;
313+
snapshotsViewWrapper = createViewHelper(
314+
snapshotsView,
315+
'snapshots',
316+
true,
317+
true,
318+
);
319+
}
320+
307321
const flamechartView = new FlamechartView(
308322
surface,
309323
defaultFrame,
@@ -340,6 +354,9 @@ function AutoSizedCanvas({
340354
if (componentMeasuresViewWrapper !== null) {
341355
rootView.addSubview(componentMeasuresViewWrapper);
342356
}
357+
if (snapshotsViewWrapper !== null) {
358+
rootView.addSubview(snapshotsViewWrapper);
359+
}
343360
rootView.addSubview(flamechartViewWrapper);
344361

345362
const verticalScrollOverflowView = new VerticalScrollOverflowView(
@@ -389,6 +406,7 @@ function AutoSizedCanvas({
389406
measure: null,
390407
nativeEvent: null,
391408
schedulingEvent: null,
409+
snapshot: null,
392410
suspenseEvent: null,
393411
userTimingMark: null,
394412
};
@@ -447,6 +465,7 @@ function AutoSizedCanvas({
447465
measure: null,
448466
nativeEvent: null,
449467
schedulingEvent: null,
468+
snapshot: null,
450469
suspenseEvent: null,
451470
userTimingMark,
452471
});
@@ -465,6 +484,7 @@ function AutoSizedCanvas({
465484
measure: null,
466485
nativeEvent,
467486
schedulingEvent: null,
487+
snapshot: null,
468488
suspenseEvent: null,
469489
userTimingMark: null,
470490
});
@@ -483,6 +503,7 @@ function AutoSizedCanvas({
483503
measure: null,
484504
nativeEvent: null,
485505
schedulingEvent,
506+
snapshot: null,
486507
suspenseEvent: null,
487508
userTimingMark: null,
488509
});
@@ -501,6 +522,7 @@ function AutoSizedCanvas({
501522
measure: null,
502523
nativeEvent: null,
503524
schedulingEvent: null,
525+
snapshot: null,
504526
suspenseEvent,
505527
userTimingMark: null,
506528
});
@@ -519,6 +541,7 @@ function AutoSizedCanvas({
519541
measure,
520542
nativeEvent: null,
521543
schedulingEvent: null,
544+
snapshot: null,
522545
suspenseEvent: null,
523546
userTimingMark: null,
524547
});
@@ -540,6 +563,26 @@ function AutoSizedCanvas({
540563
measure: null,
541564
nativeEvent: null,
542565
schedulingEvent: null,
566+
snapshot: null,
567+
suspenseEvent: null,
568+
userTimingMark: null,
569+
});
570+
}
571+
};
572+
}
573+
574+
const {current: snapshotsView} = snapshotsViewRef;
575+
if (snapshotsView) {
576+
snapshotsView.onHover = snapshot => {
577+
if (!hoveredEvent || hoveredEvent.snapshot !== snapshot) {
578+
setHoveredEvent({
579+
componentMeasure: null,
580+
data,
581+
flamechartStackFrame: null,
582+
measure: null,
583+
nativeEvent: null,
584+
schedulingEvent: null,
585+
snapshot,
543586
suspenseEvent: null,
544587
userTimingMark: null,
545588
});
@@ -561,6 +604,7 @@ function AutoSizedCanvas({
561604
measure: null,
562605
nativeEvent: null,
563606
schedulingEvent: null,
607+
snapshot: null,
564608
suspenseEvent: null,
565609
userTimingMark: null,
566610
});

packages/react-devtools-scheduling-profiler/src/EventTooltip.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
ReactProfilerData,
1818
Return,
1919
SchedulingEvent,
20+
Snapshot,
2021
SuspenseEvent,
2122
UserTimingMark,
2223
} from './types';
@@ -87,6 +88,7 @@ export default function EventTooltip({
8788
measure,
8889
nativeEvent,
8990
schedulingEvent,
91+
snapshot,
9092
suspenseEvent,
9193
userTimingMark,
9294
} = hoveredEvent;
@@ -110,6 +112,8 @@ export default function EventTooltip({
110112
tooltipRef={tooltipRef}
111113
/>
112114
);
115+
} else if (snapshot !== null) {
116+
return <TooltipSnapshot snapshot={snapshot} tooltipRef={tooltipRef} />;
113117
} else if (suspenseEvent !== null) {
114118
return (
115119
<TooltipSuspenseEvent
@@ -301,6 +305,23 @@ const TooltipSchedulingEvent = ({
301305
);
302306
};
303307

308+
const TooltipSnapshot = ({
309+
snapshot,
310+
tooltipRef,
311+
}: {
312+
snapshot: Snapshot,
313+
tooltipRef: Return<typeof useRef>,
314+
}) => {
315+
return (
316+
<div className={styles.Tooltip} ref={tooltipRef}>
317+
<img
318+
src={snapshot.imageSource}
319+
style={{width: snapshot.width / 2, height: snapshot.height / 2}}
320+
/>
321+
</div>
322+
);
323+
};
324+
304325
const TooltipSuspenseEvent = ({
305326
suspenseEvent,
306327
tooltipRef,

0 commit comments

Comments
 (0)