Flutter Engine
 
Loading...
Searching...
No Matches
ui_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
12
13#include <future>
14
15namespace flutter {
16
18 void TestBody() override {};
19};
20
21static void BM_PlatformMessageResponseDartComplete(benchmark::State& state) {
25 TaskRunners task_runners("test", thread_host.platform_thread->GetTaskRunner(),
26 thread_host.raster_thread->GetTaskRunner(),
27 thread_host.ui_thread->GetTaskRunner(),
28 thread_host.io_thread->GetTaskRunner());
29 Fixture fixture;
30 auto settings = fixture.CreateSettingsForFixture();
31 auto vm_ref = DartVMRef::Create(settings);
32 auto isolate =
33 testing::RunDartCodeInIsolate(vm_ref, settings, task_runners, "main", {},
35
36 while (state.KeepRunning()) {
37 state.PauseTiming();
38 bool successful = isolate->RunInIsolateScope([&]() -> bool {
39 // Simulate a message of 3 MB
40 std::vector<uint8_t> data(3 << 20, 0);
41 std::unique_ptr<fml::Mapping> mapping =
42 std::make_unique<fml::DataMapping>(data);
43
44 Dart_Handle library = Dart_RootLibrary();
45 Dart_Handle closure =
46 Dart_GetField(library, Dart_NewStringFromCString("messageCallback"));
47
48 auto message = fml::MakeRefCounted<PlatformMessageResponseDart>(
49 tonic::DartPersistentValue(isolate->get(), closure),
50 thread_host.ui_thread->GetTaskRunner(), "");
51
52 message->Complete(std::move(mapping));
53
54 return true;
55 });
56 FML_CHECK(successful);
57 state.ResumeTiming();
58
59 // We skip timing everything above because the copy triggered by
60 // message->Complete is a task posted on the UI thread. The following wait
61 // for a UI task would let us know when that copy is done.
62 std::promise<bool> completed;
63 task_runners.GetUITaskRunner()->PostTask(
64 [&completed] { completed.set_value(true); });
65 completed.get_future().wait();
66 }
67}
68
70 ->Unit(benchmark::kMicrosecond);
71
72} // namespace flutter
static DartVMRef Create(const Settings &settings, fml::RefPtr< const DartSnapshot > vm_snapshot=nullptr, fml::RefPtr< const DartSnapshot > isolate_snapshot=nullptr)
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
virtual Settings CreateSettingsForFixture()
virtual void PostTask(const fml::closure &task) override
G_BEGIN_DECLS GBytes * message
#define FML_CHECK(condition)
Definition logging.h:104
std::string GetDefaultKernelFilePath()
Returns the default path to kernel_blob.bin. This file is within the directory returned by GetFixture...
Definition testing.cc:18
std::unique_ptr< AutoIsolateShutdown > RunDartCodeInIsolate(DartVMRef &vm_ref, const Settings &settings, const TaskRunners &task_runners, std::string entrypoint, const std::vector< std::string > &args, const std::string &kernel_file_path, fml::WeakPtr< IOManager > io_manager, std::unique_ptr< PlatformConfiguration > platform_configuration)
BENCHMARK(BM_ShellInitialization)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36
static void BM_PlatformMessageResponseDartComplete(benchmark::State &state)
The collection of all the threads used by the engine.
Definition thread_host.h:21
std::unique_ptr< fml::Thread > io_thread
Definition thread_host.h:86
std::unique_ptr< fml::Thread > platform_thread
Definition thread_host.h:83
std::unique_ptr< fml::Thread > raster_thread
Definition thread_host.h:85
std::unique_ptr< fml::Thread > ui_thread
Definition thread_host.h:84