| OLD | NEW |
| (Empty) | |
| 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 VM_BENCHMARK_TEST_H_ |
| 6 #define 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/heap.h" |
| 13 #include "vm/isolate.h" |
| 14 #include "vm/object.h" |
| 15 #include "vm/zone.h" |
| 16 |
| 17 namespace dart { |
| 18 |
| 19 // The BENCHMARK macro is used for benchmarking a specific functionality |
| 20 // of the VM |
| 21 #define BENCHMARK(name) \ |
| 22 void Dart_Benchmark##name(Benchmark* benchmark); \ |
| 23 static const Benchmark kRegister##name(Dart_Benchmark##name, #name); \ |
| 24 static void Dart_BenchmarkHelper##name(Benchmark* benchmark); \ |
| 25 void Dart_Benchmark##name(Benchmark* benchmark) { \ |
| 26 BenchmarkIsolateScope __isolate__(benchmark); \ |
| 27 Zone __zone__(benchmark->isolate()); \ |
| 28 HandleScope __hs__(benchmark->isolate()); \ |
| 29 Dart_BenchmarkHelper##name(benchmark); \ |
| 30 } \ |
| 31 static void Dart_BenchmarkHelper##name(Benchmark* benchmark) |
| 32 |
| 33 |
| 34 class Benchmark { |
| 35 public: |
| 36 typedef void (RunEntry)(Benchmark* benchmark); |
| 37 |
| 38 Benchmark(RunEntry* run, const char* name) : |
| 39 run_(run), |
| 40 name_(name), |
| 41 score_(0), |
| 42 isolate_(NULL), |
| 43 next_(NULL) { |
| 44 if (first_ == NULL) { |
| 45 first_ = this; |
| 46 } else { |
| 47 tail_->next_ = this; |
| 48 } |
| 49 tail_ = this; |
| 50 } |
| 51 |
| 52 // Accessors. |
| 53 const char* name() const { return name_; } |
| 54 void set_score(intptr_t value) { score_ = value; } |
| 55 intptr_t score() const { return score_; } |
| 56 Isolate* isolate() const { return reinterpret_cast<Isolate*>(isolate_); } |
| 57 |
| 58 Dart_Isolate CreateIsolate(uint8_t* buffer) { |
| 59 char* err = NULL; |
| 60 isolate_ = Dart_CreateIsolate(NULL, buffer, NULL, &err); |
| 61 EXPECT(isolate_ != NULL); |
| 62 free(err); |
| 63 return isolate_; |
| 64 } |
| 65 |
| 66 void Run() { (*run_)(this); } |
| 67 void RunBenchmark(); |
| 68 |
| 69 static void RunAll(); |
| 70 |
| 71 private: |
| 72 static Benchmark* first_; |
| 73 static Benchmark* tail_; |
| 74 |
| 75 RunEntry* const run_; |
| 76 const char* name_; |
| 77 intptr_t score_; |
| 78 Dart_Isolate isolate_; |
| 79 Benchmark* next_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(Benchmark); |
| 82 }; |
| 83 |
| 84 |
| 85 class BenchmarkIsolateScope { |
| 86 public: |
| 87 explicit BenchmarkIsolateScope(Benchmark* benchmark) : benchmark_(benchmark) { |
| 88 benchmark_->CreateIsolate(NULL); |
| 89 Dart_EnterScope(); // Create a Dart API scope for unit benchmarks. |
| 90 } |
| 91 ~BenchmarkIsolateScope() { |
| 92 Dart_ExitScope(); // Exit the Dart API scope created for unit tests. |
| 93 ASSERT(benchmark_->isolate() == Isolate::Current()); |
| 94 Dart_ShutdownIsolate(); |
| 95 benchmark_ = NULL; |
| 96 } |
| 97 Benchmark* benchmark() const { return benchmark_; } |
| 98 |
| 99 private: |
| 100 Benchmark* benchmark_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(BenchmarkIsolateScope); |
| 103 }; |
| 104 |
| 105 } // namespace dart |
| 106 |
| 107 #endif // VM_BENCHMARK_TEST_H_ |
| OLD | NEW |