Commit 852a0827 authored by Tom McKee's avatar Tom McKee Committed by Commit Bot

A small renaming to reduce coupling.

The QueueingTimeEstimator had a flag that was, effectively, a
disabled/enabled flag. Instead of naming it for the external state that
causes updates to the flag, name it for what the flag is used for inside
the QueueingTimeEstimator.

Bug: 883487
Change-Id: I73c7f71ff10fcacaf1e85a3f89f5e1a123b78896
Reviewed-on: https://chromium-review.googlesource.com/c/1296822
Commit-Queue: Tom McKee <tommckee@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603535}
parent e874adda
...@@ -215,7 +215,10 @@ MainThreadSchedulerImpl::MainThreadSchedulerImpl( ...@@ -215,7 +215,10 @@ MainThreadSchedulerImpl::MainThreadSchedulerImpl(
base::Unretained(this)), base::Unretained(this)),
helper_.ControlMainThreadTaskQueue()->CreateTaskRunner( helper_.ControlMainThreadTaskQueue()->CreateTaskRunner(
TaskType::kMainThreadTaskQueueControl)), TaskType::kMainThreadTaskQueueControl)),
queueing_time_estimator_(this, kQueueingTimeWindowDuration, 20), queueing_time_estimator_(this,
kQueueingTimeWindowDuration,
20,
kLaunchingProcessIsBackgrounded),
main_thread_only_(this, main_thread_only_(this,
compositor_task_queue_, compositor_task_queue_,
helper_.GetClock(), helper_.GetClock(),
...@@ -995,7 +998,7 @@ void MainThreadSchedulerImpl::SetRendererBackgrounded(bool backgrounded) { ...@@ -995,7 +998,7 @@ void MainThreadSchedulerImpl::SetRendererBackgrounded(bool backgrounded) {
internal::ProcessState::Get()->is_process_backgrounded = backgrounded; internal::ProcessState::Get()->is_process_backgrounded = backgrounded;
main_thread_only().background_status_changed_at = tick_clock()->NowTicks(); main_thread_only().background_status_changed_at = tick_clock()->NowTicks();
queueing_time_estimator_.OnRendererStateChanged( queueing_time_estimator_.OnRecordingStateChanged(
backgrounded, main_thread_only().background_status_changed_at); backgrounded, main_thread_only().background_status_changed_at);
UpdatePolicy(); UpdatePolicy();
......
...@@ -4,12 +4,11 @@ ...@@ -4,12 +4,11 @@
#include "third_party/blink/renderer/platform/scheduler/main_thread/queueing_time_estimator.h" #include "third_party/blink/renderer/platform/scheduler/main_thread/queueing_time_estimator.h"
#include <algorithm>
#include "third_party/blink/renderer/platform/scheduler/main_thread/frame_scheduler_impl.h" #include "third_party/blink/renderer/platform/scheduler/main_thread/frame_scheduler_impl.h"
#include "third_party/blink/renderer/platform/scheduler/public/frame_scheduler.h" #include "third_party/blink/renderer/platform/scheduler/public/frame_scheduler.h"
#include <algorithm>
#include <map>
namespace blink { namespace blink {
namespace scheduler { namespace scheduler {
...@@ -42,8 +41,8 @@ base::TimeDelta ExpectedQueueingTimeFromTask(base::TimeTicks task_start, ...@@ -42,8 +41,8 @@ base::TimeDelta ExpectedQueueingTimeFromTask(base::TimeTicks task_start,
DCHECK_LE(task_start, task_end); DCHECK_LE(task_start, task_end);
DCHECK_LE(task_start, step_end); DCHECK_LE(task_start, step_end);
DCHECK_LT(step_start, step_end); DCHECK_LT(step_start, step_end);
// Because we skip steps when the renderer is backgrounded, we may have gone // Because we skip steps when disabled, we may have gone into the future, and
// into the future, and in that case we ignore this task completely. // in that case we ignore this task completely.
if (task_end < step_start) if (task_end < step_start)
return base::TimeDelta(); return base::TimeDelta();
...@@ -67,10 +66,11 @@ base::TimeDelta ExpectedQueueingTimeFromTask(base::TimeTicks task_start, ...@@ -67,10 +66,11 @@ base::TimeDelta ExpectedQueueingTimeFromTask(base::TimeTicks task_start,
QueueingTimeEstimator::QueueingTimeEstimator(Client* client, QueueingTimeEstimator::QueueingTimeEstimator(Client* client,
base::TimeDelta window_duration, base::TimeDelta window_duration,
int steps_per_window) int steps_per_window,
bool start_disabled)
: client_(client), : client_(client),
window_step_width_(window_duration / steps_per_window), window_step_width_(window_duration / steps_per_window),
renderer_backgrounded_(kLaunchingProcessIsBackgrounded), disabled_(start_disabled),
calculator_(steps_per_window) { calculator_(steps_per_window) {
DCHECK_GE(steps_per_window, 1); DCHECK_GE(steps_per_window, 1);
} }
...@@ -91,13 +91,13 @@ void QueueingTimeEstimator::OnExecutionStopped(base::TimeTicks now) { ...@@ -91,13 +91,13 @@ void QueueingTimeEstimator::OnExecutionStopped(base::TimeTicks now) {
busy_period_start_time_ = base::TimeTicks(); busy_period_start_time_ = base::TimeTicks();
} }
void QueueingTimeEstimator::OnRendererStateChanged( void QueueingTimeEstimator::OnRecordingStateChanged(
bool backgrounded, bool disabled,
base::TimeTicks transition_time) { base::TimeTicks transition_time) {
DCHECK_NE(backgrounded, renderer_backgrounded_); DCHECK_NE(disabled, disabled_);
if (!busy_) if (!busy_)
AdvanceTime(transition_time); AdvanceTime(transition_time);
renderer_backgrounded_ = backgrounded; disabled_ = disabled;
} }
void QueueingTimeEstimator::AdvanceTime(base::TimeTicks current_time) { void QueueingTimeEstimator::AdvanceTime(base::TimeTicks current_time) {
...@@ -110,11 +110,10 @@ void QueueingTimeEstimator::AdvanceTime(base::TimeTicks current_time) { ...@@ -110,11 +110,10 @@ void QueueingTimeEstimator::AdvanceTime(base::TimeTicks current_time) {
} }
base::TimeTicks reference_time = base::TimeTicks reference_time =
busy_ ? busy_period_start_time_ : step_start_time_; busy_ ? busy_period_start_time_ : step_start_time_;
if (renderer_backgrounded_ || if (disabled_ || current_time - reference_time > kInvalidPeriodThreshold) {
current_time - reference_time > kInvalidPeriodThreshold) { // Skip steps when we're disabled, when a task took too long, or when we
// Skip steps when the renderer was backgrounded, when a task took too long, // remained idle for too long. May cause |step_start_time_| to go slightly
// or when we remained idle for too long. May cause |step_start_time_| to go // into the future.
// slightly into the future.
// TODO(npm): crbug.com/776013. Base skipping long tasks/idling on a signal // TODO(npm): crbug.com/776013. Base skipping long tasks/idling on a signal
// that we've been suspended. // that we've been suspended.
step_start_time_ = step_start_time_ =
......
...@@ -5,15 +5,14 @@ ...@@ -5,15 +5,14 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_MAIN_THREAD_QUEUEING_TIME_ESTIMATOR_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_MAIN_THREAD_QUEUEING_TIME_ESTIMATOR_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_MAIN_THREAD_QUEUEING_TIME_ESTIMATOR_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_MAIN_THREAD_QUEUEING_TIME_ESTIMATOR_H_
#include <array>
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/blink/public/common/page/launching_process_state.h"
#include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_metrics_helper.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_task_queue.h" #include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_task_queue.h"
#include "third_party/blink/renderer/platform/scheduler/public/frame_status.h"
#include <array>
#include <vector>
namespace blink { namespace blink {
namespace scheduler { namespace scheduler {
...@@ -108,12 +107,12 @@ class PLATFORM_EXPORT QueueingTimeEstimator { ...@@ -108,12 +107,12 @@ class PLATFORM_EXPORT QueueingTimeEstimator {
QueueingTimeEstimator(Client* client, QueueingTimeEstimator(Client* client,
base::TimeDelta window_duration, base::TimeDelta window_duration,
int steps_per_window); int steps_per_window,
bool start_disabled);
void OnExecutionStarted(base::TimeTicks now, MainThreadTaskQueue* queue); void OnExecutionStarted(base::TimeTicks now, MainThreadTaskQueue* queue);
void OnExecutionStopped(base::TimeTicks now); void OnExecutionStopped(base::TimeTicks now);
void OnRendererStateChanged(bool backgrounded, void OnRecordingStateChanged(bool disabled, base::TimeTicks transition_time);
base::TimeTicks transition_time);
private: private:
void AdvanceTime(base::TimeTicks current_time); void AdvanceTime(base::TimeTicks current_time);
...@@ -127,8 +126,8 @@ class PLATFORM_EXPORT QueueingTimeEstimator { ...@@ -127,8 +126,8 @@ class PLATFORM_EXPORT QueueingTimeEstimator {
bool busy_ = false; bool busy_ = false;
base::TimeTicks busy_period_start_time_; base::TimeTicks busy_period_start_time_;
// |renderer_backgrounded_| is the renderer's current status. // |disabled_| is true iff we want to ignore start/stop events.
bool renderer_backgrounded_; bool disabled_;
Calculator calculator_; Calculator calculator_;
DISALLOW_ASSIGN(QueueingTimeEstimator); DISALLOW_ASSIGN(QueueingTimeEstimator);
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#include "third_party/blink/renderer/platform/scheduler/main_thread/queueing_time_estimator.h" #include "third_party/blink/renderer/platform/scheduler/main_thread/queueing_time_estimator.h"
#include <memory>
#include <string>
#include <vector>
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -14,10 +18,6 @@ ...@@ -14,10 +18,6 @@
#include "third_party/blink/renderer/platform/scheduler/test/test_queueing_time_estimator_client.h" #include "third_party/blink/renderer/platform/scheduler/test/test_queueing_time_estimator_client.h"
#include "third_party/blink/renderer/platform/testing/histogram_tester.h" #include "third_party/blink/renderer/platform/testing/histogram_tester.h"
#include <map>
#include <string>
#include <vector>
namespace blink { namespace blink {
namespace scheduler { namespace scheduler {
...@@ -195,8 +195,8 @@ TEST_F(QueueingTimeEstimatorTest, IgnoreExtremelyLongTasks) { ...@@ -195,8 +195,8 @@ TEST_F(QueueingTimeEstimatorTest, IgnoreExtremelyLongTasks) {
fine_grained); fine_grained);
} }
// If we idle for too long, ignore idling time, even if the renderer is on the // If we idle for too long, ignore idling time, even if the estimator is
// foreground. Perhaps the user's machine went to sleep while we were idling. // enabled. Perhaps the user's machine went to sleep while we were idling.
TEST_F(QueueingTimeEstimatorTest, IgnoreExtremelyLongIdlePeriods) { TEST_F(QueueingTimeEstimatorTest, IgnoreExtremelyLongIdlePeriods) {
QueueingTimeEstimatorForTest estimator( QueueingTimeEstimatorForTest estimator(
&client, base::TimeDelta::FromSeconds(5), 1, time); &client, base::TimeDelta::FromSeconds(5), 1, time);
...@@ -405,9 +405,9 @@ TEST_F(QueueingTimeEstimatorTest, ...@@ -405,9 +405,9 @@ TEST_F(QueueingTimeEstimatorTest,
} }
// There are multiple windows, but some of the EQTs are not reported due to // There are multiple windows, but some of the EQTs are not reported due to
// backgrounded renderer. EQT(win1) = 0. EQT(win3) = (1500+500)/2 = 1000. // enabling/disabling. EQT(win1) = 0. EQT(win3) = (1500+500)/2 = 1000.
// EQT(win4) = 1/2*500/2 = 250. EQT(win7) = 1/5*200/2 = 20. // EQT(win4) = 1/2*500/2 = 250. EQT(win7) = 1/5*200/2 = 20.
TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithSingleStepPerWindow) { TEST_F(QueueingTimeEstimatorTest, DisabledEQTsWithSingleStepPerWindow) {
QueueingTimeEstimatorForTest estimator( QueueingTimeEstimatorForTest estimator(
&client, base::TimeDelta::FromSeconds(1), 1, time); &client, base::TimeDelta::FromSeconds(1), 1, time);
time += base::TimeDelta::FromMilliseconds(1000); time += base::TimeDelta::FromMilliseconds(1000);
...@@ -416,12 +416,12 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithSingleStepPerWindow) { ...@@ -416,12 +416,12 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithSingleStepPerWindow) {
time += base::TimeDelta::FromMilliseconds(1001); time += base::TimeDelta::FromMilliseconds(1001);
// Second window should not be reported. // Second window should not be reported.
estimator.OnRendererStateChanged(true, time); estimator.OnRecordingStateChanged(true, time);
estimator.OnExecutionStarted(time, nullptr); estimator.OnExecutionStarted(time, nullptr);
time += base::TimeDelta::FromMilliseconds(456); time += base::TimeDelta::FromMilliseconds(456);
estimator.OnExecutionStopped(time); estimator.OnExecutionStopped(time);
time += base::TimeDelta::FromMilliseconds(200); time += base::TimeDelta::FromMilliseconds(200);
estimator.OnRendererStateChanged(false, time); estimator.OnRecordingStateChanged(false, time);
time += base::TimeDelta::FromMilliseconds(343); time += base::TimeDelta::FromMilliseconds(343);
// Third, fourth windows should be reported // Third, fourth windows should be reported
...@@ -434,9 +434,9 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithSingleStepPerWindow) { ...@@ -434,9 +434,9 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithSingleStepPerWindow) {
estimator.OnExecutionStarted(time, nullptr); estimator.OnExecutionStarted(time, nullptr);
time += base::TimeDelta::FromMilliseconds(800); time += base::TimeDelta::FromMilliseconds(800);
estimator.OnExecutionStopped(time); estimator.OnExecutionStopped(time);
estimator.OnRendererStateChanged(true, time); estimator.OnRecordingStateChanged(true, time);
time += base::TimeDelta::FromMilliseconds(200); time += base::TimeDelta::FromMilliseconds(200);
estimator.OnRendererStateChanged(false, time); estimator.OnRecordingStateChanged(false, time);
estimator.OnExecutionStarted(time, nullptr); estimator.OnExecutionStarted(time, nullptr);
time += base::TimeDelta::FromMilliseconds(999); time += base::TimeDelta::FromMilliseconds(999);
...@@ -461,9 +461,9 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithSingleStepPerWindow) { ...@@ -461,9 +461,9 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithSingleStepPerWindow) {
fine_grained); fine_grained);
} }
// We only ignore steps that contain some part that is backgrounded. Thus a // We only ignore steps that contain some time span that is disabled. Thus a
// window could be made up of non-contiguous steps. The following are EQTs, with // window could be made up of non-contiguous steps. The following are EQTs,
// time deltas with respect to the end of the first, 0-time task: // with time deltas with respect to the end of the first, 0-time task:
// Win1: [0-1000]. EQT of step [0-1000]: 500/2*1/2 = 125. EQT(win1) = 125/5 = // Win1: [0-1000]. EQT of step [0-1000]: 500/2*1/2 = 125. EQT(win1) = 125/5 =
// 25. // 25.
// Win2: [0-1000],[2000-3000]. EQT of [2000-3000]: (1000+200)/2*4/5 = 480. // Win2: [0-1000],[2000-3000]. EQT of [2000-3000]: (1000+200)/2*4/5 = 480.
...@@ -480,7 +480,7 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithSingleStepPerWindow) { ...@@ -480,7 +480,7 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithSingleStepPerWindow) {
// EQT(win7) = (0+145+900+80+1680)/5 = 561. // EQT(win7) = (0+145+900+80+1680)/5 = 561.
// Win8: [12000-17000]. EQT of [16000-17000]: (1700+700)/2 = 1200. EQT(win8) = // Win8: [12000-17000]. EQT of [16000-17000]: (1700+700)/2 = 1200. EQT(win8) =
// (145+900+80+1680+1200)/5 = 801. // (145+900+80+1680+1200)/5 = 801.
TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithMutipleStepsPerWindow) { TEST_F(QueueingTimeEstimatorTest, DisabledEQTsWithMutipleStepsPerWindow) {
QueueingTimeEstimatorForTest estimator( QueueingTimeEstimatorForTest estimator(
&client, base::TimeDelta::FromSeconds(5), 5, time); &client, base::TimeDelta::FromSeconds(5), 5, time);
time += base::TimeDelta::FromMilliseconds(5000); time += base::TimeDelta::FromMilliseconds(5000);
...@@ -492,12 +492,12 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithMutipleStepsPerWindow) { ...@@ -492,12 +492,12 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithMutipleStepsPerWindow) {
time += base::TimeDelta::FromMilliseconds(500); time += base::TimeDelta::FromMilliseconds(500);
estimator.OnExecutionStopped(time); estimator.OnExecutionStopped(time);
estimator.OnRendererStateChanged(true, time); estimator.OnRecordingStateChanged(true, time);
// This task should be ignored. // This task should be ignored.
estimator.OnExecutionStarted(time, nullptr); estimator.OnExecutionStarted(time, nullptr);
time += base::TimeDelta::FromMilliseconds(800); time += base::TimeDelta::FromMilliseconds(800);
estimator.OnExecutionStopped(time); estimator.OnExecutionStopped(time);
estimator.OnRendererStateChanged(false, time); estimator.OnRecordingStateChanged(false, time);
time += base::TimeDelta::FromMilliseconds(400); time += base::TimeDelta::FromMilliseconds(400);
estimator.OnExecutionStarted(time, nullptr); estimator.OnExecutionStarted(time, nullptr);
...@@ -505,7 +505,7 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithMutipleStepsPerWindow) { ...@@ -505,7 +505,7 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithMutipleStepsPerWindow) {
estimator.OnExecutionStopped(time); estimator.OnExecutionStopped(time);
time += base::TimeDelta::FromMilliseconds(300); time += base::TimeDelta::FromMilliseconds(300);
estimator.OnRendererStateChanged(true, time); estimator.OnRecordingStateChanged(true, time);
time += base::TimeDelta::FromMilliseconds(2000); time += base::TimeDelta::FromMilliseconds(2000);
// These tasks should be ignored. // These tasks should be ignored.
estimator.OnExecutionStarted(time, nullptr); estimator.OnExecutionStarted(time, nullptr);
...@@ -514,7 +514,7 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithMutipleStepsPerWindow) { ...@@ -514,7 +514,7 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithMutipleStepsPerWindow) {
estimator.OnExecutionStarted(time, nullptr); estimator.OnExecutionStarted(time, nullptr);
time += base::TimeDelta::FromMilliseconds(3400); time += base::TimeDelta::FromMilliseconds(3400);
estimator.OnExecutionStopped(time); estimator.OnExecutionStopped(time);
estimator.OnRendererStateChanged(false, time); estimator.OnRecordingStateChanged(false, time);
time += base::TimeDelta::FromMilliseconds(2000); time += base::TimeDelta::FromMilliseconds(2000);
estimator.OnExecutionStarted(time, nullptr); estimator.OnExecutionStarted(time, nullptr);
...@@ -527,7 +527,7 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithMutipleStepsPerWindow) { ...@@ -527,7 +527,7 @@ TEST_F(QueueingTimeEstimatorTest, BackgroundedEQTsWithMutipleStepsPerWindow) {
estimator.OnExecutionStopped(time); estimator.OnExecutionStopped(time);
// Window with last step should not be reported. // Window with last step should not be reported.
estimator.OnRendererStateChanged(true, time); estimator.OnRecordingStateChanged(true, time);
time += base::TimeDelta::FromMilliseconds(1000); time += base::TimeDelta::FromMilliseconds(1000);
estimator.OnExecutionStarted(time, nullptr); estimator.OnExecutionStarted(time, nullptr);
estimator.OnExecutionStopped(time); estimator.OnExecutionStopped(time);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "third_party/blink/public/common/page/launching_process_state.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl.h" #include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl.h"
namespace blink { namespace blink {
...@@ -140,10 +141,13 @@ QueueingTimeEstimatorForTest::QueueingTimeEstimatorForTest( ...@@ -140,10 +141,13 @@ QueueingTimeEstimatorForTest::QueueingTimeEstimatorForTest(
base::TimeDelta window_duration, base::TimeDelta window_duration,
int steps_per_window, int steps_per_window,
base::TimeTicks time) base::TimeTicks time)
: QueueingTimeEstimator(client, window_duration, steps_per_window) { : QueueingTimeEstimator(client,
// If initial state is not foregrounded, foreground. window_duration,
steps_per_window,
kLaunchingProcessIsBackgrounded) {
// If initial state is disabled, enable the estimator.
if (kLaunchingProcessIsBackgrounded) { if (kLaunchingProcessIsBackgrounded) {
this->OnRendererStateChanged(false, time); this->OnRecordingStateChanged(false, time);
} }
} }
......
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