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" |
11 | 11 |
12 #include "bin/builtin.h" | 12 #include "bin/builtin.h" |
13 #include "bin/dartutils.h" | 13 #include "bin/dartutils.h" |
14 #include "bin/dbg_connection.h" | 14 #include "bin/dbg_connection.h" |
15 #include "bin/directory.h" | 15 #include "bin/directory.h" |
16 #include "bin/eventhandler.h" | 16 #include "bin/eventhandler.h" |
17 #include "bin/extensions.h" | 17 #include "bin/extensions.h" |
18 #include "bin/file.h" | 18 #include "bin/file.h" |
19 #include "bin/isolate_data.h" | 19 #include "bin/isolate_data.h" |
20 #include "bin/log.h" | 20 #include "bin/log.h" |
21 #include "bin/platform.h" | 21 #include "bin/platform.h" |
22 #include "bin/process.h" | 22 #include "bin/process.h" |
23 #include "bin/vmstats_impl.h" | |
23 #include "platform/globals.h" | 24 #include "platform/globals.h" |
24 | 25 |
25 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise | 26 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise |
26 // it is initialized to NULL. | 27 // it is initialized to NULL. |
27 extern const uint8_t* snapshot_buffer; | 28 extern const uint8_t* snapshot_buffer; |
28 | 29 |
29 | 30 |
30 // Global state that stores a pointer to the application script snapshot. | 31 // Global state that stores a pointer to the application script snapshot. |
31 static bool use_script_snapshot = false; | 32 static bool use_script_snapshot = false; |
32 static bool generate_script_snapshot = false; | 33 static bool generate_script_snapshot = false; |
33 static File* snapshot_file = NULL; | 34 static File* snapshot_file = NULL; |
34 | 35 |
35 | 36 |
36 // Global state that indicates whether there is a debug breakpoint. | 37 // Global state that indicates whether there is a debug breakpoint. |
37 // This pointer points into an argv buffer and does not need to be | 38 // This pointer points into an argv buffer and does not need to be |
38 // free'd. | 39 // free'd. |
39 static const char* breakpoint_at = NULL; | 40 static const char* breakpoint_at = NULL; |
40 | 41 |
41 | 42 |
42 // Global state that indicates whether we should open a connection | 43 // Global state that indicates whether we should open a connection |
43 // and listen for a debugger to connect. | 44 // and listen for a debugger to connect. |
44 static bool start_debugger = false; | 45 static bool start_debugger = false; |
45 static const int DEFAULT_DEBUG_PORT = 5858; | 46 static const int DEFAULT_DEBUG_PORT = 5858; |
46 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; | 47 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; |
47 static const char* debug_ip = DEFAULT_DEBUG_IP; | 48 static const char* debug_ip = DEFAULT_DEBUG_IP; |
48 static int debug_port = 0; | 49 static int debug_port = 0; |
49 | 50 |
51 // Global state that defines the VmStats web server port and root directory. | |
52 static int vmstats_port = 0; | |
53 static const char* vmstats_root = NULL; | |
50 | 54 |
51 // Value of the --package-root flag. | 55 // Value of the --package-root flag. |
52 // (This pointer points into an argv buffer and does not need to be | 56 // (This pointer points into an argv buffer and does not need to be |
53 // free'd.) | 57 // free'd.) |
54 static const char* package_root = NULL; | 58 static const char* package_root = NULL; |
55 | 59 |
56 | 60 |
57 // Global flag that is used to indicate that we want to compile all the | 61 // Global flag that is used to indicate that we want to compile all the |
58 // dart functions and not run anything. | 62 // dart functions and not run anything. |
59 static bool has_compile_all = false; | 63 static bool has_compile_all = false; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 if (snapshot_file == NULL) { | 161 if (snapshot_file == NULL) { |
158 Log::PrintErr("Unable to open file %s for reading the snapshot\n", | 162 Log::PrintErr("Unable to open file %s for reading the snapshot\n", |
159 filename); | 163 filename); |
160 return false; | 164 return false; |
161 } | 165 } |
162 } | 166 } |
163 return true; | 167 return true; |
164 } | 168 } |
165 | 169 |
166 | 170 |
171 static bool ProcessVmStatsOption(const char* port) { | |
172 ASSERT(port != NULL); | |
173 if (*port == '\0') { | |
174 vmstats_port = -1; // Dynamically assigned port number. | |
175 } else { | |
176 if ((*port == '=') || (*port == ':')) { | |
177 vmstats_port = atoi(port + 1); | |
178 } | |
179 } | |
180 if (vmstats_port == 0) { | |
181 Log::PrintErr("unrecognized --stats option syntax. " | |
182 "Use --stats[:<port number>]\n"); | |
183 return false; | |
184 } | |
185 return true; | |
186 } | |
187 | |
188 | |
189 static bool ProcessVmStatsRootOption(const char* arg) { | |
190 ASSERT(arg != NULL); | |
191 vmstats_root = arg; | |
192 return true; | |
193 } | |
194 | |
195 | |
167 static bool ProcessGenScriptSnapshotOption(const char* filename) { | 196 static bool ProcessGenScriptSnapshotOption(const char* filename) { |
168 if (filename != NULL && strlen(filename) != 0) { | 197 if (filename != NULL && strlen(filename) != 0) { |
169 // Ensure that are already running using a full snapshot. | 198 // Ensure that are already running using a full snapshot. |
170 if (snapshot_buffer == NULL) { | 199 if (snapshot_buffer == NULL) { |
171 Log::PrintErr("Script snapshots cannot be generated in this version of" | 200 Log::PrintErr("Script snapshots cannot be generated in this version of" |
172 " dart\n"); | 201 " dart\n"); |
173 return false; | 202 return false; |
174 } | 203 } |
175 if (use_script_snapshot) { | 204 if (use_script_snapshot) { |
176 Log::PrintErr("Incompatible options specified --use-script-snapshot " | 205 Log::PrintErr("Incompatible options specified --use-script-snapshot " |
(...skipping 23 matching lines...) Expand all Loading... | |
200 { "--verbose", ProcessVerboseOption }, | 229 { "--verbose", ProcessVerboseOption }, |
201 { "-v", ProcessVerboseOption }, | 230 { "-v", ProcessVerboseOption }, |
202 { "--package-root=", ProcessPackageRootOption }, | 231 { "--package-root=", ProcessPackageRootOption }, |
203 { "-p", ProcessPackageRootOption }, | 232 { "-p", ProcessPackageRootOption }, |
204 // VM specific options to the standalone dart program. | 233 // VM specific options to the standalone dart program. |
205 { "--break_at=", ProcessBreakpointOption }, | 234 { "--break_at=", ProcessBreakpointOption }, |
206 { "--compile_all", ProcessCompileAllOption }, | 235 { "--compile_all", ProcessCompileAllOption }, |
207 { "--debug", ProcessDebugOption }, | 236 { "--debug", ProcessDebugOption }, |
208 { "--use-script-snapshot=", ProcessUseScriptSnapshotOption }, | 237 { "--use-script-snapshot=", ProcessUseScriptSnapshotOption }, |
209 { "--generate-script-snapshot=", ProcessGenScriptSnapshotOption }, | 238 { "--generate-script-snapshot=", ProcessGenScriptSnapshotOption }, |
239 { "--stats-root=", ProcessVmStatsRootOption }, | |
240 { "--stats", ProcessVmStatsOption }, | |
210 { NULL, NULL } | 241 { NULL, NULL } |
211 }; | 242 }; |
212 | 243 |
213 | 244 |
214 static bool ProcessMainOptions(const char* option) { | 245 static bool ProcessMainOptions(const char* option) { |
215 int i = 0; | 246 int i = 0; |
216 const char* name = main_options[0].option_name; | 247 const char* name = main_options[0].option_name; |
217 while (name != NULL) { | 248 while (name != NULL) { |
218 int length = strlen(name); | 249 int length = strlen(name); |
219 if (strncmp(option, name, length) == 0) { | 250 if (strncmp(option, name, length) == 0) { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 char errbuf[256]; | 512 char errbuf[256]; |
482 snprintf(errbuf, sizeof(errbuf), | 513 snprintf(errbuf, sizeof(errbuf), |
483 "Expected a library when loading script: %s", | 514 "Expected a library when loading script: %s", |
484 script_uri); | 515 script_uri); |
485 *error = strdup(errbuf); | 516 *error = strdup(errbuf); |
486 Dart_ExitScope(); | 517 Dart_ExitScope(); |
487 Dart_ShutdownIsolate(); | 518 Dart_ShutdownIsolate(); |
488 return false; | 519 return false; |
489 } | 520 } |
490 Dart_ExitScope(); | 521 Dart_ExitScope(); |
522 dart::VmStats::AddIsolate(reinterpret_cast<IsolateData*>(data), isolate); | |
491 return true; | 523 return true; |
492 } | 524 } |
493 | 525 |
494 | 526 |
495 static bool CreateIsolateAndSetup(const char* script_uri, | 527 static bool CreateIsolateAndSetup(const char* script_uri, |
496 const char* main, | 528 const char* main, |
497 void* data, char** error) { | 529 void* data, char** error) { |
498 return CreateIsolateAndSetupHelper(script_uri, | 530 return CreateIsolateAndSetupHelper(script_uri, |
499 main, | 531 main, |
500 new IsolateData(), | 532 new IsolateData(), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 " sets a breakpoint at specified location where <location> is one of :\n" | 575 " sets a breakpoint at specified location where <location> is one of :\n" |
544 " url:<line_num> e.g. test.dart:10\n" | 576 " url:<line_num> e.g. test.dart:10\n" |
545 " [<class_name>.]<function_name> e.g. B.foo\n" | 577 " [<class_name>.]<function_name> e.g. B.foo\n" |
546 "\n" | 578 "\n" |
547 "--use-script-snapshot=<file_name>\n" | 579 "--use-script-snapshot=<file_name>\n" |
548 " executes Dart script present in the specified snapshot file\n" | 580 " executes Dart script present in the specified snapshot file\n" |
549 "\n" | 581 "\n" |
550 "--generate-script-snapshot=<file_name>\n" | 582 "--generate-script-snapshot=<file_name>\n" |
551 " loads Dart script and generates a snapshot in the specified file\n" | 583 " loads Dart script and generates a snapshot in the specified file\n" |
552 "\n" | 584 "\n" |
585 "--stats[:<port number>]\n" | |
586 " enables VM stats service and listens on specified port for HTTP requests\n" | |
587 " (default port number is dynamically assigned)\n" | |
588 "\n" | |
siva
2013/02/15 05:59:10
Should we also list help for the '--stats-root' op
Tom Ball
2013/02/16 00:57:19
Done.
| |
553 "The following options are only used for VM development and may\n" | 589 "The following options are only used for VM development and may\n" |
554 "be changed in any future version:\n"); | 590 "be changed in any future version:\n"); |
555 const char* print_flags = "--print_flags"; | 591 const char* print_flags = "--print_flags"; |
556 Dart_SetVMFlags(1, &print_flags); | 592 Dart_SetVMFlags(1, &print_flags); |
557 } | 593 } |
558 } | 594 } |
559 | 595 |
560 | 596 |
561 static Dart_Handle SetBreakpoint(const char* breakpoint_at, | 597 static Dart_Handle SetBreakpoint(const char* breakpoint_at, |
562 Dart_Handle library) { | 598 Dart_Handle library) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 | 656 |
621 Dart_ExitScope(); | 657 Dart_ExitScope(); |
622 Dart_ShutdownIsolate(); | 658 Dart_ShutdownIsolate(); |
623 | 659 |
624 return kErrorExitCode; | 660 return kErrorExitCode; |
625 } | 661 } |
626 | 662 |
627 | 663 |
628 static void ShutdownIsolate(void* callback_data) { | 664 static void ShutdownIsolate(void* callback_data) { |
629 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); | 665 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); |
666 dart::VmStats::RemoveIsolate(isolate_data); | |
630 EventHandler* handler = isolate_data->event_handler; | 667 EventHandler* handler = isolate_data->event_handler; |
631 if (handler != NULL) handler->Shutdown(); | 668 if (handler != NULL) handler->Shutdown(); |
632 delete isolate_data; | 669 delete isolate_data; |
633 } | 670 } |
634 | 671 |
635 | 672 |
636 int main(int argc, char** argv) { | 673 int main(int argc, char** argv) { |
637 char* executable_name; | 674 char* executable_name; |
638 char* script_name; | 675 char* script_name; |
639 CommandLineOptions vm_options(argc); | 676 CommandLineOptions vm_options(argc); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 return kErrorExitCode; // Indicates we encountered an error. | 743 return kErrorExitCode; // Indicates we encountered an error. |
707 } | 744 } |
708 delete [] isolate_name; | 745 delete [] isolate_name; |
709 | 746 |
710 Dart_Isolate isolate = Dart_CurrentIsolate(); | 747 Dart_Isolate isolate = Dart_CurrentIsolate(); |
711 ASSERT(isolate != NULL); | 748 ASSERT(isolate != NULL); |
712 Dart_Handle result; | 749 Dart_Handle result; |
713 | 750 |
714 Dart_EnterScope(); | 751 Dart_EnterScope(); |
715 | 752 |
753 if (vmstats_port > 0) { | |
siva
2013/02/15 05:59:10
What about the case when vmstats_port is -1 ?
Tom Ball
2013/02/16 00:57:19
Good catch. It turns out 0 is the official dynamic
| |
754 dart::VmStats::Start(vmstats_port, vmstats_root); | |
755 } | |
756 | |
716 if (generate_script_snapshot) { | 757 if (generate_script_snapshot) { |
717 // First create a snapshot. | 758 // First create a snapshot. |
718 Dart_Handle result; | 759 Dart_Handle result; |
719 uint8_t* buffer = NULL; | 760 uint8_t* buffer = NULL; |
720 intptr_t size = 0; | 761 intptr_t size = 0; |
721 result = Dart_CreateScriptSnapshot(&buffer, &size); | 762 result = Dart_CreateScriptSnapshot(&buffer, &size); |
722 if (Dart_IsError(result)) { | 763 if (Dart_IsError(result)) { |
723 Log::PrintErr("%s\n", Dart_GetError(result)); | 764 Log::PrintErr("%s\n", Dart_GetError(result)); |
724 Dart_ExitScope(); | 765 Dart_ExitScope(); |
725 Dart_ShutdownIsolate(); | 766 Dart_ShutdownIsolate(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 return ErrorExit("%s\n", Dart_GetError(result)); | 807 return ErrorExit("%s\n", Dart_GetError(result)); |
767 } | 808 } |
768 // Keep handling messages until the last active receive port is closed. | 809 // Keep handling messages until the last active receive port is closed. |
769 result = Dart_RunLoop(); | 810 result = Dart_RunLoop(); |
770 if (Dart_IsError(result)) { | 811 if (Dart_IsError(result)) { |
771 return ErrorExit("%s\n", Dart_GetError(result)); | 812 return ErrorExit("%s\n", Dart_GetError(result)); |
772 } | 813 } |
773 } | 814 } |
774 | 815 |
775 Dart_ExitScope(); | 816 Dart_ExitScope(); |
817 dart::VmStats::Stop(); | |
776 // Shutdown the isolate. | 818 // Shutdown the isolate. |
777 Dart_ShutdownIsolate(); | 819 Dart_ShutdownIsolate(); |
778 // Terminate process exit-code handler. | 820 // Terminate process exit-code handler. |
779 Process::TerminateExitCodeHandler(); | 821 Process::TerminateExitCodeHandler(); |
780 // Free copied argument strings if converted. | 822 // Free copied argument strings if converted. |
781 if (argv_converted) { | 823 if (argv_converted) { |
782 for (int i = 0; i < argc; i++) free(argv[i]); | 824 for (int i = 0; i < argc; i++) free(argv[i]); |
783 } | 825 } |
784 | 826 |
785 return Process::GlobalExitCode(); | 827 return Process::GlobalExitCode(); |
786 } | 828 } |
OLD | NEW |