Delete unused downloads page asset.
[chromium-blink-merge.git] / cc / scheduler / compositor_timing_history_unittest.cc
blobe5eeeacfa2ef4c48592b30291ec7fa8c8cedffad
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/scheduler/compositor_timing_history.h"
7 #include "cc/debug/rendering_stats_instrumentation.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace cc {
11 namespace {
13 class CompositorTimingHistoryTest;
15 class TestCompositorTimingHistory : public CompositorTimingHistory {
16 public:
17 TestCompositorTimingHistory(CompositorTimingHistoryTest* test,
18 RenderingStatsInstrumentation* rendering_stats)
19 : CompositorTimingHistory(CompositorTimingHistory::NULL_UMA,
20 rendering_stats),
21 test_(test) {}
23 protected:
24 base::TimeTicks Now() const override;
26 CompositorTimingHistoryTest* test_;
28 private:
29 DISALLOW_COPY_AND_ASSIGN(TestCompositorTimingHistory);
32 class CompositorTimingHistoryTest : public testing::Test {
33 public:
34 CompositorTimingHistoryTest()
35 : rendering_stats_(RenderingStatsInstrumentation::Create()),
36 timing_history_(this, rendering_stats_.get()) {
37 AdvanceNowBy(base::TimeDelta::FromMilliseconds(1));
38 timing_history_.SetRecordingEnabled(true);
41 void AdvanceNowBy(base::TimeDelta delta) { now_ += delta; }
43 base::TimeTicks Now() { return now_; }
45 void TriggerAllNotificationsWithoutAdvancingTime() {
46 timing_history_.WillBeginMainFrame();
47 timing_history_.DidCommit();
48 timing_history_.WillPrepareTiles();
49 timing_history_.DidPrepareTiles();
50 timing_history_.ReadyToActivate();
51 timing_history_.WillActivate();
52 timing_history_.DidActivate();
53 timing_history_.WillDraw();
54 timing_history_.DidDraw();
57 void TriggerInitialUnrecordedActions() {
58 // The first two cycles are not used since
59 // they are generally more expensive then subsequent frames.
60 TriggerAllNotificationsWithoutAdvancingTime();
61 TriggerAllNotificationsWithoutAdvancingTime();
64 protected:
65 scoped_ptr<RenderingStatsInstrumentation> rendering_stats_;
66 TestCompositorTimingHistory timing_history_;
67 base::TimeTicks now_;
70 base::TimeTicks TestCompositorTimingHistory::Now() const {
71 return test_->Now();
74 TEST_F(CompositorTimingHistoryTest, FirstTwoFramesNotRecorded) {
75 base::TimeDelta one_second = base::TimeDelta::FromSeconds(1);
77 base::TimeDelta begin_main_frame_to_commit_duration =
78 base::TimeDelta::FromMilliseconds(1);
79 base::TimeDelta prepare_tiles_duration = base::TimeDelta::FromMilliseconds(2);
80 base::TimeDelta prepare_tiles_end_to_ready_to_activate_duration =
81 base::TimeDelta::FromMilliseconds(1);
82 base::TimeDelta commit_to_ready_to_activate_duration =
83 base::TimeDelta::FromMilliseconds(3);
84 base::TimeDelta activate_duration = base::TimeDelta::FromMilliseconds(4);
85 base::TimeDelta draw_duration = base::TimeDelta::FromMilliseconds(5);
87 // Verify first two frames don't affect results.
88 for (int i = 0; i < 2; i++) {
89 timing_history_.WillBeginMainFrame();
90 AdvanceNowBy(begin_main_frame_to_commit_duration);
91 timing_history_.DidCommit();
92 timing_history_.WillPrepareTiles();
93 AdvanceNowBy(prepare_tiles_duration);
94 timing_history_.DidPrepareTiles();
95 AdvanceNowBy(prepare_tiles_end_to_ready_to_activate_duration);
96 timing_history_.ReadyToActivate();
97 AdvanceNowBy(one_second);
98 timing_history_.WillActivate();
99 AdvanceNowBy(activate_duration);
100 timing_history_.DidActivate();
101 AdvanceNowBy(one_second);
102 timing_history_.WillDraw();
103 AdvanceNowBy(draw_duration);
104 timing_history_.DidDraw();
106 EXPECT_EQ(base::TimeDelta(),
107 timing_history_.BeginMainFrameToCommitDurationEstimate());
108 EXPECT_EQ(base::TimeDelta(),
109 timing_history_.CommitToReadyToActivateDurationEstimate());
110 EXPECT_EQ(base::TimeDelta(),
111 timing_history_.PrepareTilesDurationEstimate());
112 EXPECT_EQ(base::TimeDelta(), timing_history_.ActivateDurationEstimate());
113 EXPECT_EQ(base::TimeDelta(), timing_history_.DrawDurationEstimate());
116 timing_history_.WillBeginMainFrame();
117 AdvanceNowBy(begin_main_frame_to_commit_duration);
118 timing_history_.DidCommit();
119 timing_history_.WillPrepareTiles();
120 AdvanceNowBy(prepare_tiles_duration);
121 timing_history_.DidPrepareTiles();
122 AdvanceNowBy(prepare_tiles_end_to_ready_to_activate_duration);
123 timing_history_.ReadyToActivate();
124 // Do not count idle time between notification and actual activation.
125 AdvanceNowBy(one_second);
126 timing_history_.WillActivate();
127 AdvanceNowBy(activate_duration);
128 timing_history_.DidActivate();
129 // Do not count idle time between activate and draw.
130 AdvanceNowBy(one_second);
131 timing_history_.WillDraw();
132 AdvanceNowBy(draw_duration);
133 timing_history_.DidDraw();
135 EXPECT_EQ(begin_main_frame_to_commit_duration,
136 timing_history_.BeginMainFrameToCommitDurationEstimate());
137 EXPECT_EQ(commit_to_ready_to_activate_duration,
138 timing_history_.CommitToReadyToActivateDurationEstimate());
139 EXPECT_EQ(prepare_tiles_duration,
140 timing_history_.PrepareTilesDurationEstimate());
141 EXPECT_EQ(activate_duration, timing_history_.ActivateDurationEstimate());
142 EXPECT_EQ(draw_duration, timing_history_.DrawDurationEstimate());
145 TEST_F(CompositorTimingHistoryTest, AllSequentialCommit) {
146 TriggerInitialUnrecordedActions();
148 base::TimeDelta one_second = base::TimeDelta::FromSeconds(1);
150 base::TimeDelta begin_main_frame_to_commit_duration =
151 base::TimeDelta::FromMilliseconds(1);
152 base::TimeDelta prepare_tiles_duration = base::TimeDelta::FromMilliseconds(2);
153 base::TimeDelta prepare_tiles_end_to_ready_to_activate_duration =
154 base::TimeDelta::FromMilliseconds(1);
155 base::TimeDelta commit_to_ready_to_activate_duration =
156 base::TimeDelta::FromMilliseconds(3);
157 base::TimeDelta activate_duration = base::TimeDelta::FromMilliseconds(4);
158 base::TimeDelta draw_duration = base::TimeDelta::FromMilliseconds(5);
160 timing_history_.WillBeginMainFrame();
161 AdvanceNowBy(begin_main_frame_to_commit_duration);
162 timing_history_.DidCommit();
163 timing_history_.WillPrepareTiles();
164 AdvanceNowBy(prepare_tiles_duration);
165 timing_history_.DidPrepareTiles();
166 AdvanceNowBy(prepare_tiles_end_to_ready_to_activate_duration);
167 timing_history_.ReadyToActivate();
168 // Do not count idle time between notification and actual activation.
169 AdvanceNowBy(one_second);
170 timing_history_.WillActivate();
171 AdvanceNowBy(activate_duration);
172 timing_history_.DidActivate();
173 // Do not count idle time between activate and draw.
174 AdvanceNowBy(one_second);
175 timing_history_.WillDraw();
176 AdvanceNowBy(draw_duration);
177 timing_history_.DidDraw();
179 EXPECT_EQ(begin_main_frame_to_commit_duration,
180 timing_history_.BeginMainFrameToCommitDurationEstimate());
181 EXPECT_EQ(commit_to_ready_to_activate_duration,
182 timing_history_.CommitToReadyToActivateDurationEstimate());
183 EXPECT_EQ(prepare_tiles_duration,
184 timing_history_.PrepareTilesDurationEstimate());
185 EXPECT_EQ(activate_duration, timing_history_.ActivateDurationEstimate());
186 EXPECT_EQ(draw_duration, timing_history_.DrawDurationEstimate());
189 TEST_F(CompositorTimingHistoryTest, AllSequentialBeginMainFrameAborted) {
190 TriggerInitialUnrecordedActions();
192 base::TimeDelta one_second = base::TimeDelta::FromSeconds(1);
194 base::TimeDelta begin_main_frame_to_commit_duration =
195 base::TimeDelta::FromMilliseconds(1);
196 base::TimeDelta prepare_tiles_duration = base::TimeDelta::FromMilliseconds(2);
197 base::TimeDelta prepare_tiles_end_to_ready_to_activate_duration =
198 base::TimeDelta::FromMilliseconds(1);
199 base::TimeDelta commit_to_ready_to_activate_duration =
200 base::TimeDelta::FromMilliseconds(3);
201 base::TimeDelta activate_duration = base::TimeDelta::FromMilliseconds(4);
202 base::TimeDelta draw_duration = base::TimeDelta::FromMilliseconds(5);
204 timing_history_.WillBeginMainFrame();
205 AdvanceNowBy(begin_main_frame_to_commit_duration);
206 // BeginMainFrameAborted counts as a commit complete.
207 timing_history_.BeginMainFrameAborted();
208 timing_history_.WillPrepareTiles();
209 AdvanceNowBy(prepare_tiles_duration);
210 timing_history_.DidPrepareTiles();
211 AdvanceNowBy(prepare_tiles_end_to_ready_to_activate_duration);
212 timing_history_.ReadyToActivate();
213 // Do not count idle time between notification and actual activation.
214 AdvanceNowBy(one_second);
215 timing_history_.WillActivate();
216 AdvanceNowBy(activate_duration);
217 timing_history_.DidActivate();
218 // Do not count idle time between activate and draw.
219 AdvanceNowBy(one_second);
220 timing_history_.WillDraw();
221 AdvanceNowBy(draw_duration);
222 timing_history_.DidDraw();
224 EXPECT_EQ(begin_main_frame_to_commit_duration,
225 timing_history_.BeginMainFrameToCommitDurationEstimate());
226 EXPECT_EQ(commit_to_ready_to_activate_duration,
227 timing_history_.CommitToReadyToActivateDurationEstimate());
228 EXPECT_EQ(prepare_tiles_duration,
229 timing_history_.PrepareTilesDurationEstimate());
230 EXPECT_EQ(activate_duration, timing_history_.ActivateDurationEstimate());
231 EXPECT_EQ(draw_duration, timing_history_.DrawDurationEstimate());
234 } // namespace
235 } // namespace cc