Chromium Code Reviews| Index: third_party/WebKit/Source/platform/scheduler/base/queueing_time_estimator.h |
| diff --git a/third_party/WebKit/Source/platform/scheduler/base/queueing_time_estimator.h b/third_party/WebKit/Source/platform/scheduler/base/queueing_time_estimator.h |
| index 4bdd47519f24d08654b5cddf229fe1b5fefe2b35..af8291d51e58c04c4b15cb30dce5a510bcc095ec 100644 |
| --- a/third_party/WebKit/Source/platform/scheduler/base/queueing_time_estimator.h |
| +++ b/third_party/WebKit/Source/platform/scheduler/base/queueing_time_estimator.h |
| @@ -9,6 +9,8 @@ |
| #include "base/time/time.h" |
| #include "platform/PlatformExport.h" |
| +#include <vector> |
| + |
| namespace blink { |
| namespace scheduler { |
| @@ -19,7 +21,8 @@ class PLATFORM_EXPORT QueueingTimeEstimator { |
| class PLATFORM_EXPORT Client { |
| public: |
| virtual void OnQueueingTimeForWindowEstimated( |
| - base::TimeDelta queueing_time) = 0; |
| + base::TimeDelta queueing_time, |
| + base::TimeTicks window_start_time) = 0; |
| Client() {} |
| virtual ~Client() {} |
| @@ -27,23 +30,72 @@ class PLATFORM_EXPORT QueueingTimeEstimator { |
| DISALLOW_COPY_AND_ASSIGN(Client); |
| }; |
| + class RunningAverage { |
| + public: |
| + RunningAverage(int steps_per_window); |
| + int GetStepsPerWindow(); |
| + void ClearBuffer(); |
| + void Add(base::TimeDelta bin_value); |
| + base::TimeDelta GetAverage(); |
| + |
| + private: |
| + int index_; |
| + std::vector<base::TimeDelta> circular_buffer_; |
| + base::TimeDelta running_sum_; |
| + }; |
| + |
| class State { |
| public: |
| + explicit State(int steps_per_window); |
| void OnTopLevelTaskStarted(base::TimeTicks task_start_time); |
| void OnTopLevelTaskCompleted(Client* client, base::TimeTicks task_end_time); |
| void OnBeginNestedMessageLoop(); |
| - base::TimeDelta current_expected_queueing_time; |
| + // |step_expected_queueing_time| is the expected queuing time of a |
| + // smaller window of a step's width. By combining these step EQTs though |
|
tdresser
2017/05/11 13:52:44
though -> through a
Liquan (Max) Gu
2017/05/11 15:14:13
Done.
|
| + // running average, we can get window EQTs of a bigger window. |
| + // |
| + // ^ Instantaneous queuing time |
| + // | |
| + // | |
| + // | |\ |
| + // | | \ |\ |\ |
| + // | | \ | \ |\ | \ |
| + // | | \ |\ | \ | \ | \ |
| + // | | \ | \ | \ | \ | \ |
| + // ------------------------------------------------> Time |
| + // |
| + // |stepEQT|stepEQT|stepEQT|stepEQT|stepEQT|stepEQT| |
| + // |
| + // |------windowEQT_1------| |
| + // |------windowEQT_2------| |
| + // |------windowEQT_3------| |
| + // |
| + // In this case: |
| + // |steps_per_window| = 3, because each window is the length of 3 steps. |
| + |
| + base::TimeDelta step_expected_queueing_time; |
| + // |window_duration| is the size of the sliding window. |
| base::TimeDelta window_duration; |
| + base::TimeDelta window_step_width; |
| + // |steps_per_window| is the ratio of |window_duration| to the sliding |
| + // window's step width. It is an integer since the window must be a integer |
| + // multiple of the step's width. This parameter is used for deciding the |
| + // sliding window's step width, and the number of bins of the circular |
| + // buffer. |
| + int steps_per_window; |
| base::TimeTicks window_start_time; |
| base::TimeTicks current_task_start_time; |
| + RunningAverage step_queueing_times; |
| private: |
| bool TimePastWindowEnd(base::TimeTicks task_end_time); |
| bool in_nested_message_loop_ = false; |
| }; |
| - QueueingTimeEstimator(Client* client, base::TimeDelta window_duration); |
| + QueueingTimeEstimator(Client* client, |
| + base::TimeDelta window_duration, |
| + int steps_per_window); |
| explicit QueueingTimeEstimator(const State& state); |
| void OnTopLevelTaskStarted(base::TimeTicks task_start_time); |