| 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 <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "bin/file.h" | 7 #include "bin/file.h" |
| 8 | 8 |
| 9 #include "vm/benchmark_test.h" | 9 #include "vm/benchmark_test.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 this->Run(); | 52 this->Run(); |
| 53 OS::Print("%s(RunTime): %"Pd"\n", this->name(), this->score()); | 53 OS::Print("%s(RunTime): %"Pd"\n", this->name(), this->score()); |
| 54 run_matches++; | 54 run_matches++; |
| 55 } else if (run_filter == kList) { | 55 } else if (run_filter == kList) { |
| 56 fprintf(stdout, "%s\n", this->name()); | 56 fprintf(stdout, "%s\n", this->name()); |
| 57 run_matches++; | 57 run_matches++; |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 static void DumpPprofSymbolInfo(const char* pprof_filename) { | |
| 63 if (pprof_filename != NULL) { | |
| 64 char* err = NULL; | |
| 65 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &err); | |
| 66 EXPECT(isolate != NULL); | |
| 67 Dart_EnterScope(); | |
| 68 File* pprof_file = | |
| 69 File::Open(pprof_filename, File::kWriteTruncate); | |
| 70 ASSERT(pprof_file != NULL); | |
| 71 void* buffer; | |
| 72 int buffer_size; | |
| 73 Dart_GetPprofSymbolInfo(&buffer, &buffer_size); | |
| 74 if (buffer_size > 0) { | |
| 75 ASSERT(buffer != NULL); | |
| 76 pprof_file->WriteFully(buffer, buffer_size); | |
| 77 } | |
| 78 delete pprof_file; // Closes the file. | |
| 79 Dart_ExitScope(); | |
| 80 Dart_ShutdownIsolate(); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 | |
| 85 static void PrintUsage() { | 62 static void PrintUsage() { |
| 86 fprintf(stderr, "run_vm_tests [--list | --benchmarks | " | 63 fprintf(stderr, "run_vm_tests [--list | --benchmarks | " |
| 87 "--tests | --all | <test name> | <benchmark name>]\n"); | 64 "--tests | --all | <test name> | <benchmark name>]\n"); |
| 88 fprintf(stderr, "run_vm_tests [vm-flags ...] <test name>\n"); | 65 fprintf(stderr, "run_vm_tests [vm-flags ...] <test name>\n"); |
| 89 fprintf(stderr, "run_vm_tests [vm-flags ...] <benchmark name>\n"); | 66 fprintf(stderr, "run_vm_tests [vm-flags ...] <benchmark name>\n"); |
| 90 } | 67 } |
| 91 | 68 |
| 92 | 69 |
| 93 static int Main(int argc, const char** argv) { | 70 static int Main(int argc, const char** argv) { |
| 94 // Flags being passed to the Dart VM. | 71 // Flags being passed to the Dart VM. |
| 95 int dart_argc = 0; | 72 int dart_argc = 0; |
| 96 const char** dart_argv = NULL; | 73 const char** dart_argv = NULL; |
| 97 const char* pprof_filename = NULL; | |
| 98 | 74 |
| 99 if (argc < 2) { | 75 if (argc < 2) { |
| 100 // Bad parameter count. | 76 // Bad parameter count. |
| 101 PrintUsage(); | 77 PrintUsage(); |
| 102 return 1; | 78 return 1; |
| 103 } else if (argc == 2) { | 79 } else if (argc == 2) { |
| 104 if (strcmp(argv[1], "--list") == 0) { | 80 if (strcmp(argv[1], "--list") == 0) { |
| 105 run_filter = kList; | 81 run_filter = kList; |
| 106 // List all tests and benchmarks and exit without initializing the VM. | 82 // List all tests and benchmarks and exit without initializing the VM. |
| 107 TestCaseBase::RunAll(); | 83 TestCaseBase::RunAll(); |
| 108 Benchmark::RunAll(argv[0]); | 84 Benchmark::RunAll(argv[0]); |
| 109 return 0; | 85 return 0; |
| 110 } else if (strcmp(argv[1], "--all") == 0) { | 86 } else if (strcmp(argv[1], "--all") == 0) { |
| 111 run_filter = kAll; | 87 run_filter = kAll; |
| 112 } else if (strcmp(argv[1], "--tests") == 0) { | 88 } else if (strcmp(argv[1], "--tests") == 0) { |
| 113 run_filter = kAllTests; | 89 run_filter = kAllTests; |
| 114 } else if (strcmp(argv[1], "--benchmarks") == 0) { | 90 } else if (strcmp(argv[1], "--benchmarks") == 0) { |
| 115 run_filter = kAllBenchmarks; | 91 run_filter = kAllBenchmarks; |
| 116 } else { | 92 } else { |
| 117 run_filter = argv[1]; | 93 run_filter = argv[1]; |
| 118 } | 94 } |
| 119 } else { | 95 } else { |
| 120 // Last argument is the test name, the rest are vm flags. | 96 // Last argument is the test name, the rest are vm flags. |
| 121 run_filter = argv[argc - 1]; | 97 run_filter = argv[argc - 1]; |
| 122 const char* pprof_option = "--generate_pprof_symbols="; | 98 // Remove the first value (executable) from the arguments and |
| 123 int length = strlen(pprof_option); | 99 // exclude the last argument which is the test name. |
| 124 if (strncmp(pprof_option, argv[1], length) == 0) { | 100 dart_argc = argc - 2; |
| 125 pprof_filename = (argv[1] + length); | 101 dart_argv = &argv[1]; |
| 126 Dart_InitPprofSupport(); | |
| 127 // Remove the first two values (executable, pprof flag) from the | |
| 128 // arguments and exclude the last argument which is the test name. | |
| 129 dart_argc = argc - 3; | |
| 130 dart_argv = &argv[2]; | |
| 131 } else { | |
| 132 // Remove the first value (executable) from the arguments and | |
| 133 // exclude the last argument which is the test name. | |
| 134 dart_argc = argc - 2; | |
| 135 dart_argv = &argv[1]; | |
| 136 } | |
| 137 } | 102 } |
| 138 bool set_vm_flags_success = Flags::ProcessCommandLineFlags(dart_argc, | 103 bool set_vm_flags_success = Flags::ProcessCommandLineFlags(dart_argc, |
| 139 dart_argv); | 104 dart_argv); |
| 140 ASSERT(set_vm_flags_success); | 105 ASSERT(set_vm_flags_success); |
| 141 const char* err_msg = Dart::InitOnce(NULL, NULL, NULL, NULL, | 106 const char* err_msg = Dart::InitOnce(NULL, NULL, NULL, NULL, |
| 142 NULL, NULL, NULL); | 107 NULL, NULL, NULL); |
| 143 ASSERT(err_msg == NULL); | 108 ASSERT(err_msg == NULL); |
| 144 // Apply the filter to all registered tests. | 109 // Apply the filter to all registered tests. |
| 145 TestCaseBase::RunAll(); | 110 TestCaseBase::RunAll(); |
| 146 // Apply the filter to all registered benchmarks. | 111 // Apply the filter to all registered benchmarks. |
| 147 Benchmark::RunAll(argv[0]); | 112 Benchmark::RunAll(argv[0]); |
| 148 // Print a warning message if no tests or benchmarks were matched. | 113 // Print a warning message if no tests or benchmarks were matched. |
| 149 if (run_matches == 0) { | 114 if (run_matches == 0) { |
| 150 fprintf(stderr, "No tests matched: %s\n", run_filter); | 115 fprintf(stderr, "No tests matched: %s\n", run_filter); |
| 151 return 1; | 116 return 1; |
| 152 } | 117 } |
| 153 // Dump symbol information for the profiler. | |
| 154 DumpPprofSymbolInfo(pprof_filename); | |
| 155 return 0; | 118 return 0; |
| 156 } | 119 } |
| 157 | 120 |
| 158 } // namespace dart | 121 } // namespace dart |
| 159 | 122 |
| 160 | 123 |
| 161 int main(int argc, const char** argv) { | 124 int main(int argc, const char** argv) { |
| 162 return dart::Main(argc, argv); | 125 return dart::Main(argc, argv); |
| 163 } | 126 } |
| OLD | NEW |