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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/renderer/wake_up_budget_pool.cc

Issue 2778123003: [scheduler] Add WakeupBudgetPool. (Closed)
Patch Set: Addressed comments Created 3 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/platform/scheduler/renderer/wake_up_budget_pool.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 "platform/scheduler/renderer/wake_up_budget_pool.h"
6
7 #include <cstdint>
8
9 #include "base/format_macros.h"
10 #include "base/strings/stringprintf.h"
11 #include "platform/scheduler/renderer/task_queue_throttler.h"
12
13 namespace blink {
14 namespace scheduler {
15
16 namespace {
17
18 std::string PointerToId(void* pointer) {
19 return base::StringPrintf(
20 "0x%" PRIx64,
21 static_cast<uint64_t>(reinterpret_cast<uintptr_t>(pointer)));
22 }
23
24 } // namespace
25
26 WakeUpBudgetPool::WakeUpBudgetPool(const char* name,
27 BudgetPoolController* budget_pool_controller,
28 base::TimeTicks now)
29 : BudgetPool(name, budget_pool_controller), wakeups_per_second_(1) {}
30
31 WakeUpBudgetPool::~WakeUpBudgetPool() {}
32
33 QueueBlockType WakeUpBudgetPool::GetBlockType() const {
34 return QueueBlockType::kNewTasksOnly;
35 }
36
37 void WakeUpBudgetPool::SetWakeUpRate(double wakeups_per_second) {
38 wakeups_per_second_ = wakeups_per_second;
39 }
40
41 void WakeUpBudgetPool::SetWakeUpDuration(base::TimeDelta duration) {
42 wakeup_duration_ = duration;
43 }
44
45 void WakeUpBudgetPool::RecordTaskRunTime(TaskQueue* queue,
46 base::TimeTicks start_time,
47 base::TimeTicks end_time) {
48 budget_pool_controller_->UpdateQueueThrottlingState(end_time, queue);
49 }
50
51 base::Optional<base::TimeTicks> WakeUpBudgetPool::NextWakeUp() const {
52 if (!last_wakeup_)
53 return base::nullopt;
54 // Subtract 1 microsecond to work with time alignment in task queue throttler.
55 // This is needed due to alignment mechanism in task queue throttler --
56 // whole seconds need to be aligned to the next second to deal with immediate
57 // tasks correctly. By subtracting 1 microsecond we ensure that next wakeup
58 // gets aligned to a correct time.
59 return last_wakeup_.value() +
60 base::TimeDelta::FromSeconds(1 / wakeups_per_second_) -
61 base::TimeDelta::FromMicroseconds(1);
62 }
63
64 bool WakeUpBudgetPool::CanRunTasksAt(base::TimeTicks moment,
65 bool is_wake_up) const {
66 if (!last_wakeup_)
67 return false;
68 // |is_wake_up| flag means that we're in the beginning of the wake-up and
69 // |OnWakeUp| has just been called. This is needed to support backwards
70 // compability with old throttling mechanism (when |wakeup_duration| is zero)
71 // and allow only one task to run.
Sami 2017/05/04 13:25:46 We're not allowing just one task to run, but all t
72 if (last_wakeup_ == moment && is_wake_up)
73 return true;
74 return moment < last_wakeup_.value() + wakeup_duration_;
75 }
76
77 base::TimeTicks WakeUpBudgetPool::GetNextAllowedRunTime(
78 base::TimeTicks desired_run_time) const {
79 if (!last_wakeup_)
80 return desired_run_time;
81 if (desired_run_time < last_wakeup_.value() + wakeup_duration_)
82 return desired_run_time;
83 return std::max(desired_run_time, NextWakeUp().value());
84 }
85
86 void WakeUpBudgetPool::OnQueueNextWakeUpChanged(
87 TaskQueue* queue,
88 base::TimeTicks now,
89 base::TimeTicks desired_run_time) {
90 budget_pool_controller_->UpdateQueueThrottlingState(now, queue);
91 }
92
93 void WakeUpBudgetPool::OnWakeUp(base::TimeTicks now) {
94 last_wakeup_ = now;
95 }
96
97 void WakeUpBudgetPool::AsValueInto(base::trace_event::TracedValue* state,
98 base::TimeTicks now) const {
99 state->BeginDictionary(name_);
100
101 state->SetString("name", name_);
102 state->SetDouble("wakeups_per_second_rate", wakeups_per_second_);
103 state->SetDouble("wakeup_duration_in_seconds", wakeup_duration_.InSecondsF());
104 if (last_wakeup_) {
105 state->SetDouble("last_wakeup_seconds_ago",
106 (now - last_wakeup_.value()).InSecondsF());
107 }
108 state->SetBoolean("is_enabled", is_enabled_);
109
110 state->BeginArray("task_queues");
111 for (TaskQueue* queue : associated_task_queues_) {
112 state->AppendString(PointerToId(queue));
113 }
114 state->EndArray();
115
116 state->EndDictionary();
117 }
118
119 } // namespace scheduler
120 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/scheduler/renderer/wake_up_budget_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698