Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / cc / debug / rendering_stats_instrumentation.cc
blob315743b8ffc295bbc9e9b2ddb271803a38e69dec
1 // Copyright 2013 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/debug/rendering_stats_instrumentation.h"
7 namespace cc {
9 // static
10 scoped_ptr<RenderingStatsInstrumentation>
11 RenderingStatsInstrumentation::Create() {
12 return make_scoped_ptr(new RenderingStatsInstrumentation());
15 RenderingStatsInstrumentation::RenderingStatsInstrumentation()
16 : record_rendering_stats_(false) {
19 RenderingStatsInstrumentation::~RenderingStatsInstrumentation() {}
21 RenderingStats RenderingStatsInstrumentation::impl_thread_rendering_stats() {
22 base::AutoLock scoped_lock(lock_);
23 return impl_thread_rendering_stats_;
26 RenderingStats RenderingStatsInstrumentation::GetRenderingStats() {
27 base::AutoLock scoped_lock(lock_);
28 RenderingStats rendering_stats;
29 rendering_stats = impl_thread_rendering_stats_accu_;
30 rendering_stats.Add(impl_thread_rendering_stats_);
31 return rendering_stats;
34 void RenderingStatsInstrumentation::AccumulateAndClearImplThreadStats() {
35 base::AutoLock scoped_lock(lock_);
36 impl_thread_rendering_stats_accu_.Add(impl_thread_rendering_stats_);
37 impl_thread_rendering_stats_ = RenderingStats();
40 base::TimeDelta RenderingStatsInstrumentation::StartRecording() const {
41 if (record_rendering_stats_) {
42 if (base::ThreadTicks::IsSupported())
43 return base::ThreadTicks::Now() - base::ThreadTicks();
44 return base::TimeTicks::Now() - base::TimeTicks();
46 return base::TimeDelta();
49 base::TimeDelta RenderingStatsInstrumentation::EndRecording(
50 base::TimeDelta start_time) const {
51 if (start_time != base::TimeDelta()) {
52 if (base::ThreadTicks::IsSupported())
53 return (base::ThreadTicks::Now() - base::ThreadTicks()) - start_time;
54 return (base::TimeTicks::Now() - base::TimeTicks()) - start_time;
56 return base::TimeDelta();
59 void RenderingStatsInstrumentation::IncrementFrameCount(int64 count) {
60 if (!record_rendering_stats_)
61 return;
63 base::AutoLock scoped_lock(lock_);
64 impl_thread_rendering_stats_.frame_count += count;
67 void RenderingStatsInstrumentation::AddVisibleContentArea(int64 area) {
68 if (!record_rendering_stats_)
69 return;
71 base::AutoLock scoped_lock(lock_);
72 impl_thread_rendering_stats_.visible_content_area += area;
75 void RenderingStatsInstrumentation::AddApproximatedVisibleContentArea(
76 int64 area) {
77 if (!record_rendering_stats_)
78 return;
80 base::AutoLock scoped_lock(lock_);
81 impl_thread_rendering_stats_.approximated_visible_content_area += area;
84 void RenderingStatsInstrumentation::AddCheckerboardedVisibleContentArea(
85 int64 area) {
86 if (!record_rendering_stats_)
87 return;
89 base::AutoLock scoped_lock(lock_);
90 impl_thread_rendering_stats_.checkerboarded_visible_content_area += area;
93 void RenderingStatsInstrumentation::AddDrawDuration(
94 base::TimeDelta draw_duration,
95 base::TimeDelta draw_duration_estimate) {
96 if (!record_rendering_stats_)
97 return;
99 base::AutoLock scoped_lock(lock_);
100 impl_thread_rendering_stats_.draw_duration.Append(draw_duration);
101 impl_thread_rendering_stats_.draw_duration_estimate.Append(
102 draw_duration_estimate);
105 void RenderingStatsInstrumentation::AddBeginMainFrameToCommitDuration(
106 base::TimeDelta begin_main_frame_to_commit_duration,
107 base::TimeDelta begin_main_frame_to_commit_duration_estimate) {
108 if (!record_rendering_stats_)
109 return;
111 base::AutoLock scoped_lock(lock_);
112 impl_thread_rendering_stats_.begin_main_frame_to_commit_duration.Append(
113 begin_main_frame_to_commit_duration);
114 impl_thread_rendering_stats_.begin_main_frame_to_commit_duration_estimate
115 .Append(begin_main_frame_to_commit_duration_estimate);
118 void RenderingStatsInstrumentation::AddCommitToActivateDuration(
119 base::TimeDelta commit_to_activate_duration,
120 base::TimeDelta commit_to_activate_duration_estimate) {
121 if (!record_rendering_stats_)
122 return;
124 base::AutoLock scoped_lock(lock_);
125 impl_thread_rendering_stats_.commit_to_activate_duration.Append(
126 commit_to_activate_duration);
127 impl_thread_rendering_stats_.commit_to_activate_duration_estimate.Append(
128 commit_to_activate_duration_estimate);
131 } // namespace cc