Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: runtime/bin/main.cc

Issue 12221022: Initial prototype of vmstats support, based on Dart VM Stats draft design doc. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/bin.gypi ('k') | runtime/bin/vmstats.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 = -1;
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
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 = 0; // 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
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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 char errbuf[256]; 513 char errbuf[256];
483 snprintf(errbuf, sizeof(errbuf), 514 snprintf(errbuf, sizeof(errbuf),
484 "Expected a library when loading script: %s", 515 "Expected a library when loading script: %s",
485 script_uri); 516 script_uri);
486 *error = strdup(errbuf); 517 *error = strdup(errbuf);
487 Dart_ExitScope(); 518 Dart_ExitScope();
488 Dart_ShutdownIsolate(); 519 Dart_ShutdownIsolate();
489 return false; 520 return false;
490 } 521 }
491 Dart_ExitScope(); 522 Dart_ExitScope();
523 VmStats::AddIsolate(reinterpret_cast<IsolateData*>(data), isolate);
492 return true; 524 return true;
493 } 525 }
494 526
495 527
496 static bool CreateIsolateAndSetup(const char* script_uri, 528 static bool CreateIsolateAndSetup(const char* script_uri,
497 const char* main, 529 const char* main,
498 void* data, char** error) { 530 void* data, char** error) {
499 return CreateIsolateAndSetupHelper(script_uri, 531 return CreateIsolateAndSetupHelper(script_uri,
500 main, 532 main,
501 new IsolateData(), 533 new IsolateData(),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 " sets a breakpoint at specified location where <location> is one of :\n" 576 " sets a breakpoint at specified location where <location> is one of :\n"
545 " url:<line_num> e.g. test.dart:10\n" 577 " url:<line_num> e.g. test.dart:10\n"
546 " [<class_name>.]<function_name> e.g. B.foo\n" 578 " [<class_name>.]<function_name> e.g. B.foo\n"
547 "\n" 579 "\n"
548 "--use-script-snapshot=<file_name>\n" 580 "--use-script-snapshot=<file_name>\n"
549 " executes Dart script present in the specified snapshot file\n" 581 " executes Dart script present in the specified snapshot file\n"
550 "\n" 582 "\n"
551 "--generate-script-snapshot=<file_name>\n" 583 "--generate-script-snapshot=<file_name>\n"
552 " loads Dart script and generates a snapshot in the specified file\n" 584 " loads Dart script and generates a snapshot in the specified file\n"
553 "\n" 585 "\n"
586 "--stats[:<port number>]\n"
587 " enables VM stats service and listens on specified port for HTTP requests\n"
588 " (default port number is dynamically assigned)\n"
589 "\n"
590 "--stats-root=<path>\n"
591 " where to find static files used by the vmstats application\n"
592 " (used during vmstats plug-in development)\n"
593 "\n"
554 "The following options are only used for VM development and may\n" 594 "The following options are only used for VM development and may\n"
555 "be changed in any future version:\n"); 595 "be changed in any future version:\n");
556 const char* print_flags = "--print_flags"; 596 const char* print_flags = "--print_flags";
557 Dart_SetVMFlags(1, &print_flags); 597 Dart_SetVMFlags(1, &print_flags);
558 } 598 }
559 } 599 }
560 600
561 601
562 static Dart_Handle SetBreakpoint(const char* breakpoint_at, 602 static Dart_Handle SetBreakpoint(const char* breakpoint_at,
563 Dart_Handle library) { 603 Dart_Handle library) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 661
622 Dart_ExitScope(); 662 Dart_ExitScope();
623 Dart_ShutdownIsolate(); 663 Dart_ShutdownIsolate();
624 664
625 return kErrorExitCode; 665 return kErrorExitCode;
626 } 666 }
627 667
628 668
629 static void ShutdownIsolate(void* callback_data) { 669 static void ShutdownIsolate(void* callback_data) {
630 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); 670 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data);
671 VmStats::RemoveIsolate(isolate_data);
631 EventHandler* handler = isolate_data->event_handler; 672 EventHandler* handler = isolate_data->event_handler;
632 if (handler != NULL) handler->Shutdown(); 673 if (handler != NULL) handler->Shutdown();
633 delete isolate_data; 674 delete isolate_data;
634 } 675 }
635 676
636 677
637 int main(int argc, char** argv) { 678 int main(int argc, char** argv) {
638 char* executable_name; 679 char* executable_name;
639 char* script_name; 680 char* script_name;
640 CommandLineOptions vm_options(argc); 681 CommandLineOptions vm_options(argc);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 return kErrorExitCode; // Indicates we encountered an error. 748 return kErrorExitCode; // Indicates we encountered an error.
708 } 749 }
709 delete [] isolate_name; 750 delete [] isolate_name;
710 751
711 Dart_Isolate isolate = Dart_CurrentIsolate(); 752 Dart_Isolate isolate = Dart_CurrentIsolate();
712 ASSERT(isolate != NULL); 753 ASSERT(isolate != NULL);
713 Dart_Handle result; 754 Dart_Handle result;
714 755
715 Dart_EnterScope(); 756 Dart_EnterScope();
716 757
758 if (vmstats_port >= 0) {
759 VmStats::Start(vmstats_port, vmstats_root);
760 }
761
717 if (generate_script_snapshot) { 762 if (generate_script_snapshot) {
718 // First create a snapshot. 763 // First create a snapshot.
719 Dart_Handle result; 764 Dart_Handle result;
720 uint8_t* buffer = NULL; 765 uint8_t* buffer = NULL;
721 intptr_t size = 0; 766 intptr_t size = 0;
722 result = Dart_CreateScriptSnapshot(&buffer, &size); 767 result = Dart_CreateScriptSnapshot(&buffer, &size);
723 if (Dart_IsError(result)) { 768 if (Dart_IsError(result)) {
724 Log::PrintErr("%s\n", Dart_GetError(result)); 769 Log::PrintErr("%s\n", Dart_GetError(result));
725 Dart_ExitScope(); 770 Dart_ExitScope();
726 Dart_ShutdownIsolate(); 771 Dart_ShutdownIsolate();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 return ErrorExit("%s\n", Dart_GetError(result)); 812 return ErrorExit("%s\n", Dart_GetError(result));
768 } 813 }
769 // Keep handling messages until the last active receive port is closed. 814 // Keep handling messages until the last active receive port is closed.
770 result = Dart_RunLoop(); 815 result = Dart_RunLoop();
771 if (Dart_IsError(result)) { 816 if (Dart_IsError(result)) {
772 return ErrorExit("%s\n", Dart_GetError(result)); 817 return ErrorExit("%s\n", Dart_GetError(result));
773 } 818 }
774 } 819 }
775 820
776 Dart_ExitScope(); 821 Dart_ExitScope();
822 VmStats::Stop();
777 // Shutdown the isolate. 823 // Shutdown the isolate.
778 Dart_ShutdownIsolate(); 824 Dart_ShutdownIsolate();
779 // Terminate process exit-code handler. 825 // Terminate process exit-code handler.
780 Process::TerminateExitCodeHandler(); 826 Process::TerminateExitCodeHandler();
781 // Free copied argument strings if converted. 827 // Free copied argument strings if converted.
782 if (argv_converted) { 828 if (argv_converted) {
783 for (int i = 0; i < argc; i++) free(argv[i]); 829 for (int i = 0; i < argc; i++) free(argv[i]);
784 } 830 }
785 831
786 return Process::GlobalExitCode(); 832 return Process::GlobalExitCode();
787 } 833 }
OLDNEW
« no previous file with comments | « runtime/bin/bin.gypi ('k') | runtime/bin/vmstats.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698