OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_SCHEDULER_RENDERER_IDLE_TIME_ESTIMATOR_H_ | 5 #ifndef COMPONENTS_SCHEDULER_RENDERER_IDLE_TIME_ESTIMATOR_H_ |
6 #define COMPONENTS_SCHEDULER_RENDERER_IDLE_TIME_ESTIMATOR_H_ | 6 #define COMPONENTS_SCHEDULER_RENDERER_IDLE_TIME_ESTIMATOR_H_ |
7 | 7 |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/time/tick_clock.h" | 9 #include "base/time/tick_clock.h" |
10 #include "cc/base/rolling_time_delta_history.h" | 10 #include "cc/base/rolling_time_delta_history.h" |
11 #include "components/scheduler/base/task_queue.h" | 11 #include "components/scheduler/base/task_queue.h" |
12 #include "components/scheduler/scheduler_export.h" | 12 #include "components/scheduler/scheduler_export.h" |
13 | 13 |
14 namespace scheduler { | 14 namespace scheduler { |
15 | 15 |
16 // Estimates how much idle time there is available. Ignores nested tasks. | 16 // Estimates how much idle time there is available. Ignores nested tasks. |
17 class SCHEDULER_EXPORT IdleTimeEstimator | 17 class SCHEDULER_EXPORT IdleTimeEstimator |
18 : public base::MessageLoop::TaskObserver { | 18 : public base::MessageLoop::TaskObserver { |
19 public: | 19 public: |
20 IdleTimeEstimator(const scoped_refptr<TaskQueue>& compositor_task_runner, | 20 IdleTimeEstimator(const scoped_refptr<TaskQueue>& compositor_task_runner, |
| 21 base::TickClock* time_source, |
21 int sample_count, | 22 int sample_count, |
22 double estimation_percentile); | 23 double estimation_percentile); |
23 | 24 |
24 ~IdleTimeEstimator() override; | 25 ~IdleTimeEstimator() override; |
25 | 26 |
26 // Expected Idle time is defined as: |compositor_frame_interval| minus | 27 // Expected Idle time is defined as: |compositor_frame_interval| minus |
27 // expected compositor task duration. | 28 // expected compositor task duration. |
28 base::TimeDelta GetExpectedIdleDuration( | 29 base::TimeDelta GetExpectedIdleDuration( |
29 base::TimeDelta compositor_frame_interval) const; | 30 base::TimeDelta compositor_frame_interval) const; |
30 | 31 |
31 void DidCommitFrameToCompositor(); | 32 void DidCommitFrameToCompositor(); |
32 | 33 |
33 void Clear(); | 34 void Clear(); |
34 | 35 |
35 // TaskObserver implementation: | 36 // TaskObserver implementation: |
36 void WillProcessTask(const base::PendingTask& pending_task) override; | 37 void WillProcessTask(const base::PendingTask& pending_task) override; |
37 void DidProcessTask(const base::PendingTask& pending_task) override; | 38 void DidProcessTask(const base::PendingTask& pending_task) override; |
38 | 39 |
39 void SetTimeSourceForTesting(scoped_ptr<base::TickClock> time_source); | |
40 | |
41 private: | 40 private: |
42 scoped_refptr<TaskQueue> compositor_task_runner_; | 41 scoped_refptr<TaskQueue> compositor_task_runner_; |
43 cc::RollingTimeDeltaHistory per_frame_compositor_task_runtime_; | 42 cc::RollingTimeDeltaHistory per_frame_compositor_task_runtime_; |
44 scoped_ptr<base::TickClock> time_source_; | 43 base::TickClock* time_source_; // NOT OWNED |
45 double estimation_percentile_; | 44 double estimation_percentile_; |
46 | 45 |
47 base::TimeTicks task_start_time_; | 46 base::TimeTicks task_start_time_; |
48 base::TimeTicks prev_commit_time_; | 47 base::TimeTicks prev_commit_time_; |
49 base::TimeDelta cumulative_compositor_runtime_; | 48 base::TimeDelta cumulative_compositor_runtime_; |
50 int nesting_level_; | 49 int nesting_level_; |
51 bool did_commit_; | 50 bool did_commit_; |
52 | 51 |
53 DISALLOW_COPY_AND_ASSIGN(IdleTimeEstimator); | 52 DISALLOW_COPY_AND_ASSIGN(IdleTimeEstimator); |
54 }; | 53 }; |
55 | 54 |
56 } // namespace scheduler | 55 } // namespace scheduler |
57 | 56 |
58 #endif // COMPONENTS_SCHEDULER_RENDERER_IDLE_TIME_ESTIMATOR_H_ | 57 #endif // COMPONENTS_SCHEDULER_RENDERER_IDLE_TIME_ESTIMATOR_H_ |
OLD | NEW |