Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: components/scheduler/renderer/idle_time_estimator.cc

Issue 2118903002: scheduler: Move the Blink scheduler into Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/scheduler/renderer/idle_time_estimator.h"
6
7 #include "base/time/default_tick_clock.h"
8
9 namespace scheduler {
10
11 IdleTimeEstimator::IdleTimeEstimator(
12 const scoped_refptr<TaskQueue>& compositor_task_runner,
13 base::TickClock* time_source,
14 int sample_count,
15 double estimation_percentile)
16 : compositor_task_runner_(compositor_task_runner),
17 per_frame_compositor_task_runtime_(sample_count),
18 time_source_(time_source),
19 estimation_percentile_(estimation_percentile),
20 nesting_level_(0),
21 did_commit_(false) {
22 compositor_task_runner_->AddTaskObserver(this);
23 }
24
25 IdleTimeEstimator::~IdleTimeEstimator() {
26 compositor_task_runner_->RemoveTaskObserver(this);
27 }
28
29 base::TimeDelta IdleTimeEstimator::GetExpectedIdleDuration(
30 base::TimeDelta compositor_frame_interval) const {
31 base::TimeDelta expected_compositor_task_runtime_ =
32 per_frame_compositor_task_runtime_.Percentile(estimation_percentile_);
33 return std::max(base::TimeDelta(), compositor_frame_interval -
34 expected_compositor_task_runtime_);
35 }
36
37 void IdleTimeEstimator::DidCommitFrameToCompositor() {
38 // This will run inside of a WillProcessTask / DidProcessTask pair, let
39 // DidProcessTask know a frame was comitted.
40 if (nesting_level_ == 1)
41 did_commit_ = true;
42 }
43
44 void IdleTimeEstimator::Clear() {
45 task_start_time_ = base::TimeTicks();
46 prev_commit_time_ = base::TimeTicks();
47 cumulative_compositor_runtime_ = base::TimeDelta();
48 per_frame_compositor_task_runtime_.Clear();
49 did_commit_ = false;
50 }
51
52 void IdleTimeEstimator::WillProcessTask(const base::PendingTask& pending_task) {
53 nesting_level_++;
54 if (nesting_level_ == 1)
55 task_start_time_ = time_source_->NowTicks();
56 }
57
58 void IdleTimeEstimator::DidProcessTask(const base::PendingTask& pending_task) {
59 nesting_level_--;
60 DCHECK_GE(nesting_level_, 0);
61 if (nesting_level_ != 0)
62 return;
63
64 cumulative_compositor_runtime_ += time_source_->NowTicks() - task_start_time_;
65
66 if (did_commit_) {
67 per_frame_compositor_task_runtime_.InsertSample(
68 cumulative_compositor_runtime_);
69 cumulative_compositor_runtime_ = base::TimeDelta();
70 did_commit_ = false;
71 }
72 }
73
74 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/renderer/idle_time_estimator.h ('k') | components/scheduler/renderer/idle_time_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698