Fix IPC fuzzer build.
[chromium-blink-merge.git] / cc / debug / rendering_stats_instrumentation.cc
blob01499d26ae3f043367190ead0675c90cef578042
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::MainThreadRenderingStats
22 RenderingStatsInstrumentation::main_thread_rendering_stats() {
23 base::AutoLock scoped_lock(lock_);
24 return main_thread_rendering_stats_;
27 RenderingStats::ImplThreadRenderingStats
28 RenderingStatsInstrumentation::impl_thread_rendering_stats() {
29 base::AutoLock scoped_lock(lock_);
30 return impl_thread_rendering_stats_;
33 RenderingStats RenderingStatsInstrumentation::GetRenderingStats() {
34 base::AutoLock scoped_lock(lock_);
35 RenderingStats rendering_stats;
36 rendering_stats.main_stats = main_thread_rendering_stats_accu_;
37 rendering_stats.main_stats.Add(main_thread_rendering_stats_);
38 rendering_stats.impl_stats = impl_thread_rendering_stats_accu_;
39 rendering_stats.impl_stats.Add(impl_thread_rendering_stats_);
40 return rendering_stats;
43 void RenderingStatsInstrumentation::AccumulateAndClearMainThreadStats() {
44 base::AutoLock scoped_lock(lock_);
45 main_thread_rendering_stats_accu_.Add(main_thread_rendering_stats_);
46 main_thread_rendering_stats_ = RenderingStats::MainThreadRenderingStats();
49 void RenderingStatsInstrumentation::AccumulateAndClearImplThreadStats() {
50 base::AutoLock scoped_lock(lock_);
51 impl_thread_rendering_stats_accu_.Add(impl_thread_rendering_stats_);
52 impl_thread_rendering_stats_ = RenderingStats::ImplThreadRenderingStats();
55 base::TimeTicks RenderingStatsInstrumentation::StartRecording() const {
56 if (record_rendering_stats_) {
57 if (base::TimeTicks::IsThreadNowSupported())
58 return base::TimeTicks::ThreadNow();
59 return base::TimeTicks::HighResNow();
61 return base::TimeTicks();
64 base::TimeDelta RenderingStatsInstrumentation::EndRecording(
65 base::TimeTicks start_time) const {
66 if (!start_time.is_null()) {
67 if (base::TimeTicks::IsThreadNowSupported())
68 return base::TimeTicks::ThreadNow() - start_time;
69 return base::TimeTicks::HighResNow() - start_time;
71 return base::TimeDelta();
74 void RenderingStatsInstrumentation::IncrementFrameCount(int64 count,
75 bool main_thread) {
76 if (!record_rendering_stats_)
77 return;
79 base::AutoLock scoped_lock(lock_);
80 if (main_thread)
81 main_thread_rendering_stats_.frame_count += count;
82 else
83 impl_thread_rendering_stats_.frame_count += count;
86 void RenderingStatsInstrumentation::AddPaint(base::TimeDelta duration,
87 int64 pixels) {
88 if (!record_rendering_stats_)
89 return;
91 base::AutoLock scoped_lock(lock_);
92 main_thread_rendering_stats_.paint_time += duration;
93 main_thread_rendering_stats_.painted_pixel_count += pixels;
96 void RenderingStatsInstrumentation::AddRecord(base::TimeDelta duration,
97 int64 pixels) {
98 if (!record_rendering_stats_)
99 return;
101 base::AutoLock scoped_lock(lock_);
102 main_thread_rendering_stats_.record_time += duration;
103 main_thread_rendering_stats_.recorded_pixel_count += pixels;
106 void RenderingStatsInstrumentation::AddRaster(base::TimeDelta duration,
107 int64 pixels) {
108 if (!record_rendering_stats_)
109 return;
111 base::AutoLock scoped_lock(lock_);
112 impl_thread_rendering_stats_.rasterize_time += duration;
113 impl_thread_rendering_stats_.rasterized_pixel_count += pixels;
116 void RenderingStatsInstrumentation::AddAnalysis(base::TimeDelta duration,
117 int64 pixels) {
118 if (!record_rendering_stats_)
119 return;
121 base::AutoLock scoped_lock(lock_);
122 impl_thread_rendering_stats_.analysis_time += duration;
125 void RenderingStatsInstrumentation::AddVisibleContentArea(int64 area) {
126 if (!record_rendering_stats_)
127 return;
129 base::AutoLock scoped_lock(lock_);
130 impl_thread_rendering_stats_.visible_content_area += area;
133 void RenderingStatsInstrumentation::AddApproximatedVisibleContentArea(
134 int64 area) {
135 if (!record_rendering_stats_)
136 return;
138 base::AutoLock scoped_lock(lock_);
139 impl_thread_rendering_stats_.approximated_visible_content_area += area;
142 void RenderingStatsInstrumentation::AddDrawDuration(
143 base::TimeDelta draw_duration,
144 base::TimeDelta draw_duration_estimate) {
145 if (!record_rendering_stats_)
146 return;
148 base::AutoLock scoped_lock(lock_);
149 impl_thread_rendering_stats_.draw_duration.Append(draw_duration);
150 impl_thread_rendering_stats_.draw_duration_estimate.Append(
151 draw_duration_estimate);
154 void RenderingStatsInstrumentation::AddBeginMainFrameToCommitDuration(
155 base::TimeDelta begin_main_frame_to_commit_duration,
156 base::TimeDelta begin_main_frame_to_commit_duration_estimate) {
157 if (!record_rendering_stats_)
158 return;
160 base::AutoLock scoped_lock(lock_);
161 impl_thread_rendering_stats_.begin_main_frame_to_commit_duration.Append(
162 begin_main_frame_to_commit_duration);
163 impl_thread_rendering_stats_.begin_main_frame_to_commit_duration_estimate
164 .Append(begin_main_frame_to_commit_duration_estimate);
167 void RenderingStatsInstrumentation::AddCommitToActivateDuration(
168 base::TimeDelta commit_to_activate_duration,
169 base::TimeDelta commit_to_activate_duration_estimate) {
170 if (!record_rendering_stats_)
171 return;
173 base::AutoLock scoped_lock(lock_);
174 impl_thread_rendering_stats_.commit_to_activate_duration.Append(
175 commit_to_activate_duration);
176 impl_thread_rendering_stats_.commit_to_activate_duration_estimate.Append(
177 commit_to_activate_duration_estimate);
180 } // namespace cc