Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: cc/debug/rasterize_and_record_benchmark.cc

Issue 279183002: Use LapTimer in rasterize_and_record micro benchmark. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused Now() Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/debug/rasterize_and_record_benchmark.h" 5 #include "cc/debug/rasterize_and_record_benchmark.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "cc/debug/lap_timer.h"
14 #include "cc/debug/rasterize_and_record_benchmark_impl.h" 15 #include "cc/debug/rasterize_and_record_benchmark_impl.h"
15 #include "cc/layers/layer.h" 16 #include "cc/layers/layer.h"
16 #include "cc/layers/picture_layer.h" 17 #include "cc/layers/picture_layer.h"
17 #include "cc/trees/layer_tree_host.h" 18 #include "cc/trees/layer_tree_host.h"
18 #include "cc/trees/layer_tree_host_common.h" 19 #include "cc/trees/layer_tree_host_common.h"
19 #include "ui/gfx/rect.h" 20 #include "ui/gfx/rect.h"
20 21
21 namespace cc { 22 namespace cc {
22 23
23 namespace { 24 namespace {
24 25
25 const int kDefaultRecordRepeatCount = 100; 26 const int kDefaultRecordRepeatCount = 100;
26 27
28 // Parameters for LapTimer.
29 const int kTimeLimitMillis = 1;
30 const int kWarmupRuns = 0;
31 const int kTimeCheckInterval = 1;
32
27 const char* kModeSuffixes[Picture::RECORDING_MODE_COUNT] = { 33 const char* kModeSuffixes[Picture::RECORDING_MODE_COUNT] = {
28 "", "_sk_null_canvas", "_painting_disabled", "_skrecord"}; 34 "", "_sk_null_canvas", "_painting_disabled", "_skrecord"};
29 35
30 base::TimeTicks Now() {
31 return base::TimeTicks::IsThreadNowSupported()
32 ? base::TimeTicks::ThreadNow()
33 : base::TimeTicks::HighResNow();
34 }
35
36 } // namespace 36 } // namespace
37 37
38 RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark( 38 RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark(
39 scoped_ptr<base::Value> value, 39 scoped_ptr<base::Value> value,
40 const MicroBenchmark::DoneCallback& callback) 40 const MicroBenchmark::DoneCallback& callback)
41 : MicroBenchmark(callback), 41 : MicroBenchmark(callback),
42 record_repeat_count_(kDefaultRecordRepeatCount), 42 record_repeat_count_(kDefaultRecordRepeatCount),
43 settings_(value.Pass()), 43 settings_(value.Pass()),
44 main_thread_benchmark_done_(false), 44 main_thread_benchmark_done_(false),
45 host_(NULL), 45 host_(NULL),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 gfx::Rect visible_content_rect = gfx::ScaleToEnclosingRect( 114 gfx::Rect visible_content_rect = gfx::ScaleToEnclosingRect(
115 layer->visible_content_rect(), 1.f / layer->contents_scale_x()); 115 layer->visible_content_rect(), 1.f / layer->contents_scale_x());
116 if (visible_content_rect.IsEmpty()) 116 if (visible_content_rect.IsEmpty())
117 return; 117 return;
118 118
119 for (int mode_index = 0; mode_index < Picture::RECORDING_MODE_COUNT; 119 for (int mode_index = 0; mode_index < Picture::RECORDING_MODE_COUNT;
120 mode_index++) { 120 mode_index++) {
121 Picture::RecordingMode mode = 121 Picture::RecordingMode mode =
122 static_cast<Picture::RecordingMode>(mode_index); 122 static_cast<Picture::RecordingMode>(mode_index);
123 base::TimeDelta min_time = base::TimeDelta::Max(); 123 base::TimeDelta min_time = base::TimeDelta::Max();
124 LapTimer timer(kWarmupRuns,
danakj 2014/05/12 17:16:41 Can you move the LapTimer constant declarations do
125 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
danakj 2014/05/12 17:16:41 And this could go inside the for loop?
126 kTimeCheckInterval);
124 for (int i = 0; i < record_repeat_count_; ++i) { 127 for (int i = 0; i < record_repeat_count_; ++i) {
125 base::TimeTicks start = Now(); 128 // Run for a minimum amount of time to avoid problems with timer
126 scoped_refptr<Picture> picture = Picture::Create( 129 // quantization when the layer is very small.
127 visible_content_rect, painter, tile_grid_info, false, 0, mode); 130 timer.Reset();
128 base::TimeTicks end = Now(); 131 do {
129 base::TimeDelta duration = end - start; 132 scoped_refptr<Picture> picture = Picture::Create(
133 visible_content_rect, painter, tile_grid_info, false, 0, mode);
134 timer.NextLap();
135 } while (!timer.HasTimeLimitExpired());
136 base::TimeDelta duration =
137 base::TimeDelta::FromMillisecondsD(timer.MsPerLap());
130 if (duration < min_time) 138 if (duration < min_time)
131 min_time = duration; 139 min_time = duration;
132 } 140 }
133 141
134 if (mode == Picture::RECORD_NORMALLY) { 142 if (mode == Picture::RECORD_NORMALLY) {
135 record_results_.pixels_recorded += 143 record_results_.pixels_recorded +=
136 visible_content_rect.width() * visible_content_rect.height(); 144 visible_content_rect.width() * visible_content_rect.height();
137 } 145 }
138 record_results_.total_best_time[mode_index] += min_time; 146 record_results_.total_best_time[mode_index] += min_time;
139 } 147 }
140 } 148 }
141 149
142 RasterizeAndRecordBenchmark::RecordResults::RecordResults() 150 RasterizeAndRecordBenchmark::RecordResults::RecordResults()
143 : pixels_recorded(0) {} 151 : pixels_recorded(0) {}
144 152
145 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} 153 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {}
146 154
147 } // namespace cc 155 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698