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: Add marks for component effects (mount and unmount) #22578

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
21 changes: 19 additions & 2 deletions packages/react-devtools-scheduling-profiler/src/EventTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,26 @@ const TooltipReactComponentMeasure = ({
}: {|
componentMeasure: ReactComponentMeasure,
|}) => {
const {componentName, duration, timestamp, warning} = componentMeasure;
const {componentName, duration, timestamp, type, warning} = componentMeasure;

const label = `${componentName} rendered`;
let label = componentName;
switch (type) {
case 'render':
label += ' rendered';
break;
case 'layout-effect-mount':
label += ' mounted layout effect';
break;
case 'layout-effect-unmount':
label += ' unmounted layout effect';
break;
case 'passive-effect-mount':
label += ' mounted passive effect';
break;
case 'passive-effect-unmount':
label += ' unmounted passive effect';
break;
}

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ export class ComponentMeasuresView extends View {
showHoverHighlight: boolean,
): boolean {
const {frame} = this;
const {componentName, duration, timestamp, warning} = componentMeasure;
const {
componentName,
duration,
timestamp,
type,
warning,
} = componentMeasure;

const xStart = timestampToPosition(timestamp, scaleFactor, frame);
const xStop = timestampToPosition(timestamp + duration, scaleFactor, frame);
Expand All @@ -96,16 +102,53 @@ export class ComponentMeasuresView extends View {
return false; // Too small to render at this zoom level
}

let textFillStyle = ((null: any): string);
let typeLabel = ((null: any): string);

const drawableRect = intersectionOfRects(componentMeasureRect, rect);
context.beginPath();
if (warning !== null) {
context.fillStyle = showHoverHighlight
? COLORS.WARNING_BACKGROUND_HOVER
: COLORS.WARNING_BACKGROUND;
} else {
context.fillStyle = showHoverHighlight
? COLORS.REACT_COMPONENT_MEASURE_HOVER
: COLORS.REACT_COMPONENT_MEASURE;
switch (type) {
case 'render':
context.fillStyle = showHoverHighlight
? COLORS.REACT_RENDER_HOVER
: COLORS.REACT_RENDER;
textFillStyle = COLORS.REACT_RENDER_TEXT;
typeLabel = 'rendered';
break;
case 'layout-effect-mount':
context.fillStyle = showHoverHighlight
? COLORS.REACT_LAYOUT_EFFECTS_HOVER
: COLORS.REACT_LAYOUT_EFFECTS;
textFillStyle = COLORS.REACT_LAYOUT_EFFECTS_TEXT;
typeLabel = 'mounted layout effect';
break;
case 'layout-effect-unmount':
context.fillStyle = showHoverHighlight
? COLORS.REACT_LAYOUT_EFFECTS_HOVER
: COLORS.REACT_LAYOUT_EFFECTS;
textFillStyle = COLORS.REACT_LAYOUT_EFFECTS_TEXT;
typeLabel = 'unmounted layout effect';
break;
case 'passive-effect-mount':
context.fillStyle = showHoverHighlight
? COLORS.REACT_PASSIVE_EFFECTS_HOVER
: COLORS.REACT_PASSIVE_EFFECTS;
textFillStyle = COLORS.REACT_PASSIVE_EFFECTS_TEXT;
typeLabel = 'mounted passive effect';
break;
case 'passive-effect-unmount':
context.fillStyle = showHoverHighlight
? COLORS.REACT_PASSIVE_EFFECTS_HOVER
: COLORS.REACT_PASSIVE_EFFECTS;
textFillStyle = COLORS.REACT_PASSIVE_EFFECTS_TEXT;
typeLabel = 'unmounted passive effect';
break;
}
}
context.fillRect(
drawableRect.origin.x,
Expand All @@ -114,9 +157,11 @@ export class ComponentMeasuresView extends View {
drawableRect.size.height,
);

const label = `${componentName} rendered - ${formatDuration(duration)}`;
const label = `${componentName} ${typeLabel} - ${formatDuration(duration)}`;

drawText(label, context, componentMeasureRect, drawableRect);
drawText(label, context, componentMeasureRect, drawableRect, {
fillStyle: textFillStyle,
});

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ export let COLORS = {
PRIORITY_LABEL: '',
USER_TIMING: '',
USER_TIMING_HOVER: '',
REACT_COMPONENT_MEASURE: '',
REACT_COMPONENT_MEASURE_HOVER: '',
REACT_IDLE: '',
REACT_IDLE_HOVER: '',
REACT_RENDER: '',
Expand Down Expand Up @@ -138,12 +136,6 @@ export function updateColorsToMatchTheme(element: Element): boolean {
USER_TIMING_HOVER: computedStyle.getPropertyValue(
'--color-scheduling-profiler-user-timing-hover',
),
REACT_COMPONENT_MEASURE: computedStyle.getPropertyValue(
'--color-scheduling-profiler-react-render',
),
REACT_COMPONENT_MEASURE_HOVER: computedStyle.getPropertyValue(
'--color-scheduling-profiler-react-render-hover',
),
REACT_IDLE: computedStyle.getPropertyValue(
'--color-scheduling-profiler-react-idle',
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ describe('preprocessData', () => {
Object {
"batchUID": 0,
"depth": 0,
"duration": 0.0019999999999999983,
"duration": 0.004,
Copy link
Contributor

Choose a reason for hiding this comment

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

why did these values here change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we're adding more marks now and our polyfill increments the timer a bit each time we make a mark:

  function createUserTimingEntry(data) {
    return {
      pid: ++pid,
      tid: ++tid,
      ts: ++startTime,
      ...data,
    };
  }

Copy link
Contributor

Choose a reason for hiding this comment

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

ah thanks!

"lanes": Array [
4,
],
Expand All @@ -847,11 +847,11 @@ describe('preprocessData', () => {
Object {
"batchUID": 1,
"depth": 0,
"duration": 0.010000000000000002,
"duration": 0.009999999999999998,
"lanes": Array [
4,
],
"timestamp": 0.019,
"timestamp": 0.021,
"type": "render-idle",
},
Object {
Expand All @@ -861,37 +861,37 @@ describe('preprocessData', () => {
"lanes": Array [
4,
],
"timestamp": 0.019,
"timestamp": 0.021,
"type": "render",
},
Object {
"batchUID": 1,
"depth": 0,
"duration": 0.006000000000000002,
"duration": 0.005999999999999998,
"lanes": Array [
4,
],
"timestamp": 0.023,
"timestamp": 0.025,
"type": "commit",
},
Object {
"batchUID": 1,
"depth": 1,
"duration": 0.0010000000000000009,
"duration": 0.0009999999999999974,
"lanes": Array [
4,
],
"timestamp": 0.027,
"timestamp": 0.029,
"type": "layout-effects",
},
Object {
"batchUID": 1,
"depth": 0,
"duration": 0.0010000000000000009,
"duration": 0.0030000000000000027,
"lanes": Array [
4,
],
"timestamp": 0.03,
"timestamp": 0.032,
"type": "passive-effects",
},
],
Expand All @@ -901,16 +901,32 @@ describe('preprocessData', () => {
"componentName": "App",
"duration": 0.001,
"timestamp": 0.006,
"type": "render",
"warning": null,
},
Object {
"componentName": "App",
"duration": 0.0019999999999999983,
"timestamp": 0.017,
"type": "passive-effect-mount",
"warning": null,
},
Object {
"componentName": "App",
"duration": 0.0010000000000000009,
"timestamp": 0.02,
"timestamp": 0.022,
"type": "render",
"warning": null,
},
Object {
"componentName": "App",
"duration": 0.0010000000000000009,
"timestamp": 0.033,
"type": "passive-effect-mount",
"warning": null,
},
],
"duration": 0.031,
"duration": 0.035,
"flamechart": Array [],
"laneToLabelMap": Map {
0 => "Sync",
Expand Down Expand Up @@ -994,7 +1010,7 @@ describe('preprocessData', () => {
Object {
"batchUID": 0,
"depth": 0,
"duration": 0.0019999999999999983,
"duration": 0.004,
"lanes": Array [
4,
],
Expand All @@ -1004,11 +1020,11 @@ describe('preprocessData', () => {
Object {
"batchUID": 1,
"depth": 0,
"duration": 0.010000000000000002,
"duration": 0.009999999999999998,
"lanes": Array [
4,
],
"timestamp": 0.019,
"timestamp": 0.021,
"type": "render-idle",
},
Object {
Expand All @@ -1018,37 +1034,37 @@ describe('preprocessData', () => {
"lanes": Array [
4,
],
"timestamp": 0.019,
"timestamp": 0.021,
"type": "render",
},
Object {
"batchUID": 1,
"depth": 0,
"duration": 0.006000000000000002,
"duration": 0.005999999999999998,
"lanes": Array [
4,
],
"timestamp": 0.023,
"timestamp": 0.025,
"type": "commit",
},
Object {
"batchUID": 1,
"depth": 1,
"duration": 0.0010000000000000009,
"duration": 0.0009999999999999974,
"lanes": Array [
4,
],
"timestamp": 0.027,
"timestamp": 0.029,
"type": "layout-effects",
},
Object {
"batchUID": 1,
"depth": 0,
"duration": 0.0010000000000000009,
"duration": 0.0030000000000000027,
"lanes": Array [
4,
],
"timestamp": 0.03,
"timestamp": 0.032,
"type": "passive-effects",
},
],
Expand Down Expand Up @@ -1102,7 +1118,7 @@ describe('preprocessData', () => {
"lanes": Array [
4,
],
"timestamp": 0.017,
"timestamp": 0.018,
"type": "schedule-state-update",
"warning": null,
},
Expand Down
Loading