@@ -77,6 +77,8 @@ export class PerformanceMonitorImpl extends UI.Widget.HBox implements
7777 private height ! : number ;
7878 private model ?: SDK . PerformanceMetricsModel . PerformanceMetricsModel | null ;
7979 private pollTimer ?: number ;
80+ private metrics ?: Map < string , number > ;
81+ private suspended = false ;
8082
8183 constructor ( pollIntervalMs = 500 ) {
8284 super ( {
@@ -122,19 +124,19 @@ export class PerformanceMonitorImpl extends UI.Widget.HBox implements
122124 return ;
123125 }
124126 this . chartInfos = this . createChartInfos ( ) ;
125- this . controlPane . chartsInfo = this . chartInfos ;
126127 const themeSupport = ThemeSupport . ThemeSupport . instance ( ) ;
127128 themeSupport . addEventListener ( ThemeSupport . ThemeChangeEvent . eventName , ( ) => {
128129 // instantiateMetricData sets the colors for the metrics, which we need
129130 // to re-evaluate when the theme changes before re-drawing the canvas.
130131 this . chartInfos = this . createChartInfos ( ) ;
131- this . controlPane . chartsInfo = this . chartInfos ;
132+ this . requestUpdate ( ) ;
132133 this . draw ( ) ;
133134 } ) ;
134135 SDK . TargetManager . TargetManager . instance ( ) . addEventListener (
135136 SDK . TargetManager . Events . SUSPEND_STATE_CHANGED , this . suspendStateChanged , this ) ;
136137 void this . model . enable ( ) ;
137138 this . suspendStateChanged ( ) ;
139+ this . requestUpdate ( ) ;
138140 }
139141
140142 override willHide ( ) : void {
@@ -147,6 +149,17 @@ export class PerformanceMonitorImpl extends UI.Widget.HBox implements
147149 void this . model . disable ( ) ;
148150 }
149151
152+ override performUpdate ( ) : void {
153+ this . controlPane . chartsInfo = this . chartInfos ;
154+ this . controlPane . metrics = this . metrics ;
155+ this . width = this . canvas . offsetWidth ;
156+ this . canvas . width = Math . round ( this . width * window . devicePixelRatio ) ;
157+ this . canvas . height = this . height ;
158+ this . canvas . style . height = `${ this . height / window . devicePixelRatio } px` ;
159+ this . contentElement . classList . toggle ( 'suspended' , this . suspended ) ;
160+ this . draw ( ) ;
161+ }
162+
150163 modelAdded ( model : SDK . PerformanceMetricsModel . PerformanceMetricsModel ) : void {
151164 if ( model . target ( ) !== SDK . TargetManager . TargetManager . instance ( ) . primaryPageTarget ( ) ) {
152165 return ;
@@ -174,7 +187,8 @@ export class PerformanceMonitorImpl extends UI.Widget.HBox implements
174187 } else {
175188 this . startPolling ( ) ;
176189 }
177- this . contentElement . classList . toggle ( 'suspended' , suspended ) ;
190+ this . suspended = suspended ;
191+ this . requestUpdate ( ) ;
178192 }
179193
180194 private startPolling ( ) : void {
@@ -210,10 +224,14 @@ export class PerformanceMonitorImpl extends UI.Widget.HBox implements
210224 {
211225 this . metricsBuffer . splice ( 0 , this . metricsBuffer . length - maxCount ) ;
212226 }
213- this . controlPane . updateMetrics ( metrics ) ;
227+ this . metrics = metrics ;
228+ this . requestUpdate ( ) ;
214229 }
215230
216231 private draw ( ) : void {
232+ if ( ! this . canvas ) {
233+ return ;
234+ }
217235 const ctx = this . canvas . getContext ( '2d' ) as CanvasRenderingContext2D ;
218236 ctx . save ( ) ;
219237 ctx . scale ( window . devicePixelRatio , window . devicePixelRatio ) ;
@@ -428,7 +446,6 @@ export class PerformanceMonitorImpl extends UI.Widget.HBox implements
428446 override onResize ( ) : void {
429447 super . onResize ( ) ;
430448 this . width = this . canvas . offsetWidth ;
431- this . canvas . width = Math . round ( this . width * window . devicePixelRatio ) ;
432449 this . recalcChartHeight ( ) ;
433450 }
434451
@@ -440,8 +457,7 @@ export class PerformanceMonitorImpl extends UI.Widget.HBox implements
440457 }
441458 }
442459 this . height = Math . ceil ( height * window . devicePixelRatio ) ;
443- this . canvas . height = this . height ;
444- this . canvas . style . height = `${ this . height / window . devicePixelRatio } px` ;
460+ this . requestUpdate ( ) ;
445461 }
446462
447463 private createChartInfos ( ) : ChartInfo [ ] {
@@ -648,7 +664,10 @@ export class ControlPane extends UI.Widget.VBox {
648664 }
649665 }
650666
651- updateMetrics ( metrics : Map < string , number > ) : void {
667+ set metrics ( metrics : Map < string , number > | undefined ) {
668+ if ( ! metrics ) {
669+ return ;
670+ }
652671 for ( const [ name , value ] of metrics . entries ( ) ) {
653672 this . #metricValues. set ( name , value ) ;
654673 }
0 commit comments