| 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 #include "include/dart_debugger_api.h" | 10 #include "include/dart_debugger_api.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise | 25 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise |
| 26 // it is initialized to NULL. | 26 // it is initialized to NULL. |
| 27 extern const uint8_t* snapshot_buffer; | 27 extern const uint8_t* snapshot_buffer; |
| 28 | 28 |
| 29 | 29 |
| 30 // Global state that indicates whether perf_events symbol information | 30 // Global state that indicates whether perf_events symbol information |
| 31 // is to be generated or not. | 31 // is to be generated or not. |
| 32 static File* perf_events_symbols_file = NULL; | 32 static File* perf_events_symbols_file = NULL; |
| 33 | 33 |
| 34 | 34 |
| 35 // Global state that indicates whether heap tracing is on. |
| 36 static bool heap_trace = false; |
| 37 |
| 38 |
| 39 // Global state that indicates the file name prefix to use for heap |
| 40 // trace output files. |
| 41 static const char* heap_trace_file_prefix = "dart_heap_trace"; |
| 42 |
| 43 |
| 35 // Global state that indicates whether pprof symbol information is | 44 // Global state that indicates whether pprof symbol information is |
| 36 // to be generated or not. | 45 // to be generated or not. |
| 37 static const char* generate_pprof_symbols_filename = NULL; | 46 static const char* generate_pprof_symbols_filename = NULL; |
| 38 | 47 |
| 39 | 48 |
| 40 // Global state that stores a pointer to the application script snapshot. | 49 // Global state that stores a pointer to the application script snapshot. |
| 41 static bool use_script_snapshot = false; | 50 static bool use_script_snapshot = false; |
| 42 static File* snapshot_file = NULL; | 51 static File* snapshot_file = NULL; |
| 43 | 52 |
| 44 // Global state that indicates whether there is a debug breakpoint. | 53 // Global state that indicates whether there is a debug breakpoint. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 182 } |
| 174 | 183 |
| 175 | 184 |
| 176 static bool ProcessPprofOption(const char* filename) { | 185 static bool ProcessPprofOption(const char* filename) { |
| 177 ASSERT(filename != NULL); | 186 ASSERT(filename != NULL); |
| 178 generate_pprof_symbols_filename = filename; | 187 generate_pprof_symbols_filename = filename; |
| 179 return true; | 188 return true; |
| 180 } | 189 } |
| 181 | 190 |
| 182 | 191 |
| 192 static bool ProcessHeapTraceOption(const char* heap_trace_option) { |
| 193 heap_trace = true; |
| 194 return true; |
| 195 } |
| 196 |
| 197 |
| 198 static bool ProcessHeapTraceFilePrefixOption( |
| 199 const char* heap_trace_file_prefix_option) { |
| 200 ASSERT(heap_trace_file_prefix_option != NULL); |
| 201 heap_trace_file_prefix = heap_trace_file_prefix_option; |
| 202 return true; |
| 203 } |
| 204 |
| 205 |
| 183 static bool ProcessScriptSnapshotOption(const char* filename) { | 206 static bool ProcessScriptSnapshotOption(const char* filename) { |
| 184 if (filename != NULL && strlen(filename) != 0) { | 207 if (filename != NULL && strlen(filename) != 0) { |
| 185 use_script_snapshot = true; | 208 use_script_snapshot = true; |
| 186 snapshot_file = File::Open(filename, File::kRead); | 209 snapshot_file = File::Open(filename, File::kRead); |
| 187 } | 210 } |
| 188 return true; | 211 return true; |
| 189 } | 212 } |
| 190 | 213 |
| 191 | 214 |
| 192 static struct { | 215 static struct { |
| 193 const char* option_name; | 216 const char* option_name; |
| 194 bool (*process)(const char* option); | 217 bool (*process)(const char* option); |
| 195 } main_options[] = { | 218 } main_options[] = { |
| 196 // Standard options shared with dart2js. | 219 // Standard options shared with dart2js. |
| 197 { "--version", ProcessVersionOption }, | 220 { "--version", ProcessVersionOption }, |
| 198 { "--help", ProcessHelpOption }, | 221 { "--help", ProcessHelpOption }, |
| 199 { "-h", ProcessHelpOption }, | 222 { "-h", ProcessHelpOption }, |
| 200 { "--verbose", ProcessVerboseOption }, | 223 { "--verbose", ProcessVerboseOption }, |
| 201 { "-v", ProcessVerboseOption }, | 224 { "-v", ProcessVerboseOption }, |
| 202 { "--package-root=", ProcessPackageRootOption }, | 225 { "--package-root=", ProcessPackageRootOption }, |
| 203 { "-p", ProcessPackageRootOption }, | 226 { "-p", ProcessPackageRootOption }, |
| 204 // VM specific options to the standalone dart program. | 227 // VM specific options to the standalone dart program. |
| 205 { "--break_at=", ProcessBreakpointOption }, | 228 { "--break_at=", ProcessBreakpointOption }, |
| 206 { "--compile_all", ProcessCompileAllOption }, | 229 { "--compile_all", ProcessCompileAllOption }, |
| 207 { "--debug", ProcessDebugOption }, | 230 { "--debug", ProcessDebugOption }, |
| 208 { "--generate_perf_events_symbols", ProcessPerfEventsOption }, | 231 { "--generate_perf_events_symbols", ProcessPerfEventsOption }, |
| 209 { "--generate_pprof_symbols=", ProcessPprofOption }, | 232 { "--generate_pprof_symbols=", ProcessPprofOption }, |
| 233 { "--heap_trace", ProcessHeapTraceOption }, |
| 234 { "--heap_trace_file_prefix=", ProcessHeapTraceFilePrefixOption }, |
| 210 { "--use_script_snapshot=", ProcessScriptSnapshotOption }, | 235 { "--use_script_snapshot=", ProcessScriptSnapshotOption }, |
| 211 { NULL, NULL } | 236 { NULL, NULL } |
| 212 }; | 237 }; |
| 213 | 238 |
| 214 | 239 |
| 215 static bool ProcessMainOptions(const char* option) { | 240 static bool ProcessMainOptions(const char* option) { |
| 216 int i = 0; | 241 int i = 0; |
| 217 const char* name = main_options[0].option_name; | 242 const char* name = main_options[0].option_name; |
| 218 while (name != NULL) { | 243 while (name != NULL) { |
| 219 int length = strlen(name); | 244 int length = strlen(name); |
| 220 if (strncmp(option, name, length) == 0) { | 245 if (strncmp(option, name, length) == 0) { |
| 221 return main_options[i].process(option + length); | 246 return main_options[i].process(option + length); |
| 222 } | 247 } |
| 223 i += 1; | 248 i += 1; |
| 224 name = main_options[i].option_name; | 249 name = main_options[i].option_name; |
| 225 } | 250 } |
| 226 return false; | 251 return false; |
| 227 } | 252 } |
| 228 | 253 |
| 229 | 254 |
| 230 static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) { | 255 static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) { |
| 231 ASSERT(perf_events_symbols_file != NULL); | 256 ASSERT(perf_events_symbols_file != NULL); |
| 232 perf_events_symbols_file->WriteFully(buffer, num_bytes); | 257 perf_events_symbols_file->WriteFully(buffer, num_bytes); |
| 233 } | 258 } |
| 234 | 259 |
| 260 |
| 261 // This function used by the heap trace to open new trace files, one |
| 262 // file per isolate. |
| 263 static void* OpenHeapTraceFile(const char* name) { |
| 264 File* file = File::Open(name, File::kWriteTruncate); |
| 265 ASSERT(file != NULL); |
| 266 return reinterpret_cast<void*>(file); |
| 267 } |
| 268 |
| 269 |
| 270 // Function used by the heap trace to write to trace files. |
| 271 static void WriteToHeapTraceFile(const void* buffer, |
| 272 intptr_t num_bytes, |
| 273 void* stream) { |
| 274 ASSERT(stream != NULL); |
| 275 File* file_stream = reinterpret_cast<File*>(stream); |
| 276 bool bytes_written = file_stream->WriteFully(buffer, num_bytes); |
| 277 ASSERT(bytes_written); |
| 278 } |
| 279 |
| 280 |
| 281 // Function used by the heap trace to close trace files. |
| 282 static void CloseHeapTraceFile(void* stream) { |
| 283 File* file_stream = reinterpret_cast<File*>(stream); |
| 284 delete file_stream; // Closes the file. |
| 285 } |
| 286 |
| 287 |
| 235 // Convert all the arguments to UTF8. On Windows, the arguments are | 288 // Convert all the arguments to UTF8. On Windows, the arguments are |
| 236 // encoded in the current code page and not UTF8. | 289 // encoded in the current code page and not UTF8. |
| 237 // | 290 // |
| 238 // Returns true if the arguments are converted. In that case | 291 // Returns true if the arguments are converted. In that case |
| 239 // each of the arguments need to be deallocated using free. | 292 // each of the arguments need to be deallocated using free. |
| 240 static bool Utf8ConvertArgv(int argc, char** argv) { | 293 static bool Utf8ConvertArgv(int argc, char** argv) { |
| 241 bool result = false; | 294 bool result = false; |
| 242 for (int i = 0; i < argc; i++) { | 295 for (int i = 0; i < argc; i++) { |
| 243 char* arg = argv[i]; | 296 char* arg = argv[i]; |
| 244 argv[i] = StringUtils::SystemStringToUtf8(arg); | 297 argv[i] = StringUtils::SystemStringToUtf8(arg); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 344 } |
| 292 | 345 |
| 293 if (perf_events_symbols_file != NULL) { | 346 if (perf_events_symbols_file != NULL) { |
| 294 Dart_InitPerfEventsSupport(&WriteToPerfEventsFile); | 347 Dart_InitPerfEventsSupport(&WriteToPerfEventsFile); |
| 295 } | 348 } |
| 296 | 349 |
| 297 if (generate_pprof_symbols_filename != NULL) { | 350 if (generate_pprof_symbols_filename != NULL) { |
| 298 Dart_InitPprofSupport(); | 351 Dart_InitPprofSupport(); |
| 299 } | 352 } |
| 300 | 353 |
| 354 if (heap_trace) { |
| 355 Dart_InitHeapTrace(&OpenHeapTraceFile, |
| 356 &WriteToHeapTraceFile, |
| 357 &CloseHeapTraceFile, |
| 358 heap_trace_file_prefix); |
| 359 } |
| 360 |
| 301 // Get the script name. | 361 // Get the script name. |
| 302 if (i < argc) { | 362 if (i < argc) { |
| 303 *script_name = argv[i]; | 363 *script_name = argv[i]; |
| 304 i++; | 364 i++; |
| 305 } else { | 365 } else { |
| 306 return -1; | 366 return -1; |
| 307 } | 367 } |
| 308 | 368 |
| 309 // Parse out options to be passed to dart main. | 369 // Parse out options to be passed to dart main. |
| 310 while (i < argc) { | 370 while (i < argc) { |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 Dart_ShutdownIsolate(); | 835 Dart_ShutdownIsolate(); |
| 776 // Terminate process exit-code handler. | 836 // Terminate process exit-code handler. |
| 777 Process::TerminateExitCodeHandler(); | 837 Process::TerminateExitCodeHandler(); |
| 778 // Free copied argument strings if converted. | 838 // Free copied argument strings if converted. |
| 779 if (argv_converted) { | 839 if (argv_converted) { |
| 780 for (int i = 0; i < argc; i++) free(argv[i]); | 840 for (int i = 0; i < argc; i++) free(argv[i]); |
| 781 } | 841 } |
| 782 | 842 |
| 783 return 0; | 843 return 0; |
| 784 } | 844 } |
| OLD | NEW |