CockpitPerformanceReport constructor

CockpitPerformanceReport({
  1. String schemaVersion = 'cockpit.performance/v2',
  2. required DateTime startedAt,
  3. required DateTime finishedAt,
  4. required int durationUs,
  5. required int durationMs,
  6. required String platform,
  7. required String buildMode,
  8. required CockpitPerformanceMode mode,
  9. required CockpitPerformanceSummary summary,
  10. Iterable<CockpitPerformanceFrame> frames = const <CockpitPerformanceFrame>[],
  11. Iterable<CockpitPerformanceEvent> events = const <CockpitPerformanceEvent>[],
  12. int droppedFrames = 0,
  13. int droppedEvents = 0,
  14. int invalidFrames = 0,
  15. int invalidEvents = 0,
  16. CockpitPerformanceMemoryReport? memory,
  17. CockpitDevToolsProfile? devTools,
  18. String? timelineSource,
  19. String? stepId,
  20. CockpitPerformanceArchiveInfo? archive,
  21. Iterable<CockpitPerformancePluginStats> plugins = const <CockpitPerformancePluginStats>[],
})

Implementation

CockpitPerformanceReport({
  this.schemaVersion = 'cockpit.performance/v2',
  required this.startedAt,
  required this.finishedAt,
  required this.durationUs,
  required this.durationMs,
  required this.platform,
  required this.buildMode,
  required this.mode,
  required this.summary,
  Iterable<CockpitPerformanceFrame> frames =
      const <CockpitPerformanceFrame>[],
  Iterable<CockpitPerformanceEvent> events =
      const <CockpitPerformanceEvent>[],
  this.droppedFrames = 0,
  this.droppedEvents = 0,
  this.invalidFrames = 0,
  this.invalidEvents = 0,
  this.memory,
  this.devTools,
  this.timelineSource,
  this.stepId,
  this.archive,
  Iterable<CockpitPerformancePluginStats> plugins =
      const <CockpitPerformancePluginStats>[],
}) : frames = List<CockpitPerformanceFrame>.unmodifiable(frames),
     events = List<CockpitPerformanceEvent>.unmodifiable(events),
     plugins = List<CockpitPerformancePluginStats>.unmodifiable(plugins) {
  if (schemaVersion != 'cockpit.performance/v2') {
    throw const FormatException('Unsupported performance report schema.');
  }
  if (!startedAt.isUtc ||
      !finishedAt.isUtc ||
      finishedAt.isBefore(startedAt)) {
    throw const FormatException('Performance report timestamps are invalid.');
  }
  if (platform.trim().isEmpty ||
      !_performanceBuildModes.contains(buildMode) ||
      (timelineSource != null && timelineSource!.trim().isEmpty) ||
      (stepId != null && stepId!.trim().isEmpty)) {
    throw const FormatException('Performance report identity is invalid.');
  }
  if (durationUs < 0 ||
      durationMs < 0 ||
      droppedFrames < 0 ||
      droppedEvents < 0 ||
      invalidFrames < 0 ||
      invalidEvents < 0) {
    throw const FormatException('Performance report bounds are invalid.');
  }
  if (memory != null && memory!.samples.isEmpty) {
    throw const FormatException('Performance memory report is empty.');
  }
  final exactDurationUs = finishedAt.difference(startedAt).inMicroseconds;
  if (durationUs != exactDurationUs || durationMs != durationUs ~/ 1000) {
    throw const FormatException(
      'Performance report duration is inconsistent.',
    );
  }
  // A streamed integration-test result intentionally omits the retained
  // frame array from the in-memory payload; the JSONL archive is the source
  // of truth for those samples. Full/non-streamed reports still require an
  // exact summary-to-array match, while compact streamed reports validate
  // the archive's complete frame count against retained and dropped frames.
  final compactStream = archive != null && this.frames.isEmpty;
  if (!compactStream && summary.frameCount != this.frames.length) {
    throw const FormatException(
      'Performance summary sample count is inconsistent.',
    );
  }
  if (compactStream &&
      archive!.frames != summary.frameCount + droppedFrames) {
    throw const FormatException(
      'Performance stream frame count is inconsistent.',
    );
  }
  if (frames.length > 100000 || events.length > 200000) {
    throw const FormatException('Performance report is too large.');
  }
  if (this.plugins.length > 128) {
    throw const FormatException('Performance plugin count is bounded.');
  }
  if (frames.any((frame) => !frame.isValid) ||
      events.any((event) => !event.isValid) ||
      !summary.isValid) {
    throw const FormatException('Performance report contains invalid data.');
  }
  for (var i = 1; i < this.frames.length; i += 1) {
    if (this.frames[i].index <= this.frames[i - 1].index) {
      throw const FormatException(
        'Performance frame indexes are not ordered.',
      );
    }
  }
}