Commit cfc3637d authored by Nicolas Pena's avatar Nicolas Pena Committed by Commit Bot

Remove QueueingTimeEstimator::State

This CL removes the State member of QueueingTimeEstimator since it is no
longer needed. This is the first step in the plan to report EQT by TTI.

https://docs.google.com/document/d/19D0f5VGFNmqJDcl5_AqkYOm1iUX24adPloCRO58aiH4/

Bug: 832680, 830882
Change-Id: I571c75a15b51be1f8bff5b105257d6bb0d1092fc
Reviewed-on: https://chromium-review.googlesource.com/1035162Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555409}
parent 31e590f9
...@@ -69,33 +69,87 @@ QueueingTimeEstimator::QueueingTimeEstimator( ...@@ -69,33 +69,87 @@ QueueingTimeEstimator::QueueingTimeEstimator(
QueueingTimeEstimator::Client* client, QueueingTimeEstimator::Client* client,
base::TimeDelta window_duration, base::TimeDelta window_duration,
int steps_per_window) int steps_per_window)
: client_(client), state_(steps_per_window) { : client_(client),
window_step_width_(window_duration / steps_per_window),
renderer_backgrounded_(kLaunchingProcessIsBackgrounded),
processing_task_(false),
in_nested_message_loop_(false),
calculator_(steps_per_window) {
DCHECK_GE(steps_per_window, 1); DCHECK_GE(steps_per_window, 1);
state_.window_step_width = window_duration / steps_per_window;
} }
QueueingTimeEstimator::QueueingTimeEstimator(const State& state)
: client_(nullptr), state_(state) {}
void QueueingTimeEstimator::OnTopLevelTaskStarted( void QueueingTimeEstimator::OnTopLevelTaskStarted(
base::TimeTicks task_start_time, base::TimeTicks task_start_time,
MainThreadTaskQueue* queue) { MainThreadTaskQueue* queue) {
state_.OnTopLevelTaskStarted(client_, task_start_time, queue); AdvanceTime(task_start_time);
current_task_start_time_ = task_start_time;
processing_task_ = true;
calculator_.UpdateStatusFromTaskQueue(queue);
} }
void QueueingTimeEstimator::OnTopLevelTaskCompleted( void QueueingTimeEstimator::OnTopLevelTaskCompleted(
base::TimeTicks task_end_time) { base::TimeTicks task_end_time) {
state_.OnTopLevelTaskCompleted(client_, task_end_time); DCHECK(processing_task_);
AdvanceTime(task_end_time);
processing_task_ = false;
current_task_start_time_ = base::TimeTicks();
in_nested_message_loop_ = false;
} }
void QueueingTimeEstimator::OnBeginNestedRunLoop() { void QueueingTimeEstimator::OnBeginNestedRunLoop() {
state_.OnBeginNestedRunLoop(); in_nested_message_loop_ = true;
} }
void QueueingTimeEstimator::OnRendererStateChanged( void QueueingTimeEstimator::OnRendererStateChanged(
bool backgrounded, bool backgrounded,
base::TimeTicks transition_time) { base::TimeTicks transition_time) {
state_.OnRendererStateChanged(client_, backgrounded, transition_time); DCHECK_NE(backgrounded, renderer_backgrounded_);
if (!processing_task_)
AdvanceTime(transition_time);
renderer_backgrounded_ = backgrounded;
}
void QueueingTimeEstimator::AdvanceTime(base::TimeTicks current_time) {
if (step_start_time_.is_null()) {
// Ignore any time before the first task.
if (!processing_task_)
return;
step_start_time_ = current_task_start_time_;
}
base::TimeTicks reference_time =
processing_task_ ? current_task_start_time_ : step_start_time_;
if (in_nested_message_loop_ || renderer_backgrounded_ ||
current_time - reference_time > kInvalidPeriodThreshold) {
// Skip steps when the renderer was backgrounded, when we are at a nested
// message loop, when a task took too long, or when we remained idle for
// too long. May cause |step_start_time_| to go slightly into the future.
// TODO(npm): crbug.com/776013. Base skipping long tasks/idling on a signal
// that we've been suspended.
step_start_time_ =
current_time.SnappedToNextTick(step_start_time_, window_step_width_);
calculator_.ResetStep();
return;
}
while (TimePastStepEnd(current_time)) {
if (processing_task_) {
// Include the current task in this window.
calculator_.AddQueueingTime(ExpectedQueueingTimeFromTask(
current_task_start_time_, current_time, step_start_time_,
step_start_time_ + window_step_width_));
}
calculator_.EndStep(client_);
step_start_time_ += window_step_width_;
}
if (processing_task_) {
calculator_.AddQueueingTime(ExpectedQueueingTimeFromTask(
current_task_start_time_, current_time, step_start_time_,
step_start_time_ + window_step_width_));
}
}
bool QueueingTimeEstimator::TimePastStepEnd(base::TimeTicks time) {
return time >= step_start_time_ + window_step_width_;
} }
QueueingTimeEstimator::Calculator::Calculator(int steps_per_window) QueueingTimeEstimator::Calculator::Calculator(int steps_per_window)
...@@ -238,88 +292,6 @@ void QueueingTimeEstimator::Calculator::ResetStep() { ...@@ -238,88 +292,6 @@ void QueueingTimeEstimator::Calculator::ResetStep() {
step_expected_queueing_time_ = base::TimeDelta(); step_expected_queueing_time_ = base::TimeDelta();
} }
QueueingTimeEstimator::State::State(int steps_per_window)
: calculator_(steps_per_window) {}
void QueueingTimeEstimator::State::OnTopLevelTaskStarted(
QueueingTimeEstimator::Client* client,
base::TimeTicks task_start_time,
MainThreadTaskQueue* queue) {
AdvanceTime(client, task_start_time);
current_task_start_time = task_start_time;
processing_task = true;
calculator_.UpdateStatusFromTaskQueue(queue);
}
void QueueingTimeEstimator::State::OnTopLevelTaskCompleted(
QueueingTimeEstimator::Client* client,
base::TimeTicks task_end_time) {
DCHECK(processing_task);
AdvanceTime(client, task_end_time);
processing_task = false;
current_task_start_time = base::TimeTicks();
in_nested_message_loop_ = false;
}
void QueueingTimeEstimator::State::OnBeginNestedRunLoop() {
in_nested_message_loop_ = true;
}
void QueueingTimeEstimator::State::OnRendererStateChanged(
QueueingTimeEstimator::Client* client,
bool backgrounded,
base::TimeTicks transition_time) {
DCHECK_NE(backgrounded, renderer_backgrounded);
if (!processing_task)
AdvanceTime(client, transition_time);
renderer_backgrounded = backgrounded;
}
void QueueingTimeEstimator::State::AdvanceTime(
QueueingTimeEstimator::Client* client,
base::TimeTicks current_time) {
if (step_start_time.is_null()) {
// Ignore any time before the first task.
if (!processing_task)
return;
step_start_time = current_task_start_time;
}
base::TimeTicks reference_time =
processing_task ? current_task_start_time : step_start_time;
if (in_nested_message_loop_ || renderer_backgrounded ||
current_time - reference_time > kInvalidPeriodThreshold) {
// Skip steps when the renderer was backgrounded, when we are at a nested
// message loop, when a task took too long, or when we remained idle for
// too long. May cause |step_start_time| to go slightly into the future.
// TODO(npm): crbug.com/776013. Base skipping long tasks/idling on a signal
// that we've been suspended.
step_start_time =
current_time.SnappedToNextTick(step_start_time, window_step_width);
calculator_.ResetStep();
return;
}
while (TimePastStepEnd(current_time)) {
if (processing_task) {
// Include the current task in this window.
calculator_.AddQueueingTime(ExpectedQueueingTimeFromTask(
current_task_start_time, current_time, step_start_time,
step_start_time + window_step_width));
}
calculator_.EndStep(client);
step_start_time += window_step_width;
}
if (processing_task) {
calculator_.AddQueueingTime(ExpectedQueueingTimeFromTask(
current_task_start_time, current_time, step_start_time,
step_start_time + window_step_width));
}
}
bool QueueingTimeEstimator::State::TimePastStepEnd(base::TimeTicks time) {
return time >= step_start_time + window_step_width;
}
QueueingTimeEstimator::RunningAverage::RunningAverage(int size) { QueueingTimeEstimator::RunningAverage::RunningAverage(int size) {
circular_buffer_.resize(size); circular_buffer_.resize(size);
index_ = 0; index_ = 0;
......
...@@ -110,36 +110,9 @@ class PLATFORM_EXPORT QueueingTimeEstimator { ...@@ -110,36 +110,9 @@ class PLATFORM_EXPORT QueueingTimeEstimator {
FrameStatus current_frame_status_ = FrameStatus::kNone; FrameStatus current_frame_status_ = FrameStatus::kNone;
}; };
class State {
public:
explicit State(int steps_per_window);
void OnTopLevelTaskStarted(Client* client,
base::TimeTicks task_start_time,
MainThreadTaskQueue* queue);
void OnTopLevelTaskCompleted(Client* client, base::TimeTicks task_end_time);
void OnBeginNestedRunLoop();
void OnRendererStateChanged(Client* client,
bool backgrounded,
base::TimeTicks transition_time);
base::TimeDelta window_step_width;
base::TimeTicks step_start_time;
base::TimeTicks current_task_start_time;
// |renderer_backgrounded| is the renderer's current status.
bool renderer_backgrounded = kLaunchingProcessIsBackgrounded;
bool processing_task = false;
Calculator calculator_;
private:
void AdvanceTime(Client* client, base::TimeTicks current_time);
bool TimePastStepEnd(base::TimeTicks task_end_time);
bool in_nested_message_loop_ = false;
};
QueueingTimeEstimator(Client* client, QueueingTimeEstimator(Client* client,
base::TimeDelta window_duration, base::TimeDelta window_duration,
int steps_per_window); int steps_per_window);
explicit QueueingTimeEstimator(const State& state);
void OnTopLevelTaskStarted(base::TimeTicks task_start_time, void OnTopLevelTaskStarted(base::TimeTicks task_start_time,
MainThreadTaskQueue* queue); MainThreadTaskQueue* queue);
...@@ -148,12 +121,19 @@ class PLATFORM_EXPORT QueueingTimeEstimator { ...@@ -148,12 +121,19 @@ class PLATFORM_EXPORT QueueingTimeEstimator {
void OnRendererStateChanged(bool backgrounded, void OnRendererStateChanged(bool backgrounded,
base::TimeTicks transition_time); base::TimeTicks transition_time);
// Returns all state except for the current |client_|.
const State& GetState() const { return state_; }
private: private:
void AdvanceTime(base::TimeTicks current_time);
bool TimePastStepEnd(base::TimeTicks task_end_time);
Client* client_; // NOT OWNED. Client* client_; // NOT OWNED.
State state_; const base::TimeDelta window_step_width_;
base::TimeTicks step_start_time_;
base::TimeTicks current_task_start_time_;
// |renderer_backgrounded_| is the renderer's current status.
bool renderer_backgrounded_;
bool processing_task_;
bool in_nested_message_loop_;
Calculator calculator_;
DISALLOW_ASSIGN(QueueingTimeEstimator); DISALLOW_ASSIGN(QueueingTimeEstimator);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment