processTimelineData method
Process VM timeline data for PAINT scope time.
Accumulates PAINT scope durations and enriched dirty totals into
pending buffers. When at least 1 s has elapsed on the detector clock,
the window closes: its paint time divided by the measured elapsed
time (windows close at poll arrival and can run 1.0–1.5 s) is staged
with the enrichment atomically for _evaluate.
Implementation
@override
void processTimelineData(ParsedTimelineData data) {
if (!_isEnabled) return;
_paintTimeUs += data.totalFlushPaintUs;
// Accumulate enriched dirty counts from this batch
for (final event in data.phaseEvents) {
if (event.phase == TimelinePhase.paint && event.dirtyCount != null) {
_pendingEnrichedDirtyTotal += event.dirtyCount!;
}
}
final now = _clock();
final elapsedUs = now.difference(_windowStart).inMicroseconds;
if (elapsedUs >= Duration.microsecondsPerSecond) {
// Clamped: a mis-paired or nested scope could otherwise credit more
// phase time than the window holds.
final percent = (_paintTimeUs / elapsedUs * 100).clamp(0.0, 100.0);
_pendingVmWindowPercent = percent;
_pendingVmWindowUs = elapsedUs;
// Refresh capture-mode observables on every window close — before
// _evaluateVmData's threshold guard so sub-threshold legs still
// expose a measurement. The emission for this window stamps the
// same value as `observedPaintPercent`.
_lastObservedPaintPercent = percent;
if (percent > _peakObservedPaintPercent) {
_peakObservedPaintPercent = percent;
}
// Stage enrichment atomically with the window share
_stagedEnrichedDirtyTotal = _pendingEnrichedDirtyTotal > 0
? _pendingEnrichedDirtyTotal
: null;
_pendingEnrichedDirtyTotal = 0;
_paintTimeUs = 0;
_windowStart = now;
}
}