Create a benchmarking target for the shell. (flutter/engine#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.
This commit is contained in:
Chinmay Garde
2018-10-03 17:22:33 -07:00
committed by GitHub
parent 37115ff5ec
commit 6e666dadf8
7 changed files with 264 additions and 74 deletions

View File

@@ -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",

View File

@@ -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",
]
}

View File

@@ -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);
}

View File

@@ -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_

View File

@@ -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

View File

@@ -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",
]
}

View File

@@ -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> shell;
std::unique_ptr<ThreadHost> 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<ThreadHost>(
"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<PlatformView>(shell, shell.GetTaskRunners());
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(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