1
1
import React from "react" ;
2
2
3
+ import { GuiMessageBroker , GuiState , useGuiValue } from "@framework/GuiMessageBroker" ;
3
4
import { StatusSource } from "@framework/ModuleInstanceStatusController" ;
4
5
import {
5
6
ModuleInstanceStatusControllerInternal ,
@@ -43,6 +44,7 @@ export type DebugProfilerProps = {
43
44
children : React . ReactNode ;
44
45
statusController : ModuleInstanceStatusControllerInternal ;
45
46
source : StatusSource ;
47
+ guiMessageBroker : GuiMessageBroker ;
46
48
} ;
47
49
48
50
type RenderInfo = {
@@ -69,6 +71,7 @@ export const DebugProfiler: React.FC<DebugProfilerProps> = (props) => {
69
71
props . statusController ,
70
72
props . source === StatusSource . View ? "viewDebugMessage" : "settingsDebugMessage"
71
73
) ;
74
+ const debugInfoVisible = useGuiValue ( props . guiMessageBroker , GuiState . DevToolsVisible ) ;
72
75
73
76
const handleRender = React . useCallback (
74
77
(
@@ -103,55 +106,57 @@ export const DebugProfiler: React.FC<DebugProfilerProps> = (props) => {
103
106
< DebugProfilerWrapper id = { props . id } onRender = { handleRender } >
104
107
{ props . children }
105
108
</ DebugProfilerWrapper >
106
- < div className = "absolute bottom-1 w-full flex gap-2 flex-wrap" >
107
- { renderInfo && (
108
- < >
109
- { reportedRenderCount !== null && (
110
- < DebugProfilerRenderInfo title = "Reported component render count" >
111
- Component RC: { reportedRenderCount }
109
+ { debugInfoVisible && (
110
+ < div className = "absolute bottom-1 w-full flex gap-2 flex-wrap pointer-events-none" >
111
+ { renderInfo && (
112
+ < >
113
+ { reportedRenderCount !== null && (
114
+ < DebugProfilerRenderInfo title = "Reported component render count" >
115
+ Component RC: { reportedRenderCount }
116
+ </ DebugProfilerRenderInfo >
117
+ ) }
118
+ { customDebugMessage && (
119
+ < DebugProfilerRenderInfo title = "Custom debug message" >
120
+ Message: { customDebugMessage }
121
+ </ DebugProfilerRenderInfo >
122
+ ) }
123
+ < DebugProfilerRenderInfo title = "Tree render count" >
124
+ Tree RC: { renderInfo . renderCount }
112
125
</ DebugProfilerRenderInfo >
113
- ) }
114
- { customDebugMessage && (
115
- < DebugProfilerRenderInfo title = "Custom debug message" >
116
- Message: { customDebugMessage }
126
+ < DebugProfilerRenderInfo title = "Phase" > P: { renderInfo . phase } </ DebugProfilerRenderInfo >
127
+ < DebugProfilerRenderInfo
128
+ title = {
129
+ "Actual duration: The number of milliseconds spent rendering the module and its descendants for the current update. " +
130
+ "This indicates how well the subtree makes use of memoization (e.g. memo and useMemo). " +
131
+ "Ideally this value should decrease significantly after the initial mount as many of the descendants will only " +
132
+ "need to re-render if their specific props change."
133
+ }
134
+ >
135
+ AD: { renderInfo . actualDuration . toFixed ( 2 ) } ms
117
136
</ DebugProfilerRenderInfo >
118
- ) }
119
- < DebugProfilerRenderInfo title = "Tree render count" >
120
- Tree RC: { renderInfo . renderCount }
121
- </ DebugProfilerRenderInfo >
122
- < DebugProfilerRenderInfo title = "Phase" > P: { renderInfo . phase } </ DebugProfilerRenderInfo >
123
- < DebugProfilerRenderInfo
124
- title = {
125
- "Actual duration: The number of milliseconds spent rendering the module and its descendants for the current update. " +
126
- "This indicates how well the subtree makes use of memoization (e.g. memo and useMemo). " +
127
- "Ideally this value should decrease significantly after the initial mount as many of the descendants will only " +
128
- "need to re-render if their specific props change."
129
- }
130
- >
131
- AD: { renderInfo . actualDuration . toFixed ( 2 ) } ms
132
- </ DebugProfilerRenderInfo >
133
- < DebugProfilerRenderInfo
134
- title = {
135
- "Base Duration: The number of milliseconds estimating how much time it would take to re-render the entire module subtree without any optimizations. " +
136
- "It is calculated by summing up the most recent render durations of each component in the tree. " +
137
- "This value estimates a worst-case cost of rendering (e.g. the initial mount or a tree with no memoization). " +
138
- "Compare actualDuration against it to see if memoization is working."
139
- }
140
- >
141
- BD: { renderInfo . baseDuration . toFixed ( 2 ) } ms
142
- </ DebugProfilerRenderInfo >
143
- < DebugProfilerRenderInfo title = "The number of milliseconds of the fastest render duration." >
144
- MIN: { renderInfo . minTime . toFixed ( 2 ) } ms
145
- </ DebugProfilerRenderInfo >
146
- < DebugProfilerRenderInfo title = "The number of milliseconds of the slowest render duration." >
147
- MAX: { renderInfo . maxTime . toFixed ( 2 ) } ms
148
- </ DebugProfilerRenderInfo >
149
- < DebugProfilerRenderInfo title = "The number of milliseconds of the average render duration." >
150
- AVG: { renderInfo . avgTime . toFixed ( 2 ) } ms
151
- </ DebugProfilerRenderInfo >
152
- </ >
153
- ) }
154
- </ div >
137
+ < DebugProfilerRenderInfo
138
+ title = {
139
+ "Base Duration: The number of milliseconds estimating how much time it would take to re-render the entire module subtree without any optimizations. " +
140
+ "It is calculated by summing up the most recent render durations of each component in the tree. " +
141
+ "This value estimates a worst-case cost of rendering (e.g. the initial mount or a tree with no memoization). " +
142
+ "Compare actualDuration against it to see if memoization is working."
143
+ }
144
+ >
145
+ BD: { renderInfo . baseDuration . toFixed ( 2 ) } ms
146
+ </ DebugProfilerRenderInfo >
147
+ < DebugProfilerRenderInfo title = "The number of milliseconds of the fastest render duration." >
148
+ MIN: { renderInfo . minTime . toFixed ( 2 ) } ms
149
+ </ DebugProfilerRenderInfo >
150
+ < DebugProfilerRenderInfo title = "The number of milliseconds of the slowest render duration." >
151
+ MAX: { renderInfo . maxTime . toFixed ( 2 ) } ms
152
+ </ DebugProfilerRenderInfo >
153
+ < DebugProfilerRenderInfo title = "The number of milliseconds of the average render duration." >
154
+ AVG: { renderInfo . avgTime . toFixed ( 2 ) } ms
155
+ </ DebugProfilerRenderInfo >
156
+ </ >
157
+ ) }
158
+ </ div >
159
+ ) }
155
160
</ >
156
161
) ;
157
162
}
0 commit comments