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

Side by Side Diff: base/task_scheduler/scheduler_worker_pool_impl_unittest.cc

Issue 2412343003: Add TaskScheduler.NumTasksBeforeDetach.[worker pool name] histogram. (Closed)
Patch Set: self-review Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/task_scheduler/scheduler_worker_pool_impl.h" 5 #include "base/task_scheduler/scheduler_worker_pool_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <unordered_set> 10 #include <unordered_set>
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 namespace { 586 namespace {
587 587
588 class TaskSchedulerWorkerPoolHistogramTest 588 class TaskSchedulerWorkerPoolHistogramTest
589 : public TaskSchedulerWorkerPoolImplTest { 589 : public TaskSchedulerWorkerPoolImplTest {
590 public: 590 public:
591 TaskSchedulerWorkerPoolHistogramTest() = default; 591 TaskSchedulerWorkerPoolHistogramTest() = default;
592 592
593 protected: 593 protected:
594 void SetUp() override {} 594 void SetUp() override {}
595 595
596 void TearDown() override { worker_pool_->JoinForTesting(); } 596 void TearDown() override {
597 if (worker_pool_)
robliao 2016/10/13 18:04:04 Mention that worker pool initialization is handled
fdoray 2016/10/13 20:38:53 Done
598 worker_pool_->JoinForTesting();
599 }
597 600
598 private: 601 private:
599 std::unique_ptr<StatisticsRecorder> statistics_recorder_ = 602 std::unique_ptr<StatisticsRecorder> statistics_recorder_ =
600 StatisticsRecorder::CreateTemporaryForTesting(); 603 StatisticsRecorder::CreateTemporaryForTesting();
601 604
602 private: 605 private:
603 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolHistogramTest); 606 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerWorkerPoolHistogramTest);
604 }; 607 };
605 608
606 } // namespace 609 } // namespace
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 ->GetCount(1)); 719 ->GetCount(1));
717 EXPECT_EQ(0, worker_pool_->num_tasks_between_waits_histogram_for_testing() 720 EXPECT_EQ(0, worker_pool_->num_tasks_between_waits_histogram_for_testing()
718 ->SnapshotSamples() 721 ->SnapshotSamples()
719 ->GetCount(10)); 722 ->GetCount(10));
720 723
721 tasks_can_exit_event.Signal(); 724 tasks_can_exit_event.Signal();
722 worker_pool_->WaitForAllWorkersIdleForTesting(); 725 worker_pool_->WaitForAllWorkersIdleForTesting();
723 worker_pool_->DisallowWorkerDetachmentForTesting(); 726 worker_pool_->DisallowWorkerDetachmentForTesting();
724 } 727 }
725 728
729 TEST_F(TaskSchedulerWorkerPoolHistogramTest, NumTasksBeforeDetach) {
730 InitializeWorkerPool(kReclaimTimeForDetachTests, kNumWorkersInWorkerPool);
731 auto task_runner = worker_pool_->CreateTaskRunnerWithTraits(
732 TaskTraits(), ExecutionMode::SINGLE_THREADED);
733 auto other_task_runner = worker_pool_->CreateTaskRunnerWithTraits(
734 TaskTraits(), ExecutionMode::SINGLE_THREADED);
735
736 // Post 3 tasks and wait until they run.
737 task_runner->PostTask(FROM_HERE, Bind(&DoNothing));
738 task_runner->PostTask(FROM_HERE, Bind(&DoNothing));
739 task_runner->PostTask(FROM_HERE, Bind(&DoNothing));
740 worker_pool_->WaitForAllWorkersIdleForTesting();
741
742 // To allow the SchedulerWorker associated with |task_runner| to detach:
743 // - Make sure it isn't on top of the idle stack by waking up another
744 // SchedulerWorker.
745 // - Release |task_runner|.
746 other_task_runner->PostTask(FROM_HERE, Bind(&DoNothing));
747 task_runner = nullptr;
748
749 // Allow the SchedulerWorker to detach.
750 PlatformThread::Sleep(kReclaimTimeForDetachTests + kExtraTimeToWaitForDetach);
751
752 // Join the SchedulerWorkerPool. This forces SchedulerWorkers that detached
753 // during the test to record to the histogram.
754 worker_pool_->WaitForAllWorkersIdleForTesting();
755 worker_pool_->DisallowWorkerDetachmentForTesting();
756 worker_pool_->JoinForTesting();
757 const auto* histogram =
758 worker_pool_->num_tasks_before_detach_histogram_for_testing();
759 other_task_runner = nullptr;
760 worker_pool_.reset();
761
762 // Verify that counts were recorded to the histogram as expected.
763 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(0));
764 EXPECT_EQ(1, histogram->SnapshotSamples()->GetCount(3));
765 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(10));
766 }
767
726 } // namespace internal 768 } // namespace internal
727 } // namespace base 769 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698