Files
engine/shell/common/shell_benchmarks.cc
T
liyuqian 9f088c65ee Add onReportTimings and FrameRasterizedCallback API (#8983)
Using it, a Flutter app can monitor missing frames in the release mode, and a custom Flutter runner (e.g., Fuchsia) can add a custom FrameRasterizedCallback.

Related issues:
https://github.com/flutter/flutter/issues/26154
https://github.com/flutter/flutter/issues/31444
https://github.com/flutter/flutter/issues/32447

Need review as soon as possible so we can merge this before the end of May to catch the milestone.

Tests added:
* NoNeedToReportTimingsByDefault
* NeedsReportTimingsIsSetWithCallback
* ReportTimingsIsCalled
* FrameRasterizedCallbackIsCalled
* FrameTimingSetsAndGetsProperly
* onReportTimings preserves callback zone
* FrameTiming.toString has the correct format

This will need a manual engine roll as the TestWindow defined in the framework needs to implement onReportTimings.
2019-06-06 10:42:48 -07:00

81 lines
2.5 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 flutter {
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);
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);
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, 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 flutter