@@ -2000,6 +2000,7 @@ class _ConstraintRenderBox extends RenderBox
20002000 late List <_ConstrainedNode > _eventOrderList;
20012001
20022002 static const int maxTimeUsage = 20 ;
2003+ Queue <int > constraintCalculationTimeUsage = Queue ();
20032004 Queue <int > layoutTimeUsage = Queue ();
20042005 Queue <int > paintTimeUsage = Queue ();
20052006
@@ -2573,6 +2574,11 @@ class _ConstraintRenderBox extends RenderBox
25732574 }
25742575
25752576 if (_needsRecalculateConstraints) {
2577+ Stopwatch ? constraintCalculationWatch;
2578+ if (stopwatch != null ) {
2579+ constraintCalculationWatch = Stopwatch ()..start ();
2580+ }
2581+
25762582 assert (() {
25772583 if (_debugCheckConstraints) {
25782584 _debugCheckIds ();
@@ -2636,6 +2642,14 @@ class _ConstraintRenderBox extends RenderBox
26362642 _needsRecalculateConstraints = false ;
26372643 _needsReorderPaintingOrder = false ;
26382644 _needsReorderEventOrder = false ;
2645+
2646+ if (constraintCalculationWatch != null ) {
2647+ constraintCalculationTimeUsage
2648+ .add (constraintCalculationWatch.elapsedMicroseconds);
2649+ if (constraintCalculationTimeUsage.length > maxTimeUsage) {
2650+ constraintCalculationTimeUsage.removeFirst ();
2651+ }
2652+ }
26392653 }
26402654
26412655 _layoutByConstrainedNodeTrees (
@@ -3561,22 +3575,55 @@ class _ConstraintRenderBox extends RenderBox
35613575 PaintingContext context,
35623576 Offset offset,
35633577 ) {
3564- Iterator <int > layoutIterator = layoutTimeUsage.iterator;
3578+ Paint paint = Paint ()..color = Colors .white;
3579+ Iterator <int > constraintCalculateIterator =
3580+ constraintCalculationTimeUsage.iterator;
35653581 double heightOffset = 0 ;
3582+ while (constraintCalculateIterator.moveNext ()) {
3583+ int calculateTime = constraintCalculateIterator.current;
3584+ ui.ParagraphBuilder paragraphBuilder =
3585+ ui.ParagraphBuilder (ui.ParagraphStyle (
3586+ textAlign: TextAlign .left,
3587+ fontSize: 8 ,
3588+ ));
3589+ if (calculateTime > 1000 ) {
3590+ paragraphBuilder.pushStyle (ui.TextStyle (
3591+ color: Colors .red,
3592+ background: paint,
3593+ ));
3594+ } else {
3595+ paragraphBuilder.pushStyle (ui.TextStyle (
3596+ color: Colors .green,
3597+ background: paint,
3598+ ));
3599+ }
3600+ paragraphBuilder.addText ("calculate $calculateTime us" );
3601+ ui.Paragraph paragraph = paragraphBuilder.build ();
3602+ paragraph.layout (const ui.ParagraphConstraints (
3603+ width: 80 ,
3604+ ));
3605+ context.canvas.drawParagraph (paragraph, Offset (0 , heightOffset) + offset);
3606+ heightOffset += 10 ;
3607+ }
3608+
3609+ Iterator <int > layoutIterator = layoutTimeUsage.iterator;
3610+ heightOffset = 0 ;
35663611 while (layoutIterator.moveNext ()) {
35673612 int layoutTime = layoutIterator.current;
35683613 ui.ParagraphBuilder paragraphBuilder =
35693614 ui.ParagraphBuilder (ui.ParagraphStyle (
3570- textAlign: TextAlign .center ,
3615+ textAlign: TextAlign .left ,
35713616 fontSize: 8 ,
35723617 ));
35733618 if (layoutTime > 5000 ) {
35743619 paragraphBuilder.pushStyle (ui.TextStyle (
35753620 color: Colors .red,
3621+ background: paint,
35763622 ));
35773623 } else {
35783624 paragraphBuilder.pushStyle (ui.TextStyle (
35793625 color: Colors .green,
3626+ background: paint,
35803627 ));
35813628 }
35823629 paragraphBuilder.addText ("layout $layoutTime us" );
@@ -3585,7 +3632,7 @@ class _ConstraintRenderBox extends RenderBox
35853632 width: 80 ,
35863633 ));
35873634 context.canvas
3588- .drawParagraph (paragraph, Offset (20 , heightOffset) + offset);
3635+ .drawParagraph (paragraph, Offset (80 , heightOffset) + offset);
35893636 heightOffset += 10 ;
35903637 }
35913638
@@ -3601,10 +3648,12 @@ class _ConstraintRenderBox extends RenderBox
36013648 if (paintTime > 5000 ) {
36023649 paragraphBuilder.pushStyle (ui.TextStyle (
36033650 color: Colors .red,
3651+ background: paint,
36043652 ));
36053653 } else {
36063654 paragraphBuilder.pushStyle (ui.TextStyle (
36073655 color: Colors .green,
3656+ background: paint,
36083657 ));
36093658 }
36103659 paragraphBuilder.addText ("paint $paintTime us" );
@@ -3613,7 +3662,7 @@ class _ConstraintRenderBox extends RenderBox
36133662 width: 80 ,
36143663 ));
36153664 context.canvas
3616- .drawParagraph (paragraph, Offset (100 , heightOffset) + offset);
3665+ .drawParagraph (paragraph, Offset (160 , heightOffset) + offset);
36173666 heightOffset += 10 ;
36183667 }
36193668
@@ -3624,11 +3673,12 @@ class _ConstraintRenderBox extends RenderBox
36243673 ));
36253674 paragraphBuilder.pushStyle (ui.TextStyle (
36263675 color: Colors .green,
3676+ background: paint,
36273677 ));
36283678 paragraphBuilder.addText ('The bottom one is the latest' );
36293679 ui.Paragraph paragraph = paragraphBuilder.build ();
36303680 paragraph.layout (const ui.ParagraphConstraints (
3631- width: 180 ,
3681+ width: 240 ,
36323682 ));
36333683 context.canvas.drawParagraph (paragraph, Offset (0 , heightOffset) + offset);
36343684 }
0 commit comments