@@ -233,6 +233,13 @@ class LoggingController extends DevToolsScreenController
233233
234234 late final LogDetailsController logDetailsController;
235235
236+ /// Tracks the previous cumulative GC times (in seconds) for each active isolate.
237+ ///
238+ /// This is used to compute the actual duration of the current GC event (by taking
239+ /// the delta between consecutive cumulative times), rather than displaying the
240+ /// total cumulative GC time.
241+ final _previousGcTimesByIsolate = < String , double > {};
242+
236243 List <LogData > data = < LogData > [];
237244
238245 final selectedLog = ValueNotifier <LogData ?>(null );
@@ -281,6 +288,7 @@ class LoggingController extends DevToolsScreenController
281288
282289 void clear () {
283290 _updateData ([]);
291+ _previousGcTimesByIsolate.clear ();
284292 serviceConnection.errorBadgeManager.clearErrorCount (LoggingScreen .id);
285293 }
286294
@@ -448,11 +456,24 @@ class LoggingController extends DevToolsScreenController
448456 final usedBytes = newSpace.used! + oldSpace.used! ;
449457 final capacityBytes = newSpace.capacity! + oldSpace.capacity! ;
450458
451- final time = ((newSpace.time! + oldSpace.time! ) * 1000 ).round ();
459+ final isolateId = e.isolate? .id;
460+ // Cumulative time, in seconds.
461+ final newCumulativeTime = newSpace.time! + oldSpace.time! ;
462+
463+ String durationText = '' ;
464+ if (isolateId != null ) {
465+ final previousGcTime = _previousGcTimesByIsolate[isolateId];
466+ _previousGcTimesByIsolate[isolateId] = newCumulativeTime;
467+ if (previousGcTime != null && newCumulativeTime >= previousGcTime) {
468+ // Multiply by 1000 to display in milliseconds.
469+ final durationMs = (newCumulativeTime - previousGcTime) * 1000 ;
470+ durationText = ' in ${durationMs .toStringAsFixed (1 )} ms' ;
471+ }
472+ }
452473
453474 final summary =
454475 '${isolateRef ['name' ]} • '
455- '${e .json !['reason' ]} collection in $ time ms • '
476+ '${e .json !['reason' ]} collection$ durationText • '
456477 '${printBytes (usedBytes , unit : ByteUnit .mb , includeUnit : true )} used of '
457478 '${printBytes (capacityBytes , unit : ByteUnit .mb , includeUnit : true )}' ;
458479
0 commit comments