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

Side by Side Diff: content/child/child_thread_impl_perftest.cc

Issue 1187793006: content: perf tests for GpuMemoryBuffers mapping and data coherency (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
reveman 2015/06/18 21:08:57 hm, this is a browser perf test. is _perftest.cc t
vignatti (out of this project) 2015/06/18 21:59:45 I don't know where to add this test to be honest.
reveman 2015/06/22 20:41:57 Does this need to be an integration test (browsert
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/bind.h"
6 #include "base/command_line.h"
7 #include "base/memory/scoped_vector.h"
8 #include "base/time/time.h"
9 #include "content/child/child_gpu_memory_buffer_manager.h"
10 #include "content/child/child_thread_impl.h"
11 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
12 #include "content/public/common/content_switches.h"
13 #include "content/public/test/content_browser_test.h"
14 #include "content/public/test/content_browser_test_utils.h"
15 #include "content/shell/browser/shell.h"
16 #include "testing/perf/perf_test.h"
17 #include "url/gurl.h"
18
19 namespace content {
20 namespace {
21
22 static const int kNumRuns = 30;
23
24 enum NativeBufferFlag { kDisableNativeBuffers, kEnableNativeBuffers };
25
26 enum MemoryOperation { kMemoryOperationWrite, kMemoryOperationNoop };
reveman 2015/06/18 21:08:57 would this make more sense as separate tests? Map,
vignatti (out of this project) 2015/06/18 21:59:46 Acknowledged.
27
28 class ChildThreadImplBrowserTest : public ContentBrowserTest {
29 public:
30 ChildThreadImplBrowserTest()
31 : child_gpu_memory_buffer_manager_(nullptr) {}
32
33 // Overridden from BrowserTestBase:
34 void SetUpCommandLine(base::CommandLine* command_line) override {
35 command_line->AppendSwitch(switches::kSingleProcess);
36 }
37 void SetUpOnMainThread() override {
38 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
39 PostTaskToInProcessRendererAndWait(
40 base::Bind(&ChildThreadImplBrowserTest::SetUpOnChildThread, this));
41 }
42
43 ChildGpuMemoryBufferManager* child_gpu_memory_buffer_manager() {
44 return child_gpu_memory_buffer_manager_;
45 }
46
47 NativeBufferFlag native_buffer_flag_;
reveman 2015/06/18 21:08:58 do we need this as a member?
vignatti (out of this project) 2015/06/18 21:59:46 Acknowledged.
48
49 private:
50 void SetUpOnChildThread() {
51 child_gpu_memory_buffer_manager_ =
52 ChildThreadImpl::current()->gpu_memory_buffer_manager();
53 }
54
55 ChildGpuMemoryBufferManager* child_gpu_memory_buffer_manager_;
56 };
57
58 class ChildThreadImplGpuMemoryBufferPerfTest
59 : public ChildThreadImplBrowserTest,
60 public testing::WithParamInterface<
61 ::testing::tuple<NativeBufferFlag,
62 gfx::GpuMemoryBuffer::Format,
63 MemoryOperation>> {
64 public:
65 // Overridden from BrowserTestBase:
66 void SetUpCommandLine(base::CommandLine* command_line) override {
67 ChildThreadImplBrowserTest::SetUpCommandLine(command_line);
68 native_buffer_flag_ = ::testing::get<0>(GetParam());
69 switch (native_buffer_flag_) {
70 case kEnableNativeBuffers:
71 command_line->AppendSwitch(switches::kEnableNativeGpuMemoryBuffers);
72 break;
73 case kDisableNativeBuffers:
74 break;
75 }
76 }
77 };
78
79 std::string NativeBufferFlagName(NativeBufferFlag flag) {
80 switch (flag) {
81 case kDisableNativeBuffers:
82 return "fallback";
reveman 2015/06/18 21:08:57 "fallback" can be confusing as kEnableNativeBuffer
vignatti (out of this project) 2015/06/18 21:59:46 Acknowledged.
83 case kEnableNativeBuffers:
84 return "native";
85 }
86
87 NOTREACHED();
88 return "";
89 }
90
91 std::string MemoryOperationName(MemoryOperation operation) {
92 switch (operation) {
93 case kMemoryOperationWrite:
94 return "write";
95 case kMemoryOperationNoop:
96 return "noop";
97 }
98
99 NOTREACHED();
100 return "";
101 }
102
103 IN_PROC_BROWSER_TEST_P(ChildThreadImplGpuMemoryBufferPerfTest,
104 Map) {
105 gfx::GpuMemoryBuffer::Format format = ::testing::get<1>(GetParam());
106 gfx::Size buffer_size(4, 4);
107 std::string flag_name = NativeBufferFlagName(native_buffer_flag_);
108 MemoryOperation operation = ::testing::get<2>(GetParam());
109 std::string operation_name = MemoryOperationName(operation);
110
111 scoped_ptr<gfx::GpuMemoryBuffer> buffer =
112 child_gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer(
113 buffer_size, format, gfx::GpuMemoryBuffer::MAP);
114 ASSERT_TRUE(buffer);
115 EXPECT_EQ(format, buffer->GetFormat());
116
117 size_t num_planes =
118 GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(format);
119
120 // Map buffer planes.
121 scoped_ptr<void* []> planes(new void* [num_planes]);
122
123 for (int i = 0; i < kNumRuns; ++i) {
124 base::TimeTicks start = base::TimeTicks::Now();
125 bool rv = buffer->Map(planes.get());
126 base::TimeTicks end = base::TimeTicks::Now();
127 ASSERT_TRUE(rv);
128 EXPECT_TRUE(buffer->IsMapped());
129
130 // TODO(vignatti): get the mean time and print to stdout only once. At the
131 // moment it's being useful to check individual runs though cause for
132 // example VGEM has way worse performance on its first runs (got check why).
133 perf_test::PrintResult(
134 "time_to_execute_map_",
135 flag_name,
136 operation_name,
137 static_cast<size_t>((end - start).InMicroseconds()),
138 "us", true);
reveman 2015/06/18 21:08:57 can we just have one result per test? Map shows ti
vignatti (out of this project) 2015/06/18 21:59:46 as I said in the comment, I think right now I pref
139
140 // Get stride.
141 scoped_ptr<int[]> strides(new int[num_planes]);
142 buffer->GetStride(strides.get());
143
144 for (size_t plane = 0; plane < num_planes; ++plane) {
145 size_t row_size_in_bytes = 0;
146 EXPECT_TRUE(GpuMemoryBufferImpl::RowSizeInBytes(buffer_size.width(), forma t,
147 plane, &row_size_in_bytes));
148
149 scoped_ptr<char[]> data(new char[row_size_in_bytes]);
150 memset(data.get(), 0x2a + plane, row_size_in_bytes);
151
152 size_t height = buffer_size.height() /
153 GpuMemoryBufferImpl::SubsamplingFactor(format, plane);
154 for (size_t y = 0; y < height; ++y) {
155 switch (operation) {
156 case kMemoryOperationWrite:
157 // Copy |data| to row |y| of |plane| and verify result.
158 memcpy(static_cast<char*>(planes[plane]) + y * strides[plane], data. get(),
159 row_size_in_bytes);
160 EXPECT_EQ(memcmp(static_cast<char*>(planes[plane]) + y * strides[pla ne],
reveman 2015/06/18 21:08:58 this does more than write..
vignatti (out of this project) 2015/06/18 21:59:45 Acknowledged.
161 data.get(), row_size_in_bytes),
162 0);
163 break;
164 case kMemoryOperationNoop:
165 break;
166 }
167 }
168 }
169
170 buffer->Unmap();
171 EXPECT_FALSE(buffer->IsMapped());
172 }
173 }
174
175 INSTANTIATE_TEST_CASE_P(
176 ChildThreadImplGpuMemoryBufferPerfTests,
177 ChildThreadImplGpuMemoryBufferPerfTest,
178 ::testing::Combine(::testing::Values(kDisableNativeBuffers,
179 kEnableNativeBuffers),
180 ::testing::Values(gfx::GpuMemoryBuffer::BGRA_8888),
181 ::testing::Values(kMemoryOperationWrite,
182 kMemoryOperationNoop)));
183
184 } // namespace
185 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698