Flutter Engine
 
Loading...
Searching...
No Matches
shell_benchmarks.cc
Go to the documentation of this file.
1// Copyright 2013 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
6
13
14namespace flutter {
15
16static void StartupAndShutdownShell(benchmark::State& state,
17 bool measure_startup,
18 bool measure_shutdown) {
19 auto assets_dir = fml::OpenDirectory(testing::GetFixturesPath(), false,
21 std::unique_ptr<Shell> shell;
22 std::unique_ptr<ThreadHost> thread_host;
23 testing::ELFAOTSymbols aot_symbols;
24
25 {
26 benchmarking::ScopedPauseTiming pause(state, !measure_startup);
27 Settings settings = {};
28 settings.task_observer_add = [](intptr_t, const fml::closure&) {
30 };
31 settings.task_observer_remove = [](fml::TaskQueueId, intptr_t) {};
32
37 testing::PrepareSettingsForAOTWithSymbols(settings, aot_symbols))
38 << "Could not set up settings with AOT symbols.";
39 } else {
40 settings.application_kernels = [&]() {
41 std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
42 kernel_mappings.emplace_back(
43 fml::FileMapping::CreateReadOnly(assets_dir, "kernel_blob.bin"));
44 return kernel_mappings;
45 };
46 }
47
48 thread_host = std::make_unique<ThreadHost>(ThreadHost::ThreadHostConfig(
49 "io.flutter.bench.",
52
53 TaskRunners task_runners("test",
54 thread_host->platform_thread->GetTaskRunner(),
55 thread_host->raster_thread->GetTaskRunner(),
56 thread_host->ui_thread->GetTaskRunner(),
57 thread_host->io_thread->GetTaskRunner());
58
59 shell = Shell::Create(
60 flutter::PlatformData(), task_runners, settings,
61 [](Shell& shell) {
62 return std::make_unique<PlatformView>(shell, shell.GetTaskRunners());
63 },
64 [](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
65 }
66
67 FML_CHECK(shell);
68
69 {
70 // The ui thread could be busy processing tasks after shell created, e.g.,
71 // default font manager setup. The measurement of shell shutdown should be
72 // considered after those ui tasks have been done.
73 //
74 // However, if we're measuring the complete time from startup to shutdown,
75 // this time should still be included.
77 state, !measure_shutdown || !measure_startup);
79 fml::TaskRunner::RunNowOrPostTask(thread_host->ui_thread->GetTaskRunner(),
80 [&latch]() { latch.Signal(); });
81 latch.Wait();
82 }
83
84 {
85 benchmarking::ScopedPauseTiming pause(state, !measure_shutdown);
86 // Shutdown must occur synchronously on the platform thread.
89 thread_host->platform_thread->GetTaskRunner(),
90 [&shell, &latch]() mutable {
91 shell.reset();
92 latch.Signal();
93 });
94 latch.Wait();
95 thread_host.reset();
96 }
97
98 FML_CHECK(!shell);
99}
100
101static void BM_ShellInitialization(benchmark::State& state) {
102 while (state.KeepRunning()) {
103 StartupAndShutdownShell(state, true, false);
104 }
105}
106
108
109static void BM_ShellShutdown(benchmark::State& state) {
110 while (state.KeepRunning()) {
111 StartupAndShutdownShell(state, false, true);
112 }
113}
114
116
117static void BM_ShellInitializationAndShutdown(benchmark::State& state) {
118 while (state.KeepRunning()) {
119 StartupAndShutdownShell(state, true, true);
120 }
121}
122
124
125} // namespace flutter
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
Definition dart_vm.cc:176
static std::unique_ptr< Shell > Create(const PlatformData &platform_data, const TaskRunners &task_runners, Settings settings, const CreateCallback< PlatformView > &on_create_platform_view, const CreateCallback< Rasterizer > &on_create_rasterizer, bool is_gpu_disabled=false)
Creates a shell instance using the provided settings. The callbacks to create the various shell subco...
Definition shell.cc:221
const TaskRunners & GetTaskRunners() const override
If callers wish to interact directly with any shell subcomponents, they must (on the platform thread)...
Definition shell.cc:911
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition mapping.cc:20
static TaskQueueId Invalid()
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
#define FML_CHECK(condition)
Definition logging.h:104
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
ELFAOTSymbols LoadELFSymbolFromFixturesIfNeccessary(std::string elf_filename)
Attempts to resolve AOT symbols from the portable ELF loader. This location is automatically resolved...
Definition elf_loader.cc:16
bool PrepareSettingsForAOTWithSymbols(Settings &settings, const ELFAOTSymbols &symbols)
Prepare the settings objects various AOT mappings resolvers with the symbols already loaded....
constexpr const char * kDefaultAOTAppELFFileName
Definition elf_loader.h:16
static void BM_ShellInitialization(benchmark::State &state)
static void StartupAndShutdownShell(benchmark::State &state, bool measure_startup, bool measure_shutdown)
BENCHMARK(BM_ShellInitialization)
static void BM_ShellInitializationAndShutdown(benchmark::State &state)
static void BM_ShellShutdown(benchmark::State &state)
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition file_posix.cc:97
std::function< void()> closure
Definition closure.h:14
TaskObserverRemove task_observer_remove
Definition settings.h:282
MappingsCallback application_kernels
Definition settings.h:142
TaskObserverAdd task_observer_add
Definition settings.h:281