mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Some components in the Flutter engine were derived from the forked blink codebase. While the forked components have either been removed or rewritten, the use of the blink namespace has mostly (and inconsistently) remained. This renames the blink namesapce to flutter for consistency. There are no functional changes in this patch.
81 lines
2.4 KiB
C++
81 lines
2.4 KiB
C++
// 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.
|
|
|
|
#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);
|
|
flutter::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);
|
|
|
|
flutter::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
|