| 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 #include "vm/benchmark_test.h" | 5 #include "vm/benchmark_test.h" |
| 6 | 6 |
| 7 #include "bin/builtin.h" | 7 #include "bin/builtin.h" |
| 8 #include "bin/file.h" | 8 #include "bin/file.h" |
| 9 | 9 |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 // | 223 // |
| 224 // Measure compile of all dart2js(compiler) functions. | 224 // Measure compile of all dart2js(compiler) functions. |
| 225 // | 225 // |
| 226 static char* ComputeDart2JSPath(const char* arg) { | 226 static char* ComputeDart2JSPath(const char* arg) { |
| 227 char buffer[2048]; | 227 char buffer[2048]; |
| 228 char* dart2js_path = strdup(File::GetCanonicalPath(arg)); | 228 char* dart2js_path = strdup(File::GetCanonicalPath(arg)); |
| 229 const char* compiler_path = | 229 const char* compiler_path = |
| 230 "%s%spkg%scompiler%slib%scompiler.dart"; | 230 "%s%ssdk%slib%s_internal%scompiler%scompiler.dart"; |
| 231 const char* path_separator = File::PathSeparator(); | 231 const char* path_separator = File::PathSeparator(); |
| 232 ASSERT(path_separator != NULL && strlen(path_separator) == 1); | 232 ASSERT(path_separator != NULL && strlen(path_separator) == 1); |
| 233 char* ptr = strrchr(dart2js_path, *path_separator); | 233 char* ptr = strrchr(dart2js_path, *path_separator); |
| 234 while (ptr != NULL) { | 234 while (ptr != NULL) { |
| 235 *ptr = '\0'; | 235 *ptr = '\0'; |
| 236 OS::SNPrint(buffer, 2048, compiler_path, | 236 OS::SNPrint(buffer, 2048, compiler_path, |
| 237 dart2js_path, | 237 dart2js_path, |
| 238 path_separator, | 238 path_separator, |
| 239 path_separator, | 239 path_separator, |
| 240 path_separator, | 240 path_separator, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 258 | 258 |
| 259 | 259 |
| 260 static Dart_NativeFunction NativeResolver(Dart_Handle name, | 260 static Dart_NativeFunction NativeResolver(Dart_Handle name, |
| 261 int arg_count, | 261 int arg_count, |
| 262 bool* auto_setup_scope) { | 262 bool* auto_setup_scope) { |
| 263 ASSERT(auto_setup_scope != NULL); | 263 ASSERT(auto_setup_scope != NULL); |
| 264 *auto_setup_scope = false; | 264 *auto_setup_scope = false; |
| 265 return &func; | 265 return &func; |
| 266 } | 266 } |
| 267 | 267 |
| 268 static void SetupDart2JSPackagePath() { | |
| 269 Dart_Handle builtin_lib = | |
| 270 bin::Builtin::LoadAndCheckLibrary(bin::Builtin::kBuiltinLibrary); | |
| 271 DART_CHECK_VALID(builtin_lib); | |
| 272 | |
| 273 bool worked = bin::DartUtils::SetOriginalWorkingDirectory(); | |
| 274 EXPECT(worked); | |
| 275 char buffer[2048]; | |
| 276 char* executable_path = | |
| 277 strdup(File::GetCanonicalPath(Benchmark::Executable())); | |
| 278 const char* packages_path = "%s%s..%spackages"; | |
| 279 const char* path_separator = File::PathSeparator(); | |
| 280 OS::SNPrint(buffer, 2048, packages_path, | |
| 281 executable_path, path_separator, path_separator); | |
| 282 bin::DartUtils::PrepareForScriptLoading(buffer, builtin_lib); | |
| 283 } | |
| 284 | 268 |
| 285 BENCHMARK(Dart2JSCompileAll) { | 269 BENCHMARK(Dart2JSCompileAll) { |
| 286 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); | 270 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); |
| 287 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); | 271 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); |
| 288 SetupDart2JSPackagePath(); | |
| 289 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); | 272 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); |
| 290 char* script = NULL; | 273 char* script = NULL; |
| 291 if (dart_root != NULL) { | 274 if (dart_root != NULL) { |
| 292 Isolate* isolate = Isolate::Current(); | 275 Isolate* isolate = Isolate::Current(); |
| 293 HANDLESCOPE(isolate); | 276 HANDLESCOPE(isolate); |
| 294 const char* kFormatStr = | 277 const char* kFormatStr = |
| 295 "import '%s/pkg/compiler/lib/compiler.dart';"; | 278 "import '%s/sdk/lib/_internal/compiler/compiler.dart';"; |
| 296 intptr_t len = OS::SNPrint(NULL, 0, kFormatStr, dart_root) + 1; | 279 intptr_t len = OS::SNPrint(NULL, 0, kFormatStr, dart_root) + 1; |
| 297 script = reinterpret_cast<char*>(malloc(len)); | 280 script = reinterpret_cast<char*>(malloc(len)); |
| 298 EXPECT(script != NULL); | 281 EXPECT(script != NULL); |
| 299 OS::SNPrint(script, len, kFormatStr, dart_root); | 282 OS::SNPrint(script, len, kFormatStr, dart_root); |
| 300 Dart_Handle lib = TestCase::LoadTestScript( | 283 Dart_Handle lib = TestCase::LoadTestScript( |
| 301 script, | 284 script, |
| 302 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); | 285 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); |
| 303 EXPECT_VALID(lib); | 286 EXPECT_VALID(lib); |
| 304 } else { | 287 } else { |
| 305 Dart_Handle lib = TestCase::LoadTestScript( | 288 Dart_Handle lib = TestCase::LoadTestScript( |
| 306 "import 'pkg/compiler/lib/compiler.dart';", | 289 "import 'sdk/lib/_internal/compiler/compiler.dart';", |
| 307 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); | 290 reinterpret_cast<Dart_NativeEntryResolver>(NativeResolver)); |
| 308 EXPECT_VALID(lib); | 291 EXPECT_VALID(lib); |
| 309 } | 292 } |
| 310 Timer timer(true, "Compile all of dart2js benchmark"); | 293 Timer timer(true, "Compile all of dart2js benchmark"); |
| 311 timer.Start(); | 294 timer.Start(); |
| 312 Dart_Handle result = Dart_CompileAll(); | 295 Dart_Handle result = Dart_CompileAll(); |
| 313 EXPECT_VALID(result); | 296 EXPECT_VALID(result); |
| 314 timer.Stop(); | 297 timer.Stop(); |
| 315 int64_t elapsed_time = timer.TotalElapsedTime(); | 298 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 316 benchmark->set_score(elapsed_time); | 299 benchmark->set_score(elapsed_time); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 SnapshotReader reader(buffer, buffer_len, Snapshot::kMessage, isolate); | 568 SnapshotReader reader(buffer, buffer_len, Snapshot::kMessage, isolate); |
| 586 reader.ReadObject(); | 569 reader.ReadObject(); |
| 587 free(buffer); | 570 free(buffer); |
| 588 } | 571 } |
| 589 timer.Stop(); | 572 timer.Stop(); |
| 590 int64_t elapsed_time = timer.TotalElapsedTime(); | 573 int64_t elapsed_time = timer.TotalElapsedTime(); |
| 591 benchmark->set_score(elapsed_time); | 574 benchmark->set_score(elapsed_time); |
| 592 } | 575 } |
| 593 | 576 |
| 594 } // namespace dart | 577 } // namespace dart |
| OLD | NEW |