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

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

Issue 1424053002: Adds a flag to support "Virtual Time" to the blink scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 1 month 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
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 #include "components/scheduler/renderer/idle_time_estimator.h" 5 #include "components/scheduler/renderer/idle_time_estimator.h"
6 6
7 #include "base/time/default_tick_clock.h" 7 #include "base/time/default_tick_clock.h"
8 8
9 namespace scheduler { 9 namespace scheduler {
10 10
11 IdleTimeEstimator::IdleTimeEstimator( 11 IdleTimeEstimator::IdleTimeEstimator(
12 const scoped_refptr<TaskQueue>& compositor_task_runner, 12 const scoped_refptr<TaskQueue>& compositor_task_runner,
13 base::TickClock* time_source,
13 int sample_count, 14 int sample_count,
14 double estimation_percentile) 15 double estimation_percentile)
15 : compositor_task_runner_(compositor_task_runner), 16 : compositor_task_runner_(compositor_task_runner),
16 per_frame_compositor_task_runtime_(sample_count), 17 per_frame_compositor_task_runtime_(sample_count),
17 time_source_(new base::DefaultTickClock), 18 time_source_(time_source),
18 estimation_percentile_(estimation_percentile), 19 estimation_percentile_(estimation_percentile),
19 nesting_level_(0), 20 nesting_level_(0),
20 did_commit_(false) { 21 did_commit_(false) {
21 compositor_task_runner_->AddTaskObserver(this); 22 compositor_task_runner_->AddTaskObserver(this);
22 } 23 }
23 24
24 IdleTimeEstimator::~IdleTimeEstimator() { 25 IdleTimeEstimator::~IdleTimeEstimator() {
25 compositor_task_runner_->RemoveTaskObserver(this); 26 compositor_task_runner_->RemoveTaskObserver(this);
26 } 27 }
27 28
(...skipping 13 matching lines...) Expand all
41 } 42 }
42 43
43 void IdleTimeEstimator::Clear() { 44 void IdleTimeEstimator::Clear() {
44 task_start_time_ = base::TimeTicks(); 45 task_start_time_ = base::TimeTicks();
45 prev_commit_time_ = base::TimeTicks(); 46 prev_commit_time_ = base::TimeTicks();
46 cumulative_compositor_runtime_ = base::TimeDelta(); 47 cumulative_compositor_runtime_ = base::TimeDelta();
47 per_frame_compositor_task_runtime_.Clear(); 48 per_frame_compositor_task_runtime_.Clear();
48 did_commit_ = false; 49 did_commit_ = false;
49 } 50 }
50 51
51 void IdleTimeEstimator::SetTimeSourceForTesting(
52 scoped_ptr<base::TickClock> time_source) {
53 time_source_ = time_source.Pass();
54 }
55
56 void IdleTimeEstimator::WillProcessTask(const base::PendingTask& pending_task) { 52 void IdleTimeEstimator::WillProcessTask(const base::PendingTask& pending_task) {
57 nesting_level_++; 53 nesting_level_++;
58 if (nesting_level_ == 1) 54 if (nesting_level_ == 1)
59 task_start_time_ = time_source_->NowTicks(); 55 task_start_time_ = time_source_->NowTicks();
60 } 56 }
61 57
62 void IdleTimeEstimator::DidProcessTask(const base::PendingTask& pending_task) { 58 void IdleTimeEstimator::DidProcessTask(const base::PendingTask& pending_task) {
63 nesting_level_--; 59 nesting_level_--;
64 DCHECK_GE(nesting_level_, 0); 60 DCHECK_GE(nesting_level_, 0);
65 if (nesting_level_ != 0) 61 if (nesting_level_ != 0)
66 return; 62 return;
67 63
68 cumulative_compositor_runtime_ += time_source_->NowTicks() - task_start_time_; 64 cumulative_compositor_runtime_ += time_source_->NowTicks() - task_start_time_;
69 65
70 if (did_commit_) { 66 if (did_commit_) {
71 per_frame_compositor_task_runtime_.InsertSample( 67 per_frame_compositor_task_runtime_.InsertSample(
72 cumulative_compositor_runtime_); 68 cumulative_compositor_runtime_);
73 cumulative_compositor_runtime_ = base::TimeDelta(); 69 cumulative_compositor_runtime_ = base::TimeDelta();
74 did_commit_ = false; 70 did_commit_ = false;
75 } 71 }
76 } 72 }
77 73
78 } // namespace scheduler 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