Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c2128fc

Browse files
authored
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.
1 parent 30f78af commit c2128fc

File tree

7 files changed

+264
-74
lines changed

7 files changed

+264
-74
lines changed

BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ group("flutter") {
3838
"$flutter_root/flow:flow_unittests",
3939
"$flutter_root/fml:fml_unittests",
4040
"$flutter_root/runtime:runtime_unittests",
41+
"$flutter_root/shell/common:shell_benchmarks",
4142
"$flutter_root/shell/common:shell_unittests",
4243
"$flutter_root/shell/platform/embedder:embedder_unittests",
4344
"$flutter_root/synchronization:synchronization_unittests",

benchmarking/BUILD.gn

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2018 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
config("benchmark_config") {
6+
include_dirs = [ "//third_party/benchmark:benchmark_config" ]
7+
}
8+
9+
source_set("benchmarking") {
10+
testonly = true
11+
12+
sources = [
13+
"benchmarking.cc",
14+
"benchmarking.h",
15+
]
16+
17+
public_deps = [
18+
"$flutter_root/fml",
19+
"//third_party/benchmark",
20+
]
21+
22+
public_configs = [
23+
"$flutter_root:config",
24+
":benchmark_config",
25+
]
26+
}

benchmarking/benchmarking.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "benchmarking.h"
6+
7+
#include "flutter/fml/icu_util.h"
8+
9+
namespace benchmarking {
10+
11+
int Main(int argc, char** argv) {
12+
benchmark::Initialize(&argc, argv);
13+
fml::icu::InitializeICU("icudtl.dat");
14+
::benchmark::RunSpecifiedBenchmarks();
15+
return 0;
16+
}
17+
18+
} // namespace benchmarking
19+
20+
int main(int argc, char** argv) {
21+
return benchmarking::Main(argc, argv);
22+
}

benchmarking/benchmarking.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2018 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_BENCHMARKING_BENCHMARKING_H_
6+
#define FLUTTER_BENCHMARKING_BENCHMARKING_H_
7+
8+
#include "benchmark/benchmark_api.h"
9+
10+
namespace benchmarking {
11+
12+
class ScopedPauseTiming {
13+
public:
14+
ScopedPauseTiming(::benchmark::State& state, bool enabled = true)
15+
: state_(state), enabled_(enabled) {
16+
if (enabled_) {
17+
state_.PauseTiming();
18+
}
19+
}
20+
~ScopedPauseTiming() {
21+
if (enabled_) {
22+
state_.ResumeTiming();
23+
}
24+
}
25+
26+
private:
27+
::benchmark::State& state_;
28+
const bool enabled_;
29+
};
30+
31+
} // namespace benchmarking
32+
33+
#endif // FLUTTER_BENCHMARKING_BENCHMARKING_H_

ci/licenses_golden/licenses_flutter

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -470,70 +470,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
470470

471471
====================================================================================================
472472
LIBRARY: engine
473-
ORIGIN: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart + ../../../LICENSE
474-
TYPE: LicenseType.bsd
475-
FILE: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart
476-
FILE: ../../../flutter/fml/paths_unittests.cc
477-
FILE: ../../../flutter/lib/ui/isolate_name_server.dart
478-
FILE: ../../../flutter/lib/ui/painting/image_encoding.cc
479-
FILE: ../../../flutter/lib/ui/painting/image_encoding.h
480-
FILE: ../../../flutter/lib/ui/plugins.dart
481-
FILE: ../../../flutter/lib/ui/semantics/custom_accessibility_action.cc
482-
FILE: ../../../flutter/lib/ui/semantics/custom_accessibility_action.h
483-
FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc
484-
FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.h
485-
FILE: ../../../flutter/shell/platform/android/apk_asset_provider.h
486-
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformView.java
487-
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewFactory.java
488-
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistry.java
489-
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistryImpl.java
490-
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java
491-
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java
492-
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java
493-
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java
494-
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterRunArguments.java
495-
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterCallbackCache.h
496-
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h
497-
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache.mm
498-
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache_Internal.h
499-
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm
500-
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h
501-
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm
502-
FILE: ../../../flutter/shell/platform/darwin/ios/headless_platform_view_ios.h
503-
----------------------------------------------------------------------------------------------------
504-
Copyright 2018 The Chromium Authors. All rights reserved.
505-
506-
Redistribution and use in source and binary forms, with or without
507-
modification, are permitted provided that the following conditions are
508-
met:
509-
510-
* Redistributions of source code must retain the above copyright
511-
notice, this list of conditions and the following disclaimer.
512-
* Redistributions in binary form must reproduce the above
513-
copyright notice, this list of conditions and the following disclaimer
514-
in the documentation and/or other materials provided with the
515-
distribution.
516-
* Neither the name of Google Inc. nor the names of its
517-
contributors may be used to endorse or promote products derived from
518-
this software without specific prior written permission.
519-
520-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
521-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
522-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
523-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
524-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
525-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
526-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
527-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
528-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
529-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
530-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
531-
====================================================================================================
532-
533-
====================================================================================================
534-
LIBRARY: engine
535-
ORIGIN: ../../../flutter/fml/platform/android/paths_android.h + ../../../LICENSE
473+
ORIGIN: ../../../flutter/benchmarking/benchmarking.cc + ../../../LICENSE
536474
TYPE: LicenseType.bsd
475+
FILE: ../../../flutter/benchmarking/benchmarking.cc
476+
FILE: ../../../flutter/benchmarking/benchmarking.h
537477
FILE: ../../../flutter/fml/base32.cc
538478
FILE: ../../../flutter/fml/base32.h
539479
FILE: ../../../flutter/fml/base32_unittest.cc
@@ -570,6 +510,7 @@ FILE: ../../../flutter/shell/common/isolate_configuration.cc
570510
FILE: ../../../flutter/shell/common/isolate_configuration.h
571511
FILE: ../../../flutter/shell/common/persistent_cache.cc
572512
FILE: ../../../flutter/shell/common/persistent_cache.h
513+
FILE: ../../../flutter/shell/common/shell_benchmarks.cc
573514
FILE: ../../../flutter/shell/platform/android/android_shell_holder.cc
574515
FILE: ../../../flutter/shell/platform/android/android_shell_holder.h
575516
FILE: ../../../flutter/shell/platform/android/platform_message_response_android.cc
@@ -615,6 +556,68 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
615556
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
616557
====================================================================================================
617558

559+
====================================================================================================
560+
LIBRARY: engine
561+
ORIGIN: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart + ../../../LICENSE
562+
TYPE: LicenseType.bsd
563+
FILE: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart
564+
FILE: ../../../flutter/fml/paths_unittests.cc
565+
FILE: ../../../flutter/lib/ui/isolate_name_server.dart
566+
FILE: ../../../flutter/lib/ui/painting/image_encoding.cc
567+
FILE: ../../../flutter/lib/ui/painting/image_encoding.h
568+
FILE: ../../../flutter/lib/ui/plugins.dart
569+
FILE: ../../../flutter/lib/ui/semantics/custom_accessibility_action.cc
570+
FILE: ../../../flutter/lib/ui/semantics/custom_accessibility_action.h
571+
FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc
572+
FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.h
573+
FILE: ../../../flutter/shell/platform/android/apk_asset_provider.h
574+
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformView.java
575+
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewFactory.java
576+
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistry.java
577+
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistryImpl.java
578+
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java
579+
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/SingleViewPresentation.java
580+
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java
581+
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java
582+
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterRunArguments.java
583+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterCallbackCache.h
584+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h
585+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache.mm
586+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache_Internal.h
587+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPluginAppLifeCycleDelegate.mm
588+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.h
589+
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm
590+
FILE: ../../../flutter/shell/platform/darwin/ios/headless_platform_view_ios.h
591+
----------------------------------------------------------------------------------------------------
592+
Copyright 2018 The Chromium Authors. All rights reserved.
593+
594+
Redistribution and use in source and binary forms, with or without
595+
modification, are permitted provided that the following conditions are
596+
met:
597+
598+
* Redistributions of source code must retain the above copyright
599+
notice, this list of conditions and the following disclaimer.
600+
* Redistributions in binary form must reproduce the above
601+
copyright notice, this list of conditions and the following disclaimer
602+
in the documentation and/or other materials provided with the
603+
distribution.
604+
* Neither the name of Google Inc. nor the names of its
605+
contributors may be used to endorse or promote products derived from
606+
this software without specific prior written permission.
607+
608+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
609+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
610+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
611+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
612+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
613+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
614+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
615+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
616+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
617+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
618+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
619+
====================================================================================================
620+
618621
====================================================================================================
619622
LIBRARY: engine
620623
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.h + ../../../LICENSE

shell/common/BUILD.gn

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,47 @@ source_set("common") {
114114
public_configs = [ "$flutter_root:config" ]
115115
}
116116

117-
executable("shell_unittests") {
118-
testonly = true
117+
template("shell_host_executable") {
118+
executable(target_name) {
119+
testonly = true
119120

121+
deps = []
122+
123+
ldflags = []
124+
125+
forward_variables_from(invoker, "*")
126+
127+
deps += [
128+
":common",
129+
"$flutter_root/fml",
130+
"$flutter_root/lib/snapshot",
131+
"//third_party/dart/runtime:libdart_jit",
132+
"//third_party/skia",
133+
"//third_party/tonic",
134+
]
135+
136+
if (is_linux) {
137+
ldflags += [ "-rdynamic" ]
138+
}
139+
}
140+
}
141+
142+
shell_host_executable("shell_unittests") {
120143
sources = [
121144
"shell_unittests.cc",
122145
]
146+
123147
deps = [
124-
":common",
125-
"$flutter_root/fml",
126-
"$flutter_root/lib/snapshot",
127148
"$flutter_root/testing",
128-
"//third_party/dart/runtime:libdart_jit",
129-
"//third_party/skia",
130-
"//third_party/tonic",
131149
]
132-
if (is_linux) {
133-
ldflags = [ "-rdynamic" ]
134-
}
150+
}
151+
152+
shell_host_executable("shell_benchmarks") {
153+
sources = [
154+
"shell_benchmarks.cc",
155+
]
156+
157+
deps = [
158+
"$flutter_root/benchmarking",
159+
]
135160
}

shell/common/shell_benchmarks.cc

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2018 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/benchmarking/benchmarking.h"
6+
#include "flutter/fml/logging.h"
7+
#include "flutter/shell/common/shell.h"
8+
#include "flutter/shell/common/thread_host.h"
9+
10+
namespace shell {
11+
12+
static void StartupAndShutdownShell(benchmark::State& state,
13+
bool measure_startup,
14+
bool measure_shutdown) {
15+
std::unique_ptr<Shell> shell;
16+
std::unique_ptr<ThreadHost> thread_host;
17+
{
18+
benchmarking::ScopedPauseTiming pause(state, !measure_startup);
19+
blink::Settings settings = {};
20+
settings.task_observer_add = [](intptr_t, fml::closure) {};
21+
settings.task_observer_remove = [](intptr_t) {};
22+
23+
// Measure the time it takes to setup the threads as well.
24+
thread_host = std::make_unique<ThreadHost>(
25+
"io.flutter.bench.", ThreadHost::Type::Platform |
26+
ThreadHost::Type::GPU | ThreadHost::Type::IO |
27+
ThreadHost::Type::UI);
28+
29+
blink::TaskRunners task_runners(
30+
"test", thread_host->platform_thread->GetTaskRunner(),
31+
thread_host->gpu_thread->GetTaskRunner(),
32+
thread_host->ui_thread->GetTaskRunner(),
33+
thread_host->io_thread->GetTaskRunner());
34+
35+
shell = Shell::Create(
36+
std::move(task_runners), settings,
37+
[](Shell& shell) {
38+
return std::make_unique<PlatformView>(shell, shell.GetTaskRunners());
39+
},
40+
[](Shell& shell) {
41+
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
42+
});
43+
}
44+
45+
FML_CHECK(shell);
46+
47+
{
48+
benchmarking::ScopedPauseTiming pause(state, !measure_shutdown);
49+
shell.reset(); // Shutdown is synchronous.
50+
thread_host.reset();
51+
}
52+
53+
FML_CHECK(!shell);
54+
}
55+
56+
static void BM_ShellInitialization(benchmark::State& state) {
57+
while (state.KeepRunning()) {
58+
StartupAndShutdownShell(state, true, false);
59+
}
60+
}
61+
62+
BENCHMARK(BM_ShellInitialization);
63+
64+
static void BM_ShellShutdown(benchmark::State& state) {
65+
while (state.KeepRunning()) {
66+
StartupAndShutdownShell(state, false, true);
67+
}
68+
}
69+
70+
BENCHMARK(BM_ShellShutdown);
71+
72+
static void BM_ShellInitializationAndShutdown(benchmark::State& state) {
73+
while (state.KeepRunning()) {
74+
StartupAndShutdownShell(state, true, true);
75+
}
76+
}
77+
78+
BENCHMARK(BM_ShellInitializationAndShutdown);
79+
80+
} // namespace shell

0 commit comments

Comments
 (0)