• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 MainThreadRenderingStats
main_thread_rendering_stats()22 RenderingStatsInstrumentation::main_thread_rendering_stats() {
23   base::AutoLock scoped_lock(lock_);
24   return main_thread_rendering_stats_;
25 }
26 
27 ImplThreadRenderingStats
impl_thread_rendering_stats()28 RenderingStatsInstrumentation::impl_thread_rendering_stats() {
29   base::AutoLock scoped_lock(lock_);
30   return impl_thread_rendering_stats_;
31 }
32 
GetRenderingStats()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;
41 }
42 
AccumulateAndClearMainThreadStats()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_ = MainThreadRenderingStats();
47 }
48 
AccumulateAndClearImplThreadStats()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_ = ImplThreadRenderingStats();
53 }
54 
StartRecording() const55 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();
60   }
61   return base::TimeTicks();
62 }
63 
EndRecording(base::TimeTicks start_time) const64 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;
70   }
71   return base::TimeDelta();
72 }
73 
IncrementFrameCount(int64 count,bool main_thread)74 void RenderingStatsInstrumentation::IncrementFrameCount(int64 count,
75                                                         bool main_thread) {
76   if (!record_rendering_stats_)
77     return;
78 
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;
84 }
85 
AddPaint(base::TimeDelta duration,int64 pixels)86 void RenderingStatsInstrumentation::AddPaint(base::TimeDelta duration,
87                                              int64 pixels) {
88   if (!record_rendering_stats_)
89     return;
90 
91   base::AutoLock scoped_lock(lock_);
92   main_thread_rendering_stats_.paint_time += duration;
93   main_thread_rendering_stats_.painted_pixel_count += pixels;
94 }
95 
AddRecord(base::TimeDelta duration,int64 pixels)96 void RenderingStatsInstrumentation::AddRecord(base::TimeDelta duration,
97                                               int64 pixels) {
98   if (!record_rendering_stats_)
99     return;
100 
101   base::AutoLock scoped_lock(lock_);
102   main_thread_rendering_stats_.record_time += duration;
103   main_thread_rendering_stats_.recorded_pixel_count += pixels;
104 }
105 
AddRaster(base::TimeDelta duration,int64 pixels)106 void RenderingStatsInstrumentation::AddRaster(base::TimeDelta duration,
107                                               int64 pixels) {
108   if (!record_rendering_stats_)
109     return;
110 
111   base::AutoLock scoped_lock(lock_);
112   impl_thread_rendering_stats_.rasterize_time += duration;
113   impl_thread_rendering_stats_.rasterized_pixel_count += pixels;
114 }
115 
AddAnalysis(base::TimeDelta duration,int64 pixels)116 void RenderingStatsInstrumentation::AddAnalysis(base::TimeDelta duration,
117                                                 int64 pixels) {
118   if (!record_rendering_stats_)
119     return;
120 
121   base::AutoLock scoped_lock(lock_);
122   impl_thread_rendering_stats_.analysis_time += duration;
123 }
124 
AddVisibleContentArea(int64 area)125 void RenderingStatsInstrumentation::AddVisibleContentArea(int64 area) {
126   if (!record_rendering_stats_)
127     return;
128 
129   base::AutoLock scoped_lock(lock_);
130   impl_thread_rendering_stats_.visible_content_area += area;
131 }
132 
AddApproximatedVisibleContentArea(int64 area)133 void RenderingStatsInstrumentation::AddApproximatedVisibleContentArea(
134     int64 area) {
135   if (!record_rendering_stats_)
136     return;
137 
138   base::AutoLock scoped_lock(lock_);
139   impl_thread_rendering_stats_.approximated_visible_content_area += area;
140 }
141 
142 }  // namespace cc
143