CockpitPerformanceReport constructor
CockpitPerformanceReport({
- String schemaVersion = 'cockpit.performance/v2',
- required DateTime startedAt,
- required DateTime finishedAt,
- required int durationUs,
- required int durationMs,
- required String platform,
- required String buildMode,
- required CockpitPerformanceMode mode,
- required CockpitPerformanceSummary summary,
- Iterable<
CockpitPerformanceFrame> frames = const <CockpitPerformanceFrame>[], - Iterable<
CockpitPerformanceEvent> events = const <CockpitPerformanceEvent>[], - int droppedFrames = 0,
- int droppedEvents = 0,
- int invalidFrames = 0,
- int invalidEvents = 0,
- CockpitPerformanceMemoryReport? memory,
- CockpitDevToolsProfile? devTools,
- String? timelineSource,
- String? stepId,
- CockpitPerformanceArchiveInfo? archive,
- 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.',
);
}
}
}