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.
4
5 #include "cc/debug/rendering_stats_instrumentation.h"
6
7 namespace cc {
8
9 // static
10 scoped_ptr<RenderingStatsInstrumentation>
Create()11 RenderingStatsInstrumentation::Create() {
12 return make_scoped_ptr(new RenderingStatsInstrumentation());
13 }
14
RenderingStatsInstrumentation()15 RenderingStatsInstrumentation::RenderingStatsInstrumentation()
16 : record_rendering_stats_(false) {
17 }
18
~RenderingStatsInstrumentation()19 RenderingStatsInstrumentation::~RenderingStatsInstrumentation() {}
20
GetRenderingStats()21 RenderingStats RenderingStatsInstrumentation::GetRenderingStats() {
22 base::AutoLock scoped_lock(lock_);
23 RenderingStats rendering_stats;
24 rendering_stats.main_stats = main_stats_accu_;
25 rendering_stats.main_stats.Add(main_stats_);
26 rendering_stats.impl_stats = impl_stats_accu_;
27 rendering_stats.impl_stats.Add(impl_stats_);
28 return rendering_stats;
29 }
30
AccumulateAndClearMainThreadStats()31 void RenderingStatsInstrumentation::AccumulateAndClearMainThreadStats() {
32 main_stats_accu_.Add(main_stats_);
33 main_stats_ = MainThreadRenderingStats();
34 }
35
AccumulateAndClearImplThreadStats()36 void RenderingStatsInstrumentation::AccumulateAndClearImplThreadStats() {
37 impl_stats_accu_.Add(impl_stats_);
38 impl_stats_ = ImplThreadRenderingStats();
39 }
40
StartRecording() const41 base::TimeTicks RenderingStatsInstrumentation::StartRecording() const {
42 if (record_rendering_stats_) {
43 if (base::TimeTicks::IsThreadNowSupported())
44 return base::TimeTicks::ThreadNow();
45 return base::TimeTicks::HighResNow();
46 }
47 return base::TimeTicks();
48 }
49
EndRecording(base::TimeTicks start_time) const50 base::TimeDelta RenderingStatsInstrumentation::EndRecording(
51 base::TimeTicks start_time) const {
52 if (!start_time.is_null()) {
53 if (base::TimeTicks::IsThreadNowSupported())
54 return base::TimeTicks::ThreadNow() - start_time;
55 return base::TimeTicks::HighResNow() - start_time;
56 }
57 return base::TimeDelta();
58 }
59
IncrementFrameCount(int64 count,bool main_thread)60 void RenderingStatsInstrumentation::IncrementFrameCount(int64 count,
61 bool main_thread) {
62 if (!record_rendering_stats_)
63 return;
64
65 base::AutoLock scoped_lock(lock_);
66 if (main_thread)
67 main_stats_.frame_count += count;
68 else
69 impl_stats_.frame_count += count;
70 }
71
AddPaint(base::TimeDelta duration,int64 pixels)72 void RenderingStatsInstrumentation::AddPaint(base::TimeDelta duration,
73 int64 pixels) {
74 if (!record_rendering_stats_)
75 return;
76
77 base::AutoLock scoped_lock(lock_);
78 main_stats_.paint_time += duration;
79 main_stats_.painted_pixel_count += pixels;
80 }
81
AddRecord(base::TimeDelta duration,int64 pixels)82 void RenderingStatsInstrumentation::AddRecord(base::TimeDelta duration,
83 int64 pixels) {
84 if (!record_rendering_stats_)
85 return;
86
87 base::AutoLock scoped_lock(lock_);
88 main_stats_.record_time += duration;
89 main_stats_.recorded_pixel_count += pixels;
90 }
91
AddRaster(base::TimeDelta duration,int64 pixels)92 void RenderingStatsInstrumentation::AddRaster(base::TimeDelta duration,
93 int64 pixels) {
94 if (!record_rendering_stats_)
95 return;
96
97 base::AutoLock scoped_lock(lock_);
98 impl_stats_.rasterize_time += duration;
99 impl_stats_.rasterized_pixel_count += pixels;
100 }
101
AddAnalysis(base::TimeDelta duration,int64 pixels)102 void RenderingStatsInstrumentation::AddAnalysis(base::TimeDelta duration,
103 int64 pixels) {
104 if (!record_rendering_stats_)
105 return;
106
107 base::AutoLock scoped_lock(lock_);
108 impl_stats_.analysis_time += duration;
109 }
110
111 } // namespace cc
112