Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update constructor
  • Loading branch information
CareF committed Aug 6, 2020
commit ecca65eb7068a71576e4c083fc8f118c1338e25b
2 changes: 1 addition & 1 deletion lib/ui/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void _reportTimings(List<int> timings) {
assert(timings.length % FramePhase.values.length == 0);
final List<FrameTiming> frameTimings = <FrameTiming>[];
for (int i = 0; i < timings.length; i += FramePhase.values.length) {
frameTimings.add(FrameTiming(timings.sublist(i, i + FramePhase.values.length)));
frameTimings.add(FrameTiming._(timings.sublist(i, i + FramePhase.values.length)));
}
_invoke1(window.onReportTimings, window._onReportTimingsZone, frameTimings);
}
Expand Down
26 changes: 24 additions & 2 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,34 @@ enum FramePhase {
/// Therefore it's recommended to only monitor and analyze performance metrics
/// in profile and release modes.
class FrameTiming {
/// Construct [FrameTiming] with raw timestamps in microseconds.
///
/// This constructor is used for unit test only. Real [FrameTiming]s should
/// be retrieved from [Window.onReportTimings].
factory FrameTiming({
required int vsyncStart,
required int buildStart,
required int buildFinish,
required int rasterStart,
required int rasterFinish,
}) {
return FrameTiming._(<int>[
vsyncStart,
buildStart,
buildFinish,
rasterStart,
rasterFinish
]);
}

/// Construct [FrameTiming] with raw timestamps in microseconds.
///
/// List [timestamps] must have the same number of elements as
/// [FramePhase.values].
///
/// This constructor is usually only called by the Flutter engine, or a test.
/// To get the [FrameTiming] of your app, see [Window.onReportTimings].
FrameTiming(List<int> timestamps)
FrameTiming._(List<int> timestamps)
: assert(timestamps.length == FramePhase.values.length), _timestamps = timestamps;

/// Construct [FrameTiming] with given timestamp in micrseconds.
Expand All @@ -111,7 +131,9 @@ class FrameTiming {
required int rasterStart,
required int rasterFinish
}) {
return FrameTiming(<int>[
return FrameTiming._(<int>[
// This is for temporarily backward compatiblilty.
vsyncStart ?? buildStart,
buildStart,
buildFinish,
rasterStart,
Expand Down
38 changes: 33 additions & 5 deletions lib/web_ui/lib/src/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1040,16 +1040,35 @@ enum FramePhase {
/// Therefore it's recommended to only monitor and analyze performance metrics
/// in profile and release modes.
class FrameTiming {
/// Construct [FrameTiming] with raw timestamps in microseconds.
///
/// This constructor is used for unit test only. Real [FrameTiming]s should
/// be retrieved from [Window.onReportTimings].
factory FrameTiming({
required int vsyncStart,
required int buildStart,
required int buildFinish,
required int rasterStart,
required int rasterFinish,
}) {
return FrameTiming._(<int>[
vsyncStart,
buildStart,
buildFinish,
rasterStart,
rasterFinish
]);
}

/// Construct [FrameTiming] with raw timestamps in microseconds.
///
/// List [timestamps] must have the same number of elements as
/// [FramePhase.values].
///
/// This constructor is usually only called by the Flutter engine, or a test.
/// To get the [FrameTiming] of your app, see [Window.onReportTimings].
FrameTiming(List<int> timestamps)
: assert(timestamps.length == FramePhase.values.length),
_timestamps = timestamps;
FrameTiming._(List<int> timestamps)
: assert(timestamps.length == FramePhase.values.length), _timestamps = timestamps;

/// Construct [FrameTiming] with given timestamp in micrseconds.
///
Expand All @@ -1058,13 +1077,22 @@ class FrameTiming {
///
/// TODO(CareF): This is part of #20229. Remove back to default constructor
/// after #20229 lands and corresponding framwork PRs land.
FrameTiming.fromTimeStamps({
factory FrameTiming.fromTimeStamps({
int? vsyncStart,
required int buildStart,
required int buildFinish,
required int rasterStart,
required int rasterFinish
}) : _timestamps = <int>[buildStart, buildFinish, rasterStart, rasterFinish];
}) {
return FrameTiming._(<int>[
// This is for temporarily backward compatiblilty.
vsyncStart ?? buildStart,
buildStart,
buildFinish,
rasterStart,
rasterFinish
]);
}

/// This is a raw timestamp in microseconds from some epoch. The epoch in all
/// [FrameTiming] is the same, but it may not match [DateTime]'s epoch.
Expand Down
8 changes: 7 additions & 1 deletion testing/dart/window_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ void main() {
});

test('FrameTiming.toString has the correct format', () {
final FrameTiming timing = FrameTiming(<int>[500, 1000, 8000, 9000, 19500]);
final FrameTiming timing = FrameTiming(
vsyncStart: 500,
buildStart: 1000,
buildFinish: 8000,
rasterStart: 9000,
rasterFinish: 19500
);
expect(timing.toString(), 'FrameTiming(buildDuration: 7.0ms, rasterDuration: 10.5ms, vsyncOverhead: 0.5ms, totalSpan: 19.0ms)');
});

Expand Down