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

Scheduling Profiler: Inline snapshots #22091

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
user-select: none;
pointer-events: none;
background-color: var(--color-tooltip-background);
border: 1px solid var(border);
box-shadow: 1px 1px 2px var(--color-shadow);
color: var(--color-tooltip-text);
font-size: 11px;
Expand Down Expand Up @@ -72,4 +71,8 @@
.InfoText,
.WarningText {
color: var(--color-warning-text-color);
}

.Image {
border: 1px solid var(--color-border);
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ const TooltipSnapshot = ({
return (
<div className={styles.Tooltip} ref={tooltipRef}>
<img
className={styles.Image}
src={snapshot.imageSource}
style={{width: snapshot.width / 2, height: snapshot.height / 2}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import type {Snapshot, ReactProfilerData} from '../types';
import type {
Interaction,
MouseMoveInteraction,
Point,
Rect,
Size,
Surface,
Expand Down Expand Up @@ -67,6 +67,10 @@ export class SnapshotsView extends View {
// draw them at fixed intervals and just show the nearest one.
while (x < visibleArea.origin.x + visibleArea.size.width) {
const snapshot = this._findClosestSnapshot(x);
if (snapshot === null) {
// This shold never happen.
break;
}

const scaledHeight = SNAPSHOT_HEIGHT;
const scaledWidth = (snapshot.width * SNAPSHOT_HEIGHT) / snapshot.height;
Expand Down Expand Up @@ -97,7 +101,11 @@ export class SnapshotsView extends View {
handleInteraction(interaction: Interaction, viewRefs: ViewRefs) {
switch (interaction.type) {
case 'mousemove':
this._handleMouseMove(interaction, viewRefs);
case 'wheel-control':
case 'wheel-meta':
case 'wheel-plain':
case 'wheel-shift':
this._updateHover(interaction.payload.location, viewRefs);
break;
}
}
Expand Down Expand Up @@ -125,6 +133,14 @@ export class SnapshotsView extends View {
context.clip();
}

context.fillStyle = COLORS.REACT_RESIZE_BAR_BORDER;
context.fillRect(
imageRect.origin.x,
imageRect.origin.y,
imageRect.size.width,
imageRect.size.height,
);

// $FlowFixMe Flow doesn't know about the 9 argument variant of drawImage()
context.drawImage(
snapshot.image,
Expand All @@ -138,20 +154,20 @@ export class SnapshotsView extends View {
snapshot.height,

// Canvas coordinates
imageRect.origin.x,
imageRect.origin.y,
imageRect.origin.x + BORDER_SIZE,
imageRect.origin.y + BORDER_SIZE,

// Scaled image size
imageRect.size.width,
imageRect.size.height,
imageRect.size.width - BORDER_SIZE * 2,
imageRect.size.height - BORDER_SIZE * 2,
);

if (shouldClip) {
context.restore();
}
}

_findClosestSnapshot(x: number): Snapshot {
_findClosestSnapshot(x: number): Snapshot | null {
const frame = this.frame;
const scaleFactor = positioningScaleFactor(
this._intrinsicSize.width,
Expand All @@ -178,28 +194,25 @@ export class SnapshotsView extends View {
}
}

return snapshots[stopIndex];
return snapshots[stopIndex] || null;
}

/**
* @private
*/
_handleMouseMove(interaction: MouseMoveInteraction, viewRefs: ViewRefs) {
_updateHover(location: Point, viewRefs: ViewRefs) {
const {onHover, visibleArea} = this;
if (!onHover) {
return;
}

const {location} = interaction.payload;
if (!rectContainsPoint(location, visibleArea)) {
onHover(null);
return;
}

const snapshot = this._findClosestSnapshot(location.x);
if (snapshot) {
this.currentCursor = 'context-menu';
viewRefs.hoveredView = this;
if (snapshot !== null) {
onHover(snapshot);
} else {
onHover(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const REACT_MEASURE_HEIGHT = 14;
export const BORDER_SIZE = 1;
export const FLAMECHART_FRAME_HEIGHT = 14;
export const TEXT_PADDING = 3;
export const SNAPSHOT_HEIGHT = 50;
export const SNAPSHOT_HEIGHT = 35;

export const INTERVAL_TIMES = [
1,
Expand Down