Unverified Commit 2c716c4d authored by Ming Lyu (CareF)'s avatar Ming Lyu (CareF) Committed by GitHub

add vsync overhead to `FrameTimingSummarizer` (#63835)

parent 8f3805f5
......@@ -31,12 +31,18 @@ class FrameTimingSummarizer {
);
final List<Duration> frameRasterizerTimeSorted =
List<Duration>.from(frameRasterizerTime)..sort();
final List<Duration> vsyncOverhead = List<Duration>.unmodifiable(
data.map<Duration>((FrameTiming datum) => datum.vsyncOverhead),
);
final List<Duration> vsyncOverheadSorted =
List<Duration>.from(vsyncOverhead)..sort();
final Duration Function(Duration, Duration) add =
(Duration a, Duration b) => a + b;
return FrameTimingSummarizer._(
frameBuildTime: frameBuildTime,
frameRasterizerTime: frameRasterizerTime,
// This avarage calculation is microsecond precision, which is fine
vsyncOverhead: vsyncOverhead,
// This average calculation is microsecond precision, which is fine
// because typical values of these times are milliseconds.
averageFrameBuildTime: frameBuildTime.reduce(add) ~/ data.length,
p90FrameBuildTime: _findPercentile(frameBuildTimeSorted, 0.90),
......@@ -50,6 +56,10 @@ class FrameTimingSummarizer {
worstFrameRasterizerTime: frameRasterizerTimeSorted.last,
missedFrameRasterizerBudget:
_countExceed(frameRasterizerTimeSorted, kBuildBudget),
averageVsyncOverhead: vsyncOverhead.reduce(add) ~/ data.length,
p90VsyncOverhead: _findPercentile(vsyncOverheadSorted, 0.90),
p99VsyncOverhead: _findPercentile(vsyncOverheadSorted, 0.99),
worstVsyncOverhead: vsyncOverheadSorted.last,
);
}
......@@ -66,6 +76,11 @@ class FrameTimingSummarizer {
@required this.p99FrameRasterizerTime,
@required this.worstFrameRasterizerTime,
@required this.missedFrameRasterizerBudget,
@required this.vsyncOverhead,
@required this.averageVsyncOverhead,
@required this.p90VsyncOverhead,
@required this.p99VsyncOverhead,
@required this.worstVsyncOverhead,
});
/// List of frame build time in microseconds
......@@ -74,6 +89,10 @@ class FrameTimingSummarizer {
/// List of frame rasterizer time in microseconds
final List<Duration> frameRasterizerTime;
/// List of the time difference between vsync signal and frame building start
/// time
final List<Duration> vsyncOverhead;
/// The average value of [frameBuildTime] in milliseconds.
final Duration averageFrameBuildTime;
......@@ -104,6 +123,18 @@ class FrameTimingSummarizer {
/// Number of items in [frameRasterizerTime] that's greater than [kBuildBudget]
final int missedFrameRasterizerBudget;
/// The average value of [vsyncOverhead];
final Duration averageVsyncOverhead;
/// The 90-th percentile value of [vsyncOverhead] in milliseconds
final Duration p90VsyncOverhead;
/// The 99-th percentile value of [vsyncOverhead] in milliseconds
final Duration p99VsyncOverhead;
/// The largest value of [vsyncOverhead] in milliseconds.
final Duration worstVsyncOverhead;
/// Convert the summary result to a json object.
///
/// See [TimelineSummary.summaryJson] for detail.
......
......@@ -8,24 +8,30 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
test('Test FrameTimingSummarizer', () {
List<int> vsyncTimes = <int>[
for (int i = 0; i < 100; i += 1) 100 * (i + 1),
];
List<int> buildTimes = <int>[
for (int i = 1; i <= 100; i += 1) 1000 * i,
for (int i = 0; i < 100; i += 1) vsyncTimes[i] + 1000 * (i + 1),
];
buildTimes = buildTimes.reversed.toList();
List<int> rasterTimes = <int>[
for (int i = 1; i <= 100; i += 1) 1000 * i + 1000,
for (int i = 0; i < 100; i += 1) 1000 * (i + 1) + 1000,
];
// reversed to make sure sort is working.
buildTimes = buildTimes.reversed.toList();
rasterTimes = rasterTimes.reversed.toList();
vsyncTimes = vsyncTimes.reversed.toList();
final List<FrameTiming> inputData = <FrameTiming>[
for (int i = 0; i < 100; i += 1)
FrameTiming(
vsyncStart: 0,
buildStart: 0,
buildStart: vsyncTimes[i],
buildFinish: buildTimes[i],
rasterStart: 500,
rasterFinish: rasterTimes[i],
),
];
final FrameTimingSummarizer summary = FrameTimingSummarizer(inputData);
expect(summary.averageFrameBuildTime.inMicroseconds, 50500);
expect(summary.p90FrameBuildTime.inMicroseconds, 90000);
......@@ -39,5 +45,10 @@ void main() {
expect(summary.worstFrameRasterizerTime.inMicroseconds, 100500);
expect(summary.missedFrameRasterizerBudget, 85);
expect(summary.frameBuildTime.length, 100);
expect(summary.averageVsyncOverhead.inMicroseconds, 5050);
expect(summary.p90VsyncOverhead.inMicroseconds, 9000);
expect(summary.p99VsyncOverhead.inMicroseconds, 9900);
expect(summary.worstVsyncOverhead.inMicroseconds, 10000);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment