Skip to content

Commit

Permalink
Frame timings clone fix (flutter#27751)
Browse files Browse the repository at this point in the history
  • Loading branch information
flar authored Jul 28, 2021
1 parent 135819f commit 0eac131
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
4 changes: 3 additions & 1 deletion flow/frame_timings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ std::unique_ptr<FrameTimingsRecorder> FrameTimingsRecorder::CloneUntil(
std::scoped_lock state_lock(state_mutex_);
std::unique_ptr<FrameTimingsRecorder> recorder =
std::make_unique<FrameTimingsRecorder>(frame_number_);
FML_DCHECK(state_ >= state);
recorder->state_ = state;

if (state >= State::kVsync) {
Expand All @@ -147,7 +148,7 @@ std::unique_ptr<FrameTimingsRecorder> FrameTimingsRecorder::CloneUntil(
recorder->build_start_ = build_start_;
}

if (state >= State::kRasterEnd) {
if (state >= State::kBuildEnd) {
recorder->build_end_ = build_end_;
}

Expand All @@ -157,6 +158,7 @@ std::unique_ptr<FrameTimingsRecorder> FrameTimingsRecorder::CloneUntil(

if (state >= State::kRasterEnd) {
recorder->raster_end_ = raster_end_;
recorder->raster_end_wall_time_ = raster_end_wall_time_;
}

return recorder;
Expand Down
81 changes: 80 additions & 1 deletion flow/frame_timings_recorder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,90 @@ TEST(FrameTimingsRecorderTest, RecordersHaveUniqueFrameNumbers) {
TEST(FrameTimingsRecorderTest, ClonedHasSameFrameNumber) {
auto recorder = std::make_unique<FrameTimingsRecorder>();

auto cloned =
recorder->CloneUntil(FrameTimingsRecorder::State::kUninitialized);
ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
}

TEST(FrameTimingsRecorderTest, ClonedHasSameVsyncStartAndTarget) {
auto recorder = std::make_unique<FrameTimingsRecorder>();

const auto now = fml::TimePoint::Now();
recorder->RecordVsync(now, now);
recorder->RecordVsync(now, now + fml::TimeDelta::FromMilliseconds(16));

auto cloned = recorder->CloneUntil(FrameTimingsRecorder::State::kVsync);
ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
ASSERT_EQ(recorder->GetVsyncStartTime(), cloned->GetVsyncStartTime());
ASSERT_EQ(recorder->GetVsyncTargetTime(), cloned->GetVsyncTargetTime());
}

TEST(FrameTimingsRecorderTest, ClonedHasSameBuildStart) {
auto recorder = std::make_unique<FrameTimingsRecorder>();

const auto now = fml::TimePoint::Now();
recorder->RecordVsync(now, now + fml::TimeDelta::FromMilliseconds(16));
recorder->RecordBuildStart(fml::TimePoint::Now());

auto cloned = recorder->CloneUntil(FrameTimingsRecorder::State::kBuildStart);
ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
ASSERT_EQ(recorder->GetVsyncStartTime(), cloned->GetVsyncStartTime());
ASSERT_EQ(recorder->GetVsyncTargetTime(), cloned->GetVsyncTargetTime());
ASSERT_EQ(recorder->GetBuildStartTime(), cloned->GetBuildStartTime());
}

TEST(FrameTimingsRecorderTest, ClonedHasSameBuildEnd) {
auto recorder = std::make_unique<FrameTimingsRecorder>();

const auto now = fml::TimePoint::Now();
recorder->RecordVsync(now, now + fml::TimeDelta::FromMilliseconds(16));
recorder->RecordBuildStart(fml::TimePoint::Now());
recorder->RecordBuildEnd(fml::TimePoint::Now());

auto cloned = recorder->CloneUntil(FrameTimingsRecorder::State::kBuildEnd);
ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
ASSERT_EQ(recorder->GetVsyncStartTime(), cloned->GetVsyncStartTime());
ASSERT_EQ(recorder->GetVsyncTargetTime(), cloned->GetVsyncTargetTime());
ASSERT_EQ(recorder->GetBuildStartTime(), cloned->GetBuildStartTime());
ASSERT_EQ(recorder->GetBuildEndTime(), cloned->GetBuildEndTime());
}

TEST(FrameTimingsRecorderTest, ClonedHasSameRasterStart) {
auto recorder = std::make_unique<FrameTimingsRecorder>();

const auto now = fml::TimePoint::Now();
recorder->RecordVsync(now, now + fml::TimeDelta::FromMilliseconds(16));
recorder->RecordBuildStart(fml::TimePoint::Now());
recorder->RecordBuildEnd(fml::TimePoint::Now());
recorder->RecordRasterStart(fml::TimePoint::Now());

auto cloned = recorder->CloneUntil(FrameTimingsRecorder::State::kRasterStart);
ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
ASSERT_EQ(recorder->GetVsyncStartTime(), cloned->GetVsyncStartTime());
ASSERT_EQ(recorder->GetVsyncTargetTime(), cloned->GetVsyncTargetTime());
ASSERT_EQ(recorder->GetBuildStartTime(), cloned->GetBuildStartTime());
ASSERT_EQ(recorder->GetBuildEndTime(), cloned->GetBuildEndTime());
ASSERT_EQ(recorder->GetRasterStartTime(), cloned->GetRasterStartTime());
}

TEST(FrameTimingsRecorderTest, ClonedHasSameRasterEnd) {
auto recorder = std::make_unique<FrameTimingsRecorder>();

const auto now = fml::TimePoint::Now();
recorder->RecordVsync(now, now + fml::TimeDelta::FromMilliseconds(16));
recorder->RecordBuildStart(fml::TimePoint::Now());
recorder->RecordBuildEnd(fml::TimePoint::Now());
recorder->RecordRasterStart(fml::TimePoint::Now());
recorder->RecordRasterEnd();

auto cloned = recorder->CloneUntil(FrameTimingsRecorder::State::kRasterEnd);
ASSERT_EQ(recorder->GetFrameNumber(), cloned->GetFrameNumber());
ASSERT_EQ(recorder->GetVsyncStartTime(), cloned->GetVsyncStartTime());
ASSERT_EQ(recorder->GetVsyncTargetTime(), cloned->GetVsyncTargetTime());
ASSERT_EQ(recorder->GetBuildStartTime(), cloned->GetBuildStartTime());
ASSERT_EQ(recorder->GetBuildEndTime(), cloned->GetBuildEndTime());
ASSERT_EQ(recorder->GetRasterStartTime(), cloned->GetRasterStartTime());
ASSERT_EQ(recorder->GetRasterEndTime(), cloned->GetRasterEndTime());
ASSERT_EQ(recorder->GetRasterEndWallTime(), cloned->GetRasterEndWallTime());
}

TEST(FrameTimingsRecorderTest, FrameNumberTraceArgIsValid) {
Expand Down

0 comments on commit 0eac131

Please sign in to comment.