OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "cc/scheduler/compositor_timing_history.h" | |
6 | |
7 #include "cc/debug/rendering_stats_instrumentation.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace cc { | |
11 namespace { | |
12 | |
13 class CompositorTimingHistoryTest; | |
14 | |
15 class TestCompositorTimingHistory : public CompositorTimingHistory { | |
16 public: | |
17 TestCompositorTimingHistory(CompositorTimingHistoryTest* test, | |
18 RenderingStatsInstrumentation* rendering_stats) | |
19 : CompositorTimingHistory(rendering_stats), test_(test) {} | |
20 | |
21 protected: | |
22 base::TimeTicks Now() const override; | |
23 | |
24 CompositorTimingHistoryTest* test_; | |
25 | |
26 private: | |
27 DISALLOW_COPY_AND_ASSIGN(TestCompositorTimingHistory); | |
28 }; | |
29 | |
30 class CompositorTimingHistoryTest : public testing::Test { | |
31 public: | |
32 CompositorTimingHistoryTest() | |
33 : rendering_stats_(RenderingStatsInstrumentation::Create()), | |
34 timing_history_(this, rendering_stats_.get()) { | |
35 AdvanceNowBy(base::TimeDelta::FromMilliseconds(1)); | |
36 timing_history_.SetRecordingEnabled(true); | |
37 } | |
38 | |
39 void AdvanceNowBy(base::TimeDelta delta) { now_ += delta; } | |
40 | |
41 base::TimeTicks Now() { return now_; } | |
42 | |
43 protected: | |
44 scoped_ptr<RenderingStatsInstrumentation> rendering_stats_; | |
45 TestCompositorTimingHistory timing_history_; | |
46 base::TimeTicks now_; | |
47 }; | |
48 | |
49 base::TimeTicks TestCompositorTimingHistory::Now() const { | |
50 return test_->Now(); | |
51 } | |
52 | |
53 TEST_F(CompositorTimingHistoryTest, AllSequentialCommit) { | |
54 base::TimeDelta one_second = base::TimeDelta::FromSeconds(1); | |
55 | |
56 base::TimeDelta begin_main_frame_to_commit_duration = | |
57 base::TimeDelta::FromMilliseconds(1); | |
58 base::TimeDelta prepare_tiles_duration = base::TimeDelta::FromMilliseconds(2); | |
59 base::TimeDelta prepare_tiles_end_to_ready_to_activate_duration = | |
60 base::TimeDelta::FromMilliseconds(1); | |
61 base::TimeDelta commit_to_ready_to_activate_duration = | |
62 base::TimeDelta::FromMilliseconds(3); | |
63 base::TimeDelta activate_duration = base::TimeDelta::FromMilliseconds(4); | |
64 base::TimeDelta draw_duration = base::TimeDelta::FromMilliseconds(5); | |
65 | |
66 timing_history_.WillBeginMainFrame(); | |
67 AdvanceNowBy(begin_main_frame_to_commit_duration); | |
68 // timing_history_.BeginMainFrameAborted(); | |
69 timing_history_.DidCommit(); | |
70 timing_history_.WillPrepareTiles(); | |
71 AdvanceNowBy(prepare_tiles_duration); | |
72 timing_history_.DidPrepareTiles(); | |
73 AdvanceNowBy(prepare_tiles_end_to_ready_to_activate_duration); | |
74 timing_history_.ReadyToActivate(); | |
75 // Do not count idle time between notification and actual activation. | |
76 AdvanceNowBy(one_second); | |
77 timing_history_.WillActivate(); | |
78 AdvanceNowBy(activate_duration); | |
79 timing_history_.DidActivate(); | |
80 // Do not count idle time between activate and draw. | |
81 AdvanceNowBy(one_second); | |
82 timing_history_.WillDraw(); | |
83 AdvanceNowBy(draw_duration); | |
84 timing_history_.DidDraw(); | |
85 | |
86 EXPECT_EQ(begin_main_frame_to_commit_duration, | |
87 timing_history_.BeginMainFrameToCommitDurationEstimate()); | |
88 EXPECT_EQ(commit_to_ready_to_activate_duration, | |
89 timing_history_.CommitToReadyToActivateDurationEstimate()); | |
90 EXPECT_EQ(prepare_tiles_duration, | |
91 timing_history_.PrepareTilesDurationEstimate()); | |
92 EXPECT_EQ(activate_duration, timing_history_.ActivateDurationEstimate()); | |
93 EXPECT_EQ(draw_duration, timing_history_.DrawDurationEstimate()); | |
94 } | |
95 | |
96 TEST_F(CompositorTimingHistoryTest, AllSequentialBeginMainFrameAborted) { | |
97 base::TimeDelta one_second = base::TimeDelta::FromSeconds(1); | |
98 | |
99 base::TimeDelta begin_main_frame_to_commit_duration = | |
100 base::TimeDelta::FromMilliseconds(1); | |
101 base::TimeDelta prepare_tiles_duration = base::TimeDelta::FromMilliseconds(2); | |
102 base::TimeDelta prepare_tiles_end_to_ready_to_activate_duration = | |
103 base::TimeDelta::FromMilliseconds(1); | |
104 base::TimeDelta commit_to_ready_to_activate_duration = | |
105 base::TimeDelta::FromMilliseconds(3); | |
106 base::TimeDelta activate_duration = base::TimeDelta::FromMilliseconds(4); | |
107 base::TimeDelta draw_duration = base::TimeDelta::FromMilliseconds(5); | |
108 | |
109 timing_history_.WillBeginMainFrame(); | |
110 AdvanceNowBy(begin_main_frame_to_commit_duration); | |
111 // BeginMainFrameAborted counts as a commit complete. | |
112 timing_history_.BeginMainFrameAborted(); | |
113 timing_history_.WillPrepareTiles(); | |
114 AdvanceNowBy(prepare_tiles_duration); | |
115 timing_history_.DidPrepareTiles(); | |
116 AdvanceNowBy(prepare_tiles_end_to_ready_to_activate_duration); | |
117 timing_history_.ReadyToActivate(); | |
118 // Do not count idle time between notification and actual activation. | |
119 AdvanceNowBy(one_second); | |
120 timing_history_.WillActivate(); | |
121 AdvanceNowBy(activate_duration); | |
122 timing_history_.DidActivate(); | |
123 // Do not count idle time between activate and draw. | |
124 AdvanceNowBy(one_second); | |
125 timing_history_.WillDraw(); | |
126 AdvanceNowBy(draw_duration); | |
127 timing_history_.DidDraw(); | |
128 | |
129 EXPECT_EQ(begin_main_frame_to_commit_duration, | |
130 timing_history_.BeginMainFrameToCommitDurationEstimate()); | |
131 EXPECT_EQ(commit_to_ready_to_activate_duration, | |
132 timing_history_.CommitToReadyToActivateDurationEstimate()); | |
133 EXPECT_EQ(prepare_tiles_duration, | |
134 timing_history_.PrepareTilesDurationEstimate()); | |
135 EXPECT_EQ(activate_duration, timing_history_.ActivateDurationEstimate()); | |
136 EXPECT_EQ(draw_duration, timing_history_.DrawDurationEstimate()); | |
137 } | |
138 | |
139 } // namespace | |
140 } // namespace cc | |
OLD | NEW |