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

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

Issue 1081483002: GPU Tracer no longer issue device traces when device category is off. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit test to test that trace calls are only called when categories are enabled Created 5 years, 8 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 | « gpu/command_buffer/service/gpu_tracer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 expect_start_time, expect_end_time)) 287 expect_start_time, expect_end_time))
288 .Times(Exactly(1)); 288 .Times(Exactly(1));
289 } else { 289 } else {
290 EXPECT_CALL(*outputter, TraceDevice(category, name, 290 EXPECT_CALL(*outputter, TraceDevice(category, name,
291 expect_start_time, expect_end_time)) 291 expect_start_time, expect_end_time))
292 .Times(Exactly(0)); 292 .Times(Exactly(0));
293 } 293 }
294 } 294 }
295 295
296 void ExpectOutputterMocks(MockOutputter* outputter, 296 void ExpectOutputterMocks(MockOutputter* outputter,
297 bool tracing_device,
297 const std::string& category, 298 const std::string& category,
298 const std::string& name, int64 expect_start_time, 299 const std::string& name, int64 expect_start_time,
299 int64 expect_end_time) { 300 int64 expect_end_time) {
300 ExpectOutputterBeginMocks(outputter, category, name); 301 ExpectOutputterBeginMocks(outputter, category, name);
301 bool valid_timer = gpu_timing_client_->IsAvailable() && 302 bool valid_timer = tracing_device &&
303 gpu_timing_client_->IsAvailable() &&
302 gpu_timing_client_->IsTimerOffsetAvailable(); 304 gpu_timing_client_->IsTimerOffsetAvailable();
303 ExpectOutputterEndMocks(outputter, category, name, expect_start_time, 305 ExpectOutputterEndMocks(outputter, category, name, expect_start_time,
304 expect_end_time, valid_timer); 306 expect_end_time, valid_timer);
305 } 307 }
306 308
307 void ExpectTracerOffsetQueryMocks() { 309 void ExpectTracerOffsetQueryMocks() {
308 if (GetTimerType() != gfx::GPUTiming::kTimerTypeARB) { 310 if (GetTimerType() != gfx::GPUTiming::kTimerTypeARB) {
309 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) 311 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull()))
310 .Times(Exactly(0)); 312 .Times(Exactly(0));
311 } else { 313 } else {
(...skipping 12 matching lines...) Expand all
324 scoped_refptr<gfx::GPUTimingClient> gpu_timing_client_; 326 scoped_refptr<gfx::GPUTimingClient> gpu_timing_client_;
325 scoped_refptr<MockOutputter> outputter_ref_; 327 scoped_refptr<MockOutputter> outputter_ref_;
326 }; 328 };
327 329
328 // Test GPUTrace calls all the correct gl calls. 330 // Test GPUTrace calls all the correct gl calls.
329 class BaseGpuTraceTest : public BaseGpuTest { 331 class BaseGpuTraceTest : public BaseGpuTest {
330 public: 332 public:
331 explicit BaseGpuTraceTest(gfx::GPUTiming::TimerType test_timer_type) 333 explicit BaseGpuTraceTest(gfx::GPUTiming::TimerType test_timer_type)
332 : BaseGpuTest(test_timer_type) {} 334 : BaseGpuTest(test_timer_type) {}
333 335
334 void DoTraceTest() { 336 void DoTraceTest(bool tracing_service, bool tracing_device) {
335 // Expected results 337 // Expected results
336 const std::string category_name("trace_category"); 338 const std::string category_name("trace_category");
337 const std::string trace_name("trace_test"); 339 const std::string trace_name("trace_test");
338 const int64 offset_time = 3231; 340 const int64 offset_time = 3231;
339 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; 341 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond;
340 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; 342 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond;
341 const int64 expect_start_time = 343 const int64 expect_start_time =
342 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + 344 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) +
343 offset_time; 345 offset_time;
344 const int64 expect_end_time = 346 const int64 expect_end_time =
345 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; 347 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time;
346 348
347 ExpectTraceQueryMocks(); 349 if (tracing_service)
348 ExpectOutputterMocks(outputter_ref_.get(), category_name, trace_name, 350 ExpectOutputterMocks(outputter_ref_.get(), tracing_device, category_name,
349 expect_start_time, expect_end_time); 351 trace_name, expect_start_time, expect_end_time);
352
353 if (tracing_device)
354 ExpectTraceQueryMocks();
350 355
351 scoped_refptr<GPUTrace> trace = new GPUTrace( 356 scoped_refptr<GPUTrace> trace = new GPUTrace(
352 outputter_ref_, gpu_timing_client_.get(), 357 outputter_ref_, gpu_timing_client_.get(),
353 category_name, trace_name, true); 358 category_name, trace_name, tracing_service, tracing_device);
354 359
355 gl_fake_queries_.SetCurrentGLTime(start_timestamp); 360 gl_fake_queries_.SetCurrentGLTime(start_timestamp);
356 g_fakeCPUTime = expect_start_time; 361 g_fakeCPUTime = expect_start_time;
357 trace->Start(true); 362 trace->Start();
358 363
359 // Shouldn't be available before End() call 364 // Shouldn't be available before End() call
360 gl_fake_queries_.SetCurrentGLTime(end_timestamp); 365 gl_fake_queries_.SetCurrentGLTime(end_timestamp);
361 g_fakeCPUTime = expect_end_time; 366 g_fakeCPUTime = expect_end_time;
362 EXPECT_FALSE(trace->IsAvailable()); 367 if (tracing_device)
368 EXPECT_FALSE(trace->IsAvailable());
363 369
364 trace->End(true); 370 trace->End();
365 371
366 // Shouldn't be available until the queries complete 372 // Shouldn't be available until the queries complete
367 gl_fake_queries_.SetCurrentGLTime(end_timestamp - 373 gl_fake_queries_.SetCurrentGLTime(end_timestamp -
368 base::Time::kNanosecondsPerMicrosecond); 374 base::Time::kNanosecondsPerMicrosecond);
369 EXPECT_FALSE(trace->IsAvailable()); 375 if (tracing_device)
376 EXPECT_FALSE(trace->IsAvailable());
370 377
371 // Now it should be available 378 // Now it should be available
372 gl_fake_queries_.SetCurrentGLTime(end_timestamp); 379 gl_fake_queries_.SetCurrentGLTime(end_timestamp);
373 EXPECT_TRUE(trace->IsAvailable()); 380 EXPECT_TRUE(trace->IsAvailable());
374 381
375 // Proces should output expected Trace results to MockOutputter 382 // Proces should output expected Trace results to MockOutputter
376 trace->Process(); 383 trace->Process();
377 384
378 // Destroy trace after we are done. 385 // Destroy trace after we are done.
379 trace->Destroy(true); 386 trace->Destroy(true);
380 387
381 outputter_ref_ = NULL; 388 outputter_ref_ = NULL;
382 } 389 }
383 }; 390 };
384 391
385 class GpuARBTimerTraceTest : public BaseGpuTraceTest { 392 class GpuARBTimerTraceTest : public BaseGpuTraceTest {
386 public: 393 public:
387 GpuARBTimerTraceTest() : BaseGpuTraceTest(gfx::GPUTiming::kTimerTypeARB) {} 394 GpuARBTimerTraceTest() : BaseGpuTraceTest(gfx::GPUTiming::kTimerTypeARB) {}
388 }; 395 };
389 396
390 class GpuDisjointTimerTraceTest : public BaseGpuTraceTest { 397 class GpuDisjointTimerTraceTest : public BaseGpuTraceTest {
391 public: 398 public:
392 GpuDisjointTimerTraceTest() 399 GpuDisjointTimerTraceTest()
393 : BaseGpuTraceTest(gfx::GPUTiming::kTimerTypeDisjoint) {} 400 : BaseGpuTraceTest(gfx::GPUTiming::kTimerTypeDisjoint) {}
394 }; 401 };
395 402
396 TEST_F(GpuARBTimerTraceTest, ARBTimerTraceTest) { 403 TEST_F(GpuARBTimerTraceTest, ARBTimerTraceTestOff) {
397 DoTraceTest(); 404 DoTraceTest(false, false);
398 } 405 }
399 406
400 TEST_F(GpuDisjointTimerTraceTest, DisjointTimerTraceTest) { 407 TEST_F(GpuARBTimerTraceTest, ARBTimerTraceTestServiceOnly) {
401 DoTraceTest(); 408 DoTraceTest(true, false);
409 }
410
411 TEST_F(GpuARBTimerTraceTest, ARBTimerTraceTestDeviceOnly) {
412 DoTraceTest(false, true);
413 }
414
415 TEST_F(GpuARBTimerTraceTest, ARBTimerTraceTestBothOn) {
416 DoTraceTest(true, true);
417 }
418
419 TEST_F(GpuDisjointTimerTraceTest, DisjointTimerTraceTestOff) {
420 DoTraceTest(false, false);
421 }
422
423 TEST_F(GpuDisjointTimerTraceTest, DisjointTimerTraceTestServiceOnly) {
424 DoTraceTest(true, false);
425 }
426
427 TEST_F(GpuDisjointTimerTraceTest, DisjointTimerTraceTestDeviceOnly) {
428 DoTraceTest(false, true);
429 }
430
431 TEST_F(GpuDisjointTimerTraceTest, DisjointTimerTraceTestBothOn) {
432 DoTraceTest(true, true);
402 } 433 }
403 434
404 // Test GPUTracer calls all the correct gl calls. 435 // Test GPUTracer calls all the correct gl calls.
405 class BaseGpuTracerTest : public BaseGpuTest { 436 class BaseGpuTracerTest : public BaseGpuTest {
406 public: 437 public:
407 explicit BaseGpuTracerTest(gfx::GPUTiming::TimerType test_timer_type) 438 explicit BaseGpuTracerTest(gfx::GPUTiming::TimerType test_timer_type)
408 : BaseGpuTest(test_timer_type) {} 439 : BaseGpuTest(test_timer_type) {}
409 440
410 void DoBasicTracerTest() { 441 void DoBasicTracerTest() {
411 ExpectTracerOffsetQueryMocks(); 442 ExpectTracerOffsetQueryMocks();
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 scoped_refptr<gfx::GPUTimingClient> client3 = 733 scoped_refptr<gfx::GPUTimingClient> client3 =
703 GetGLContext()->CreateGPUTimingClient(); 734 GetGLContext()->CreateGPUTimingClient();
704 ASSERT_TRUE(client1->CheckAndResetTimerErrors()); 735 ASSERT_TRUE(client1->CheckAndResetTimerErrors());
705 ASSERT_TRUE(client2->CheckAndResetTimerErrors()); 736 ASSERT_TRUE(client2->CheckAndResetTimerErrors());
706 ASSERT_FALSE(client3->CheckAndResetTimerErrors()); 737 ASSERT_FALSE(client3->CheckAndResetTimerErrors());
707 } 738 }
708 739
709 } // namespace 740 } // namespace
710 } // namespace gles2 741 } // namespace gles2
711 } // namespace gpu 742 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gpu_tracer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698