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

Side by Side Diff: gpu/command_buffer/service/gpu_tracer_unittest.cc

Issue 937263006: Refactored GLContext to own GPUTiming which spawn GPUTimingClients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" 9 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
10 #include "gpu/command_buffer/service/gpu_service_test.h" 10 #include "gpu/command_buffer/service/gpu_service_test.h"
11 #include "gpu/command_buffer/service/gpu_timing.h"
12 #include "gpu/command_buffer/service/gpu_tracer.h" 11 #include "gpu/command_buffer/service/gpu_tracer.h"
13 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/gl/gl_mock.h" 13 #include "ui/gl/gl_mock.h"
14 #include "ui/gl/gpu_timing.h"
15 15
16 namespace gpu { 16 namespace gpu {
17 namespace gles2 { 17 namespace gles2 {
18 namespace { 18 namespace {
19 19
20 using ::testing::_; 20 using ::testing::_;
21 using ::testing::AtLeast; 21 using ::testing::AtLeast;
22 using ::testing::AtMost; 22 using ::testing::AtMost;
23 using ::testing::Exactly; 23 using ::testing::Exactly;
24 using ::testing::Invoke; 24 using ::testing::Invoke;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 GLint64 current_time_ = 0; 145 GLint64 current_time_ = 0;
146 GLuint next_query_id_ = 0; 146 GLuint next_query_id_ = 0;
147 std::set<GLuint> alloced_queries_; 147 std::set<GLuint> alloced_queries_;
148 std::map<GLuint, GLint64> query_timestamp_; 148 std::map<GLuint, GLint64> query_timestamp_;
149 }; 149 };
150 150
151 class GPUTracerTester : public GPUTracer { 151 class GPUTracerTester : public GPUTracer {
152 public: 152 public:
153 explicit GPUTracerTester(gles2::GLES2Decoder* decoder) 153 explicit GPUTracerTester(gles2::GLES2Decoder* decoder)
154 : GPUTracer(decoder), tracing_enabled_(0) { 154 : GPUTracer(decoder), tracing_enabled_(0) {
155 gpu_timing_.SetCpuTimeForTesting(base::Bind(&FakeCpuTime)); 155 gpu_timing_client_->SetCpuTimeForTesting(base::Bind(&FakeCpuTime));
156 156
157 // Force tracing to be dependent on our mock variable here. 157 // Force tracing to be dependent on our mock variable here.
158 gpu_trace_srv_category = &tracing_enabled_; 158 gpu_trace_srv_category = &tracing_enabled_;
159 gpu_trace_dev_category = &tracing_enabled_; 159 gpu_trace_dev_category = &tracing_enabled_;
160 } 160 }
161 161
162 ~GPUTracerTester() override {} 162 ~GPUTracerTester() override {}
163 163
164 void SetTracingEnabled(bool enabled) { 164 void SetTracingEnabled(bool enabled) {
165 tracing_enabled_ = enabled ? 1 : 0; 165 tracing_enabled_ = enabled ? 1 : 0;
(...skipping 18 matching lines...) Expand all
184 184
185 unsigned char tracing_enabled_; 185 unsigned char tracing_enabled_;
186 186
187 scoped_refptr<Outputter> set_outputter_; 187 scoped_refptr<Outputter> set_outputter_;
188 }; 188 };
189 189
190 class BaseGpuTest : public GpuServiceTest { 190 class BaseGpuTest : public GpuServiceTest {
191 public: 191 public:
192 explicit BaseGpuTest(GPUTiming::TimerType test_timer_type) 192 explicit BaseGpuTest(GPUTiming::TimerType test_timer_type)
193 : test_timer_type_(test_timer_type) { 193 : test_timer_type_(test_timer_type) {
194 gpu_timing_.SetCpuTimeForTesting(base::Bind(&FakeCpuTime));
195 gpu_timing_.SetTimerTypeForTesting(test_timer_type);
196 } 194 }
197 195
198 protected: 196 protected:
199 void SetUp() override { 197 void SetUp() override {
200 g_fakeCPUTime = 0; 198 g_fakeCPUTime = 0;
201 const char* gl_version = "3.2"; 199 const char* gl_version = "3.2";
202 const char* extensions = ""; 200 const char* extensions = "";
203 if (GetTimerType() == GPUTiming::kTimerTypeDisjoint) { 201 if (GetTimerType() == GPUTiming::kTimerTypeDisjoint) {
204 gl_version = "opengl es 3.0"; 202 gl_version = "opengl es 3.0";
205 extensions = "GL_EXT_disjoint_timer_query"; 203 extensions = "GL_EXT_disjoint_timer_query";
206 } else if (GetTimerType() == GPUTiming::kTimerTypeARB) { 204 } else if (GetTimerType() == GPUTiming::kTimerTypeARB) {
207 // TODO(sievers): The tracer should not depend on ARB_occlusion_query. 205 // TODO(sievers): The tracer should not depend on ARB_occlusion_query.
208 // Try merge Query APIs (core, ARB, EXT) into a single binding each. 206 // Try merge Query APIs (core, ARB, EXT) into a single binding each.
209 extensions = "GL_ARB_timer_query GL_ARB_occlusion_query"; 207 extensions = "GL_ARB_timer_query GL_ARB_occlusion_query";
210 } 208 }
211 GpuServiceTest::SetUpWithGLVersion(gl_version, extensions); 209 GpuServiceTest::SetUpWithGLVersion(gl_version, extensions);
210 gpu_timing_.Initialize(GetGLContext());
211 gpu_timing_client_ = gpu_timing_.CreateGPUTimingClient();
212 gpu_timing_client_->SetCpuTimeForTesting(base::Bind(&FakeCpuTime));
212 gl_fake_queries_.Reset(); 213 gl_fake_queries_.Reset();
213 214
214 outputter_ref_ = new MockOutputter(); 215 outputter_ref_ = new MockOutputter();
215 } 216 }
216 217
217 void TearDown() override { 218 void TearDown() override {
218 outputter_ref_ = NULL; 219 outputter_ref_ = NULL;
219 220
220 gl_fake_queries_.Reset(); 221 gl_fake_queries_.Reset();
221 GpuServiceTest::TearDown(); 222 GpuServiceTest::TearDown();
222 } 223 }
223 224
224 void ExpectTraceQueryMocks() { 225 void ExpectTraceQueryMocks() {
225 if (GetTimerType() != GPUTiming::kTimerTypeInvalid) { 226 if (GetTimerType() != GPUTiming::kTimerTypeInvalid) {
226 // Delegate query APIs used by GPUTrace to a GlFakeQueries 227 // Delegate query APIs used by GPUTrace to a GlFakeQueries
227 EXPECT_CALL(*gl_, GenQueriesARB(2, NotNull())).Times(AtLeast(1)) 228 EXPECT_CALL(*gl_, GenQueriesARB(2, NotNull())).Times(AtLeast(1))
228 .WillRepeatedly( 229 .WillRepeatedly(
229 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB)); 230 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB));
230 231
231 EXPECT_CALL(*gl_, GetQueryObjectivARB(_, GL_QUERY_RESULT_AVAILABLE, 232 EXPECT_CALL(*gl_, GetQueryObjectivARB(_, GL_QUERY_RESULT_AVAILABLE,
232 NotNull())) 233 NotNull()))
233 .WillRepeatedly( 234 .WillRepeatedly(
234 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectivARB)); 235 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectivARB));
235 236
236 if (GetTimerType() == GPUTiming::kTimerTypeDisjoint) { 237 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, _))
237 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, _))
238 .WillRepeatedly( 238 .WillRepeatedly(
239 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); 239 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v));
240 }
241 240
242 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)).Times(AtLeast(2)) 241 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)).Times(AtLeast(2))
243 .WillRepeatedly( 242 .WillRepeatedly(
244 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); 243 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter));
245 244
246 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) 245 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull()))
247 .WillRepeatedly( 246 .WillRepeatedly(
248 Invoke(&gl_fake_queries_, 247 Invoke(&gl_fake_queries_,
249 &GlFakeQueries::GetQueryObjectui64v)); 248 &GlFakeQueries::GetQueryObjectui64v));
250 249
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); 310 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v));
312 } 311 }
313 } 312 }
314 313
315 GPUTiming::TimerType GetTimerType() { return test_timer_type_; } 314 GPUTiming::TimerType GetTimerType() { return test_timer_type_; }
316 315
317 GPUTiming::TimerType test_timer_type_; 316 GPUTiming::TimerType test_timer_type_;
318 GlFakeQueries gl_fake_queries_; 317 GlFakeQueries gl_fake_queries_;
319 318
320 GPUTiming gpu_timing_; 319 GPUTiming gpu_timing_;
320 scoped_refptr<GPUTimingClient> gpu_timing_client_;
321 scoped_refptr<MockOutputter> outputter_ref_; 321 scoped_refptr<MockOutputter> outputter_ref_;
322 }; 322 };
323 323
324 // Test GPUTrace calls all the correct gl calls. 324 // Test GPUTrace calls all the correct gl calls.
325 class BaseGpuTraceTest : public BaseGpuTest { 325 class BaseGpuTraceTest : public BaseGpuTest {
326 public: 326 public:
327 explicit BaseGpuTraceTest(GPUTiming::TimerType test_timer_type) 327 explicit BaseGpuTraceTest(GPUTiming::TimerType test_timer_type)
328 : BaseGpuTest(test_timer_type) {} 328 : BaseGpuTest(test_timer_type) {}
329 329
330 void DoTraceTest() { 330 void DoTraceTest() {
331 // Expected results 331 // Expected results
332 const std::string category_name("trace_category"); 332 const std::string category_name("trace_category");
333 const std::string trace_name("trace_test"); 333 const std::string trace_name("trace_test");
334 const int64 offset_time = 3231; 334 const int64 offset_time = 3231;
335 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; 335 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond;
336 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; 336 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond;
337 const int64 expect_start_time = 337 const int64 expect_start_time =
338 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + 338 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) +
339 offset_time; 339 offset_time;
340 const int64 expect_end_time = 340 const int64 expect_end_time =
341 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; 341 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time;
342 342
343 ExpectTraceQueryMocks(); 343 ExpectTraceQueryMocks();
344 ExpectOutputterMocks(outputter_ref_.get(), category_name, trace_name, 344 ExpectOutputterMocks(outputter_ref_.get(), category_name, trace_name,
345 expect_start_time, expect_end_time); 345 expect_start_time, expect_end_time);
346 346
347 scoped_refptr<GPUTrace> trace = new GPUTrace( 347 scoped_refptr<GPUTrace> trace = new GPUTrace(
348 outputter_ref_, &gpu_timing_, category_name, trace_name, true); 348 outputter_ref_, gpu_timing_client_.get(),
349 349 category_name, trace_name, true);
350 gpu_timing_.SetOffsetForTesting(
351 offset_time, test_timer_type_ == GPUTiming::kTimerTypeARB);
352 350
353 gl_fake_queries_.SetCurrentGLTime(start_timestamp); 351 gl_fake_queries_.SetCurrentGLTime(start_timestamp);
354 g_fakeCPUTime = expect_start_time; 352 g_fakeCPUTime = expect_start_time;
355 trace->Start(true); 353 trace->Start(true);
356 354
357 // Shouldn't be available before End() call 355 // Shouldn't be available before End() call
358 gl_fake_queries_.SetCurrentGLTime(end_timestamp); 356 gl_fake_queries_.SetCurrentGLTime(end_timestamp);
359 g_fakeCPUTime = expect_end_time; 357 g_fakeCPUTime = expect_end_time;
360 EXPECT_FALSE(trace->IsAvailable()); 358 EXPECT_FALSE(trace->IsAvailable());
361 359
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 638
641 ASSERT_TRUE(tracer_tester_->BeginDecoding()); 639 ASSERT_TRUE(tracer_tester_->BeginDecoding());
642 EXPECT_TRUE( 640 EXPECT_TRUE(
643 tracer_tester_->Begin(category_name, trace_name, kTraceGroupMarker)); 641 tracer_tester_->Begin(category_name, trace_name, kTraceGroupMarker));
644 ASSERT_TRUE(tracer_tester_->EndDecoding()); 642 ASSERT_TRUE(tracer_tester_->EndDecoding());
645 } 643 }
646 644
647 } // namespace 645 } // namespace
648 } // namespace gles2 646 } // namespace gles2
649 } // namespace gpu 647 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698