1 // Copyright 2012 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 "base/values.h"
6 #include "cc/debug/rendering_stats.h"
7
8 namespace cc {
9
MainThreadRenderingStats()10 MainThreadRenderingStats::MainThreadRenderingStats()
11 : frame_count(0),
12 painted_pixel_count(0),
13 recorded_pixel_count(0) {}
14
15 scoped_refptr<base::debug::ConvertableToTraceFormat>
AsTraceableData() const16 MainThreadRenderingStats::AsTraceableData() const {
17 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue());
18 record_data->SetInteger("frame_count", frame_count);
19 record_data->SetDouble("paint_time", paint_time.InSecondsF());
20 record_data->SetInteger("painted_pixel_count", painted_pixel_count);
21 record_data->SetDouble("record_time", record_time.InSecondsF());
22 record_data->SetInteger("recorded_pixel_count", recorded_pixel_count);
23 return TracedValue::FromValue(record_data.release());
24 }
25
Add(const MainThreadRenderingStats & other)26 void MainThreadRenderingStats::Add(const MainThreadRenderingStats& other) {
27 frame_count += other.frame_count;
28 paint_time += other.paint_time;
29 painted_pixel_count += other.painted_pixel_count;
30 record_time += other.record_time;
31 recorded_pixel_count += other.recorded_pixel_count;
32 }
33
ImplThreadRenderingStats()34 ImplThreadRenderingStats::ImplThreadRenderingStats()
35 : frame_count(0),
36 rasterized_pixel_count(0) {}
37
38 scoped_refptr<base::debug::ConvertableToTraceFormat>
AsTraceableData() const39 ImplThreadRenderingStats::AsTraceableData() const {
40 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue());
41 record_data->SetInteger("frame_count", frame_count);
42 record_data->SetDouble("rasterize_time", rasterize_time.InSecondsF());
43 record_data->SetInteger("rasterized_pixel_count", rasterized_pixel_count);
44 return TracedValue::FromValue(record_data.release());
45 }
46
Add(const ImplThreadRenderingStats & other)47 void ImplThreadRenderingStats::Add(const ImplThreadRenderingStats& other) {
48 frame_count += other.frame_count;
49 rasterize_time += other.rasterize_time;
50 analysis_time += other.analysis_time;
51 rasterized_pixel_count += other.rasterized_pixel_count;
52 }
53
EnumerateFields(Enumerator * enumerator) const54 void RenderingStats::EnumerateFields(Enumerator* enumerator) const {
55 enumerator->AddInt64("frameCount",
56 main_stats.frame_count + impl_stats.frame_count);
57 enumerator->AddDouble("paintTime",
58 main_stats.paint_time.InSecondsF());
59 enumerator->AddInt64("paintedPixelCount",
60 main_stats.painted_pixel_count);
61 enumerator->AddDouble("recordTime",
62 main_stats.record_time.InSecondsF());
63 enumerator->AddInt64("recordedPixelCount",
64 main_stats.recorded_pixel_count);
65 // Combine rasterization and analysis time as a precursor to combining
66 // them in the same step internally.
67 enumerator->AddDouble("rasterizeTime",
68 impl_stats.rasterize_time.InSecondsF() +
69 impl_stats.analysis_time.InSecondsF());
70 enumerator->AddInt64("rasterizedPixelCount",
71 impl_stats.rasterized_pixel_count);
72 }
73
Add(const RenderingStats & other)74 void RenderingStats::Add(const RenderingStats& other) {
75 main_stats.Add(other.main_stats);
76 impl_stats.Add(other.impl_stats);
77 }
78
79 } // namespace cc
80