processFrame method

  1. @override
void processFrame(
  1. FrameStats frame
)
override

Process one presented frame from FrameTiming.

Called once per frame on every tier (no VM needed), at display rate, for every enabled detector except the frame-timing producer itself. A batch of N timings delivered in one engine callback yields N calls in presentation order. Keep the work constant-time and allocation-free; accumulate here and emit from finalizeScan. A detector that throws is reported once and skipped until the next structural scan. Default is a no-op.

Implementation

@override
void processFrame(FrameStats frame) {
  if (!_isEnabled) return;
  if (_insideStartupWindow()) return;
  _windowFrameCount++;
  final atUs = frame.vsyncStartUs ?? frame.rasterFinishUs;
  final newest = _newestFrameAtUs;
  if (atUs != null && (newest == null || atUs > newest)) {
    _newestFrameAtUs = atUs;
  }
  final uiUs = frame.uiDuration.inMicroseconds;
  final rasterUs = frame.rasterDuration.inMicroseconds;
  if (uiUs <= 0 || rasterUs <= 0) return;
  // The frame missed its deadline on the raster thread, and raster, not
  // the UI thread, was the larger cost.
  if (rasterUs <= frame.frameBudgetUs) return;
  if (rasterUs <= maxFrameRasterFloorUs) return;
  if (rasterUs <= rasterMultiplierThreshold * uiUs) return;

  _dominantCount++;
  if (rasterUs > _worstFrameRasterUs) _worstFrameRasterUs = rasterUs;
  final i = _ringWrite;
  _ringRasterUs[i] = rasterUs;
  _ringUiUs[i] = uiUs;
  _ringHasAt[i] = atUs != null;
  _ringAtUs[i] = atUs ?? 0;
  final identityUs = frame.rasterFinishUs ?? frame.vsyncStartUs;
  _ringHasIdentity[i] = identityUs != null;
  _ringIdentityUs[i] = identityUs ?? 0;
  _ringFresh[i] = true;
  _ringWrite = (i + 1) % _ringCapacity;
  if (_ringCount < _ringCapacity) _ringCount++;
}