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

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

Issue 2600023002: Remove worker pool names from TaskScheduler.TaskLatency.* histograms. (Closed)
Patch Set: self-review Created 3 years, 12 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/task_tracker.h" 5 #include "base/task_scheduler/task_tracker.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/metrics/histogram_base.h"
20 #include "base/metrics/histogram_samples.h"
21 #include "base/metrics/statistics_recorder.h"
19 #include "base/sequence_token.h" 22 #include "base/sequence_token.h"
20 #include "base/sequenced_task_runner.h" 23 #include "base/sequenced_task_runner.h"
21 #include "base/single_thread_task_runner.h" 24 #include "base/single_thread_task_runner.h"
22 #include "base/synchronization/atomic_flag.h" 25 #include "base/synchronization/atomic_flag.h"
23 #include "base/synchronization/waitable_event.h" 26 #include "base/synchronization/waitable_event.h"
24 #include "base/task_scheduler/scheduler_lock.h" 27 #include "base/task_scheduler/scheduler_lock.h"
25 #include "base/task_scheduler/task.h" 28 #include "base/task_scheduler/task.h"
26 #include "base/task_scheduler/task_traits.h" 29 #include "base/task_scheduler/task_traits.h"
27 #include "base/test/gtest_util.h" 30 #include "base/test/gtest_util.h"
28 #include "base/test/test_simple_task_runner.h" 31 #include "base/test/test_simple_task_runner.h"
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 // task. 881 // task.
879 TEST(TaskSchedulerTaskTrackerWaitAllowedTest, WaitAllowed) { 882 TEST(TaskSchedulerTaskTrackerWaitAllowedTest, WaitAllowed) {
880 // Run the test on the separate thread since it is not possible to reset the 883 // Run the test on the separate thread since it is not possible to reset the
881 // "wait allowed" bit of a thread without being a friend of 884 // "wait allowed" bit of a thread without being a friend of
882 // ThreadRestrictions. 885 // ThreadRestrictions.
883 WaitAllowedTestThread wait_allowed_test_thread; 886 WaitAllowedTestThread wait_allowed_test_thread;
884 wait_allowed_test_thread.Start(); 887 wait_allowed_test_thread.Start();
885 wait_allowed_test_thread.Join(); 888 wait_allowed_test_thread.Join();
886 } 889 }
887 890
891 // Verify that TaskScheduler.TaskLatency.* histograms are correctly recorded
892 // when a task runs.
893 TEST(TaskSchedulerTaskTrackerHistogramTest, TaskLatency) {
894 auto statistics_recorder = StatisticsRecorder::CreateTemporaryForTesting();
895
896 TaskTracker tracker;
897
898 struct {
899 const TaskTraits traits;
900 HistogramBase* const expected_histogram;
901 } tests[] = {
902 {TaskTraits().WithPriority(TaskPriority::BACKGROUND),
903 tracker.task_latency_histograms_[static_cast<int>(
904 TaskPriority::BACKGROUND)][0]},
905 {TaskTraits().WithPriority(TaskPriority::BACKGROUND).MayBlock(),
906 tracker.task_latency_histograms_[static_cast<int>(
907 TaskPriority::BACKGROUND)][1]},
908 {TaskTraits()
909 .WithPriority(TaskPriority::BACKGROUND)
910 .WithBaseSyncPrimitives(),
911 tracker.task_latency_histograms_[static_cast<int>(
912 TaskPriority::BACKGROUND)][1]},
913 {TaskTraits().WithPriority(TaskPriority::USER_VISIBLE),
914 tracker.task_latency_histograms_[static_cast<int>(
915 TaskPriority::USER_VISIBLE)][0]},
916 {TaskTraits().WithPriority(TaskPriority::USER_VISIBLE).MayBlock(),
917 tracker.task_latency_histograms_[static_cast<int>(
918 TaskPriority::USER_VISIBLE)][1]},
919 {TaskTraits()
920 .WithPriority(TaskPriority::USER_VISIBLE)
921 .WithBaseSyncPrimitives(),
922 tracker.task_latency_histograms_[static_cast<int>(
923 TaskPriority::USER_VISIBLE)][1]},
924 {TaskTraits().WithPriority(TaskPriority::USER_BLOCKING),
925 tracker.task_latency_histograms_[static_cast<int>(
926 TaskPriority::USER_BLOCKING)][0]},
927 {TaskTraits().WithPriority(TaskPriority::USER_BLOCKING).MayBlock(),
928 tracker.task_latency_histograms_[static_cast<int>(
929 TaskPriority::USER_BLOCKING)][1]},
930 {TaskTraits()
931 .WithPriority(TaskPriority::USER_BLOCKING)
932 .WithBaseSyncPrimitives(),
933 tracker.task_latency_histograms_[static_cast<int>(
934 TaskPriority::USER_BLOCKING)][1]}};
gab 2017/01/05 19:25:46 Use HistogramTester instead of friending and using
fdoray 2017/01/05 20:13:38 Done.
935
936 for (const auto& test : tests) {
gab 2017/01/05 19:25:46 Interesting use of auto! I thought something was w
fdoray 2017/01/05 20:13:38 Acknowledged.
937 // Take a snapshot of the histogram so that the snapshot below only contains
938 // increments that occurred within this scope.
939 test.expected_histogram->SnapshotDelta();
940
941 auto task =
942 MakeUnique<Task>(FROM_HERE, Bind(&DoNothing), test.traits, TimeDelta());
943 ASSERT_TRUE(tracker.WillPostTask(task.get()));
944 EXPECT_TRUE(tracker.RunTask(std::move(task), SequenceToken::Create()));
945 EXPECT_EQ(1, test.expected_histogram->SnapshotDelta()->TotalCount());
946 }
947 }
948
888 } // namespace internal 949 } // namespace internal
889 } // namespace base 950 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698