OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/scheduler/base/queueing_time_estimator.h" | 5 #include "platform/scheduler/base/queueing_time_estimator.h" |
6 #include "platform/scheduler/base/test_time_source.h" | 6 #include "platform/scheduler/base/test_time_source.h" |
7 #include "testing/gmock/include/gmock/gmock.h" | 7 #include "testing/gmock/include/gmock/gmock.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
(...skipping 25 matching lines...) Expand all Loading... |
36 // Three tasks of one second each, all within a 5 second window. Expected | 36 // Three tasks of one second each, all within a 5 second window. Expected |
37 // queueing time is the probability of falling into one of these tasks (3/5), | 37 // queueing time is the probability of falling into one of these tasks (3/5), |
38 // multiplied by the expected queueing time within a task (0.5 seconds). Thus we | 38 // multiplied by the expected queueing time within a task (0.5 seconds). Thus we |
39 // expect a queueing time of 0.3 seconds. | 39 // expect a queueing time of 0.3 seconds. |
40 TEST_F(QueueingTimeEstimatorTest, AllTasksWithinWindow) { | 40 TEST_F(QueueingTimeEstimatorTest, AllTasksWithinWindow) { |
41 base::TimeTicks time; | 41 base::TimeTicks time; |
42 TestQueueingTimeEstimatorClient client; | 42 TestQueueingTimeEstimatorClient client; |
43 QueueingTimeEstimatorForTest estimator(&client, | 43 QueueingTimeEstimatorForTest estimator(&client, |
44 base::TimeDelta::FromSeconds(5)); | 44 base::TimeDelta::FromSeconds(5)); |
45 for (int i = 0; i < 3; ++i) { | 45 for (int i = 0; i < 3; ++i) { |
46 estimator.OnToplevelTaskCompleted( | 46 estimator.OnTopLevelTaskCompleted( |
47 time, time + base::TimeDelta::FromMilliseconds(1000)); | 47 time, time + base::TimeDelta::FromMilliseconds(1000)); |
48 time += base::TimeDelta::FromMilliseconds(1500); | 48 time += base::TimeDelta::FromMilliseconds(1500); |
49 } | 49 } |
50 | 50 |
51 // Flush the data by adding a task in the next window. | 51 // Flush the data by adding a task in the next window. |
52 time += base::TimeDelta::FromMilliseconds(5000); | 52 time += base::TimeDelta::FromMilliseconds(5000); |
53 estimator.OnToplevelTaskCompleted( | 53 estimator.OnTopLevelTaskCompleted( |
54 time, time + base::TimeDelta::FromMilliseconds(500)); | 54 time, time + base::TimeDelta::FromMilliseconds(500)); |
55 | 55 |
56 EXPECT_THAT(client.expected_queueing_times(), | 56 EXPECT_THAT(client.expected_queueing_times(), |
57 testing::ElementsAre(base::TimeDelta::FromMilliseconds(300))); | 57 testing::ElementsAre(base::TimeDelta::FromMilliseconds(300))); |
58 } | 58 } |
59 | 59 |
60 // One 20 second long task, starting 3 seconds into the first window. | 60 // One 20 second long task, starting 3 seconds into the first window. |
61 // Window 1: Probability of being within task = 2/5. Expected delay within task: | 61 // Window 1: Probability of being within task = 2/5. Expected delay within task: |
62 // avg(20, 18). Total expected queueing time = 7.6s. | 62 // avg(20, 18). Total expected queueing time = 7.6s. |
63 // Window 2: Probability of being within task = 1. Expected delay within task: | 63 // Window 2: Probability of being within task = 1. Expected delay within task: |
64 // avg(18, 13). Total expected queueing time = 15.5s. | 64 // avg(18, 13). Total expected queueing time = 15.5s. |
65 // Window 5: Probability of being within task = 3/5. Expected delay within task: | 65 // Window 5: Probability of being within task = 3/5. Expected delay within task: |
66 // avg(3, 0). Total expected queueing time = 0.9s. | 66 // avg(3, 0). Total expected queueing time = 0.9s. |
67 TEST_F(QueueingTimeEstimatorTest, MultiWindowTask) { | 67 TEST_F(QueueingTimeEstimatorTest, MultiWindowTask) { |
68 TestQueueingTimeEstimatorClient client; | 68 TestQueueingTimeEstimatorClient client; |
69 QueueingTimeEstimatorForTest estimator(&client, | 69 QueueingTimeEstimatorForTest estimator(&client, |
70 base::TimeDelta::FromSeconds(5)); | 70 base::TimeDelta::FromSeconds(5)); |
71 base::TimeTicks time; | 71 base::TimeTicks time; |
72 time += base::TimeDelta::FromMilliseconds(5000); | 72 time += base::TimeDelta::FromMilliseconds(5000); |
73 estimator.OnToplevelTaskCompleted(time, time); | 73 estimator.OnTopLevelTaskCompleted(time, time); |
74 | 74 |
75 time += base::TimeDelta::FromMilliseconds(3000); | 75 time += base::TimeDelta::FromMilliseconds(3000); |
76 | 76 |
77 estimator.OnToplevelTaskCompleted( | 77 estimator.OnTopLevelTaskCompleted( |
78 time, time + base::TimeDelta::FromMilliseconds(20000)); | 78 time, time + base::TimeDelta::FromMilliseconds(20000)); |
79 | 79 |
80 // Flush the data by adding a task in the next window. | 80 // Flush the data by adding a task in the next window. |
81 time += base::TimeDelta::FromMilliseconds(25000); | 81 time += base::TimeDelta::FromMilliseconds(25000); |
82 | 82 |
83 estimator.OnToplevelTaskCompleted( | 83 estimator.OnTopLevelTaskCompleted( |
84 time, time + base::TimeDelta::FromMilliseconds(500)); | 84 time, time + base::TimeDelta::FromMilliseconds(500)); |
85 | 85 |
86 EXPECT_THAT(client.expected_queueing_times(), | 86 EXPECT_THAT(client.expected_queueing_times(), |
87 testing::ElementsAre(base::TimeDelta::FromMilliseconds(7600), | 87 testing::ElementsAre(base::TimeDelta::FromMilliseconds(7600), |
88 base::TimeDelta::FromMilliseconds(15500), | 88 base::TimeDelta::FromMilliseconds(15500), |
89 base::TimeDelta::FromMilliseconds(10500), | 89 base::TimeDelta::FromMilliseconds(10500), |
90 base::TimeDelta::FromMilliseconds(5500), | 90 base::TimeDelta::FromMilliseconds(5500), |
91 base::TimeDelta::FromMilliseconds(900))); | 91 base::TimeDelta::FromMilliseconds(900))); |
92 } | 92 } |
93 | 93 |
| 94 // The main thread is considered unresponsive during a single long task. In this |
| 95 // case, the single long task is 3 seconds long. |
| 96 // Probability of being with the task = 3/5. Expected delay within task: |
| 97 // avg(0, 3). Total expected queueing time = 3/5 * 3/2 = 0.9s. |
| 98 // In this example, the queueing time comes from the current, incomplete window. |
| 99 TEST_F(QueueingTimeEstimatorTest, |
| 100 EstimateQueueingTimeDuringSingleLongTaskIncompleteWindow) { |
| 101 TestQueueingTimeEstimatorClient client; |
| 102 QueueingTimeEstimatorForTest estimator(&client, |
| 103 base::TimeDelta::FromSeconds(5)); |
| 104 base::TimeTicks time; |
| 105 time += base::TimeDelta::FromMilliseconds(5000); |
| 106 estimator.OnTopLevelTaskCompleted(time, time); |
| 107 |
| 108 base::TimeTicks start_time = time; |
| 109 estimator.OnTopLevelTaskStarted(start_time); |
| 110 |
| 111 time += base::TimeDelta::FromMilliseconds(3000); |
| 112 |
| 113 base::TimeDelta estimatedQueueingTime = |
| 114 estimator.EstimateQueueingTimeIncludingCurrentTask(time); |
| 115 |
| 116 EXPECT_EQ(base::TimeDelta::FromMilliseconds(900), estimatedQueueingTime); |
| 117 } |
| 118 |
| 119 // The main thread is considered unresponsive during a single long task, which |
| 120 // exceeds the size of one window. In this example, the window with the worst |
| 121 // queueing time is aligned with the start of the long task. |
| 122 // Probability of being within the task = 100%, as the task fills the whole |
| 123 // window. Expected delay within this task = avg(13, 8) = 10.5. |
| 124 TEST_F(QueueingTimeEstimatorTest, EstimateQueueingTimeDuringSingleLongTaskExceed
ingWindow) { |
| 125 TestQueueingTimeEstimatorClient client; |
| 126 QueueingTimeEstimatorForTest estimator(&client, |
| 127 base::TimeDelta::FromSeconds(5)); |
| 128 base::TimeTicks time; |
| 129 time += base::TimeDelta::FromMilliseconds(5000); |
| 130 estimator.OnTopLevelTaskCompleted(time, time); |
| 131 |
| 132 base::TimeTicks start_time = time; |
| 133 estimator.OnTopLevelTaskStarted(start_time); |
| 134 |
| 135 time += base::TimeDelta::FromMilliseconds(13000); |
| 136 |
| 137 base::TimeDelta estimatedQueueingTime = |
| 138 estimator.EstimateQueueingTimeIncludingCurrentTask(time); |
| 139 |
| 140 EXPECT_EQ(base::TimeDelta::FromMilliseconds(10500), estimatedQueueingTime); |
| 141 } |
| 142 |
94 } // namespace scheduler | 143 } // namespace scheduler |
95 } // namespace blink | 144 } // namespace blink |
OLD | NEW |