forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a benchmarking target for the shell. (flutter#6420)
Also adds //flutter/benchmarking which, similar to //flutter/testing, allows for the creation of a benchmarking executable. This is also the target that contains benchmarking utilities.
- Loading branch information
1 parent
30f78af
commit c2128fc
Showing
7 changed files
with
264 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2018 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. | ||
|
||
config("benchmark_config") { | ||
include_dirs = [ "//third_party/benchmark:benchmark_config" ] | ||
} | ||
|
||
source_set("benchmarking") { | ||
testonly = true | ||
|
||
sources = [ | ||
"benchmarking.cc", | ||
"benchmarking.h", | ||
] | ||
|
||
public_deps = [ | ||
"$flutter_root/fml", | ||
"//third_party/benchmark", | ||
] | ||
|
||
public_configs = [ | ||
"$flutter_root:config", | ||
":benchmark_config", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2018 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 "benchmarking.h" | ||
|
||
#include "flutter/fml/icu_util.h" | ||
|
||
namespace benchmarking { | ||
|
||
int Main(int argc, char** argv) { | ||
benchmark::Initialize(&argc, argv); | ||
fml::icu::InitializeICU("icudtl.dat"); | ||
::benchmark::RunSpecifiedBenchmarks(); | ||
return 0; | ||
} | ||
|
||
} // namespace benchmarking | ||
|
||
int main(int argc, char** argv) { | ||
return benchmarking::Main(argc, argv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2018 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. | ||
|
||
#ifndef FLUTTER_BENCHMARKING_BENCHMARKING_H_ | ||
#define FLUTTER_BENCHMARKING_BENCHMARKING_H_ | ||
|
||
#include "benchmark/benchmark_api.h" | ||
|
||
namespace benchmarking { | ||
|
||
class ScopedPauseTiming { | ||
public: | ||
ScopedPauseTiming(::benchmark::State& state, bool enabled = true) | ||
: state_(state), enabled_(enabled) { | ||
if (enabled_) { | ||
state_.PauseTiming(); | ||
} | ||
} | ||
~ScopedPauseTiming() { | ||
if (enabled_) { | ||
state_.ResumeTiming(); | ||
} | ||
} | ||
|
||
private: | ||
::benchmark::State& state_; | ||
const bool enabled_; | ||
}; | ||
|
||
} // namespace benchmarking | ||
|
||
#endif // FLUTTER_BENCHMARKING_BENCHMARKING_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2018 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); | ||
blink::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); | ||
|
||
blink::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 |