Simplify web_view.js
[chromium-blink-merge.git] / cc / trees / proxy_timing_history.cc
blob9020ad51ef1d51e69efd4da7739eb7636e069298
1 // Copyright 2014 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.
5 #include "cc/trees/proxy_timing_history.h"
7 #include "base/metrics/histogram.h"
9 const size_t kDurationHistorySize = 60;
10 const double kCommitAndActivationDurationEstimationPercentile = 50.0;
11 const double kDrawDurationEstimationPercentile = 100.0;
12 const int kDrawDurationEstimatePaddingInMicroseconds = 0;
14 namespace cc {
16 ProxyTimingHistory::ProxyTimingHistory(
17 RenderingStatsInstrumentation* rendering_stats_instrumentation)
18 : draw_duration_history_(kDurationHistorySize),
19 begin_main_frame_to_commit_duration_history_(kDurationHistorySize),
20 commit_to_activate_duration_history_(kDurationHistorySize),
21 rendering_stats_instrumentation_(rendering_stats_instrumentation) {
24 ProxyTimingHistory::~ProxyTimingHistory() {}
26 base::TimeDelta ProxyTimingHistory::DrawDurationEstimate() const {
27 base::TimeDelta historical_estimate =
28 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile);
29 base::TimeDelta padding = base::TimeDelta::FromMicroseconds(
30 kDrawDurationEstimatePaddingInMicroseconds);
31 return historical_estimate + padding;
34 base::TimeDelta ProxyTimingHistory::BeginMainFrameToCommitDurationEstimate()
35 const {
36 return begin_main_frame_to_commit_duration_history_.Percentile(
37 kCommitAndActivationDurationEstimationPercentile);
40 base::TimeDelta ProxyTimingHistory::CommitToActivateDurationEstimate() const {
41 return commit_to_activate_duration_history_.Percentile(
42 kCommitAndActivationDurationEstimationPercentile);
45 void ProxyTimingHistory::DidBeginMainFrame() {
46 begin_main_frame_sent_time_ = base::TimeTicks::HighResNow();
49 void ProxyTimingHistory::DidCommit() {
50 commit_complete_time_ = base::TimeTicks::HighResNow();
51 base::TimeDelta begin_main_frame_to_commit_duration =
52 commit_complete_time_ - begin_main_frame_sent_time_;
54 // Before adding the new data point to the timing history, see what we would
55 // have predicted for this frame. This allows us to keep track of the accuracy
56 // of our predictions.
57 rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration(
58 begin_main_frame_to_commit_duration,
59 BeginMainFrameToCommitDurationEstimate());
61 begin_main_frame_to_commit_duration_history_.InsertSample(
62 begin_main_frame_to_commit_duration);
65 void ProxyTimingHistory::DidActivateSyncTree() {
66 base::TimeDelta commit_to_activate_duration =
67 base::TimeTicks::HighResNow() - commit_complete_time_;
69 // Before adding the new data point to the timing history, see what we would
70 // have predicted for this frame. This allows us to keep track of the accuracy
71 // of our predictions.
72 rendering_stats_instrumentation_->AddCommitToActivateDuration(
73 commit_to_activate_duration, CommitToActivateDurationEstimate());
75 commit_to_activate_duration_history_.InsertSample(
76 commit_to_activate_duration);
79 void ProxyTimingHistory::DidStartDrawing() {
80 start_draw_time_ = base::TimeTicks::HighResNow();
83 void ProxyTimingHistory::DidFinishDrawing() {
84 base::TimeDelta draw_duration =
85 base::TimeTicks::HighResNow() - start_draw_time_;
87 // Before adding the new data point to the timing history, see what we would
88 // have predicted for this frame. This allows us to keep track of the accuracy
89 // of our predictions.
90 base::TimeDelta draw_duration_estimate = DrawDurationEstimate();
91 rendering_stats_instrumentation_->AddDrawDuration(draw_duration,
92 draw_duration_estimate);
94 AddDrawDurationUMA(draw_duration, draw_duration_estimate);
96 draw_duration_history_.InsertSample(draw_duration);
99 void ProxyTimingHistory::AddDrawDurationUMA(
100 base::TimeDelta draw_duration,
101 base::TimeDelta draw_duration_estimate) {
102 base::TimeDelta draw_duration_overestimate;
103 base::TimeDelta draw_duration_underestimate;
104 if (draw_duration > draw_duration_estimate)
105 draw_duration_underestimate = draw_duration - draw_duration_estimate;
106 else
107 draw_duration_overestimate = draw_duration_estimate - draw_duration;
108 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration",
109 draw_duration,
110 base::TimeDelta::FromMilliseconds(1),
111 base::TimeDelta::FromMilliseconds(100),
112 50);
113 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate",
114 draw_duration_underestimate,
115 base::TimeDelta::FromMilliseconds(1),
116 base::TimeDelta::FromMilliseconds(100),
117 50);
118 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate",
119 draw_duration_overestimate,
120 base::TimeDelta::FromMilliseconds(1),
121 base::TimeDelta::FromMilliseconds(100),
122 50);
125 } // namespace cc