GeezerVison is showing github.com — Scheduling Profiler: Add marks for component effects (mount and unmou… · react/react@0e8a5af
File treeExpand file treeCollapse file tree Open diff view settings react-devtools-scheduling-profiler/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-scheduling-profiler/src/EventTooltip.js +19-2Lines changed: 19 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -140,9 +140,26 @@ const TooltipReactComponentMeasure = ({ | 140 | 140 | }: {| | 141 | 141 | componentMeasure: ReactComponentMeasure, | 142 | 142 | |}) => { | 143 | | - const {componentName, duration, timestamp, warning} = componentMeasure; | | 143 | + const {componentName, duration, timestamp, type, warning} = componentMeasure; | 144 | 144 |
| 145 | | - const label = `${componentName} rendered`; | | 145 | + let label = componentName; | | 146 | + switch (type) { | | 147 | + case 'render': | | 148 | + label += ' rendered'; | | 149 | + break; | | 150 | + case 'layout-effect-mount': | | 151 | + label += ' mounted layout effect'; | | 152 | + break; | | 153 | + case 'layout-effect-unmount': | | 154 | + label += ' unmounted layout effect'; | | 155 | + break; | | 156 | + case 'passive-effect-mount': | | 157 | + label += ' mounted passive effect'; | | 158 | + break; | | 159 | + case 'passive-effect-unmount': | | 160 | + label += ' unmounted passive effect'; | | 161 | + break; | | 162 | + } | 146 | 163 |
| 147 | 164 | return ( | 148 | 165 | <> | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-scheduling-profiler/src/content-views/ComponentMeasuresView.js +51-6Lines changed: 51 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -76,7 +76,13 @@ export class ComponentMeasuresView extends View { | 76 | 76 | showHoverHighlight: boolean, | 77 | 77 | ): boolean { | 78 | 78 | const {frame} = this; | 79 | | - const {componentName, duration, timestamp, warning} = componentMeasure; | | 79 | + const { | | 80 | + componentName, | | 81 | + duration, | | 82 | + timestamp, | | 83 | + type, | | 84 | + warning, | | 85 | + } = componentMeasure; | 80 | 86 |
| 81 | 87 | const xStart = timestampToPosition(timestamp, scaleFactor, frame); | 82 | 88 | const xStop = timestampToPosition(timestamp + duration, scaleFactor, frame); | @@ -96,16 +102,53 @@ export class ComponentMeasuresView extends View { | 96 | 102 | return false; // Too small to render at this zoom level | 97 | 103 | } | 98 | 104 |
| | 105 | + let textFillStyle = ((null: any): string); | | 106 | + let typeLabel = ((null: any): string); | | 107 | + | 99 | 108 | const drawableRect = intersectionOfRects(componentMeasureRect, rect); | 100 | 109 | context.beginPath(); | 101 | 110 | if (warning !== null) { | 102 | 111 | context.fillStyle = showHoverHighlight | 103 | 112 | ? COLORS.WARNING_BACKGROUND_HOVER | 104 | 113 | : COLORS.WARNING_BACKGROUND; | 105 | 114 | } else { | 106 | | - context.fillStyle = showHoverHighlight | 107 | | - ? COLORS.REACT_COMPONENT_MEASURE_HOVER | 108 | | - : COLORS.REACT_COMPONENT_MEASURE; | | 115 | + switch (type) { | | 116 | + case 'render': | | 117 | + context.fillStyle = showHoverHighlight | | 118 | + ? COLORS.REACT_RENDER_HOVER | | 119 | + : COLORS.REACT_RENDER; | | 120 | + textFillStyle = COLORS.REACT_RENDER_TEXT; | | 121 | + typeLabel = 'rendered'; | | 122 | + break; | | 123 | + case 'layout-effect-mount': | | 124 | + context.fillStyle = showHoverHighlight | | 125 | + ? COLORS.REACT_LAYOUT_EFFECTS_HOVER | | 126 | + : COLORS.REACT_LAYOUT_EFFECTS; | | 127 | + textFillStyle = COLORS.REACT_LAYOUT_EFFECTS_TEXT; | | 128 | + typeLabel = 'mounted layout effect'; | | 129 | + break; | | 130 | + case 'layout-effect-unmount': | | 131 | + context.fillStyle = showHoverHighlight | | 132 | + ? COLORS.REACT_LAYOUT_EFFECTS_HOVER | | 133 | + : COLORS.REACT_LAYOUT_EFFECTS; | | 134 | + textFillStyle = COLORS.REACT_LAYOUT_EFFECTS_TEXT; | | 135 | + typeLabel = 'unmounted layout effect'; | | 136 | + break; | | 137 | + case 'passive-effect-mount': | | 138 | + context.fillStyle = showHoverHighlight | | 139 | + ? COLORS.REACT_PASSIVE_EFFECTS_HOVER | | 140 | + : COLORS.REACT_PASSIVE_EFFECTS; | | 141 | + textFillStyle = COLORS.REACT_PASSIVE_EFFECTS_TEXT; | | 142 | + typeLabel = 'mounted passive effect'; | | 143 | + break; | | 144 | + case 'passive-effect-unmount': | | 145 | + context.fillStyle = showHoverHighlight | | 146 | + ? COLORS.REACT_PASSIVE_EFFECTS_HOVER | | 147 | + : COLORS.REACT_PASSIVE_EFFECTS; | | 148 | + textFillStyle = COLORS.REACT_PASSIVE_EFFECTS_TEXT; | | 149 | + typeLabel = 'unmounted passive effect'; | | 150 | + break; | | 151 | + } | 109 | 152 | } | 110 | 153 | context.fillRect( | 111 | 154 | drawableRect.origin.x, | @@ -114,9 +157,11 @@ export class ComponentMeasuresView extends View { | 114 | 157 | drawableRect.size.height, | 115 | 158 | ); | 116 | 159 |
| 117 | | - const label = `${componentName} rendered - ${formatDuration(duration)}`; | | 160 | + const label = `${componentName} ${typeLabel} - ${formatDuration(duration)}`; | 118 | 161 |
| 119 | | - drawText(label, context, componentMeasureRect, drawableRect); | | 162 | + drawText(label, context, componentMeasureRect, drawableRect, { | | 163 | + fillStyle: textFillStyle, | | 164 | + }); | 120 | 165 |
| 121 | 166 | return true; | 122 | 167 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-scheduling-profiler/src/content-views/constants.js -8Lines changed: 0 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,8 +59,6 @@ export let COLORS = { | 59 | 59 | PRIORITY_LABEL: '', | 60 | 60 | USER_TIMING: '', | 61 | 61 | USER_TIMING_HOVER: '', | 62 | | - REACT_COMPONENT_MEASURE: '', | 63 | | - REACT_COMPONENT_MEASURE_HOVER: '', | 64 | 62 | REACT_IDLE: '', | 65 | 63 | REACT_IDLE_HOVER: '', | 66 | 64 | REACT_RENDER: '', | @@ -150,12 +148,6 @@ export function updateColorsToMatchTheme(element: Element): boolean { | 150 | 148 | USER_TIMING_HOVER: computedStyle.getPropertyValue( | 151 | 149 | '--color-scheduling-profiler-user-timing-hover', | 152 | 150 | ), | 153 | | - REACT_COMPONENT_MEASURE: computedStyle.getPropertyValue( | 154 | | - '--color-scheduling-profiler-react-render', | 155 | | - ), | 156 | | - REACT_COMPONENT_MEASURE_HOVER: computedStyle.getPropertyValue( | 157 | | - '--color-scheduling-profiler-react-render-hover', | 158 | | - ), | 159 | 151 | REACT_IDLE: computedStyle.getPropertyValue( | 160 | 152 | '--color-scheduling-profiler-react-idle', | 161 | 153 | ), | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-scheduling-profiler/src/import-worker/__tests__/preprocessData-test.internal.js +39-23Lines changed: 39 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -840,7 +840,7 @@ describe('preprocessData', () => { | 840 | 840 | Object { | 841 | 841 | "batchUID": 0, | 842 | 842 | "depth": 0, | 843 | | - "duration": 0.0019999999999999983, | | 843 | + "duration": 0.004, | 844 | 844 | "lanes": Array [ | 845 | 845 | 4, | 846 | 846 | ], | @@ -852,11 +852,11 @@ describe('preprocessData', () => { | 852 | 852 | Object { | 853 | 853 | "batchUID": 1, | 854 | 854 | "depth": 0, | 855 | | - "duration": 0.010000000000000002, | | 855 | + "duration": 0.009999999999999998, | 856 | 856 | "lanes": Array [ | 857 | 857 | 4, | 858 | 858 | ], | 859 | | - "timestamp": 0.019, | | 859 | + "timestamp": 0.021, | 860 | 860 | "type": "render-idle", | 861 | 861 | }, | 862 | 862 | Object { | @@ -866,37 +866,37 @@ describe('preprocessData', () => { | 866 | 866 | "lanes": Array [ | 867 | 867 | 4, | 868 | 868 | ], | 869 | | - "timestamp": 0.019, | | 869 | + "timestamp": 0.021, | 870 | 870 | "type": "render", | 871 | 871 | }, | 872 | 872 | Object { | 873 | 873 | "batchUID": 1, | 874 | 874 | "depth": 0, | 875 | | - "duration": 0.006000000000000002, | | 875 | + "duration": 0.005999999999999998, | 876 | 876 | "lanes": Array [ | 877 | 877 | 4, | 878 | 878 | ], | 879 | | - "timestamp": 0.023, | | 879 | + "timestamp": 0.025, | 880 | 880 | "type": "commit", | 881 | 881 | }, | 882 | 882 | Object { | 883 | 883 | "batchUID": 1, | 884 | 884 | "depth": 1, | 885 | | - "duration": 0.0010000000000000009, | | 885 | + "duration": 0.0009999999999999974, | 886 | 886 | "lanes": Array [ | 887 | 887 | 4, | 888 | 888 | ], | 889 | | - "timestamp": 0.027, | | 889 | + "timestamp": 0.029, | 890 | 890 | "type": "layout-effects", | 891 | 891 | }, | 892 | 892 | Object { | 893 | 893 | "batchUID": 1, | 894 | 894 | "depth": 0, | 895 | | - "duration": 0.0010000000000000009, | | 895 | + "duration": 0.0030000000000000027, | 896 | 896 | "lanes": Array [ | 897 | 897 | 4, | 898 | 898 | ], | 899 | | - "timestamp": 0.03, | | 899 | + "timestamp": 0.032, | 900 | 900 | "type": "passive-effects", | 901 | 901 | }, | 902 | 902 | ], | @@ -906,16 +906,32 @@ describe('preprocessData', () => { | 906 | 906 | "componentName": "App", | 907 | 907 | "duration": 0.001, | 908 | 908 | "timestamp": 0.006, | | 909 | + "type": "render", | | 910 | + "warning": null, | | 911 | + }, | | 912 | + Object { | | 913 | + "componentName": "App", | | 914 | + "duration": 0.0019999999999999983, | | 915 | + "timestamp": 0.017, | | 916 | + "type": "passive-effect-mount", | 909 | 917 | "warning": null, | 910 | 918 | }, | 911 | 919 | Object { | 912 | 920 | "componentName": "App", | 913 | 921 | "duration": 0.0010000000000000009, | 914 | | - "timestamp": 0.02, | | 922 | + "timestamp": 0.022, | | 923 | + "type": "render", | | 924 | + "warning": null, | | 925 | + }, | | 926 | + Object { | | 927 | + "componentName": "App", | | 928 | + "duration": 0.0010000000000000009, | | 929 | + "timestamp": 0.033, | | 930 | + "type": "passive-effect-mount", | 915 | 931 | "warning": null, | 916 | 932 | }, | 917 | 933 | ], | 918 | | - "duration": 0.031, | | 934 | + "duration": 0.035, | 919 | 935 | "flamechart": Array [], | 920 | 936 | "internalModuleSourceToRanges": Map {}, | 921 | 937 | "laneToLabelMap": Map { | @@ -1000,7 +1016,7 @@ describe('preprocessData', () => { | 1000 | 1016 | Object { | 1001 | 1017 | "batchUID": 0, | 1002 | 1018 | "depth": 0, | 1003 | | - "duration": 0.0019999999999999983, | | 1019 | + "duration": 0.004, | 1004 | 1020 | "lanes": Array [ | 1005 | 1021 | 4, | 1006 | 1022 | ], | @@ -1010,11 +1026,11 @@ describe('preprocessData', () => { | 1010 | 1026 | Object { | 1011 | 1027 | "batchUID": 1, | 1012 | 1028 | "depth": 0, | 1013 | | - "duration": 0.010000000000000002, | | 1029 | + "duration": 0.009999999999999998, | 1014 | 1030 | "lanes": Array [ | 1015 | 1031 | 4, | 1016 | 1032 | ], | 1017 | | - "timestamp": 0.019, | | 1033 | + "timestamp": 0.021, | 1018 | 1034 | "type": "render-idle", | 1019 | 1035 | }, | 1020 | 1036 | Object { | @@ -1024,37 +1040,37 @@ describe('preprocessData', () => { | 1024 | 1040 | "lanes": Array [ | 1025 | 1041 | 4, | 1026 | 1042 | ], | 1027 | | - "timestamp": 0.019, | | 1043 | + "timestamp": 0.021, | 1028 | 1044 | "type": "render", | 1029 | 1045 | }, | 1030 | 1046 | Object { | 1031 | 1047 | "batchUID": 1, | 1032 | 1048 | "depth": 0, | 1033 | | - "duration": 0.006000000000000002, | | 1049 | + "duration": 0.005999999999999998, | 1034 | 1050 | "lanes": Array [ | 1035 | 1051 | 4, | 1036 | 1052 | ], | 1037 | | - "timestamp": 0.023, | | 1053 | + "timestamp": 0.025, | 1038 | 1054 | "type": "commit", | 1039 | 1055 | }, | 1040 | 1056 | Object { | 1041 | 1057 | "batchUID": 1, | 1042 | 1058 | "depth": 1, | 1043 | | - "duration": 0.0010000000000000009, | | 1059 | + "duration": 0.0009999999999999974, | 1044 | 1060 | "lanes": Array [ | 1045 | 1061 | 4, | 1046 | 1062 | ], | 1047 | | - "timestamp": 0.027, | | 1063 | + "timestamp": 0.029, | 1048 | 1064 | "type": "layout-effects", | 1049 | 1065 | }, | 1050 | 1066 | Object { | 1051 | 1067 | "batchUID": 1, | 1052 | 1068 | "depth": 0, | 1053 | | - "duration": 0.0010000000000000009, | | 1069 | + "duration": 0.0030000000000000027, | 1054 | 1070 | "lanes": Array [ | 1055 | 1071 | 4, | 1056 | 1072 | ], | 1057 | | - "timestamp": 0.03, | | 1073 | + "timestamp": 0.032, | 1058 | 1074 | "type": "passive-effects", | 1059 | 1075 | }, | 1060 | 1076 | ], | @@ -1108,7 +1124,7 @@ describe('preprocessData', () => { | 1108 | 1124 | "lanes": Array [ | 1109 | 1125 | 4, | 1110 | 1126 | ], | 1111 | | - "timestamp": 0.017, | | 1127 | + "timestamp": 0.018, | 1112 | 1128 | "type": "schedule-state-update", | 1113 | 1129 | "warning": null, | 1114 | 1130 | }, | |
|