Flutter Engine
The 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
5#include "flutter/shell/common/shell.h"
6
7#include "flutter/benchmarking/benchmarking.h"
8#include "flutter/fml/logging.h"
9#include "flutter/runtime/dart_vm.h"
10#include "flutter/shell/common/thread_host.h"
11#include "flutter/testing/elf_loader.h"
12#include "flutter/testing/testing.h"
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&) {};
29 settings.task_observer_remove = [](intptr_t) {};
30
35 testing::PrepareSettingsForAOTWithSymbols(settings, aot_symbols))
36 << "Could not set up settings with AOT symbols.";
37 } else {
38 settings.application_kernels = [&]() {
39 std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
40 kernel_mappings.emplace_back(
41 fml::FileMapping::CreateReadOnly(assets_dir, "kernel_blob.bin"));
42 return kernel_mappings;
43 };
44 }
45
46 thread_host = std::make_unique<ThreadHost>(ThreadHost::ThreadHostConfig(
47 "io.flutter.bench.",
50
51 TaskRunners task_runners("test",
52 thread_host->platform_thread->GetTaskRunner(),
53 thread_host->raster_thread->GetTaskRunner(),
54 thread_host->ui_thread->GetTaskRunner(),
55 thread_host->io_thread->GetTaskRunner());
56
57 shell = Shell::Create(
58 flutter::PlatformData(), task_runners, settings,
59 [](Shell& shell) {
60 return std::make_unique<PlatformView>(shell, shell.GetTaskRunners());
61 },
62 [](Shell& shell) { return std::make_unique<Rasterizer>(shell); });
63 }
64
65 FML_CHECK(shell);
66
67 {
68 // The ui thread could be busy processing tasks after shell created, e.g.,
69 // default font manager setup. The measurement of shell shutdown should be
70 // considered after those ui tasks have been done.
71 //
72 // However, if we're measuring the complete time from startup to shutdown,
73 // this time should still be included.
75 state, !measure_shutdown || !measure_startup);
77 fml::TaskRunner::RunNowOrPostTask(thread_host->ui_thread->GetTaskRunner(),
78 [&latch]() { latch.Signal(); });
79 latch.Wait();
80 }
81
82 {
83 benchmarking::ScopedPauseTiming pause(state, !measure_shutdown);
84 // Shutdown must occur synchronously on the platform thread.
87 thread_host->platform_thread->GetTaskRunner(),
88 [&shell, &latch]() mutable {
89 shell.reset();
90 latch.Signal();
91 });
92 latch.Wait();
93 thread_host.reset();
94 }
95
96 FML_CHECK(!shell);
97}
98
99static void BM_ShellInitialization(benchmark::State& state) {
100 while (state.KeepRunning()) {
101 StartupAndShutdownShell(state, true, false);
102 }
103}
104
106
107static void BM_ShellShutdown(benchmark::State& state) {
108 while (state.KeepRunning()) {
109 StartupAndShutdownShell(state, false, true);
110 }
111}
112
114
115static void BM_ShellInitializationAndShutdown(benchmark::State& state) {
116 while (state.KeepRunning()) {
117 StartupAndShutdownShell(state, true, true);
118 }
119}
120
122
123} // namespace flutter
#define BENCHMARK(name)
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:205
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:167
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition mapping.cc:20
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
AtkStateType state
#define FML_CHECK(condition)
Definition logging.h:85
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:17
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:17
static void BM_ShellInitialization(benchmark::State &state)
static void StartupAndShutdownShell(benchmark::State &state, bool measure_startup, bool measure_shutdown)
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