summaryrefslogtreecommitdiffstats
path: root/cc/trees/proxy_timing_history.cc
blob: 9020ad51ef1d51e69efd4da7739eb7636e069298 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/trees/proxy_timing_history.h"

#include "base/metrics/histogram.h"

const size_t kDurationHistorySize = 60;
const double kCommitAndActivationDurationEstimationPercentile = 50.0;
const double kDrawDurationEstimationPercentile = 100.0;
const int kDrawDurationEstimatePaddingInMicroseconds = 0;

namespace cc {

ProxyTimingHistory::ProxyTimingHistory(
    RenderingStatsInstrumentation* rendering_stats_instrumentation)
    : draw_duration_history_(kDurationHistorySize),
      begin_main_frame_to_commit_duration_history_(kDurationHistorySize),
      commit_to_activate_duration_history_(kDurationHistorySize),
      rendering_stats_instrumentation_(rendering_stats_instrumentation) {
}

ProxyTimingHistory::~ProxyTimingHistory() {}

base::TimeDelta ProxyTimingHistory::DrawDurationEstimate() const {
  base::TimeDelta historical_estimate =
      draw_duration_history_.Percentile(kDrawDurationEstimationPercentile);
  base::TimeDelta padding = base::TimeDelta::FromMicroseconds(
      kDrawDurationEstimatePaddingInMicroseconds);
  return historical_estimate + padding;
}

base::TimeDelta ProxyTimingHistory::BeginMainFrameToCommitDurationEstimate()
    const {
  return begin_main_frame_to_commit_duration_history_.Percentile(
      kCommitAndActivationDurationEstimationPercentile);
}

base::TimeDelta ProxyTimingHistory::CommitToActivateDurationEstimate() const {
  return commit_to_activate_duration_history_.Percentile(
      kCommitAndActivationDurationEstimationPercentile);
}

void ProxyTimingHistory::DidBeginMainFrame() {
  begin_main_frame_sent_time_ = base::TimeTicks::HighResNow();
}

void ProxyTimingHistory::DidCommit() {
  commit_complete_time_ = base::TimeTicks::HighResNow();
  base::TimeDelta begin_main_frame_to_commit_duration =
      commit_complete_time_ - begin_main_frame_sent_time_;

  // Before adding the new data point to the timing history, see what we would
  // have predicted for this frame. This allows us to keep track of the accuracy
  // of our predictions.
  rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration(
      begin_main_frame_to_commit_duration,
      BeginMainFrameToCommitDurationEstimate());

  begin_main_frame_to_commit_duration_history_.InsertSample(
      begin_main_frame_to_commit_duration);
}

void ProxyTimingHistory::DidActivateSyncTree() {
  base::TimeDelta commit_to_activate_duration =
      base::TimeTicks::HighResNow() - commit_complete_time_;

  // Before adding the new data point to the timing history, see what we would
  // have predicted for this frame. This allows us to keep track of the accuracy
  // of our predictions.
  rendering_stats_instrumentation_->AddCommitToActivateDuration(
      commit_to_activate_duration, CommitToActivateDurationEstimate());

  commit_to_activate_duration_history_.InsertSample(
      commit_to_activate_duration);
}

void ProxyTimingHistory::DidStartDrawing() {
  start_draw_time_ = base::TimeTicks::HighResNow();
}

void ProxyTimingHistory::DidFinishDrawing() {
  base::TimeDelta draw_duration =
      base::TimeTicks::HighResNow() - start_draw_time_;

  // Before adding the new data point to the timing history, see what we would
  // have predicted for this frame. This allows us to keep track of the accuracy
  // of our predictions.
  base::TimeDelta draw_duration_estimate = DrawDurationEstimate();
  rendering_stats_instrumentation_->AddDrawDuration(draw_duration,
                                                    draw_duration_estimate);

  AddDrawDurationUMA(draw_duration, draw_duration_estimate);

  draw_duration_history_.InsertSample(draw_duration);
}

void ProxyTimingHistory::AddDrawDurationUMA(
    base::TimeDelta draw_duration,
    base::TimeDelta draw_duration_estimate) {
  base::TimeDelta draw_duration_overestimate;
  base::TimeDelta draw_duration_underestimate;
  if (draw_duration > draw_duration_estimate)
    draw_duration_underestimate = draw_duration - draw_duration_estimate;
  else
    draw_duration_overestimate = draw_duration_estimate - draw_duration;
  UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration",
                             draw_duration,
                             base::TimeDelta::FromMilliseconds(1),
                             base::TimeDelta::FromMilliseconds(100),
                             50);
  UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate",
                             draw_duration_underestimate,
                             base::TimeDelta::FromMilliseconds(1),
                             base::TimeDelta::FromMilliseconds(100),
                             50);
  UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate",
                             draw_duration_overestimate,
                             base::TimeDelta::FromMilliseconds(1),
                             base::TimeDelta::FromMilliseconds(100),
                             50);
}

}  // namespace cc