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

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

Issue 1898233002: Report expected task queueing time via UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Super rough alternative approach. Created 4 years, 6 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 2016 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/queueing_time_estimator.h"
6
7 #include "components/scheduler/renderer/coarse_duration_timer.h"
8
9 namespace scheduler {
10
11 namespace {
12
13 base::TimeDelta ExpectedQueueingTimeFromTask(base::TimeTicks task_start,
14 base::TimeTicks task_end,
15 base::TimeTicks window_start,
16 base::TimeTicks window_end) {
17 DCHECK(task_start <= task_end);
Lei Zhang 2016/06/08 01:05:27 DCHECK_LE() and friends are preferred, BTW. They w
tdresser 2016/06/08 14:25:05 Thanks, I'll clean this up if the overall approach
18 DCHECK(task_start <= window_end);
19 DCHECK(window_start < window_end);
20 DCHECK(task_end >= window_start);
21 base::TimeTicks task_in_window_start_time =
22 std::max(task_start, window_start);
23 base::TimeTicks task_in_window_end_time =
24 std::min(task_end, window_end);
25 DCHECK(task_in_window_end_time <= task_in_window_end_time);
26
27 double probability_of_this_task =
28 static_cast<double>((task_in_window_end_time - task_in_window_start_time)
29 .InMicroseconds()) /
30 (window_end - window_start).InMicroseconds();
31
32 base::TimeDelta expected_queueing_duration_within_task =
33 ((task_end - task_in_window_start_time) +
34 (task_end - task_in_window_end_time)) /
35 2;
36
37 return base::TimeDelta::FromMillisecondsD(
38 probability_of_this_task *
39 expected_queueing_duration_within_task.InMillisecondsF());
40 }
41
42 } // namespace
43
44 QueueingTimeEstimator::QueueingTimeEstimator(
45 QueueingTimeEstimator::Client* client,
46 CoarseDurationTimer* timer,
47 base::TimeDelta window_duration)
48 : client_(client),
49 timer_(timer),
50 outstanding_task_count_(0),
51 window_duration_(window_duration) {}
52
53 QueueingTimeEstimator::~QueueingTimeEstimator() {}
54
55 void QueueingTimeEstimator::WillProcessTask(
56 const base::PendingTask& pending_task) {
57 // Avoid measuring the duration in nested run loops.
58 if (++outstanding_task_count_ != 1)
59 return;
60
61 timer_->BeginInterval();
62 }
63
64 void QueueingTimeEstimator::DidProcessTask(
65 const base::PendingTask& pending_task) {
66 if (--outstanding_task_count_ != 0)
67 return;
68
69 base::TimeDelta duration = timer_->EndInterval();
70 if (duration.is_zero())
71 return;
72
73 base::TimeTicks task_end_time = timer_->most_recent_time();
74 base::TimeTicks task_start_time = task_end_time - duration;
75
76 // If this is the first task, set the window start time such that the window
77 // and the task end at the same time.
78 if (window_start_time_.is_null())
79 window_start_time_ = task_end_time - window_duration_;
80
81 bool start_past_window =
82 task_start_time > window_start_time_ + window_duration_;
83 bool end_past_window =
84 task_end_time > window_start_time_ + window_duration_;
85
86 while (end_past_window) {
87 if (!start_past_window) {
88 // Include the current task in this window.
89 current_expected_queueing_time_ += ExpectedQueueingTimeFromTask(
90 task_start_time, task_end_time, window_start_time_,
91 window_start_time_ + window_duration_);
92 }
93 client_->OnQueueingTimeForWindowEstimated(current_expected_queueing_time_);
94 window_start_time_ += window_duration_;
95 current_expected_queueing_time_ = base::TimeDelta();
96
97 start_past_window =
98 task_start_time > window_start_time_ + window_duration_;
99 end_past_window =
100 task_end_time > window_start_time_ + window_duration_;
101 }
102
103 current_expected_queueing_time_ += ExpectedQueueingTimeFromTask(
104 task_start_time, task_end_time, window_start_time_,
105 window_start_time_ + window_duration_);
106 }
107
108 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698