Run WebGL conformance tests on Android GPU bot
[chromium-blink-merge.git] / cc / debug / rendering_stats_instrumentation.cc
blob3987b7e0751dc79df214735fe92984b4c14c33c0
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::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;
31 void RenderingStatsInstrumentation::AccumulateAndClearMainThreadStats() {
32 main_stats_accu_.Add(main_stats_);
33 main_stats_ = MainThreadRenderingStats();
36 void RenderingStatsInstrumentation::AccumulateAndClearImplThreadStats() {
37 impl_stats_accu_.Add(impl_stats_);
38 impl_stats_ = ImplThreadRenderingStats();
41 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();
47 return base::TimeTicks();
50 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;
57 return base::TimeDelta();
60 void RenderingStatsInstrumentation::IncrementFrameCount(int64 count,
61 bool main_thread) {
62 if (!record_rendering_stats_)
63 return;
65 base::AutoLock scoped_lock(lock_);
66 if (main_thread)
67 main_stats_.frame_count += count;
68 else
69 impl_stats_.frame_count += count;
72 void RenderingStatsInstrumentation::AddPaint(base::TimeDelta duration,
73 int64 pixels) {
74 if (!record_rendering_stats_)
75 return;
77 base::AutoLock scoped_lock(lock_);
78 main_stats_.paint_time += duration;
79 main_stats_.painted_pixel_count += pixels;
82 void RenderingStatsInstrumentation::AddRecord(base::TimeDelta duration,
83 int64 pixels) {
84 if (!record_rendering_stats_)
85 return;
87 base::AutoLock scoped_lock(lock_);
88 main_stats_.record_time += duration;
89 main_stats_.recorded_pixel_count += pixels;
92 void RenderingStatsInstrumentation::AddRaster(base::TimeDelta duration,
93 int64 pixels) {
94 if (!record_rendering_stats_)
95 return;
97 base::AutoLock scoped_lock(lock_);
98 impl_stats_.rasterize_time += duration;
99 impl_stats_.rasterized_pixel_count += pixels;
102 } // namespace cc