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"
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::TimeTicks
RenderingStatsInstrumentation::StartRecording() const {
41 if (record_rendering_stats_
) {
42 if (base::TimeTicks::IsThreadNowSupported())
43 return base::TimeTicks::ThreadNow();
44 return base::TimeTicks::Now();
46 return base::TimeTicks();
49 base::TimeDelta
RenderingStatsInstrumentation::EndRecording(
50 base::TimeTicks start_time
) const {
51 if (!start_time
.is_null()) {
52 if (base::TimeTicks::IsThreadNowSupported())
53 return base::TimeTicks::ThreadNow() - start_time
;
54 return base::TimeTicks::Now() - start_time
;
56 return base::TimeDelta();
59 void RenderingStatsInstrumentation::IncrementFrameCount(int64 count
) {
60 if (!record_rendering_stats_
)
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_
)
71 base::AutoLock
scoped_lock(lock_
);
72 impl_thread_rendering_stats_
.visible_content_area
+= area
;
75 void RenderingStatsInstrumentation::AddApproximatedVisibleContentArea(
77 if (!record_rendering_stats_
)
80 base::AutoLock
scoped_lock(lock_
);
81 impl_thread_rendering_stats_
.approximated_visible_content_area
+= area
;
84 void RenderingStatsInstrumentation::AddCheckerboardedVisibleContentArea(
86 if (!record_rendering_stats_
)
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_
)
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_
)
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_
)
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
);