Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
benchmark_test.h
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_BENCHMARK_TEST_H_
6#define RUNTIME_VM_BENCHMARK_TEST_H_
7
8#include "include/dart_api.h"
9
10#include "vm/dart.h"
11#include "vm/globals.h"
12#include "vm/isolate.h"
13#include "vm/object.h"
14#include "vm/unit_test.h"
15#include "vm/zone.h"
16
17namespace dart {
18
19DECLARE_FLAG(int, code_heap_size);
20DECLARE_FLAG(int, old_gen_growth_space_ratio);
21
22namespace bin {
23// Snapshot pieces if we link in a snapshot, otherwise initialized to nullptr.
24extern const uint8_t* vm_snapshot_data;
25extern const uint8_t* vm_snapshot_instructions;
26extern const uint8_t* core_isolate_snapshot_data;
27extern const uint8_t* core_isolate_snapshot_instructions;
28} // namespace bin
29
30// The BENCHMARK macros are used for benchmarking a specific functionality
31// of the VM.
32#define BENCHMARK_HELPER(name, kind) \
33 void Dart_Benchmark##name(Benchmark* benchmark); \
34 static Benchmark kRegister##name(Dart_Benchmark##name, #name, kind); \
35 static void Dart_BenchmarkHelper##name(Benchmark* benchmark, \
36 Thread* thread); \
37 void Dart_Benchmark##name(Benchmark* benchmark) { \
38 FLAG_old_gen_growth_space_ratio = 100; \
39 BenchmarkIsolateScope __isolate__(benchmark); \
40 Thread* __thread__ = Thread::Current(); \
41 ASSERT(__thread__->isolate() == benchmark->isolate()); \
42 Dart_BenchmarkHelper##name(benchmark, __thread__); \
43 } \
44 static void Dart_BenchmarkHelper##name(Benchmark* benchmark, Thread* thread)
45
46#define BENCHMARK(name) BENCHMARK_HELPER(name, "RunTime")
47#define BENCHMARK_SIZE(name) BENCHMARK_HELPER(name, "CodeSize")
48#define BENCHMARK_MEMORY(name) BENCHMARK_HELPER(name, "MemoryUse")
49
50inline Dart_Handle NewString(const char* str) {
51 return Dart_NewStringFromCString(str);
52}
53
54class Benchmark {
55 public:
56 typedef void(RunEntry)(Benchmark* benchmark);
57
58 Benchmark(RunEntry* run, const char* name, const char* score_kind)
59 : run_(run),
60 name_(name),
61 score_kind_(score_kind),
62 score_(0),
63 isolate_(nullptr),
64 next_(nullptr) {
65 if (first_ == nullptr) {
66 first_ = this;
67 } else {
68 tail_->next_ = this;
69 }
70 tail_ = this;
71 }
72
73 // Accessors.
74 const char* name() const { return name_; }
75 const char* score_kind() const { return score_kind_; }
76 void set_score(int64_t value) { score_ = value; }
77 int64_t score() const { return score_; }
78 Isolate* isolate() const { return reinterpret_cast<Isolate*>(isolate_); }
79
80 void Run() { (*run_)(this); }
81 void RunBenchmark();
82
83 static void RunAll(const char* executable);
84 static void SetExecutable(const char* arg) { executable_ = arg; }
85 static const char* Executable() { return executable_; }
86
88 isolate_ = TestCase::CreateTestIsolate();
89 EXPECT(isolate_ != nullptr);
90 }
91
92 private:
93 static Benchmark* first_;
94 static Benchmark* tail_;
95 static const char* executable_;
96
97 RunEntry* const run_;
98 const char* name_;
99 const char* score_kind_;
100 int64_t score_;
101 Dart_Isolate isolate_;
102 Benchmark* next_;
103
105};
106
108 public:
110 benchmark->CreateIsolate();
111 Dart_EnterScope(); // Create a Dart API scope for unit benchmarks.
112 }
114 Dart_ExitScope(); // Exit the Dart API scope created for unit tests.
115 ASSERT(benchmark_->isolate() == Isolate::Current());
117 benchmark_ = nullptr;
118 }
119 Benchmark* benchmark() const { return benchmark_; }
120
121 private:
122 Benchmark* benchmark_;
123
125};
126
127} // namespace dart
128
129#endif // RUNTIME_VM_BENCHMARK_TEST_H_
#define EXPECT(type, expectedAlignment, expectedSize)
Benchmark * benchmark() const
BenchmarkIsolateScope(Benchmark *benchmark)
static const char * Executable()
Benchmark(RunEntry *run, const char *name, const char *score_kind)
void set_score(int64_t value)
const char * name() const
void() RunEntry(Benchmark *benchmark)
int64_t score() const
const char * score_kind() const
static void RunAll(const char *executable)
Isolate * isolate() const
static void SetExecutable(const char *arg)
static Isolate * Current()
Definition isolate.h:939
static Dart_Isolate CreateTestIsolate(const char *name=nullptr, void *isolate_group_data=nullptr, void *isolate_data=nullptr)
Definition unit_test.cc:139
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
struct _Dart_Isolate * Dart_Isolate
Definition dart_api.h:88
#define ASSERT(E)
uint8_t value
#define DECLARE_FLAG(type, name)
Definition flags.h:14
const uint8_t * vm_snapshot_data
Definition main_impl.cc:56
const uint8_t * vm_snapshot_instructions
Definition main_impl.cc:57
const uint8_t * core_isolate_snapshot_data
Definition main_impl.cc:58
const uint8_t * core_isolate_snapshot_instructions
Definition main_impl.cc:59
DART_EXPORT void Dart_EnterScope()
Dart_Handle NewString(const char *str)
DART_EXPORT void Dart_ExitScope()
DART_EXPORT void Dart_ShutdownIsolate()
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
Definition run.py:1
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581