6#include "flutter/flow/frame_timings.h"
7#include "flutter/flow/testing/layer_test.h"
8#include "flutter/flow/testing/mock_layer.h"
9#include "flutter/flow/testing/mock_raster_cache.h"
11#include "flutter/fml/time/time_delta.h"
12#include "flutter/fml/time/time_point.h"
14#include "gtest/gtest.h"
18using testing::MockRasterCache;
20TEST(FrameTimingsRecorderTest, RecordVsync) {
21 auto recorder = std::make_unique<FrameTimingsRecorder>();
24 recorder->RecordVsync(st, en);
26 ASSERT_EQ(st, recorder->GetVsyncStartTime());
27 ASSERT_EQ(en, recorder->GetVsyncTargetTime());
30TEST(FrameTimingsRecorderTest, RecordBuildTimes) {
31 auto recorder = std::make_unique<FrameTimingsRecorder>();
35 recorder->RecordVsync(st, en);
39 recorder->RecordBuildStart(build_start);
40 recorder->RecordBuildEnd(build_end);
42 ASSERT_EQ(build_start, recorder->GetBuildStartTime());
43 ASSERT_EQ(build_end, recorder->GetBuildEndTime());
46TEST(FrameTimingsRecorderTest, RecordRasterTimes) {
47 auto recorder = std::make_unique<FrameTimingsRecorder>();
51 recorder->RecordVsync(st, en);
55 recorder->RecordBuildStart(build_start);
56 recorder->RecordBuildEnd(build_end);
58 using namespace std::chrono_literals;
61 recorder->RecordRasterStart(raster_start);
63 std::this_thread::sleep_for(1ms);
64 const auto timing = recorder->RecordRasterEnd();
65 std::this_thread::sleep_for(1ms);
68 ASSERT_EQ(raster_start, recorder->GetRasterStartTime());
69 ASSERT_GT(recorder->GetRasterEndWallTime(), before_raster_end_wall_time);
70 ASSERT_LT(recorder->GetRasterEndWallTime(), after_raster_end_wall_time);
71 ASSERT_EQ(recorder->GetFrameNumber(), timing.GetFrameNumber());
72 ASSERT_EQ(recorder->GetLayerCacheCount(), 0u);
73 ASSERT_EQ(recorder->GetLayerCacheBytes(), 0u);
74 ASSERT_EQ(recorder->GetPictureCacheCount(), 0u);
75 ASSERT_EQ(recorder->GetPictureCacheBytes(), 0u);
78TEST(FrameTimingsRecorderTest, RecordRasterTimesWithCache) {
79 auto recorder = std::make_unique<FrameTimingsRecorder>();
83 recorder->RecordVsync(st, en);
87 recorder->RecordBuildStart(build_start);
88 recorder->RecordBuildEnd(build_end);
90 using namespace std::chrono_literals;
96 recorder->RecordRasterStart(raster_start);
98 cache.AddMockLayer(100, 100);
99 size_t layer_bytes =
cache.EstimateLayerCacheByteSize();
100 EXPECT_GT(layer_bytes, 0u);
101 cache.AddMockPicture(100, 100);
102 size_t picture_bytes =
cache.EstimatePictureCacheByteSize();
103 EXPECT_GT(picture_bytes, 0u);
104 cache.EvictUnusedCacheEntries();
109 std::this_thread::sleep_for(1ms);
110 const auto timing = recorder->RecordRasterEnd(&
cache);
111 std::this_thread::sleep_for(1ms);
114 ASSERT_EQ(raster_start, recorder->GetRasterStartTime());
115 ASSERT_GT(recorder->GetRasterEndWallTime(), before_raster_end_wall_time);
116 ASSERT_LT(recorder->GetRasterEndWallTime(), after_raster_end_wall_time);
117 ASSERT_EQ(recorder->GetFrameNumber(), timing.GetFrameNumber());
118 ASSERT_EQ(recorder->GetLayerCacheCount(), 1u);
119 ASSERT_EQ(recorder->GetLayerCacheBytes(), layer_bytes);
120 ASSERT_EQ(recorder->GetPictureCacheCount(), 1u);
121 ASSERT_EQ(recorder->GetPictureCacheBytes(), picture_bytes);
125#if !defined(OS_FUCHSIA) && !defined(FML_OS_WIN) && \
126 (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
128TEST(FrameTimingsRecorderTest, ThrowWhenRecordBuildBeforeVsync) {
129 auto recorder = std::make_unique<FrameTimingsRecorder>();
132 fml::Status status = recorder->RecordBuildStartImpl(build_start);
133 EXPECT_FALSE(status.
ok());
134 EXPECT_EQ(status.
message(),
"Check failed: state_ == State::kVsync.");
137TEST(FrameTimingsRecorderTest, ThrowWhenRecordRasterBeforeBuildEnd) {
138 auto recorder = std::make_unique<FrameTimingsRecorder>();
142 recorder->RecordVsync(st, en);
145 fml::Status status = recorder->RecordRasterStartImpl(raster_start);
146 EXPECT_FALSE(status.
ok());
147 EXPECT_EQ(status.
message(),
"Check failed: state_ == State::kBuildEnd.");
152TEST(FrameTimingsRecorderTest, RecordersHaveUniqueFrameNumbers) {
153 auto recorder1 = std::make_unique<FrameTimingsRecorder>();
154 auto recorder2 = std::make_unique<FrameTimingsRecorder>();
156 ASSERT_TRUE(recorder2->GetFrameNumber() > recorder1->GetFrameNumber());
159TEST(FrameTimingsRecorderTest, ClonedHasSameFrameNumber) {
160 auto recorder = std::make_unique<FrameTimingsRecorder>();
164 ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
167TEST(FrameTimingsRecorderTest, ClonedHasSameVsyncStartAndTarget) {
168 auto recorder = std::make_unique<FrameTimingsRecorder>();
174 ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
175 ASSERT_EQ(recorder->GetVsyncStartTime(), cloned->GetVsyncStartTime());
176 ASSERT_EQ(recorder->GetVsyncTargetTime(), cloned->GetVsyncTargetTime());
179TEST(FrameTimingsRecorderTest, ClonedHasSameBuildStart) {
180 auto recorder = std::make_unique<FrameTimingsRecorder>();
187 ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
188 ASSERT_EQ(recorder->GetVsyncStartTime(), cloned->GetVsyncStartTime());
189 ASSERT_EQ(recorder->GetVsyncTargetTime(), cloned->GetVsyncTargetTime());
190 ASSERT_EQ(recorder->GetBuildStartTime(), cloned->GetBuildStartTime());
193TEST(FrameTimingsRecorderTest, ClonedHasSameBuildEnd) {
194 auto recorder = std::make_unique<FrameTimingsRecorder>();
202 ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
203 ASSERT_EQ(recorder->GetVsyncStartTime(), cloned->GetVsyncStartTime());
204 ASSERT_EQ(recorder->GetVsyncTargetTime(), cloned->GetVsyncTargetTime());
205 ASSERT_EQ(recorder->GetBuildStartTime(), cloned->GetBuildStartTime());
206 ASSERT_EQ(recorder->GetBuildEndTime(), cloned->GetBuildEndTime());
209TEST(FrameTimingsRecorderTest, ClonedHasSameRasterStart) {
210 auto recorder = std::make_unique<FrameTimingsRecorder>();
219 ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
220 ASSERT_EQ(recorder->GetVsyncStartTime(), cloned->GetVsyncStartTime());
221 ASSERT_EQ(recorder->GetVsyncTargetTime(), cloned->GetVsyncTargetTime());
222 ASSERT_EQ(recorder->GetBuildStartTime(), cloned->GetBuildStartTime());
223 ASSERT_EQ(recorder->GetBuildEndTime(), cloned->GetBuildEndTime());
224 ASSERT_EQ(recorder->GetRasterStartTime(), cloned->GetRasterStartTime());
227TEST(FrameTimingsRecorderTest, ClonedHasSameRasterEnd) {
228 auto recorder = std::make_unique<FrameTimingsRecorder>();
235 recorder->RecordRasterEnd();
238 ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
239 ASSERT_EQ(recorder->GetVsyncStartTime(), cloned->GetVsyncStartTime());
240 ASSERT_EQ(recorder->GetVsyncTargetTime(), cloned->GetVsyncTargetTime());
241 ASSERT_EQ(recorder->GetBuildStartTime(), cloned->GetBuildStartTime());
242 ASSERT_EQ(recorder->GetBuildEndTime(), cloned->GetBuildEndTime());
243 ASSERT_EQ(recorder->GetRasterStartTime(), cloned->GetRasterStartTime());
244 ASSERT_EQ(recorder->GetRasterEndTime(), cloned->GetRasterEndTime());
245 ASSERT_EQ(recorder->GetRasterEndWallTime(), cloned->GetRasterEndWallTime());
246 ASSERT_EQ(recorder->GetLayerCacheCount(), cloned->GetLayerCacheCount());
247 ASSERT_EQ(recorder->GetLayerCacheBytes(), cloned->GetLayerCacheBytes());
248 ASSERT_EQ(recorder->GetPictureCacheCount(), cloned->GetPictureCacheCount());
249 ASSERT_EQ(recorder->GetPictureCacheBytes(), cloned->GetPictureCacheBytes());
252TEST(FrameTimingsRecorderTest, ClonedHasSameRasterEndWithCache) {
253 auto recorder = std::make_unique<FrameTimingsRecorder>();
263 cache.AddMockLayer(100, 100);
264 size_t layer_bytes =
cache.EstimateLayerCacheByteSize();
265 EXPECT_GT(layer_bytes, 0u);
266 cache.AddMockPicture(100, 100);
267 size_t picture_bytes =
cache.EstimatePictureCacheByteSize();
268 EXPECT_GT(picture_bytes, 0u);
269 cache.EvictUnusedCacheEntries();
271 recorder->RecordRasterEnd(&
cache);
274 ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
275 ASSERT_EQ(recorder->GetVsyncStartTime(), cloned->GetVsyncStartTime());
276 ASSERT_EQ(recorder->GetVsyncTargetTime(), cloned->GetVsyncTargetTime());
277 ASSERT_EQ(recorder->GetBuildStartTime(), cloned->GetBuildStartTime());
278 ASSERT_EQ(recorder->GetBuildEndTime(), cloned->GetBuildEndTime());
279 ASSERT_EQ(recorder->GetRasterStartTime(), cloned->GetRasterStartTime());
280 ASSERT_EQ(recorder->GetRasterEndTime(), cloned->GetRasterEndTime());
281 ASSERT_EQ(recorder->GetRasterEndWallTime(), cloned->GetRasterEndWallTime());
282 ASSERT_EQ(recorder->GetLayerCacheCount(), cloned->GetLayerCacheCount());
283 ASSERT_EQ(recorder->GetLayerCacheBytes(), cloned->GetLayerCacheBytes());
284 ASSERT_EQ(recorder->GetPictureCacheCount(), cloned->GetPictureCacheCount());
285 ASSERT_EQ(recorder->GetPictureCacheBytes(), cloned->GetPictureCacheBytes());
288TEST(FrameTimingsRecorderTest, FrameNumberTraceArgIsValid) {
289 auto recorder = std::make_unique<FrameTimingsRecorder>();
292 sprintf(buff,
"%d",
static_cast<int>(recorder->GetFrameNumber()));
293 std::string actual_arg = buff;
294 std::string expected_arg = recorder->GetFrameNumberTraceArg();
296 ASSERT_EQ(actual_arg, expected_arg);
A RasterCache implementation that simulates the act of rendering a Layer or DisplayList without the o...
std::string_view message() const
static constexpr TimeDelta FromMillisecondsF(double millis)
static constexpr TimeDelta FromMilliseconds(int64_t millis)
static TimePoint CurrentWallTime()
TEST(FrameTimingsRecorderTest, RecordVsync)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache