OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_VM_BENCHMARK_TEST_H_ | 5 #ifndef RUNTIME_VM_BENCHMARK_TEST_H_ |
6 #define RUNTIME_VM_BENCHMARK_TEST_H_ | 6 #define RUNTIME_VM_BENCHMARK_TEST_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 | 9 |
10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
11 #include "vm/globals.h" | 11 #include "vm/globals.h" |
12 #include "vm/heap.h" | 12 #include "vm/heap.h" |
13 #include "vm/isolate.h" | 13 #include "vm/isolate.h" |
14 #include "vm/malloc_hooks.h" | 14 #include "vm/malloc_hooks.h" |
15 #include "vm/object.h" | 15 #include "vm/object.h" |
16 #include "vm/zone.h" | 16 #include "vm/zone.h" |
17 | 17 |
18 namespace dart { | 18 namespace dart { |
19 | 19 |
20 DECLARE_FLAG(int, code_heap_size); | 20 DECLARE_FLAG(int, code_heap_size); |
21 DECLARE_FLAG(int, old_gen_growth_space_ratio); | 21 DECLARE_FLAG(int, old_gen_growth_space_ratio); |
22 | 22 |
23 namespace bin { | 23 namespace bin { |
24 // Snapshot pieces if we link in a snapshot, otherwise initialized to NULL. | 24 // Snapshot pieces if we link in a snapshot, otherwise initialized to NULL. |
25 extern const uint8_t* vm_snapshot_data; | 25 extern const uint8_t* vm_snapshot_data; |
26 extern const uint8_t* vm_snapshot_instructions; | 26 extern const uint8_t* vm_snapshot_instructions; |
27 extern const uint8_t* core_isolate_snapshot_data; | 27 extern const uint8_t* core_isolate_snapshot_data; |
28 extern const uint8_t* core_isolate_snapshot_instructions; | 28 extern const uint8_t* core_isolate_snapshot_instructions; |
29 } | 29 } // namespace bin |
30 | 30 |
31 // The BENCHMARK macros are used for benchmarking a specific functionality | 31 // The BENCHMARK macros are used for benchmarking a specific functionality |
32 // of the VM. | 32 // of the VM. |
33 #define BENCHMARK_HELPER(name, kind) \ | 33 #define BENCHMARK_HELPER(name, kind) \ |
34 void Dart_Benchmark##name(Benchmark* benchmark); \ | 34 void Dart_Benchmark##name(Benchmark* benchmark); \ |
35 static Benchmark kRegister##name(Dart_Benchmark##name, #name, kind); \ | 35 static Benchmark kRegister##name(Dart_Benchmark##name, #name, kind); \ |
36 static void Dart_BenchmarkHelper##name(Benchmark* benchmark, \ | 36 static void Dart_BenchmarkHelper##name(Benchmark* benchmark, \ |
37 Thread* thread); \ | 37 Thread* thread); \ |
38 void Dart_Benchmark##name(Benchmark* benchmark) { \ | 38 void Dart_Benchmark##name(Benchmark* benchmark) { \ |
39 bool __stack_trace_collection_enabled__ = \ | 39 bool __stack_trace_collection_enabled__ = \ |
(...skipping 12 matching lines...) Expand all Loading... |
52 static void Dart_BenchmarkHelper##name(Benchmark* benchmark, Thread* thread) | 52 static void Dart_BenchmarkHelper##name(Benchmark* benchmark, Thread* thread) |
53 | 53 |
54 #define BENCHMARK(name) BENCHMARK_HELPER(name, "RunTime") | 54 #define BENCHMARK(name) BENCHMARK_HELPER(name, "RunTime") |
55 #define BENCHMARK_SIZE(name) BENCHMARK_HELPER(name, "CodeSize") | 55 #define BENCHMARK_SIZE(name) BENCHMARK_HELPER(name, "CodeSize") |
56 #define BENCHMARK_MEMORY(name) BENCHMARK_HELPER(name, "MemoryUse") | 56 #define BENCHMARK_MEMORY(name) BENCHMARK_HELPER(name, "MemoryUse") |
57 | 57 |
58 inline Dart_Handle NewString(const char* str) { | 58 inline Dart_Handle NewString(const char* str) { |
59 return Dart_NewStringFromCString(str); | 59 return Dart_NewStringFromCString(str); |
60 } | 60 } |
61 | 61 |
62 | |
63 class Benchmark { | 62 class Benchmark { |
64 public: | 63 public: |
65 typedef void(RunEntry)(Benchmark* benchmark); | 64 typedef void(RunEntry)(Benchmark* benchmark); |
66 | 65 |
67 Benchmark(RunEntry* run, const char* name, const char* score_kind) | 66 Benchmark(RunEntry* run, const char* name, const char* score_kind) |
68 : run_(run), | 67 : run_(run), |
69 name_(name), | 68 name_(name), |
70 score_kind_(score_kind), | 69 score_kind_(score_kind), |
71 score_(0), | 70 score_(0), |
72 isolate_(NULL), | 71 isolate_(NULL), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 RunEntry* const run_; | 103 RunEntry* const run_; |
105 const char* name_; | 104 const char* name_; |
106 const char* score_kind_; | 105 const char* score_kind_; |
107 int64_t score_; | 106 int64_t score_; |
108 Dart_Isolate isolate_; | 107 Dart_Isolate isolate_; |
109 Benchmark* next_; | 108 Benchmark* next_; |
110 | 109 |
111 DISALLOW_COPY_AND_ASSIGN(Benchmark); | 110 DISALLOW_COPY_AND_ASSIGN(Benchmark); |
112 }; | 111 }; |
113 | 112 |
114 | |
115 class BenchmarkIsolateScope { | 113 class BenchmarkIsolateScope { |
116 public: | 114 public: |
117 explicit BenchmarkIsolateScope(Benchmark* benchmark) : benchmark_(benchmark) { | 115 explicit BenchmarkIsolateScope(Benchmark* benchmark) : benchmark_(benchmark) { |
118 benchmark_->CreateIsolate(bin::core_isolate_snapshot_data, | 116 benchmark_->CreateIsolate(bin::core_isolate_snapshot_data, |
119 bin::core_isolate_snapshot_instructions); | 117 bin::core_isolate_snapshot_instructions); |
120 Dart_EnterScope(); // Create a Dart API scope for unit benchmarks. | 118 Dart_EnterScope(); // Create a Dart API scope for unit benchmarks. |
121 } | 119 } |
122 ~BenchmarkIsolateScope() { | 120 ~BenchmarkIsolateScope() { |
123 Dart_ExitScope(); // Exit the Dart API scope created for unit tests. | 121 Dart_ExitScope(); // Exit the Dart API scope created for unit tests. |
124 ASSERT(benchmark_->isolate() == Isolate::Current()); | 122 ASSERT(benchmark_->isolate() == Isolate::Current()); |
125 Dart_ShutdownIsolate(); | 123 Dart_ShutdownIsolate(); |
126 benchmark_ = NULL; | 124 benchmark_ = NULL; |
127 } | 125 } |
128 Benchmark* benchmark() const { return benchmark_; } | 126 Benchmark* benchmark() const { return benchmark_; } |
129 | 127 |
130 private: | 128 private: |
131 Benchmark* benchmark_; | 129 Benchmark* benchmark_; |
132 | 130 |
133 DISALLOW_COPY_AND_ASSIGN(BenchmarkIsolateScope); | 131 DISALLOW_COPY_AND_ASSIGN(BenchmarkIsolateScope); |
134 }; | 132 }; |
135 | 133 |
136 } // namespace dart | 134 } // namespace dart |
137 | 135 |
138 #endif // RUNTIME_VM_BENCHMARK_TEST_H_ | 136 #endif // RUNTIME_VM_BENCHMARK_TEST_H_ |
OLD | NEW |