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

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

Issue 940633004: Added disjoint context class which manages disjoints within gpu timing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initialize disjoint value to proper value 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"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 protected: 143 protected:
144 bool disjointed_ = false; 144 bool disjointed_ = false;
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, GPUTiming* gpu_timing)
Daniele Castagna 2015/02/19 18:15:32 nit: explicit here is not needed anymore.
154 : GPUTracer(decoder), tracing_enabled_(0) { 154 : GPUTracer(decoder, gpu_timing), tracing_enabled_(0) {
155 gpu_timing_.SetCpuTimeForTesting(base::Bind(&FakeCpuTime)); 155 gpu_timing_->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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 class BaseGpuTracerTest : public BaseGpuTest { 399 class BaseGpuTracerTest : public BaseGpuTest {
400 public: 400 public:
401 explicit BaseGpuTracerTest(GPUTiming::TimerType test_timer_type) 401 explicit BaseGpuTracerTest(GPUTiming::TimerType test_timer_type)
402 : BaseGpuTest(test_timer_type) {} 402 : BaseGpuTest(test_timer_type) {}
403 403
404 void DoBasicTracerTest() { 404 void DoBasicTracerTest() {
405 ExpectTracerOffsetQueryMocks(); 405 ExpectTracerOffsetQueryMocks();
406 406
407 MockGLES2Decoder decoder; 407 MockGLES2Decoder decoder;
408 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); 408 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext()));
409 GPUTracerTester tracer(&decoder); 409 GPUTracerTester tracer(&decoder, &gpu_timing_);
410 tracer.SetTracingEnabled(true); 410 tracer.SetTracingEnabled(true);
411 411
412 tracer.SetOutputter(outputter_ref_); 412 tracer.SetOutputter(outputter_ref_);
413 413
414 ASSERT_TRUE(tracer.BeginDecoding()); 414 ASSERT_TRUE(tracer.BeginDecoding());
415 ASSERT_TRUE(tracer.EndDecoding()); 415 ASSERT_TRUE(tracer.EndDecoding());
416 416
417 outputter_ref_ = NULL; 417 outputter_ref_ = NULL;
418 } 418 }
419 419
(...skipping 10 matching lines...) Expand all
430 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; 430 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond;
431 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; 431 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond;
432 const int64 expect_start_time = 432 const int64 expect_start_time =
433 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + 433 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) +
434 offset_time; 434 offset_time;
435 const int64 expect_end_time = 435 const int64 expect_end_time =
436 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; 436 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time;
437 437
438 MockGLES2Decoder decoder; 438 MockGLES2Decoder decoder;
439 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); 439 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext()));
440 GPUTracerTester tracer(&decoder); 440 GPUTracerTester tracer(&decoder, &gpu_timing_);
441 tracer.SetTracingEnabled(true); 441 tracer.SetTracingEnabled(true);
442 442
443 tracer.SetOutputter(outputter_ref_); 443 tracer.SetOutputter(outputter_ref_);
444 444
445 gl_fake_queries_.SetCurrentGLTime(start_timestamp); 445 gl_fake_queries_.SetCurrentGLTime(start_timestamp);
446 g_fakeCPUTime = expect_start_time; 446 g_fakeCPUTime = expect_start_time;
447 447
448 ASSERT_TRUE(tracer.BeginDecoding()); 448 ASSERT_TRUE(tracer.BeginDecoding());
449 449
450 ExpectTraceQueryMocks(); 450 ExpectTraceQueryMocks();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; 515 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond;
516 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; 516 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond;
517 const int64 expect_start_time = 517 const int64 expect_start_time =
518 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + 518 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) +
519 offset_time; 519 offset_time;
520 const int64 expect_end_time = 520 const int64 expect_end_time =
521 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; 521 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time;
522 522
523 MockGLES2Decoder decoder; 523 MockGLES2Decoder decoder;
524 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); 524 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext()));
525 GPUTracerTester tracer(&decoder); 525 GPUTracerTester tracer(&decoder, &gpu_timing_);
526 tracer.SetTracingEnabled(true); 526 tracer.SetTracingEnabled(true);
527 527
528 tracer.SetOutputter(outputter_ref_); 528 tracer.SetOutputter(outputter_ref_);
529 529
530 gl_fake_queries_.SetCurrentGLTime(start_timestamp); 530 gl_fake_queries_.SetCurrentGLTime(start_timestamp);
531 g_fakeCPUTime = expect_start_time; 531 g_fakeCPUTime = expect_start_time;
532 532
533 ASSERT_TRUE(tracer.BeginDecoding()); 533 ASSERT_TRUE(tracer.BeginDecoding());
534 534
535 ExpectTraceQueryMocks(); 535 ExpectTraceQueryMocks();
536 536
537 ExpectOutputterBeginMocks(outputter_ref_.get(), 537 ExpectOutputterBeginMocks(outputter_ref_.get(),
538 category_name, trace_name); 538 category_name, trace_name);
539 ASSERT_TRUE(tracer.Begin(category_name, trace_name, source)); 539 ASSERT_TRUE(tracer.Begin(category_name, trace_name, source));
540 540
541 gl_fake_queries_.SetCurrentGLTime(end_timestamp); 541 gl_fake_queries_.SetCurrentGLTime(end_timestamp);
542 g_fakeCPUTime = expect_end_time; 542 g_fakeCPUTime = expect_end_time;
543
544 // Create a disjoint context to test disjoint behavior. This should not
545 // interfere with the tracer's disjoint context.
546 scoped_refptr<DisjointContext> disjoint_context =
547 gpu_timing_.CreateDisjointContext();
548
549 ASSERT_FALSE(disjoint_context->CheckAndResetTimerErrors());
543 gl_fake_queries_.SetDisjoint(); 550 gl_fake_queries_.SetDisjoint();
551 ASSERT_TRUE(disjoint_context->CheckAndResetTimerErrors());
544 552
545 ExpectOutputterEndMocks(outputter_ref_.get(), category_name, trace_name, 553 ExpectOutputterEndMocks(outputter_ref_.get(), category_name, trace_name,
546 expect_start_time, expect_end_time, false); 554 expect_start_time, expect_end_time, false);
547 555
548 ASSERT_TRUE(tracer.End(source)); 556 ASSERT_TRUE(tracer.End(source));
549 ASSERT_TRUE(tracer.EndDecoding()); 557 ASSERT_TRUE(tracer.EndDecoding());
550 558
551 outputter_ref_ = NULL; 559 outputter_ref_ = NULL;
552 } 560 }
553 }; 561 };
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 606
599 class GPUTracerTest : public GpuServiceTest { 607 class GPUTracerTest : public GpuServiceTest {
600 protected: 608 protected:
601 void SetUp() override { 609 void SetUp() override {
602 g_fakeCPUTime = 0; 610 g_fakeCPUTime = 0;
603 GpuServiceTest::SetUpWithGLVersion("3.2", ""); 611 GpuServiceTest::SetUpWithGLVersion("3.2", "");
604 decoder_.reset(new MockGLES2Decoder()); 612 decoder_.reset(new MockGLES2Decoder());
605 EXPECT_CALL(*decoder_, GetGLContext()) 613 EXPECT_CALL(*decoder_, GetGLContext())
606 .Times(AtMost(1)) 614 .Times(AtMost(1))
607 .WillRepeatedly(Return(GetGLContext())); 615 .WillRepeatedly(Return(GetGLContext()));
608 tracer_tester_.reset(new GPUTracerTester(decoder_.get())); 616 tracer_tester_.reset(new GPUTracerTester(decoder_.get(), &gpu_timing_));
609 } 617 }
610 618
611 void TearDown() override { 619 void TearDown() override {
612 tracer_tester_ = nullptr; 620 tracer_tester_ = nullptr;
613 decoder_ = nullptr; 621 decoder_ = nullptr;
614 GpuServiceTest::TearDown(); 622 GpuServiceTest::TearDown();
615 } 623 }
624 GPUTiming gpu_timing_;
616 scoped_ptr<MockGLES2Decoder> decoder_; 625 scoped_ptr<MockGLES2Decoder> decoder_;
617 scoped_ptr<GPUTracerTester> tracer_tester_; 626 scoped_ptr<GPUTracerTester> tracer_tester_;
618 }; 627 };
619 628
620 TEST_F(GPUTracerTest, IsTracingTest) { 629 TEST_F(GPUTracerTest, IsTracingTest) {
621 EXPECT_FALSE(tracer_tester_->IsTracing()); 630 EXPECT_FALSE(tracer_tester_->IsTracing());
622 tracer_tester_->SetTracingEnabled(true); 631 tracer_tester_->SetTracingEnabled(true);
623 EXPECT_TRUE(tracer_tester_->IsTracing()); 632 EXPECT_TRUE(tracer_tester_->IsTracing());
624 } 633 }
625 // Test basic functionality of the GPUTracerTester. 634 // Test basic functionality of the GPUTracerTester.
(...skipping 10 matching lines...) Expand all
636 645
637 EXPECT_FALSE( 646 EXPECT_FALSE(
638 tracer_tester_->Begin(category_name, trace_name, kTraceGroupMarker)); 647 tracer_tester_->Begin(category_name, trace_name, kTraceGroupMarker));
639 648
640 ASSERT_TRUE(tracer_tester_->BeginDecoding()); 649 ASSERT_TRUE(tracer_tester_->BeginDecoding());
641 EXPECT_TRUE( 650 EXPECT_TRUE(
642 tracer_tester_->Begin(category_name, trace_name, kTraceGroupMarker)); 651 tracer_tester_->Begin(category_name, trace_name, kTraceGroupMarker));
643 ASSERT_TRUE(tracer_tester_->EndDecoding()); 652 ASSERT_TRUE(tracer_tester_->EndDecoding());
644 } 653 }
645 654
655 TEST_F(GpuDisjointTimerTracerTest, MultipleDisjointContexts) {
656 EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(AtLeast(1))
657 .WillRepeatedly(
658 Invoke(&gl_fake_queries_, &GlFakeQueries::GetIntegerv));
659
660 scoped_refptr<DisjointContext> disjoint_context1 =
661 gpu_timing_.CreateDisjointContext();
662 scoped_refptr<DisjointContext> disjoint_context2 =
663 gpu_timing_.CreateDisjointContext();
664
665 // Test both contexts are initialized as no errors.
666 ASSERT_FALSE(disjoint_context1->CheckAndResetTimerErrors());
667 ASSERT_FALSE(disjoint_context2->CheckAndResetTimerErrors());
668
669 // Issue a disjoint.
670 gl_fake_queries_.SetDisjoint();
671
672 ASSERT_TRUE(disjoint_context1->CheckAndResetTimerErrors());
673 ASSERT_TRUE(disjoint_context2->CheckAndResetTimerErrors());
674
675 // Test new context gets the disjoint value as if no other contexts reset it.
676 scoped_refptr<DisjointContext> disjoint_context3 =
677 gpu_timing_.CreateDisjointContext();
678 ASSERT_TRUE(disjoint_context3->CheckAndResetTimerErrors());
679
680 // Test all 3 are all reset.
681 ASSERT_FALSE(disjoint_context1->CheckAndResetTimerErrors());
682 ASSERT_FALSE(disjoint_context2->CheckAndResetTimerErrors());
683 ASSERT_FALSE(disjoint_context3->CheckAndResetTimerErrors());
684 }
685
686 TEST_F(GpuDisjointTimerTracerTest, DisjointContextDestruction) {
687 ASSERT_EQ(0u, gpu_timing_.GetDisjointContextsCount());
688
689 {
690 scoped_refptr<DisjointContext> context =
691 gpu_timing_.CreateDisjointContext();
692 ASSERT_EQ(1u, gpu_timing_.GetDisjointContextsCount());
693 }
694
695 ASSERT_EQ(0u, gpu_timing_.GetDisjointContextsCount());
696 }
697
646 } // namespace 698 } // namespace
647 } // namespace gles2 699 } // namespace gles2
648 } // namespace gpu 700 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698