| OLD | NEW |
| 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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 event.Signal(); | 626 event.Signal(); |
| 627 worker_pool_->WaitForAllWorkersIdleForTesting(); | 627 worker_pool_->WaitForAllWorkersIdleForTesting(); |
| 628 | 628 |
| 629 // Wake up the SchedulerWorker that just became idle by posting a task and | 629 // Wake up the SchedulerWorker that just became idle by posting a task and |
| 630 // wait until it becomes idle again. The SchedulerWorker should record the | 630 // wait until it becomes idle again. The SchedulerWorker should record the |
| 631 // TaskScheduler.NumTasksBetweenWaits.* histogram on wake up. | 631 // TaskScheduler.NumTasksBetweenWaits.* histogram on wake up. |
| 632 task_runner->PostTask(FROM_HERE, Bind(&DoNothing)); | 632 task_runner->PostTask(FROM_HERE, Bind(&DoNothing)); |
| 633 worker_pool_->WaitForAllWorkersIdleForTesting(); | 633 worker_pool_->WaitForAllWorkersIdleForTesting(); |
| 634 | 634 |
| 635 // Verify that counts were recorded to the histogram as expected. | 635 // Verify that counts were recorded to the histogram as expected. |
| 636 EXPECT_EQ(0, worker_pool_->num_tasks_between_waits_histogram_for_testing() | 636 EXPECT_EQ(0, worker_pool_->num_tasks_between_waits_histogram() |
| 637 ->SnapshotSamples() | 637 ->SnapshotSamples() |
| 638 ->GetCount(0)); | 638 ->GetCount(0)); |
| 639 EXPECT_EQ(1, worker_pool_->num_tasks_between_waits_histogram_for_testing() | 639 EXPECT_EQ(1, worker_pool_->num_tasks_between_waits_histogram() |
| 640 ->SnapshotSamples() | 640 ->SnapshotSamples() |
| 641 ->GetCount(3)); | 641 ->GetCount(3)); |
| 642 EXPECT_EQ(0, worker_pool_->num_tasks_between_waits_histogram_for_testing() | 642 EXPECT_EQ(0, worker_pool_->num_tasks_between_waits_histogram() |
| 643 ->SnapshotSamples() | 643 ->SnapshotSamples() |
| 644 ->GetCount(10)); | 644 ->GetCount(10)); |
| 645 } | 645 } |
| 646 | 646 |
| 647 namespace { | 647 namespace { |
| 648 | 648 |
| 649 void SignalAndWaitEvent(WaitableEvent* signal_event, | 649 void SignalAndWaitEvent(WaitableEvent* signal_event, |
| 650 WaitableEvent* wait_event) { | 650 WaitableEvent* wait_event) { |
| 651 signal_event->Signal(); | 651 signal_event->Signal(); |
| 652 wait_event->Wait(); | 652 wait_event->Wait(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 } | 696 } |
| 697 for (const auto& task_started_event : task_started_events) | 697 for (const auto& task_started_event : task_started_events) |
| 698 task_started_event->Wait(); | 698 task_started_event->Wait(); |
| 699 | 699 |
| 700 // Verify that counts were recorded to the histogram as expected. | 700 // Verify that counts were recorded to the histogram as expected. |
| 701 // - The "0" bucket has a count of at least 1 because the SchedulerWorker on | 701 // - The "0" bucket has a count of at least 1 because the SchedulerWorker on |
| 702 // top of the idle stack isn't allowed to detach when its sleep timeout | 702 // top of the idle stack isn't allowed to detach when its sleep timeout |
| 703 // expires. Instead, it waits on its WaitableEvent again without running a | 703 // expires. Instead, it waits on its WaitableEvent again without running a |
| 704 // task. The count may be higher than 1 because of spurious wake ups before | 704 // task. The count may be higher than 1 because of spurious wake ups before |
| 705 // the sleep timeout expires. | 705 // the sleep timeout expires. |
| 706 EXPECT_GE(worker_pool_->num_tasks_between_waits_histogram_for_testing() | 706 EXPECT_GE(worker_pool_->num_tasks_between_waits_histogram() |
| 707 ->SnapshotSamples() | 707 ->SnapshotSamples() |
| 708 ->GetCount(0), | 708 ->GetCount(0), |
| 709 1); | 709 1); |
| 710 // - The "1" bucket has a count of |kNumWorkersInWorkerPool| because each | 710 // - The "1" bucket has a count of |kNumWorkersInWorkerPool| because each |
| 711 // SchedulerWorker ran a task before waiting on its WaitableEvent at the | 711 // SchedulerWorker ran a task before waiting on its WaitableEvent at the |
| 712 // beginning of the test. | 712 // beginning of the test. |
| 713 EXPECT_EQ(static_cast<int>(kNumWorkersInWorkerPool), | 713 EXPECT_EQ(static_cast<int>(kNumWorkersInWorkerPool), |
| 714 worker_pool_->num_tasks_between_waits_histogram_for_testing() | 714 worker_pool_->num_tasks_between_waits_histogram() |
| 715 ->SnapshotSamples() | 715 ->SnapshotSamples() |
| 716 ->GetCount(1)); | 716 ->GetCount(1)); |
| 717 EXPECT_EQ(0, worker_pool_->num_tasks_between_waits_histogram_for_testing() | 717 EXPECT_EQ(0, worker_pool_->num_tasks_between_waits_histogram() |
| 718 ->SnapshotSamples() | 718 ->SnapshotSamples() |
| 719 ->GetCount(10)); | 719 ->GetCount(10)); |
| 720 | 720 |
| 721 tasks_can_exit_event.Signal(); | 721 tasks_can_exit_event.Signal(); |
| 722 worker_pool_->WaitForAllWorkersIdleForTesting(); | 722 worker_pool_->WaitForAllWorkersIdleForTesting(); |
| 723 worker_pool_->DisallowWorkerDetachmentForTesting(); | 723 worker_pool_->DisallowWorkerDetachmentForTesting(); |
| 724 } | 724 } |
| 725 | 725 |
| 726 } // namespace internal | 726 } // namespace internal |
| 727 } // namespace base | 727 } // namespace base |
| OLD | NEW |