From c2128fc809345d30b209c764399f72add9b26d9d Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 3 Oct 2018 17:22:33 -0700 Subject: [PATCH] Create a benchmarking target for the shell. (#6420) Also adds //flutter/benchmarking which, similar to //flutter/testing, allows for the creation of a benchmarking executable. This is also the target that contains benchmarking utilities. --- BUILD.gn | 1 + benchmarking/BUILD.gn | 26 ++++++ benchmarking/benchmarking.cc | 22 +++++ benchmarking/benchmarking.h | 33 +++++++ ci/licenses_golden/licenses_flutter | 129 ++++++++++++++-------------- shell/common/BUILD.gn | 47 +++++++--- shell/common/shell_benchmarks.cc | 80 +++++++++++++++++ 7 files changed, 264 insertions(+), 74 deletions(-) create mode 100644 benchmarking/BUILD.gn create mode 100644 benchmarking/benchmarking.cc create mode 100644 benchmarking/benchmarking.h create mode 100644 shell/common/shell_benchmarks.cc diff --git a/BUILD.gn b/BUILD.gn index 36cb322ca..59d85c477 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -38,6 +38,7 @@ group("flutter") { "$flutter_root/flow:flow_unittests", "$flutter_root/fml:fml_unittests", "$flutter_root/runtime:runtime_unittests", + "$flutter_root/shell/common:shell_benchmarks", "$flutter_root/shell/common:shell_unittests", "$flutter_root/shell/platform/embedder:embedder_unittests", "$flutter_root/synchronization:synchronization_unittests", diff --git a/benchmarking/BUILD.gn b/benchmarking/BUILD.gn new file mode 100644 index 000000000..7fa479c95 --- /dev/null +++ b/benchmarking/BUILD.gn @@ -0,0 +1,26 @@ +# Copyright 2018 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +config("benchmark_config") { + include_dirs = [ "//third_party/benchmark:benchmark_config" ] +} + +source_set("benchmarking") { + testonly = true + + sources = [ + "benchmarking.cc", + "benchmarking.h", + ] + + public_deps = [ + "$flutter_root/fml", + "//third_party/benchmark", + ] + + public_configs = [ + "$flutter_root:config", + ":benchmark_config", + ] +} diff --git a/benchmarking/benchmarking.cc b/benchmarking/benchmarking.cc new file mode 100644 index 000000000..12588208c --- /dev/null +++ b/benchmarking/benchmarking.cc @@ -0,0 +1,22 @@ +// Copyright 2018 The Flutter 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 "benchmarking.h" + +#include "flutter/fml/icu_util.h" + +namespace benchmarking { + +int Main(int argc, char** argv) { + benchmark::Initialize(&argc, argv); + fml::icu::InitializeICU("icudtl.dat"); + ::benchmark::RunSpecifiedBenchmarks(); + return 0; +} + +} // namespace benchmarking + +int main(int argc, char** argv) { + return benchmarking::Main(argc, argv); +} diff --git a/benchmarking/benchmarking.h b/benchmarking/benchmarking.h new file mode 100644 index 000000000..4bc8cd535 --- /dev/null +++ b/benchmarking/benchmarking.h @@ -0,0 +1,33 @@ +// Copyright 2018 The Flutter 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 FLUTTER_BENCHMARKING_BENCHMARKING_H_ +#define FLUTTER_BENCHMARKING_BENCHMARKING_H_ + +#include "benchmark/benchmark_api.h" + +namespace benchmarking { + +class ScopedPauseTiming { + public: + ScopedPauseTiming(::benchmark::State& state, bool enabled = true) + : state_(state), enabled_(enabled) { + if (enabled_) { + state_.PauseTiming(); + } + } + ~ScopedPauseTiming() { + if (enabled_) { + state_.ResumeTiming(); + } + } + + private: + ::benchmark::State& state_; + const bool enabled_; +}; + +} // namespace benchmarking + +#endif // FLUTTER_BENCHMARKING_BENCHMARKING_H_ diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 1fb930253..09f307de6 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -470,70 +470,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ==================================================================================================== LIBRARY: engine -ORIGIN: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart + ../../../LICENSE -TYPE: LicenseType.bsd -FILE: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart -FILE: ../../../flutter/fml/paths_unittests.cc -FILE: ../../../flutter/lib/ui/isolate_name_server.dart -FILE: ../../../flutter/lib/ui/painting/image_encoding.cc -FILE: ../../../flutter/lib/ui/painting/image_encoding.h -FILE: ../../../flutter/lib/ui/plugins.dart -FILE: ../../../flutter/lib/ui/semantics/custom_accessibility_action.cc -FILE: ../../../flutter/lib/ui/semantics/custom_accessibility_action.h -FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc -FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.h -FILE: ../../../flutter/shell/platform/android/apk_asset_provider.h -FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformView.java -FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewFactory.java -FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistry.java -FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistryImpl.java -FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java -FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java -FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java -FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java -FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterRunArguments.java -FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterCallbackCache.h -FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h -FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache.mm -FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache_Internal.h -FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm -FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h -FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm -FILE: ../../../flutter/shell/platform/darwin/ios/headless_platform_view_ios.h ----------------------------------------------------------------------------------------------------- -Copyright 2018 The Chromium Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -==================================================================================================== - -==================================================================================================== -LIBRARY: engine -ORIGIN: ../../../flutter/fml/platform/android/paths_android.h + ../../../LICENSE +ORIGIN: ../../../flutter/benchmarking/benchmarking.cc + ../../../LICENSE TYPE: LicenseType.bsd +FILE: ../../../flutter/benchmarking/benchmarking.cc +FILE: ../../../flutter/benchmarking/benchmarking.h FILE: ../../../flutter/fml/base32.cc FILE: ../../../flutter/fml/base32.h FILE: ../../../flutter/fml/base32_unittest.cc @@ -570,6 +510,7 @@ FILE: ../../../flutter/shell/common/isolate_configuration.cc FILE: ../../../flutter/shell/common/isolate_configuration.h FILE: ../../../flutter/shell/common/persistent_cache.cc FILE: ../../../flutter/shell/common/persistent_cache.h +FILE: ../../../flutter/shell/common/shell_benchmarks.cc FILE: ../../../flutter/shell/platform/android/android_shell_holder.cc FILE: ../../../flutter/shell/platform/android/android_shell_holder.h FILE: ../../../flutter/shell/platform/android/platform_message_response_android.cc @@ -615,6 +556,68 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ==================================================================================================== +==================================================================================================== +LIBRARY: engine +ORIGIN: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart + ../../../LICENSE +TYPE: LicenseType.bsd +FILE: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart +FILE: ../../../flutter/fml/paths_unittests.cc +FILE: ../../../flutter/lib/ui/isolate_name_server.dart +FILE: ../../../flutter/lib/ui/painting/image_encoding.cc +FILE: ../../../flutter/lib/ui/painting/image_encoding.h +FILE: ../../../flutter/lib/ui/plugins.dart +FILE: ../../../flutter/lib/ui/semantics/custom_accessibility_action.cc +FILE: ../../../flutter/lib/ui/semantics/custom_accessibility_action.h +FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc +FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.h +FILE: ../../../flutter/shell/platform/android/apk_asset_provider.h +FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformView.java +FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewFactory.java +FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistry.java +FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistryImpl.java +FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java +FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java +FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java +FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterRunArguments.java +FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterCallbackCache.h +FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h +FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache.mm +FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache_Internal.h +FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm +FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h +FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm +FILE: ../../../flutter/shell/platform/darwin/ios/headless_platform_view_ios.h +---------------------------------------------------------------------------------------------------- +Copyright 2018 The Chromium Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +==================================================================================================== + ==================================================================================================== LIBRARY: engine ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.h + ../../../LICENSE diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index 628cd30c5..578cb02f4 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -114,22 +114,47 @@ source_set("common") { public_configs = [ "$flutter_root:config" ] } -executable("shell_unittests") { - testonly = true +template("shell_host_executable") { + executable(target_name) { + testonly = true + deps = [] + + ldflags = [] + + forward_variables_from(invoker, "*") + + deps += [ + ":common", + "$flutter_root/fml", + "$flutter_root/lib/snapshot", + "//third_party/dart/runtime:libdart_jit", + "//third_party/skia", + "//third_party/tonic", + ] + + if (is_linux) { + ldflags += [ "-rdynamic" ] + } + } +} + +shell_host_executable("shell_unittests") { sources = [ "shell_unittests.cc", ] + deps = [ - ":common", - "$flutter_root/fml", - "$flutter_root/lib/snapshot", "$flutter_root/testing", - "//third_party/dart/runtime:libdart_jit", - "//third_party/skia", - "//third_party/tonic", ] - if (is_linux) { - ldflags = [ "-rdynamic" ] - } +} + +shell_host_executable("shell_benchmarks") { + sources = [ + "shell_benchmarks.cc", + ] + + deps = [ + "$flutter_root/benchmarking", + ] } diff --git a/shell/common/shell_benchmarks.cc b/shell/common/shell_benchmarks.cc new file mode 100644 index 000000000..9d26a068b --- /dev/null +++ b/shell/common/shell_benchmarks.cc @@ -0,0 +1,80 @@ +// Copyright 2018 The Flutter 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 "flutter/benchmarking/benchmarking.h" +#include "flutter/fml/logging.h" +#include "flutter/shell/common/shell.h" +#include "flutter/shell/common/thread_host.h" + +namespace shell { + +static void StartupAndShutdownShell(benchmark::State& state, + bool measure_startup, + bool measure_shutdown) { + std::unique_ptr shell; + std::unique_ptr thread_host; + { + benchmarking::ScopedPauseTiming pause(state, !measure_startup); + blink::Settings settings = {}; + settings.task_observer_add = [](intptr_t, fml::closure) {}; + settings.task_observer_remove = [](intptr_t) {}; + + // Measure the time it takes to setup the threads as well. + thread_host = std::make_unique( + "io.flutter.bench.", ThreadHost::Type::Platform | + ThreadHost::Type::GPU | ThreadHost::Type::IO | + ThreadHost::Type::UI); + + blink::TaskRunners task_runners( + "test", thread_host->platform_thread->GetTaskRunner(), + thread_host->gpu_thread->GetTaskRunner(), + thread_host->ui_thread->GetTaskRunner(), + thread_host->io_thread->GetTaskRunner()); + + shell = Shell::Create( + std::move(task_runners), settings, + [](Shell& shell) { + return std::make_unique(shell, shell.GetTaskRunners()); + }, + [](Shell& shell) { + return std::make_unique(shell.GetTaskRunners()); + }); + } + + FML_CHECK(shell); + + { + benchmarking::ScopedPauseTiming pause(state, !measure_shutdown); + shell.reset(); // Shutdown is synchronous. + thread_host.reset(); + } + + FML_CHECK(!shell); +} + +static void BM_ShellInitialization(benchmark::State& state) { + while (state.KeepRunning()) { + StartupAndShutdownShell(state, true, false); + } +} + +BENCHMARK(BM_ShellInitialization); + +static void BM_ShellShutdown(benchmark::State& state) { + while (state.KeepRunning()) { + StartupAndShutdownShell(state, false, true); + } +} + +BENCHMARK(BM_ShellShutdown); + +static void BM_ShellInitializationAndShutdown(benchmark::State& state) { + while (state.KeepRunning()) { + StartupAndShutdownShell(state, true, true); + } +} + +BENCHMARK(BM_ShellInitializationAndShutdown); + +} // namespace shell -- GitLab