Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
dart_native_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
5#include "flutter/shell/common/shell.h"
6
7#include "flutter/benchmarking/benchmarking.h"
8#include "flutter/shell/common/thread_host.h"
9#include "flutter/testing/dart_fixture.h"
10#include "flutter/testing/dart_isolate_runner.h"
11#include "flutter/testing/testing.h"
14
15// CREATE_NATIVE_ENTRY is leaky by design
16// NOLINTBEGIN(clang-analyzer-core.StackAddressEscape)
17
18namespace flutter::testing {
19
20class DartNativeBenchmarks : public DartFixture, public benchmark::Fixture {
21 public:
23
24 void SetUp(const ::benchmark::State& state) {}
25
26 void TearDown(const ::benchmark::State& state) {}
27
28 private:
30};
31
32BENCHMARK_F(DartNativeBenchmarks, TimeToFirstNativeMessageFromIsolateInNewVM)
33(benchmark::State& st) {
34 while (st.KeepRunning()) {
36 st.PauseTiming();
37 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
38 AddNativeCallback("NotifyNative",
40 latch.Signal();
41 })));
42
43 const auto settings = CreateSettingsForFixture();
44 DartVMRef vm_ref = DartVMRef::Create(settings);
45
46 ThreadHost thread_host("io.flutter.test.DartNativeBenchmarks.",
49 TaskRunners task_runners(
50 "test",
51 thread_host.platform_thread->GetTaskRunner(), // platform
52 thread_host.platform_thread->GetTaskRunner(), // raster
53 thread_host.ui_thread->GetTaskRunner(), // ui
54 thread_host.io_thread->GetTaskRunner() // io
55 );
56
57 {
58 st.ResumeTiming();
59 auto isolate =
60 RunDartCodeInIsolate(vm_ref, settings, task_runners, "notifyNative",
62 ASSERT_TRUE(isolate);
63 ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
64 latch.Wait();
65 }
66 }
67}
68
69BENCHMARK_F(DartNativeBenchmarks, MultipleDartToNativeMessages)
70(benchmark::State& st) {
71 while (st.KeepRunning()) {
72 fml::CountDownLatch latch(1000);
73 st.PauseTiming();
74 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
75 AddNativeCallback("NotifyNative",
77 latch.CountDown();
78 })));
79
80 const auto settings = CreateSettingsForFixture();
81 DartVMRef vm_ref = DartVMRef::Create(settings);
82
83 ThreadHost thread_host("io.flutter.test.DartNativeBenchmarks.",
86 TaskRunners task_runners(
87 "test",
88 thread_host.platform_thread->GetTaskRunner(), // platform
89 thread_host.platform_thread->GetTaskRunner(), // raster
90 thread_host.ui_thread->GetTaskRunner(), // ui
91 thread_host.io_thread->GetTaskRunner() // io
92 );
93
94 {
95 st.ResumeTiming();
96 auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners,
97 "thousandCallsToNative", {},
99 ASSERT_TRUE(isolate);
100 ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
101 latch.Wait();
102 }
103 }
104}
105
106} // namespace flutter::testing
107
108// NOLINTEND(clang-analyzer-core.StackAddressEscape)
static DartVMRef Create(const Settings &settings, fml::RefPtr< const DartSnapshot > vm_snapshot=nullptr, fml::RefPtr< const DartSnapshot > isolate_snapshot=nullptr)
static bool IsInstanceRunning()
void TearDown(const ::benchmark::State &state)
void SetUp(const ::benchmark::State &state)
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3010
AtkStateType state
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::string GetDefaultKernelFilePath()
Returns the default path to kernel_blob.bin. This file is within the directory returned by GetFixture...
Definition testing.cc:19
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::shared_ptr< VolatilePathTracker > volatile_path_tracker, std::unique_ptr< PlatformConfiguration > platform_configuration)
BENCHMARK_F(SkParagraphFixture, ShortLayout)(benchmark
#define CREATE_NATIVE_ENTRY(native_entry)