This repository has been archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
/
Copy pathshell_benchmarks.cc
126 lines (107 loc) · 4.26 KB
/
shell_benchmarks.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2013 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.
// FLUTTER_NOLINT
#include "flutter/benchmarking/benchmarking.h"
#include "flutter/fml/logging.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/thread_host.h"
#include "flutter/testing/elf_loader.h"
#include "flutter/testing/testing.h"
namespace flutter {
static void StartupAndShutdownShell(benchmark::State& state,
bool measure_startup,
bool measure_shutdown) {
auto assets_dir = fml::OpenDirectory(testing::GetFixturesPath(), false,
fml::FilePermission::kRead);
std::unique_ptr<Shell> shell;
std::unique_ptr<ThreadHost> thread_host;
testing::ELFAOTSymbols aot_symbols;
{
benchmarking::ScopedPauseTiming pause(state, !measure_startup);
Settings settings = {};
settings.task_observer_add = [](intptr_t, fml::closure) {};
settings.task_observer_remove = [](intptr_t) {};
if (DartVM::IsRunningPrecompiledCode()) {
aot_symbols = testing::LoadELFSymbolFromFixturesIfNeccessary();
FML_CHECK(
testing::PrepareSettingsForAOTWithSymbols(settings, aot_symbols))
<< "Could not setup settings with AOT symbols.";
} else {
settings.application_kernels = [&]() {
std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
kernel_mappings.emplace_back(
fml::FileMapping::CreateReadOnly(assets_dir, "kernel_blob.bin"));
return kernel_mappings;
};
}
thread_host = std::make_unique<ThreadHost>(
"io.flutter.bench.", ThreadHost::Type::Platform |
ThreadHost::Type::GPU | ThreadHost::Type::IO |
ThreadHost::Type::UI);
TaskRunners task_runners("test",
thread_host->platform_thread->GetTaskRunner(),
thread_host->raster_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, shell.GetTaskRunners(),
shell.GetIsGpuDisabledSyncSwitch());
});
}
FML_CHECK(shell);
{
// The ui thread could be busy processing tasks after shell created, e.g.,
// default font manager setup. The measurement of shell shutdown should be
// considered after those ui tasks have been done.
//
// However, if we're measuring the complete time from startup to shutdown,
// this time should still be included.
benchmarking::ScopedPauseTiming pause(
state, !measure_shutdown || !measure_startup);
fml::AutoResetWaitableEvent latch;
fml::TaskRunner::RunNowOrPostTask(thread_host->ui_thread->GetTaskRunner(),
[&latch]() { latch.Signal(); });
latch.Wait();
}
{
benchmarking::ScopedPauseTiming pause(state, !measure_shutdown);
// Shutdown must occur synchronously on the platform thread.
fml::AutoResetWaitableEvent latch;
fml::TaskRunner::RunNowOrPostTask(
thread_host->platform_thread->GetTaskRunner(),
[&shell, &latch]() mutable {
shell.reset();
latch.Signal();
});
latch.Wait();
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 flutter