From 5d0b477a95189d16d18dbd026b5792d0cd153e6b Mon Sep 17 00:00:00 2001 From: Richard Townsend Date: Wed, 6 Mar 2019 13:33:30 +0000 Subject: [PATCH] refactor: cc::LapTimer => base::LapTimer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes LapTimer (which provides a runs per second figure) accessible to base_perftests benchmarks by updating it and moving it into base/. Bug: 908966 Change-Id: I7913ea8e37b04d5309bed577dbdc54d98df971c5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1353950 Reviewed-by: Dan Erat Reviewed-by: Tibor Goldschwendt Reviewed-by: Trent Apted Reviewed-by: Sami Kyöstilä Reviewed-by: François Doray Reviewed-by: danakj Commit-Queue: Richard Townsend Cr-Commit-Position: refs/heads/master@{#638100} --- .../ash_background_filter_blur_perftest.cc | 4 +- base/BUILD.gn | 3 + base/timer/lap_timer.cc | 118 ++++++++++++++++++ base/timer/lap_timer.h | 87 +++++++++++++ base/timer/lap_timer_unittest.cc | 85 +++++++++++++ cc/animation/animation_host_perftest.cc | 4 +- cc/base/BUILD.gn | 2 - cc/base/DEPS | 4 - cc/base/lap_timer.cc | 105 ---------------- cc/base/lap_timer.h | 67 ---------- cc/base/rtree_perftest.cc | 4 +- .../rasterize_and_record_benchmark.cc | 13 +- .../rasterize_and_record_benchmark_impl.cc | 13 +- cc/layers/layer_perftest.cc | 4 +- cc/layers/picture_layer_impl_perftest.cc | 4 +- cc/paint/paint_op_perftest.cc | 4 +- cc/raster/raster_buffer_provider_perftest.cc | 4 +- cc/raster/task_graph_runner_perftest.cc | 4 +- cc/tiles/gpu_image_decode_cache_perftest.cc | 4 +- .../software_image_decode_cache_perftest.cc | 4 +- cc/tiles/tile_manager_perftest.cc | 4 +- cc/trees/layer_tree_host_common_perftest.cc | 12 +- cc/trees/layer_tree_host_perftest.cc | 12 +- chrome/browser/vr/text_perftest.cc | 6 +- .../viz/common/quads/draw_quad_perftest.cc | 4 +- .../viz/service/display/bsp_tree_perftest.cc | 6 +- .../viz/service/display/display_perftest.cc | 4 +- .../display/surface_aggregator_perftest.cc | 4 +- .../renderer/platform/scheduler/test/DEPS | 4 - .../test/queueing_time_estimator_perf_test.cc | 4 +- .../testing/shape_result_perf_test.cc | 5 +- .../testing/shaping_line_breaker_perf_test.cc | 5 +- ui/views/controls/label_perftest.cc | 4 +- 33 files changed, 359 insertions(+), 252 deletions(-) create mode 100644 base/timer/lap_timer.cc create mode 100644 base/timer/lap_timer.h create mode 100644 base/timer/lap_timer_unittest.cc delete mode 100644 cc/base/lap_timer.cc delete mode 100644 cc/base/lap_timer.h diff --git a/ash/perftests/ash_background_filter_blur_perftest.cc b/ash/perftests/ash_background_filter_blur_perftest.cc index c5edf2282b6ac8..1bbdf3a57d864d 100644 --- a/ash/perftests/ash_background_filter_blur_perftest.cc +++ b/ash/perftests/ash_background_filter_blur_perftest.cc @@ -6,7 +6,7 @@ #include "ash/shell.h" #include "ash/test/ash_test_base.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "testing/perf/perf_test.h" #include "ui/aura/window.h" #include "ui/compositor/test/draw_waiter_for_test.h" @@ -45,7 +45,7 @@ class AshBackgroundFilterBlurPerfTest : public AshTestBase { ui::Compositor* compositor_ = nullptr; - cc::LapTimer timer_; + base::LapTimer timer_; DISALLOW_COPY_AND_ASSIGN(AshBackgroundFilterBlurPerfTest); }; diff --git a/base/BUILD.gn b/base/BUILD.gn index f7791c42eb67dc..f0f3461961fe14 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -892,6 +892,8 @@ jumbo_component("base") { "timer/elapsed_timer.h", "timer/hi_res_timer_manager.h", "timer/hi_res_timer_manager_win.cc", + "timer/lap_timer.cc", + "timer/lap_timer.h", "timer/timer.cc", "timer/timer.h", "token.cc", @@ -2576,6 +2578,7 @@ test("base_unittests") { "time/time_unittest.cc", "time/time_win_unittest.cc", "timer/hi_res_timer_manager_unittest.cc", + "timer/lap_timer_unittest.cc", "timer/mock_timer_unittest.cc", "timer/timer_unittest.cc", "token_unittest.cc", diff --git a/base/timer/lap_timer.cc b/base/timer/lap_timer.cc new file mode 100644 index 00000000000000..3ff2465496f697 --- /dev/null +++ b/base/timer/lap_timer.cc @@ -0,0 +1,118 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/timer/lap_timer.h" +#include "base/logging.h" + +namespace base { + +namespace { + +// Default values. +constexpr TimeDelta kDefaultTimeLimit = TimeDelta::FromSeconds(3); +constexpr int kDefaultWarmupRuns = 5; +constexpr int kDefaultTimeCheckInterval = 10; + +} // namespace + +LapTimer::LapTimer(int warmup_laps, + TimeDelta time_limit, + int check_interval, + LapTimer::TimerMethod method) + : warmup_laps_(warmup_laps), + time_limit_(time_limit), + check_interval_(check_interval), + method_(method) { + DETACH_FROM_SEQUENCE(sequence_checker_); + DCHECK_GT(check_interval, 0); + Reset(); +} + +LapTimer::LapTimer(LapTimer::TimerMethod method) + : LapTimer(kDefaultWarmupRuns, + kDefaultTimeLimit, + kDefaultTimeCheckInterval, + method) {} + +void LapTimer::Reset() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + if (ThreadTicks::IsSupported() && method_ == TimerMethod::kUseThreadTicks) + ThreadTicks::WaitUntilInitialized(); + num_laps_ = 0; + remaining_warmups_ = warmup_laps_; + remaining_no_check_laps_ = check_interval_; + Start(); +} + +void LapTimer::Start() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK_EQ(num_laps_, 0); + // last_timed_ variables are initialized here (instead of in the constructor) + // because not all platforms support ThreadTicks. + if (method_ == TimerMethod::kUseThreadTicks) { + start_thread_ticks_ = ThreadTicks::Now(); + last_timed_lap_end_thread_ticks_ = ThreadTicks::Now(); + } else { + start_time_ticks_ = TimeTicks::Now(); + last_timed_lap_end_ticks_ = TimeTicks::Now(); + } +} + +bool LapTimer::IsWarmedUp() const { + return remaining_warmups_ <= 0; +} + +void LapTimer::NextLap() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK(!start_thread_ticks_.is_null() || !start_time_ticks_.is_null()); + if (!IsWarmedUp()) { + --remaining_warmups_; + if (IsWarmedUp()) { + Start(); + } + return; + } + ++num_laps_; + --remaining_no_check_laps_; + if (!remaining_no_check_laps_) { + if (method_ == TimerMethod::kUseTimeTicks) { + last_timed_lap_end_ticks_ = TimeTicks::Now(); + } else { + last_timed_lap_end_thread_ticks_ = ThreadTicks::Now(); + } + remaining_no_check_laps_ = check_interval_; + } +} + +TimeDelta LapTimer::GetAccumulatedTime() const { + if (method_ == TimerMethod::kUseTimeTicks) { + return last_timed_lap_end_ticks_ - start_time_ticks_; + } + return last_timed_lap_end_thread_ticks_ - start_thread_ticks_; +} + +bool LapTimer::HasTimeLimitExpired() const { + return GetAccumulatedTime() >= time_limit_; +} + +bool LapTimer::HasTimedAllLaps() const { + return num_laps_ && !(num_laps_ % check_interval_); +} + +TimeDelta LapTimer::TimePerLap() const { + DCHECK(HasTimedAllLaps()); + DCHECK_GT(num_laps_, 0); + return GetAccumulatedTime() / num_laps_; +} + +float LapTimer::LapsPerSecond() const { + DCHECK(HasTimedAllLaps()); + DCHECK_GT(num_laps_, 0); + return num_laps_ / GetAccumulatedTime().InSecondsF(); +} + +int LapTimer::NumLaps() const { + return num_laps_; +} +} // namespace base diff --git a/base/timer/lap_timer.h b/base/timer/lap_timer.h new file mode 100644 index 00000000000000..c28a0df1db32d9 --- /dev/null +++ b/base/timer/lap_timer.h @@ -0,0 +1,87 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_TIMER_LAP_TIMER_H_ +#define BASE_TIMER_LAP_TIMER_H_ + +#include "base/base_export.h" +#include "base/macros.h" +#include "base/sequence_checker.h" +#include "base/time/time.h" + +namespace base { + +// LapTimer is used to calculate average times per "Lap" in perf tests. +// NextLap increments the lap counter, used in counting the per lap averages. +// If you initialize the LapTimer with a non zero |warmup_laps|, it will ignore +// the times for that many laps at the start. +// If you set the |time_limit| then you can use HasTimeLimitExpired() to see if +// the current accumulated time has crossed that threshold, with an optimization +// that it only tests this every |check_interval| laps. +// +// See base/timer/lap_timer_unittest.cc for a usage example. +// +class BASE_EXPORT LapTimer { + public: + enum class TimerMethod { + // Measures CPU time consumed by the thread running the LapTimer. + kUseThreadTicks, + // Measures elapsed wall time (default). + kUseTimeTicks + }; + + LapTimer(int warmup_laps, + TimeDelta time_limit, + int check_interval, + TimerMethod timing_method = TimerMethod::kUseTimeTicks); + // Create LapTimer with sensible default values. + LapTimer(TimerMethod timing_method = TimerMethod::kUseTimeTicks); + // Sets the timer back to its starting state. + void Reset(); + // Sets the start point to now. + void Start(); + // Returns true if there are no more warmup laps to do. + bool IsWarmedUp() const; + // Advance the lap counter and update the accumulated time. + // The accumulated time is only updated every check_interval laps. + // If accumulating then the start point will also be updated. + void NextLap(); + // Returns true if the stored time has exceeded the time limit specified. + // May cause a call to Store(). + bool HasTimeLimitExpired() const; + // The average time taken per lap. + TimeDelta TimePerLap() const; + // The number of laps per second. + float LapsPerSecond() const; + // The number of laps recorded. + int NumLaps() const; + + private: + // Returns true if all lap times have been timed. Only true every n'th + // lap, where n = check_interval. + bool HasTimedAllLaps() const; + // Returns the current accumulated time. + TimeDelta GetAccumulatedTime() const; + + const int warmup_laps_; + const TimeDelta time_limit_; + const int check_interval_; + const TimerMethod method_; + + ThreadTicks start_thread_ticks_; + TimeTicks start_time_ticks_; + + ThreadTicks last_timed_lap_end_thread_ticks_; + TimeTicks last_timed_lap_end_ticks_; + + int num_laps_; + int remaining_warmups_ = 0; + int remaining_no_check_laps_ = 0; + + SEQUENCE_CHECKER(sequence_checker_); + DISALLOW_COPY_AND_ASSIGN(LapTimer); +}; +} // namespace base + +#endif // BASE_TIMER_LAP_TIMER_H_ diff --git a/base/timer/lap_timer_unittest.cc b/base/timer/lap_timer_unittest.cc new file mode 100644 index 00000000000000..b45ab393dabf9a --- /dev/null +++ b/base/timer/lap_timer_unittest.cc @@ -0,0 +1,85 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/timer/lap_timer.h" +#include "base/test/scoped_task_environment.h" +#include "base/time/time.h" +#include "build/build_config.h" +#include "testing/gtest/include/gtest/gtest.h" + +// This file contains a minimal unit test for LapTimer, used for benchmarking. +// This file is supposed to match closely with the example code, documented in +// lap_timer.h. Please update that documentation if you need to change things. + +namespace base { + +namespace test { + +namespace { + +constexpr base::TimeDelta kTimeLimit = base::TimeDelta::FromMilliseconds(15); +constexpr base::TimeDelta kTimeAdvance = base::TimeDelta::FromMilliseconds(1); +constexpr int kWarmupRuns = 5; +constexpr int kTimeCheckInterval = 10; + +} // namespace + +TEST(LapTimer, UsageExample) { + ScopedTaskEnvironment scoped_task_environment( + ScopedTaskEnvironment::MainThreadType::MOCK_TIME, + ScopedTaskEnvironment::NowSource::MAIN_THREAD_MOCK_TIME); + + // Advance time a little bit so that TimeTicks::Now().is_null() becomes false. + scoped_task_environment.FastForwardBy(kTimeAdvance); + + LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval); + + EXPECT_FALSE(timer.HasTimeLimitExpired()); + EXPECT_FALSE(timer.IsWarmedUp()); + + do { + scoped_task_environment.FastForwardBy(kTimeAdvance); + timer.NextLap(); + } while (!timer.HasTimeLimitExpired()); + + EXPECT_NEAR(timer.LapsPerSecond(), 1000, 0.1); + EXPECT_NEAR(timer.TimePerLap().InMillisecondsF(), 1.0f, 0.1); + // Output number of laps is 20, because the warm up runs are ignored and the + // timer is only checked every kTimeInterval laps. + EXPECT_EQ(timer.NumLaps(), 20); + + EXPECT_TRUE(timer.HasTimeLimitExpired()); + EXPECT_TRUE(timer.IsWarmedUp()); +} + +#if !defined(OS_IOS) +// iOS simulator does not support using ThreadTicks. +TEST(LapTimer, ThreadTicksUsageExample) { + ScopedTaskEnvironment scoped_task_environment( + ScopedTaskEnvironment::MainThreadType::MOCK_TIME, + ScopedTaskEnvironment::NowSource::MAIN_THREAD_MOCK_TIME); + LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval, + LapTimer::TimerMethod::kUseThreadTicks); + + EXPECT_FALSE(timer.HasTimeLimitExpired()); + EXPECT_FALSE(timer.IsWarmedUp()); + + do { + scoped_task_environment.FastForwardBy(kTimeAdvance); + timer.NextLap(); + } while (!timer.HasTimeLimitExpired()); + + // Because advancing the ScopedTaskEnvironment time won't affect the + // ThreadTicks, laps will be much faster than the regular UsageExample. + EXPECT_GT(timer.LapsPerSecond(), 1000); + EXPECT_LT(timer.TimePerLap().InMillisecondsF(), 1.0f); + EXPECT_GT(timer.NumLaps(), 20); + + EXPECT_TRUE(timer.HasTimeLimitExpired()); + EXPECT_TRUE(timer.IsWarmedUp()); +} +#endif + +} // namespace test +} // namespace base diff --git a/cc/animation/animation_host_perftest.cc b/cc/animation/animation_host_perftest.cc index afadb46eba4f5a..3bd25688d508cf 100644 --- a/cc/animation/animation_host_perftest.cc +++ b/cc/animation/animation_host_perftest.cc @@ -5,11 +5,11 @@ #include "cc/animation/animation_host.h" #include "base/threading/thread_task_runner_handle.h" +#include "base/timer/lap_timer.h" #include "cc/animation/animation_id_provider.h" #include "cc/animation/animation_timeline.h" #include "cc/animation/keyframe_effect.h" #include "cc/animation/single_keyframe_effect_animation.h" -#include "cc/base/lap_timer.h" #include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_layer_tree_host_client.h" @@ -149,7 +149,7 @@ class AnimationHostPerfTest : public testing::Test { int first_animation_id_; int last_animation_id_; - LapTimer timer_; + base::LapTimer timer_; TestTaskGraphRunner task_graph_runner_; }; diff --git a/cc/base/BUILD.gn b/cc/base/BUILD.gn index 8f8a1845ae0e9a..9546cd277ad0bd 100644 --- a/cc/base/BUILD.gn +++ b/cc/base/BUILD.gn @@ -20,8 +20,6 @@ component("base") { "index_rect.h", "invalidation_region.cc", "invalidation_region.h", - "lap_timer.cc", - "lap_timer.h", "list_container.h", "list_container_helper.cc", "list_container_helper.h", diff --git a/cc/base/DEPS b/cc/base/DEPS index 1bcb1a18c2fc0e..909b4a27346e4d 100644 --- a/cc/base/DEPS +++ b/cc/base/DEPS @@ -9,8 +9,4 @@ specific_include_rules = { ".*unittest\.cc": [ "+cc/test", ], - # Allow lap_timer.h for perftests - ".*perftest\.cc": [ - "+cc/debug/lap_timer.h", - ], } diff --git a/cc/base/lap_timer.cc b/cc/base/lap_timer.cc deleted file mode 100644 index 42335a8cce0862..00000000000000 --- a/cc/base/lap_timer.cc +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "cc/base/lap_timer.h" - -#include "base/logging.h" - -namespace cc { - -namespace { - -// Returns the offset from the origin from the ThreadTicks time source. -// TimeTicks is used as a fallback if ThreadTicks is not available on the -// current platform. -base::TimeDelta Now() { - return base::ThreadTicks::IsSupported() - ? base::ThreadTicks::Now().since_origin() - : base::TimeTicks::Now().since_origin(); -} - -// Default values. -static const int kTimeLimitMillis = 3000; -static const int kWarmupRuns = 5; -static const int kTimeCheckInterval = 10; - -} // namespace - -LapTimer::LapTimer(int warmup_laps, - base::TimeDelta time_limit, - int check_interval) - : warmup_laps_(warmup_laps), - remaining_warmups_(0), - remaining_no_check_laps_(0), - time_limit_(time_limit), - check_interval_(check_interval) { - DCHECK_GT(check_interval, 0); - Reset(); -} - -LapTimer::LapTimer() - : LapTimer(kWarmupRuns, - base::TimeDelta::FromMilliseconds(kTimeLimitMillis), - kTimeCheckInterval) { - if (base::ThreadTicks::IsSupported()) - base::ThreadTicks::WaitUntilInitialized(); -} - -void LapTimer::Reset() { - accumulator_ = base::TimeDelta(); - num_laps_ = 0; - remaining_warmups_ = warmup_laps_; - remaining_no_check_laps_ = check_interval_; - Start(); -} - -void LapTimer::Start() { - start_time_ = Now(); -} - -bool LapTimer::IsWarmedUp() { - return remaining_warmups_ <= 0; -} - -void LapTimer::NextLap() { - if (!IsWarmedUp()) { - --remaining_warmups_; - if (IsWarmedUp()) { - Start(); - } - return; - } - ++num_laps_; - --remaining_no_check_laps_; - if (!remaining_no_check_laps_) { - base::TimeDelta now = Now(); - accumulator_ += now - start_time_; - start_time_ = now; - remaining_no_check_laps_ = check_interval_; - } -} - -bool LapTimer::HasTimeLimitExpired() { - return accumulator_ >= time_limit_; -} - -bool LapTimer::HasTimedAllLaps() { - return !(num_laps_ % check_interval_); -} - -float LapTimer::MsPerLap() { - DCHECK(HasTimedAllLaps()); - return accumulator_.InMillisecondsF() / num_laps_; -} - -float LapTimer::LapsPerSecond() { - DCHECK(HasTimedAllLaps()); - return num_laps_ / accumulator_.InSecondsF(); -} - -int LapTimer::NumLaps() { - return num_laps_; -} - -} // namespace cc diff --git a/cc/base/lap_timer.h b/cc/base/lap_timer.h deleted file mode 100644 index 5b27e2578547b7..00000000000000 --- a/cc/base/lap_timer.h +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CC_BASE_LAP_TIMER_H_ -#define CC_BASE_LAP_TIMER_H_ - -#include "base/macros.h" -#include "base/time/time.h" -#include "cc/base/base_export.h" - -namespace cc { - -// LapTimer is used to calculate average times per "Lap" in perf tests. -// Current() reports the time since the last call to Start(). -// Store() adds the time since the last call to Start() to the accumulator, and -// resets the start time to now. Stored() returns the accumulated time. -// NextLap increments the lap counter, used in counting the per lap averages. -// If you initialize the LapTimer with a non zero warmup_laps, it will ignore -// the times for that many laps at the start. -// If you set the time_limit then you can use HasTimeLimitExpired() to see if -// the current accumulated time has crossed that threshold, with an optimization -// that it only tests this every check_interval laps. -class CC_BASE_EXPORT LapTimer { - public: - LapTimer(int warmup_laps, base::TimeDelta time_limit, int check_interval); - // Create LapTimer with sensible default values. - LapTimer(); - // Resets the timer back to it's starting state. - void Reset(); - // Sets the start point to now. - void Start(); - // Returns true if there are no more warmup laps to do. - bool IsWarmedUp(); - // Advance the lap counter and update the accumulated time. - // The accumulated time is only updated every check_interval laps. - // If accumulating then the start point will also be updated. - void NextLap(); - // Returns true if the stored time has exceeded the time limit specified. - // May cause a call to Store(). - bool HasTimeLimitExpired(); - // Returns true if all lap times have been timed. Only true every n'th - // lap, where n = check_interval. - bool HasTimedAllLaps(); - // The average milliseconds per lap. - float MsPerLap(); - // The number of laps per second. - float LapsPerSecond(); - // The number of laps recorded. - int NumLaps(); - - private: - base::TimeDelta start_time_; - base::TimeDelta accumulator_; - int num_laps_; - int warmup_laps_; - int remaining_warmups_; - int remaining_no_check_laps_; - base::TimeDelta time_limit_; - int check_interval_; - - DISALLOW_COPY_AND_ASSIGN(LapTimer); -}; - -} // namespace cc - -#endif // CC_BASE_LAP_TIMER_H_ diff --git a/cc/base/rtree_perftest.cc b/cc/base/rtree_perftest.cc index 70d44bcd8432c9..3b12bf594f76a9 100644 --- a/cc/base/rtree_perftest.cc +++ b/cc/base/rtree_perftest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "cc/base/rtree.h" #include "testing/gtest/include/gtest/gtest.h" @@ -85,7 +85,7 @@ class RTreePerfTest : public testing::Test { } protected: - LapTimer timer_; + base::LapTimer timer_; }; TEST_F(RTreePerfTest, Construct) { diff --git a/cc/benchmarks/rasterize_and_record_benchmark.cc b/cc/benchmarks/rasterize_and_record_benchmark.cc index 4b78bfd3b81593..844f66aef1dd40 100644 --- a/cc/benchmarks/rasterize_and_record_benchmark.cc +++ b/cc/benchmarks/rasterize_and_record_benchmark.cc @@ -13,8 +13,8 @@ #include "base/bind.h" #include "base/memory/ptr_util.h" #include "base/strings/stringprintf.h" +#include "base/timer/lap_timer.h" #include "base/values.h" -#include "cc/base/lap_timer.h" #include "cc/benchmarks/rasterize_and_record_benchmark_impl.h" #include "cc/layers/content_layer_client.h" #include "cc/layers/layer.h" @@ -31,7 +31,7 @@ namespace { const int kDefaultRecordRepeatCount = 100; -// Parameters for LapTimer. +// Parameters for base::LapTimer. const int kTimeLimitMillis = 1; const int kWarmupRuns = 0; const int kTimeCheckInterval = 1; @@ -158,9 +158,9 @@ void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { for (int i = 0; i < record_repeat_count_; ++i) { // Run for a minimum amount of time to avoid problems with timer // quantization when the layer is very small. - LapTimer timer(kWarmupRuns, - base::TimeDelta::FromMilliseconds(kTimeLimitMillis), - kTimeCheckInterval); + base::LapTimer timer(kWarmupRuns, + base::TimeDelta::FromMilliseconds(kTimeLimitMillis), + kTimeCheckInterval); do { display_list = painter->PaintContentsToDisplayList(painting_control); @@ -179,8 +179,7 @@ void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { timer.NextLap(); } while (!timer.HasTimeLimitExpired()); - base::TimeDelta duration = - base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); + base::TimeDelta duration = timer.TimePerLap(); if (duration < min_time) min_time = duration; } diff --git a/cc/benchmarks/rasterize_and_record_benchmark_impl.cc b/cc/benchmarks/rasterize_and_record_benchmark_impl.cc index d3652f0dba9b89..cf7f706eb87948 100644 --- a/cc/benchmarks/rasterize_and_record_benchmark_impl.cc +++ b/cc/benchmarks/rasterize_and_record_benchmark_impl.cc @@ -9,8 +9,8 @@ #include #include +#include "base/timer/lap_timer.h" #include "base/values.h" -#include "cc/base/lap_timer.h" #include "cc/layers/layer_impl.h" #include "cc/layers/picture_layer_impl.h" #include "cc/raster/playback_image_provider.h" @@ -34,7 +34,7 @@ void RunBenchmark(RasterSource* raster_source, size_t repeat_count, base::TimeDelta* min_time, bool* is_solid_color) { - // Parameters for LapTimer. + // Parameters for base::LapTimer. const int kTimeLimitMillis = 1; const int kWarmupRuns = 0; const int kTimeCheckInterval = 1; @@ -43,9 +43,9 @@ void RunBenchmark(RasterSource* raster_source, for (size_t i = 0; i < repeat_count; ++i) { // Run for a minimum amount of time to avoid problems with timer // quantization when the layer is very small. - LapTimer timer(kWarmupRuns, - base::TimeDelta::FromMilliseconds(kTimeLimitMillis), - kTimeCheckInterval); + base::LapTimer timer(kWarmupRuns, + base::TimeDelta::FromMilliseconds(kTimeLimitMillis), + kTimeCheckInterval); SkColor color = SK_ColorTRANSPARENT; gfx::Rect layer_rect = gfx::ScaleToEnclosingRect(content_rect, 1.f / contents_scale); @@ -78,8 +78,7 @@ void RunBenchmark(RasterSource* raster_source, timer.NextLap(); } while (!timer.HasTimeLimitExpired()); - base::TimeDelta duration = - base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); + base::TimeDelta duration = timer.TimePerLap(); if (duration < *min_time) *min_time = duration; } diff --git a/cc/layers/layer_perftest.cc b/cc/layers/layer_perftest.cc index a0bee528b4af6c..c2171885cbbc7c 100644 --- a/cc/layers/layer_perftest.cc +++ b/cc/layers/layer_perftest.cc @@ -5,8 +5,8 @@ #include "cc/layers/layer.h" #include "base/threading/thread_task_runner_handle.h" +#include "base/timer/lap_timer.h" #include "cc/animation/animation_host.h" -#include "cc/base/lap_timer.h" #include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_layer_tree_host_client.h" @@ -53,7 +53,7 @@ class LayerPerfTest : public testing::Test { FakeLayerTreeHostClient fake_client_; std::unique_ptr animation_host_; std::unique_ptr layer_tree_host_; - LapTimer timer_; + base::LapTimer timer_; }; TEST_F(LayerPerfTest, PushPropertiesTo) { diff --git a/cc/layers/picture_layer_impl_perftest.cc b/cc/layers/picture_layer_impl_perftest.cc index 36425eb5e5a39f..281beab9f1d6d8 100644 --- a/cc/layers/picture_layer_impl_perftest.cc +++ b/cc/layers/picture_layer_impl_perftest.cc @@ -6,7 +6,7 @@ #include "base/macros.h" #include "base/threading/thread_task_runner_handle.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_frame_sink.h" #include "cc/test/fake_layer_tree_host_impl.h" @@ -174,7 +174,7 @@ class PictureLayerImplPerfTest : public testing::Test { std::unique_ptr layer_tree_frame_sink_; FakeLayerTreeHostImpl host_impl_; FakePictureLayerImpl* pending_layer_; - LapTimer timer_; + base::LapTimer timer_; private: DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest); diff --git a/cc/paint/paint_op_perftest.cc b/cc/paint/paint_op_perftest.cc index d137118dcf058a..6dacf3ebadfa26 100644 --- a/cc/paint/paint_op_perftest.cc +++ b/cc/paint/paint_op_perftest.cc @@ -6,7 +6,7 @@ #include "base/test/launcher/unit_test_launcher.h" #include "base/test/test_suite.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "cc/paint/paint_op_buffer.h" #include "cc/paint/paint_op_buffer_serializer.h" #include "cc/test/test_options_provider.h" @@ -104,7 +104,7 @@ class PaintOpPerfTest : public testing::Test { } protected: - LapTimer timer_; + base::LapTimer timer_; std::unique_ptr serialized_data_; std::unique_ptr deserialized_data_; }; diff --git a/cc/raster/raster_buffer_provider_perftest.cc b/cc/raster/raster_buffer_provider_perftest.cc index dc5fd57eee09c2..6eb36031837c51 100644 --- a/cc/raster/raster_buffer_provider_perftest.cc +++ b/cc/raster/raster_buffer_provider_perftest.cc @@ -8,8 +8,8 @@ #include "base/macros.h" #include "base/test/test_simple_task_runner.h" #include "base/time/time.h" +#include "base/timer/lap_timer.h" #include "build/build_config.h" -#include "cc/base/lap_timer.h" #include "cc/raster/bitmap_raster_buffer_provider.h" #include "cc/raster/gpu_raster_buffer_provider.h" #include "cc/raster/one_copy_raster_buffer_provider.h" @@ -340,7 +340,7 @@ class RasterBufferProviderPerfTestBase { scoped_refptr task_runner_; std::unique_ptr resource_pool_; std::unique_ptr task_graph_runner_; - LapTimer timer_; + base::LapTimer timer_; }; class RasterBufferProviderPerfTest diff --git a/cc/raster/task_graph_runner_perftest.cc b/cc/raster/task_graph_runner_perftest.cc index 8a674517fad340..36ee90fab57e12 100644 --- a/cc/raster/task_graph_runner_perftest.cc +++ b/cc/raster/task_graph_runner_perftest.cc @@ -11,8 +11,8 @@ #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/time/time.h" +#include "base/timer/lap_timer.h" #include "cc/base/completion_event.h" -#include "cc/base/lap_timer.h" #include "cc/raster/synchronous_task_graph_runner.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/perf/perf_test.h" @@ -274,7 +274,7 @@ class TaskGraphRunnerPerfTest : public testing::Test { // minimal additional complexity over the TaskGraphWorkQueue helpers. std::unique_ptr task_graph_runner_; NamespaceToken namespace_token_; - LapTimer timer_; + base::LapTimer timer_; }; TEST_F(TaskGraphRunnerPerfTest, BuildTaskGraph) { diff --git a/cc/tiles/gpu_image_decode_cache_perftest.cc b/cc/tiles/gpu_image_decode_cache_perftest.cc index 819d16bb2d972a..5d0f2e62871530 100644 --- a/cc/tiles/gpu_image_decode_cache_perftest.cc +++ b/cc/tiles/gpu_image_decode_cache_perftest.cc @@ -4,7 +4,7 @@ #include -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "cc/paint/draw_image.h" #include "cc/paint/paint_image_builder.h" #include "cc/raster/tile_task.h" @@ -87,7 +87,7 @@ class GpuImageDecodeCachePerfTest } } - LapTimer timer_; + base::LapTimer timer_; scoped_refptr context_provider_; std::unique_ptr cache_; }; diff --git a/cc/tiles/software_image_decode_cache_perftest.cc b/cc/tiles/software_image_decode_cache_perftest.cc index 5f693179b1cc51..f873c9774bbaf4 100644 --- a/cc/tiles/software_image_decode_cache_perftest.cc +++ b/cc/tiles/software_image_decode_cache_perftest.cc @@ -4,7 +4,7 @@ #include -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "cc/paint/draw_image.h" #include "cc/paint/paint_image_builder.h" #include "cc/raster/tile_task.h" @@ -82,7 +82,7 @@ class SoftwareImageDecodeCachePerfTest : public testing::Test { } private: - LapTimer timer_; + base::LapTimer timer_; }; TEST_F(SoftwareImageDecodeCachePerfTest, FromDrawImage) { diff --git a/cc/tiles/tile_manager_perftest.cc b/cc/tiles/tile_manager_perftest.cc index 8a875845f9b232..e6334235e4dcab 100644 --- a/cc/tiles/tile_manager_perftest.cc +++ b/cc/tiles/tile_manager_perftest.cc @@ -10,7 +10,7 @@ #include "base/stl_util.h" #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "cc/raster/raster_buffer.h" #include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_frame_sink.h" @@ -292,7 +292,7 @@ class TileManagerPerfTest : public TestLayerTreeHostBase { TileManager* tile_manager() { return host_impl()->tile_manager(); } protected: - LapTimer timer_; + base::LapTimer timer_; }; // Failing. https://crbug.com/792995 diff --git a/cc/trees/layer_tree_host_common_perftest.cc b/cc/trees/layer_tree_host_common_perftest.cc index 561cdd1ade5748..2c1c4ab1d8262c 100644 --- a/cc/trees/layer_tree_host_common_perftest.cc +++ b/cc/trees/layer_tree_host_common_perftest.cc @@ -13,7 +13,7 @@ #include "base/strings/string_piece.h" #include "base/threading/thread.h" #include "base/time/time.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "cc/layers/layer.h" #include "cc/test/fake_content_layer_client.h" #include "cc/test/fake_layer_tree_host_client.h" @@ -62,17 +62,13 @@ class LayerTreeHostCommonPerfTest : public LayerTreeTest { void AfterTest() override { CHECK(!test_name_.empty()) << "Must SetTestName() before TearDown()."; - perf_test::PrintResult("calc_draw_props_time", - "", - test_name_, - 1000 * timer_.MsPerLap(), - "us", - true); + perf_test::PrintResult("calc_draw_props_time", "", test_name_, + timer_.TimePerLap().InMicrosecondsF(), "us", true); } protected: FakeContentLayerClient content_layer_client_; - LapTimer timer_; + base::LapTimer timer_; std::string test_name_; std::string json_; }; diff --git a/cc/trees/layer_tree_host_perftest.cc b/cc/trees/layer_tree_host_perftest.cc index 0e2f8b7319e4e5..35953305fc8f9b 100644 --- a/cc/trees/layer_tree_host_perftest.cc +++ b/cc/trees/layer_tree_host_perftest.cc @@ -14,7 +14,7 @@ #include "base/path_service.h" #include "base/strings/string_piece.h" #include "base/time/time.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "cc/layers/nine_patch_layer.h" #include "cc/layers/solid_color_layer.h" #include "cc/layers/texture_layer.h" @@ -108,16 +108,18 @@ class LayerTreeHostPerfTest : public LayerTreeTest { void AfterTest() override { CHECK(!test_name_.empty()) << "Must SetTestName() before AfterTest()."; perf_test::PrintResult("layer_tree_host_frame_time", "", test_name_, - 1000 * draw_timer_.MsPerLap(), "us", true); + draw_timer_.TimePerLap().InMicrosecondsF(), "us", + true); if (measure_commit_cost_) { perf_test::PrintResult("layer_tree_host_commit_time", "", test_name_, - 1000 * commit_timer_.MsPerLap(), "us", true); + commit_timer_.TimePerLap().InMicrosecondsF(), "us", + true); } } protected: - LapTimer draw_timer_; - LapTimer commit_timer_; + base::LapTimer draw_timer_; + base::LapTimer commit_timer_; std::string test_name_; FakeContentLayerClient fake_content_layer_client_; diff --git a/chrome/browser/vr/text_perftest.cc b/chrome/browser/vr/text_perftest.cc index 172d674b7975b7..e24071e0d89bbf 100644 --- a/chrome/browser/vr/text_perftest.cc +++ b/chrome/browser/vr/text_perftest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "base/strings/utf_string_conversions.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "chrome/browser/vr/elements/text.h" #include "chrome/browser/vr/skia_surface_provider_factory.h" #include "chrome/browser/vr/test/constants.h" @@ -43,7 +43,7 @@ class TextPerfTest : public testing::Test { protected: void PrintResults(const std::string& name) { perf_test::PrintResult("TextPerfTest", ".render_time_avg", name, - timer_.MsPerLap(), "ms", true); + timer_.TimePerLap().InMillisecondsF(), "ms", true); perf_test::PrintResult("TextPerfTest", ".number_of_runs", name, static_cast(timer_.NumLaps()), "runs", true); } @@ -57,7 +57,7 @@ class TextPerfTest : public testing::Test { } std::unique_ptr text_element_; - cc::LapTimer timer_; + base::LapTimer timer_; private: std::unique_ptr provider_; diff --git a/components/viz/common/quads/draw_quad_perftest.cc b/components/viz/common/quads/draw_quad_perftest.cc index 8e2353285c9a11..6759fde24696ba 100644 --- a/components/viz/common/quads/draw_quad_perftest.cc +++ b/components/viz/common/quads/draw_quad_perftest.cc @@ -6,7 +6,7 @@ #include "base/bind.h" #include "base/time/time.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "components/viz/common/quads/draw_quad.h" #include "components/viz/common/quads/render_pass.h" #include "components/viz/common/quads/texture_draw_quad.h" @@ -104,7 +104,7 @@ class DrawQuadPerfTest : public testing::Test { private: std::unique_ptr render_pass_; SharedQuadState* shared_state_; - cc::LapTimer timer_; + base::LapTimer timer_; }; TEST_F(DrawQuadPerfTest, IterateResources) { diff --git a/components/viz/service/display/bsp_tree_perftest.cc b/components/viz/service/display/bsp_tree_perftest.cc index 29efb30ae91c50..2895bd10070360 100644 --- a/components/viz/service/display/bsp_tree_perftest.cc +++ b/components/viz/service/display/bsp_tree_perftest.cc @@ -14,7 +14,7 @@ #include "base/strings/string_piece.h" #include "base/threading/thread.h" #include "base/time/time.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "cc/layers/layer.h" #include "cc/test/fake_content_layer_client.h" #include "cc/test/fake_layer_tree_host_client.h" @@ -135,12 +135,12 @@ class BspTreePerfTest : public cc::LayerTreeTest { void AfterTest() override { CHECK(!test_name_.empty()) << "Must SetTestName() before TearDown()."; perf_test::PrintResult("calc_draw_props_time", "", test_name_, - 1000 * timer_.MsPerLap(), "us", true); + timer_.TimePerLap().InMicrosecondsF(), "us", true); } private: cc::FakeContentLayerClient content_layer_client_; - cc::LapTimer timer_; + base::LapTimer timer_; std::string test_name_; std::string json_; cc::LayerImplList base_list_; diff --git a/components/viz/service/display/display_perftest.cc b/components/viz/service/display/display_perftest.cc index dc09344a333a48..d6f91b74fd9082 100644 --- a/components/viz/service/display/display_perftest.cc +++ b/components/viz/service/display/display_perftest.cc @@ -7,7 +7,7 @@ #include "base/bind.h" #include "base/test/null_task_runner.h" #include "base/time/time.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "components/viz/common/display/renderer_settings.h" #include "components/viz/common/quads/compositor_frame.h" #include "components/viz/common/quads/draw_quad.h" @@ -290,7 +290,7 @@ class RemoveOverdrawQuadPerfTest : public testing::Test { private: CompositorFrame frame_; - cc::LapTimer timer_; + base::LapTimer timer_; StubBeginFrameSource begin_frame_source_; scoped_refptr task_runner_; ServerSharedBitmapManager bitmap_manager_; diff --git a/components/viz/service/display/surface_aggregator_perftest.cc b/components/viz/service/display/surface_aggregator_perftest.cc index 2975828aa8c74a..95539d512178b1 100644 --- a/components/viz/service/display/surface_aggregator_perftest.cc +++ b/components/viz/service/display/surface_aggregator_perftest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "cc/test/fake_output_surface_client.h" #include "components/viz/common/frame_sinks/begin_frame_args.h" #include "components/viz/common/quads/compositor_frame.h" @@ -157,7 +157,7 @@ class SurfaceAggregatorPerfTest : public testing::Test { scoped_refptr context_provider_; std::unique_ptr resource_provider_; std::unique_ptr aggregator_; - cc::LapTimer timer_; + base::LapTimer timer_; }; TEST_F(SurfaceAggregatorPerfTest, ManySurfacesOpaque) { diff --git a/third_party/blink/renderer/platform/scheduler/test/DEPS b/third_party/blink/renderer/platform/scheduler/test/DEPS index f97ca86f638d2e..545b3526e982c9 100644 --- a/third_party/blink/renderer/platform/scheduler/test/DEPS +++ b/third_party/blink/renderer/platform/scheduler/test/DEPS @@ -1,7 +1,3 @@ -include_rules = [ - "+cc/base/lap_timer.h" -] - specific_include_rules = { "renderer_scheduler_test_support\.cc": [ "+base/task/sequence_manager/test/lazy_thread_controller_for_test.h", diff --git a/third_party/blink/renderer/platform/scheduler/test/queueing_time_estimator_perf_test.cc b/third_party/blink/renderer/platform/scheduler/test/queueing_time_estimator_perf_test.cc index 6cd179e03eaf9c..59a75eeb0db708 100644 --- a/third_party/blink/renderer/platform/scheduler/test/queueing_time_estimator_perf_test.cc +++ b/third_party/blink/renderer/platform/scheduler/test/queueing_time_estimator_perf_test.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/perf/perf_test.h" #include "third_party/blink/renderer/platform/scheduler/test/test_queueing_time_estimator_client.h" @@ -21,7 +21,7 @@ class QueueingTimeEstimatorTestPerfTest : public testing::Test { public: QueueingTimeEstimatorTestPerfTest() : timer_(kWarmupRuns, kTimeLimit, kCheckInterval) {} - cc::LapTimer timer_; + base::LapTimer timer_; base::TimeTicks time; TestQueueingTimeEstimatorClient client; }; diff --git a/third_party/blink/renderer/platform/testing/shape_result_perf_test.cc b/third_party/blink/renderer/platform/testing/shape_result_perf_test.cc index ce5241ccdae749..e635da9fce6256 100644 --- a/third_party/blink/renderer/platform/testing/shape_result_perf_test.cc +++ b/third_party/blink/renderer/platform/testing/shape_result_perf_test.cc @@ -3,8 +3,7 @@ // found in the LICENSE file. #include "base/time/time.h" -#include "cc/base/lap_timer.h" - +#include "base/timer/lap_timer.h" #include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/perf/perf_test.h" @@ -58,7 +57,7 @@ class ShapeResultPerfTest { {roboto, "third_party/Roboto/roboto-regular.woff2"}, }; - cc::LapTimer timer; + base::LapTimer timer; }; class OffsetForPositionPerfTest : public ShapeResultPerfTest, diff --git a/third_party/blink/renderer/platform/testing/shaping_line_breaker_perf_test.cc b/third_party/blink/renderer/platform/testing/shaping_line_breaker_perf_test.cc index 9ce988029fd690..c265e21a38e1dc 100644 --- a/third_party/blink/renderer/platform/testing/shaping_line_breaker_perf_test.cc +++ b/third_party/blink/renderer/platform/testing/shaping_line_breaker_perf_test.cc @@ -5,8 +5,9 @@ #include "third_party/blink/renderer/platform/fonts/shaping/shaping_line_breaker.h" #include + #include "base/time/time.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "third_party/blink/renderer/platform/fonts/font.h" #include "third_party/blink/renderer/platform/fonts/font_cache.h" #include "third_party/blink/renderer/platform/fonts/font_test_utilities.h" @@ -77,7 +78,7 @@ class ShapingLineBreakerPerfTest : public testing::Test { unsigned start_index = 0; unsigned num_glyphs = 0; hb_script_t script = HB_SCRIPT_INVALID; - cc::LapTimer timer_; + base::LapTimer timer_; }; TEST_F(ShapingLineBreakerPerfTest, ShapeLatinText) { diff --git a/ui/views/controls/label_perftest.cc b/ui/views/controls/label_perftest.cc index bd0094dfb6a364..e8b5c5936362d1 100644 --- a/ui/views/controls/label_perftest.cc +++ b/ui/views/controls/label_perftest.cc @@ -5,7 +5,7 @@ #include "ui/views/controls/label.h" #include "base/strings/utf_string_conversions.h" -#include "cc/base/lap_timer.h" +#include "base/timer/lap_timer.h" #include "testing/perf/perf_test.h" #include "ui/views/test/views_test_base.h" @@ -28,7 +28,7 @@ TEST_F(LabelPerfTest, GetPreferredSize) { // The time limit is unused. Use kLaps for the check interval so the time is // only measured once. - cc::LapTimer timer(kWarmupLaps, base::TimeDelta(), kLaps); + base::LapTimer timer(kWarmupLaps, base::TimeDelta(), kLaps); for (int i = 0; i < kLaps + kWarmupLaps; ++i) { label.SetText(i % 2 == 0 ? string1 : string2); label.GetPreferredSize();